diff options
author | Julian Eisel <julian@blender.org> | 2020-03-06 18:22:28 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2020-03-06 18:27:13 +0300 |
commit | d5572eacc5958db38ac4a4a32eddb3a2cd24bf68 (patch) | |
tree | 5252d8f509dae02bf9c137a1710c073d5bbac592 /source/blender/editors/interface | |
parent | b242cc67928a6858a835c088e4d3ea8822c83168 (diff) |
Cleanup: Reduce context usage in UI functions
Part of https://developer.blender.org/T74429.
There's a chance that this causes some issues becaue in some cases we
change from getting the window from context to getting it from somewhere
else.
Diffstat (limited to 'source/blender/editors/interface')
8 files changed, 32 insertions, 42 deletions
diff --git a/source/blender/editors/interface/interface_eyedropper_datablock.c b/source/blender/editors/interface/interface_eyedropper_datablock.c index fd5a46e7716..0220f3f5afd 100644 --- a/source/blender/editors/interface/interface_eyedropper_datablock.c +++ b/source/blender/editors/interface/interface_eyedropper_datablock.c @@ -125,7 +125,9 @@ static int datadropper_init(bContext *C, wmOperator *op) static void datadropper_exit(bContext *C, wmOperator *op) { - WM_cursor_modal_restore(CTX_wm_window(C)); + wmWindow *win = CTX_wm_window(C); + + WM_cursor_modal_restore(win); if (op->customdata) { DataDropper *ddr = (DataDropper *)op->customdata; @@ -139,7 +141,7 @@ static void datadropper_exit(bContext *C, wmOperator *op) op->customdata = NULL; } - WM_event_add_mousemove(C); + WM_event_add_mousemove(win); } /* *** datadropper id helper functions *** */ diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index e96e4bfd72a..cf736d65596 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -1552,7 +1552,7 @@ static int ui_handler_region_drag_toggle(bContext *C, const wmEvent *event, void false); ui_handler_region_drag_toggle_remove(C, drag_info); - WM_event_add_mousemove(C); + WM_event_add_mousemove(win); return WM_UI_HANDLER_BREAK; } else { @@ -1843,7 +1843,7 @@ static bool ui_but_drag_init(bContext *C, const wmEvent *event) { /* prevent other WM gestures to start while we try to drag */ - WM_gestures_remove(C); + WM_gestures_remove(CTX_wm_window(C)); /* Clamp the maximum to half the UI unit size so a high user preference * doesn't require the user to drag more then half the default button height. */ @@ -3280,7 +3280,7 @@ wmIMEData *ui_but_ime_data_get(uiBut *but) static void ui_textedit_begin(bContext *C, uiBut *but, uiHandleButtonData *data) { - wmWindow *win = CTX_wm_window(C); + wmWindow *win = data->window; int len; const bool is_num_but = ELEM(but->type, UI_BTYPE_NUM, UI_BTYPE_NUM_SLIDER); bool no_zero_strip = false; @@ -3370,7 +3370,7 @@ static void ui_textedit_begin(bContext *C, uiBut *but, uiHandleButtonData *data) static void ui_textedit_end(bContext *C, uiBut *but, uiHandleButtonData *data) { - wmWindow *win = CTX_wm_window(C); + wmWindow *win = data->window; if (but) { if (UI_but_is_utf8(but)) { @@ -3945,7 +3945,7 @@ static void ui_but_extra_operator_icon_apply(bContext *C, uiBut *but, uiButExtra /* Force recreation of extra operator icons (pseudo update). */ ui_but_extra_operator_icons_free(but); - WM_event_add_mousemove(C); + WM_event_add_mousemove(CTX_wm_window(C)); } /** \} */ @@ -4020,8 +4020,7 @@ static void ui_block_open_begin(bContext *C, uiBut *but, uiHandleButtonData *dat #ifdef USE_ALLSELECT { - wmWindow *win = CTX_wm_window(C); - if (IS_ALLSELECT_EVENT(win->eventstate)) { + if (IS_ALLSELECT_EVENT(data->window->eventstate)) { data->select_others.is_enabled = true; } } @@ -5570,7 +5569,7 @@ static int ui_do_but_BLOCK(bContext *C, uiBut *but, uiHandleButtonData *data, co * The active state of the button could be maintained some other way * and remove this mousemove event. */ - WM_event_add_mousemove(C); + WM_event_add_mousemove(data->window); return WM_UI_HANDLER_BREAK; } @@ -8039,11 +8038,12 @@ static void button_activate_init(bContext *C, ARegion *ar, uiBut *but, uiButtonA static void button_activate_exit( bContext *C, uiBut *but, uiHandleButtonData *data, const bool mousemove, const bool onfree) { + wmWindow *win = data->window; uiBlock *block = but->block; uiBut *bt; if (but->type == UI_BTYPE_GRIP) { - WM_cursor_modal_restore(data->window); + WM_cursor_modal_restore(win); } /* ensure we are in the exit state */ @@ -8160,7 +8160,7 @@ static void button_activate_exit( * still over a button. We cannot just check for this ourselves because * at this point the mouse may be over a button in another region */ if (mousemove) { - WM_event_add_mousemove(C); + WM_event_add_mousemove(CTX_wm_window(C)); } } @@ -8818,7 +8818,7 @@ static int ui_handle_button_event(bContext *C, const wmEvent *event, uiBut *but) button_activate_init(C, ar, post_but, post_type); } else { - /* XXX issue is because WM_event_add_mousemove(C) is a bad hack and not reliable, + /* XXX issue is because WM_event_add_mousemove(wm) is a bad hack and not reliable, * if that gets coded better this bypass can go away too. * * This is needed to make sure if a button was active, @@ -9592,7 +9592,7 @@ static int ui_handle_menu_event(bContext *C, but->active->cancel = true; button_activate_exit(C, but, but->active, false, false); } - WM_event_add_mousemove(C); + WM_event_add_mousemove(but->active->window); } } break; @@ -10776,7 +10776,7 @@ static int ui_popup_handler(bContext *C, const wmEvent *event, void *userdata) temp.cancel_func(C, temp.popup_arg); } - WM_event_add_mousemove(C); + WM_event_add_mousemove(win); } else { /* re-enable tooltips */ diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c index 9fa8431beea..9de2824e3a3 100644 --- a/source/blender/editors/interface/interface_ops.c +++ b/source/blender/editors/interface/interface_ops.c @@ -1649,7 +1649,7 @@ static int ui_button_press_invoke(bContext *C, wmOperator *op, const wmEvent *ev but->optype = but_optype; - WM_event_add_mousemove(C); + WM_event_add_mousemove(CTX_wm_window(C)); return OPERATOR_FINISHED; } diff --git a/source/blender/editors/interface/interface_region_menu_pie.c b/source/blender/editors/interface/interface_region_menu_pie.c index 330a9d48ff4..f75f4c054a3 100644 --- a/source/blender/editors/interface/interface_region_menu_pie.c +++ b/source/blender/editors/interface/interface_region_menu_pie.c @@ -213,7 +213,7 @@ void UI_pie_menu_end(bContext *C, uiPieMenu *pie) menu->towardstime = PIL_check_seconds_timer(); UI_popup_handlers_add(C, &window->modalhandlers, menu, WM_HANDLER_ACCEPT_DBL_CLICK); - WM_event_add_mousemove(C); + WM_event_add_mousemove(window); MEM_freeN(pie); } diff --git a/source/blender/editors/interface/interface_region_menu_popup.c b/source/blender/editors/interface/interface_region_menu_popup.c index 560c6146afe..2b6125fc193 100644 --- a/source/blender/editors/interface/interface_region_menu_popup.c +++ b/source/blender/editors/interface/interface_region_menu_popup.c @@ -357,7 +357,7 @@ uiPopupBlockHandle *ui_popup_menu_create( handle->popup = true; UI_popup_handlers_add(C, &window->modalhandlers, handle, 0); - WM_event_add_mousemove(C); + WM_event_add_mousemove(window); } MEM_freeN(pup); @@ -467,7 +467,7 @@ void UI_popup_menu_end(bContext *C, uiPopupMenu *pup) menu->popup = true; UI_popup_handlers_add(C, &window->modalhandlers, menu, 0); - WM_event_add_mousemove(C); + WM_event_add_mousemove(window); MEM_freeN(pup); } @@ -599,7 +599,7 @@ void UI_popup_block_invoke_ex(bContext *C, UI_popup_handlers_add(C, &window->modalhandlers, handle, 0); UI_block_active_only_flagged_buttons(C, handle->region, handle->region->uiblocks.first); - WM_event_add_mousemove(C); + WM_event_add_mousemove(window); } void UI_popup_block_invoke(bContext *C, @@ -633,7 +633,7 @@ void UI_popup_block_ex(bContext *C, UI_popup_handlers_add(C, &window->modalhandlers, handle, 0); UI_block_active_only_flagged_buttons(C, handle->region, handle->region->uiblocks.first); - WM_event_add_mousemove(C); + WM_event_add_mousemove(window); } #if 0 /* UNUSED */ @@ -676,14 +676,10 @@ void UI_popup_block_close(bContext *C, wmWindow *win, uiBlock *block) } } -bool UI_popup_block_name_exists(bContext *C, const char *name) +bool UI_popup_block_name_exists(const bScreen *screen, const char *name) { - bScreen *sc = CTX_wm_screen(C); - uiBlock *block; - ARegion *ar; - - for (ar = sc->regionbase.first; ar; ar = ar->next) { - for (block = ar->uiblocks.first; block; block = block->next) { + for (const ARegion *ar = screen->regionbase.first; ar; ar = ar->next) { + for (const uiBlock *block = ar->uiblocks.first; block; block = block->next) { if (STREQ(block->name, name)) { return true; } diff --git a/source/blender/editors/interface/interface_region_popover.c b/source/blender/editors/interface/interface_region_popover.c index f412519d655..5e88d48a787 100644 --- a/source/blender/editors/interface/interface_region_popover.c +++ b/source/blender/editors/interface/interface_region_popover.c @@ -284,7 +284,7 @@ uiPopupBlockHandle *ui_popover_panel_create( * add a modal handler and pass on events. */ if (!but) { UI_popup_handlers_add(C, &window->modalhandlers, handle, 0); - WM_event_add_mousemove(C); + WM_event_add_mousemove(window); handle->popup = true; } @@ -403,7 +403,7 @@ void UI_popover_end(bContext *C, uiPopover *pup, wmKeyMap *keymap) /* Add handlers. */ UI_popup_handlers_add(C, &window->modalhandlers, handle, 0); - WM_event_add_mousemove(C); + WM_event_add_mousemove(window); handle->popup = true; /* Re-add so it gets priority. */ diff --git a/source/blender/editors/interface/interface_region_popup.c b/source/blender/editors/interface/interface_region_popup.c index 462f4871764..b509f5e352b 100644 --- a/source/blender/editors/interface/interface_region_popup.c +++ b/source/blender/editors/interface/interface_region_popup.c @@ -706,15 +706,6 @@ uiBlock *ui_popup_block_refresh(bContext *C, } } else { - /* Add an offset to draw the popover arrow. */ - if ((block->flag & UI_BLOCK_POPOVER) && ELEM(block->direction, UI_DIR_UP, UI_DIR_DOWN)) { - /* Keep sync with 'ui_draw_popover_back_impl'. */ - const float unit_size = U.widget_unit / block->aspect; - const float unit_half = unit_size * (block->direction == UI_DIR_DOWN ? 0.5 : -0.5); - - UI_block_translate(block, 0, -unit_half); - } - /* clip block with window boundary */ ui_popup_block_clip(window, block); diff --git a/source/blender/editors/interface/view2d_ops.c b/source/blender/editors/interface/view2d_ops.c index 527c23e4588..10d327cb2ba 100644 --- a/source/blender/editors/interface/view2d_ops.c +++ b/source/blender/editors/interface/view2d_ops.c @@ -188,7 +188,7 @@ static void view_pan_apply_ex(bContext *C, v2dViewPanData *vpd, float dx, float ED_region_tag_redraw_no_rebuild(vpd->ar); /* request updates to be done... */ - WM_event_add_mousemove(C); + WM_event_add_mousemove(CTX_wm_window(C)); UI_view2d_sync(vpd->sc, vpd->sa, v2d, V2D_LOCK_COPY); } @@ -1592,6 +1592,7 @@ void UI_view2d_smooth_view(bContext *C, ARegion *ar, const rctf *cur, const int /* only meant for timer usage */ static int view2d_smoothview_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event) { + wmWindow *win = CTX_wm_window(C); ARegion *ar = CTX_wm_region(C); View2D *v2d = &ar->v2d; struct SmoothView2DStore *sms = v2d->sms; @@ -1616,11 +1617,11 @@ static int view2d_smoothview_invoke(bContext *C, wmOperator *UNUSED(op), const w MEM_freeN(v2d->sms); v2d->sms = NULL; - WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), v2d->smooth_timer); + WM_event_remove_timer(CTX_wm_manager(C), win, v2d->smooth_timer); v2d->smooth_timer = NULL; /* Event handling won't know if a UI item has been moved under the pointer. */ - WM_event_add_mousemove(C); + WM_event_add_mousemove(win); } else { /* ease in/out */ |