Gizmo: add support for gizmos to initialize from the active tool
authorCampbell Barton <ideasman42@gmail.com>
Wed, 23 Jan 2019 05:14:52 +0000 (16:14 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 23 Jan 2019 05:14:52 +0000 (16:14 +1100)
source/blender/windowmanager/gizmo/WM_gizmo_api.h
source/blender/windowmanager/gizmo/WM_gizmo_types.h
source/blender/windowmanager/gizmo/intern/wm_gizmo.c
source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c
source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c

index 667646c..2a4f6b3 100644 (file)
@@ -83,6 +83,8 @@ struct wmGizmoOpElem *WM_gizmo_operator_get(
 struct PointerRNA *WM_gizmo_operator_set(
         struct wmGizmo *gz, int part_index,
         struct wmOperatorType *ot, struct IDProperty *properties);
+int WM_gizmo_operator_invoke(
+        struct bContext *C, struct wmGizmo *gz, struct wmGizmoOpElem *gzop);
 
 /* callbacks */
 void WM_gizmo_set_fn_custom_modal(struct wmGizmo *gz, wmGizmoFnModal fn);
index c92172d..ee574d2 100644 (file)
@@ -87,6 +87,9 @@ typedef enum eWM_GizmoFlag {
        WM_GIZMO_MOVE_CURSOR = (1 << 7),
        /** Don't write into the depth buffer when selecting. */
        WM_GIZMO_SELECT_BACKGROUND  = (1 << 8),
+
+       /** Use the active tools operator properties when running as an operator. */
+       WM_GIZMO_OPERATOR_TOOL_INIT  = (1 << 9),
 } eWM_GizmoFlag;
 
 /**
index 0bef33a..0058681 100644 (file)
@@ -48,6 +48,7 @@
 #include "BKE_idprop.h"
 
 #include "WM_api.h"
+#include "WM_toolsystem.h"
 #include "WM_types.h"
 
 #include "ED_screen.h"
@@ -271,6 +272,23 @@ PointerRNA *WM_gizmo_operator_set(
        return &gzop->ptr;
 }
 
+int WM_gizmo_operator_invoke(bContext *C, wmGizmo *gz, wmGizmoOpElem *gzop)
+{
+       if (gz->flag & WM_GIZMO_OPERATOR_TOOL_INIT) {
+               /* Merge toolsettings into the gizmo properties. */
+               PointerRNA tref_ptr;
+               bToolRef *tref = WM_toolsystem_ref_from_context(C);
+               if (tref && WM_toolsystem_ref_properties_get_from_operator(tref, gzop->type, &tref_ptr)) {
+                       if (gzop->ptr.data == NULL) {
+                               IDPropertyTemplate val = {0};
+                               gzop->ptr.data = IDP_New(IDP_GROUP, &val, "wmOperatorProperties");
+                       }
+                       IDP_MergeGroup(gzop->ptr.data, tref_ptr.data, false);
+               }
+       }
+       return WM_operator_name_call_ptr(C, gzop->type, WM_OP_INVOKE_DEFAULT, &gzop->ptr);
+}
+
 static void wm_gizmo_set_matrix_rotation_from_z_axis__internal(
         float matrix[4][4], const float z_axis[3])
 {
index 89df826..8483b25 100644 (file)
@@ -404,7 +404,7 @@ static bool gizmo_tweak_start_and_finish(
                                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, gzop->type, WM_OP_INVOKE_DEFAULT, &gzop->ptr);
+                       WM_gizmo_operator_invoke(C, gz, gzop);
                }
                return true;
        }
index 68c7364..2635515 100644 (file)
@@ -971,7 +971,7 @@ void wm_gizmomap_modal_set(
 
                struct wmGizmoOpElem *gzop = WM_gizmo_operator_get(gz, gz->highlight_part);
                if (gzop && gzop->type) {
-                       const int retval = WM_operator_name_call_ptr(C, gzop->type, WM_OP_INVOKE_DEFAULT, &gzop->ptr);
+                       const int retval = WM_gizmo_operator_invoke(C, gz, gzop);
                        if ((retval & OPERATOR_RUNNING_MODAL) == 0) {
                                wm_gizmomap_modal_set(gzmap, C, gz, event, false);
                        }