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:
@@ -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++) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -199,6 +199,12 @@ struct wmGizmo {
|
||||
* -1 when unset, otherwise a valid index. (Used as index to 'op_data'). */
|
||||
int highlight_part;
|
||||
|
||||
/**
|
||||
* For gizmos that differentiate between click & drag,
|
||||
* use a different part for any drag events, -1 when unused.
|
||||
*/
|
||||
int drag_part;
|
||||
|
||||
/** Distance to bias this gizmo above others when picking
|
||||
* (in worldspace, scaled by the gizmo scale - when used). */
|
||||
float select_bias;
|
||||
|
||||
@@ -90,6 +90,8 @@ static wmGizmo *wm_gizmo_create(const wmGizmoType *gzt, PointerRNA *properties)
|
||||
unit_m4(gz->matrix_basis);
|
||||
unit_m4(gz->matrix_offset);
|
||||
|
||||
gz->drag_part = -1;
|
||||
|
||||
return gz;
|
||||
}
|
||||
|
||||
|
||||
@@ -360,10 +360,6 @@ static bool gizmo_tweak_start(bContext *C, wmGizmoMap *gzmap, wmGizmo *gz, const
|
||||
static bool gizmo_tweak_start_and_finish(
|
||||
bContext *C, wmGizmoMap *gzmap, wmGizmo *gz, const wmEvent *event, bool *r_is_modal)
|
||||
{
|
||||
if (gz->parent_gzgroup->type->invoke_prepare) {
|
||||
gz->parent_gzgroup->type->invoke_prepare(C, gz->parent_gzgroup, gz, event);
|
||||
}
|
||||
|
||||
wmGizmoOpElem *gzop = WM_gizmo_operator_get(gz, gz->highlight_part);
|
||||
if (r_is_modal) {
|
||||
*r_is_modal = false;
|
||||
@@ -394,6 +390,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, event);
|
||||
}
|
||||
/* Allow for 'button' gizmos, single click to run an action. */
|
||||
WM_gizmo_operator_invoke(C, gz, gzop);
|
||||
}
|
||||
@@ -502,12 +501,21 @@ static int gizmo_tweak_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH);
|
||||
}
|
||||
|
||||
const int highlight_part_init = gz->highlight_part;
|
||||
|
||||
if (gz->drag_part != -1) {
|
||||
if (ISTWEAK(event->type) || (event->val == KM_CLICK_DRAG)) {
|
||||
gz->highlight_part = gz->drag_part;
|
||||
}
|
||||
}
|
||||
|
||||
if (gizmo_tweak_start_and_finish(C, gzmap, gz, event, NULL)) {
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
if (!gizmo_tweak_start(C, gzmap, gz, event)) {
|
||||
/* failed to start */
|
||||
gz->highlight_part = highlight_part_init;
|
||||
return OPERATOR_PASS_THROUGH;
|
||||
}
|
||||
|
||||
|
||||
@@ -1017,6 +1017,11 @@ void wm_gizmomap_modal_set(
|
||||
|
||||
WM_tooltip_clear(C, win);
|
||||
|
||||
/* Use even if we don't have invoke, so we can setup data before an operator runs. */
|
||||
if (gz->parent_gzgroup->type->invoke_prepare) {
|
||||
gz->parent_gzgroup->type->invoke_prepare(C, gz->parent_gzgroup, gz, event);
|
||||
}
|
||||
|
||||
if (gz->type->invoke && (gz->type->modal || gz->custom_modal)) {
|
||||
const int retval = gz->type->invoke(C, gz, event);
|
||||
if ((retval & OPERATOR_RUNNING_MODAL) == 0) {
|
||||
|
||||
Reference in New Issue
Block a user