add textures
authorDana Jansens <danakj@orodu.net>
Mon, 26 May 2003 18:48:34 +0000 (18:48 +0000)
committerDana Jansens <danakj@orodu.net>
Mon, 26 May 2003 18:48:34 +0000 (18:48 +0000)
render2/Makefile.am
render2/render.h
render2/surface.h
render2/texture.c [new file with mode: 0644]
render2/texture.h [new file with mode: 0644]

index 88f862447c7273c47cc7cc46b6bd62998471f96f..8f9c4d21b23268703f149e027dc82c5f48825370 100644 (file)
@@ -15,9 +15,21 @@ rendertest_LDFLAGS=-lobrender2 -L.
 rendertest_SOURCES=test.c
 
 lib_LTLIBRARIES=libobrender2.la
-libobrender2_la_SOURCES=init.c instance.c color.c debug.c font.c surface.c
-
-noinst_HEADERS=render.h instance.h debug.h surface.h
+libobrender2_la_SOURCES=\
+       init.c \
+       instance.c \
+       color.c \
+       debug.c \
+       font.c \
+       surface.c \
+       texture.h
+
+noinst_HEADERS=\
+       render.h \
+       instance.h \
+       debug.h \
+       surface.h \
+       texture.h
 
 MAINTAINERCLEANFILES=Makefile.in
 
index 8c0611ca6594c09cd379a9e4d8043b01edbf7369..90a5b56e4e1ba83c83068bd11e7d92d6f29ccb85 100644 (file)
@@ -76,17 +76,12 @@ int RrFontMaxCharWidth(struct RrFont *font);
 /* surfaces */
 
 struct RrSurface;
-struct RrTexture;
 
 enum RrSurfaceType {
     RR_SURFACE_PLANAR,
     RR_SURFACE_NONPLANAR
 };
 
-enum RrTextureType {
-    RR_TEXTURE_FOO
-};
-
 /*! The options available for the background of an RrSurface */
 enum RrSurfaceColorType {
     /*! No rendering on the surface background, its contents will be
@@ -133,6 +128,38 @@ struct RrSurface *RrSurfaceCopyChild(struct RrSurface *sur,
 void RrSurfaceFree(struct RrSurface *sur);
 
 Window RrSurfaceWindow(struct RrSurface *sur);
-struct RrTexture *RrSurfaceTexture(struct RrSurface *sur, int texnum);
+
+/* textures */
+
+enum RrLayout {
+    RR_TOP_LEFT,
+    RR_TOP,
+    RR_TOP_RIGHT,
+    RR_LEFT,
+    RR_CENTER,
+    RR_RIGHT,
+    RR_BOTTOM_LEFT,
+    RR_BOTTOM,
+    RR_BOTTOM_RIGHT
+};
+
+#ifndef __LONG64
+typedef long RrData32;
+#else
+typedef int RrData32;
+#endif
+
+void RrTextureSetRGBA(struct RrSurface *sur,
+                      int texnum,
+                      RrData32 *data,
+                      int x,
+                      int y,
+                      int w,
+                      int h);
+void RrTextureSetText(struct RrSurface *sur,
+                      int texnum,
+                      struct RrFont *font,
+                      enum RrLayout layout,
+                      const char *text);
 
 #endif
index 1a0ff756646dd0690270bf5159e88f726c2df7b0..9218b67c4ae09c36dadbe2e8562c5c5489ab1b83 100644 (file)
@@ -42,4 +42,6 @@ struct RrSurface {
     int parenty;
 };
 
+struct RrTexture *RrSurfaceTexture(struct RrSurface *sur, int texnum);
+
 #endif
diff --git a/render2/texture.c b/render2/texture.c
new file mode 100644 (file)
index 0000000..d2b6da6
--- /dev/null
@@ -0,0 +1,56 @@
+#include "texture.h"
+#include "surface.h"
+
+void texture_free(struct RrTexture *tex)
+{
+    switch (tex->type) {
+    case RR_TEXTURE_NONE:
+        break;
+    case RR_TEXTURE_TEXT:
+        free(tex->data.text.string);
+        break;
+    case RR_TEXTUER_RGBA:
+        break;
+    }
+    tex->type = RR_TEXTURE_NONE;
+}
+
+void RrTextureSetRGBA(struct RrSurface *sur,
+                      int texnum,
+                      RrData32 *data,
+                      int x,
+                      int y,
+                      int w,
+                      int h)
+{
+    struct RrTexture *tex = RrSurfaceTexture(sur, texnum);
+
+    if (!tex) return;
+    texture_free(tex);
+    tex->type = RR_TEXTURE_RGBA;
+    tex->data.rgba.data = data;
+    tex->data.rgba.x = x;
+    tex->data.rgba.y = y;
+    tex->data.rgba.w = w;
+    tex->data.rgba.h = h;
+}
+
+void RrTextureSetText(struct RrSurface *sur,
+                      int texnum,
+                      struct RrFont *font,
+                      enum RrLayout layout,
+                      const char *text)
+{
+    struct RrTexture *tex = RrSurfaceTexture(sur, texnum);
+    int l;
+
+    if (!tex) return;
+    texture_free(tex);
+    tex->type = RR_TEXTURE_TEXT;
+    tex->data.text.font = font;
+    tex->data.text.layout = layout;
+
+    l = strlen(text) + 1;
+    tex->data.text.string = malloc(l);
+    memcpy(tex->data.text.string, text, l);
+}
diff --git a/render2/texture.h b/render2/texture.h
new file mode 100644 (file)
index 0000000..5415dbb
--- /dev/null
@@ -0,0 +1,36 @@
+#ifndef __render_texture_h
+#define __render_texture_h
+
+#include "render.h"
+
+enum RrTextureType {
+    RR_TEXTURE_NONE,
+    RR_TEXTURE_TEXT,
+    RR_TEXTURE_RGBA
+};
+
+struct RrTextureText {
+    struct RrFont *font;
+    enum RrLayout layout;
+    char *string;
+};
+
+struct RrTextureRGBA {
+    RrData32 *data;
+    int x;
+    int y;
+    int w;
+    int h;
+};
+
+union RrTextureData {
+    struct RrTextureText text;
+    struct RrTextureRGBA rgba;
+};
+
+struct RrTexture {
+    enum RrTextureType type;
+    union RrTextureData data;
+};
+
+#endif