diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-11-18 23:01:35 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-11-18 23:01:35 +0300 |
commit | ae5a814f26e78dd65557773b5c00c341cdca1947 (patch) | |
tree | c605eed391e60b097820b501e588309d517acf07 /source/blender/makesrna/intern/rna_access.c | |
parent | 5f6b9fd324162358ac482b151bc034e0006d6734 (diff) |
ID properties that are displayed via RNA can now define their own UI settings,
only implimented min/max precision & step.
at the moment there is no way to edit these other then via python
example of setting UI limits...
>>> C.object['foo'] = 0.5
>>> C.object['_RNA_UI'] = {'foo': {'step': 0.5, 'soft_max': 10.0, 'soft_min': 0.0, 'precision': 2, 'description': 'Some setting'}}
Also fixed typo's: precission -> precision
Diffstat (limited to 'source/blender/makesrna/intern/rna_access.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 107 |
1 files changed, 106 insertions, 1 deletions
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 422c4d9befe..155f2ff594d 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -190,6 +190,29 @@ PointerRNA rna_pointer_inherit_refine(PointerRNA *ptr, StructRNA *type, void *da /* ID Properties */ +/* return a UI local ID prop definition for this prop */ +IDProperty *rna_idproperty_ui(PropertyRNA *prop) +{ + IDProperty *idprop; + + for(idprop= ((IDProperty *)prop)->prev; idprop; idprop= idprop->prev) { + if (strcmp(RNA_IDP_UI, idprop->name)==0) + break; + } + + if(idprop==NULL) { + for(idprop= ((IDProperty *)prop)->next; idprop; idprop= idprop->next) { + if (strcmp(RNA_IDP_UI, idprop->name)==0) + break; + } + } + + if (idprop) + return IDP_GetPropertyFromGroup(idprop, ((IDProperty *)prop)->name); + + return NULL; +} + IDProperty *RNA_struct_idproperties(PointerRNA *ptr, int create) { StructRNA *type= ptr->type; @@ -396,8 +419,17 @@ static const char *rna_ensure_property_description(PropertyRNA *prop) { if(prop->magic == RNA_MAGIC) return prop->description; - else + else { + /* attempt to get the local ID values */ + IDProperty *idp_ui= rna_idproperty_ui(prop); + + if(idp_ui) { /* TODO, type checking on ID props */ + IDProperty *item= IDP_GetPropertyFromGroup(idp_ui, "description"); + return item ? ((IDProperty*)prop)->name : item->data.pointer; + } + return ((IDProperty*)prop)->name; /* XXX - not correct */ + } } static const char *rna_ensure_property_name(PropertyRNA *prop) @@ -668,6 +700,22 @@ void RNA_property_int_range(PointerRNA *ptr, PropertyRNA *prop, int *hardmin, in { IntPropertyRNA *iprop= (IntPropertyRNA*)rna_ensure_property(prop); + if(prop->magic != RNA_MAGIC) { + /* attempt to get the local ID values */ + IDProperty *idp_ui= rna_idproperty_ui(prop); + IDProperty *item; + + if(idp_ui) { /* TODO, type checking on ID props */ + item= IDP_GetPropertyFromGroup(idp_ui, "min"); + *hardmin= item ? item->data.val : INT_MIN; + + item= IDP_GetPropertyFromGroup(idp_ui, "max"); + *hardmax= item ? item->data.val : INT_MAX; + + return; + } + } + if(iprop->range) { iprop->range(ptr, hardmin, hardmax); } @@ -682,6 +730,25 @@ void RNA_property_int_ui_range(PointerRNA *ptr, PropertyRNA *prop, int *softmin, IntPropertyRNA *iprop= (IntPropertyRNA*)rna_ensure_property(prop); int hardmin, hardmax; + if(prop->magic != RNA_MAGIC) { + /* attempt to get the local ID values */ + IDProperty *idp_ui= rna_idproperty_ui(prop); + IDProperty *item; + + if(idp_ui) { /* TODO, type checking on ID props */ + item= IDP_GetPropertyFromGroup(idp_ui, "soft_min"); + *softmin= item ? item->data.val : INT_MIN; + + item= IDP_GetPropertyFromGroup(idp_ui, "soft_max"); + *softmax= item ? item->data.val : INT_MAX; + + item= IDP_GetPropertyFromGroup(idp_ui, "step"); + *step= item ? item->data.val : 1; + + return; + } + } + if(iprop->range) { iprop->range(ptr, &hardmin, &hardmax); *softmin= MAX2(iprop->softmin, hardmin); @@ -699,6 +766,22 @@ void RNA_property_float_range(PointerRNA *ptr, PropertyRNA *prop, float *hardmin { FloatPropertyRNA *fprop= (FloatPropertyRNA*)rna_ensure_property(prop); + if(prop->magic != RNA_MAGIC) { + /* attempt to get the local ID values */ + IDProperty *idp_ui= rna_idproperty_ui(prop); + IDProperty *item; + + if(idp_ui) { /* TODO, type checking on ID props */ + item= IDP_GetPropertyFromGroup(idp_ui, "min"); + *hardmin= item ? *(double*)&item->data.val : FLT_MIN; + + item= IDP_GetPropertyFromGroup(idp_ui, "max"); + *hardmax= item ? *(double*)&item->data.val : FLT_MAX; + + return; + } + } + if(fprop->range) { fprop->range(ptr, hardmin, hardmax); } @@ -713,6 +796,28 @@ void RNA_property_float_ui_range(PointerRNA *ptr, PropertyRNA *prop, float *soft FloatPropertyRNA *fprop= (FloatPropertyRNA*)rna_ensure_property(prop); float hardmin, hardmax; + if(prop->magic != RNA_MAGIC) { + /* attempt to get the local ID values */ + IDProperty *idp_ui= rna_idproperty_ui(prop); + IDProperty *item; + + if(idp_ui) { /* TODO, type checking on ID props */ + item= IDP_GetPropertyFromGroup(idp_ui, "soft_min"); + *softmin= item ? *(double*)&item->data.val : FLT_MIN; + + item= IDP_GetPropertyFromGroup(idp_ui, "soft_max"); + *softmax= item ? *(double*)&item->data.val : FLT_MAX; + + item= IDP_GetPropertyFromGroup(idp_ui, "step"); + *step= item ? *(double*)&item->data.val : 1.0f; + + item= IDP_GetPropertyFromGroup(idp_ui, "precision"); + *precision= item ? *(double*)&item->data.val : 3.0f; + + return; + } + } + if(fprop->range) { fprop->range(ptr, &hardmin, &hardmax); *softmin= MAX2(fprop->softmin, hardmin); |