[Bf-blender-cvs] [be3adb51de2] master: UI: ignore events in empty region overlap areas

Campbell Barton noreply at git.blender.org
Tue Apr 23 08:55:17 CEST 2019


Commit: be3adb51de21652d64a6839cd5614c5096064c6a
Author: Campbell Barton
Date:   Tue Apr 23 16:43:50 2019 +1000
Branches: master
https://developer.blender.org/rBbe3adb51de21652d64a6839cd5614c5096064c6a

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

===================================================================

M	source/blender/editors/include/ED_screen.h
M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/include/UI_view2d.h
M	source/blender/editors/interface/interface_handlers.c
M	source/blender/editors/interface/interface_intern.h
M	source/blender/editors/interface/interface_query.c
M	source/blender/editors/interface/view2d.c
M	source/blender/editors/screen/CMakeLists.txt
M	source/blender/editors/screen/area.c
A	source/blender/editors/screen/area_query.c
M	source/blender/editors/screen/screen_edit.c
M	source/blender/windowmanager/intern/wm_event_system.c

===================================================================

diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h
index 5d9c493737c..00771142553 100644
--- a/source/blender/editors/include/ED_screen.h
+++ b/source/blender/editors/include/ED_screen.h
@@ -403,6 +403,18 @@ void ED_region_generic_tools_region_message_subscribe(const struct bContext *C,
                                                       struct wmMsgBus *mbus);
 int ED_region_generic_tools_region_snap_size(const struct ARegion *ar, int size, int axis);
 
+/* area_query.c */
+bool ED_region_overlap_isect_x(const ARegion *ar, const int event_x);
+bool ED_region_overlap_isect_y(const ARegion *ar, const int event_y);
+bool ED_region_overlap_isect_xy(const ARegion *ar, const int event_xy[2]);
+bool ED_region_overlap_isect_x_with_margin(const ARegion *ar, const int event_x, const int margin);
+bool ED_region_overlap_isect_y_with_margin(const ARegion *ar, const int event_y, const int margin);
+bool ED_region_overlap_isect_xy_with_margin(const ARegion *ar,
+                                            const int event_xy[2],
+                                            const int margin);
+
+bool ED_region_contains_xy(const struct ARegion *ar, const int event_xy[2]);
+
 /* interface_region_hud.c */
 struct ARegionType *ED_area_type_hud(int space_type);
 void ED_area_type_hud_clear(struct wmWindowManager *wm, ScrArea *sa_keep);
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index dd086461801..3b77146b70e 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -86,6 +86,14 @@ typedef struct uiPopupBlockHandle uiPopupBlockHandle;
 #define UI_MAX_NAME_STR 128
 #define UI_MAX_SHORTCUT_STR 64
 
+/**
+ * For #ARegion.overlap regions, pass events though if they don't overlap
+ * the regions contents (the usable part of the #View2D and buttons).
+ *
+ * The margin is needed so it's not possible to accidentally click inbetween buttons.
+ */
+#define UI_REGION_OVERLAP_MARGIN (U.widget_unit / 3)
+
 /* use for clamping popups within the screen */
 #define UI_SCREEN_MARGIN 10
 
@@ -2302,6 +2310,7 @@ void UI_context_active_but_prop_get_templateID(struct bContext *C,
 struct ID *UI_context_active_but_get_tab_ID(struct bContext *C);
 
 uiBut *UI_region_active_but_get(struct ARegion *ar);
+uiBut *UI_region_but_find_rect_over(const struct ARegion *ar, const struct rcti *isect);
 
 /* uiFontStyle.align */
 typedef enum eFontStyle_Align {
diff --git a/source/blender/editors/include/UI_view2d.h b/source/blender/editors/include/UI_view2d.h
index fde865d4bba..a16c1efd6cf 100644
--- a/source/blender/editors/include/UI_view2d.h
+++ b/source/blender/editors/include/UI_view2d.h
@@ -117,6 +117,9 @@ enum eView2D_Gridlines {
 #define IN_2D_VERT_SCROLL(v2d, co) (BLI_rcti_isect_pt_v(&v2d->vert, co))
 #define IN_2D_HORIZ_SCROLL(v2d, co) (BLI_rcti_isect_pt_v(&v2d->hor, co))
 
+#define IN_2D_VERT_SCROLL_RECT(v2d, rct) (BLI_rcti_isect(&v2d->vert, rct, NULL))
+#define IN_2D_HORIZ_SCROLL_RECT(v2d, rct) (BLI_rcti_isect(&v2d->hor, rct, NULL))
+
 /* ------------------------------------------ */
 /* Type definitions:                          */
 
@@ -275,6 +278,13 @@ char UI_view2d_mouse_in_scrollers(const struct ARegion *ar,
                                   const struct View2D *v2d,
                                   int x,
                                   int y);
+char UI_view2d_rect_in_scrollers_ex(const struct ARegion *ar,
+                                    const struct View2D *v2d,
+                                    const struct rcti *rect,
+                                    int *r_scroll);
+char UI_view2d_rect_in_scrollers(const struct ARegion *ar,
+                                 const struct View2D *v2d,
+                                 const struct rcti *rect);
 
 /* cached text drawing in v2d, to allow pixel-aligned draw as post process */
 void UI_view2d_text_cache_add(
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) ||
+       

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list