]> git.draconx.ca Git - upkg.git/blob - src/engine/texture.c
Minor fixes.
[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
40         U_OBJECT_CLASS(engine_texture_parent_class)->deserialize(o, f);
41
42         printf("Texture size: %ux%u\n", t->usize, t->vsize);
43
44         return 0;
45 }
46
47 void texture_register(GTypeModule *m)
48 {
49         engine_texture_register_type(m);
50 }
51
52 static void
53 set_property(GObject *o, guint id, const GValue *val, GParamSpec *spec)
54 {
55         EngineTexture *t = ENGINE_TEXTURE(o);
56
57         switch (id) {
58         case PROP_USIZE:
59                 t->usize = g_value_get_uint(val);
60                 break;
61         case PROP_VSIZE:
62                 t->vsize = g_value_get_uint(val);
63                 break;
64         default:
65                 G_OBJECT_WARN_INVALID_PROPERTY_ID(o, id, spec);
66         }
67 }
68
69 static void
70 get_property(GObject *o, guint id, GValue *val, GParamSpec *spec)
71 {
72         EngineTexture *t = ENGINE_TEXTURE(o);
73
74         switch (id) {
75         case PROP_USIZE:
76                 g_value_set_boolean(val, t->usize);
77                 break;
78         case PROP_VSIZE:
79                 g_value_set_boolean(val, t->vsize);
80                 break;
81         default:
82                 G_OBJECT_WARN_INVALID_PROPERTY_ID(o, id, spec);
83         }
84 }
85
86 static void engine_texture_init(EngineTexture *t)
87 {
88         t->usize = t->vsize = 0;
89 }
90
91 static void engine_texture_class_init(EngineTextureClass *class)
92 {
93         UObjectClass *uo = U_OBJECT_CLASS(class);
94         GObjectClass *go = G_OBJECT_CLASS(class);
95
96         g_type_class_add_private(class, sizeof (struct texture_priv));
97
98         uo->deserialize = deserialize;
99         go->set_property = set_property;
100         go->get_property = get_property;
101
102         g_object_class_install_property(go, PROP_USIZE,
103                 g_param_spec_uint("USize",
104                         "USize",
105                         "Width of the texture.",
106                         0, 2048, 0,
107                         G_PARAM_READWRITE));
108         g_object_class_install_property(go, PROP_VSIZE,
109                 g_param_spec_uint("VSize",
110                         "VSize",
111                         "Height of the texture.",
112                         0, 2048, 0,
113                         G_PARAM_READWRITE));
114 }
115
116 static void engine_texture_class_finalize(EngineTextureClass *class)
117 {
118 }