RNA
[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);
82         RNA_def_struct_ui_text(srna, "Controller", "logic brick to connect 'Sensors' to 'Actuators'");
83         RNA_def_struct_sdna(srna, "bController");
84         RNA_def_struct_refine_func(srna, "rna_Controller_refine");
85
86         prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
87         RNA_def_property_ui_text(prop, "Name", "");
88         RNA_def_struct_name_property(srna, prop);
89
90         /* type is not editable, would need to do proper data free/alloc */
91         prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
92         RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
93         RNA_def_property_enum_items(prop, controller_type_items);
94         RNA_def_property_ui_text(prop, "Type", "");
95
96         /* Expression Controller */
97         srna= RNA_def_struct(brna, "ExpressionController", "Controller");
98         RNA_def_struct_ui_text(srna, "Expression Controller", "DOC_BROKEN");
99         RNA_def_struct_sdna_from(srna, "bExpressionCont", "data");
100
101         prop= RNA_def_property(srna, "expression", PROP_STRING, PROP_NONE);
102         RNA_def_property_string_sdna(prop, NULL, "str");
103         RNA_def_property_string_maxlength(prop, 127);
104         RNA_def_property_ui_text(prop, "Expression", "");
105
106         /* Python Controller */
107         srna= RNA_def_struct(brna, "PythonController", "Controller" );
108         RNA_def_struct_ui_text(srna, "Python Controller", "DOC_BROKEN");
109         RNA_def_struct_sdna_from(srna, "bPythonCont", "data");
110
111         prop= RNA_def_property(srna, "text", PROP_POINTER, PROP_NONE);
112         RNA_def_property_struct_type(prop, "ID");
113         RNA_def_property_ui_text(prop, "Python Text", "");
114
115         /* Other Controllers */
116         srna= RNA_def_struct(brna, "AndController", "Controller");
117         RNA_def_struct_ui_text(srna, "And Controller", "DOC_BROKEN");
118         
119         srna= RNA_def_struct(brna, "OrController", "Controller");
120         RNA_def_struct_ui_text(srna, "Or Controller", "DOC_BROKEN");
121         
122         srna= RNA_def_struct(brna, "NorController", "Controller");
123         RNA_def_struct_ui_text(srna, "Nor Controller", "DOC_BROKEN");
124         
125         srna= RNA_def_struct(brna, "NandController", "Controller");
126         RNA_def_struct_ui_text(srna, "Nand Controller", "DOC_BROKEN");
127         
128         srna= RNA_def_struct(brna, "XorController", "Controller");
129         RNA_def_struct_ui_text(srna, "Xor Controller", "DOC_BROKEN");
130         
131         srna= RNA_def_struct(brna, "XnorController", "Controller");
132         RNA_def_struct_ui_text(srna, "Xnor Controller", "DOC_BROKEN");
133 }
134
135 #endif
136