diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-04-23 09:43:50 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-04-23 09:51:00 +0300 |
commit | be3adb51de21652d64a6839cd5614c5096064c6a (patch) | |
tree | b76f6346673205ed3aeb33a4768bd2a182a4c605 /source/blender/editors/interface | |
parent | 310f288bb03b4197f54b7d7b6d611669f2604d04 (diff) |
UI: ignore events in empty region overlap areas
- Resizable areas use 2D view bounds.
- Header uses the button bounds.
- A margin is added to avoid clicking between buttons.
- Region resize edges clamp to the 2D view bounds.
Resovles T61554
Diffstat (limited to 'source/blender/editors/interface')
-rw-r--r-- | source/blender/editors/interface/interface_handlers.c | 5 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_intern.h | 4 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_query.c | 78 | ||||
-rw-r--r-- | source/blender/editors/interface/view2d.c | 43 |
4 files changed, 115 insertions, 15 deletions
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 8125a42d3be..608ef69c4cc 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -7692,6 +7692,11 @@ uiBut *UI_region_active_but_get(ARegion *ar) return ui_context_button_active(ar, NULL); } +uiBut *UI_region_but_find_rect_over(const ARegion *ar, const rcti *rect_px) +{ + return ui_but_find_rect_over(ar, rect_px); +} + /** * Version of #UI_context_active_but_get that also returns RNA property info. * Helper function for insert keyframe, reset to default, etc operators. diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index d6f18b4cd87..4af7fdd779f 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -903,6 +903,7 @@ void ui_but_pie_dir(RadialDirection dir, float vec[2]); bool ui_but_is_cursor_warp(const uiBut *but) ATTR_WARN_UNUSED_RESULT; bool ui_but_contains_pt(const uiBut *but, float mx, float my) ATTR_WARN_UNUSED_RESULT; +bool ui_but_contains_rect(const uiBut *but, const rctf *rect); bool ui_but_contains_point_px_icon(const uiBut *but, struct ARegion *ar, const struct wmEvent *event) ATTR_WARN_UNUSED_RESULT; @@ -918,6 +919,8 @@ uiBut *ui_but_find_mouse_over_ex(struct ARegion *ar, const bool labeledit) ATTR_WARN_UNUSED_RESULT; uiBut *ui_but_find_mouse_over(struct ARegion *ar, const struct wmEvent *event) ATTR_WARN_UNUSED_RESULT; +uiBut *ui_but_find_rect_over(const struct ARegion *ar, + const rcti *rect_px) ATTR_WARN_UNUSED_RESULT; uiBut *ui_list_find_mouse_over_ex(struct ARegion *ar, int x, int y) ATTR_WARN_UNUSED_RESULT; @@ -936,6 +939,7 @@ bool ui_block_is_popup_any(const uiBlock *block) ATTR_WARN_UNUSED_RESULT; uiBut *ui_region_find_first_but_test_flag(struct ARegion *ar, int flag_include, int flag_exclude); uiBut *ui_region_find_active_but(struct ARegion *ar) ATTR_WARN_UNUSED_RESULT; bool ui_region_contains_point_px(const struct ARegion *ar, int x, int y) ATTR_WARN_UNUSED_RESULT; +bool ui_region_contains_rect_px(const struct ARegion *ar, const rcti *rect_px); /* interface_context_menu.c */ bool ui_popup_context_menu_for_button(struct bContext *C, uiBut *but); diff --git a/source/blender/editors/interface/interface_query.c b/source/blender/editors/interface/interface_query.c index 9129bbddf69..db60e967d6d 100644 --- a/source/blender/editors/interface/interface_query.c +++ b/source/blender/editors/interface/interface_query.c @@ -201,6 +201,11 @@ bool ui_but_contains_pt(const uiBut *but, float mx, float my) return BLI_rctf_isect_pt(&but->rect, mx, my); } +bool ui_but_contains_rect(const uiBut *but, const rctf *rect) +{ + return BLI_rctf_isect(&but->rect, rect, NULL); +} + bool ui_but_contains_point_px(const uiBut *but, const ARegion *ar, int x, int y) { uiBlock *block = but->block; @@ -301,6 +306,44 @@ uiBut *ui_but_find_mouse_over(ARegion *ar, const wmEvent *event) return ui_but_find_mouse_over_ex(ar, event->x, event->y, event->ctrl != 0); } +uiBut *ui_but_find_rect_over(const struct ARegion *ar, const rcti *rect_px) +{ + if (!ui_region_contains_rect_px(ar, rect_px)) { + return NULL; + } + + /* Currently no need to expose this at the moment. */ + bool labeledit = true; + rctf rect_px_fl; + BLI_rctf_rcti_copy(&rect_px_fl, rect_px); + uiBut *butover = NULL; + + for (uiBlock *block = ar->uiblocks.first; block; block = block->next) { + rctf rect_block; + ui_window_to_block_rctf(ar, block, &rect_block, &rect_px_fl); + + for (uiBut *but = block->buttons.last; but; but = but->prev) { + if (ui_but_is_interactive(but, labeledit)) { + /* No pie menu support. */ + BLI_assert(but->pie_dir == UI_RADIAL_NONE); + if (ui_but_contains_rect(but, &rect_block)) { + butover = but; + break; + } + } + } + + /* CLIP_EVENTS prevents the event from reaching other blocks */ + if (block->flag & UI_BLOCK_CLIP_EVENTS) { + /* check if mouse is inside block */ + if (BLI_rctf_isect(&block->rect, &rect_block, NULL)) { + break; + } + } + } + return butover; +} + uiBut *ui_list_find_mouse_over_ex(ARegion *ar, int x, int y) { uiBlock *block; @@ -485,17 +528,13 @@ uiBut *ui_region_find_first_but_test_flag(ARegion *ar, int flag_include, int fla /** \} */ /* -------------------------------------------------------------------- */ -/** \name Region (#ARegion) State +/** \name Region (#ARegion) Spatial * \{ */ bool ui_region_contains_point_px(const ARegion *ar, int x, int y) { rcti winrct; - - /* scale down area rect to exclude shadow */ ui_region_winrct_get_no_margin(ar, &winrct); - - /* check if the mouse is in the region */ if (!BLI_rcti_isect_pt(&winrct, x, y)) { return false; } @@ -507,14 +546,9 @@ bool ui_region_contains_point_px(const ARegion *ar, int x, int y) */ if (ar->v2d.mask.xmin != ar->v2d.mask.xmax) { const View2D *v2d = &ar->v2d; - int mx, my; + int mx = x, my = y; - /* convert window coordinates to region coordinates */ - mx = x; - my = y; ui_window_to_region(ar, &mx, &my); - - /* check if in the rect */ if (!BLI_rcti_isect_pt(&v2d->mask, mx, my) || UI_view2d_mouse_in_scrollers(ar, &ar->v2d, x, y)) { return false; @@ -524,4 +558,26 @@ bool ui_region_contains_point_px(const ARegion *ar, int x, int y) return true; } +bool ui_region_contains_rect_px(const ARegion *ar, const rcti *rect_px) +{ + rcti winrct; + ui_region_winrct_get_no_margin(ar, &winrct); + if (!BLI_rcti_isect(&winrct, rect_px, NULL)) { + return false; + } + + /* See comment in 'ui_region_contains_point_px' */ + if (ar->v2d.mask.xmin != ar->v2d.mask.xmax) { + const View2D *v2d = &ar->v2d; + rcti rect_region; + ui_window_to_region_rcti(ar, &rect_region, rect_px); + if (!BLI_rcti_isect(&v2d->mask, &rect_region, NULL) || + UI_view2d_rect_in_scrollers(ar, &ar->v2d, rect_px)) { + return false; + } + } + + return true; +} + /** \} */ diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c index 4e53e59d7c0..096ea230bbe 100644 --- a/source/blender/editors/interface/view2d.c +++ b/source/blender/editors/interface/view2d.c @@ -2626,13 +2626,14 @@ void UI_view2d_offset(struct View2D *v2d, float xfac, float yfac) char UI_view2d_mouse_in_scrollers_ex( const ARegion *ar, const View2D *v2d, int x, int y, int *r_scroll) { - int co[2]; - int scroll = view2d_scroll_mapped(v2d->scroll); + const int scroll = view2d_scroll_mapped(v2d->scroll); *r_scroll = scroll; /* clamp x,y to region-coordinates first */ - co[0] = x - ar->winrct.xmin; - co[1] = y - ar->winrct.ymin; + const int co[2] = { + x - ar->winrct.xmin, + y - ar->winrct.ymin, + }; /* check if within scrollbars */ if (scroll & V2D_SCROLL_HORIZONTAL) { @@ -2650,12 +2651,46 @@ char UI_view2d_mouse_in_scrollers_ex( return 0; } +char UI_view2d_rect_in_scrollers_ex(const ARegion *ar, + const View2D *v2d, + const rcti *rect, + int *r_scroll) +{ + const int scroll = view2d_scroll_mapped(v2d->scroll); + *r_scroll = scroll; + + /* clamp x,y to region-coordinates first */ + rcti rect_region = *rect; + BLI_rcti_translate(&rect_region, -ar->winrct.xmin, ar->winrct.ymin); + + /* check if within scrollbars */ + if (scroll & V2D_SCROLL_HORIZONTAL) { + if (IN_2D_HORIZ_SCROLL_RECT(v2d, &rect_region)) { + return 'h'; + } + } + if (scroll & V2D_SCROLL_VERTICAL) { + if (IN_2D_VERT_SCROLL_RECT(v2d, &rect_region)) { + return 'v'; + } + } + + /* not found */ + return 0; +} + char UI_view2d_mouse_in_scrollers(const ARegion *ar, const View2D *v2d, int x, int y) { int scroll_dummy = 0; return UI_view2d_mouse_in_scrollers_ex(ar, v2d, x, y, &scroll_dummy); } +char UI_view2d_rect_in_scrollers(const ARegion *ar, const View2D *v2d, const rcti *rect) +{ + int scroll_dummy = 0; + return UI_view2d_rect_in_scrollers_ex(ar, v2d, rect, &scroll_dummy); +} + /* ******************* view2d text drawing cache ******************** */ typedef struct View2DString { |