]> icculus.org git repositories - dana/openbox.git/blob - render2/texture.c
add textures
[dana/openbox.git] / render2 / texture.c
1 #include "texture.h"
2 #include "surface.h"
3
4 void texture_free(struct RrTexture *tex)
5 {
6     switch (tex->type) {
7     case RR_TEXTURE_NONE:
8         break;
9     case RR_TEXTURE_TEXT:
10         free(tex->data.text.string);
11         break;
12     case RR_TEXTUER_RGBA:
13         break;
14     }
15     tex->type = RR_TEXTURE_NONE;
16 }
17
18 void RrTextureSetRGBA(struct RrSurface *sur,
19                       int texnum,
20                       RrData32 *data,
21                       int x,
22                       int y,
23                       int w,
24                       int h)
25 {
26     struct RrTexture *tex = RrSurfaceTexture(sur, texnum);
27
28     if (!tex) return;
29     texture_free(tex);
30     tex->type = RR_TEXTURE_RGBA;
31     tex->data.rgba.data = data;
32     tex->data.rgba.x = x;
33     tex->data.rgba.y = y;
34     tex->data.rgba.w = w;
35     tex->data.rgba.h = h;
36 }
37
38 void RrTextureSetText(struct RrSurface *sur,
39                       int texnum,
40                       struct RrFont *font,
41                       enum RrLayout layout,
42                       const char *text)
43 {
44     struct RrTexture *tex = RrSurfaceTexture(sur, texnum);
45     int l;
46
47     if (!tex) return;
48     texture_free(tex);
49     tex->type = RR_TEXTURE_TEXT;
50     tex->data.text.font = font;
51     tex->data.text.layout = layout;
52
53     l = strlen(text) + 1;
54     tex->data.text.string = malloc(l);
55     memcpy(tex->data.text.string, text, l);
56 }