diff --git a/engines/stark/gfx/driver.cpp b/engines/stark/gfx/driver.cpp index 36643f2a5be..350db108f8b 100644 --- a/engines/stark/gfx/driver.cpp +++ b/engines/stark/gfx/driver.cpp @@ -66,23 +66,31 @@ void Driver::toggleFullscreen() const { g_system->setFeatureState(OSystem::kFeatureFullscreenMode, !oldFullscreen); } -void Driver::computeScreenViewport() { +bool Driver::computeScreenViewport() { int32 screenWidth = g_system->getWidth(); int32 screenHeight = g_system->getHeight(); + Common::Rect viewport; if (g_system->getFeatureState(OSystem::kFeatureAspectRatioCorrection)) { // Aspect ratio correction int32 viewportWidth = MIN(screenWidth, screenHeight * kOriginalWidth / kOriginalHeight); int32 viewportHeight = MIN(screenHeight, screenWidth * kOriginalHeight / kOriginalWidth); - _screenViewport = Common::Rect(viewportWidth, viewportHeight); + viewport = Common::Rect(viewportWidth, viewportHeight); // Pillarboxing - _screenViewport.translate((screenWidth - viewportWidth) / 2, + viewport.translate((screenWidth - viewportWidth) / 2, (screenHeight - viewportHeight) / 2); } else { // Aspect ratio correction disabled, just stretch - _screenViewport = Common::Rect(screenWidth, screenHeight); + viewport = Common::Rect(screenWidth, screenHeight); } + + if (viewport == _screenViewport) { + return false; + } + + _screenViewport = viewport; + return true; } Common::Rect Driver::gameViewport() const { diff --git a/engines/stark/gfx/driver.h b/engines/stark/gfx/driver.h index 8c0897b2119..ac51e7f9054 100644 --- a/engines/stark/gfx/driver.h +++ b/engines/stark/gfx/driver.h @@ -54,7 +54,7 @@ public: */ void toggleFullscreen() const; - void computeScreenViewport(); + bool computeScreenViewport(); virtual void setScreenViewport(bool noScaling) = 0; // deprecated virtual void setViewport(const Common::Rect &rect) = 0; diff --git a/engines/stark/stark.cpp b/engines/stark/stark.cpp index b7af3e8bbe9..13575163cda 100644 --- a/engines/stark/stark.cpp +++ b/engines/stark/stark.cpp @@ -338,9 +338,7 @@ void StarkEngine::processEvents() { } else if (e.type == Common::EVENT_RBUTTONDOWN) { _userInterface->handleRightClick(); } else if (e.type == Common::EVENT_SCREEN_CHANGED) { - _gfx->computeScreenViewport(); - _fontProvider->initFonts(); - _userInterface->onScreenChanged(); + onScreenChanged(); } } } @@ -500,19 +498,19 @@ Common::String StarkEngine::formatSaveName(const char *target, int slot) { void StarkEngine::pauseEngineIntern(bool pause) { Engine::pauseEngineIntern(pause); - if (!_global || !_global->getLevel() || !_global->getCurrent() || !_frameLimiter) { - // This function may be called when an error occurs before the engine is fully initialized - return; + // This function may be called when an error occurs before the engine is fully initialized + if (_global && _global->getLevel() && _global->getCurrent()) { + _global->getLevel()->onEnginePause(pause); + _global->getCurrent()->getLevel()->onEnginePause(pause); + _global->getCurrent()->getLocation()->onEnginePause(pause); } - _global->getLevel()->onEnginePause(pause); - _global->getCurrent()->getLevel()->onEnginePause(pause); - _global->getCurrent()->getLocation()->onEnginePause(pause); - - _frameLimiter->pause(pause); + if (_frameLimiter) { + _frameLimiter->pause(pause); + } // Grab a game screen thumbnail in case we need one when writing a save file - if (_userInterface->isInGameScreen()) { + if (_userInterface && _userInterface->isInGameScreen()) { if (pause) { _userInterface->saveGameScreenThumbnail(); } else { @@ -520,9 +518,19 @@ void StarkEngine::pauseEngineIntern(bool pause) { } } - // The user may have moved the mouse while the engine was paused - if (!pause) { - StarkUserInterface->handleMouseMove(_eventMan->getMousePos()); + // The user may have moved the mouse or resized the window while the engine was paused + if (!pause && _userInterface) { + onScreenChanged(); + _userInterface->handleMouseMove(_eventMan->getMousePos()); } } + +void StarkEngine::onScreenChanged() const { + bool changed = _gfx->computeScreenViewport(); + if (changed) { + _fontProvider->initFonts(); + _userInterface->onScreenChanged(); + } +} + } // End of namespace Stark diff --git a/engines/stark/stark.h b/engines/stark/stark.h index 1c52d39e025..7a257e9775e 100644 --- a/engines/stark/stark.h +++ b/engines/stark/stark.h @@ -77,6 +77,7 @@ private: void mainLoop(); void updateDisplayScene(); void processEvents(); + void onScreenChanged() const; Gfx::Driver *_gfx; Gfx::FrameLimiter *_frameLimiter;