Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * Contributor(s): Blender Foundation (2008). 00019 * 00020 * ***** END GPL LICENSE BLOCK ***** 00021 */ 00022 00028 #include <stdlib.h> 00029 00030 #include "RNA_define.h" 00031 00032 #include "rna_internal.h" 00033 00034 #include "DNA_property_types.h" 00035 00036 #include "WM_types.h" 00037 00038 EnumPropertyItem gameproperty_type_items[] ={ 00039 {GPROP_BOOL, "BOOL", 0, "Boolean", "Boolean Property"}, 00040 {GPROP_INT, "INT", 0, "Integer", "Integer Property"}, 00041 {GPROP_FLOAT, "FLOAT", 0, "Float", "Floating-Point Property"}, 00042 {GPROP_STRING, "STRING", 0, "String", "String Property"}, 00043 {GPROP_TIME, "TIMER", 0, "Timer", "Timer Property"}, 00044 {0, NULL, 0, NULL, NULL}}; 00045 00046 00047 #ifdef RNA_RUNTIME 00048 00049 #include "BKE_property.h" 00050 00051 static StructRNA* rna_GameProperty_refine(struct PointerRNA *ptr) 00052 { 00053 bProperty *property= (bProperty*)ptr->data; 00054 00055 switch(property->type){ 00056 case GPROP_BOOL: 00057 return &RNA_GameBooleanProperty; 00058 case GPROP_INT: 00059 return &RNA_GameIntProperty; 00060 case GPROP_FLOAT: 00061 return &RNA_GameFloatProperty; 00062 case GPROP_STRING: 00063 return &RNA_GameStringProperty; 00064 case GPROP_TIME: 00065 return &RNA_GameTimerProperty; 00066 default: 00067 return &RNA_GameProperty; 00068 } 00069 } 00070 00071 /* for both float and timer */ 00072 static float rna_GameFloatProperty_value_get(PointerRNA *ptr) 00073 { 00074 bProperty *prop= (bProperty*)(ptr->data); 00075 return *(float*)(&prop->data); 00076 } 00077 00078 static void rna_GameFloatProperty_value_set(PointerRNA *ptr, float value) 00079 { 00080 bProperty *prop= (bProperty*)(ptr->data); 00081 CLAMP(value, -10000.0f, 10000.0f); 00082 *(float*)(&prop->data)= value; 00083 } 00084 00085 static void rna_GameProperty_type_set(PointerRNA *ptr, int value) 00086 { 00087 bProperty *prop= (bProperty*)(ptr->data); 00088 00089 if(prop->type != value) { 00090 prop->type= value; 00091 init_property(prop); 00092 } 00093 } 00094 00095 static void rna_GameProperty_name_set(PointerRNA *ptr, const char *value) 00096 { 00097 bProperty *prop= (bProperty*)(ptr->data); 00098 BLI_strncpy_utf8(prop->name, value, sizeof(prop->name)); 00099 unique_property(NULL, prop, 1); 00100 } 00101 00102 00103 #else 00104 00105 void RNA_def_gameproperty(BlenderRNA *brna) 00106 { 00107 StructRNA *srna; 00108 PropertyRNA *prop; 00109 00110 /* Base Struct for GameProperty */ 00111 srna= RNA_def_struct(brna, "GameProperty", NULL); 00112 RNA_def_struct_ui_text(srna , "Game Property", "Game engine user defined object property"); 00113 RNA_def_struct_sdna(srna, "bProperty"); 00114 RNA_def_struct_refine_func(srna, "rna_GameProperty_refine"); 00115 00116 prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); 00117 RNA_def_property_ui_text(prop, "Name", "Available as GameObject attributes in the game engine's python API"); 00118 RNA_def_struct_name_property(srna, prop); 00119 RNA_def_property_string_funcs(prop, NULL, NULL, "rna_GameProperty_name_set"); 00120 RNA_def_property_update(prop, NC_LOGIC, NULL); 00121 00122 prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE); 00123 RNA_def_property_enum_items(prop, gameproperty_type_items); 00124 RNA_def_property_ui_text(prop, "Type", ""); 00125 RNA_def_property_enum_funcs(prop, NULL, "rna_GameProperty_type_set", NULL); 00126 RNA_def_property_update(prop, NC_LOGIC, NULL); 00127 00128 prop= RNA_def_property(srna, "show_debug", PROP_BOOLEAN, PROP_NONE); 00129 RNA_def_property_boolean_sdna(prop, NULL, "flag", PROP_DEBUG); 00130 RNA_def_property_ui_text(prop, "Debug", "Print debug information for this property"); 00131 RNA_def_property_update(prop, NC_LOGIC, NULL); 00132 00133 /* GameBooleanProperty */ 00134 srna= RNA_def_struct(brna, "GameBooleanProperty", "GameProperty"); 00135 RNA_def_struct_ui_text(srna , "Game Boolean Property", "Game engine user defined Boolean property"); 00136 RNA_def_struct_sdna(srna, "bProperty"); 00137 RNA_def_property_update(prop, NC_LOGIC, NULL); 00138 00139 prop= RNA_def_property(srna, "value", PROP_BOOLEAN, PROP_NONE); 00140 RNA_def_property_boolean_sdna(prop, NULL, "data", 1); 00141 RNA_def_property_ui_text(prop, "Value", "Property value"); 00142 RNA_def_property_update(prop, NC_LOGIC, NULL); 00143 00144 /* GameIntProperty */ 00145 srna= RNA_def_struct(brna, "GameIntProperty", "GameProperty"); 00146 RNA_def_struct_ui_text(srna , "Game Integer Property", "Game engine user defined integer number property"); 00147 RNA_def_struct_sdna(srna, "bProperty"); 00148 00149 prop= RNA_def_property(srna, "value", PROP_INT, PROP_NONE); 00150 RNA_def_property_int_sdna(prop, NULL, "data"); 00151 RNA_def_property_ui_text(prop, "Value", "Property value"); 00152 RNA_def_property_range(prop, -10000, 10000); 00153 RNA_def_property_update(prop, NC_LOGIC, NULL); 00154 00155 /* GameFloatProperty */ 00156 srna= RNA_def_struct(brna, "GameFloatProperty", "GameProperty"); 00157 RNA_def_struct_ui_text(srna, "Game Float Property", "Game engine user defined floating point number property"); 00158 RNA_def_struct_sdna(srna, "bProperty"); 00159 00160 prop= RNA_def_property(srna, "value", PROP_FLOAT, PROP_NONE); 00161 // RNA_def_property_float_sdna(prop, NULL, "data"); 00162 RNA_def_property_ui_text(prop, "Value", "Property value"); 00163 RNA_def_property_range(prop, -10000, 10000); 00164 RNA_def_property_float_funcs(prop, "rna_GameFloatProperty_value_get", "rna_GameFloatProperty_value_set", NULL); 00165 RNA_def_property_update(prop, NC_LOGIC, NULL); 00166 00167 /* GameTimerProperty */ 00168 srna= RNA_def_struct(brna, "GameTimerProperty", "GameProperty"); 00169 RNA_def_struct_ui_text(srna, "Game Timer Property", "Game engine user defined timer property"); 00170 RNA_def_struct_sdna(srna, "bProperty"); 00171 00172 prop= RNA_def_property(srna, "value", PROP_FLOAT, PROP_NONE); 00173 // RNA_def_property_float_sdna(prop, NULL, "data"); 00174 RNA_def_property_ui_text(prop, "Value", "Property value"); 00175 RNA_def_property_range(prop, -10000, 10000); 00176 RNA_def_property_float_funcs(prop, "rna_GameFloatProperty_value_get", "rna_GameFloatProperty_value_set", NULL); 00177 RNA_def_property_update(prop, NC_LOGIC, NULL); 00178 00179 /* GameStringProperty */ 00180 srna= RNA_def_struct(brna, "GameStringProperty", "GameProperty"); 00181 RNA_def_struct_ui_text(srna, "Game String Property", "Game engine user defined text string property"); 00182 RNA_def_struct_sdna(srna, "bProperty"); 00183 00184 prop= RNA_def_property(srna, "value", PROP_STRING, PROP_NONE); 00185 RNA_def_property_string_sdna(prop, NULL, "poin"); 00186 RNA_def_property_string_maxlength(prop, MAX_PROPSTRING); 00187 RNA_def_property_ui_text(prop, "Value", "Property value"); 00188 RNA_def_property_update(prop, NC_LOGIC, NULL); 00189 } 00190 00191 #endif 00192