diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-09-26 09:08:45 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-09-26 09:31:31 +0300 |
commit | c47be43674f525c568f52afc900963875e742678 (patch) | |
tree | 3ae1bf27d07aebc0361fc2f167d2cad8ccef675e | |
parent | bb8023ff7f1a2b27dca92c8f8d147768b2206da0 (diff) |
Gizmo: add invoke_prepare callback
Allows gizmo groups to set values based on the gizmo about to be invoked.
5 files changed, 38 insertions, 0 deletions
diff --git a/source/blender/makesrna/intern/rna_wm_gizmo.c b/source/blender/makesrna/intern/rna_wm_gizmo.c index 358549fecd2..ac579851944 100644 --- a/source/blender/makesrna/intern/rna_wm_gizmo.c +++ b/source/blender/makesrna/intern/rna_wm_gizmo.c @@ -719,6 +719,25 @@ static void rna_gizmogroup_draw_prepare_cb(const bContext *C, wmGizmoGroup *gzgr RNA_parameter_list_free(&list); } +static void rna_gizmogroup_invoke_prepare_cb(const bContext *C, wmGizmoGroup *gzgroup, wmGizmo *gz) +{ + extern FunctionRNA rna_GizmoGroup_invoke_prepare_func; + + PointerRNA gzgroup_ptr; + ParameterList list; + FunctionRNA *func; + + RNA_pointer_create(NULL, gzgroup->type->ext.srna, gzgroup, &gzgroup_ptr); + func = &rna_GizmoGroup_invoke_prepare_func; /* RNA_struct_find_function(&wgroupr, "invoke_prepare"); */ + + RNA_parameter_list_create(&list, &gzgroup_ptr, func); + RNA_parameter_set_lookup(&list, "context", &C); + RNA_parameter_set_lookup(&list, "gizmo", &gz); + gzgroup->type->ext.call((bContext *)C, &gzgroup_ptr, func, &list); + + RNA_parameter_list_free(&list); +} + void BPY_RNA_gizmogroup_wrapper(wmGizmoGroupType *gzgt, void *userdata); static void rna_GizmoGroup_unregister(struct Main *bmain, StructRNA *type); @@ -808,6 +827,7 @@ static StructRNA *rna_GizmoGroup_register( dummywgt.setup = (have_function[2]) ? rna_gizmogroup_setup_cb : NULL; dummywgt.refresh = (have_function[3]) ? rna_gizmogroup_refresh_cb : NULL; dummywgt.draw_prepare = (have_function[4]) ? rna_gizmogroup_draw_prepare_cb : NULL; + dummywgt.invoke_prepare = (have_function[5]) ? rna_gizmogroup_invoke_prepare_cb : NULL; wmGizmoGroupType *gzgt = WM_gizmogrouptype_append_ptr( BPY_RNA_gizmogroup_wrapper, (void *)&dummywgt); @@ -1304,6 +1324,14 @@ static void rna_def_gizmogroup(BlenderRNA *brna) parm = RNA_def_pointer(func, "context", "Context", "", ""); RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED); + func = RNA_def_function(srna, "invoke_prepare", NULL); + RNA_def_function_ui_description(func, "Run before invoke"); + RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL); + parm = RNA_def_pointer(func, "context", "Context", "", ""); + RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED); + parm = RNA_def_pointer(func, "gizmo", "Gizmo", "", ""); + RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED); + /* -------------------------------------------------------------------- */ /* Instance Variables */ diff --git a/source/blender/windowmanager/gizmo/WM_gizmo_types.h b/source/blender/windowmanager/gizmo/WM_gizmo_types.h index f67a0d05bee..dc3e77eb130 100644 --- a/source/blender/windowmanager/gizmo/WM_gizmo_types.h +++ b/source/blender/windowmanager/gizmo/WM_gizmo_types.h @@ -372,6 +372,8 @@ typedef struct wmGizmoGroupType { wmGizmoGroupFnRefresh refresh; /* refresh data for drawing, called before each redraw */ wmGizmoGroupFnDrawPrepare draw_prepare; + /* Initialize data for before invoke. */ + wmGizmoGroupFnInvokePrepare invoke_prepare; /* Keymap init callback for this gizmo-group (optional), * will fall back to default tweak keymap when left NULL. */ diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c b/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c index 221d8df6c2b..f4cb40b0b94 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c @@ -381,6 +381,9 @@ static bool gizmo_tweak_start_and_finish( } } else { + if (gz->parent_gzgroup->type->invoke_prepare) { + gz->parent_gzgroup->type->invoke_prepare(C, gz->parent_gzgroup, gz); + } /* Allow for 'button' gizmos, single click to run an action. */ WM_operator_name_call_ptr(C, mpop->type, WM_OP_INVOKE_DEFAULT, &mpop->ptr); } diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c b/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c index c6d6a5cd48c..2c52b06a32a 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c @@ -948,6 +948,9 @@ void wm_gizmomap_modal_set( if (gz->type->invoke && (gz->type->modal || gz->custom_modal)) { + if (gz->parent_gzgroup->type->invoke_prepare) { + gz->parent_gzgroup->type->invoke_prepare(C, gz->parent_gzgroup, gz); + } const int retval = gz->type->invoke(C, gz, event); if ((retval & OPERATOR_RUNNING_MODAL) == 0) { return; diff --git a/source/blender/windowmanager/gizmo/wm_gizmo_fn.h b/source/blender/windowmanager/gizmo/wm_gizmo_fn.h index 88065a0fcd5..3361932c6e3 100644 --- a/source/blender/windowmanager/gizmo/wm_gizmo_fn.h +++ b/source/blender/windowmanager/gizmo/wm_gizmo_fn.h @@ -39,6 +39,8 @@ typedef void (*wmGizmoGroupFnRefresh)( const struct bContext *, struct wmGizmoGroup *); typedef void (*wmGizmoGroupFnDrawPrepare)( const struct bContext *, struct wmGizmoGroup *); +typedef void (*wmGizmoGroupFnInvokePrepare)( + const struct bContext *, struct wmGizmoGroup *, struct wmGizmo *); typedef struct wmKeyMap *(*wmGizmoGroupFnSetupKeymap)( const struct wmGizmoGroupType *, struct wmKeyConfig *) ATTR_WARN_UNUSED_RESULT; |