]> git.draconx.ca Git - upkg.git/blob - src/engine/texture.c
texture: Add missing integer properties.
[upkg.git] / src / engine / texture.c
1 /*
2  *  upkg: tool for manipulating Unreal Tournament packages.
3  *  Copyright © 2009-2011 Nick Bowler
4  *
5  *  This program is free software: you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation, either version 3 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #include <stdio.h>
20 #include <string.h>
21 #include <glib-object.h>
22
23 #include <uobject/uobject.h>
24 #include <uobject/exportable.h>
25 #include "texture.h"
26 #include "upkg.h"
27
28 #define TEXTURE_GET_PRIV(o) \
29         G_TYPE_INSTANCE_GET_PRIVATE(o, ENGINE_TEXTURE_TYPE, struct texture_priv)
30
31 enum {
32         PROP_0,
33         PROP_USIZE,
34         PROP_VSIZE,
35         PROP_UCLAMP,
36         PROP_VCLAMP,
37         PROP_UBITS,
38         PROP_VBITS,
39 };
40
41 struct texture_priv {
42         unsigned type;
43
44         struct upkg_file *f;
45         size_t base, len;
46
47         unsigned char buf[2048];
48         unsigned long nbuf;
49 };
50
51 void exportable_init(UObjectExportable *e)
52 {
53 }
54
55 G_DEFINE_DYNAMIC_TYPE(EngineTexture, engine_texture, U_OBJECT_TYPE);
56
57 static int deserialize(UObject *uo)
58 {
59         struct texture_priv *priv = TEXTURE_GET_PRIV(uo);
60         EngineTexture *t = ENGINE_TEXTURE(uo);
61
62         U_OBJECT_CLASS(engine_texture_parent_class)->deserialize(uo);
63
64         return 0;
65 }
66
67 void texture_register(GTypeModule *m)
68 {
69         engine_texture_register_type(m);
70 }
71
72 static void
73 set_property(GObject *o, guint id, const GValue *val, GParamSpec *spec)
74 {
75         EngineTexture *t = ENGINE_TEXTURE(o);
76
77         switch (id) {
78         case PROP_USIZE:
79                 t->usize = g_value_get_uint(val);
80                 break;
81         case PROP_VSIZE:
82                 t->vsize = g_value_get_uint(val);
83                 break;
84         case PROP_UCLAMP:
85                 t->uclamp = g_value_get_uint(val);
86                 break;
87         case PROP_VCLAMP:
88                 t->vclamp = g_value_get_uint(val);
89                 break;
90         case PROP_UBITS:
91                 t->ubits = g_value_get_uint(val);
92                 break;
93         case PROP_VBITS:
94                 t->vbits = g_value_get_uint(val);
95                 break;
96         default:
97                 G_OBJECT_WARN_INVALID_PROPERTY_ID(o, id, spec);
98         }
99 }
100
101 static void
102 get_property(GObject *o, guint id, GValue *val, GParamSpec *spec)
103 {
104         EngineTexture *t = ENGINE_TEXTURE(o);
105
106         switch (id) {
107         case PROP_USIZE:
108                 g_value_set_uint(val, t->usize);
109                 break;
110         case PROP_VSIZE:
111                 g_value_set_uint(val, t->vsize);
112                 break;
113         case PROP_UCLAMP:
114                 g_value_set_uint(val, t->uclamp);
115                 break;
116         case PROP_VCLAMP:
117                 g_value_set_uint(val, t->vclamp);
118                 break;
119         case PROP_UBITS:
120                 g_value_set_uint(val, t->ubits);
121                 break;
122         case PROP_VBITS:
123                 g_value_set_uint(val, t->vbits);
124                 break;
125         default:
126                 G_OBJECT_WARN_INVALID_PROPERTY_ID(o, id, spec);
127         }
128 }
129
130 static void engine_texture_init(EngineTexture *t)
131 {
132         t->usize = t->vsize = 0;
133 }
134
135 static void engine_texture_class_init(EngineTextureClass *class)
136 {
137         UObjectClass *uo = U_OBJECT_CLASS(class);
138         GObjectClass *go = G_OBJECT_CLASS(class);
139
140         g_type_class_add_private(class, sizeof (struct texture_priv));
141
142         uo->deserialize = deserialize;
143         go->set_property = set_property;
144         go->get_property = get_property;
145
146         g_object_class_install_property(go, PROP_USIZE,
147                 g_param_spec_uint("USize",
148                         "USize",
149                         "Width of the texture.",
150                         0, 2048, 0,
151                         G_PARAM_READWRITE));
152         g_object_class_install_property(go, PROP_VSIZE,
153                 g_param_spec_uint("VSize",
154                         "VSize",
155                         "Height of the texture.",
156                         0, 2048, 0,
157                         G_PARAM_READWRITE));
158         g_object_class_install_property(go, PROP_UCLAMP,
159                 g_param_spec_uint("UClamp",
160                         "UClamp",
161                         "???",
162                         0, 2048, 0,
163                         G_PARAM_READWRITE));
164         g_object_class_install_property(go, PROP_VCLAMP,
165                 g_param_spec_uint("VClamp",
166                         "VClamp",
167                         "???",
168                         0, 2048, 0,
169                         G_PARAM_READWRITE));
170         g_object_class_install_property(go, PROP_UBITS,
171                 g_param_spec_uint("UBits",
172                         "UBits",
173                         "???",
174                         0, 64, 0,
175                         G_PARAM_READWRITE));
176         g_object_class_install_property(go, PROP_VBITS,
177                 g_param_spec_uint("VBits",
178                         "VBits",
179                         "???",
180                         0, 64, 0,
181                         G_PARAM_READWRITE));
182 }
183
184 static void engine_texture_class_finalize(EngineTextureClass *class)
185 {
186 }