]> git.draconx.ca Git - upkg.git/blob - src/engine/texture.c
Use GObject properties for stuff since it makes much more sense.
[upkg.git] / src / engine / texture.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <glib-object.h>
4
5 #include "exportable.h"
6 #include "uobject.h"
7 #include "texture.h"
8 #include "upkg.h"
9
10 #define TEXTURE_GET_PRIV(o) \
11         G_TYPE_INSTANCE_GET_PRIVATE(o, ENGINE_TEXTURE_TYPE, struct texture_priv)
12
13 enum {
14         PROP_0,
15         PROP_USIZE,
16         PROP_VSIZE,
17 };
18
19 struct texture_priv {
20         unsigned type;
21
22         struct upkg_file *f;
23         size_t base, len;
24
25         unsigned char buf[2048];
26         unsigned long nbuf;
27 };
28
29 void exportable_init(UObjectExportable *e)
30 {
31 }
32
33 G_DEFINE_DYNAMIC_TYPE(EngineTexture, engine_texture, U_OBJECT_TYPE);
34
35 static int deserialize(UObject *o, struct upkg_file *f)
36 {
37         struct texture_priv *priv = TEXTURE_GET_PRIV(o);
38         EngineTexture *t = ENGINE_TEXTURE(o);
39         const GValue *val;
40
41         U_OBJECT_CLASS(engine_texture_parent_class)->deserialize(o, f);
42
43         printf("Texture size: %lux%lu\n", t->usize, t->vsize);
44
45         return 0;
46 }
47
48 void texture_register(GTypeModule *m)
49 {
50         engine_texture_register_type(m);
51 }
52
53 static void
54 set_property(GObject *o, guint id, const GValue *val, GParamSpec *spec)
55 {
56         EngineTexture *t = ENGINE_TEXTURE(o);
57
58         switch (id) {
59         case PROP_USIZE:
60                 t->usize = g_value_get_uint(val);
61                 break;
62         case PROP_VSIZE:
63                 t->vsize = g_value_get_uint(val);
64                 break;
65         default:
66                 G_OBJECT_WARN_INVALID_PROPERTY_ID(o, id, spec);
67         }
68 }
69
70 static void
71 get_property(GObject *o, guint id, GValue *val, GParamSpec *spec)
72 {
73         EngineTexture *t = ENGINE_TEXTURE(o);
74
75         switch (id) {
76         case PROP_USIZE:
77                 g_value_set_boolean(val, t->usize);
78                 break;
79         case PROP_VSIZE:
80                 g_value_set_boolean(val, t->vsize);
81                 break;
82         default:
83                 G_OBJECT_WARN_INVALID_PROPERTY_ID(o, id, spec);
84         }
85 }
86
87 static void engine_texture_init(EngineTexture *t)
88 {
89         t->usize = t->vsize = 0;
90 }
91
92 static void engine_texture_class_init(EngineTextureClass *class)
93 {
94         UObjectClass *uo = U_OBJECT_CLASS(class);
95         GObjectClass *go = G_OBJECT_CLASS(class);
96
97         g_type_class_add_private(class, sizeof (struct texture_priv));
98
99         uo->deserialize = deserialize;
100         go->set_property = set_property;
101         go->get_property = get_property;
102
103         g_object_class_install_property(go, PROP_USIZE,
104                 g_param_spec_uint("USize",
105                         "USize",
106                         "Width of the texture.",
107                         0, 2048, 0,
108                         G_PARAM_READWRITE));
109         g_object_class_install_property(go, PROP_VSIZE,
110                 g_param_spec_uint("VSize",
111                         "VSize",
112                         "Height of the texture.",
113                         0, 2048, 0,
114                         G_PARAM_READWRITE));
115 }
116
117 static void engine_texture_class_finalize(EngineTextureClass *class)
118 {
119 }