dc3d2486126a427f50c40da73e62479da53cc045
[blender.git] / source / blender / makesrna / intern / rna_rna.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * Contributor(s): Blender Foundation (2008).
21  *
22  * ***** END GPL LICENSE BLOCK *****
23  */
24
25 #include <stdlib.h>
26
27 #include "RNA_access.h"
28 #include "RNA_define.h"
29 #include "RNA_types.h"
30
31 #ifdef RNA_RUNTIME
32
33 /* Struct */
34
35 static void rna_StructRNA_cname_get(PointerRNA *ptr, char *value)
36 {
37         strcpy(value, ((StructRNA*)ptr->data)->cname);
38 }
39
40 static int rna_StructRNA_cname_length(PointerRNA *ptr)
41 {
42         return strlen(((StructRNA*)ptr->data)->cname);
43 }
44
45 static void rna_StructRNA_name_get(PointerRNA *ptr, char *value)
46 {
47         strcpy(value, ((StructRNA*)ptr->data)->name);
48 }
49
50 static int rna_StructRNA_name_length(PointerRNA *ptr)
51 {
52         return strlen(((StructRNA*)ptr->data)->name);
53 }
54
55 static void *rna_StructRNA_name_property_get(PointerRNA *ptr)
56 {
57         return ((StructRNA*)ptr->data)->nameproperty;
58 }
59
60 static void *rna_StructRNA_iterator_property_get(PointerRNA *ptr)
61 {
62         return ((StructRNA*)ptr->data)->iteratorproperty;
63 }
64
65 static void rna_StructRNA_properties_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
66 {
67         rna_iterator_listbase_begin(iter, &((StructRNA*)ptr->data)->properties);
68 }
69
70 static void rna_StructRNA_properties_next(CollectionPropertyIterator *iter)
71 {
72         rna_iterator_listbase_next(iter);
73 }
74
75 static void *rna_StructRNA_properties_get(CollectionPropertyIterator *iter)
76 {
77         return rna_iterator_listbase_get(iter);
78 }
79
80 static StructRNA *rna_StructRNA_properties_type(CollectionPropertyIterator *iter)
81 {
82         PropertyRNA *prop= iter->internal;
83
84         switch(prop->type) {
85                 case PROP_BOOLEAN: return &RNA_BooleanPropertyRNA;
86                 case PROP_INT: return &RNA_IntPropertyRNA;
87                 case PROP_FLOAT: return &RNA_FloatPropertyRNA;
88                 case PROP_STRING: return &RNA_StringPropertyRNA;
89                 case PROP_ENUM: return &RNA_EnumPropertyRNA;
90                 case PROP_POINTER: return &RNA_PointerPropertyRNA;
91                 case PROP_COLLECTION: return &RNA_CollectionPropertyRNA;
92                 default: return NULL;
93         }
94 }
95
96 static void rna_builtin_properties_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
97 {
98         PointerRNA newptr;
99
100         /* we create a new with the type as the data */
101         newptr.type= &RNA_StructRNA;
102         newptr.data= ptr->type;
103
104         if(ptr->type->flag & STRUCT_ID) {
105                 newptr.id.type= ptr->type;
106                 newptr.id.data= ptr->data;
107         }
108         else {
109                 newptr.id.type= NULL;
110                 newptr.id.data= NULL;
111         }
112
113         rna_StructRNA_properties_begin(iter, &newptr);
114 }
115
116 static void rna_builtin_properties_next(CollectionPropertyIterator *iter)
117 {
118         rna_StructRNA_properties_next(iter);
119 }
120
121 static void *rna_builtin_properties_get(CollectionPropertyIterator *iter)
122 {
123         return rna_StructRNA_properties_get(iter);
124 }
125
126 static StructRNA *rna_builtin_properties_type(CollectionPropertyIterator *iter)
127 {
128         return rna_StructRNA_properties_type(iter);
129 }
130
131 static void *rna_builtin_type_get(PointerRNA *ptr)
132 {
133         return ptr->type;
134 }
135
136 /* Property */
137
138 static void rna_PropertyRNA_cname_get(PointerRNA *ptr, char *value)
139 {
140         strcpy(value, ((PropertyRNA*)ptr->data)->cname);
141 }
142
143 static int rna_PropertyRNA_cname_length(PointerRNA *ptr)
144 {
145         return strlen(((PropertyRNA*)ptr->data)->cname);
146 }
147
148 static void rna_PropertyRNA_name_get(PointerRNA *ptr, char *value)
149 {
150         strcpy(value, ((PropertyRNA*)ptr->data)->name);
151 }
152
153 static int rna_PropertyRNA_name_length(PointerRNA *ptr)
154 {
155         return strlen(((PropertyRNA*)ptr->data)->name);
156 }
157
158 static void rna_PropertyRNA_description_get(PointerRNA *ptr, char *value)
159 {
160         strcpy(value, ((PropertyRNA*)ptr->data)->description);
161 }
162
163 static int rna_PropertyRNA_description_length(PointerRNA *ptr)
164 {
165         return strlen(((PropertyRNA*)ptr->data)->description);
166 }
167
168 static int rna_PropertyRNA_type_get(PointerRNA *ptr)
169 {
170         return ((PropertyRNA*)ptr->data)->type;
171 }
172
173 static int rna_PropertyRNA_subtype_get(PointerRNA *ptr)
174 {
175         return ((PropertyRNA*)ptr->data)->subtype;
176 }
177
178 static int rna_PropertyRNA_array_length_get(PointerRNA *ptr)
179 {
180         return ((PropertyRNA*)ptr->data)->arraylength;
181 }
182
183 #else
184
185 static void rna_def_property(StructRNA *srna)
186 {
187         PropertyRNA *prop;
188         static PropertyEnumItem type_items[] = {
189                 {PROP_BOOLEAN, "BOOLEAN", "Boolean"},
190                 {PROP_INT, "INT", "Integer"},
191                 {PROP_FLOAT, "FLOAT", "Float"},
192                 {PROP_STRING, "STRING", "String"},
193                 {PROP_ENUM, "ENUM", "Enumeration"},
194                 {PROP_POINTER, "POINTER", "Pointer"},
195                 {PROP_COLLECTION, "COLLECTION", "Collection"},
196                 {0, NULL, NULL}};
197         static PropertyEnumItem subtype_items[] = {
198                 {PROP_NONE, "NONE", "None"},
199                 {PROP_UNSIGNED, "UNSIGNED", "Unsigned Number"},
200                 {PROP_FILEPATH, "FILEPATH", "File Path"},
201                 {PROP_COLOR, "COLOR", "Color"},
202                 {PROP_VECTOR, "VECTOR", "Vector"},
203                 {PROP_MATRIX, "MATRIX", "Matrix"},
204                 {PROP_ROTATION, "ROTATION", "Rotation"},
205                 {0, NULL, NULL}};
206
207         prop= RNA_def_property(srna, "cname", PROP_STRING, PROP_NONE);
208         RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
209         RNA_def_property_string_funcs(prop, "rna_PropertyRNA_cname_get", "rna_PropertyRNA_cname_length", NULL);
210
211         prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
212         RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
213         RNA_def_property_string_funcs(prop, "rna_PropertyRNA_name_get", "rna_PropertyRNA_name_length", NULL);
214         RNA_def_struct_name_property(srna, prop);
215
216         prop= RNA_def_property(srna, "description", PROP_STRING, PROP_NONE);
217         RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
218         RNA_def_property_string_funcs(prop, "rna_PropertyRNA_description_get", "rna_PropertyRNA_description_length", NULL);
219
220         prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
221         RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
222         RNA_def_property_enum_items(prop, type_items);
223         RNA_def_property_enum_funcs(prop, "rna_PropertyRNA_type_get", NULL);
224
225         prop= RNA_def_property(srna, "subtype", PROP_ENUM, PROP_NONE);
226         RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
227         RNA_def_property_enum_items(prop, subtype_items);
228         RNA_def_property_enum_funcs(prop, "rna_PropertyRNA_subtype_get", NULL);
229
230         prop= RNA_def_property(srna, "array_length", PROP_INT, PROP_NONE);
231         RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
232         RNA_def_property_int_funcs(prop, "rna_PropertyRNA_array_length_get", NULL);
233 }
234
235 void RNA_def_rna(BlenderRNA *brna)
236 {
237         StructRNA *srna;
238         PropertyRNA *prop;
239
240         /* StructRNA */
241         srna= RNA_def_struct(brna, "StructRNA", "Struct RNA");
242
243         prop= RNA_def_property(srna, "cname", PROP_STRING, PROP_NONE);
244         RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
245         RNA_def_property_string_funcs(prop, "rna_StructRNA_cname_get", "rna_StructRNA_cname_length", NULL);
246
247         prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
248         RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
249         RNA_def_property_string_funcs(prop, "rna_StructRNA_name_get", "rna_StructRNA_name_length", NULL);
250         RNA_def_struct_name_property(srna, prop);
251
252         prop= RNA_def_property(srna, "name_property", PROP_POINTER, PROP_NONE);
253         RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
254         RNA_def_property_struct_type(prop, "StringPropertyRNA");
255         RNA_def_property_pointer_funcs(prop, "rna_StructRNA_name_property_get", NULL, NULL);
256
257         prop= RNA_def_property(srna, "iterator_property", PROP_POINTER, PROP_NONE);
258         RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
259         RNA_def_property_struct_type(prop, "CollectionPropertyRNA");
260         RNA_def_property_pointer_funcs(prop, "rna_StructRNA_iterator_property_get", NULL, NULL);
261
262         prop= RNA_def_property(srna, "properties", PROP_COLLECTION, PROP_NONE);
263         RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
264         RNA_def_property_collection_funcs(prop, "rna_StructRNA_properties_begin", "rna_StructRNA_properties_next", 0, "rna_StructRNA_properties_get", "rna_StructRNA_properties_type", 0, 0, 0);
265
266         /* BooleanPropertyRNA */
267         srna= RNA_def_struct(brna, "BooleanPropertyRNA", "Boolean Property");
268         rna_def_property(srna);
269
270         /* IntPropertyRNA */
271         srna= RNA_def_struct(brna, "IntPropertyRNA", "Int Property");
272         rna_def_property(srna);
273
274         /* FloatPropertyRNA */
275         srna= RNA_def_struct(brna, "FloatPropertyRNA", "Float Property");
276         rna_def_property(srna);
277
278         /* StringPropertyRNA */
279         srna= RNA_def_struct(brna, "StringPropertyRNA", "String Property");
280         rna_def_property(srna);
281
282         /* EnumPropertyRNA */
283         srna= RNA_def_struct(brna, "EnumPropertyRNA", "Enum Property");
284         rna_def_property(srna);
285
286         /* PointerPropertyRNA */
287         srna= RNA_def_struct(brna, "PointerPropertyRNA", "Pointer Property");
288         rna_def_property(srna);
289
290         /* CollectionPropertyRNA */
291         srna= RNA_def_struct(brna, "CollectionPropertyRNA", "Collection Property");
292         rna_def_property(srna);
293 }
294
295 void rna_def_builtin_properties(StructRNA *srna)
296 {
297         PropertyRNA *prop;
298
299         prop= RNA_def_property(srna, "rna_properties", PROP_COLLECTION, PROP_NONE);
300         RNA_def_property_flag(prop, PROP_NOT_EDITABLE|PROP_BUILTIN);
301         RNA_def_property_collection_funcs(prop, "rna_builtin_properties_begin", "rna_builtin_properties_next", 0, "rna_builtin_properties_get", "rna_builtin_properties_type", 0, 0, 0);
302
303         prop= RNA_def_property(srna, "rna_type", PROP_POINTER, PROP_NONE);
304         RNA_def_property_flag(prop, PROP_NOT_EDITABLE|PROP_BUILTIN);
305         RNA_def_property_struct_type(prop, "StructRNA");
306         RNA_def_property_pointer_funcs(prop, "rna_builtin_type_get", NULL, NULL);
307 }
308
309 #endif
310