Cleanup: move screen region find into utility function
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -737,6 +737,23 @@ ARegion *BKE_area_find_region_xy(ScrArea *sa, const int regiontype, int x, int y
|
||||
return ar_found;
|
||||
}
|
||||
|
||||
/**
|
||||
* \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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user