Changeset View
Changeset View
Standalone View
Standalone View
source/blender/windowmanager/intern/wm_operators.c
| Show First 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | |||||
| #include "BKE_library_query.h" | #include "BKE_library_query.h" | ||||
| #include "BKE_global.h" | #include "BKE_global.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "BKE_material.h" | #include "BKE_material.h" | ||||
| #include "BKE_report.h" | #include "BKE_report.h" | ||||
| #include "BKE_scene.h" | #include "BKE_scene.h" | ||||
| #include "BKE_screen.h" /* BKE_ST_MAXNAME */ | #include "BKE_screen.h" /* BKE_ST_MAXNAME */ | ||||
| #include "BKE_unit.h" | #include "BKE_unit.h" | ||||
| #include "BKE_utildefines.h" | |||||
| #include "BKE_object.h" | |||||
| #include "BKE_idcode.h" | #include "BKE_idcode.h" | ||||
| #include "BIF_glutil.h" /* for paint cursor */ | #include "BIF_glutil.h" /* for paint cursor */ | ||||
| #include "BLF_api.h" | #include "BLF_api.h" | ||||
| #include "IMB_imbuf_types.h" | #include "IMB_imbuf_types.h" | ||||
| #include "IMB_imbuf.h" | #include "IMB_imbuf.h" | ||||
| ▲ Show 20 Lines • Show All 4,023 Lines • ▼ Show 20 Lines | static void WM_OT_stereo3d_set(wmOperatorType *ot) | ||||
| prop = RNA_def_boolean(ot->srna, "use_interlace_swap", false, "Swap Left/Right", | prop = RNA_def_boolean(ot->srna, "use_interlace_swap", false, "Swap Left/Right", | ||||
| "Swap left and right stereo channels"); | "Swap left and right stereo channels"); | ||||
| RNA_def_property_flag(prop, PROP_SKIP_SAVE); | RNA_def_property_flag(prop, PROP_SKIP_SAVE); | ||||
| prop = RNA_def_boolean(ot->srna, "use_sidebyside_crosseyed", false, "Cross-Eyed", | prop = RNA_def_boolean(ot->srna, "use_sidebyside_crosseyed", false, "Cross-Eyed", | ||||
| "Right eye should see left image and vice-versa"); | "Right eye should see left image and vice-versa"); | ||||
| RNA_def_property_flag(prop, PROP_SKIP_SAVE); | RNA_def_property_flag(prop, PROP_SKIP_SAVE); | ||||
| } | } | ||||
| #ifdef WITH_INPUT_HMD | |||||
| /* ******************************************************* */ | |||||
| /* Head Mounted Display */ | |||||
| static void hmd_view_prepare_screen(wmWindowManager *wm, wmWindow *win, const RegionView3D *rv3d_current) | |||||
| { | |||||
| ScrArea *sa_hmd = win->screen->areabase.first; | |||||
| View3D *v3d_hmd = sa_hmd->spacedata.first; | |||||
| RegionView3D *rv3d_hmd = BKE_area_find_region_type(sa_hmd, RGN_TYPE_WINDOW)->regiondata; | |||||
| BLI_assert(sa_hmd->spacetype == SPACE_VIEW3D); | |||||
| /* sync view options */ | |||||
| v3d_hmd->drawtype = wm->hmd_view.view_shade; | |||||
| /* copy view orientation from current 3D view to newly opened HMD view */ | |||||
| ED_view3d_copy_region_view_data(rv3d_current, rv3d_hmd); | |||||
| } | |||||
| static int wm_hmd_view_toggle_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *UNUSED(event)) | |||||
| { | |||||
| wmWindow *prevwin = CTX_wm_window(C); | |||||
| wmWindowManager *wm = CTX_wm_manager(C); | |||||
| wmWindow *win; | |||||
| /* close */ | |||||
| if ((win = wm->hmd_view.hmd_win)) { | |||||
| wm->hmd_view.hmd_win->screen->is_hmd_running = false; | |||||
| wm_window_close(C, wm, win); | |||||
| wm->hmd_view.hmd_win = NULL; | |||||
| /* close HMD */ | |||||
| WM_device_HMD_state_set(U.hmd_settings.device, false); | |||||
| } | |||||
| /* open */ | |||||
| else { | |||||
| ARegion *ar_current; | |||||
| View3D *v3d_current; | |||||
| RegionView3D *rv3d_current; | |||||
| rcti rect = {prevwin->posx, prevwin->posx + (int)(prevwin->sizex * 0.9f), | |||||
| prevwin->posy, prevwin->posy + (int)(prevwin->sizey * 0.9f)}; | |||||
| /* WM_window_open_restricted changes context, so get current context data first */ | |||||
| ED_view3d_context_user_region(C, &v3d_current, &ar_current); | |||||
| rv3d_current = ar_current->regiondata; | |||||
| BLI_assert(v3d_current && ar_current && rv3d_current); | |||||
| win = WM_window_open_restricted(C, &rect, WM_WINDOW_HMD); | |||||
| wm->hmd_view.hmd_win = win; | |||||
| hmd_view_prepare_screen(wm, win, rv3d_current); | |||||
| } | |||||
| return OPERATOR_FINISHED; | |||||
| } | |||||
| static void WM_OT_hmd_view_toggle(wmOperatorType *ot) | |||||
| { | |||||
| ot->name = "Open/Close HMD View Window"; | |||||
| ot->idname = "WM_OT_hmd_view_toggle"; | |||||
| ot->description = "Open/Close a separate window for a head mounted display"; | |||||
| ot->invoke = wm_hmd_view_toggle_invoke; | |||||
| } | |||||
| static int hmd_session_toggle_poll(bContext *C) | |||||
| { | |||||
| wmWindowManager *wm = CTX_wm_manager(C); | |||||
| if (!wm->hmd_view.hmd_win) { | |||||
| CTX_wm_operator_poll_msg_set(C, "Open a HMD window first"); | |||||
| return false; | |||||
| } | |||||
| return true; | |||||
| } | |||||
| static void hmd_session_disable_viewlocks(wmWindowManager *wm) | |||||
| { | |||||
| for (wmWindow *win = wm->windows.first; win; win = win->next) { | |||||
| for (ScrArea *sa = win->screen->areabase.first; sa; sa = sa->next) { | |||||
| if (sa->spacetype == SPACE_VIEW3D) { | |||||
| View3D *v3d = sa->spacedata.first; | |||||
| if (v3d->flag3 & V3D_SHOW_HMD_MIRROR) { | |||||
| for (ARegion *ar = sa->regionbase.first; ar; ar = ar->next) { | |||||
| if (ar->regiontype == RGN_TYPE_WINDOW) { | |||||
| RegionView3D *rv3d = ar->regiondata; | |||||
| if (RV3D_IS_LOCKED_SHARED(rv3d)) { | |||||
| rv3d->viewlock &= ~RV3D_LOCKED_SHARED; | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| static void hmd_session_prepare_screen(wmWindow *hmd_win) | |||||
| { | |||||
| ScrArea *sa = hmd_win->screen->areabase.first; | |||||
| View3D *v3d = sa->spacedata.first; | |||||
| ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); | |||||
| RegionView3D *rv3d = ar->regiondata; | |||||
| BLI_assert(ar && sa->spacetype == SPACE_VIEW3D); | |||||
| v3d->fx_settings.fx_flag |= GPU_FX_FLAG_LensDist; | |||||
| /* Set distortion type for 3D View but first we need to validate fx settings. */ | |||||
| BKE_screen_gpu_fx_validate(&v3d->fx_settings); | |||||
| if (rv3d->persp == RV3D_ORTHO) { | |||||
| rv3d->persp = RV3D_PERSP; | |||||
| } | |||||
| rv3d->viewlock |= RV3D_LOCK_PERSP_VIEW; | |||||
| hmd_win->screen->is_hmd_running = true; | |||||
| WM_window_fullscreen_toggle(hmd_win, true, false); | |||||
| } | |||||
| static int hmd_session_toggle_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *UNUSED(event)) | |||||
| { | |||||
| wmWindowManager *wm = CTX_wm_manager(C); | |||||
| wmWindow *hmd_win = wm->hmd_view.hmd_win; | |||||
| if (!hmd_win) { | |||||
| return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH); | |||||
| } | |||||
| if (hmd_win->screen->is_hmd_running) { | |||||
| ScrArea *sa = hmd_win->screen->areabase.first; | |||||
| View3D *v3d = sa->spacedata.first; | |||||
| BLI_assert(sa->spacetype == SPACE_VIEW3D); | |||||
| /* exit session */ | |||||
| v3d->fx_settings.fx_flag &= ~GPU_FX_FLAG_LensDist; | |||||
| MEM_SAFE_FREE(v3d->fx_settings.lensdist); | |||||
| hmd_win->screen->is_hmd_running = false; | |||||
| WM_window_fullscreen_toggle(hmd_win, false, true); | |||||
| WM_device_HMD_state_set(U.hmd_settings.device, false); | |||||
| hmd_session_disable_viewlocks(wm); | |||||
| } | |||||
| else { | |||||
| /* start session */ | |||||
| WM_device_HMD_state_set(U.hmd_settings.device, true); | |||||
| if ((U.hmd_settings.flag & USER_HMD_USE_DEVICE_IPD) == 0) { | |||||
| U.hmd_settings.init_ipd = WM_device_HMD_IPD_get(); | |||||
| WM_device_HMD_IPD_set(U.hmd_settings.custom_ipd); | |||||
| } | |||||
| hmd_session_prepare_screen(hmd_win); | |||||
| } | |||||
| return OPERATOR_FINISHED; | |||||
| } | |||||
| static void WM_OT_hmd_session_toggle(wmOperatorType *ot) | |||||
| { | |||||
| /* identifiers */ | |||||
| ot->name = "Run HMD Session"; | |||||
| ot->description = "Start/Stop a head mounted display session"; | |||||
| ot->idname = "WM_OT_hmd_session_run"; | |||||
| /* api callbacks */ | |||||
| ot->invoke = hmd_session_toggle_invoke; | |||||
| ot->poll = hmd_session_toggle_poll; | |||||
| } | |||||
| static int hmd_session_refresh_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *UNUSED(event)) | |||||
| { | |||||
| wmWindowManager *wm = CTX_wm_manager(C); | |||||
| wmWindow *hmd_win = wm->hmd_view.hmd_win; | |||||
| ScrArea *sa; | |||||
| View3D *v3d; | |||||
| if (!hmd_win || !hmd_win->screen->is_hmd_running) { | |||||
| return OPERATOR_CANCELLED; | |||||
| } | |||||
| sa = hmd_win->screen->areabase.first; | |||||
| v3d = sa->spacedata.first; | |||||
| BLI_assert(sa->spacetype == SPACE_VIEW3D); | |||||
| /* Actually the only thing we have to do is ensuring a redraw, we'll then | |||||
| * get the modelview/projection matrices from HMD device when drawing */ | |||||
| ED_area_tag_redraw(sa); | |||||
| /* Tag mirrored 3D views for redraw too */ | |||||
| for (wmWindow *win = wm->windows.first; win; win = win->next) { | |||||
| for (sa = win->screen->areabase.first; sa; sa = sa->next) { | |||||
| if (sa->spacetype == SPACE_VIEW3D) { | |||||
| v3d = sa->spacedata.first; | |||||
| if (v3d->flag3 & V3D_SHOW_HMD_MIRROR) { | |||||
| for (ARegion *ar = sa->regionbase.first; ar; ar = ar->next) { | |||||
| if (ar->regiontype == RGN_TYPE_WINDOW) { | |||||
| RegionView3D *rv3d = ar->regiondata; | |||||
| if (RV3D_IS_LOCKED_SHARED(rv3d)) { | |||||
| /* this rv3d shares data with the HMD view */ | |||||
| ED_region_tag_redraw(ar); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| return OPERATOR_FINISHED; | |||||
| } | |||||
| static void WM_OT_hmd_session_refresh(wmOperatorType *ot) | |||||
| { | |||||
| /* identifiers */ | |||||
| ot->name = "Refresh HMD Session"; | |||||
| ot->description = "Refresh data for a head mounted display (virtual reality) session"; | |||||
| ot->idname = "WM_OT_hmd_session_refresh"; | |||||
| /* api callbacks */ | |||||
| ot->invoke = hmd_session_refresh_invoke; | |||||
| /* flags */ | |||||
| ot->flag = OPTYPE_INTERNAL; | |||||
| } | |||||
| #endif /* WITH_INPUT_HMD */ | |||||
| /* ******************************************************* */ | /* ******************************************************* */ | ||||
| /* called on initialize WM_exit() */ | /* called on initialize WM_exit() */ | ||||
| void wm_operatortype_free(void) | void wm_operatortype_free(void) | ||||
| { | { | ||||
| BLI_ghash_free(global_ops_hash, NULL, (GHashValFreeFP)operatortype_ghash_free_cb); | BLI_ghash_free(global_ops_hash, NULL, (GHashValFreeFP)operatortype_ghash_free_cb); | ||||
| global_ops_hash = NULL; | global_ops_hash = NULL; | ||||
| } | } | ||||
| Show All 30 Lines | void wm_operatortype_init(void) | ||||
| WM_operatortype_append(WM_OT_debug_menu); | WM_operatortype_append(WM_OT_debug_menu); | ||||
| WM_operatortype_append(WM_OT_operator_defaults); | WM_operatortype_append(WM_OT_operator_defaults); | ||||
| WM_operatortype_append(WM_OT_splash); | WM_operatortype_append(WM_OT_splash); | ||||
| WM_operatortype_append(WM_OT_search_menu); | WM_operatortype_append(WM_OT_search_menu); | ||||
| WM_operatortype_append(WM_OT_call_menu); | WM_operatortype_append(WM_OT_call_menu); | ||||
| WM_operatortype_append(WM_OT_call_menu_pie); | WM_operatortype_append(WM_OT_call_menu_pie); | ||||
| WM_operatortype_append(WM_OT_radial_control); | WM_operatortype_append(WM_OT_radial_control); | ||||
| WM_operatortype_append(WM_OT_stereo3d_set); | WM_operatortype_append(WM_OT_stereo3d_set); | ||||
| #ifdef WITH_INPUT_HMD | |||||
| WM_operatortype_append(WM_OT_hmd_view_toggle); | |||||
| WM_operatortype_append(WM_OT_hmd_session_toggle); | |||||
| WM_operatortype_append(WM_OT_hmd_session_refresh); | |||||
| #endif | |||||
| #if defined(WIN32) | #if defined(WIN32) | ||||
| WM_operatortype_append(WM_OT_console_toggle); | WM_operatortype_append(WM_OT_console_toggle); | ||||
| #endif | #endif | ||||
| WM_operatortype_append(WM_OT_previews_ensure); | WM_operatortype_append(WM_OT_previews_ensure); | ||||
| WM_operatortype_append(WM_OT_previews_clear); | WM_operatortype_append(WM_OT_previews_clear); | ||||
| WM_operatortype_append(WM_OT_doc_view_manual_ui_context); | WM_operatortype_append(WM_OT_doc_view_manual_ui_context); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 230 Lines • ▼ Show 20 Lines | #endif | ||||
| WM_keymap_verify_item(keymap, "WM_OT_debug_menu", DKEY, KM_PRESS, KM_ALT | KM_CTRL, 0); | WM_keymap_verify_item(keymap, "WM_OT_debug_menu", DKEY, KM_PRESS, KM_ALT | KM_CTRL, 0); | ||||
| /* menus that can be accessed anywhere in blender */ | /* menus that can be accessed anywhere in blender */ | ||||
| WM_keymap_verify_item(keymap, "WM_OT_search_menu", SPACEKEY, KM_PRESS, 0, 0); | WM_keymap_verify_item(keymap, "WM_OT_search_menu", SPACEKEY, KM_PRESS, 0, 0); | ||||
| #ifdef WITH_INPUT_NDOF | #ifdef WITH_INPUT_NDOF | ||||
| WM_keymap_add_menu(keymap, "USERPREF_MT_ndof_settings", NDOF_BUTTON_MENU, KM_PRESS, 0, 0); | WM_keymap_add_menu(keymap, "USERPREF_MT_ndof_settings", NDOF_BUTTON_MENU, KM_PRESS, 0, 0); | ||||
| #endif | #endif | ||||
| #ifdef WITH_INPUT_HMD | |||||
| WM_keymap_add_item(keymap, "WM_OT_hmd_view_toggle", EVT_ACTIONZONE_FULLSCREEN, 0, 0, 0); | |||||
| WM_keymap_add_item(keymap, "WM_OT_hmd_session_refresh", EVT_HMD_TRANSFORM, KM_ANY, KM_ANY, 0); | |||||
| #endif | |||||
| /* Space switching */ | /* Space switching */ | ||||
| kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F2KEY, KM_PRESS, KM_SHIFT, 0); /* new in 2.5x, was DXF export */ | kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F2KEY, KM_PRESS, KM_SHIFT, 0); /* new in 2.5x, was DXF export */ | ||||
| RNA_string_set(kmi->ptr, "data_path", "area.type"); | RNA_string_set(kmi->ptr, "data_path", "area.type"); | ||||
| RNA_string_set(kmi->ptr, "value", "LOGIC_EDITOR"); | RNA_string_set(kmi->ptr, "value", "LOGIC_EDITOR"); | ||||
| kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F3KEY, KM_PRESS, KM_SHIFT, 0); | kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F3KEY, KM_PRESS, KM_SHIFT, 0); | ||||
| RNA_string_set(kmi->ptr, "data_path", "area.type"); | RNA_string_set(kmi->ptr, "data_path", "area.type"); | ||||
| RNA_string_set(kmi->ptr, "value", "NODE_EDITOR"); | RNA_string_set(kmi->ptr, "value", "NODE_EDITOR"); | ||||
| ▲ Show 20 Lines • Show All 140 Lines • Show Last 20 Lines | |||||