diff options
author | Hans Goudey <h.goudey@me.com> | 2020-08-12 04:59:16 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2020-08-12 04:59:16 +0300 |
commit | ef11238c743e6985fe325280fb13e05d6ec27378 (patch) | |
tree | 1dd2605a676bee52296535825b99f000a9c255eb /source/blender/windowmanager | |
parent | 1f768bbe4145daed111636ca09dd53b25b8d29b5 (diff) | |
parent | ec5f39208785c1bbe723054ffe69e1ac2ab470dd (diff) |
Merge branch 'master' into property-search-uiproperty-search-ui
Diffstat (limited to 'source/blender/windowmanager')
47 files changed, 536 insertions, 601 deletions
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 3d4c84805f9..07746af4b60 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -16,8 +16,7 @@ * The Original Code is Copyright (C) 2007 Blender Foundation. * All rights reserved. */ -#ifndef __WM_API_H__ -#define __WM_API_H__ +#pragma once /** \file * \ingroup wm @@ -99,7 +98,7 @@ void WM_main(struct bContext *C) ATTR_NORETURN; void WM_init_splash(struct bContext *C); -void WM_init_opengl(struct Main *bmain); +void WM_init_opengl(void); void WM_check(struct bContext *C); void WM_reinit_gizmomap_all(struct Main *bmain); @@ -904,5 +903,3 @@ bool WM_xr_session_state_viewer_pose_matrix_info_get(const wmXrData *xr, #ifdef __cplusplus } #endif - -#endif /* __WM_API_H__ */ diff --git a/source/blender/windowmanager/WM_keymap.h b/source/blender/windowmanager/WM_keymap.h index 53a3fd5ebda..15be21bdbc4 100644 --- a/source/blender/windowmanager/WM_keymap.h +++ b/source/blender/windowmanager/WM_keymap.h @@ -17,8 +17,7 @@ * All rights reserved. */ -#ifndef __WM_KEYMAP_H__ -#define __WM_KEYMAP_H__ +#pragma once /** \file * \ingroup wm @@ -194,5 +193,3 @@ const char *WM_bool_as_string(bool test); #ifdef __cplusplus } #endif - -#endif /* __WM_KEYMAP_H__ */ diff --git a/source/blender/windowmanager/WM_message.h b/source/blender/windowmanager/WM_message.h index 1527d514e9b..25d5bae392b 100644 --- a/source/blender/windowmanager/WM_message.h +++ b/source/blender/windowmanager/WM_message.h @@ -18,9 +18,6 @@ * \ingroup wm */ -#ifndef __WM_MESSAGE_H__ -#define __WM_MESSAGE_H__ +#pragma once #include "message_bus/wm_message_bus.h" - -#endif /* __WM_MESSAGE_H__ */ diff --git a/source/blender/windowmanager/WM_toolsystem.h b/source/blender/windowmanager/WM_toolsystem.h index 163f37be974..13d1666dc95 100644 --- a/source/blender/windowmanager/WM_toolsystem.h +++ b/source/blender/windowmanager/WM_toolsystem.h @@ -13,8 +13,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef __WM_TOOLSYSTEM_H__ -#define __WM_TOOLSYSTEM_H__ +#pragma once /** \file * \ingroup wm @@ -140,5 +139,3 @@ void WM_toolsystem_refresh_screen_all(struct Main *bmain); #ifdef __cplusplus } #endif - -#endif /* __WM_TOOLSYSTEM_API_H__ */ diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index b4b3d0957af..efe600a846a 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -106,8 +106,7 @@ * \endcode */ -#ifndef __WM_TYPES_H__ -#define __WM_TYPES_H__ +#pragma once struct ID; struct ImBuf; @@ -928,5 +927,3 @@ extern struct CLG_LogRef *WM_LOG_MSGBUS_SUB; #ifdef __cplusplus } #endif - -#endif /* __WM_TYPES_H__ */ diff --git a/source/blender/windowmanager/gizmo/WM_gizmo_api.h b/source/blender/windowmanager/gizmo/WM_gizmo_api.h index 1066f009214..a4412ecce5c 100644 --- a/source/blender/windowmanager/gizmo/WM_gizmo_api.h +++ b/source/blender/windowmanager/gizmo/WM_gizmo_api.h @@ -26,8 +26,7 @@ * Only included in WM_api.h */ -#ifndef __WM_GIZMO_API_H__ -#define __WM_GIZMO_API_H__ +#pragma once struct ARegion; struct GHashIterator; @@ -403,5 +402,3 @@ void WM_gizmo_group_refresh(const struct bContext *C, struct wmGizmoGroup *gzgro #ifdef __cplusplus } #endif - -#endif /* __WM_GIZMO_API_H__ */ diff --git a/source/blender/windowmanager/gizmo/WM_gizmo_types.h b/source/blender/windowmanager/gizmo/WM_gizmo_types.h index 5def7f8d2f9..bddf54b846f 100644 --- a/source/blender/windowmanager/gizmo/WM_gizmo_types.h +++ b/source/blender/windowmanager/gizmo/WM_gizmo_types.h @@ -26,8 +26,7 @@ * Only included in WM_types.h and lower level files. */ -#ifndef __WM_GIZMO_TYPES_H__ -#define __WM_GIZMO_TYPES_H__ +#pragma once #include "BLI_compiler_attrs.h" @@ -513,5 +512,3 @@ typedef enum eWM_GizmoFlagMapDrawStep { #ifdef __cplusplus } #endif - -#endif /* __WM_GIZMO_TYPES_H__ */ diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo.c b/source/blender/windowmanager/gizmo/intern/wm_gizmo.c index 90d9ba45637..87cb4d5f584 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo.c +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo.c @@ -452,9 +452,7 @@ bool wm_gizmo_select_and_highlight(bContext *C, wmGizmoMap *gzmap, wmGizmo *gz) wm_gizmomap_highlight_set(gzmap, C, gz, gz->highlight_part); return true; } - else { - return false; - } + return false; } /** diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c b/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c index 67f30f0d7ee..b64d544962d 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c @@ -166,12 +166,10 @@ int WM_gizmo_cmp_temp_fl(const void *gz_a_ptr, const void *gz_b_ptr) if (gz_a->temp.f < gz_b->temp.f) { return -1; } - else if (gz_a->temp.f > gz_b->temp.f) { + if (gz_a->temp.f > gz_b->temp.f) { return 1; } - else { - return 0; - } + return 0; } int WM_gizmo_cmp_temp_fl_reverse(const void *gz_a_ptr, const void *gz_b_ptr) @@ -181,12 +179,10 @@ int WM_gizmo_cmp_temp_fl_reverse(const void *gz_a_ptr, const void *gz_b_ptr) if (gz_a->temp.f < gz_b->temp.f) { return 1; } - else if (gz_a->temp.f > gz_b->temp.f) { + if (gz_a->temp.f > gz_b->temp.f) { return -1; } - else { - return 0; - } + return 0; } static bool wm_gizmo_keymap_uses_event_modifier(wmWindowManager *wm, @@ -396,10 +392,9 @@ static int gizmo_select_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSE return OPERATOR_FINISHED; } - else { - BLI_assert(0); - return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH); - } + + BLI_assert(0); + return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH); } void GIZMOGROUP_OT_gizmo_select(wmOperatorType *ot) @@ -476,9 +471,7 @@ static bool gizmo_tweak_start_and_finish( } return true; } - else { - return false; - } + return false; } static void gizmo_tweak_finish(bContext *C, wmOperator *op, const bool cancel, bool clear_modal) diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_intern.h b/source/blender/windowmanager/gizmo/intern/wm_gizmo_intern.h index 00df6edef22..953722f28e9 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_intern.h +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_intern.h @@ -18,8 +18,7 @@ * \ingroup wm */ -#ifndef __WM_GIZMO_INTERN_H__ -#define __WM_GIZMO_INTERN_H__ +#pragma once struct BLI_Buffer; struct wmGizmoMap; @@ -142,5 +141,3 @@ bool wm_gizmomap_deselect_all(struct wmGizmoMap *gzmap); void wm_gizmomap_select_array_shrink(struct wmGizmoMap *gzmap, int len_subtract); void wm_gizmomap_select_array_push_back(struct wmGizmoMap *gzmap, wmGizmo *gz); void wm_gizmomap_select_array_remove(struct wmGizmoMap *gzmap, wmGizmo *gz); - -#endif diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c b/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c index 2038a82c9fd..cecd324ff28 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c @@ -263,11 +263,10 @@ bool WM_gizmomap_minmax(const wmGizmoMap *gzmap, } return i != 0; } - else { - bool ok = false; - BLI_assert(!"TODO"); - return ok; - } + + bool ok = false; + BLI_assert(!"TODO"); + return ok; } /** @@ -647,10 +646,9 @@ static int gizmo_find_intersected_3d_intern(wmGizmo **visible_gizmos, } return hit_found; } - else { - const uint *hit_near = GPU_select_buffer_near(buffer, hits); - return hit_near ? hit_near[3] : -1; - } + + const uint *hit_near = GPU_select_buffer_near(buffer, hits); + return hit_near ? hit_near[3] : -1; } /** diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_target_props.c b/source/blender/windowmanager/gizmo/intern/wm_gizmo_target_props.c index 2dc03d1419c..b056ed40943 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_target_props.c +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_target_props.c @@ -70,9 +70,7 @@ wmGizmoProperty *WM_gizmo_target_property_find(wmGizmo *gz, const char *idname) if (index != -1) { return WM_gizmo_target_property_at_index(gz, index); } - else { - return NULL; - } + return NULL; } void WM_gizmo_target_property_def_rna_ptr(wmGizmo *gz, @@ -195,9 +193,7 @@ float WM_gizmo_target_property_float_get(const wmGizmo *gz, wmGizmoProperty *gz_ if (gz_prop->index == -1) { return RNA_property_float_get(&gz_prop->ptr, gz_prop->prop); } - else { - return RNA_property_float_get_index(&gz_prop->ptr, gz_prop->prop, gz_prop->index); - } + return RNA_property_float_get_index(&gz_prop->ptr, gz_prop->prop, gz_prop->index); } void WM_gizmo_target_property_float_set(bContext *C, @@ -255,9 +251,7 @@ bool WM_gizmo_target_property_float_range_get(const wmGizmo *gz, gz_prop->custom_func.range_get_fn(gz, gz_prop, range); return true; } - else { - return false; - } + return false; } float step, precision; diff --git a/source/blender/windowmanager/gizmo/wm_gizmo_fn.h b/source/blender/windowmanager/gizmo/wm_gizmo_fn.h index 00a3f476bac..418e848e35b 100644 --- a/source/blender/windowmanager/gizmo/wm_gizmo_fn.h +++ b/source/blender/windowmanager/gizmo/wm_gizmo_fn.h @@ -20,8 +20,7 @@ * Callback function definitions, needed for both Types & API headers. */ -#ifndef __WM_GIZMO_FN_H__ -#define __WM_GIZMO_FN_H__ +#pragma once #include "BLI_compiler_attrs.h" @@ -92,5 +91,3 @@ typedef struct wmGizmoPropertyFnParams { #ifdef __cplusplus } #endif - -#endif /* __WM_GIZMO_FN_H__ */ diff --git a/source/blender/windowmanager/gizmo/wm_gizmo_wmapi.h b/source/blender/windowmanager/gizmo/wm_gizmo_wmapi.h index edded4c7620..18b3f40aba6 100644 --- a/source/blender/windowmanager/gizmo/wm_gizmo_wmapi.h +++ b/source/blender/windowmanager/gizmo/wm_gizmo_wmapi.h @@ -28,8 +28,7 @@ * Only included in wm.h and lower level files. */ -#ifndef __WM_GIZMO_WMAPI_H__ -#define __WM_GIZMO_WMAPI_H__ +#pragma once struct wmEventHandler_Gizmo; struct wmEventHandler_Op; @@ -99,5 +98,3 @@ void wm_gizmomaptypes_free(void); #ifdef __cplusplus } #endif - -#endif /* __WM_GIZMO_WMAPI_H__ */ diff --git a/source/blender/windowmanager/intern/wm.c b/source/blender/windowmanager/intern/wm.c index 2112477e62a..43c08a2b980 100644 --- a/source/blender/windowmanager/intern/wm.c +++ b/source/blender/windowmanager/intern/wm.c @@ -293,7 +293,7 @@ void WM_keyconfig_init(bContext *C) /* initialize only after python init is done, for keymaps that * use python operators */ - if (CTX_py_init_get(C) && (wm->initialized & WM_KEYCONFIG_IS_INITIALIZED) == 0) { + if (CTX_py_init_get(C) && (wm->initialized & WM_KEYCONFIG_IS_INIT) == 0) { /* create default key config, only initialize once, * it's persistent across sessions */ if (!(wm->defaultconf->flag & KEYCONF_INIT_DEFAULT)) { @@ -308,7 +308,7 @@ void WM_keyconfig_init(bContext *C) WM_keyconfig_update_tag(NULL, NULL); WM_keyconfig_update(wm); - wm->initialized |= WM_KEYCONFIG_IS_INITIALIZED; + wm->initialized |= WM_KEYCONFIG_IS_INIT; } } @@ -334,7 +334,7 @@ void WM_check(bContext *C) if (!G.background) { /* case: fileread */ - if ((wm->initialized & WM_WINDOW_IS_INITIALIZED) == 0) { + if ((wm->initialized & WM_WINDOW_IS_INIT) == 0) { WM_keyconfig_init(C); WM_autosave_init(wm); } @@ -345,9 +345,9 @@ void WM_check(bContext *C) /* case: fileread */ /* note: this runs in bg mode to set the screen context cb */ - if ((wm->initialized & WM_WINDOW_IS_INITIALIZED) == 0) { - ED_screens_initialize(bmain, wm); - wm->initialized |= WM_WINDOW_IS_INITIALIZED; + if ((wm->initialized & WM_WINDOW_IS_INIT) == 0) { + ED_screens_init(bmain, wm); + wm->initialized |= WM_WINDOW_IS_INIT; } } diff --git a/source/blender/windowmanager/intern/wm_cursors.c b/source/blender/windowmanager/intern/wm_cursors.c index 2af68956923..8e89c08a831 100644 --- a/source/blender/windowmanager/intern/wm_cursors.c +++ b/source/blender/windowmanager/intern/wm_cursors.c @@ -121,7 +121,7 @@ static GHOST_TStandardCursor convert_to_ghost_standard_cursor(WMCursorType curs) } static void window_set_custom_cursor( - wmWindow *win, const uchar mask[16][2], uchar bitmap[16][2], int hotx, int hoty) + wmWindow *win, const uchar mask[16][2], const uchar bitmap[16][2], int hotx, int hoty) { GHOST_SetCustomCursorShape( win->ghostwin, (GHOST_TUns8 *)bitmap, (GHOST_TUns8 *)mask, 16, 16, hotx, hoty, true); @@ -319,15 +319,15 @@ bool wm_cursor_arrow_move(wmWindow *win, const wmEvent *event) wm_cursor_warp_relative(win, 0, fac); return 1; } - else if (event->type == EVT_DOWNARROWKEY) { + if (event->type == EVT_DOWNARROWKEY) { wm_cursor_warp_relative(win, 0, -fac); return 1; } - else if (event->type == EVT_LEFTARROWKEY) { + if (event->type == EVT_LEFTARROWKEY) { wm_cursor_warp_relative(win, -fac, 0); return 1; } - else if (event->type == EVT_RIGHTARROWKEY) { + if (event->type == EVT_RIGHTARROWKEY) { wm_cursor_warp_relative(win, fac, 0); return 1; } diff --git a/source/blender/windowmanager/intern/wm_dragdrop.c b/source/blender/windowmanager/intern/wm_dragdrop.c index 5f13adcb971..ec18a401fa4 100644 --- a/source/blender/windowmanager/intern/wm_dragdrop.c +++ b/source/blender/windowmanager/intern/wm_dragdrop.c @@ -296,7 +296,7 @@ void WM_drag_add_ID(wmDrag *drag, ID *id, ID *from_parent) } return; } - else if (GS(drag_id->id->name) != GS(id->name)) { + if (GS(drag_id->id->name) != GS(id->name)) { BLI_assert(!"All dragged IDs must have the same type"); return; } @@ -355,7 +355,7 @@ static const char *wm_drag_name(wmDrag *drag) if (single) { return id->name + 2; } - else if (id) { + if (id) { return BKE_idtype_idcode_to_name_plural(GS(id->name)); } break; diff --git a/source/blender/windowmanager/intern/wm_draw.c b/source/blender/windowmanager/intern/wm_draw.c index 16454e473cc..b8cb5432a49 100644 --- a/source/blender/windowmanager/intern/wm_draw.c +++ b/source/blender/windowmanager/intern/wm_draw.c @@ -51,7 +51,7 @@ #include "ED_screen.h" #include "ED_view3d.h" -#include "GPU_draw.h" +#include "GPU_context.h" #include "GPU_framebuffer.h" #include "GPU_immediate.h" #include "GPU_state.h" @@ -207,7 +207,7 @@ static bool wm_draw_region_stereo_set(Main *bmain, if (region->regiontype == RGN_TYPE_PREVIEW) { return true; } - else if (region->regiontype == RGN_TYPE_WINDOW) { + if (region->regiontype == RGN_TYPE_WINDOW) { return (sseq->draw_flag & SEQ_DRAW_BACKDROP) != 0; } } @@ -520,9 +520,7 @@ GPUTexture *wm_draw_region_texture(ARegion *region, int view) if (viewport) { return GPU_viewport_color_texture(viewport, view); } - else { - return GPU_offscreen_color_texture(region->draw_buffer->offscreen); - } + return GPU_offscreen_color_texture(region->draw_buffer->offscreen); } void wm_draw_region_blend(ARegion *region, int view, bool blend) @@ -572,8 +570,8 @@ void wm_draw_region_blend(ARegion *region, int view, bool blend) } /* Not the same layout as rectf/recti. */ - float rectt[4] = {rect_tex.xmin, rect_tex.ymin, rect_tex.xmax, rect_tex.ymax}; - float rectg[4] = {rect_geo.xmin, rect_geo.ymin, rect_geo.xmax, rect_geo.ymax}; + const float rectt[4] = {rect_tex.xmin, rect_tex.ymin, rect_tex.xmax, rect_tex.ymax}; + const float rectg[4] = {rect_geo.xmin, rect_geo.ymin, rect_geo.xmax, rect_geo.ymax}; if (blend) { /* GL_ONE because regions drawn offscreen have premultiplied alpha. */ @@ -999,7 +997,8 @@ void wm_draw_update(bContext *C) wmWindowManager *wm = CTX_wm_manager(C); wmWindow *win; - GPU_free_unused_buffers(); + GPU_context_main_lock(); + BKE_image_free_unused_gpu_textures(); for (win = wm->windows.first; win; win = win->next) { #ifdef WIN32 @@ -1036,6 +1035,8 @@ void wm_draw_update(bContext *C) /* Draw non-windows (surfaces) */ wm_surfaces_iter(C, wm_draw_surface); + + GPU_context_main_unlock(); } void wm_draw_region_clear(wmWindow *win, ARegion *UNUSED(region)) diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 05ef4bfac30..bea4faa779a 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -387,6 +387,18 @@ void wm_event_do_refresh_wm_and_depsgraph(bContext *C) CTX_wm_window_set(C, NULL); } +static void wm_event_execute_timers(bContext *C) +{ + wmWindowManager *wm = CTX_wm_manager(C); + + /* Set the first window as context, so that there is some minimal context. This avoids crashes + * when calling code that assumes that there is always a window in the context (which many + * operators do). */ + CTX_wm_window_set(C, wm->windows.first); + BLI_timer_execute(); + CTX_wm_window_set(C, NULL); +} + /* called in mainloop */ void wm_event_do_notifiers(bContext *C) { @@ -398,7 +410,7 @@ void wm_event_do_notifiers(bContext *C) return; } - BLI_timer_execute(); + wm_event_execute_timers(C); /* disable? - keep for now since its used for window level notifiers. */ #if 1 @@ -597,7 +609,7 @@ static int wm_handler_ui_call(bContext *C, if (is_wheel) { return WM_HANDLER_CONTINUE; } - else if (wm_event_always_pass(event) == 0) { + if (wm_event_always_pass(event) == 0) { do_wheel_ui = true; } } @@ -783,7 +795,7 @@ bool WM_operator_poll(bContext *C, wmOperatorType *ot) if (ot->pyop_poll) { return ot->pyop_poll(C, ot); } - else if (ot->poll) { + if (ot->poll) { return ot->poll(C); } @@ -1095,7 +1107,7 @@ bool WM_operator_repeat_check(const bContext *UNUSED(C), wmOperator *op) if (op->type->exec != NULL) { return true; } - else if (op->opm) { + if (op->opm) { /* for macros, check all have exec() we can call */ wmOperatorTypeMacro *otmacro; for (otmacro = op->opm->type->macro.first; otmacro; otmacro = otmacro->next) { @@ -1816,10 +1828,10 @@ static bool wm_eventmatch(const wmEvent *winevent, const wmKeyMapItem *kmi) /* tablet events can occur on hover + keypress */ return false; } - else if ((kmitype == TABLET_STYLUS) && (wmtab->active != EVT_TABLET_STYLUS)) { + if ((kmitype == TABLET_STYLUS) && (wmtab->active != EVT_TABLET_STYLUS)) { return false; } - else if ((kmitype == TABLET_ERASER) && (wmtab->active != EVT_TABLET_ERASER)) { + if ((kmitype == TABLET_ERASER) && (wmtab->active != EVT_TABLET_ERASER)) { return false; } } @@ -2434,13 +2446,11 @@ static int wm_handlers_do_keymap_with_keymap_handler( } break; } + if (action & WM_HANDLER_HANDLED) { + CLOG_INFO(WM_LOG_HANDLERS, 2, "handled - and pass on! '%s'", kmi->idname); + } else { - if (action & WM_HANDLER_HANDLED) { - CLOG_INFO(WM_LOG_HANDLERS, 2, "handled - and pass on! '%s'", kmi->idname); - } - else { - CLOG_INFO(WM_LOG_HANDLERS, 2, "un-handled '%s'", kmi->idname); - } + CLOG_INFO(WM_LOG_HANDLERS, 2, "un-handled '%s'", kmi->idname); } } } @@ -2492,16 +2502,14 @@ static int wm_handlers_do_keymap_with_gizmo_handler( } break; } - else { - if (action & WM_HANDLER_HANDLED) { - if (G.debug & (G_DEBUG_EVENTS | G_DEBUG_HANDLERS)) { - printf("%s: handled - and pass on! '%s'\n", __func__, kmi->idname); - } - } - else { - PRINT("%s: un-handled '%s'\n", __func__, kmi->idname); + if (action & WM_HANDLER_HANDLED) { + if (G.debug & (G_DEBUG_EVENTS | G_DEBUG_HANDLERS)) { + printf("%s: handled - and pass on! '%s'\n", __func__, kmi->idname); } } + else { + PRINT("%s: un-handled '%s'\n", __func__, kmi->idname); + } } } } @@ -3126,13 +3134,9 @@ static bool wm_event_pie_filter(wmWindow *win, const wmEvent *event) win->lock_pie_event = EVENT_NONE; return false; } - else { - return true; - } - } - else { - return false; + return true; } + return false; } /** @@ -3692,10 +3696,8 @@ wmKeyMap *WM_event_get_keymap_from_toolsystem_fallback(wmWindowManager *wm, handler->keymap_tool = area->runtime.tool; return km; } - else { - printf( - "Keymap: '%s' not found for tool '%s'\n", tref_rt->keymap, area->runtime.tool->idname); - } + printf( + "Keymap: '%s' not found for tool '%s'\n", tref_rt->keymap, area->runtime.tool->idname); } } return NULL; @@ -3716,10 +3718,8 @@ wmKeyMap *WM_event_get_keymap_from_toolsystem(wmWindowManager *wm, wmEventHandle handler->keymap_tool = area->runtime.tool; return km; } - else { - printf( - "Keymap: '%s' not found for tool '%s'\n", tref_rt->keymap, area->runtime.tool->idname); - } + printf( + "Keymap: '%s' not found for tool '%s'\n", tref_rt->keymap, area->runtime.tool->idname); } } return NULL; @@ -3775,12 +3775,10 @@ static bool event_or_prev_in_rect(const wmEvent *event, const rcti *rect) if (BLI_rcti_isect_pt(rect, event->x, event->y)) { return true; } - else if (event->type == MOUSEMOVE && BLI_rcti_isect_pt(rect, event->prevx, event->prevy)) { + if (event->type == MOUSEMOVE && BLI_rcti_isect_pt(rect, event->prevx, event->prevy)) { return true; } - else { - return false; - } + return false; } static bool handler_region_v2d_mask_test(const ARegion *region, const wmEvent *event) @@ -3966,138 +3964,137 @@ static int convert_key(GHOST_TKey key) if (key >= GHOST_kKeyA && key <= GHOST_kKeyZ) { return (EVT_AKEY + ((int)key - GHOST_kKeyA)); } - else if (key >= GHOST_kKey0 && key <= GHOST_kKey9) { + if (key >= GHOST_kKey0 && key <= GHOST_kKey9) { return (EVT_ZEROKEY + ((int)key - GHOST_kKey0)); } - else if (key >= GHOST_kKeyNumpad0 && key <= GHOST_kKeyNumpad9) { + if (key >= GHOST_kKeyNumpad0 && key <= GHOST_kKeyNumpad9) { return (EVT_PAD0 + ((int)key - GHOST_kKeyNumpad0)); } - else if (key >= GHOST_kKeyF1 && key <= GHOST_kKeyF24) { + if (key >= GHOST_kKeyF1 && key <= GHOST_kKeyF24) { return (EVT_F1KEY + ((int)key - GHOST_kKeyF1)); } - else { - switch (key) { - case GHOST_kKeyBackSpace: - return EVT_BACKSPACEKEY; - case GHOST_kKeyTab: - return EVT_TABKEY; - case GHOST_kKeyLinefeed: - return EVT_LINEFEEDKEY; - case GHOST_kKeyClear: - return 0; - case GHOST_kKeyEnter: - return EVT_RETKEY; - - case GHOST_kKeyEsc: - return EVT_ESCKEY; - case GHOST_kKeySpace: - return EVT_SPACEKEY; - case GHOST_kKeyQuote: - return EVT_QUOTEKEY; - case GHOST_kKeyComma: - return EVT_COMMAKEY; - case GHOST_kKeyMinus: - return EVT_MINUSKEY; - case GHOST_kKeyPlus: - return EVT_PLUSKEY; - case GHOST_kKeyPeriod: - return EVT_PERIODKEY; - case GHOST_kKeySlash: - return EVT_SLASHKEY; - - case GHOST_kKeySemicolon: - return EVT_SEMICOLONKEY; - case GHOST_kKeyEqual: - return EVT_EQUALKEY; - - case GHOST_kKeyLeftBracket: - return EVT_LEFTBRACKETKEY; - case GHOST_kKeyRightBracket: - return EVT_RIGHTBRACKETKEY; - case GHOST_kKeyBackslash: - return EVT_BACKSLASHKEY; - case GHOST_kKeyAccentGrave: - return EVT_ACCENTGRAVEKEY; - - case GHOST_kKeyLeftShift: - return EVT_LEFTSHIFTKEY; - case GHOST_kKeyRightShift: - return EVT_RIGHTSHIFTKEY; - case GHOST_kKeyLeftControl: - return EVT_LEFTCTRLKEY; - case GHOST_kKeyRightControl: - return EVT_RIGHTCTRLKEY; - case GHOST_kKeyOS: - return EVT_OSKEY; - case GHOST_kKeyLeftAlt: - return EVT_LEFTALTKEY; - case GHOST_kKeyRightAlt: - return EVT_RIGHTALTKEY; - case GHOST_kKeyApp: - return EVT_APPKEY; - - case GHOST_kKeyCapsLock: - return EVT_CAPSLOCKKEY; - case GHOST_kKeyNumLock: - return 0; - case GHOST_kKeyScrollLock: - return 0; - - case GHOST_kKeyLeftArrow: - return EVT_LEFTARROWKEY; - case GHOST_kKeyRightArrow: - return EVT_RIGHTARROWKEY; - case GHOST_kKeyUpArrow: - return EVT_UPARROWKEY; - case GHOST_kKeyDownArrow: - return EVT_DOWNARROWKEY; - - case GHOST_kKeyPrintScreen: - return 0; - case GHOST_kKeyPause: - return EVT_PAUSEKEY; - - case GHOST_kKeyInsert: - return EVT_INSERTKEY; - case GHOST_kKeyDelete: - return EVT_DELKEY; - case GHOST_kKeyHome: - return EVT_HOMEKEY; - case GHOST_kKeyEnd: - return EVT_ENDKEY; - case GHOST_kKeyUpPage: - return EVT_PAGEUPKEY; - case GHOST_kKeyDownPage: - return EVT_PAGEDOWNKEY; - - case GHOST_kKeyNumpadPeriod: - return EVT_PADPERIOD; - case GHOST_kKeyNumpadEnter: - return EVT_PADENTER; - case GHOST_kKeyNumpadPlus: - return EVT_PADPLUSKEY; - case GHOST_kKeyNumpadMinus: - return EVT_PADMINUS; - case GHOST_kKeyNumpadAsterisk: - return EVT_PADASTERKEY; - case GHOST_kKeyNumpadSlash: - return EVT_PADSLASHKEY; - - case GHOST_kKeyGrLess: - return EVT_GRLESSKEY; - - case GHOST_kKeyMediaPlay: - return EVT_MEDIAPLAY; - case GHOST_kKeyMediaStop: - return EVT_MEDIASTOP; - case GHOST_kKeyMediaFirst: - return EVT_MEDIAFIRST; - case GHOST_kKeyMediaLast: - return EVT_MEDIALAST; - - default: - return EVT_UNKNOWNKEY; /* GHOST_kKeyUnknown */ - } + + switch (key) { + case GHOST_kKeyBackSpace: + return EVT_BACKSPACEKEY; + case GHOST_kKeyTab: + return EVT_TABKEY; + case GHOST_kKeyLinefeed: + return EVT_LINEFEEDKEY; + case GHOST_kKeyClear: + return 0; + case GHOST_kKeyEnter: + return EVT_RETKEY; + + case GHOST_kKeyEsc: + return EVT_ESCKEY; + case GHOST_kKeySpace: + return EVT_SPACEKEY; + case GHOST_kKeyQuote: + return EVT_QUOTEKEY; + case GHOST_kKeyComma: + return EVT_COMMAKEY; + case GHOST_kKeyMinus: + return EVT_MINUSKEY; + case GHOST_kKeyPlus: + return EVT_PLUSKEY; + case GHOST_kKeyPeriod: + return EVT_PERIODKEY; + case GHOST_kKeySlash: + return EVT_SLASHKEY; + + case GHOST_kKeySemicolon: + return EVT_SEMICOLONKEY; + case GHOST_kKeyEqual: + return EVT_EQUALKEY; + + case GHOST_kKeyLeftBracket: + return EVT_LEFTBRACKETKEY; + case GHOST_kKeyRightBracket: + return EVT_RIGHTBRACKETKEY; + case GHOST_kKeyBackslash: + return EVT_BACKSLASHKEY; + case GHOST_kKeyAccentGrave: + return EVT_ACCENTGRAVEKEY; + + case GHOST_kKeyLeftShift: + return EVT_LEFTSHIFTKEY; + case GHOST_kKeyRightShift: + return EVT_RIGHTSHIFTKEY; + case GHOST_kKeyLeftControl: + return EVT_LEFTCTRLKEY; + case GHOST_kKeyRightControl: + return EVT_RIGHTCTRLKEY; + case GHOST_kKeyOS: + return EVT_OSKEY; + case GHOST_kKeyLeftAlt: + return EVT_LEFTALTKEY; + case GHOST_kKeyRightAlt: + return EVT_RIGHTALTKEY; + case GHOST_kKeyApp: + return EVT_APPKEY; + + case GHOST_kKeyCapsLock: + return EVT_CAPSLOCKKEY; + case GHOST_kKeyNumLock: + return 0; + case GHOST_kKeyScrollLock: + return 0; + + case GHOST_kKeyLeftArrow: + return EVT_LEFTARROWKEY; + case GHOST_kKeyRightArrow: + return EVT_RIGHTARROWKEY; + case GHOST_kKeyUpArrow: + return EVT_UPARROWKEY; + case GHOST_kKeyDownArrow: + return EVT_DOWNARROWKEY; + + case GHOST_kKeyPrintScreen: + return 0; + case GHOST_kKeyPause: + return EVT_PAUSEKEY; + + case GHOST_kKeyInsert: + return EVT_INSERTKEY; + case GHOST_kKeyDelete: + return EVT_DELKEY; + case GHOST_kKeyHome: + return EVT_HOMEKEY; + case GHOST_kKeyEnd: + return EVT_ENDKEY; + case GHOST_kKeyUpPage: + return EVT_PAGEUPKEY; + case GHOST_kKeyDownPage: + return EVT_PAGEDOWNKEY; + + case GHOST_kKeyNumpadPeriod: + return EVT_PADPERIOD; + case GHOST_kKeyNumpadEnter: + return EVT_PADENTER; + case GHOST_kKeyNumpadPlus: + return EVT_PADPLUSKEY; + case GHOST_kKeyNumpadMinus: + return EVT_PADMINUS; + case GHOST_kKeyNumpadAsterisk: + return EVT_PADASTERKEY; + case GHOST_kKeyNumpadSlash: + return EVT_PADSLASHKEY; + + case GHOST_kKeyGrLess: + return EVT_GRLESSKEY; + + case GHOST_kKeyMediaPlay: + return EVT_MEDIAPLAY; + case GHOST_kKeyMediaStop: + return EVT_MEDIASTOP; + case GHOST_kKeyMediaFirst: + return EVT_MEDIAFIRST; + case GHOST_kKeyMediaLast: + return EVT_MEDIALAST; + + default: + return EVT_UNKNOWNKEY; /* GHOST_kKeyUnknown */ } } diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index f431a6f431b..ef4f2b4a62a 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -258,7 +258,7 @@ static void wm_window_match_keep_current_wm(const bContext *C, bScreen *screen = NULL; /* match oldwm to new dbase, only old files */ - wm->initialized &= ~WM_WINDOW_IS_INITIALIZED; + wm->initialized &= ~WM_WINDOW_IS_INIT; /* when loading without UI, no matching needed */ if (load_ui && (screen = CTX_wm_screen(C))) { @@ -1404,10 +1404,8 @@ bool write_crash_blend(void) printf("written: %s\n", path); return 1; } - else { - printf("failed: %s\n", path); - return 0; - } + printf("failed: %s\n", path); + return 0; } /** @@ -2091,9 +2089,7 @@ static int wm_homefile_read_invoke(bContext *C, wmOperator *op, const wmEvent *U wm_close_file_dialog(C, callback); return OPERATOR_INTERFACE; } - else { - return wm_homefile_read_exec(C, op); - } + return wm_homefile_read_exec(C, op); } static void read_homefile_props(wmOperatorType *ot) @@ -2255,9 +2251,7 @@ static int wm_open_mainfile__discard_changes(bContext *C, wmOperator *op) wm_close_file_dialog(C, callback); return OPERATOR_INTERFACE; } - else { - return wm_open_mainfile_dispatch(C, op); - } + return wm_open_mainfile_dispatch(C, op); } static int wm_open_mainfile__select_file_path(bContext *C, wmOperator *op) @@ -2328,9 +2322,7 @@ static int wm_open_mainfile__open(bContext *C, wmOperator *op) ED_view3d_local_collections_reset(C, (G.fileflags & G_FILE_NO_UI) != 0); return OPERATOR_FINISHED; } - else { - return OPERATOR_CANCELLED; - } + return OPERATOR_CANCELLED; } static OperatorDispatchTarget wm_open_mainfile_dispatch_targets[] = { @@ -2475,9 +2467,7 @@ static int wm_revert_mainfile_exec(bContext *C, wmOperator *op) if (success) { return OPERATOR_FINISHED; } - else { - return OPERATOR_CANCELLED; - } + return OPERATOR_CANCELLED; } static bool wm_revert_mainfile_poll(bContext *UNUSED(C)) @@ -2572,9 +2562,7 @@ static int wm_recover_auto_save_exec(bContext *C, wmOperator *op) if (success) { return OPERATOR_FINISHED; } - else { - return OPERATOR_CANCELLED; - } + return OPERATOR_CANCELLED; } static int wm_recover_auto_save_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) diff --git a/source/blender/windowmanager/intern/wm_files_link.c b/source/blender/windowmanager/intern/wm_files_link.c index 31d36603505..6ccc5d79962 100644 --- a/source/blender/windowmanager/intern/wm_files_link.c +++ b/source/blender/windowmanager/intern/wm_files_link.c @@ -357,11 +357,11 @@ static int wm_link_append_exec(bContext *C, wmOperator *op) BKE_reportf(op->reports, RPT_ERROR, "'%s': not a library", path); return OPERATOR_CANCELLED; } - else if (!group) { + if (!group) { BKE_reportf(op->reports, RPT_ERROR, "'%s': nothing indicated", path); return OPERATOR_CANCELLED; } - else if (BLI_path_cmp(BKE_main_blendfile_path(bmain), libname) == 0) { + if (BLI_path_cmp(BKE_main_blendfile_path(bmain), libname) == 0) { BKE_reportf(op->reports, RPT_ERROR, "'%s': cannot use current file as library", path); return OPERATOR_CANCELLED; } @@ -755,7 +755,7 @@ static void lib_relocate_do_remap(Main *bmain, if (c == '.') { break; } - else if (c < '0' || c > '9') { + if (c < '0' || c > '9') { has_num = false; break; } diff --git a/source/blender/windowmanager/intern/wm_gesture.c b/source/blender/windowmanager/intern/wm_gesture.c index 5a66cbd10eb..55233168ab2 100644 --- a/source/blender/windowmanager/intern/wm_gesture.c +++ b/source/blender/windowmanager/intern/wm_gesture.c @@ -324,7 +324,7 @@ static void draw_filled_lasso(wmGesture *gt) int(*mcoords)[2] = MEM_mallocN(sizeof(*mcoords) * (mcoords_len + 1), __func__); int i; rcti rect; - float red[4] = {1.0f, 0.0f, 0.0f, 0.0f}; + const float red[4] = {1.0f, 0.0f, 0.0f, 0.0f}; for (i = 0; i < mcoords_len; i++, lasso += 2) { mcoords[i][0] = lasso[0]; diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index 945d5fd42e4..03e84f098c0 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -59,6 +59,7 @@ #include "BKE_font.h" #include "BKE_global.h" #include "BKE_icons.h" +#include "BKE_image.h" #include "BKE_keyconfig.h" #include "BKE_lib_remap.h" #include "BKE_main.h" @@ -120,7 +121,7 @@ #include "UI_interface.h" #include "UI_resources.h" -#include "GPU_draw.h" +#include "GPU_context.h" #include "GPU_init_exit.h" #include "GPU_material.h" @@ -171,7 +172,7 @@ void WM_init_state_start_with_console_set(bool value) */ static bool opengl_is_init = false; -void WM_init_opengl(Main *bmain) +void WM_init_opengl(void) { /* must be called only once */ BLI_assert(opengl_is_init == false); @@ -185,9 +186,6 @@ void WM_init_opengl(Main *bmain) DRW_opengl_context_create(); GPU_init(); - GPU_set_mipmap(bmain, true); - GPU_set_linear_mipmap(true); - GPU_set_anisotropic(U.anisotropic_filter); GPU_pass_cache_init(); @@ -315,7 +313,7 @@ void WM_init(bContext *C, int argc, const char **argv) /* sets 3D mouse deadzone */ WM_ndof_deadzone_set(U.ndof_deadzone); #endif - WM_init_opengl(G_MAIN); + WM_init_opengl(); if (!WM_platform_support_perform_checks()) { exit(-1); @@ -578,7 +576,7 @@ void WM_exit_ex(bContext *C, const bool do_python) BKE_subdiv_exit(); if (opengl_is_init) { - GPU_free_unused_buffers(); + BKE_image_free_unused_gpu_textures(); } BKE_blender_free(); /* blender.c, does entire library and spacetypes */ @@ -637,6 +635,8 @@ void WM_exit_ex(bContext *C, const bool do_python) RNA_exit(); /* should be after BPY_python_end so struct python slots are cleared */ + GPU_backend_exit(); + wm_ghost_exit(); CTX_free(C); diff --git a/source/blender/windowmanager/intern/wm_jobs.c b/source/blender/windowmanager/intern/wm_jobs.c index 87a19d832c9..c9b125901e7 100644 --- a/source/blender/windowmanager/intern/wm_jobs.c +++ b/source/blender/windowmanager/intern/wm_jobs.c @@ -344,9 +344,7 @@ void *WM_jobs_customdata_get(wmJob *wm_job) if (!wm_job->customdata) { return wm_job->run_customdata; } - else { - return wm_job->customdata; - } + return wm_job->customdata; } void WM_jobs_customdata_set(wmJob *wm_job, void *customdata, void (*free)(void *)) diff --git a/source/blender/windowmanager/intern/wm_keymap.c b/source/blender/windowmanager/intern/wm_keymap.c index d7102a1e8af..d7ff2689a86 100644 --- a/source/blender/windowmanager/intern/wm_keymap.c +++ b/source/blender/windowmanager/intern/wm_keymap.c @@ -321,9 +321,7 @@ bool WM_keyconfig_remove(wmWindowManager *wm, wmKeyConfig *keyconf) return true; } - else { - return false; - } + return false; } void WM_keyconfig_clear(wmKeyConfig *keyconf) @@ -363,7 +361,7 @@ void WM_keyconfig_set_active(wmWindowManager *wm, const char *idname) WM_keyconfig_update(wm); BLI_strncpy(U.keyconfigstr, idname, sizeof(U.keyconfigstr)); - if (wm->initialized & WM_KEYCONFIG_IS_INITIALIZED) { + if (wm->initialized & WM_KEYCONFIG_IS_INIT) { U.runtime.is_dirty = true; } @@ -448,9 +446,7 @@ bool WM_keymap_remove(wmKeyConfig *keyconf, wmKeyMap *keymap) return true; } - else { - return false; - } + return false; } bool WM_keymap_poll(bContext *C, wmKeyMap *keymap) @@ -551,9 +547,7 @@ bool WM_keymap_remove_item(wmKeyMap *keymap, wmKeyMapItem *kmi) WM_keyconfig_update_tag(keymap, NULL); return true; } - else { - return false; - } + return false; } /** \} */ @@ -1122,7 +1116,7 @@ const char *WM_key_event_string(const short type, const bool compact) if (platform == MACOS) { return key_event_glyph_or_text(font_id, IFACE_("Cmd"), "\xe2\x8c\x98"); } - else if (platform == MSWIN) { + if (platform == MSWIN) { return key_event_glyph_or_text(font_id, IFACE_("Win"), "\xe2\x9d\x96"); } return IFACE_("OS"); diff --git a/source/blender/windowmanager/intern/wm_keymap_utils.c b/source/blender/windowmanager/intern/wm_keymap_utils.c index 5ab36b15666..953fb9fed79 100644 --- a/source/blender/windowmanager/intern/wm_keymap_utils.c +++ b/source/blender/windowmanager/intern/wm_keymap_utils.c @@ -217,7 +217,6 @@ wmKeyMap *WM_keymap_guess_opname(const bContext *C, const char *opname) * FLUID_OT * TEXTURE_OT * UI_OT - * VIEW2D_OT * WORLD_OT */ @@ -344,6 +343,10 @@ wmKeyMap *WM_keymap_guess_opname(const bContext *C, const char *opname) break; } } + /* General 2D View, not bound to a specific spacetype. */ + else if (STRPREFIX(opname, "VIEW2D_OT")) { + km = WM_keymap_find_all(wm, "View2D", 0, 0); + } /* Image Editor */ else if (STRPREFIX(opname, "IMAGE_OT")) { km = WM_keymap_find_all(wm, "Image", sl->spacetype, 0); @@ -379,7 +382,25 @@ wmKeyMap *WM_keymap_guess_opname(const bContext *C, const char *opname) } /* Animation Generic - after channels */ else if (STRPREFIX(opname, "ANIM_OT")) { - km = WM_keymap_find_all(wm, "Animation", 0, 0); + if (sl->spacetype == SPACE_VIEW3D) { + switch (CTX_data_mode_enum(C)) { + case CTX_MODE_OBJECT: + km = WM_keymap_find_all(wm, "Object Mode", 0, 0); + break; + case CTX_MODE_POSE: + km = WM_keymap_find_all(wm, "Pose", 0, 0); + break; + default: + break; + } + if (km && !WM_keymap_poll((bContext *)C, km)) { + km = NULL; + } + } + + if (!km) { + km = WM_keymap_find_all(wm, "Animation", 0, 0); + } } /* Graph Editor */ else if (STRPREFIX(opname, "GRAPH_OT")) { diff --git a/source/blender/windowmanager/intern/wm_operator_type.c b/source/blender/windowmanager/intern/wm_operator_type.c index 650d5bbe015..457cd0f16be 100644 --- a/source/blender/windowmanager/intern/wm_operator_type.c +++ b/source/blender/windowmanager/intern/wm_operator_type.c @@ -606,9 +606,7 @@ char *WM_operatortype_description(struct bContext *C, if (description[0]) { return description; } - else { - MEM_freeN(description); - } + MEM_freeN(description); } } @@ -621,9 +619,7 @@ char *WM_operatortype_description(struct bContext *C, if (info && info[0]) { return BLI_strdup(info); } - else { - return NULL; - } + return NULL; } /** \} */ diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index d1f65b6271b..1964813fff9 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -864,19 +864,17 @@ int WM_generic_select_modal(bContext *C, wmOperator *op, const wmEvent *event) } return ret_value | OPERATOR_PASS_THROUGH; } - else { - /* If we are in init phase, and cannot validate init of modal operations, - * just fall back to basic exec. - */ - RNA_property_boolean_set(op->ptr, wait_to_deselect_prop, false); + /* If we are in init phase, and cannot validate init of modal operations, + * just fall back to basic exec. + */ + RNA_property_boolean_set(op->ptr, wait_to_deselect_prop, false); - ret_value = op->type->exec(C, op); - OPERATOR_RETVAL_CHECK(ret_value); + ret_value = op->type->exec(C, op); + OPERATOR_RETVAL_CHECK(ret_value); - return ret_value | OPERATOR_PASS_THROUGH; - } + return ret_value | OPERATOR_PASS_THROUGH; } - else if (event->type == init_event_type && event->val == KM_RELEASE) { + if (event->type == init_event_type && event->val == KM_RELEASE) { RNA_property_boolean_set(op->ptr, wait_to_deselect_prop, false); ret_value = op->type->exec(C, op); @@ -884,7 +882,7 @@ int WM_generic_select_modal(bContext *C, wmOperator *op, const wmEvent *event) return ret_value | OPERATOR_PASS_THROUGH; } - else if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) { + if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) { const int drag_delta[2] = { mval[0] - event->mval[0], mval[1] - event->mval[1], @@ -895,11 +893,9 @@ int WM_generic_select_modal(bContext *C, wmOperator *op, const wmEvent *event) if (WM_event_drag_test_with_delta(event, drag_delta)) { return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH; } - else { - /* Important not to return anything other than PASS_THROUGH here, - * otherwise it prevents underlying tweak detection code to work properly. */ - return OPERATOR_PASS_THROUGH; - } + /* Important not to return anything other than PASS_THROUGH here, + * otherwise it prevents underlying tweak detection code to work properly. */ + return OPERATOR_PASS_THROUGH; } return OPERATOR_RUNNING_MODAL | OPERATOR_PASS_THROUGH; @@ -1151,9 +1147,7 @@ int WM_operator_confirm_or_exec(bContext *C, wmOperator *op, const wmEvent *UNUS if (confirm) { return WM_operator_confirm_message(C, op, NULL); } - else { - return op->type->exec(C, op); - } + return op->type->exec(C, op); } /* op->invoke, opens fileselect if path property not set, otherwise executes */ @@ -1162,10 +1156,8 @@ int WM_operator_filesel(bContext *C, wmOperator *op, const wmEvent *UNUSED(event if (RNA_struct_property_is_set(op->ptr, "filepath")) { return WM_operator_call_notest(C, op); /* call exec direct */ } - else { - WM_event_add_fileselect(C, op); - return OPERATOR_RUNNING_MODAL; - } + WM_event_add_fileselect(C, op); + return OPERATOR_RUNNING_MODAL; } bool WM_operator_filesel_ensure_ext_imtype(wmOperator *op, const struct ImageFormatData *im_format) @@ -2322,7 +2314,7 @@ static void radial_control_paint_curve(uint pos, Brush *br, float radius, int li GPU_line_width(2.0f); immUniformColor4f(0.8f, 0.8f, 0.8f, 0.85f); float step = (radius * 2.0f) / (float)line_segments; - BKE_curvemapping_initialize(br->curve); + BKE_curvemapping_init(br->curve); immBegin(GPU_PRIM_LINES, line_segments * 2); for (int i = 0; i < line_segments; i++) { float h1 = BKE_brush_curve_strength_clamped(br, fabsf((i * step) - radius), radius); @@ -2453,7 +2445,7 @@ static void radial_control_paint_cursor(bContext *UNUSED(C), int x, int y, void imm_draw_circle_wire_2d(pos, 0.0f, 0.0f, r2, 80); if (rmin > 0.0f) { /* Inner fill circle to increase the contrast of the value */ - float black[3] = {0.0f}; + const float black[3] = {0.0f}; immUniformColor3fvAlpha(black, 0.2f); imm_draw_circle_fill_2d(pos, 0.0, 0.0f, rmin, 80); @@ -2536,10 +2528,8 @@ static int radial_control_get_path(PointerRNA *ctx_ptr, if (flags & RC_PROP_ALLOW_MISSING) { return 1; } - else { - BKE_reportf(op->reports, RPT_ERROR, "Could not resolve path '%s'", name); - return 0; - } + BKE_reportf(op->reports, RPT_ERROR, "Could not resolve path '%s'", name); + return 0; } /* check property type */ @@ -2591,13 +2581,12 @@ static int radial_control_get_properties(bContext *C, wmOperator *op) (RC_PROP_ALLOW_MISSING | RC_PROP_REQUIRE_BOOL))) { return 0; } + + if (use_secondary_prop && RNA_property_boolean_get(&use_secondary_ptr, use_secondary_prop)) { + data_path = "data_path_secondary"; + } else { - if (use_secondary_prop && RNA_property_boolean_get(&use_secondary_ptr, use_secondary_prop)) { - data_path = "data_path_secondary"; - } - else { - data_path = "data_path_primary"; - } + data_path = "data_path_primary"; } if (!radial_control_get_path(&ctx_ptr, op, data_path, &rc->ptr, &rc->prop, 0, 0)) { @@ -2664,7 +2653,7 @@ static int radial_control_get_properties(bContext *C, wmOperator *op) if (!radial_control_get_path(&ctx_ptr, op, "image_id", &rc->image_id_ptr, NULL, 0, 0)) { return 0; } - else if (rc->image_id_ptr.data) { + if (rc->image_id_ptr.data) { /* extra check, pointer must be to an ID */ if (!RNA_struct_is_ID(rc->image_id_ptr.type)) { BKE_report(op->reports, RPT_ERROR, "Pointer from path image_id is not an ID"); @@ -2841,171 +2830,169 @@ static int radial_control_modal(bContext *C, wmOperator *op, const wmEvent *even radial_control_update_header(op, C); return OPERATOR_RUNNING_MODAL; } - else { - handled = false; - switch (event->type) { - case EVT_ESCKEY: - case RIGHTMOUSE: - /* canceled; restore original value */ - radial_control_set_value(rc, rc->initial_value); - ret = OPERATOR_CANCELLED; - break; - - case LEFTMOUSE: - case EVT_PADENTER: - case EVT_RETKEY: - /* done; value already set */ - RNA_property_update(C, &rc->ptr, rc->prop); - ret = OPERATOR_FINISHED; - break; - - case MOUSEMOVE: - if (!has_numInput) { - if (rc->slow_mode) { - if (rc->subtype == PROP_ANGLE) { - float position[2] = {event->x, event->y}; - - /* calculate the initial angle here first */ - delta[0] = rc->initial_mouse[0] - rc->slow_mouse[0]; - delta[1] = rc->initial_mouse[1] - rc->slow_mouse[1]; - - /* precision angle gets calculated from dial and gets added later */ - angle_precision = -0.1f * BLI_dial_angle(rc->dial, position); - } - else { - delta[0] = rc->initial_mouse[0] - rc->slow_mouse[0]; - delta[1] = 0.0f; - if (rc->zoom_prop) { - RNA_property_float_get_array(&rc->zoom_ptr, rc->zoom_prop, zoom); - delta[0] /= zoom[0]; - } + handled = false; + switch (event->type) { + case EVT_ESCKEY: + case RIGHTMOUSE: + /* canceled; restore original value */ + radial_control_set_value(rc, rc->initial_value); + ret = OPERATOR_CANCELLED; + break; - dist = len_v2(delta); + case LEFTMOUSE: + case EVT_PADENTER: + case EVT_RETKEY: + /* done; value already set */ + RNA_property_update(C, &rc->ptr, rc->prop); + ret = OPERATOR_FINISHED; + break; - delta[0] = event->x - rc->slow_mouse[0]; + case MOUSEMOVE: + if (!has_numInput) { + if (rc->slow_mode) { + if (rc->subtype == PROP_ANGLE) { + const float position[2] = {event->x, event->y}; - if (rc->zoom_prop) { - delta[0] /= zoom[0]; - } + /* calculate the initial angle here first */ + delta[0] = rc->initial_mouse[0] - rc->slow_mouse[0]; + delta[1] = rc->initial_mouse[1] - rc->slow_mouse[1]; - dist = dist + 0.1f * (delta[0]); - } + /* precision angle gets calculated from dial and gets added later */ + angle_precision = -0.1f * BLI_dial_angle(rc->dial, position); } else { - delta[0] = rc->initial_mouse[0] - event->x; - delta[1] = rc->initial_mouse[1] - event->y; + delta[0] = rc->initial_mouse[0] - rc->slow_mouse[0]; + delta[1] = 0.0f; + if (rc->zoom_prop) { RNA_property_float_get_array(&rc->zoom_ptr, rc->zoom_prop, zoom); delta[0] /= zoom[0]; - delta[1] /= zoom[1]; } - if (rc->subtype == PROP_ANGLE) { - dist = len_v2(delta); - } - else { - dist = clamp_f(-delta[0], 0.0f, FLT_MAX); + + dist = len_v2(delta); + + delta[0] = event->x - rc->slow_mouse[0]; + + if (rc->zoom_prop) { + delta[0] /= zoom[0]; } - } - /* calculate new value and apply snapping */ - switch (rc->subtype) { - case PROP_NONE: - case PROP_DISTANCE: - case PROP_PIXEL: - new_value = dist; - if (snap) { - new_value = ((int)new_value + 5) / 10 * 10; - } - break; - case PROP_PERCENTAGE: - new_value = ((dist - WM_RADIAL_CONTROL_DISPLAY_MIN_SIZE) / - WM_RADIAL_CONTROL_DISPLAY_WIDTH) * - 100.0f; - if (snap) { - new_value = ((int)(new_value + 2.5f)) / 5 * 5; - } - break; - case PROP_FACTOR: - new_value = (WM_RADIAL_CONTROL_DISPLAY_SIZE - dist) / - WM_RADIAL_CONTROL_DISPLAY_WIDTH; - if (snap) { - new_value = ((int)ceil(new_value * 10.f) * 10.0f) / 100.f; - } - /* Invert new value to increase the factor moving the mouse to the right */ - new_value = 1 - new_value; - break; - case PROP_ANGLE: - new_value = atan2f(delta[1], delta[0]) + (float)M_PI + angle_precision; - new_value = fmod(new_value, 2.0f * (float)M_PI); - if (new_value < 0.0f) { - new_value += 2.0f * (float)M_PI; - } - if (snap) { - new_value = DEG2RADF(((int)RAD2DEGF(new_value) + 5) / 10 * 10); - } - break; - default: - new_value = dist; /* dummy value, should this ever happen? - campbell */ - break; + dist = dist + 0.1f * (delta[0]); } - - /* clamp and update */ - CLAMP(new_value, rc->min_value, rc->max_value); - radial_control_set_value(rc, new_value); - rc->current_value = new_value; - handled = true; - break; } - break; - - case EVT_LEFTSHIFTKEY: - case EVT_RIGHTSHIFTKEY: { - if (event->val == KM_PRESS) { - rc->slow_mouse[0] = event->x; - rc->slow_mouse[1] = event->y; - rc->slow_mode = true; + else { + delta[0] = rc->initial_mouse[0] - event->x; + delta[1] = rc->initial_mouse[1] - event->y; + if (rc->zoom_prop) { + RNA_property_float_get_array(&rc->zoom_ptr, rc->zoom_prop, zoom); + delta[0] /= zoom[0]; + delta[1] /= zoom[1]; + } if (rc->subtype == PROP_ANGLE) { - float initial_position[2] = {UNPACK2(rc->initial_mouse)}; - float current_position[2] = {UNPACK2(rc->slow_mouse)}; - rc->dial = BLI_dial_initialize(initial_position, 0.0f); - /* immediately set the position to get a an initial direction */ - BLI_dial_angle(rc->dial, current_position); + dist = len_v2(delta); } - handled = true; - } - if (event->val == KM_RELEASE) { - rc->slow_mode = false; - handled = true; - if (rc->dial) { - MEM_freeN(rc->dial); - rc->dial = NULL; + else { + dist = clamp_f(-delta[0], 0.0f, FLT_MAX); } } + + /* calculate new value and apply snapping */ + switch (rc->subtype) { + case PROP_NONE: + case PROP_DISTANCE: + case PROP_PIXEL: + new_value = dist; + if (snap) { + new_value = ((int)new_value + 5) / 10 * 10; + } + break; + case PROP_PERCENTAGE: + new_value = ((dist - WM_RADIAL_CONTROL_DISPLAY_MIN_SIZE) / + WM_RADIAL_CONTROL_DISPLAY_WIDTH) * + 100.0f; + if (snap) { + new_value = ((int)(new_value + 2.5f)) / 5 * 5; + } + break; + case PROP_FACTOR: + new_value = (WM_RADIAL_CONTROL_DISPLAY_SIZE - dist) / WM_RADIAL_CONTROL_DISPLAY_WIDTH; + if (snap) { + new_value = ((int)ceil(new_value * 10.f) * 10.0f) / 100.f; + } + /* Invert new value to increase the factor moving the mouse to the right */ + new_value = 1 - new_value; + break; + case PROP_ANGLE: + new_value = atan2f(delta[1], delta[0]) + (float)M_PI + angle_precision; + new_value = fmod(new_value, 2.0f * (float)M_PI); + if (new_value < 0.0f) { + new_value += 2.0f * (float)M_PI; + } + if (snap) { + new_value = DEG2RADF(((int)RAD2DEGF(new_value) + 5) / 10 * 10); + } + break; + default: + new_value = dist; /* dummy value, should this ever happen? - campbell */ + break; + } + + /* clamp and update */ + CLAMP(new_value, rc->min_value, rc->max_value); + radial_control_set_value(rc, new_value); + rc->current_value = new_value; + handled = true; break; } + break; + + case EVT_LEFTSHIFTKEY: + case EVT_RIGHTSHIFTKEY: { + if (event->val == KM_PRESS) { + rc->slow_mouse[0] = event->x; + rc->slow_mouse[1] = event->y; + rc->slow_mode = true; + if (rc->subtype == PROP_ANGLE) { + const float initial_position[2] = {UNPACK2(rc->initial_mouse)}; + const float current_position[2] = {UNPACK2(rc->slow_mouse)}; + rc->dial = BLI_dial_init(initial_position, 0.0f); + /* immediately set the position to get a an initial direction */ + BLI_dial_angle(rc->dial, current_position); + } + handled = true; + } + if (event->val == KM_RELEASE) { + rc->slow_mode = false; + handled = true; + if (rc->dial) { + MEM_freeN(rc->dial); + rc->dial = NULL; + } + } + break; } + } - /* Modal numinput inactive, try to handle numeric inputs last... */ - if (!handled && event->val == KM_PRESS && handleNumInput(C, &rc->num_input, event)) { - applyNumInput(&rc->num_input, &numValue); + /* Modal numinput inactive, try to handle numeric inputs last... */ + if (!handled && event->val == KM_PRESS && handleNumInput(C, &rc->num_input, event)) { + applyNumInput(&rc->num_input, &numValue); - if (rc->subtype == PROP_ANGLE) { - numValue = fmod(numValue, 2.0f * (float)M_PI); - if (numValue < 0.0f) { - numValue += 2.0f * (float)M_PI; - } + if (rc->subtype == PROP_ANGLE) { + numValue = fmod(numValue, 2.0f * (float)M_PI); + if (numValue < 0.0f) { + numValue += 2.0f * (float)M_PI; } + } - CLAMP(numValue, rc->min_value, rc->max_value); - new_value = numValue; + CLAMP(numValue, rc->min_value, rc->max_value); + new_value = numValue; - radial_control_set_value(rc, new_value); + radial_control_set_value(rc, new_value); - rc->current_value = new_value; - radial_control_update_header(op, C); - return OPERATOR_RUNNING_MODAL; - } + rc->current_value = new_value; + radial_control_update_header(op, C); + return OPERATOR_RUNNING_MODAL; } ED_region_tag_redraw(CTX_wm_region(C)); @@ -3722,6 +3709,7 @@ static int wm_xr_session_toggle_exec(bContext *C, wmOperator *UNUSED(op)) { Main *bmain = CTX_data_main(C); wmWindowManager *wm = CTX_wm_manager(C); + wmWindow *win = CTX_wm_window(C); View3D *v3d = CTX_wm_view3d(C); /* Lazy-create xr context - tries to dynlink to the runtime, reading active_runtime.json. */ @@ -3730,7 +3718,7 @@ static int wm_xr_session_toggle_exec(bContext *C, wmOperator *UNUSED(op)) } v3d->runtime.flag |= V3D_RUNTIME_XR_SESSION_ROOT; - wm_xr_session_toggle(wm, wm_xr_session_update_screen_on_exit_cb); + wm_xr_session_toggle(wm, win, wm_xr_session_update_screen_on_exit_cb); wm_xr_session_update_screen(bmain, &wm->xr); WM_event_add_notifier(C, NC_WM | ND_XR_DATA_CHANGED, NULL); @@ -3917,6 +3905,7 @@ static void gesture_box_modal_keymap(wmKeyConfig *keyconf) WM_modalkeymap_assign(keymap, "CLIP_OT_select_box"); WM_modalkeymap_assign(keymap, "CLIP_OT_graph_select_box"); WM_modalkeymap_assign(keymap, "MASK_OT_select_box"); + WM_modalkeymap_assign(keymap, "PAINT_OT_mask_box_gesture"); WM_modalkeymap_assign(keymap, "VIEW2D_OT_zoom_border"); WM_modalkeymap_assign(keymap, "VIEW3D_OT_clip_border"); WM_modalkeymap_assign(keymap, "VIEW3D_OT_render_border"); diff --git a/source/blender/windowmanager/intern/wm_platform_support.h b/source/blender/windowmanager/intern/wm_platform_support.h index a8e20f6bcdf..6346f517343 100644 --- a/source/blender/windowmanager/intern/wm_platform_support.h +++ b/source/blender/windowmanager/intern/wm_platform_support.h @@ -20,11 +20,8 @@ /** \file * \ingroup wm */ -#ifndef __WM_PLATFORM_SUPPORT_H__ -#define __WM_PLATFORM_SUPPORT_H__ +#pragma once #include "BLI_sys_types.h" bool WM_platform_support_perform_checks(void); - -#endif diff --git a/source/blender/windowmanager/intern/wm_playanim.c b/source/blender/windowmanager/intern/wm_playanim.c index d0a70596957..a0a21fadbbb 100644 --- a/source/blender/windowmanager/intern/wm_playanim.c +++ b/source/blender/windowmanager/intern/wm_playanim.c @@ -1293,8 +1293,7 @@ static char *wm_main_playanim_intern(int argc, const char **argv) // GHOST_ActivateWindowDrawingContext(g_WS.ghost_window); /* initialize OpenGL immediate mode */ - GLuint default_fb = GHOST_GetDefaultOpenGLFramebuffer(g_WS.ghost_window); - g_WS.gpu_context = GPU_context_create(default_fb); + g_WS.gpu_context = GPU_context_create(g_WS.ghost_window); GPU_init(); immActivate(); diff --git a/source/blender/windowmanager/intern/wm_stereo.c b/source/blender/windowmanager/intern/wm_stereo.c index 245560d3795..9667ed5b631 100644 --- a/source/blender/windowmanager/intern/wm_stereo.c +++ b/source/blender/windowmanager/intern/wm_stereo.c @@ -353,12 +353,11 @@ int wm_stereo3d_set_exec(bContext *C, wmOperator *op) WM_event_add_notifier(C, NC_WINDOW, NULL); return OPERATOR_FINISHED; } - else { - /* without this, the popup won't be freed freed properly T44688 */ - CTX_wm_window_set(C, win_src); - win_src->stereo3d_format->display_mode = prev_display_mode; - return OPERATOR_CANCELLED; - } + + /* without this, the popup won't be freed freed properly T44688 */ + CTX_wm_window_set(C, win_src); + win_src->stereo3d_format->display_mode = prev_display_mode; + return OPERATOR_CANCELLED; } int wm_stereo3d_set_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) @@ -368,9 +367,7 @@ int wm_stereo3d_set_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(ev if (wm_stereo3d_set_properties(C, op)) { return wm_stereo3d_set_exec(C, op); } - else { - return WM_operator_props_dialog_popup(C, op, 250); - } + return WM_operator_props_dialog_popup(C, op, 250); } void wm_stereo3d_set_draw(bContext *UNUSED(C), wmOperator *op) diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index e444c5b2109..47afa343394 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -355,10 +355,8 @@ wmWindow *wm_window_copy_test(bContext *C, WM_event_add_notifier_ex(wm, CTX_wm_window(C), NC_WINDOW | NA_ADDED, NULL); return win_dst; } - else { - wm_window_close(C, wm, win_dst); - return NULL; - } + wm_window_close(C, wm, win_dst); + return NULL; } /** \} */ @@ -617,8 +615,7 @@ static void wm_window_ghostwindow_add(wmWindowManager *wm, if (ghostwin) { GHOST_RectangleHandle bounds; - GLuint default_fb = GHOST_GetDefaultOpenGLFramebuffer(ghostwin); - win->gpuctx = GPU_context_create(default_fb); + win->gpuctx = GPU_context_create(ghostwin); /* needed so we can detect the graphics card below */ GPU_init(); @@ -813,9 +810,7 @@ static bool wm_window_update_size_position(wmWindow *win) win->posy = posy; return true; } - else { - return false; - } + return false; } /** @@ -840,11 +835,10 @@ wmWindow *WM_window_open(bContext *C, const rcti *rect) if (win->ghostwin) { return win; } - else { - wm_window_close(C, wm, win); - CTX_wm_window_set(C, win_prev); - return NULL; - } + + wm_window_close(C, wm, win); + CTX_wm_window_set(C, win_prev); + return NULL; } /** @@ -969,13 +963,12 @@ wmWindow *WM_window_open_temp(bContext *C, GHOST_SetTitle(win->ghostwin, title); return win; } - else { - /* very unlikely! but opening a new window can fail */ - wm_window_close(C, wm, win); - CTX_wm_window_set(C, win_prev); - return NULL; - } + /* very unlikely! but opening a new window can fail */ + wm_window_close(C, wm, win); + CTX_wm_window_set(C, win_prev); + + return NULL; } /* ****************** Operators ****************** */ @@ -1206,7 +1199,7 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr /* Ghost now can call this function for life resizes, * but it should return if WM didn't initialize yet. * Can happen on file read (especially full size window). */ - if ((wm->initialized & WM_WINDOW_IS_INITIALIZED) == 0) { + if ((wm->initialized & WM_WINDOW_IS_INIT) == 0) { return 1; } if (!ghostwin) { @@ -1215,15 +1208,13 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr puts("<!> event has no window"); return 1; } - else if (!GHOST_ValidWindow(g_system, ghostwin)) { + if (!GHOST_ValidWindow(g_system, ghostwin)) { /* XXX - should be checked, why are we getting an event here, and */ /* what is it? */ puts("<!> event has invalid window"); return 1; } - else { - win = GHOST_GetWindowUserData(ghostwin); - } + win = GHOST_GetWindowUserData(ghostwin); switch (type) { case GHOST_kEventWindowDeactivate: diff --git a/source/blender/windowmanager/intern/wm_window_private.h b/source/blender/windowmanager/intern/wm_window_private.h index 115539861d7..c208d07ee37 100644 --- a/source/blender/windowmanager/intern/wm_window_private.h +++ b/source/blender/windowmanager/intern/wm_window_private.h @@ -20,8 +20,7 @@ /** \file * \ingroup wm */ -#ifndef __WM_WINDOW_PRIVATE_H__ -#define __WM_WINDOW_PRIVATE_H__ +#pragma once #include "BLI_sys_types.h" #include "GHOST_Types.h" @@ -38,5 +37,3 @@ void WM_ghost_show_message_box(const char *title, const char *continue_label, const char *link, GHOST_DialogOptions dialog_options); - -#endif diff --git a/source/blender/windowmanager/message_bus/intern/wm_message_bus_intern.h b/source/blender/windowmanager/message_bus/intern/wm_message_bus_intern.h index ccf7034e3e0..24c0192fe14 100644 --- a/source/blender/windowmanager/message_bus/intern/wm_message_bus_intern.h +++ b/source/blender/windowmanager/message_bus/intern/wm_message_bus_intern.h @@ -18,8 +18,7 @@ * \ingroup wm */ -#ifndef __WM_MESSAGE_BUS_INTERN_H__ -#define __WM_MESSAGE_BUS_INTERN_H__ +#pragma once #include "../wm_message_bus.h" @@ -47,5 +46,3 @@ BLI_INLINE wmMsg *wm_msg_subscribe_value_msg_cast_mut(wmMsgSubscribeKey *key) { return &((wmMsgSubscribeKey_Generic *)key)->msg; } - -#endif /* __WM_MESSAGE_BUS_INTERN_H__ */ diff --git a/source/blender/windowmanager/message_bus/wm_message_bus.h b/source/blender/windowmanager/message_bus/wm_message_bus.h index 74472386a39..23a53eace52 100644 --- a/source/blender/windowmanager/message_bus/wm_message_bus.h +++ b/source/blender/windowmanager/message_bus/wm_message_bus.h @@ -18,8 +18,7 @@ * \ingroup wm */ -#ifndef __WM_MESSAGE_BUS_H__ -#define __WM_MESSAGE_BUS_H__ +#pragma once #include "RNA_types.h" #include <stdio.h> @@ -294,5 +293,3 @@ void WM_msg_publish_ID(struct wmMsgBus *mbus, struct ID *id); #ifdef __cplusplus } #endif - -#endif /* __WM_MESSAGE_BUS_H__ */ diff --git a/source/blender/windowmanager/wm.h b/source/blender/windowmanager/wm.h index 2b59e047f23..baa47098bd3 100644 --- a/source/blender/windowmanager/wm.h +++ b/source/blender/windowmanager/wm.h @@ -21,8 +21,7 @@ * \ingroup wm */ -#ifndef __WM_H__ -#define __WM_H__ +#pragma once struct ARegion; struct ReportList; @@ -104,5 +103,3 @@ void wm_open_init_use_scripts(wmOperator *op, bool use_prefs); #ifdef __cplusplus } #endif - -#endif diff --git a/source/blender/windowmanager/wm_cursors.h b/source/blender/windowmanager/wm_cursors.h index cdd6b325063..b85616deda5 100644 --- a/source/blender/windowmanager/wm_cursors.h +++ b/source/blender/windowmanager/wm_cursors.h @@ -21,8 +21,7 @@ * \ingroup wm */ -#ifndef __WM_CURSORS_H__ -#define __WM_CURSORS_H__ +#pragma once struct wmEvent; struct wmWindow; @@ -84,5 +83,3 @@ bool wm_cursor_arrow_move(struct wmWindow *win, const struct wmEvent *event); #ifdef __cplusplus } #endif - -#endif /* __WM_CURSORS_H__ */ diff --git a/source/blender/windowmanager/wm_draw.h b/source/blender/windowmanager/wm_draw.h index 9b6bd66c0e5..4997361b485 100644 --- a/source/blender/windowmanager/wm_draw.h +++ b/source/blender/windowmanager/wm_draw.h @@ -21,8 +21,7 @@ * \ingroup wm */ -#ifndef __WM_DRAW_H__ -#define __WM_DRAW_H__ +#pragma once struct GPUOffScreen; struct GPUTexture; @@ -55,5 +54,3 @@ struct GPUTexture *wm_draw_region_texture(struct ARegion *region, int view); #ifdef __cplusplus } #endif - -#endif /* __WM_DRAW_H__ */ diff --git a/source/blender/windowmanager/wm_event_system.h b/source/blender/windowmanager/wm_event_system.h index c61ba61f55d..787c840de8a 100644 --- a/source/blender/windowmanager/wm_event_system.h +++ b/source/blender/windowmanager/wm_event_system.h @@ -21,8 +21,7 @@ * \ingroup wm */ -#ifndef __WM_EVENT_SYSTEM_H__ -#define __WM_EVENT_SYSTEM_H__ +#pragma once /* return value of handler-operator call */ #define WM_HANDLER_CONTINUE 0 @@ -172,5 +171,3 @@ void wm_drags_draw(bContext *C, wmWindow *win, rcti *rect); #ifdef __cplusplus } #endif - -#endif /* __WM_EVENT_SYSTEM_H__ */ diff --git a/source/blender/windowmanager/wm_event_types.h b/source/blender/windowmanager/wm_event_types.h index 16b872c3c9c..ed8f39fea48 100644 --- a/source/blender/windowmanager/wm_event_types.h +++ b/source/blender/windowmanager/wm_event_types.h @@ -23,8 +23,7 @@ * Blender copied the conventions quite some, and expanded it with internal new defines (ton) */ -#ifndef __WM_EVENT_TYPES_H__ -#define __WM_EVENT_TYPES_H__ +#pragma once #ifdef __cplusplus extern "C" { @@ -496,5 +495,3 @@ enum { #ifdef __cplusplus } #endif - -#endif /* __WM_EVENT_TYPES_H__ */ diff --git a/source/blender/windowmanager/wm_files.h b/source/blender/windowmanager/wm_files.h index d7f8c3fc583..d54090a6025 100644 --- a/source/blender/windowmanager/wm_files.h +++ b/source/blender/windowmanager/wm_files.h @@ -21,8 +21,7 @@ * \ingroup wm */ -#ifndef __WM_FILES_H__ -#define __WM_FILES_H__ +#pragma once struct Main; struct wmGenericCallback; @@ -75,5 +74,3 @@ void WM_OT_lib_reload(struct wmOperatorType *ot); #ifdef __cplusplus } #endif - -#endif /* __WM_FILES_H__ */ diff --git a/source/blender/windowmanager/wm_surface.h b/source/blender/windowmanager/wm_surface.h index 8ab6301e8c9..06c29231361 100644 --- a/source/blender/windowmanager/wm_surface.h +++ b/source/blender/windowmanager/wm_surface.h @@ -22,8 +22,7 @@ * Container to manage painting in an offscreen context. */ -#ifndef __WM_SURFACE_H__ -#define __WM_SURFACE_H__ +#pragma once struct bContext; @@ -66,5 +65,3 @@ void wm_surface_reset_drawable(void); #ifdef __cplusplus } #endif - -#endif /* __WM_SURFACE_H__ */ diff --git a/source/blender/windowmanager/wm_window.h b/source/blender/windowmanager/wm_window.h index e3e8abae531..336db7edb50 100644 --- a/source/blender/windowmanager/wm_window.h +++ b/source/blender/windowmanager/wm_window.h @@ -21,8 +21,7 @@ * \ingroup wm */ -#ifndef __WM_WINDOW_H__ -#define __WM_WINDOW_H__ +#pragma once struct wmOperator; @@ -92,5 +91,3 @@ void wm_test_autorun_warning(bContext *C); #ifdef __cplusplus } #endif - -#endif /* __WM_WINDOW_H__ */ diff --git a/source/blender/windowmanager/xr/intern/wm_xr_draw.c b/source/blender/windowmanager/xr/intern/wm_xr_draw.c index 684e59eb8b2..6f96d2ea6a0 100644 --- a/source/blender/windowmanager/xr/intern/wm_xr_draw.c +++ b/source/blender/windowmanager/xr/intern/wm_xr_draw.c @@ -55,7 +55,7 @@ static void wm_xr_draw_matrices_create(const wmXrDrawData *draw_data, copy_qt_qt(eye_pose.orientation_quat, draw_view->eye_pose.orientation_quat); copy_v3_v3(eye_pose.position, draw_view->eye_pose.position); - add_v3_v3(eye_pose.position, draw_data->eye_position_ofs); + sub_v3_v3(eye_pose.position, draw_data->eye_position_ofs); if ((session_settings->flag & XR_SESSION_USE_POSITION_TRACKING) == 0) { sub_v3_v3(eye_pose.position, draw_view->local_pose.position); } diff --git a/source/blender/windowmanager/xr/intern/wm_xr_intern.h b/source/blender/windowmanager/xr/intern/wm_xr_intern.h index 9b7e9a15948..25e3da3ffb4 100644 --- a/source/blender/windowmanager/xr/intern/wm_xr_intern.h +++ b/source/blender/windowmanager/xr/intern/wm_xr_intern.h @@ -18,8 +18,7 @@ * \ingroup wm */ -#ifndef __WM_XR_INTERN_H__ -#define __WM_XR_INTERN_H__ +#pragma once #include "CLG_log.h" @@ -50,7 +49,11 @@ typedef struct wmXrSessionState { typedef struct wmXrRuntimeData { GHOST_XrContextHandle context; - /* Although this struct is internal, RNA gets a handle to this for state information queries. */ + /** The window the session was started in. Stored to be able to follow its view-layer. This may + * be an invalid reference, i.e. the window may have been closed. */ + wmWindow *session_root_win; + + /** Although this struct is internal, RNA gets a handle to this for state information queries. */ wmXrSessionState session_state; wmXrSessionExitFn exit_fn; } wmXrRuntimeData; @@ -71,6 +74,8 @@ typedef struct wmXrDrawData { * space). With positional tracking enabled, it should be the same as the base pose, when * disabled it also contains a location delta from the moment the option was toggled. */ GHOST_XrPose base_pose; + /** Offset to _substract_ from the OpenXR eye and viewer pose to get the wanted effective pose + * (e.g. a pose exactly at the landmark position). */ float eye_position_ofs[3]; /* Local/view space. */ } wmXrDrawData; @@ -92,5 +97,3 @@ void wm_xr_session_gpu_binding_context_destroy(GHOST_ContextHandle context); void wm_xr_pose_to_viewmat(const GHOST_XrPose *pose, float r_viewmat[4][4]); void wm_xr_draw_view(const GHOST_XrDrawViewInfo *draw_view, void *customdata); - -#endif diff --git a/source/blender/windowmanager/xr/intern/wm_xr_session.c b/source/blender/windowmanager/xr/intern/wm_xr_session.c index 8e7101ddcd5..f3ce7be993f 100644 --- a/source/blender/windowmanager/xr/intern/wm_xr_session.c +++ b/source/blender/windowmanager/xr/intern/wm_xr_session.c @@ -19,7 +19,10 @@ */ #include "BKE_context.h" +#include "BKE_main.h" +#include "BKE_scene.h" +#include "BLI_listbase.h" #include "BLI_math.h" #include "DEG_depsgraph.h" @@ -41,8 +44,8 @@ #include "wm_window.h" #include "wm_xr_intern.h" -wmSurface *g_xr_surface = NULL; -CLG_LogRef LOG = {"wm.xr"}; +static wmSurface *g_xr_surface = NULL; +static CLG_LogRef LOG = {"wm.xr"}; /* -------------------------------------------------------------------- */ @@ -68,7 +71,9 @@ static void wm_xr_session_begin_info_create(wmXrData *xr_data, r_begin_info->exit_customdata = xr_data; } -void wm_xr_session_toggle(wmWindowManager *wm, wmXrSessionExitFn session_exit_fn) +void wm_xr_session_toggle(wmWindowManager *wm, + wmWindow *session_root_win, + wmXrSessionExitFn session_exit_fn) { wmXrData *xr_data = &wm->xr; @@ -78,6 +83,7 @@ void wm_xr_session_toggle(wmWindowManager *wm, wmXrSessionExitFn session_exit_fn else { GHOST_XrSessionBeginInfo begin_info; + xr_data->runtime->session_root_win = session_root_win; xr_data->runtime->session_state.is_started = true; xr_data->runtime->exit_fn = session_exit_fn; @@ -159,6 +165,43 @@ static void wm_xr_session_draw_data_populate(wmXrData *xr_data, wm_xr_session_base_pose_calc(r_draw_data->scene, settings, &r_draw_data->base_pose); } +static wmWindow *wm_xr_session_root_window_or_fallback_get(const wmWindowManager *wm, + const wmXrRuntimeData *runtime_data) +{ + if (runtime_data->session_root_win && + BLI_findindex(&wm->windows, runtime_data->session_root_win) != -1) { + /* Root window is still valid, use it. */ + return runtime_data->session_root_win; + } + /* Otherwise, fallback. */ + return wm->windows.first; +} + +/** + * Get the scene and depsgraph shown in the VR session's root window (the window the session was + * started from) if still available. If it's not available, use some fallback window. + * + * It's important that the VR session follows some existing window, otherwise it would need to have + * an own depsgraph, which is an expense we should avoid. + */ +static void wm_xr_session_scene_and_evaluated_depsgraph_get(Main *bmain, + const wmWindowManager *wm, + Scene **r_scene, + Depsgraph **r_depsgraph) +{ + const wmWindow *root_win = wm_xr_session_root_window_or_fallback_get(wm, wm->xr.runtime); + + /* Follow the scene & view layer shown in the root 3D View. */ + Scene *scene = WM_window_get_active_scene(root_win); + ViewLayer *view_layer = WM_window_get_active_view_layer(root_win); + + Depsgraph *depsgraph = BKE_scene_get_depsgraph(bmain, scene, view_layer, false); + BLI_assert(scene && view_layer && depsgraph); + BKE_scene_graph_evaluated_ensure(depsgraph, bmain); + *r_scene = scene; + *r_depsgraph = depsgraph; +} + typedef enum wmXrSessionStateEvent { SESSION_STATE_EVENT_NONE = 0, SESSION_STATE_EVENT_START, @@ -183,16 +226,15 @@ static wmXrSessionStateEvent wm_xr_session_state_to_event(const wmXrSessionState if (!state->is_view_data_set) { return SESSION_STATE_EVENT_START; } - else if (wm_xr_session_draw_data_needs_reset_to_base_pose(state, settings)) { + if (wm_xr_session_draw_data_needs_reset_to_base_pose(state, settings)) { return SESSION_STATE_EVENT_RESET_TO_BASE_POSE; } - else { - const bool position_tracking_toggled = ((state->prev_settings_flag & - XR_SESSION_USE_POSITION_TRACKING) != - (settings->flag & XR_SESSION_USE_POSITION_TRACKING)); - if (position_tracking_toggled) { - return SESSION_STATE_EVENT_POSITON_TRACKING_TOGGLE; - } + + const bool position_tracking_toggled = ((state->prev_settings_flag & + XR_SESSION_USE_POSITION_TRACKING) != + (settings->flag & XR_SESSION_USE_POSITION_TRACKING)); + if (position_tracking_toggled) { + return SESSION_STATE_EVENT_POSITON_TRACKING_TOGGLE; } return SESSION_STATE_EVENT_NONE; @@ -208,8 +250,9 @@ void wm_xr_session_draw_data_update(const wmXrSessionState *state, switch (event) { case SESSION_STATE_EVENT_START: - /* Always use the exact base pose with no offset when starting the session. */ - copy_v3_fl(draw_data->eye_position_ofs, 0.0f); + /* We want to start the session exactly at landmark position. + * Run-times may have a non-[0,0,0] starting position that we have to subtract for that. */ + copy_v3_v3(draw_data->eye_position_ofs, draw_view->local_pose.position); break; /* This should be triggered by the VR add-on if a landmark changes. */ case SESSION_STATE_EVENT_RESET_TO_BASE_POSE: @@ -256,9 +299,9 @@ void wm_xr_session_state_update(const XrSessionSettings *settings, copy_v3_v3(viewer_pose.position, draw_data->base_pose.position); /* The local pose and the eye pose (which is copied from an earlier local pose) both are view * space, so Y-up. In this case we need them in regular Z-up. */ - viewer_pose.position[0] += draw_data->eye_position_ofs[0]; - viewer_pose.position[1] -= draw_data->eye_position_ofs[2]; - viewer_pose.position[2] += draw_data->eye_position_ofs[1]; + viewer_pose.position[0] -= draw_data->eye_position_ofs[0]; + viewer_pose.position[1] += draw_data->eye_position_ofs[2]; + viewer_pose.position[2] -= draw_data->eye_position_ofs[1]; if (use_position_tracking) { viewer_pose.position[0] += draw_view->local_pose.position[0]; viewer_pose.position[1] -= draw_view->local_pose.position[2]; @@ -344,13 +387,17 @@ static void wm_xr_session_surface_draw(bContext *C) { wmXrSurfaceData *surface_data = g_xr_surface->customdata; wmWindowManager *wm = CTX_wm_manager(C); + Main *bmain = CTX_data_main(C); wmXrDrawData draw_data; if (!GHOST_XrSessionIsRunning(wm->xr.runtime->context)) { return; } - wm_xr_session_draw_data_populate( - &wm->xr, CTX_data_scene(C), CTX_data_ensure_evaluated_depsgraph(C), &draw_data); + + Scene *scene; + Depsgraph *depsgraph; + wm_xr_session_scene_and_evaluated_depsgraph_get(bmain, wm, &scene, &depsgraph); + wm_xr_session_draw_data_populate(&wm->xr, scene, depsgraph, &draw_data); GHOST_XrSessionDrawViews(wm->xr.runtime->context, &draw_data); diff --git a/source/blender/windowmanager/xr/wm_xr.h b/source/blender/windowmanager/xr/wm_xr.h index 33f79bc75b2..0f0fbe8bc00 100644 --- a/source/blender/windowmanager/xr/wm_xr.h +++ b/source/blender/windowmanager/xr/wm_xr.h @@ -18,8 +18,7 @@ * \ingroup wm */ -#ifndef __WM_XR_H__ -#define __WM_XR_H__ +#pragma once struct wmWindowManager; struct wmXrData; @@ -29,7 +28,5 @@ typedef void (*wmXrSessionExitFn)(const wmXrData *xr_data); /* wm_xr.c */ bool wm_xr_init(wmWindowManager *wm); void wm_xr_exit(wmWindowManager *wm); -void wm_xr_session_toggle(wmWindowManager *wm, wmXrSessionExitFn session_exit_fn); +void wm_xr_session_toggle(wmWindowManager *wm, wmWindow *win, wmXrSessionExitFn session_exit_fn); bool wm_xr_events_handle(wmWindowManager *wm); - -#endif |