Gizmo: changes to internal drag logic

Minor changes to recent gizmo click/drag logic 08dff7b40b

Changing the gizmos highlighted part in the invoke_prepare
callback is too error prone since it needs to run
before it's known which operator will execute.

Add back 'drag_part', since it simplifies click-drag use.
While this isn't essential with custom keymaps per gizmo
it avoids having to define a keymap in the case a drag
event needs a different action.
This commit is contained in:
2019-05-28 13:26:50 +10:00
parent 219e6a98c6
commit 2e22cfd08a
6 changed files with 36 additions and 38 deletions

View File

@@ -883,25 +883,19 @@ static uiTooltipData *ui_tooltip_data_from_gizmo(bContext *C, wmGizmo *gz)
/* Operator Actions */
{
const bool use_drag = gz->drag_part != -1 && gz->highlight_part != gz->drag_part;
const struct {
int part;
const char *prefix;
} gzop_actions[] = {
#if 0
{
.part = gz->highlight_part,
.prefix = use_drag ? CTX_TIP_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Click") : NULL,
},
{
.part = use_drag ? gz->drag_part : -1,
.prefix = use_drag ? CTX_TIP_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Drag") : NULL,
},
#else
{
.part = gz->highlight_part,
.prefix = NULL,
},
#endif
{
.part = gz->highlight_part,
.prefix = use_drag ? CTX_TIP_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Click") : NULL,
},
{
.part = use_drag ? gz->drag_part : -1,
.prefix = use_drag ? CTX_TIP_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Drag") : NULL,
},
};
for (int i = 0; i < ARRAY_SIZE(gzop_actions); i++) {

View File

@@ -225,33 +225,17 @@ static void WIDGETGROUP_navigate_setup(const bContext *C, wmGizmoGroup *gzgroup)
PointerRNA *ptr = WM_gizmo_operator_set(gz, part_index + 1, ot_view_axis, NULL);
RNA_enum_set(ptr, "type", mapping[part_index]);
}
}
{
/* When dragging an axis, use this instead. */
wmWindowManager *wm = CTX_wm_manager(C);
wmGizmo *gz = navgroup->gz_array[GZ_INDEX_ROTATE];
gz->keymap = WM_keymap_ensure(
wm->defaultconf, "Generic Gizmos Click Drag", SPACE_EMPTY, RGN_TYPE_WINDOW);
gz->drag_part = 0;
}
gzgroup->customdata = navgroup;
}
static void WIDGETGROUP_navigate_invoke_prepare(const bContext *UNUSED(C),
wmGizmoGroup *gzgroup,
wmGizmo *gz,
const wmEvent *event)
{
struct NavigateWidgetGroup *navgroup = gzgroup->customdata;
wmGizmo *gz_rotate = navgroup->gz_array[GZ_INDEX_ROTATE];
if (gz_rotate == gz) {
if (ISTWEAK(event->type)) {
/* When dragging an axis, use this instead. */
gz->highlight_part = 0;
}
}
}
static void WIDGETGROUP_navigate_draw_prepare(const bContext *C, wmGizmoGroup *gzgroup)
{
struct NavigateWidgetGroup *navgroup = gzgroup->customdata;
@@ -345,7 +329,6 @@ void VIEW3D_GGT_navigate(wmGizmoGroupType *gzgt)
gzgt->poll = WIDGETGROUP_navigate_poll;
gzgt->setup = WIDGETGROUP_navigate_setup;
gzgt->invoke_prepare = WIDGETGROUP_navigate_invoke_prepare;
gzgt->draw_prepare = WIDGETGROUP_navigate_draw_prepare;
}