diff options
author | Campbell Barton <ideasman42@gmail.com> | 2008-12-02 17:36:35 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2008-12-02 17:36:35 +0300 |
commit | 9f27be3b2dcf4cd9abfacaca0871340811586664 (patch) | |
tree | 373df23dcf530e9840f4ba0cf1dbc6e1c4ca7c09 /source/blender/makesrna | |
parent | 54908979c54ab332156f438e995d5dce8ee8420c (diff) |
Added RNA functions from PyRNA
* RNA_property_enum_value
* RNA_property_enum_identifier
To get an enum string from a value and a value from an enum.
BPy_StructRNA types (objects, meshes, images etc) can now be used as dictionary keys.
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r-- | source/blender/makesrna/RNA_access.h | 3 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 35 |
2 files changed, 38 insertions, 0 deletions
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index 3b685792d33..8c296dce5f2 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -174,6 +174,9 @@ void RNA_property_float_ui_range(PointerRNA *ptr, PropertyRNA *prop, float *soft int RNA_property_string_maxlength(PointerRNA *ptr, PropertyRNA *prop); void RNA_property_enum_items(PointerRNA *ptr, PropertyRNA *prop, const EnumPropertyItem **item, int *totitem); +int RNA_property_enum_value(PointerRNA *ptr, PropertyRNA *prop, const char *identifier, int *value); +int RNA_property_enum_identifier(PointerRNA *ptr, PropertyRNA *prop, const int value, const char **identifier); + const char *RNA_property_ui_name(PointerRNA *ptr, PropertyRNA *prop); const char *RNA_property_ui_description(PointerRNA *ptr, PropertyRNA *prop); diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 9f07d2a3311..2c9cb9f4dfa 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -401,6 +401,40 @@ void RNA_property_enum_items(PointerRNA *ptr, PropertyRNA *prop, const EnumPrope *totitem= eprop->totitem; } +int RNA_property_enum_value(PointerRNA *ptr, PropertyRNA *prop, const char *identifier, int *value) +{ + const EnumPropertyItem *item; + int totitem, i; + + RNA_property_enum_items(ptr, prop, &item, &totitem); + + for (i=0; i<totitem; i++) { + if (strcmp(item[i].identifier, identifier)==0) { + *value = item[i].value; + return 1; + } + } + + return 0; +} + +int RNA_property_enum_identifier(PointerRNA *ptr, PropertyRNA *prop, const int value, const char **identifier) +{ + const EnumPropertyItem *item; + int totitem, i; + + RNA_property_enum_items(ptr, prop, &item, &totitem); + + for (i=0; i<totitem; i++) { + if (item[i].value==value) { + *identifier = item[i].identifier; + return 1; + } + } + + return 0; +} + const char *RNA_property_ui_name(PointerRNA *ptr, PropertyRNA *prop) { PropertyRNA *oldprop= prop; @@ -764,6 +798,7 @@ int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop) return eprop->defaultvalue; } + void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value) { EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop; |