Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/makesrna/intern/rna_define.c')
-rw-r--r--source/blender/makesrna/intern/rna_define.c179
1 files changed, 142 insertions, 37 deletions
diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c
index f22fd594d8d..8d05cbde74c 100644
--- a/source/blender/makesrna/intern/rna_define.c
+++ b/source/blender/makesrna/intern/rna_define.c
@@ -1001,18 +1001,18 @@ void RNA_def_property_clear_flag(PropertyRNA *prop, int flag)
prop->flag &= ~flag;
}
-void RNA_def_property_array(PropertyRNA *prop, int arraylength)
+void RNA_def_property_array(PropertyRNA *prop, int length)
{
StructRNA *srna= DefRNA.laststruct;
- if(arraylength<0) {
+ if(length<0) {
fprintf(stderr, "RNA_def_property_array: %s.%s, array length must be zero of greater.\n", srna->identifier, prop->identifier);
DefRNA.error= 1;
return;
}
- if(arraylength>RNA_MAX_ARRAY) {
- fprintf(stderr, "RNA_def_property_array: %s.%s, array length must be smaller than %d.\n", srna->identifier, prop->identifier, RNA_MAX_ARRAY);
+ if(length>RNA_MAX_ARRAY_LENGTH) {
+ fprintf(stderr, "RNA_def_property_array: %s.%s, array length must be smaller than %d.\n", srna->identifier, prop->identifier, RNA_MAX_ARRAY_LENGTH);
DefRNA.error= 1;
return;
}
@@ -1021,7 +1021,9 @@ void RNA_def_property_array(PropertyRNA *prop, int arraylength)
case PROP_BOOLEAN:
case PROP_INT:
case PROP_FLOAT:
- prop->arraylength= arraylength;
+ prop->arraylength[0]= length;
+ prop->totarraylength= length;
+ prop->arraydimension= 1;
break;
default:
fprintf(stderr, "RNA_def_property_array: %s.%s, only boolean/int/float can be array.\n", srna->identifier, prop->identifier);
@@ -1030,6 +1032,44 @@ void RNA_def_property_array(PropertyRNA *prop, int arraylength)
}
}
+void RNA_def_property_multi_array(PropertyRNA *prop, int dimension, int length[])
+{
+ StructRNA *srna= DefRNA.laststruct;
+ int i;
+
+ if (dimension < 1 || dimension > RNA_MAX_ARRAY_DIMENSION) {
+ fprintf(stderr, "RNA_def_property_multi_array: %s.%s, array dimension must be between 1 and %d.\n", srna->identifier, prop->identifier, RNA_MAX_ARRAY_DIMENSION);
+ DefRNA.error= 1;
+ return;
+ }
+
+ switch(prop->type) {
+ case PROP_BOOLEAN:
+ case PROP_INT:
+ case PROP_FLOAT:
+ break;
+ default:
+ fprintf(stderr, "RNA_def_property_multi_array: %s.%s, only boolean/int/float can be array.\n", srna->identifier, prop->identifier);
+ DefRNA.error= 1;
+ break;
+ }
+
+ prop->arraydimension= dimension;
+ prop->totarraylength= 0;
+
+ if(length) {
+ memcpy(prop->arraylength, length, sizeof(int)*dimension);
+
+ prop->totarraylength= length[0];
+ for(i=1; i<dimension; i++)
+ prop->totarraylength *= length[i];
+ }
+ else
+ memset(prop->arraylength, 0, sizeof(prop->arraylength));
+
+ /* TODO make sure arraylength values are sane */
+}
+
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
{
prop->name= name;
@@ -1173,8 +1213,14 @@ void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item
defaultfound= 1;
}
- if(!defaultfound)
- eprop->defaultvalue= item[0].value;
+ if(!defaultfound) {
+ for(i=0; item[i].identifier; i++) {
+ if(item[i].identifier[0]) {
+ eprop->defaultvalue= item[i].value;
+ break;
+ }
+ }
+ }
break;
}
@@ -1394,10 +1440,15 @@ static PropertyDefRNA *rna_def_property_sdna(PropertyRNA *prop, const char *stru
}
}
- if(smember.arraylength > 1)
- prop->arraylength= smember.arraylength;
- else
- prop->arraylength= 0;
+ if(smember.arraylength > 1) {
+ prop->arraylength[0]= smember.arraylength;
+ prop->totarraylength= smember.arraylength;
+ prop->arraydimension= 1;
+ }
+ else {
+ prop->arraydimension= 0;
+ prop->totarraylength= 0;
+ }
dp->dnastructname= structname;
dp->dnastructfromname= ds->dnafromname;
@@ -1517,8 +1568,10 @@ void RNA_def_property_enum_sdna(PropertyRNA *prop, const char *structname, const
}
if((dp=rna_def_property_sdna(prop, structname, propname))) {
- if(prop->arraylength) {
- prop->arraylength= 0;
+ if(prop->arraydimension) {
+ prop->arraydimension= 0;
+ prop->totarraylength= 0;
+
if(!DefRNA.silent) {
fprintf(stderr, "RNA_def_property_enum_sdna: %s.%s, array not supported for enum type.\n", structname, propname);
DefRNA.error= 1;
@@ -1557,9 +1610,10 @@ void RNA_def_property_string_sdna(PropertyRNA *prop, const char *structname, con
}
if((dp=rna_def_property_sdna(prop, structname, propname))) {
- if(prop->arraylength) {
- sprop->maxlength= prop->arraylength;
- prop->arraylength= 0;
+ if(prop->arraydimension) {
+ sprop->maxlength= prop->totarraylength;
+ prop->arraydimension= 0;
+ prop->totarraylength= 0;
}
}
}
@@ -1581,8 +1635,10 @@ void RNA_def_property_pointer_sdna(PropertyRNA *prop, const char *structname, co
}
if((dp=rna_def_property_sdna(prop, structname, propname))) {
- if(prop->arraylength) {
- prop->arraylength= 0;
+ if(prop->arraydimension) {
+ prop->arraydimension= 0;
+ prop->totarraylength= 0;
+
if(!DefRNA.silent) {
fprintf(stderr, "RNA_def_property_pointer_sdna: %s.%s, array not supported for pointer type.\n", structname, propname);
DefRNA.error= 1;
@@ -1609,8 +1665,9 @@ void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname,
}
if((dp=rna_def_property_sdna(prop, structname, propname))) {
- if(prop->arraylength && !lengthpropname) {
- prop->arraylength= 0;
+ if(prop->arraydimension && !lengthpropname) {
+ prop->arraydimension= 0;
+ prop->totarraylength= 0;
if(!DefRNA.silent) {
fprintf(stderr, "RNA_def_property_collection_sdna: %s.%s, array of collections not supported.\n", structname, propname);
@@ -1634,8 +1691,9 @@ void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname,
if(lengthpropname[0] == 0 || rna_find_sdna_member(DefRNA.sdna, structname, lengthpropname, &smember)) {
if(lengthpropname[0] == 0) {
- dp->dnalengthfixed= prop->arraylength;
- prop->arraylength= 0;
+ dp->dnalengthfixed= prop->totarraylength;
+ prop->arraydimension= 0;
+ prop->totarraylength= 0;
}
else {
dp->dnalengthstructname= structname;
@@ -1682,6 +1740,22 @@ void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
prop->update= (UpdateFunc)func;
}
+void RNA_def_property_dynamic_array_funcs(PropertyRNA *prop, const char *getlength)
+{
+ if(!DefRNA.preprocess) {
+ fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
+ return;
+ }
+
+ if (!(prop->flag & PROP_DYNAMIC)) {
+ fprintf(stderr, "RNA_def_property_dynamic_array_funcs: property is a not dynamic array.\n");
+ DefRNA.error= 1;
+ return;
+ }
+
+ if(getlength) prop->getlength= (PropArrayLengthGetFunc)getlength;
+}
+
void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set)
{
StructRNA *srna= DefRNA.laststruct;
@@ -1695,7 +1769,7 @@ void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const ch
case PROP_BOOLEAN: {
BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
- if(prop->arraylength) {
+ if(prop->arraydimension) {
if(get) bprop->getarray= (PropBooleanArrayGetFunc)get;
if(set) bprop->setarray= (PropBooleanArraySetFunc)set;
}
@@ -1725,7 +1799,7 @@ void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *
case PROP_INT: {
IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
- if(prop->arraylength) {
+ if(prop->arraydimension) {
if(get) iprop->getarray= (PropIntArrayGetFunc)get;
if(set) iprop->setarray= (PropIntArraySetFunc)set;
}
@@ -1756,7 +1830,7 @@ void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char
case PROP_FLOAT: {
FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
- if(prop->arraylength) {
+ if(prop->arraydimension) {
if(get) fprop->getarray= (PropFloatArrayGetFunc)get;
if(set) fprop->setarray= (PropFloatArraySetFunc)set;
}
@@ -1908,6 +1982,34 @@ PropertyRNA *RNA_def_boolean_array(StructOrFunctionRNA *cont_, const char *ident
return prop;
}
+PropertyRNA *RNA_def_boolean_layer(StructOrFunctionRNA *cont_, const char *identifier, int len, int *default_value,
+ const char *ui_name, const char *ui_description)
+{
+ ContainerRNA *cont= cont_;
+ PropertyRNA *prop;
+
+ prop= RNA_def_property(cont, identifier, PROP_BOOLEAN, PROP_LAYER);
+ if(len != 0) RNA_def_property_array(prop, len);
+ if(default_value) RNA_def_property_boolean_array_default(prop, default_value);
+ RNA_def_property_ui_text(prop, ui_name, ui_description);
+
+ return prop;
+}
+
+PropertyRNA *RNA_def_boolean_layer_member(StructOrFunctionRNA *cont_, const char *identifier, int len, int *default_value,
+ const char *ui_name, const char *ui_description)
+{
+ ContainerRNA *cont= cont_;
+ PropertyRNA *prop;
+
+ prop= RNA_def_property(cont, identifier, PROP_BOOLEAN, PROP_LAYER_MEMBER);
+ if(len != 0) RNA_def_property_array(prop, len);
+ if(default_value) RNA_def_property_boolean_array_default(prop, default_value);
+ RNA_def_property_ui_text(prop, ui_name, ui_description);
+
+ return prop;
+}
+
PropertyRNA *RNA_def_boolean_vector(StructOrFunctionRNA *cont_, const char *identifier, int len, int *default_value,
const char *ui_name, const char *ui_description)
{
@@ -2079,14 +2181,15 @@ PropertyRNA *RNA_def_float_color(StructOrFunctionRNA *cont_, const char *identif
}
-PropertyRNA *RNA_def_float_matrix(StructOrFunctionRNA *cont_, const char *identifier, int len, const float *default_value,
+PropertyRNA *RNA_def_float_matrix(StructOrFunctionRNA *cont_, const char *identifier, int rows, int columns, const float *default_value,
float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
{
ContainerRNA *cont= cont_;
PropertyRNA *prop;
+ int length[2]= {rows, columns};
prop= RNA_def_property(cont, identifier, PROP_FLOAT, PROP_MATRIX);
- if(len != 0) RNA_def_property_array(prop, len);
+ RNA_def_property_multi_array(prop, 2, length);
if(default_value) RNA_def_property_float_array_default(prop, default_value);
if(hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
RNA_def_property_ui_text(prop, ui_name, ui_description);
@@ -2283,11 +2386,12 @@ void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
int rna_parameter_size(PropertyRNA *parm)
{
PropertyType ptype= parm->type;
- int len= parm->arraylength;
-
- if (parm->flag & PROP_DYNAMIC_ARRAY) return sizeof(void*);
+ int len= parm->totarraylength; /* only supports fixed length at the moment */
if(len > 0) {
+ if (parm->flag & PROP_DYNAMIC)
+ return sizeof(void *);
+
switch (ptype) {
case PROP_BOOLEAN:
case PROP_INT:
@@ -2432,8 +2536,8 @@ void RNA_def_property_duplicate_pointers(PropertyRNA *prop)
BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
if(bprop->defaultarray) {
- iarray= MEM_callocN(sizeof(int)*prop->arraylength, "RNA_def_property_store");
- memcpy(iarray, bprop->defaultarray, sizeof(int)*prop->arraylength);
+ iarray= MEM_callocN(sizeof(int)*prop->totarraylength, "RNA_def_property_store");
+ memcpy(iarray, bprop->defaultarray, sizeof(int)*prop->totarraylength);
bprop->defaultarray= iarray;
}
break;
@@ -2442,8 +2546,8 @@ void RNA_def_property_duplicate_pointers(PropertyRNA *prop)
IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
if(iprop->defaultarray) {
- iarray= MEM_callocN(sizeof(int)*prop->arraylength, "RNA_def_property_store");
- memcpy(iarray, iprop->defaultarray, sizeof(int)*prop->arraylength);
+ iarray= MEM_callocN(sizeof(int)*prop->totarraylength, "RNA_def_property_store");
+ memcpy(iarray, iprop->defaultarray, sizeof(int)*prop->totarraylength);
iprop->defaultarray= iarray;
}
break;
@@ -2468,8 +2572,8 @@ void RNA_def_property_duplicate_pointers(PropertyRNA *prop)
FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
if(fprop->defaultarray) {
- farray= MEM_callocN(sizeof(float)*prop->arraylength, "RNA_def_property_store");
- memcpy(farray, fprop->defaultarray, sizeof(float)*prop->arraylength);
+ farray= MEM_callocN(sizeof(float)*prop->totarraylength, "RNA_def_property_store");
+ memcpy(farray, fprop->defaultarray, sizeof(float)*prop->totarraylength);
fprop->defaultarray= farray;
}
break;
@@ -2513,13 +2617,14 @@ void RNA_def_property_free_pointers(PropertyRNA *prop)
}
case PROP_ENUM: {
EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
- if(eprop->item) MEM_freeN((void*)eprop->item);
for(a=0; a<eprop->totitem; a++) {
if(eprop->item[a].identifier) MEM_freeN((void*)eprop->item[a].identifier);
if(eprop->item[a].name) MEM_freeN((void*)eprop->item[a].name);
if(eprop->item[a].description) MEM_freeN((void*)eprop->item[a].description);
}
+
+ if(eprop->item) MEM_freeN((void*)eprop->item);
break;
}
case PROP_STRING: {