]> git.draconx.ca Git - upkg.git/blob - src/engine/texture.c
license: Update copyright notices.
[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 };
36
37 struct texture_priv {
38         unsigned type;
39
40         struct upkg_file *f;
41         size_t base, len;
42
43         unsigned char buf[2048];
44         unsigned long nbuf;
45 };
46
47 void exportable_init(UObjectExportable *e)
48 {
49 }
50
51 G_DEFINE_DYNAMIC_TYPE(EngineTexture, engine_texture, U_OBJECT_TYPE);
52
53 static int deserialize(UObject *uo)
54 {
55         struct texture_priv *priv = TEXTURE_GET_PRIV(uo);
56         EngineTexture *t = ENGINE_TEXTURE(uo);
57
58         U_OBJECT_CLASS(engine_texture_parent_class)->deserialize(uo);
59
60         printf("Texture size: %ux%u\n", t->usize, t->vsize);
61
62         return 0;
63 }
64
65 void texture_register(GTypeModule *m)
66 {
67         engine_texture_register_type(m);
68 }
69
70 static void
71 set_property(GObject *o, guint id, const GValue *val, GParamSpec *spec)
72 {
73         EngineTexture *t = ENGINE_TEXTURE(o);
74
75         switch (id) {
76         case PROP_USIZE:
77                 t->usize = g_value_get_uint(val);
78                 break;
79         case PROP_VSIZE:
80                 t->vsize = g_value_get_uint(val);
81                 break;
82         default:
83                 G_OBJECT_WARN_INVALID_PROPERTY_ID(o, id, spec);
84         }
85 }
86
87 static void
88 get_property(GObject *o, guint id, GValue *val, GParamSpec *spec)
89 {
90         EngineTexture *t = ENGINE_TEXTURE(o);
91
92         switch (id) {
93         case PROP_USIZE:
94                 g_value_set_boolean(val, t->usize);
95                 break;
96         case PROP_VSIZE:
97                 g_value_set_boolean(val, t->vsize);
98                 break;
99         default:
100                 G_OBJECT_WARN_INVALID_PROPERTY_ID(o, id, spec);
101         }
102 }
103
104 static void engine_texture_init(EngineTexture *t)
105 {
106         t->usize = t->vsize = 0;
107 }
108
109 static void engine_texture_class_init(EngineTextureClass *class)
110 {
111         UObjectClass *uo = U_OBJECT_CLASS(class);
112         GObjectClass *go = G_OBJECT_CLASS(class);
113
114         g_type_class_add_private(class, sizeof (struct texture_priv));
115
116         uo->deserialize = deserialize;
117         go->set_property = set_property;
118         go->get_property = get_property;
119
120         g_object_class_install_property(go, PROP_USIZE,
121                 g_param_spec_uint("USize",
122                         "USize",
123                         "Width of the texture.",
124                         0, 2048, 0,
125                         G_PARAM_READWRITE));
126         g_object_class_install_property(go, PROP_VSIZE,
127                 g_param_spec_uint("VSize",
128                         "VSize",
129                         "Height of the texture.",
130                         0, 2048, 0,
131                         G_PARAM_READWRITE));
132 }
133
134 static void engine_texture_class_finalize(EngineTextureClass *class)
135 {
136 }