diff options
Diffstat (limited to 'source/blender/windowmanager/intern/wm_init_exit.c')
-rw-r--r-- | source/blender/windowmanager/intern/wm_init_exit.c | 119 |
1 files changed, 111 insertions, 8 deletions
diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index adf0e9d2001..0fd42ffb8aa 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -49,6 +49,7 @@ #include "BKE_font.h" #include "BKE_global.h" #include "BKE_library.h" +#include "BKE_main.h" #include "BKE_mball.h" #include "BKE_report.h" #include "BKE_utildefines.h" @@ -95,6 +96,7 @@ #include "BKE_depsgraph.h" #include "BKE_sound.h" +#include "GHOST_C-api.h" static void wm_init_reports(bContext *C) { @@ -165,6 +167,10 @@ void WM_init(bContext *C, int argc, char **argv) G.ndofdevice = -1; /* XXX bad initializer, needs set otherwise buttons show! */ read_history(); + + if(G.sce[0] == 0) + BLI_make_file_string("/", G.sce, BLI_getDefaultDocumentFolder(), "untitled.blend"); + BLI_strncpy(G.lib, G.sce, FILE_MAX); } @@ -183,18 +189,115 @@ void WM_init_splash(bContext *C) } } -void WM_init_game(bContext *C) +static ScrArea *biggest_view3d(bContext *C) +{ + bScreen *sc= CTX_wm_screen(C); + ScrArea *sa, *big= NULL; + int size, maxsize= 0; + + for(sa= sc->areabase.first; sa; sa= sa->next) { + if(sa->spacetype==SPACE_VIEW3D) { + size= sa->winx * sa->winy; + if(size > maxsize) { + maxsize= size; + big= sa; + } + } + } + return big; +} + +int WM_init_game(bContext *C) { - //XXX copied from WM_init_splash we may not even need those "window" related code - //XXX not working yet, it fails at the game_start_operator pool (it needs an area) wmWindowManager *wm= CTX_wm_manager(C); - wmWindow *prevwin= CTX_wm_window(C); - - if(wm->windows.first) { - CTX_wm_window_set(C, wm->windows.first); + wmWindow* win; + + ScrArea *sa; + ARegion *ar; + + Scene *scene= CTX_data_scene(C); + + if (!scene) { + // XXX, this should not be needed. + Main *bmain = CTX_data_main(C); + scene= bmain->scene.first; + } + + win = wm->windows.first; + + //first to get a valid window + if(win) + CTX_wm_window_set(C, win); + + sa = biggest_view3d(C); + + if(sa) + { + for(ar=sa->regionbase.first; ar; ar=ar->next) { + if(ar->regiontype == RGN_TYPE_WINDOW) { + break; + } + } + } + + // if we have a valid 3D view + if (sa && ar) { + ARegion *arhide; + + CTX_wm_area_set(C, sa); + CTX_wm_region_set(C, ar); + + /* disable quad view */ + if(ar->alignment == RGN_ALIGN_QSPLIT) + WM_operator_name_call(C, "SCREEN_OT_region_quadview", WM_OP_EXEC_DEFAULT, NULL); + + /* toolbox, properties panel and header are hidden */ + for(arhide=sa->regionbase.first; arhide; arhide=arhide->next) { + if(arhide->regiontype != RGN_TYPE_WINDOW) { + if(!(arhide->flag & RGN_FLAG_HIDDEN)) { + ED_region_toggle_hidden(C, arhide); + } + } + } + + /* full screen the area */ + if(!sa->full) { + ED_screen_full_toggle(C, wm->windows.first, sa); + } + + /* Fullscreen */ + if(scene->gm.fullscreen) { + WM_operator_name_call(C, "WM_OT_window_fullscreen_toggle", WM_OP_EXEC_DEFAULT, NULL); + wm_get_screensize(&ar->winrct.xmax, &ar->winrct.ymax); + } + else + { + GHOST_RectangleHandle rect = GHOST_GetClientBounds(win->ghostwin); + ar->winrct.ymax = GHOST_GetHeightRectangle(rect); + ar->winrct.xmax = GHOST_GetWidthRectangle(rect); + GHOST_DisposeRectangle(rect); + } + WM_operator_name_call(C, "VIEW3D_OT_game_start", WM_OP_EXEC_DEFAULT, NULL); - CTX_wm_window_set(C, prevwin); + + return 1; + } + else + { + ReportTimerInfo *rti; + + BKE_report(&wm->reports, RPT_ERROR, "No valid 3D View found. Game auto start is not possible."); + + /* After adding the report to the global list, reset the report timer. */ + WM_event_remove_timer(wm, NULL, wm->reports.reporttimer); + + /* Records time since last report was added */ + wm->reports.reporttimer = WM_event_add_timer(wm, CTX_wm_window(C), TIMER, 0.02); + + rti = MEM_callocN(sizeof(ReportTimerInfo), "ReportTimerInfo"); + wm->reports.reporttimer->customdata = rti; } + return 0; } /* free strings of open recent files */ |