Fix tweak/drag event use with gizmos

It was possible to use a drag event for a gizmo
that dragged away from the gizmo, changing the active gizmo.

Now use gizmo located at the location that was clicked on.
This commit is contained in:
Campbell Barton 2019-05-28 01:19:02 +10:00
parent 58ce4061a8
commit dee7edffcf
4 changed files with 34 additions and 7 deletions

View File

@ -174,12 +174,12 @@ int WM_gizmo_cmp_temp_fl_reverse(const void *gz_a_ptr, const void *gz_b_ptr)
wmGizmo *wm_gizmogroup_find_intersected_gizmo(const wmGizmoGroup *gzgroup,
bContext *C,
const wmEvent *event,
const int mval[2],
int *r_part)
{
for (wmGizmo *gz = gzgroup->gizmos.first; gz; gz = gz->next) {
if (gz->type->test_select && (gz->flag & (WM_GIZMO_HIDDEN | WM_GIZMO_HIDDEN_SELECT)) == 0) {
if ((*r_part = gz->type->test_select(C, gz, event->mval)) != -1) {
if ((*r_part = gz->type->test_select(C, gz, mval)) != -1) {
return gz;
}
}

View File

@ -63,7 +63,7 @@ void wm_gizmogroup_free(bContext *C, struct wmGizmoGroup *gzgroup);
void wm_gizmogroup_gizmo_register(struct wmGizmoGroup *gzgroup, struct wmGizmo *gz);
struct wmGizmo *wm_gizmogroup_find_intersected_gizmo(const struct wmGizmoGroup *gzgroup,
struct bContext *C,
const struct wmEvent *event,
const int mval[2],
int *r_part);
void wm_gizmogroup_intersectable_gizmos_to_list(const struct wmGizmoGroup *gzgroup,
struct BLI_Buffer *visible_gizmos);

View File

@ -683,6 +683,15 @@ wmGizmo *wm_gizmomap_highlight_find(wmGizmoMap *gzmap,
BLI_buffer_declare_static(wmGizmo *, visible_3d_gizmos, BLI_BUFFER_NOP, 128);
bool do_step[WM_GIZMOMAP_DRAWSTEP_MAX];
int mval[2] = {UNPACK2(event->mval)};
/* Ensure for drag events we use the location where the user clicked.
* Without this click-dragging on a gizmo can accidentally act on the wrong gizmo. */
if (ISTWEAK(event->type) || (event->val == KM_CLICK_DRAG)) {
mval[0] += event->x - event->prevclickx;
mval[1] += event->y - event->prevclicky;
}
for (int i = 0; i < ARRAY_SIZE(do_step); i++) {
do_step[i] = WM_gizmo_context_check_drawstep(C, i);
}
@ -715,7 +724,7 @@ wmGizmo *wm_gizmomap_highlight_find(wmGizmoMap *gzmap,
wm_gizmogroup_intersectable_gizmos_to_list(gzgroup, &visible_3d_gizmos);
}
else if (step == WM_GIZMOMAP_DRAWSTEP_2D) {
if ((gz = wm_gizmogroup_find_intersected_gizmo(gzgroup, C, event, r_part))) {
if ((gz = wm_gizmogroup_find_intersected_gizmo(gzgroup, C, mval, r_part))) {
break;
}
}
@ -727,7 +736,7 @@ wmGizmo *wm_gizmomap_highlight_find(wmGizmoMap *gzmap,
/* 2D gizmos get priority. */
if (gz == NULL) {
gz = gizmo_find_intersected_3d(
C, event->mval, visible_3d_gizmos.data, visible_3d_gizmos.count, r_part);
C, mval, visible_3d_gizmos.data, visible_3d_gizmos.count, r_part);
}
}
BLI_buffer_free(&visible_3d_gizmos);

View File

@ -2721,8 +2721,25 @@ static int wm_handlers_do_intern(bContext *C, wmEvent *event, ListBase *handlers
wm_gizmomap_handler_context_gizmo(C, handler);
wm_region_mouse_co(C, event);
/* Drag events use the previous click location to highlight the gizmos,
* Get the highlight again in case the user dragged off the gizmo. */
const bool is_event_drag = ISTWEAK(event->type) || (event->val == KM_CLICK_DRAG);
bool handle_highlight = false;
bool handle_keymap = false;
/* handle gizmo highlighting */
if (event->type == MOUSEMOVE && !wm_gizmomap_modal_get(gzmap)) {
if (!wm_gizmomap_modal_get(gzmap) && ((event->type == MOUSEMOVE) || is_event_drag)) {
handle_highlight = true;
if (is_event_drag) {
handle_keymap = true;
}
}
else {
handle_keymap = true;
}
if (handle_highlight) {
int part;
gz = wm_gizmomap_highlight_find(gzmap, C, event, &part);
if (wm_gizmomap_highlight_set(gzmap, C, gz, part) && gz != NULL) {
@ -2731,7 +2748,8 @@ static int wm_handlers_do_intern(bContext *C, wmEvent *event, ListBase *handlers
}
}
}
else {
if (handle_keymap) {
/* Handle highlight gizmo. */
if (gz != NULL) {
wmGizmoGroup *gzgroup = gz->parent_gzgroup;