2.50: svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r17434...
[blender.git] / source / blender / makesrna / intern / rna_controller.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 #include "rna_internal.h"
32
33 #include "DNA_controller_types.h"
34
35 #ifdef RNA_RUNTIME
36
37 static struct StructRNA* rna_Controller_refine(struct PointerRNA *ptr)
38 {
39         bController *controller= (bController*)ptr->data;
40
41         switch(controller->type) {
42                 case CONT_LOGIC_AND:
43                         return &RNA_AndController;
44                 case CONT_LOGIC_OR:
45                         return &RNA_OrController;
46                 case CONT_LOGIC_NAND:
47                         return &RNA_NandController;
48                 case CONT_LOGIC_NOR:
49                         return &RNA_NorController;
50                 case CONT_LOGIC_XOR:
51                         return &RNA_XorController;
52                 case CONT_LOGIC_XNOR:
53                         return &RNA_XnorController;
54                 case CONT_EXPRESSION:
55                         return &RNA_ExpressionController;
56                 case CONT_PYTHON:
57                         return &RNA_PythonController;
58                 default:
59                         return &RNA_Controller;
60         }
61 }
62
63 #else
64
65 void RNA_def_controller(BlenderRNA *brna)
66 {
67         StructRNA *srna;
68         PropertyRNA *prop;
69         static EnumPropertyItem controller_type_items[] ={
70                 {CONT_LOGIC_AND, "LOGICAND", "Logic And", ""},
71                 {CONT_LOGIC_OR, "LOGICOR", "Logic Or", ""},
72                 {CONT_LOGIC_NAND, "LOGICNAND", "Logic Nand", ""},
73                 {CONT_LOGIC_NOR, "LOGICNOR", "Logic Nor", ""},
74                 {CONT_LOGIC_XOR, "LOGICXOR", "Logic Xor", ""},
75                 {CONT_LOGIC_XNOR, "LOGICXNOR", "Logic Xnor", ""},
76                 {CONT_EXPRESSION, "EXPRESSION", "Expression", ""},
77                 {CONT_PYTHON, "PYTHON", "Python Script", ""},
78                 {0, NULL, NULL, NULL}};
79
80         /* Controller */
81         srna= RNA_def_struct(brna, "Controller", NULL , "Controller");
82         RNA_def_struct_sdna(srna, "bController");
83         RNA_def_struct_funcs(srna, NULL, "rna_Controller_refine");
84
85         prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
86         RNA_def_property_ui_text(prop, "Name", "");
87         RNA_def_struct_name_property(srna, prop);
88
89         /* type is not editable, would need to do proper data free/alloc */
90         prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
91         RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
92         RNA_def_property_enum_items(prop, controller_type_items);
93         RNA_def_property_ui_text(prop, "Type", "");
94
95         /* Expression Controller */
96         srna= RNA_def_struct(brna, "ExpressionController", "Controller", "Expression Controller");
97         RNA_def_struct_sdna_from(srna, "bExpressionCont", "data");
98
99         prop= RNA_def_property(srna, "expression", PROP_STRING, PROP_NONE);
100         RNA_def_property_string_sdna(prop, NULL, "str");
101         RNA_def_property_string_maxlength(prop, 127);
102         RNA_def_property_ui_text(prop, "Expression", "");
103
104         /* Python Controller */
105         srna= RNA_def_struct(brna, "PythonController", "Controller" , "Python Controller");
106         RNA_def_struct_sdna_from(srna, "bPythonCont", "data");
107
108         prop= RNA_def_property(srna, "text", PROP_POINTER, PROP_NONE);
109         RNA_def_property_struct_type(prop, "ID");
110         RNA_def_property_ui_text(prop, "Python Text", "");
111
112         /* Other Controllers */
113         RNA_def_struct(brna, "AndController", "Controller", "And Controller");
114         RNA_def_struct(brna, "OrController", "Controller", "Or Controller");
115         RNA_def_struct(brna, "NorController", "Controller", "Nor Controller");
116         RNA_def_struct(brna, "NandController", "Controller", "Nand Controller");
117         RNA_def_struct(brna, "XorController", "Controller", "Xor Controller");
118         RNA_def_struct(brna, "XnorController", "Controller", "Xnor Controller");
119 }
120
121 #endif
122