]> git.draconx.ca Git - upkg.git/blob - src/engine/texture.c
Merge branch 'uobject' of git://git.draconx.ca/upkg into uobject
[upkg.git] / src / engine / texture.c
1 /*
2  *  upkg: tool for manipulating Unreal Tournament packages.
3  *  Copyright (C) 2009 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 2 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, write to the Free Software
17  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19
20 #include <stdio.h>
21 #include <string.h>
22 #include <glib-object.h>
23
24 #include <uobject/uobject.h>
25 #include <uobject/exportable.h>
26 #include "texture.h"
27 #include "upkg.h"
28
29 #define TEXTURE_GET_PRIV(o) \
30         G_TYPE_INSTANCE_GET_PRIVATE(o, ENGINE_TEXTURE_TYPE, struct texture_priv)
31
32 enum {
33         PROP_0,
34         PROP_USIZE,
35         PROP_VSIZE,
36 };
37
38 struct texture_priv {
39         unsigned type;
40
41         struct upkg_file *f;
42         size_t base, len;
43
44         unsigned char buf[2048];
45         unsigned long nbuf;
46 };
47
48 void exportable_init(UObjectExportable *e)
49 {
50 }
51
52 G_DEFINE_DYNAMIC_TYPE(EngineTexture, engine_texture, U_OBJECT_TYPE);
53
54 static int deserialize(UObject *o, struct upkg_file *f)
55 {
56         struct texture_priv *priv = TEXTURE_GET_PRIV(o);
57         EngineTexture *t = ENGINE_TEXTURE(o);
58
59         U_OBJECT_CLASS(engine_texture_parent_class)->deserialize(o, f);
60
61         printf("Texture size: %ux%u\n", t->usize, t->vsize);
62
63         return 0;
64 }
65
66 void texture_register(GTypeModule *m)
67 {
68         engine_texture_register_type(m);
69 }
70
71 static void
72 set_property(GObject *o, guint id, const GValue *val, GParamSpec *spec)
73 {
74         EngineTexture *t = ENGINE_TEXTURE(o);
75
76         switch (id) {
77         case PROP_USIZE:
78                 t->usize = g_value_get_uint(val);
79                 break;
80         case PROP_VSIZE:
81                 t->vsize = g_value_get_uint(val);
82                 break;
83         default:
84                 G_OBJECT_WARN_INVALID_PROPERTY_ID(o, id, spec);
85         }
86 }
87
88 static void
89 get_property(GObject *o, guint id, GValue *val, GParamSpec *spec)
90 {
91         EngineTexture *t = ENGINE_TEXTURE(o);
92
93         switch (id) {
94         case PROP_USIZE:
95                 g_value_set_boolean(val, t->usize);
96                 break;
97         case PROP_VSIZE:
98                 g_value_set_boolean(val, t->vsize);
99                 break;
100         default:
101                 G_OBJECT_WARN_INVALID_PROPERTY_ID(o, id, spec);
102         }
103 }
104
105 static void engine_texture_init(EngineTexture *t)
106 {
107         t->usize = t->vsize = 0;
108 }
109
110 static void engine_texture_class_init(EngineTextureClass *class)
111 {
112         UObjectClass *uo = U_OBJECT_CLASS(class);
113         GObjectClass *go = G_OBJECT_CLASS(class);
114
115         g_type_class_add_private(class, sizeof (struct texture_priv));
116
117         uo->deserialize = deserialize;
118         go->set_property = set_property;
119         go->get_property = get_property;
120
121         g_object_class_install_property(go, PROP_USIZE,
122                 g_param_spec_uint("USize",
123                         "USize",
124                         "Width of the texture.",
125                         0, 2048, 0,
126                         G_PARAM_READWRITE));
127         g_object_class_install_property(go, PROP_VSIZE,
128                 g_param_spec_uint("VSize",
129                         "VSize",
130                         "Height of the texture.",
131                         0, 2048, 0,
132                         G_PARAM_READWRITE));
133 }
134
135 static void engine_texture_class_finalize(EngineTextureClass *class)
136 {
137 }