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:
authorAlexander Gavrilov <angavrilov@gmail.com>2018-12-15 22:37:12 +0300
committerAlexander Gavrilov <angavrilov@gmail.com>2018-12-19 14:20:35 +0300
commit61c941f040d367d18fcaa57c9e8e0c2078193d97 (patch)
tree9cf843e4f19fffda991afb77595ec4d287a0b142 /source/blender/editors/interface/interface_ops.c
parent908a2742403b279cd6dfa5c27acb76d68d3f1523 (diff)
RNA: support setting default values for custom properties.
NLA requires a usable default value for all properties that are to be animated via it, without any exceptions. This is the real cause of T36496: using the default of 0 for a scale related custom property obviously doesn't work. Thus, to really fix this it is necessary to support configurable default values for custom properties, which are very frequently used in rigs for auxiliary settings. For common use it is enough to support this for scalar float and integer properties. The default can be set via the custom property configuration popup, or a right click menu option. In addition, to help in updating old rigs, an operator that saves current values as defaults for all object and bone properties is added. Reviewers: campbellbarton, brecht Differential Revision: https://developer.blender.org/D4084
Diffstat (limited to 'source/blender/editors/interface/interface_ops.c')
-rw-r--r--source/blender/editors/interface/interface_ops.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c
index b4b59cae75b..1cb9f156eeb 100644
--- a/source/blender/editors/interface/interface_ops.c
+++ b/source/blender/editors/interface/interface_ops.c
@@ -301,6 +301,58 @@ static void UI_OT_reset_default_button(wmOperatorType *ot)
RNA_def_boolean(ot->srna, "all", 1, "All", "Reset to default values all elements of the array");
}
+/* Assign Value as Default Button Operator ------------------------ */
+
+static bool assign_default_button_poll(bContext *C)
+{
+ PointerRNA ptr;
+ PropertyRNA *prop;
+ int index;
+
+ UI_context_active_but_prop_get(C, &ptr, &prop, &index);
+
+ if (ptr.data && prop && RNA_property_editable(&ptr, prop)) {
+ PropertyType type = RNA_property_type(prop);
+
+ return RNA_property_is_idprop(prop) && !RNA_property_array_check(prop) && ELEM(type, PROP_INT, PROP_FLOAT);
+ }
+
+ return false;
+}
+
+static int assign_default_button_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ PointerRNA ptr;
+ PropertyRNA *prop;
+ int index;
+
+ /* try to reset the nominated setting to its default value */
+ UI_context_active_but_prop_get(C, &ptr, &prop, &index);
+
+ /* if there is a valid property that is editable... */
+ if (ptr.data && prop && RNA_property_editable(&ptr, prop)) {
+ if (RNA_property_assign_default(&ptr, prop))
+ return operator_button_property_finish(C, &ptr, prop);
+ }
+
+ return OPERATOR_CANCELLED;
+}
+
+static void UI_OT_assign_default_button(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Assign Value as Default";
+ ot->idname = "UI_OT_assign_default_button";
+ ot->description = "Set this property's current value as the new default";
+
+ /* callbacks */
+ ot->poll = assign_default_button_poll;
+ ot->exec = assign_default_button_exec;
+
+ /* flags */
+ ot->flag = OPTYPE_UNDO;
+}
+
/* Unset Property Button Operator ------------------------ */
static int unset_property_button_exec(bContext *C, wmOperator *UNUSED(op))
@@ -1557,6 +1609,7 @@ void ED_operatortypes_ui(void)
WM_operatortype_append(UI_OT_copy_data_path_button);
WM_operatortype_append(UI_OT_copy_python_command_button);
WM_operatortype_append(UI_OT_reset_default_button);
+ WM_operatortype_append(UI_OT_assign_default_button);
WM_operatortype_append(UI_OT_unset_property_button);
WM_operatortype_append(UI_OT_override_type_set_button);
WM_operatortype_append(UI_OT_override_remove_button);