diff options
author | Lukas Toenne <lukas.toenne@googlemail.com> | 2013-01-05 18:56:37 +0400 |
---|---|---|
committer | Lukas Toenne <lukas.toenne@googlemail.com> | 2013-01-05 18:56:37 +0400 |
commit | e8b415bdb4ba282e3574cad1463bf2512fe5eb8f (patch) | |
tree | 42d45b749f9442393ef08e41a1c98bc3e4978872 /source/blender/makesrna/intern/rna_define.c | |
parent | 5ee3cd6c86391e78a6905d1aa9c5241f623dcfc1 (diff) |
This patch adds support in bpy.props for getter/setter callback functions. We already have update callbacks, but generic get/set functions can come in handy in some cases where the functionality is too complex to use a single value.
The current C callback functions are too simple allow a straightforward implementation, in particular they don't receive the PropertyRNA pointer itself as an argument, which means the callback cannot directly access the PropertyRNA's py_data pointers which store the python function objects. For this reason a second runtime variant of these callbacks has been added. It is only used for runtime callbacks and not in makesrna, but otherwise works the same way.
Diffstat (limited to 'source/blender/makesrna/intern/rna_define.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_define.c | 144 |
1 files changed, 138 insertions, 6 deletions
diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c index 727b1e44931..0a8254cb9c1 100644 --- a/source/blender/makesrna/intern/rna_define.c +++ b/source/blender/makesrna/intern/rna_define.c @@ -2017,6 +2017,38 @@ void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const ch } } +void RNA_def_property_boolean_funcs_runtime(PropertyRNA *prop, BooleanPropertyGetFunc getfunc, BooleanPropertySetFunc setfunc) +{ + BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop; + + if (getfunc) bprop->get_ex = getfunc; + if (setfunc) bprop->set_ex = setfunc; + + if (getfunc || setfunc) { + /* don't save in id properties */ + prop->flag &= ~PROP_IDPROPERTY; + + if (!setfunc) + prop->flag &= ~PROP_EDITABLE; + } +} + +void RNA_def_property_boolean_array_funcs_runtime(PropertyRNA *prop, BooleanArrayPropertyGetFunc getfunc, BooleanArrayPropertySetFunc setfunc) +{ + BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop; + + if (getfunc) bprop->getarray_ex = getfunc; + if (setfunc) bprop->setarray_ex = setfunc; + + if (getfunc || setfunc) { + /* don't save in id properties */ + prop->flag &= ~PROP_IDPROPERTY; + + if (!setfunc) + prop->flag &= ~PROP_EDITABLE; + } +} + void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range) { StructRNA *srna = DefRNA.laststruct; @@ -2049,6 +2081,38 @@ void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char * } } +void RNA_def_property_int_funcs_runtime(PropertyRNA *prop, IntPropertyGetFunc getfunc, IntPropertySetFunc setfunc, IntPropertyRangeFunc rangefunc) +{ + IntPropertyRNA *iprop = (IntPropertyRNA *)prop; + + if (getfunc) iprop->get_ex = getfunc; + if (setfunc) iprop->set_ex = setfunc; + + if (getfunc || setfunc) { + /* don't save in id properties */ + prop->flag &= ~PROP_IDPROPERTY; + + if (!setfunc) + prop->flag &= ~PROP_EDITABLE; + } +} + +void RNA_def_property_int_array_funcs_runtime(PropertyRNA *prop, IntArrayPropertyGetFunc getfunc, IntArrayPropertySetFunc setfunc, IntPropertyRangeFunc rangefunc) +{ + IntPropertyRNA *iprop = (IntPropertyRNA *)prop; + + if (getfunc) iprop->getarray_ex = getfunc; + if (setfunc) iprop->setarray_ex = setfunc; + + if (getfunc || setfunc) { + /* don't save in id properties */ + prop->flag &= ~PROP_IDPROPERTY; + + if (!setfunc) + prop->flag &= ~PROP_EDITABLE; + } +} + void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range) { StructRNA *srna = DefRNA.laststruct; @@ -2081,6 +2145,40 @@ void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char } } +void RNA_def_property_float_funcs_runtime(PropertyRNA *prop, FloatPropertyGetFunc getfunc, FloatPropertySetFunc setfunc, FloatPropertyRangeFunc rangefunc) +{ + FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop; + + if (getfunc) fprop->get_ex = getfunc; + if (setfunc) fprop->set_ex = setfunc; + if (rangefunc) fprop->range_ex = rangefunc; + + if (getfunc || setfunc) { + /* don't save in id properties */ + prop->flag &= ~PROP_IDPROPERTY; + + if (!setfunc) + prop->flag &= ~PROP_EDITABLE; + } +} + +void RNA_def_property_float_array_funcs_runtime(PropertyRNA *prop, FloatArrayPropertyGetFunc getfunc, FloatArrayPropertySetFunc setfunc, FloatPropertyRangeFunc rangefunc) +{ + FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop; + + if (getfunc) fprop->getarray_ex = getfunc; + if (setfunc) fprop->setarray_ex = setfunc; + if (rangefunc) fprop->range_ex = rangefunc; + + if (getfunc || setfunc) { + /* don't save in id properties */ + prop->flag &= ~PROP_IDPROPERTY; + + if (!setfunc) + prop->flag &= ~PROP_EDITABLE; + } +} + void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char *set, const char *item) { StructRNA *srna = DefRNA.laststruct; @@ -2107,6 +2205,29 @@ void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char } } +void RNA_def_property_enum_funcs_runtime(PropertyRNA *prop, EnumPropertyGetFunc getfunc, EnumPropertySetFunc setfunc, EnumPropertyItemFunc itemfunc) +{ + EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop; + + if (getfunc) eprop->get_ex = getfunc; + if (setfunc) eprop->set_ex = setfunc; + if (itemfunc) eprop->itemf = itemfunc; + + if (getfunc || setfunc) { + /* don't save in id properties */ + prop->flag &= ~PROP_IDPROPERTY; + + if (!setfunc) + prop->flag &= ~PROP_EDITABLE; + } +} + +void RNA_def_property_enum_py_data(PropertyRNA *prop, void *py_data) +{ + EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop; + eprop->py_data = py_data; +} + void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const char *length, const char *set) { StructRNA *srna = DefRNA.laststruct; @@ -2133,6 +2254,23 @@ void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const cha } } +void RNA_def_property_string_funcs_runtime(PropertyRNA *prop, StringPropertyGetFunc getfunc, StringPropertyLengthFunc lengthfunc, StringPropertySetFunc setfunc) +{ + StringPropertyRNA *sprop = (StringPropertyRNA *)prop; + + if (getfunc) sprop->get_ex = getfunc; + if (lengthfunc) sprop->length_ex = lengthfunc; + if (setfunc) sprop->set_ex = setfunc; + + if (getfunc || setfunc) { + /* don't save in id properties */ + prop->flag &= ~PROP_IDPROPERTY; + + if (!setfunc) + prop->flag &= ~PROP_EDITABLE; + } +} + void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *set, const char *typef, const char *poll) { @@ -2447,12 +2585,6 @@ void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc) eprop->itemf = itemfunc; } -void RNA_def_enum_py_data(PropertyRNA *prop, void *py_data) -{ - EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop; - eprop->py_data = py_data; -} - PropertyRNA *RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, float default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax) |