diff options
author | Yevgeny Makarov <jenkm> | 2020-11-24 04:22:20 +0300 |
---|---|---|
committer | Harley Acheson <harley.acheson@gmail.com> | 2020-11-24 04:22:20 +0300 |
commit | df31ecf0c3e3b406906dd8bbe99cb75273e9dc4b (patch) | |
tree | 402ec79c14d91a4a00bdd743279cb4ad1c32d2ae /source | |
parent | b6a50b5dcb461fe06cc3efc76b34e483a2ca6c0e (diff) |
UI: Add Trackpad Smooth Scrolling for Popovers
Adds smooth scrolling with the trackpad for popovers. Also fixes the position of the scroll arrows on high-DPI.
Differential Revision: https://developer.blender.org/D9533
Reviewed by Brecht Van Lommel
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/interface/interface_handlers.c | 73 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_intern.h | 6 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_widgets.c | 4 |
3 files changed, 47 insertions, 36 deletions
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 7dd6e400ae7..4fe4bbaf189 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -9327,26 +9327,26 @@ static void ui_menu_scroll_apply_offset_y(ARegion *region, uiBlock *block, float { BLI_assert(dy != 0.0f); - if (ui_block_is_menu(block)) { - if (dy < 0.0f) { - /* Stop at top item, extra 0.5 UI_UNIT_Y makes it snap nicer. */ - float ymax = -FLT_MAX; - LISTBASE_FOREACH (uiBut *, bt, &block->buttons) { - ymax = max_ff(ymax, bt->rect.ymax); - } - if (ymax + dy - UI_UNIT_Y * 0.5f < block->rect.ymax - UI_MENU_SCROLL_PAD) { - dy = block->rect.ymax - ymax - UI_MENU_SCROLL_PAD; - } + const int scroll_pad = ui_block_is_menu(block) ? UI_MENU_SCROLL_PAD : UI_UNIT_Y * 0.5f; + + if (dy < 0.0f) { + /* Stop at top item, extra 0.5 UI_UNIT_Y makes it snap nicer. */ + float ymax = -FLT_MAX; + LISTBASE_FOREACH (uiBut *, bt, &block->buttons) { + ymax = max_ff(ymax, bt->rect.ymax); } - else { - /* Stop at bottom item, extra 0.5 UI_UNIT_Y makes it snap nicer. */ - float ymin = FLT_MAX; - LISTBASE_FOREACH (uiBut *, bt, &block->buttons) { - ymin = min_ff(ymin, bt->rect.ymin); - } - if (ymin + dy + UI_UNIT_Y * 0.5f > block->rect.ymin + UI_MENU_SCROLL_PAD) { - dy = block->rect.ymin - ymin + UI_MENU_SCROLL_PAD; - } + if (ymax + dy - UI_UNIT_Y * 0.5f < block->rect.ymax - scroll_pad) { + dy = block->rect.ymax - ymax - scroll_pad; + } + } + else { + /* Stop at bottom item, extra 0.5 UI_UNIT_Y makes it snap nicer. */ + float ymin = FLT_MAX; + LISTBASE_FOREACH (uiBut *, bt, &block->buttons) { + ymin = min_ff(ymin, bt->rect.ymin); + } + if (ymin + dy + UI_UNIT_Y * 0.5f > block->rect.ymin + scroll_pad) { + dy = block->rect.ymin - ymin + scroll_pad; } } @@ -9697,24 +9697,17 @@ static int ui_handle_menu_event(bContext *C, retval = WM_UI_HANDLER_BREAK; break; - case WHEELUPMOUSE: - case WHEELDOWNMOUSE: + /* Smooth scrolling for popovers. */ case MOUSEPAN: { if (IS_EVENT_MOD(event, shift, ctrl, alt, oskey)) { /* pass */ } else if (!ui_block_is_menu(block)) { - int type = event->type; - int val = event->val; - - /* Convert pan to scroll-wheel. */ - if (type == MOUSEPAN) { - ui_pan_to_scroll(event, &type, &val); - } + if (block->flag & (UI_BLOCK_CLIPTOP | UI_BLOCK_CLIPBOTTOM)) { + const float dy = event->y - event->prevy; + if (dy != 0.0f) { + ui_menu_scroll_apply_offset_y(region, block, dy); - if (type != MOUSEPAN) { - const int scroll_dir = (type == WHEELUPMOUSE) ? 1 : -1; - if (ui_menu_scroll_step(region, block, scroll_dir)) { if (but) { but->active->cancel = true; button_activate_exit(C, but, but->active, false, false); @@ -9726,6 +9719,24 @@ static int ui_handle_menu_event(bContext *C, } ATTR_FALLTHROUGH; } + case WHEELUPMOUSE: + case WHEELDOWNMOUSE: { + if (IS_EVENT_MOD(event, shift, ctrl, alt, oskey)) { + /* pass */ + } + else if (!ui_block_is_menu(block)) { + const int scroll_dir = (event->type == WHEELUPMOUSE) ? 1 : -1; + if (ui_menu_scroll_step(region, block, scroll_dir)) { + if (but) { + but->active->cancel = true; + button_activate_exit(C, but, but->active, false, false); + } + WM_event_add_mousemove(CTX_wm_window(C)); + } + break; + } + ATTR_FALLTHROUGH; + } case EVT_UPARROWKEY: case EVT_DOWNARROWKEY: case EVT_PAGEUPKEY: diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index 13234c82bfa..5c7cad4c8d5 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -62,9 +62,9 @@ struct wmTimer; #define UI_MENU_SUBMENU_PADDING (6 * UI_DPI_FAC) /* menu scrolling */ -#define UI_MENU_SCROLL_ARROW 12 -#define UI_MENU_SCROLL_MOUSE (UI_MENU_SCROLL_ARROW + 2) -#define UI_MENU_SCROLL_PAD 4 +#define UI_MENU_SCROLL_ARROW (12 * UI_DPI_FAC) +#define UI_MENU_SCROLL_MOUSE (UI_MENU_SCROLL_ARROW + 2 * UI_DPI_FAC) +#define UI_MENU_SCROLL_PAD (4 * UI_DPI_FAC) /* panel limits */ #define UI_PANEL_MINX 100 diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index 6d7e3ec1d8d..b550dc2665f 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -4831,11 +4831,11 @@ static void ui_draw_clip_tri(uiBlock *block, rcti *rect, uiWidgetType *wt) if (block->flag & UI_BLOCK_CLIPTOP) { /* XXX no scaling for UI here yet */ - UI_draw_icon_tri(BLI_rcti_cent_x(rect), rect->ymax - 8, 't', draw_color); + UI_draw_icon_tri(BLI_rcti_cent_x(rect), rect->ymax - 6 * U.dpi_fac, 't', draw_color); } if (block->flag & UI_BLOCK_CLIPBOTTOM) { /* XXX no scaling for UI here yet */ - UI_draw_icon_tri(BLI_rcti_cent_x(rect), rect->ymin + 10, 'v', draw_color); + UI_draw_icon_tri(BLI_rcti_cent_x(rect), rect->ymin + 10 * U.dpi_fac, 'v', draw_color); } } } |