diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-05-27 18:19:02 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-05-27 18:36:31 +0300 |
commit | dee7edffcf2a6c4a1ce35ab5d5ab35873d113c0f (patch) | |
tree | fc6337dd9314eb8d5d24b3a5cf4cfa2a37b5d306 /source/blender/windowmanager | |
parent | 58ce4061a83d03d601c3713d8df11252d182db07 (diff) |
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.
Diffstat (limited to 'source/blender/windowmanager')
4 files changed, 34 insertions, 7 deletions
diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c b/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c index ded308f4b7b..03e8717012c 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c @@ -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; } } diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_intern.h b/source/blender/windowmanager/gizmo/intern/wm_gizmo_intern.h index 3a4f303fda8..9874b0e12af 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_intern.h +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_intern.h @@ -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); diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c b/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c index 9c18406b84d..56de2202731 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c @@ -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); diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 07d5f4b0d59..70044e059c8 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -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; |