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