Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface_handlers.c
| Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| static void ui_menu_scroll_apply_offset_y(ARegion *region, uiBlock *block, float dy) | static void ui_menu_scroll_apply_offset_y(ARegion *region, uiBlock *block, float dy) | ||||
| { | { | ||||
| BLI_assert(dy != 0.0f); | BLI_assert(dy != 0.0f); | ||||
| if (ui_block_is_menu(block)) { | 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. */ | if (dy < 0.0f) { | ||||
| float ymax = -FLT_MAX; | /* Stop at top item, extra 0.5 UI_UNIT_Y makes it snap nicer. */ | ||||
| LISTBASE_FOREACH (uiBut *, bt, &block->buttons) { | float ymax = -FLT_MAX; | ||||
| ymax = max_ff(ymax, bt->rect.ymax); | 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; | |||||
| } | |||||
| } | } | ||||
| else { | if (ymax + dy - UI_UNIT_Y * 0.5f < block->rect.ymax - scroll_pad) { | ||||
| /* Stop at bottom item, extra 0.5 UI_UNIT_Y makes it snap nicer. */ | dy = block->rect.ymax - ymax - scroll_pad; | ||||
| float ymin = FLT_MAX; | } | ||||
| LISTBASE_FOREACH (uiBut *, bt, &block->buttons) { | } | ||||
| ymin = min_ff(ymin, bt->rect.ymin); | else { | ||||
| } | /* Stop at bottom item, extra 0.5 UI_UNIT_Y makes it snap nicer. */ | ||||
| if (ymin + dy + UI_UNIT_Y * 0.5f > block->rect.ymin + UI_MENU_SCROLL_PAD) { | float ymin = FLT_MAX; | ||||
| dy = block->rect.ymin - ymin + UI_MENU_SCROLL_PAD; | 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; | |||||
| } | } | ||||
| } | } | ||||
| /* remember scroll offset for refreshes */ | /* remember scroll offset for refreshes */ | ||||
| block->handle->scrolloffset += dy; | block->handle->scrolloffset += dy; | ||||
| /* apply scroll offset */ | /* apply scroll offset */ | ||||
| LISTBASE_FOREACH (uiBut *, bt, &block->buttons) { | LISTBASE_FOREACH (uiBut *, bt, &block->buttons) { | ||||
| ▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | |||||
| if (but && ELEM(but->type, UI_BTYPE_BLOCK, UI_BTYPE_PULLDOWN)) { | if (but && ELEM(but->type, UI_BTYPE_BLOCK, UI_BTYPE_PULLDOWN)) { | ||||
| ui_handle_button_activate(C, region, but, BUTTON_ACTIVATE_OPEN); | ui_handle_button_activate(C, region, but, BUTTON_ACTIVATE_OPEN); | ||||
| } | } | ||||
| } | } | ||||
| retval = WM_UI_HANDLER_BREAK; | retval = WM_UI_HANDLER_BREAK; | ||||
| break; | break; | ||||
| case WHEELUPMOUSE: | /* Smooth scrolling for popovers. */ | ||||
| case WHEELDOWNMOUSE: | |||||
| case MOUSEPAN: { | case MOUSEPAN: { | ||||
| if (IS_EVENT_MOD(event, shift, ctrl, alt, oskey)) { | if (IS_EVENT_MOD(event, shift, ctrl, alt, oskey)) { | ||||
| /* pass */ | /* pass */ | ||||
| } | } | ||||
| else if (!ui_block_is_menu(block)) { | else if (!ui_block_is_menu(block)) { | ||||
| int type = event->type; | if (block->flag & (UI_BLOCK_CLIPTOP | UI_BLOCK_CLIPBOTTOM)) { | ||||
| int val = event->val; | const float dy = event->y - event->prevy; | ||||
| if (dy != 0.0f) { | |||||
| /* Convert pan to scroll-wheel. */ | ui_menu_scroll_apply_offset_y(region, block, dy); | ||||
| if (type == MOUSEPAN) { | |||||
| ui_pan_to_scroll(event, &type, &val); | |||||
| } | |||||
| if (type != MOUSEPAN) { | |||||
| const int scroll_dir = (type == WHEELUPMOUSE) ? 1 : -1; | |||||
| if (ui_menu_scroll_step(region, block, scroll_dir)) { | |||||
| if (but) { | if (but) { | ||||
| but->active->cancel = true; | but->active->cancel = true; | ||||
| button_activate_exit(C, but, but->active, false, false); | button_activate_exit(C, but, but->active, false, false); | ||||
| } | } | ||||
| WM_event_add_mousemove(CTX_wm_window(C)); | WM_event_add_mousemove(CTX_wm_window(C)); | ||||
| } | } | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| ATTR_FALLTHROUGH; | 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_UPARROWKEY: | ||||
| case EVT_DOWNARROWKEY: | case EVT_DOWNARROWKEY: | ||||
| case EVT_PAGEUPKEY: | case EVT_PAGEUPKEY: | ||||
| case EVT_PAGEDOWNKEY: | case EVT_PAGEDOWNKEY: | ||||
| case EVT_HOMEKEY: | case EVT_HOMEKEY: | ||||
| case EVT_ENDKEY: | case EVT_ENDKEY: | ||||
| /* Arrow-keys: only handle for block_loop blocks. */ | /* Arrow-keys: only handle for block_loop blocks. */ | ||||
| if (IS_EVENT_MOD(event, shift, ctrl, alt, oskey)) { | if (IS_EVENT_MOD(event, shift, ctrl, alt, oskey)) { | ||||
| ▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines | |||||