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