Cleanup: minor UI code changes

- Rename ui_but_find_active_in_region -> ui_region_find_active_but
- Remove ui_but_is_active (use ui_region_find_active_but instead)
- Re-order ui_but_* functions take the button as their first arg.
This commit is contained in:
Campbell Barton 2019-03-23 00:18:16 +11:00
parent 8f3ecd08e1
commit be750e2aee
5 changed files with 37 additions and 43 deletions

View File

@ -3836,7 +3836,7 @@ static int ui_do_but_HOTKEYEVT(
if (event->type == LEFTMOUSE && event->val == KM_PRESS) {
/* only cancel if click outside the button */
if (ui_but_contains_point_px(but->active->region, but, event->x, event->y) == 0) {
if (ui_but_contains_point_px(but, but->active->region, event->x, event->y) == 0) {
/* data->cancel doesn't work, this button opens immediate */
if (but->flag & UI_BUT_IMMEDIATE)
ui_but_value_set(but, 0);
@ -7668,7 +7668,7 @@ static void ui_handle_button_activate(bContext *C, ARegion *ar, uiBut *but, uiBu
uiBut *oldbut;
uiHandleButtonData *data;
oldbut = ui_but_find_active_in_region(ar);
oldbut = ui_region_find_active_but(ar);
if (oldbut) {
data = oldbut->active;
data->cancel = true;
@ -7765,7 +7765,7 @@ static int ui_handle_button_event(bContext *C, const wmEvent *event, uiBut *but)
/* always deactivate button for pie menus,
* else moving to blank space will leave activated */
if ((!ui_block_is_menu(block) || ui_block_is_pie_menu(block)) &&
!ui_but_contains_point_px(ar, but, event->x, event->y))
!ui_but_contains_point_px(but, ar, event->x, event->y))
{
exit = true;
}
@ -7792,7 +7792,7 @@ static int ui_handle_button_event(bContext *C, const wmEvent *event, uiBut *but)
WM_event_remove_timer(data->wm, data->window, data->autoopentimer);
data->autoopentimer = NULL;
if (ui_but_contains_point_px(ar, but, event->x, event->y) || but->active) {
if (ui_but_contains_point_px(but, ar, event->x, event->y) || but->active) {
button_activate_state(C, but, BUTTON_STATE_MENU_OPEN);
}
}
@ -7844,7 +7844,7 @@ static int ui_handle_button_event(bContext *C, const wmEvent *event, uiBut *but)
{
/* deselect the button when moving the mouse away */
/* also de-activate for buttons that only show highlights */
if (ui_but_contains_point_px(ar, but, event->x, event->y)) {
if (ui_but_contains_point_px(but, ar, event->x, event->y)) {
/* Drag on a hold button (used in the toolbar) now opens it immediately. */
if (data->hold_action_timer) {
@ -8159,7 +8159,7 @@ static void ui_handle_button_return_submenu(bContext *C, const wmEvent *event, u
button_activate_exit(C, but, data, true, false);
}
else if (menu->menuretval & UI_RETURN_OUT) {
if (event->type == MOUSEMOVE && ui_but_contains_point_px(data->region, but, event->x, event->y)) {
if (event->type == MOUSEMOVE && ui_but_contains_point_px(but, data->region, event->x, event->y)) {
button_activate_state(C, but, BUTTON_STATE_HIGHLIGHT);
}
else {
@ -8472,7 +8472,7 @@ static bool ui_menu_pass_event_to_parent_if_nonactive(
static int ui_handle_menu_button(bContext *C, const wmEvent *event, uiPopupBlockHandle *menu)
{
ARegion *ar = menu->region;
uiBut *but = ui_but_find_active_in_region(ar);
uiBut *but = ui_region_find_active_but(ar);
int retval;
if (but) {
@ -8488,7 +8488,7 @@ static int ui_handle_menu_button(bContext *C, const wmEvent *event, uiPopupBlock
/* pass, needed to click-exit outside of non-flaoting menus */
}
else if ((!ELEM(event->type, MOUSEMOVE, WHEELUPMOUSE, WHEELDOWNMOUSE, MOUSEPAN)) && ISMOUSE(event->type)) {
if (!ui_but_contains_point_px(but->active->region, but, event->x, event->y)) {
if (!ui_but_contains_point_px(but, but->active->region, event->x, event->y)) {
but = NULL;
}
}
@ -8563,7 +8563,7 @@ static int ui_handle_menu_event(
inside_title = inside && ((my + (UI_UNIT_Y * 1.5f)) > block->rect.ymax);
/* if there's an active modal button, don't check events or outside, except for search menu */
but = ui_but_find_active_in_region(ar);
but = ui_region_find_active_but(ar);
#ifdef USE_DRAG_POPUP
if (menu->is_grab) {
@ -8661,7 +8661,7 @@ static int ui_handle_menu_event(
if (ui_menu_pass_event_to_parent_if_nonactive(menu, but, level, retval))
break;
but = ui_but_find_active_in_region(ar);
but = ui_region_find_active_but(ar);
if (!but) {
/* no item active, we make first active */
@ -8722,7 +8722,7 @@ static int ui_handle_menu_event(
ui_mouse_motion_keynav_init(&menu->keynav_state, event);
#endif
but = ui_but_find_active_in_region(ar);
but = ui_region_find_active_but(ar);
if (but) {
/* next button */
but = is_next ? ui_but_next(but) : ui_but_prev(but);
@ -8942,14 +8942,14 @@ static int ui_handle_menu_event(
else if (ELEM(event->type, RETKEY, PADENTER) && event->val == KM_PRESS) {
/* enter will always close this block, we let the event
* get handled by the button if it is activated, otherwise we cancel */
if (!ui_but_find_active_in_region(ar))
if (!ui_region_find_active_but(ar))
menu->menuretval = UI_RETURN_CANCEL | UI_RETURN_POPUP_OK;
}
#ifdef USE_DRAG_POPUP
else if ((event->type == LEFTMOUSE) && (event->val == KM_PRESS) &&
(inside && is_floating && inside_title))
{
if (!but || !ui_but_contains_point_px(ar, but, event->x, event->y)) {
if (!but || !ui_but_contains_point_px(but, ar, event->x, event->y)) {
if (but) {
UI_but_tooltip_timer_remove(C, but);
}
@ -9043,7 +9043,7 @@ static int ui_handle_menu_return_submenu(bContext *C, const wmEvent *event, uiPo
ar = menu->region;
block = ar->uiblocks.first;
but = ui_but_find_active_in_region(ar);
but = ui_region_find_active_but(ar);
BLI_assert(but);
@ -9099,7 +9099,7 @@ static int ui_but_pie_menu_apply(bContext *C, uiPopupBlockHandle *menu, uiBut *b
if (but->type == UI_BTYPE_MENU) {
/* forcing the pie menu to close will not handle menus */
if (!force_close) {
uiBut *active_but = ui_but_find_active_in_region(menu->region);
uiBut *active_but = ui_region_find_active_but(menu->region);
if (active_but) {
button_activate_exit(C, active_but, active_but->active, false, false);
@ -9150,7 +9150,7 @@ static int ui_but_pie_button_activate(bContext *C, uiBut *but, uiPopupBlockHandl
if (but == NULL)
return WM_UI_HANDLER_BREAK;
active_but = ui_but_find_active_in_region(menu->region);
active_but = ui_region_find_active_but(menu->region);
if (active_but)
button_activate_exit(C, active_but, active_but->active, false, false);
@ -9185,7 +9185,7 @@ static int ui_pie_handler(bContext *C, const wmEvent *event, uiPopupBlockHandle
is_click_style = (block->pie_data.flags & UI_PIE_CLICK_STYLE);
/* if there's an active modal button, don't check events or outside, except for search menu */
but = ui_but_find_active_in_region(ar);
but = ui_region_find_active_but(ar);
if (menu->scrolltimer == NULL) {
menu->scrolltimer =
@ -9264,7 +9264,7 @@ static int ui_pie_handler(bContext *C, const wmEvent *event, uiPopupBlockHandle
}
if (len_sq < 1.0f) {
but = ui_but_find_active_in_region(menu->region);
but = ui_region_find_active_but(menu->region);
if (but) {
return ui_but_pie_menu_apply(C, menu, but, true);
@ -9291,7 +9291,7 @@ static int ui_pie_handler(bContext *C, const wmEvent *event, uiPopupBlockHandle
block->pie_data.flags |= UI_PIE_CLICK_STYLE;
}
else {
but = ui_but_find_active_in_region(menu->region);
but = ui_region_find_active_but(menu->region);
if (but && (U.pie_menu_confirm > 0) &&
(dist >= U.dpi_fac * (U.pie_menu_threshold + U.pie_menu_confirm)))
@ -9430,7 +9430,7 @@ static int ui_handle_menus_recursive(
bool do_towards_reinit = false;
/* check if we have a submenu, and handle events for it first */
but = ui_but_find_active_in_region(menu->region);
but = ui_region_find_active_but(menu->region);
data = (but) ? but->active : NULL;
submenu = (data) ? data->menu : NULL;
@ -9480,7 +9480,7 @@ static int ui_handle_menus_recursive(
if (block->flag & (UI_BLOCK_MOVEMOUSE_QUIT | UI_BLOCK_POPOVER)) {
/* when there is a active search button and we close it,
* we need to reinit the mouse coords [#35346] */
if (ui_but_find_active_in_region(menu->region) != but) {
if (ui_region_find_active_but(menu->region) != but) {
do_towards_reinit = true;
}
}
@ -9551,7 +9551,7 @@ static int ui_region_handler(bContext *C, const wmEvent *event, void *UNUSED(use
}
/* either handle events for already activated button or try to activate */
but = ui_but_find_active_in_region(ar);
but = ui_region_find_active_but(ar);
listbox = ui_list_find_mouse_over(ar, event);
retval = ui_handler_panel_region(C, event, ar, listbox ? listbox : but);
@ -9616,7 +9616,7 @@ static int ui_handler_region_menu(bContext *C, const wmEvent *event, void *UNUSE
if (!ar)
ar = CTX_wm_region(C);
but = ui_but_find_active_in_region(ar);
but = ui_region_find_active_but(ar);
if (but) {
bScreen *screen = CTX_wm_screen(C);
@ -9919,7 +9919,7 @@ void UI_screen_free_active_but(const bContext *C, bScreen *screen)
ED_screen_areas_iter(win, screen, area) {
for (ARegion *region = area->regionbase.first; region; region = region->next) {
uiBut *but = ui_but_find_active_in_region(region);
uiBut *but = ui_region_find_active_but(region);
if (but) {
uiHandleButtonData *data = but->active;
@ -9937,7 +9937,7 @@ void UI_screen_free_active_but(const bContext *C, bScreen *screen)
bool UI_but_active_drop_name(bContext *C)
{
ARegion *ar = CTX_wm_region(C);
uiBut *but = ui_but_find_active_in_region(ar);
uiBut *but = ui_region_find_active_but(ar);
if (but) {
if (ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU))
@ -9952,7 +9952,7 @@ bool UI_but_active_drop_color(bContext *C)
ARegion *ar = CTX_wm_region(C);
if (ar) {
uiBut *but = ui_but_find_active_in_region(ar);
uiBut *but = ui_region_find_active_but(ar);
if (but && but->type == UI_BTYPE_COLOR)
return true;

View File

@ -818,18 +818,15 @@ bool ui_but_contains_pt(
bool ui_but_contains_point_px_icon(
const uiBut *but, struct ARegion *ar, const struct wmEvent *event) ATTR_WARN_UNUSED_RESULT;
bool ui_but_contains_point_px(
const struct ARegion *ar, const uiBut *but, int x, int y) ATTR_WARN_UNUSED_RESULT;
bool ui_region_contains_point_px(
const struct ARegion *ar, int x, int y) ATTR_WARN_UNUSED_RESULT;
const uiBut *but, const struct ARegion *ar, int x, int y) ATTR_WARN_UNUSED_RESULT;
uiBut *ui_list_find_mouse_over(ARegion *ar, const struct wmEvent *event) ATTR_WARN_UNUSED_RESULT;
uiBut *ui_list_find_mouse_over(struct ARegion *ar, const struct wmEvent *event) ATTR_WARN_UNUSED_RESULT;
uiBut *ui_but_find_mouse_over_ex(ARegion *ar, const int x, const int y, const bool labeledit) ATTR_WARN_UNUSED_RESULT;
uiBut *ui_but_find_mouse_over_ex(struct ARegion *ar, const int x, const int y, 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_list_find_mouse_over_ex(struct ARegion *ar, int x, int y) ATTR_WARN_UNUSED_RESULT;
bool ui_but_is_active(struct ARegion *ar) ATTR_WARN_UNUSED_RESULT;
bool ui_but_contains_password(const uiBut *but) ATTR_WARN_UNUSED_RESULT;
uiBut *ui_but_prev(uiBut *but) ATTR_WARN_UNUSED_RESULT;
@ -842,7 +839,9 @@ bool ui_block_is_popover(const uiBlock *block) ATTR_WARN_UNUSED_RESULT;
bool ui_block_is_pie_menu(const uiBlock *block) ATTR_WARN_UNUSED_RESULT;
bool ui_block_is_popup_any(const uiBlock *block) ATTR_WARN_UNUSED_RESULT;
uiBut *ui_but_find_active_in_region(struct ARegion *ar) ATTR_WARN_UNUSED_RESULT;
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;
/* interface_context_menu.c */
bool ui_popup_context_menu_for_button(struct bContext *C, uiBut *but);

View File

@ -1521,7 +1521,7 @@ static int drop_color_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(
/* find button under mouse, check if it has RNA color property and
* if it does copy the data */
but = ui_but_find_active_in_region(ar);
but = ui_region_find_active_but(ar);
if (but && but->type == UI_BTYPE_COLOR && but->rnaprop) {
const int color_len = RNA_property_array_length(&but->rnapoin, but->rnaprop);

View File

@ -2250,8 +2250,9 @@ int ui_handler_panel_region(bContext *C, const wmEvent *event, ARegion *ar, cons
}
/* on active button, do not handle panels */
if (ui_but_is_active(ar))
if (ui_region_find_active_but(ar) != NULL) {
continue;
}
if (ELEM(mouse_state, PANEL_MOUSE_INSIDE_CONTENT, PANEL_MOUSE_INSIDE_HEADER)) {

View File

@ -191,7 +191,7 @@ 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_point_px(const ARegion *ar, const uiBut *but, int x, int y)
bool ui_but_contains_point_px(const uiBut *but, const ARegion *ar, int x, int y)
{
uiBlock *block = but->block;
float mx, my;
@ -433,13 +433,7 @@ bool UI_block_is_empty(const uiBlock *block)
/** \name Region (#ARegion) State
* \{ */
bool ui_but_is_active(ARegion *ar)
{
return (ui_but_find_active_in_region(ar) != NULL);
}
uiBut *ui_but_find_active_in_region(ARegion *ar)
uiBut *ui_region_find_active_but(ARegion *ar)
{
uiBlock *block;
uiBut *but;