diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-07-01 05:10:49 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-07-01 05:10:49 +0300 |
commit | 05129ffb3e2cea8ec51cb6ee4890f5cd5e31794c (patch) | |
tree | 60f96dd7eb056f46c417fb39fb079b30b0ede620 /source/blender | |
parent | 26e05cf67adb142086e9aa2655424144d14d8913 (diff) |
Cleanup: move screen region find into utility function
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/BKE_screen.h | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/screen.c | 17 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_ops.c | 20 |
3 files changed, 26 insertions, 14 deletions
diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h index dcf6d6c3907..5d3e7ad5ec2 100644 --- a/source/blender/blenkernel/BKE_screen.h +++ b/source/blender/blenkernel/BKE_screen.h @@ -350,6 +350,9 @@ void BKE_region_callback_refresh_tag_gizmomap_set(void (*callback)(struct wmGizm struct ARegion *BKE_area_find_region_type(const struct ScrArea *sa, int type); struct ARegion *BKE_area_find_region_active_win(struct ScrArea *sa); struct ARegion *BKE_area_find_region_xy(struct ScrArea *sa, const int regiontype, int x, int y); +struct ARegion *BKE_screen_find_region_xy(struct bScreen *sc, const int regiontype, int x, int y) + ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1); + struct ScrArea *BKE_screen_find_area_from_space(struct bScreen *sc, struct SpaceLink *sl) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2); diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c index 86fec1ee754..619845c9ecb 100644 --- a/source/blender/blenkernel/intern/screen.c +++ b/source/blender/blenkernel/intern/screen.c @@ -738,6 +738,23 @@ ARegion *BKE_area_find_region_xy(ScrArea *sa, const int regiontype, int x, int y } /** + * \note This is only for screen level regions (typically menus/popups). + */ +ARegion *BKE_screen_find_region_xy(bScreen *sc, const int regiontype, int x, int y) +{ + ARegion *ar_found = NULL; + for (ARegion *ar = sc->regionbase.first; ar; ar = ar->next) { + if ((regiontype == RGN_TYPE_ANY) || (ar->regiontype == regiontype)) { + if (BLI_rcti_isect_pt(&ar->winrct, x, y)) { + ar_found = ar; + break; + } + } + } + return ar_found; +} + +/** * \note, ideally we can get the area from the context, * there are a few places however where this isn't practical. */ diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c index 1df70573acb..7d2ccd9c3ec 100644 --- a/source/blender/editors/interface/interface_ops.c +++ b/source/blender/editors/interface/interface_ops.c @@ -1507,29 +1507,21 @@ static void UI_OT_reloadtranslation(wmOperatorType *ot) /** \name Press Button Operator * \{ */ -static ARegion *region_event_inside_for_screen(bContext *C, const int xy[2]) -{ - bScreen *sc = CTX_wm_screen(C); - if (sc) { - for (ARegion *ar = sc->regionbase.first; ar; ar = ar->next) { - if (BLI_rcti_isect_pt_v(&ar->winrct, xy)) { - return ar; - } - } - } - return NULL; -} - static int ui_button_press_invoke(bContext *C, wmOperator *op, const wmEvent *event) { + bScreen *sc = CTX_wm_screen(C); const bool skip_depressed = RNA_boolean_get(op->ptr, "skip_depressed"); ARegion *ar_prev = CTX_wm_region(C); - ARegion *ar = region_event_inside_for_screen(C, &event->x); + ARegion *ar = sc ? BKE_screen_find_region_xy(sc, RGN_TYPE_ANY, event->x, event->y) : NULL; if (ar == NULL) { ar = ar_prev; } + if (ar == NULL) { + return OPERATOR_PASS_THROUGH; + } + CTX_wm_region_set(C, ar); uiBut *but = UI_context_active_but_get(C); CTX_wm_region_set(C, ar_prev); |