diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 1147525e6..423e41088 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -826,6 +826,31 @@ MainWindow::~MainWindow(){ if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } +int MainWindow::getDesiredScreenWidth() { + Config &config= Config::getInstance(); + return config.getInt("ScreenWidth"); +} +int MainWindow::getDesiredScreenHeight() { + Config &config= Config::getInstance(); + return config.getInt("ScreenHeight"); +} + +void MainWindow::eventToggleFullScreen(bool isFullscreen) { + WindowGl::eventToggleFullScreen(isFullscreen); + + if(isFullscreen) { + Metrics::reload(this->program->getWindow()->getScreenWidth(), + this->program->getWindow()->getScreenHeight()); + } + else { + Config &config= Config::getInstance(); + Metrics::reload(config.getInt("ScreenWidth"),config.getInt("ScreenHeight")); + //window->setText(config.getString("WindowTitle","MegaGlest")); + //this->mainMenu->init(); + } + +} + void MainWindow::eventMouseDown(int x, int y, MouseButton mouseButton){ const Metrics &metrics = Metrics::getInstance(); int vx = metrics.toVirtualX(x); diff --git a/source/glest_game/main/main.h b/source/glest_game/main/main.h index 485606306..824e6830f 100644 --- a/source/glest_game/main/main.h +++ b/source/glest_game/main/main.h @@ -62,6 +62,11 @@ public: bool getTriggerLanguageToggle() const { return triggerLanguageToggle; } string getTriggerLanguage() const { return triggerLanguage; } + virtual int getDesiredScreenWidth(); + virtual int getDesiredScreenHeight(); + +protected: + virtual void eventToggleFullScreen(bool isFullscreen); }; }}//end namespace diff --git a/source/shared_lib/include/platform/sdl/window.h b/source/shared_lib/include/platform/sdl/window.h index 44c385587..3f5112722 100644 --- a/source/shared_lib/include/platform/sdl/window.h +++ b/source/shared_lib/include/platform/sdl/window.h @@ -213,6 +213,7 @@ protected: virtual void eventMenu(int menuId) {} virtual void eventClose() {}; virtual void eventDestroy() {}; + virtual void eventToggleFullScreen(bool isFullscreen) {}; private: /// needed to detect double clicks diff --git a/source/shared_lib/include/platform/sdl/window_gl.h b/source/shared_lib/include/platform/sdl/window_gl.h index 36bf31a15..260408ec8 100644 --- a/source/shared_lib/include/platform/sdl/window_gl.h +++ b/source/shared_lib/include/platform/sdl/window_gl.h @@ -45,11 +45,16 @@ public: SDL_Surface * getScreenSurface(); virtual int getScreenWidth(); virtual int getScreenHeight(); + virtual int getDesiredScreenWidth() { return getScreenWidth(); } + virtual int getDesiredScreenHeight() { return getScreenHeight(); } virtual bool ChangeVideoMode(bool preserveContext, int resWidth, int resHeight, bool fullscreenWindow, int colorBits, int depthBits, int stencilBits, bool hardware_acceleration, bool fullscreen_anti_aliasing, float gammaValue); + +protected: + virtual void eventToggleFullScreen(bool isFullscreen); }; }}//end namespace diff --git a/source/shared_lib/sources/platform/sdl/window.cpp b/source/shared_lib/sources/platform/sdl/window.cpp index ac80cd7dc..f9cb7543a 100644 --- a/source/shared_lib/sources/platform/sdl/window.cpp +++ b/source/shared_lib/sources/platform/sdl/window.cpp @@ -617,16 +617,8 @@ void Window::toggleFullscreen() { Window::isFullScreen = !Window::isFullScreen; - if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false) { - //SDL_Surface *cur_surface = SDL_GetVideoSurface(); - if(sdlWindow != NULL) { - if(isFullScreen){ - SDL_SetWindowFullscreen(sdlWindow,SDL_WINDOW_FULLSCREEN); - } - else { - SDL_SetWindowFullscreen(sdlWindow,0); - } - } + if(global_window) { + global_window->eventToggleFullScreen(Window::isFullScreen); } if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); diff --git a/source/shared_lib/sources/platform/sdl/window_gl.cpp b/source/shared_lib/sources/platform/sdl/window_gl.cpp index f0f3c4c3f..31abfafdf 100644 --- a/source/shared_lib/sources/platform/sdl/window_gl.cpp +++ b/source/shared_lib/sources/platform/sdl/window_gl.cpp @@ -96,6 +96,38 @@ void WindowGl::swapBuffersGl(){ context.swapBuffers(); } +void WindowGl::eventToggleFullScreen(bool isFullscreen) { + Window::eventToggleFullScreen(isFullscreen); + + if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false) { + //SDL_Surface *cur_surface = SDL_GetVideoSurface(); + if(getScreenWindow() != NULL) { + if(getIsFullScreen()){ + SDL_SetWindowFullscreen(getScreenWindow(),SDL_WINDOW_FULLSCREEN_DESKTOP); + } + else { + SDL_SetWindowFullscreen(getScreenWindow(),0); + } + } + + if(isFullscreen) { + changeVideoModeFullScreen(isFullscreen); + ChangeVideoMode(true, getScreenWidth(), getScreenHeight(), + true,context.getColorBits(), context.getDepthBits(), context.getStencilBits(), + context.getHardware_acceleration(),context.getFullscreen_anti_aliasing(), + context.getGammaValue()); + + } + else { + changeVideoModeFullScreen(false); + ChangeVideoMode(true, getDesiredScreenWidth(), getDesiredScreenHeight(), + false,context.getColorBits(), context.getDepthBits(), context.getStencilBits(), + context.getHardware_acceleration(),context.getFullscreen_anti_aliasing(), + context.getGammaValue()); + } + } +} + // changes display resolution at any time bool WindowGl::ChangeVideoMode(bool preserveContext, int resWidth, int resHeight, bool fullscreenWindow,