diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-09-15 14:01:20 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-09-15 14:01:20 +0400 |
commit | 689b77ba9df8b618e0d7b58feda9161317361d74 (patch) | |
tree | 963205bf16d9c0064e431c390ad05cbfd1c2a05e /source/blender/makesrna/intern/rna_rna.c | |
parent | 223bc8aee1c6f0c1e6d16d0edd8cf23387c33a3f (diff) |
- new property attribute - default_array, which returns a variable size array useful to get the defaults for operator & function arrays.
- updated python api to check for array types rather then the length since a variable length array can be 1 or 0 length.
- python docgen added .0 to the end of floats which messed up values like 1e-05
Diffstat (limited to 'source/blender/makesrna/intern/rna_rna.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_rna.c | 80 |
1 files changed, 75 insertions, 5 deletions
diff --git a/source/blender/makesrna/intern/rna_rna.c b/source/blender/makesrna/intern/rna_rna.c index 8df6398f1f4..196d25ada86 100644 --- a/source/blender/makesrna/intern/rna_rna.c +++ b/source/blender/makesrna/intern/rna_rna.c @@ -458,6 +458,62 @@ static int rna_IntProperty_default_get(PointerRNA *ptr) rna_idproperty_check(&prop, ptr); return ((IntPropertyRNA*)prop)->defaultvalue; } +/* int/float/bool */ +static int rna_NumberProperty_default_array_get_length(PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION]) +{ + PropertyRNA *prop= (PropertyRNA*)ptr->data; + rna_idproperty_check(&prop, ptr); + + length[0]= prop->totarraylength; + + return length[0]; +} +static void rna_IntProperty_default_array_get(PointerRNA *ptr, int *values) +{ + PropertyRNA *prop= (PropertyRNA*)ptr->data; + IntPropertyRNA *nprop= (IntPropertyRNA*)prop; + rna_idproperty_check(&prop, ptr); + + if(nprop->defaultarray) { + memcpy(values, nprop->defaultarray, prop->totarraylength * sizeof(int)); + } + else { + int i; + for(i=0; i < prop->totarraylength; i++) + values[i]= nprop->defaultvalue; + } +} +static void rna_BoolProperty_default_array_get(PointerRNA *ptr, int *values) +{ + PropertyRNA *prop= (PropertyRNA*)ptr->data; + BooleanPropertyRNA *nprop= (BooleanPropertyRNA*)prop; + rna_idproperty_check(&prop, ptr); + + if(nprop->defaultarray) { + memcpy(values, nprop->defaultarray, prop->totarraylength * sizeof(int)); + } + else { + int i; + for(i=0; i < prop->totarraylength; i++) + values[i]= nprop->defaultvalue; + } +} +static void rna_FloatProperty_default_array_get(PointerRNA *ptr, float *values) +{ + PropertyRNA *prop= (PropertyRNA*)ptr->data; + FloatPropertyRNA *nprop= (FloatPropertyRNA*)prop; + rna_idproperty_check(&prop, ptr); + + if(nprop->defaultarray) { + memcpy(values, nprop->defaultarray, prop->totarraylength * sizeof(float)); + } + else { + int i; + for(i=0; i < prop->totarraylength; i++) + values[i]= nprop->defaultvalue; + } +} + static int rna_IntProperty_hard_min_get(PointerRNA *ptr) { PropertyRNA *prop= (PropertyRNA*)ptr->data; @@ -932,13 +988,27 @@ static void rna_def_number_property(StructRNA *srna, PropertyType type) } -#if 0 // XXX - Variable length arrays prop= RNA_def_property(srna, "default_array", type, PROP_NONE); RNA_def_property_clear_flag(prop, PROP_EDITABLE); - if(type == PROP_INT) RNA_def_property_int_funcs(prop, "rna_IntProperty_default_array_get", NULL, NULL); - else RNA_def_property_float_funcs(prop, "rna_FloatProperty_default_array_get", NULL, NULL); - RNA_def_property_ui_text(prop, "Default", "Default value for this number"); -#endif + RNA_def_property_array(prop, RNA_MAX_ARRAY_DIMENSION); /* no fixed default length, important its not 0 though */ + RNA_def_property_flag(prop, PROP_DYNAMIC); + RNA_def_property_dynamic_array_funcs(prop, "rna_NumberProperty_default_array_get_length"); /* same for all types */ + + switch(type) { + case PROP_BOOLEAN: + RNA_def_property_boolean_funcs(prop, "rna_BoolProperty_default_array_get", NULL); + break; + case PROP_INT: + RNA_def_property_int_funcs(prop, "rna_IntProperty_default_array_get", NULL, NULL); + break; + case PROP_FLOAT: + RNA_def_property_float_funcs(prop, "rna_FloatProperty_default_array_get", NULL, NULL); + break; + default: + break; + } + RNA_def_property_ui_text(prop, "Default Array", "Default value for this array"); + prop= RNA_def_property(srna, "array_length", PROP_INT, PROP_UNSIGNED); RNA_def_property_clear_flag(prop, PROP_EDITABLE); |