Gizmo: add support for gizmos to initialize from the active tool

This commit is contained in:
Campbell Barton
2019-01-23 16:14:52 +11:00
parent 7ce38978ae
commit be24da0a98
5 changed files with 25 additions and 2 deletions

View 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);

View 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;
/**

View 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])
{

View 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;
}

View 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);
}