From aacae0daa5307ed8ca6e3794c508e9ed82d3b997 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Thu, 23 Nov 2023 03:21:16 +0330 Subject: [PATCH 01/55] Upon file deletion scroll to previous file or 0 if first on the list --- src/fheroes2/dialog/dialog_selectfile.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/fheroes2/dialog/dialog_selectfile.cpp b/src/fheroes2/dialog/dialog_selectfile.cpp index 9dee978f8d0..56207f51318 100644 --- a/src/fheroes2/dialog/dialog_selectfile.cpp +++ b/src/fheroes2/dialog/dialog_selectfile.cpp @@ -509,6 +509,9 @@ namespace listbox.updateScrollBarImage(); listbox.SetListContent( lists ); + + listbox.SetCurrent( std::max( listId - 1, 0 ) ); + } needRedraw = true; From fddf90f810c6214eab36a09f36ae1026757f1e1f Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Thu, 23 Nov 2023 08:19:21 +0330 Subject: [PATCH 02/55] styling fix --- src/fheroes2/dialog/dialog_selectfile.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/fheroes2/dialog/dialog_selectfile.cpp b/src/fheroes2/dialog/dialog_selectfile.cpp index 56207f51318..46ac51b33cb 100644 --- a/src/fheroes2/dialog/dialog_selectfile.cpp +++ b/src/fheroes2/dialog/dialog_selectfile.cpp @@ -509,9 +509,7 @@ namespace listbox.updateScrollBarImage(); listbox.SetListContent( lists ); - listbox.SetCurrent( std::max( listId - 1, 0 ) ); - } needRedraw = true; From 622ccc35bf72aee91832d752e44327d74cd710aa Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Thu, 23 Nov 2023 11:11:42 +0330 Subject: [PATCH 03/55] _displayMonitor Property Decleration Getter And Setter Defenition Setting File Reader And Writer Updated --- src/fheroes2/system/settings.cpp | 13 +++++++++++++ src/fheroes2/system/settings.h | 10 +++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/fheroes2/system/settings.cpp b/src/fheroes2/system/settings.cpp index a24580fb99a..5df63e998a6 100644 --- a/src/fheroes2/system/settings.cpp +++ b/src/fheroes2/system/settings.cpp @@ -102,6 +102,7 @@ Settings::Settings() , battle_speed( DEFAULT_BATTLE_SPEED ) , game_type( 0 ) , preferably_count_players( 0 ) + , _displayMonitor(0) { _optGlobal.SetModes( GLOBAL_FIRST_RUN ); _optGlobal.SetModes( GLOBAL_SHOW_INTRO ); @@ -326,6 +327,10 @@ bool Settings::Read( const std::string & filePath ) _optGlobal.SetModes( GLOBAL_ENABLE_EDITOR ); } + if ( config.Exists( "monitor" ) ) { + setDisplayMonitor( std::max( config.IntParams( "monitor" ), 0 ) ); + } + return true; } @@ -477,6 +482,9 @@ std::string Settings::String() const os << "editor = beta" << std::endl; } + os << std::endl << "# Display Monitor for Multi-Monitor Setups (defaults to first monitor)" << std::endl; + os << "monitor = " << DisplayMonitor() << std::endl; + return os.str(); } @@ -955,6 +963,11 @@ void Settings::setDebug( int debug ) Logging::setDebugLevel( debug ); } + +void Settings::setDisplayMonitor( int monitor ) { + _displayMonitor = monitor; +} + void Settings::SetSoundVolume( int v ) { sound_volume = std::clamp( v, 0, 10 ); diff --git a/src/fheroes2/system/settings.h b/src/fheroes2/system/settings.h index cb58d93496c..264dd5c431e 100644 --- a/src/fheroes2/system/settings.h +++ b/src/fheroes2/system/settings.h @@ -249,7 +249,8 @@ class Settings void setHideInterface( const bool enable ); void setEvilInterface( const bool enable ); void setScreenScalingTypeNearest( const bool enable ); - + + void setDisplayMonitor( int monitor ); void SetSoundVolume( int v ); void SetMusicVolume( int v ); @@ -260,6 +261,11 @@ class Settings bool setGameLanguage( const std::string & language ); + int DisplayMonitor() const + { + return _displayMonitor; + } + int SoundVolume() const { return sound_volume; @@ -443,6 +449,8 @@ class Settings BitModes _optGlobal; fheroes2::ResolutionInfo _resolutionInfo; + int _displayMonitor; + int game_difficulty; std::string path_program; From 086cbcb7738e17a6625ba11e51f8125eb1080aad Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Thu, 23 Nov 2023 11:16:38 +0330 Subject: [PATCH 04/55] adding _displayMonitor Property to BaseRenderEngine and Display Class --- src/engine/screen.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/engine/screen.h b/src/engine/screen.h index bb2d2672b82..203e348ec30 100644 --- a/src/engine/screen.h +++ b/src/engine/screen.h @@ -139,10 +139,21 @@ namespace fheroes2 return _nearestScaling; } + int DisplayMonitor() const + { + return _displayMonitor; + } + + void setDisplayMonitor( int monitor ) + { + _displayMonitor = monitor; + } + protected: BaseRenderEngine() : _isFullScreen( false ) , _nearestScaling( false ) + , _displayMonitor( 0 ) { // Do nothing. } @@ -178,6 +189,8 @@ namespace fheroes2 private: bool _isFullScreen; + int _displayMonitor; + bool _nearestScaling; }; @@ -209,6 +222,16 @@ namespace fheroes2 // Do not call this method. It serves as a patch over the basic class. void resize( int32_t width_, int32_t height_ ) override; + + void setDisplayMonitor(int monitor) + { + _displayMonitor = monitor; + } + + int DisplayMonitor() const + { + return _displayMonitor; + } void setResolution( ResolutionInfo info ); @@ -252,6 +275,7 @@ namespace fheroes2 PostRenderProcessing _postprocessing; uint8_t * _renderSurface; + int _displayMonitor; // Previous area drawn on the screen. Rect _prevRoi; From 2c42c9c85c5cd23dc0ab0ac112d939629da3a3ae Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Thu, 23 Nov 2023 11:18:31 +0330 Subject: [PATCH 05/55] passing Display Count to render Engine from Display Changing SDL_CreateWindow to process monitor coordinates --- src/engine/screen.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/engine/screen.cpp b/src/engine/screen.cpp index 240b022e758..963905c30df 100644 --- a/src/engine/screen.cpp +++ b/src/engine/screen.cpp @@ -1071,8 +1071,11 @@ namespace } flags |= SDL_WINDOW_RESIZABLE; - - _window = SDL_CreateWindow( _previousWindowTitle.data(), _prevWindowPos.x, _prevWindowPos.y, resolutionInfo.screenWidth, resolutionInfo.screenHeight, flags ); + + SDL_Rect monRect; + SDL_GetDisplayBounds( DisplayMonitor() , &monRect ); + + _window = SDL_CreateWindow( _previousWindowTitle.data(), monRect.x + _prevWindowPos.x, monRect.y + _prevWindowPos.y, resolutionInfo.screenWidth, resolutionInfo.screenHeight, flags ); if ( _window == nullptr ) { ERROR_LOG( "Failed to create an application window of " << resolutionInfo.screenWidth << " x " << resolutionInfo.screenHeight << " size. The error: " << SDL_GetError() ) @@ -1161,7 +1164,7 @@ namespace SDL_Renderer * _renderer; SDL_Texture * _texture; int _driverIndex; - + std::string _previousWindowTitle; fheroes2::Point _prevWindowPos; fheroes2::Size _currentScreenResolution; @@ -1336,11 +1339,12 @@ namespace fheroes2 && info.screenHeight == _screenSize.height ) // nothing to resize return; + _engine->setDisplayMonitor(_displayMonitor); const bool isFullScreen = _engine->isFullScreen(); // deallocate engine resources _engine->clear(); - + _prevRoi = {}; // allocate engine resources From b9be3e0fd70b9752347dc08bee45ed55e4268e63 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Thu, 23 Nov 2023 11:21:26 +0330 Subject: [PATCH 06/55] - Changing GraphicsSetting Dialog to 6 Button ICN - Adding Display Monitor Button - Adding Filler Image to fill 6th Empty Space --- .../dialog/dialog_graphics_settings.cpp | 45 ++++++++++++++++--- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/src/fheroes2/dialog/dialog_graphics_settings.cpp b/src/fheroes2/dialog/dialog_graphics_settings.cpp index f98a3ccbfd2..461cfbe722e 100644 --- a/src/fheroes2/dialog/dialog_graphics_settings.cpp +++ b/src/fheroes2/dialog/dialog_graphics_settings.cpp @@ -49,17 +49,30 @@ namespace Mode, VSync, SystemInfo, + MonitorList, Exit }; - const fheroes2::Size offsetBetweenOptions{ 118, 110 }; - const fheroes2::Point optionOffset{ 69, 47 }; + const fheroes2::Size offsetBetweenOptions{ 92, 110 }; + const fheroes2::Point optionOffset{ 36, 47 }; const int32_t optionWindowSize{ 65 }; const fheroes2::Rect resolutionRoi{ optionOffset.x, optionOffset.y, optionWindowSize, optionWindowSize }; const fheroes2::Rect modeRoi{ optionOffset.x + offsetBetweenOptions.width, optionOffset.y, optionWindowSize, optionWindowSize }; const fheroes2::Rect vSyncRoi{ optionOffset.x, optionOffset.y + offsetBetweenOptions.height, optionWindowSize, optionWindowSize }; const fheroes2::Rect systemInfoRoi{ optionOffset.x + offsetBetweenOptions.width, optionOffset.y + offsetBetweenOptions.height, optionWindowSize, optionWindowSize }; + + const fheroes2::Rect monitorList{ optionOffset.x + offsetBetweenOptions.width * 2, optionOffset.y, optionWindowSize, optionWindowSize }; + const fheroes2::Rect fillerRoi{ optionOffset.x + offsetBetweenOptions.width * 2 ,optionOffset.y + offsetBetweenOptions.height + ,optionWindowSize ,optionWindowSize }; + + void drawMonitor(const fheroes2::Rect& optionRoi) { + + const Settings & conf = Settings::Get(); + fheroes2::drawOption( optionRoi, fheroes2::AGG::GetICN( ICN::SPANEL, Settings::Get().isEvilInterfaceEnabled() ? 17 : 16 ), "Display Monitor" + ,SDL_GetDisplayName(conf.DisplayMonitor()) + ,fheroes2::UiOptionTextWidth::TWO_ELEMENTS_ROW ); + } void drawResolution( const fheroes2::Rect & optionRoi ) { @@ -119,6 +132,7 @@ namespace fheroes2::drawOption( optionRoi, image, _( "System Info" ), isSystemInfoDisplayed ? _( "on" ) : _( "off" ), fheroes2::UiOptionTextWidth::TWO_ELEMENTS_ROW ); } + SelectedWindow showConfigurationWindow() { @@ -126,8 +140,12 @@ namespace const Settings & conf = Settings::Get(); const bool isEvilInterface = conf.isEvilInterfaceEnabled(); - const fheroes2::Sprite & dialog = fheroes2::AGG::GetICN( ( isEvilInterface ? ICN::ESPANBKG_EVIL : ICN::ESPANBKG ), 0 ); + const fheroes2::Sprite & dialog = fheroes2::AGG::GetICN( ( isEvilInterface ? ICN::CSPANBKE : ICN::CSPANBKG ), 0 ); const fheroes2::Sprite & dialogShadow = fheroes2::AGG::GetICN( ( isEvilInterface ? ICN::CSPANBKE : ICN::CSPANBKG ), 1 ); + + fheroes2::Sprite placeholder = fheroes2::AGG::GetICN( Settings::Get().isEvilInterfaceEnabled() ? ICN::STONBAKE : ICN::STONEBAK, 0 ); + //this image needs to be bigger than other buttons cause it's gonna fill in shadow as well + placeholder = fheroes2::Crop( placeholder, 0, 0, optionWindowSize+20, optionWindowSize +20 ); const fheroes2::Point dialogOffset( ( display.width() - dialog.width() ) / 2, ( display.height() - dialog.height() ) / 2 ); const fheroes2::Point shadowOffset( dialogOffset.x - BORDERWIDTH, dialogOffset.y ); @@ -138,6 +156,9 @@ namespace fheroes2::Blit( dialogShadow, display, windowRoi.x - BORDERWIDTH, windowRoi.y + BORDERWIDTH ); fheroes2::Blit( dialog, display, windowRoi.x, windowRoi.y ); + //filling the empty space alognside the shadow + fheroes2::Blit( placeholder, display, windowRoi.x + optionOffset.x -10 + offsetBetweenOptions.width * 2 + , windowRoi.y + optionOffset.y -10 + offsetBetweenOptions.height ); fheroes2::ImageRestorer emptyDialogRestorer( display, windowRoi.x, windowRoi.y, windowRoi.width, windowRoi.height ); @@ -145,12 +166,15 @@ namespace const fheroes2::Rect windowModeRoi( modeRoi + windowRoi.getPosition() ); const fheroes2::Rect windowVSyncRoi( vSyncRoi + windowRoi.getPosition() ); const fheroes2::Rect windowSystemInfoRoi( systemInfoRoi + windowRoi.getPosition() ); - - const auto drawOptions = [&windowResolutionRoi, &windowModeRoi, &windowVSyncRoi, &windowSystemInfoRoi]() { + + const fheroes2::Rect windowMonitorList( monitorList + windowRoi.getPosition() ); + + const auto drawOptions = [&windowResolutionRoi, &windowModeRoi, &windowVSyncRoi, &windowSystemInfoRoi, &windowMonitorList]() { drawResolution( windowResolutionRoi ); drawMode( windowModeRoi ); drawVSync( windowVSyncRoi ); drawSystemInfo( windowSystemInfoRoi ); + drawMonitor(windowMonitorList); }; drawOptions(); @@ -187,6 +211,9 @@ namespace if ( le.MouseClickLeft( windowSystemInfoRoi ) ) { return SelectedWindow::SystemInfo; } + if ( le.MouseClickLeft( windowMonitorList ) ) { + return SelectedWindow::MonitorList; + } if ( le.MousePressRight( windowResolutionRoi ) ) { fheroes2::showStandardTextMessage( _( "Select Game Resolution" ), _( "Change the resolution of the game." ), 0 ); @@ -197,6 +224,9 @@ namespace else if ( le.MousePressRight( windowVSyncRoi ) ) { fheroes2::showStandardTextMessage( _( "V-Sync" ), _( "The V-Sync option can be enabled to resolve flickering issues on some monitors." ), 0 ); } + else if ( le.MousePressRight( windowMonitorList ) ) { + fheroes2::showStandardTextMessage( _( "Monitor Selection" ), _( "Toggle Between available monitors, Restart Required to take Effect" ), 0 ); + } if ( le.MousePressRight( windowSystemInfoRoi ) ) { fheroes2::showStandardTextMessage( _( "System Info" ), _( "Show extra information such as FPS and current time." ), 0 ); } @@ -253,6 +283,11 @@ namespace fheroes2 conf.Save( Settings::configFileName ); windowType = SelectedWindow::Configuration; break; + case SelectedWindow::MonitorList: + conf.setDisplayMonitor( ( conf.DisplayMonitor() + 1 ) % SDL_GetNumVideoDisplays() ); + conf.Save( Settings::configFileName ); + windowType = SelectedWindow::Configuration; + break; default: return; } From 1f49b7278c50cd75db8ada9c666c1fa53a5aa32d Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Thu, 23 Nov 2023 11:22:38 +0330 Subject: [PATCH 07/55] Setting Display Before Create the Window either from setting or default --- src/fheroes2/game/fheroes2.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/fheroes2/game/fheroes2.cpp b/src/fheroes2/game/fheroes2.cpp index 29b75cd2cca..b9575f9b0fc 100644 --- a/src/fheroes2/game/fheroes2.cpp +++ b/src/fheroes2/game/fheroes2.cpp @@ -166,10 +166,12 @@ namespace bestResolution = info; } } - + // set display monitor to first monitor available + display.setDisplayMonitor( 0 ); display.setResolution( bestResolution ); } else { + display.setDisplayMonitor( conf.DisplayMonitor() ); display.setResolution( conf.currentResolutionInfo() ); } From 3651946af42916feca96d8565ed936ed94717cf8 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Thu, 23 Nov 2023 12:15:12 +0330 Subject: [PATCH 08/55] styling fix --- .../dialog/dialog_graphics_settings.cpp | 24 ++++++++----------- src/fheroes2/system/settings.cpp | 6 ++--- src/fheroes2/system/settings.h | 1 - 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/fheroes2/dialog/dialog_graphics_settings.cpp b/src/fheroes2/dialog/dialog_graphics_settings.cpp index 461cfbe722e..af6463d3c2c 100644 --- a/src/fheroes2/dialog/dialog_graphics_settings.cpp +++ b/src/fheroes2/dialog/dialog_graphics_settings.cpp @@ -61,17 +61,14 @@ namespace const fheroes2::Rect modeRoi{ optionOffset.x + offsetBetweenOptions.width, optionOffset.y, optionWindowSize, optionWindowSize }; const fheroes2::Rect vSyncRoi{ optionOffset.x, optionOffset.y + offsetBetweenOptions.height, optionWindowSize, optionWindowSize }; const fheroes2::Rect systemInfoRoi{ optionOffset.x + offsetBetweenOptions.width, optionOffset.y + offsetBetweenOptions.height, optionWindowSize, optionWindowSize }; - const fheroes2::Rect monitorList{ optionOffset.x + offsetBetweenOptions.width * 2, optionOffset.y, optionWindowSize, optionWindowSize }; - const fheroes2::Rect fillerRoi{ optionOffset.x + offsetBetweenOptions.width * 2 ,optionOffset.y + offsetBetweenOptions.height - ,optionWindowSize ,optionWindowSize }; + const fheroes2::Rect fillerRoi{ optionOffset.x + offsetBetweenOptions.width * 2, optionOffset.y + offsetBetweenOptions.height, optionWindowSize, optionWindowSize }; - void drawMonitor(const fheroes2::Rect& optionRoi) { - + void drawMonitor( const fheroes2::Rect & optionRoi ) + { const Settings & conf = Settings::Get(); - fheroes2::drawOption( optionRoi, fheroes2::AGG::GetICN( ICN::SPANEL, Settings::Get().isEvilInterfaceEnabled() ? 17 : 16 ), "Display Monitor" - ,SDL_GetDisplayName(conf.DisplayMonitor()) - ,fheroes2::UiOptionTextWidth::TWO_ELEMENTS_ROW ); + fheroes2::drawOption( optionRoi, fheroes2::AGG::GetICN( ICN::SPANEL, Settings::Get().isEvilInterfaceEnabled() ? 17 : 16 ), "Display Monitor", + SDL_GetDisplayName( conf.DisplayMonitor() ), fheroes2::UiOptionTextWidth::TWO_ELEMENTS_ROW ); } void drawResolution( const fheroes2::Rect & optionRoi ) @@ -132,7 +129,6 @@ namespace fheroes2::drawOption( optionRoi, image, _( "System Info" ), isSystemInfoDisplayed ? _( "on" ) : _( "off" ), fheroes2::UiOptionTextWidth::TWO_ELEMENTS_ROW ); } - SelectedWindow showConfigurationWindow() { @@ -144,8 +140,8 @@ namespace const fheroes2::Sprite & dialogShadow = fheroes2::AGG::GetICN( ( isEvilInterface ? ICN::CSPANBKE : ICN::CSPANBKG ), 1 ); fheroes2::Sprite placeholder = fheroes2::AGG::GetICN( Settings::Get().isEvilInterfaceEnabled() ? ICN::STONBAKE : ICN::STONEBAK, 0 ); - //this image needs to be bigger than other buttons cause it's gonna fill in shadow as well - placeholder = fheroes2::Crop( placeholder, 0, 0, optionWindowSize+20, optionWindowSize +20 ); + // this image needs to be bigger than other buttons cause it's gonna fill in shadow as well + placeholder = fheroes2::Crop( placeholder, 0, 0, optionWindowSize + 20, optionWindowSize + 20 ); const fheroes2::Point dialogOffset( ( display.width() - dialog.width() ) / 2, ( display.height() - dialog.height() ) / 2 ); const fheroes2::Point shadowOffset( dialogOffset.x - BORDERWIDTH, dialogOffset.y ); @@ -156,9 +152,9 @@ namespace fheroes2::Blit( dialogShadow, display, windowRoi.x - BORDERWIDTH, windowRoi.y + BORDERWIDTH ); fheroes2::Blit( dialog, display, windowRoi.x, windowRoi.y ); - //filling the empty space alognside the shadow - fheroes2::Blit( placeholder, display, windowRoi.x + optionOffset.x -10 + offsetBetweenOptions.width * 2 - , windowRoi.y + optionOffset.y -10 + offsetBetweenOptions.height ); + // filling the empty space alognside the shadow + fheroes2::Blit( placeholder, display, windowRoi.x + optionOffset.x - 10 + offsetBetweenOptions.width * 2, + windowRoi.y + optionOffset.y - 10 + offsetBetweenOptions.height ); fheroes2::ImageRestorer emptyDialogRestorer( display, windowRoi.x, windowRoi.y, windowRoi.width, windowRoi.height ); diff --git a/src/fheroes2/system/settings.cpp b/src/fheroes2/system/settings.cpp index 5df63e998a6..6172cc09230 100644 --- a/src/fheroes2/system/settings.cpp +++ b/src/fheroes2/system/settings.cpp @@ -102,7 +102,7 @@ Settings::Settings() , battle_speed( DEFAULT_BATTLE_SPEED ) , game_type( 0 ) , preferably_count_players( 0 ) - , _displayMonitor(0) + , _displayMonitor( 0 ) { _optGlobal.SetModes( GLOBAL_FIRST_RUN ); _optGlobal.SetModes( GLOBAL_SHOW_INTRO ); @@ -963,8 +963,8 @@ void Settings::setDebug( int debug ) Logging::setDebugLevel( debug ); } - -void Settings::setDisplayMonitor( int monitor ) { +void Settings::setDisplayMonitor( int monitor ) +{ _displayMonitor = monitor; } diff --git a/src/fheroes2/system/settings.h b/src/fheroes2/system/settings.h index 264dd5c431e..c50158c1c5c 100644 --- a/src/fheroes2/system/settings.h +++ b/src/fheroes2/system/settings.h @@ -249,7 +249,6 @@ class Settings void setHideInterface( const bool enable ); void setEvilInterface( const bool enable ); void setScreenScalingTypeNearest( const bool enable ); - void setDisplayMonitor( int monitor ); void SetSoundVolume( int v ); void SetMusicVolume( int v ); From 0fcc4ea2ea0f556a6b83761e2b2848e0e0e9b169 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Thu, 23 Nov 2023 16:08:29 +0330 Subject: [PATCH 09/55] more sudden style fix --- src/engine/screen.cpp | 7 ++----- src/fheroes2/dialog/dialog_graphics_settings.cpp | 5 +---- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/engine/screen.cpp b/src/engine/screen.cpp index 963905c30df..d05e1688041 100644 --- a/src/engine/screen.cpp +++ b/src/engine/screen.cpp @@ -1071,11 +1071,10 @@ namespace } flags |= SDL_WINDOW_RESIZABLE; - SDL_Rect monRect; SDL_GetDisplayBounds( DisplayMonitor() , &monRect ); - - _window = SDL_CreateWindow( _previousWindowTitle.data(), monRect.x + _prevWindowPos.x, monRect.y + _prevWindowPos.y, resolutionInfo.screenWidth, resolutionInfo.screenHeight, flags ); + _window = SDL_CreateWindow( _previousWindowTitle.data(), monRect.x + _prevWindowPos.x, monRect.y + _prevWindowPos.y, resolutionInfo.screenWidth, + resolutionInfo.screenHeight, flags ); if ( _window == nullptr ) { ERROR_LOG( "Failed to create an application window of " << resolutionInfo.screenWidth << " x " << resolutionInfo.screenHeight << " size. The error: " << SDL_GetError() ) @@ -1164,7 +1163,6 @@ namespace SDL_Renderer * _renderer; SDL_Texture * _texture; int _driverIndex; - std::string _previousWindowTitle; fheroes2::Point _prevWindowPos; fheroes2::Size _currentScreenResolution; @@ -1344,7 +1342,6 @@ namespace fheroes2 // deallocate engine resources _engine->clear(); - _prevRoi = {}; // allocate engine resources diff --git a/src/fheroes2/dialog/dialog_graphics_settings.cpp b/src/fheroes2/dialog/dialog_graphics_settings.cpp index af6463d3c2c..09394f28a13 100644 --- a/src/fheroes2/dialog/dialog_graphics_settings.cpp +++ b/src/fheroes2/dialog/dialog_graphics_settings.cpp @@ -138,7 +138,6 @@ namespace const bool isEvilInterface = conf.isEvilInterfaceEnabled(); const fheroes2::Sprite & dialog = fheroes2::AGG::GetICN( ( isEvilInterface ? ICN::CSPANBKE : ICN::CSPANBKG ), 0 ); const fheroes2::Sprite & dialogShadow = fheroes2::AGG::GetICN( ( isEvilInterface ? ICN::CSPANBKE : ICN::CSPANBKG ), 1 ); - fheroes2::Sprite placeholder = fheroes2::AGG::GetICN( Settings::Get().isEvilInterfaceEnabled() ? ICN::STONBAKE : ICN::STONEBAK, 0 ); // this image needs to be bigger than other buttons cause it's gonna fill in shadow as well placeholder = fheroes2::Crop( placeholder, 0, 0, optionWindowSize + 20, optionWindowSize + 20 ); @@ -162,15 +161,13 @@ namespace const fheroes2::Rect windowModeRoi( modeRoi + windowRoi.getPosition() ); const fheroes2::Rect windowVSyncRoi( vSyncRoi + windowRoi.getPosition() ); const fheroes2::Rect windowSystemInfoRoi( systemInfoRoi + windowRoi.getPosition() ); - const fheroes2::Rect windowMonitorList( monitorList + windowRoi.getPosition() ); - const auto drawOptions = [&windowResolutionRoi, &windowModeRoi, &windowVSyncRoi, &windowSystemInfoRoi, &windowMonitorList]() { drawResolution( windowResolutionRoi ); drawMode( windowModeRoi ); drawVSync( windowVSyncRoi ); drawSystemInfo( windowSystemInfoRoi ); - drawMonitor(windowMonitorList); + drawMonitor( windowMonitorList ); }; drawOptions(); From 64aa1cf9ee3af25db3019e056d19aa8917e18806 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Thu, 23 Nov 2023 19:15:14 +0330 Subject: [PATCH 10/55] More Sudden styles fixes from Visual studio --- src/engine/screen.cpp | 4 ++-- src/engine/screen.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/engine/screen.cpp b/src/engine/screen.cpp index d05e1688041..f1cb48c1972 100644 --- a/src/engine/screen.cpp +++ b/src/engine/screen.cpp @@ -1072,7 +1072,7 @@ namespace flags |= SDL_WINDOW_RESIZABLE; SDL_Rect monRect; - SDL_GetDisplayBounds( DisplayMonitor() , &monRect ); + SDL_GetDisplayBounds( DisplayMonitor(), &monRect ); _window = SDL_CreateWindow( _previousWindowTitle.data(), monRect.x + _prevWindowPos.x, monRect.y + _prevWindowPos.y, resolutionInfo.screenWidth, resolutionInfo.screenHeight, flags ); if ( _window == nullptr ) { @@ -1337,7 +1337,7 @@ namespace fheroes2 && info.screenHeight == _screenSize.height ) // nothing to resize return; - _engine->setDisplayMonitor(_displayMonitor); + _engine->setDisplayMonitor( _displayMonitor ); const bool isFullScreen = _engine->isFullScreen(); // deallocate engine resources diff --git a/src/engine/screen.h b/src/engine/screen.h index 203e348ec30..8d86e20330f 100644 --- a/src/engine/screen.h +++ b/src/engine/screen.h @@ -222,8 +222,8 @@ namespace fheroes2 // Do not call this method. It serves as a patch over the basic class. void resize( int32_t width_, int32_t height_ ) override; - - void setDisplayMonitor(int monitor) + + void setDisplayMonitor( int monitor ) { _displayMonitor = monitor; } From e121a1d4a3cac523acb3d3d106fb17260e4c8049 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Thu, 23 Nov 2023 20:08:11 +0330 Subject: [PATCH 11/55] Reordering for the Analyzers [-Wreorder-ctor] and [-Werror=reorder] --- src/engine/screen.h | 3 ++- src/fheroes2/system/settings.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/engine/screen.h b/src/engine/screen.h index 8d86e20330f..3f9804545f5 100644 --- a/src/engine/screen.h +++ b/src/engine/screen.h @@ -152,8 +152,9 @@ namespace fheroes2 protected: BaseRenderEngine() : _isFullScreen( false ) - , _nearestScaling( false ) , _displayMonitor( 0 ) + , _nearestScaling( false ) + { // Do nothing. } diff --git a/src/fheroes2/system/settings.cpp b/src/fheroes2/system/settings.cpp index 6172cc09230..21aec86e939 100644 --- a/src/fheroes2/system/settings.cpp +++ b/src/fheroes2/system/settings.cpp @@ -101,8 +101,8 @@ Settings::Settings() , scroll_speed( SCROLL_SPEED_NORMAL ) , battle_speed( DEFAULT_BATTLE_SPEED ) , game_type( 0 ) - , preferably_count_players( 0 ) , _displayMonitor( 0 ) + , preferably_count_players( 0 ) { _optGlobal.SetModes( GLOBAL_FIRST_RUN ); _optGlobal.SetModes( GLOBAL_SHOW_INTRO ); From d88c6fd8c0f5b53fc2e5bbd47786fa27cb549176 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Thu, 23 Nov 2023 23:25:42 +0330 Subject: [PATCH 12/55] More Reordering For Analyzers Compiled with C5038 enabled as error --- src/fheroes2/system/settings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fheroes2/system/settings.cpp b/src/fheroes2/system/settings.cpp index 21aec86e939..c76407ce873 100644 --- a/src/fheroes2/system/settings.cpp +++ b/src/fheroes2/system/settings.cpp @@ -91,6 +91,7 @@ std::string Settings::GetVersion() Settings::Settings() : _resolutionInfo( fheroes2::Display::DEFAULT_WIDTH, fheroes2::Display::DEFAULT_HEIGHT ) + , _displayMonitor( 0 ) , game_difficulty( Difficulty::NORMAL ) , sound_volume( 6 ) , music_volume( 6 ) @@ -101,7 +102,6 @@ Settings::Settings() , scroll_speed( SCROLL_SPEED_NORMAL ) , battle_speed( DEFAULT_BATTLE_SPEED ) , game_type( 0 ) - , _displayMonitor( 0 ) , preferably_count_players( 0 ) { _optGlobal.SetModes( GLOBAL_FIRST_RUN ); From 604f0df6fd3c89688d58534b983d49cdaf3f22f3 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Fri, 24 Nov 2023 01:42:56 +0330 Subject: [PATCH 13/55] Update src/engine/screen.h Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/engine/screen.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/screen.h b/src/engine/screen.h index 3f9804545f5..0153e9680b7 100644 --- a/src/engine/screen.h +++ b/src/engine/screen.h @@ -152,7 +152,7 @@ namespace fheroes2 protected: BaseRenderEngine() : _isFullScreen( false ) - , _displayMonitor( 0 ) + , , _nearestScaling( false ) { From 04dc87893efbf47e33eded865ef4340b954bdf8a Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Fri, 24 Nov 2023 01:43:03 +0330 Subject: [PATCH 14/55] Update src/engine/screen.h Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/engine/screen.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/screen.h b/src/engine/screen.h index 0153e9680b7..1ed20a9eb12 100644 --- a/src/engine/screen.h +++ b/src/engine/screen.h @@ -190,7 +190,7 @@ namespace fheroes2 private: bool _isFullScreen; - int _displayMonitor; + int _displayMonitor{ 0 }; bool _nearestScaling; }; From 20f480ed394de3ed354f1e635b4c468c115d968c Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Fri, 24 Nov 2023 01:52:05 +0330 Subject: [PATCH 15/55] Update screen.h --- src/engine/screen.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/engine/screen.h b/src/engine/screen.h index 1ed20a9eb12..358648f28be 100644 --- a/src/engine/screen.h +++ b/src/engine/screen.h @@ -152,7 +152,6 @@ namespace fheroes2 protected: BaseRenderEngine() : _isFullScreen( false ) - , , _nearestScaling( false ) { From 53b5b4678bca36279d22b7858b7fe99c01bd6a20 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Fri, 24 Nov 2023 16:15:44 +0330 Subject: [PATCH 16/55] Update dialog_graphics_settings.cpp include for analyzer --- src/fheroes2/dialog/dialog_graphics_settings.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/fheroes2/dialog/dialog_graphics_settings.cpp b/src/fheroes2/dialog/dialog_graphics_settings.cpp index 09394f28a13..7999b6b5cd6 100644 --- a/src/fheroes2/dialog/dialog_graphics_settings.cpp +++ b/src/fheroes2/dialog/dialog_graphics_settings.cpp @@ -24,6 +24,8 @@ #include #include +#include + #include "agg_image.h" #include "dialog_resolution.h" #include "game_hotkeys.h" From 2aa5eae7844735173d636061cdd80347868c515b Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Sat, 25 Nov 2023 13:03:18 +0330 Subject: [PATCH 17/55] Resolving Some Reviews For PR #8072 --- src/engine/screen.cpp | 2 ++ src/engine/screen.h | 2 +- src/fheroes2/dialog/dialog_selectfile.cpp | 1 - 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/engine/screen.cpp b/src/engine/screen.cpp index f1cb48c1972..3b9098487a9 100644 --- a/src/engine/screen.cpp +++ b/src/engine/screen.cpp @@ -1163,6 +1163,7 @@ namespace SDL_Renderer * _renderer; SDL_Texture * _texture; int _driverIndex; + std::string _previousWindowTitle; fheroes2::Point _prevWindowPos; fheroes2::Size _currentScreenResolution; @@ -1342,6 +1343,7 @@ namespace fheroes2 // deallocate engine resources _engine->clear(); + _prevRoi = {}; // allocate engine resources diff --git a/src/engine/screen.h b/src/engine/screen.h index 358648f28be..3f96471ed84 100644 --- a/src/engine/screen.h +++ b/src/engine/screen.h @@ -144,7 +144,7 @@ namespace fheroes2 return _displayMonitor; } - void setDisplayMonitor( int monitor ) + void setDisplayMonitor( const int monitor ) { _displayMonitor = monitor; } diff --git a/src/fheroes2/dialog/dialog_selectfile.cpp b/src/fheroes2/dialog/dialog_selectfile.cpp index 46ac51b33cb..9dee978f8d0 100644 --- a/src/fheroes2/dialog/dialog_selectfile.cpp +++ b/src/fheroes2/dialog/dialog_selectfile.cpp @@ -509,7 +509,6 @@ namespace listbox.updateScrollBarImage(); listbox.SetListContent( lists ); - listbox.SetCurrent( std::max( listId - 1, 0 ) ); } needRedraw = true; From 6f62708ef25f3dba3cd73de39bc6f69f26361642 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Fri, 1 Dec 2023 23:47:59 +0330 Subject: [PATCH 18/55] Adding InterfaceType to Graphic Settings Changing Monitor Selection Icon Moving SDL related function as function inside Screen.h --- src/engine/screen.cpp | 11 +++ src/engine/screen.h | 3 + .../dialog/dialog_graphics_settings.cpp | 68 +++++++++++++------ 3 files changed, 62 insertions(+), 20 deletions(-) diff --git a/src/engine/screen.cpp b/src/engine/screen.cpp index 3b9098487a9..b521b4aa917 100644 --- a/src/engine/screen.cpp +++ b/src/engine/screen.cpp @@ -1475,4 +1475,15 @@ namespace fheroes2 { return *( Display::instance()._cursor ); } + + int getNumberOfVideoDisplays() + { + return SDL_GetNumVideoDisplays(); + } + + const char * getDisplayName( const int display ) + { + return SDL_GetDisplayName( display ); + } + } diff --git a/src/engine/screen.h b/src/engine/screen.h index 3f96471ed84..d590e952b58 100644 --- a/src/engine/screen.h +++ b/src/engine/screen.h @@ -35,6 +35,9 @@ namespace fheroes2 class Cursor; class Display; + int getNumberOfVideoDisplays(); + const char * getDisplayName( const int display ); + struct ResolutionInfo { ResolutionInfo() = default; diff --git a/src/fheroes2/dialog/dialog_graphics_settings.cpp b/src/fheroes2/dialog/dialog_graphics_settings.cpp index 7999b6b5cd6..50a48e11c6d 100644 --- a/src/fheroes2/dialog/dialog_graphics_settings.cpp +++ b/src/fheroes2/dialog/dialog_graphics_settings.cpp @@ -24,8 +24,6 @@ #include #include -#include - #include "agg_image.h" #include "dialog_resolution.h" #include "game_hotkeys.h" @@ -52,6 +50,7 @@ namespace VSync, SystemInfo, MonitorList, + InterfaceType, Exit }; @@ -63,14 +62,15 @@ namespace const fheroes2::Rect modeRoi{ optionOffset.x + offsetBetweenOptions.width, optionOffset.y, optionWindowSize, optionWindowSize }; const fheroes2::Rect vSyncRoi{ optionOffset.x, optionOffset.y + offsetBetweenOptions.height, optionWindowSize, optionWindowSize }; const fheroes2::Rect systemInfoRoi{ optionOffset.x + offsetBetweenOptions.width, optionOffset.y + offsetBetweenOptions.height, optionWindowSize, optionWindowSize }; - const fheroes2::Rect monitorList{ optionOffset.x + offsetBetweenOptions.width * 2, optionOffset.y, optionWindowSize, optionWindowSize }; - const fheroes2::Rect fillerRoi{ optionOffset.x + offsetBetweenOptions.width * 2, optionOffset.y + offsetBetweenOptions.height, optionWindowSize, optionWindowSize }; + const fheroes2::Rect monitorListRoi{ optionOffset.x + offsetBetweenOptions.width * 2, optionOffset.y, optionWindowSize, optionWindowSize }; + const fheroes2::Rect interfaceTypeRoi{ optionOffset.x + offsetBetweenOptions.width * 2, optionOffset.y + offsetBetweenOptions.height, optionWindowSize, + optionWindowSize }; void drawMonitor( const fheroes2::Rect & optionRoi ) { const Settings & conf = Settings::Get(); - fheroes2::drawOption( optionRoi, fheroes2::AGG::GetICN( ICN::SPANEL, Settings::Get().isEvilInterfaceEnabled() ? 17 : 16 ), "Display Monitor", - SDL_GetDisplayName( conf.DisplayMonitor() ), fheroes2::UiOptionTextWidth::TWO_ELEMENTS_ROW ); + fheroes2::drawOption( optionRoi, fheroes2::AGG::GetICN( ICN::GAME_OPTION_ICON, 1 ), "Display Monitor", fheroes2::getDisplayName( conf.DisplayMonitor() ), + fheroes2::UiOptionTextWidth::TWO_ELEMENTS_ROW ); } void drawResolution( const fheroes2::Rect & optionRoi ) @@ -132,6 +132,26 @@ namespace fheroes2::drawOption( optionRoi, image, _( "System Info" ), isSystemInfoDisplayed ? _( "on" ) : _( "off" ), fheroes2::UiOptionTextWidth::TWO_ELEMENTS_ROW ); } + void drawInterfaceType( const fheroes2::Rect & optionRoi ) + { + fheroes2::Sprite goodInterface = fheroes2::AGG::GetICN( ICN::SPANEL, 16 ); + fheroes2::Sprite evilInterface = fheroes2::AGG::GetICN( ICN::SPANEL, 17 ); + const Settings & conf = Settings::Get(); + const bool isEvilInterface = conf.isEvilInterfaceEnabled(); + + std::string value; + if ( isEvilInterface ) { + value = _( "Evil" ); + } + else { + value = _( "Good" ); + } + goodInterface = fheroes2::Crop( goodInterface, 0, 0, goodInterface.width() / 2, goodInterface.height() ); + fheroes2::Blit( goodInterface, evilInterface ); + + fheroes2::drawOption( optionRoi, evilInterface, _( "Interface Type" ), std::move( value ), fheroes2::UiOptionTextWidth::TWO_ELEMENTS_ROW ); + } + SelectedWindow showConfigurationWindow() { fheroes2::Display & display = fheroes2::Display::instance(); @@ -140,9 +160,6 @@ namespace const bool isEvilInterface = conf.isEvilInterfaceEnabled(); const fheroes2::Sprite & dialog = fheroes2::AGG::GetICN( ( isEvilInterface ? ICN::CSPANBKE : ICN::CSPANBKG ), 0 ); const fheroes2::Sprite & dialogShadow = fheroes2::AGG::GetICN( ( isEvilInterface ? ICN::CSPANBKE : ICN::CSPANBKG ), 1 ); - fheroes2::Sprite placeholder = fheroes2::AGG::GetICN( Settings::Get().isEvilInterfaceEnabled() ? ICN::STONBAKE : ICN::STONEBAK, 0 ); - // this image needs to be bigger than other buttons cause it's gonna fill in shadow as well - placeholder = fheroes2::Crop( placeholder, 0, 0, optionWindowSize + 20, optionWindowSize + 20 ); const fheroes2::Point dialogOffset( ( display.width() - dialog.width() ) / 2, ( display.height() - dialog.height() ) / 2 ); const fheroes2::Point shadowOffset( dialogOffset.x - BORDERWIDTH, dialogOffset.y ); @@ -153,9 +170,6 @@ namespace fheroes2::Blit( dialogShadow, display, windowRoi.x - BORDERWIDTH, windowRoi.y + BORDERWIDTH ); fheroes2::Blit( dialog, display, windowRoi.x, windowRoi.y ); - // filling the empty space alognside the shadow - fheroes2::Blit( placeholder, display, windowRoi.x + optionOffset.x - 10 + offsetBetweenOptions.width * 2, - windowRoi.y + optionOffset.y - 10 + offsetBetweenOptions.height ); fheroes2::ImageRestorer emptyDialogRestorer( display, windowRoi.x, windowRoi.y, windowRoi.width, windowRoi.height ); @@ -163,13 +177,16 @@ namespace const fheroes2::Rect windowModeRoi( modeRoi + windowRoi.getPosition() ); const fheroes2::Rect windowVSyncRoi( vSyncRoi + windowRoi.getPosition() ); const fheroes2::Rect windowSystemInfoRoi( systemInfoRoi + windowRoi.getPosition() ); - const fheroes2::Rect windowMonitorList( monitorList + windowRoi.getPosition() ); - const auto drawOptions = [&windowResolutionRoi, &windowModeRoi, &windowVSyncRoi, &windowSystemInfoRoi, &windowMonitorList]() { + const fheroes2::Rect windowMonitorListRoi( monitorListRoi + windowRoi.getPosition() ); + const fheroes2::Rect windowInterfaceTypeRoi( interfaceTypeRoi + windowRoi.getPosition() ); + + const auto drawOptions = [&windowResolutionRoi, &windowModeRoi, &windowVSyncRoi, &windowSystemInfoRoi, &windowMonitorListRoi, &windowInterfaceTypeRoi]() { drawResolution( windowResolutionRoi ); drawMode( windowModeRoi ); drawVSync( windowVSyncRoi ); drawSystemInfo( windowSystemInfoRoi ); - drawMonitor( windowMonitorList ); + drawMonitor( windowMonitorListRoi ); + drawInterfaceType( windowInterfaceTypeRoi ); }; drawOptions(); @@ -206,10 +223,12 @@ namespace if ( le.MouseClickLeft( windowSystemInfoRoi ) ) { return SelectedWindow::SystemInfo; } - if ( le.MouseClickLeft( windowMonitorList ) ) { + if ( le.MouseClickLeft( windowMonitorListRoi ) ) { return SelectedWindow::MonitorList; } - + if ( le.MouseClickLeft( windowInterfaceTypeRoi ) ) { + return SelectedWindow::InterfaceType; + } if ( le.MousePressRight( windowResolutionRoi ) ) { fheroes2::showStandardTextMessage( _( "Select Game Resolution" ), _( "Change the resolution of the game." ), 0 ); } @@ -219,12 +238,15 @@ namespace else if ( le.MousePressRight( windowVSyncRoi ) ) { fheroes2::showStandardTextMessage( _( "V-Sync" ), _( "The V-Sync option can be enabled to resolve flickering issues on some monitors." ), 0 ); } - else if ( le.MousePressRight( windowMonitorList ) ) { + else if ( le.MousePressRight( windowMonitorListRoi ) ) { fheroes2::showStandardTextMessage( _( "Monitor Selection" ), _( "Toggle Between available monitors, Restart Required to take Effect" ), 0 ); } - if ( le.MousePressRight( windowSystemInfoRoi ) ) { + else if ( le.MousePressRight( windowSystemInfoRoi ) ) { fheroes2::showStandardTextMessage( _( "System Info" ), _( "Show extra information such as FPS and current time." ), 0 ); } + else if ( le.MousePressRight( windowInterfaceTypeRoi ) ) { + fheroes2::showStandardTextMessage( _( "Interface Type" ), _( "Toggle Between Evil and Good Interface." ), 0 ); + } else if ( le.MousePressRight( okayButton.area() ) ) { fheroes2::showStandardTextMessage( _( "Okay" ), _( "Exit this menu." ), 0 ); } @@ -279,7 +301,13 @@ namespace fheroes2 windowType = SelectedWindow::Configuration; break; case SelectedWindow::MonitorList: - conf.setDisplayMonitor( ( conf.DisplayMonitor() + 1 ) % SDL_GetNumVideoDisplays() ); + conf.setDisplayMonitor( ( conf.DisplayMonitor() + 1 ) % fheroes2::getNumberOfVideoDisplays() ); + conf.Save( Settings::configFileName ); + windowType = SelectedWindow::Configuration; + break; + case SelectedWindow::InterfaceType: + conf.setEvilInterface( !conf.isEvilInterfaceEnabled() ); + updateUI(); conf.Save( Settings::configFileName ); windowType = SelectedWindow::Configuration; break; From d1b65a240d9034c25128042082e815a0cdaf6187 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Fri, 1 Dec 2023 23:57:21 +0330 Subject: [PATCH 19/55] rename _displayMonitor property to _displayId with it's getter and setter methods --- src/engine/screen.cpp | 4 ++-- src/engine/screen.h | 20 +++++++++---------- .../dialog/dialog_graphics_settings.cpp | 4 ++-- src/fheroes2/game/fheroes2.cpp | 4 ++-- src/fheroes2/system/settings.cpp | 10 +++++----- src/fheroes2/system/settings.h | 8 ++++---- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/engine/screen.cpp b/src/engine/screen.cpp index b521b4aa917..f2ef2511446 100644 --- a/src/engine/screen.cpp +++ b/src/engine/screen.cpp @@ -1072,7 +1072,7 @@ namespace flags |= SDL_WINDOW_RESIZABLE; SDL_Rect monRect; - SDL_GetDisplayBounds( DisplayMonitor(), &monRect ); + SDL_GetDisplayBounds( getDisplayId(), &monRect ); _window = SDL_CreateWindow( _previousWindowTitle.data(), monRect.x + _prevWindowPos.x, monRect.y + _prevWindowPos.y, resolutionInfo.screenWidth, resolutionInfo.screenHeight, flags ); if ( _window == nullptr ) { @@ -1338,7 +1338,7 @@ namespace fheroes2 && info.screenHeight == _screenSize.height ) // nothing to resize return; - _engine->setDisplayMonitor( _displayMonitor ); + _engine->setDisplayId( _displayId ); const bool isFullScreen = _engine->isFullScreen(); // deallocate engine resources diff --git a/src/engine/screen.h b/src/engine/screen.h index d590e952b58..4e58652b7cc 100644 --- a/src/engine/screen.h +++ b/src/engine/screen.h @@ -142,14 +142,14 @@ namespace fheroes2 return _nearestScaling; } - int DisplayMonitor() const + int getDisplayId() const { - return _displayMonitor; + return _displayId; } - void setDisplayMonitor( const int monitor ) + void setDisplayId( const int monitor ) { - _displayMonitor = monitor; + _displayId = monitor; } protected: @@ -192,7 +192,7 @@ namespace fheroes2 private: bool _isFullScreen; - int _displayMonitor{ 0 }; + int _displayId{ 0 }; bool _nearestScaling; }; @@ -226,14 +226,14 @@ namespace fheroes2 // Do not call this method. It serves as a patch over the basic class. void resize( int32_t width_, int32_t height_ ) override; - void setDisplayMonitor( int monitor ) + void setDisplayId( int monitor ) { - _displayMonitor = monitor; + _displayId = monitor; } - int DisplayMonitor() const + int getDisplayId() const { - return _displayMonitor; + return _displayId; } void setResolution( ResolutionInfo info ); @@ -278,7 +278,7 @@ namespace fheroes2 PostRenderProcessing _postprocessing; uint8_t * _renderSurface; - int _displayMonitor; + int _displayId; // Previous area drawn on the screen. Rect _prevRoi; diff --git a/src/fheroes2/dialog/dialog_graphics_settings.cpp b/src/fheroes2/dialog/dialog_graphics_settings.cpp index 50a48e11c6d..056b9cc5be6 100644 --- a/src/fheroes2/dialog/dialog_graphics_settings.cpp +++ b/src/fheroes2/dialog/dialog_graphics_settings.cpp @@ -69,7 +69,7 @@ namespace void drawMonitor( const fheroes2::Rect & optionRoi ) { const Settings & conf = Settings::Get(); - fheroes2::drawOption( optionRoi, fheroes2::AGG::GetICN( ICN::GAME_OPTION_ICON, 1 ), "Display Monitor", fheroes2::getDisplayName( conf.DisplayMonitor() ), + fheroes2::drawOption( optionRoi, fheroes2::AGG::GetICN( ICN::GAME_OPTION_ICON, 1 ), "Display Monitor", fheroes2::getDisplayName( conf.getDisplayId() ), fheroes2::UiOptionTextWidth::TWO_ELEMENTS_ROW ); } @@ -301,7 +301,7 @@ namespace fheroes2 windowType = SelectedWindow::Configuration; break; case SelectedWindow::MonitorList: - conf.setDisplayMonitor( ( conf.DisplayMonitor() + 1 ) % fheroes2::getNumberOfVideoDisplays() ); + conf.setDisplayId( ( conf.getDisplayId() + 1 ) % fheroes2::getNumberOfVideoDisplays() ); conf.Save( Settings::configFileName ); windowType = SelectedWindow::Configuration; break; diff --git a/src/fheroes2/game/fheroes2.cpp b/src/fheroes2/game/fheroes2.cpp index b9575f9b0fc..0ff5f9923db 100644 --- a/src/fheroes2/game/fheroes2.cpp +++ b/src/fheroes2/game/fheroes2.cpp @@ -167,11 +167,11 @@ namespace } } // set display monitor to first monitor available - display.setDisplayMonitor( 0 ); + display.setDisplayId( 0 ); display.setResolution( bestResolution ); } else { - display.setDisplayMonitor( conf.DisplayMonitor() ); + display.setDisplayId( conf.getDisplayId() ); display.setResolution( conf.currentResolutionInfo() ); } diff --git a/src/fheroes2/system/settings.cpp b/src/fheroes2/system/settings.cpp index c76407ce873..2a8aa485074 100644 --- a/src/fheroes2/system/settings.cpp +++ b/src/fheroes2/system/settings.cpp @@ -91,7 +91,7 @@ std::string Settings::GetVersion() Settings::Settings() : _resolutionInfo( fheroes2::Display::DEFAULT_WIDTH, fheroes2::Display::DEFAULT_HEIGHT ) - , _displayMonitor( 0 ) + , _displayId( 0 ) , game_difficulty( Difficulty::NORMAL ) , sound_volume( 6 ) , music_volume( 6 ) @@ -328,7 +328,7 @@ bool Settings::Read( const std::string & filePath ) } if ( config.Exists( "monitor" ) ) { - setDisplayMonitor( std::max( config.IntParams( "monitor" ), 0 ) ); + setDisplayId( std::max( config.IntParams( "monitor" ), 0 ) ); } return true; @@ -483,7 +483,7 @@ std::string Settings::String() const } os << std::endl << "# Display Monitor for Multi-Monitor Setups (defaults to first monitor)" << std::endl; - os << "monitor = " << DisplayMonitor() << std::endl; + os << "monitor = " << getDisplayId() << std::endl; return os.str(); } @@ -963,9 +963,9 @@ void Settings::setDebug( int debug ) Logging::setDebugLevel( debug ); } -void Settings::setDisplayMonitor( int monitor ) +void Settings::setDisplayId( int monitor ) { - _displayMonitor = monitor; + _displayId = monitor; } void Settings::SetSoundVolume( int v ) diff --git a/src/fheroes2/system/settings.h b/src/fheroes2/system/settings.h index c50158c1c5c..3ccd5d418e7 100644 --- a/src/fheroes2/system/settings.h +++ b/src/fheroes2/system/settings.h @@ -249,7 +249,7 @@ class Settings void setHideInterface( const bool enable ); void setEvilInterface( const bool enable ); void setScreenScalingTypeNearest( const bool enable ); - void setDisplayMonitor( int monitor ); + void setDisplayId( int monitor ); void SetSoundVolume( int v ); void SetMusicVolume( int v ); @@ -260,9 +260,9 @@ class Settings bool setGameLanguage( const std::string & language ); - int DisplayMonitor() const + int getDisplayId() const { - return _displayMonitor; + return _displayId; } int SoundVolume() const @@ -448,7 +448,7 @@ class Settings BitModes _optGlobal; fheroes2::ResolutionInfo _resolutionInfo; - int _displayMonitor; + int _displayId; int game_difficulty; From 5566d2d0e140a7728c21937bc68e33b7776ebc42 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Fri, 1 Dec 2023 23:59:12 +0330 Subject: [PATCH 20/55] remove inplace initilization --- src/engine/screen.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/screen.h b/src/engine/screen.h index 4e58652b7cc..b18daf8e2f8 100644 --- a/src/engine/screen.h +++ b/src/engine/screen.h @@ -192,7 +192,7 @@ namespace fheroes2 private: bool _isFullScreen; - int _displayId{ 0 }; + int _displayId; bool _nearestScaling; }; From 1fc9224842c6479b194c5a8555c380a891b5a2c8 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Sat, 2 Dec 2023 00:01:47 +0330 Subject: [PATCH 21/55] fix to style --- src/engine/screen.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/engine/screen.cpp b/src/engine/screen.cpp index f2ef2511446..aa8dcbd75bd 100644 --- a/src/engine/screen.cpp +++ b/src/engine/screen.cpp @@ -1485,5 +1485,4 @@ namespace fheroes2 { return SDL_GetDisplayName( display ); } - } From a193e3e51d9ec4015d9d812777f5d6c150047b85 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Thu, 7 Dec 2023 23:16:49 +0330 Subject: [PATCH 22/55] Limiting Screen Switch Ability to windows only --- src/engine/screen.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/engine/screen.cpp b/src/engine/screen.cpp index aa8dcbd75bd..ce745d1394f 100644 --- a/src/engine/screen.cpp +++ b/src/engine/screen.cpp @@ -1071,10 +1071,15 @@ namespace } flags |= SDL_WINDOW_RESIZABLE; + +#if defined( _WIN32 ) SDL_Rect monRect; SDL_GetDisplayBounds( getDisplayId(), &monRect ); _window = SDL_CreateWindow( _previousWindowTitle.data(), monRect.x + _prevWindowPos.x, monRect.y + _prevWindowPos.y, resolutionInfo.screenWidth, resolutionInfo.screenHeight, flags ); +#else + _window = SDL_CreateWindow( _previousWindowTitle.data(), monRect.x, monRect.y, resolutionInfo.screenWidth, resolutionInfo.screenHeight, flags ); +#endif if ( _window == nullptr ) { ERROR_LOG( "Failed to create an application window of " << resolutionInfo.screenWidth << " x " << resolutionInfo.screenHeight << " size. The error: " << SDL_GetError() ) From 8989928a14db154bba65e8ce0867e12d7b004eb0 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Thu, 7 Dec 2023 23:26:03 +0330 Subject: [PATCH 23/55] Changing Mistaken Variable --- src/engine/screen.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/screen.cpp b/src/engine/screen.cpp index ce745d1394f..d9039b2a434 100644 --- a/src/engine/screen.cpp +++ b/src/engine/screen.cpp @@ -1078,7 +1078,7 @@ namespace _window = SDL_CreateWindow( _previousWindowTitle.data(), monRect.x + _prevWindowPos.x, monRect.y + _prevWindowPos.y, resolutionInfo.screenWidth, resolutionInfo.screenHeight, flags ); #else - _window = SDL_CreateWindow( _previousWindowTitle.data(), monRect.x, monRect.y, resolutionInfo.screenWidth, resolutionInfo.screenHeight, flags ); + _window = SDL_CreateWindow( _previousWindowTitle.data(), _prevWindowPos.x, _prevWindowPos.y, resolutionInfo.screenWidth, resolutionInfo.screenHeight, flags ); #endif if ( _window == nullptr ) { ERROR_LOG( "Failed to create an application window of " << resolutionInfo.screenWidth << " x " << resolutionInfo.screenHeight From 714d86757ea9dd0e3c4c2ae04e46706e5fa16354 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Mon, 11 Dec 2023 02:59:35 +0330 Subject: [PATCH 24/55] Addressing Reviews - Removing _displayId variable and it's methods from Display and Settings Class - Renaming Monitor variable names to Display - Adding Safeguard to fallback to first display in absence of selected display --- src/engine/screen.cpp | 7 +++--- src/engine/screen.h | 21 ++++++---------- .../dialog/dialog_graphics_settings.cpp | 25 +++++++++---------- src/fheroes2/game/fheroes2.cpp | 2 -- src/fheroes2/system/settings.cpp | 16 ++++-------- src/fheroes2/system/settings.h | 7 ------ 6 files changed, 28 insertions(+), 50 deletions(-) diff --git a/src/engine/screen.cpp b/src/engine/screen.cpp index d9039b2a434..a187813ebff 100644 --- a/src/engine/screen.cpp +++ b/src/engine/screen.cpp @@ -1073,9 +1073,9 @@ namespace flags |= SDL_WINDOW_RESIZABLE; #if defined( _WIN32 ) - SDL_Rect monRect; - SDL_GetDisplayBounds( getDisplayId(), &monRect ); - _window = SDL_CreateWindow( _previousWindowTitle.data(), monRect.x + _prevWindowPos.x, monRect.y + _prevWindowPos.y, resolutionInfo.screenWidth, + SDL_Rect displayRect; + SDL_GetDisplayBounds( getDisplayId(), &displayRect ); + _window = SDL_CreateWindow( _previousWindowTitle.data(), displayRect.x + _prevWindowPos.x, displayRect.y + _prevWindowPos.y, resolutionInfo.screenWidth, resolutionInfo.screenHeight, flags ); #else _window = SDL_CreateWindow( _previousWindowTitle.data(), _prevWindowPos.x, _prevWindowPos.y, resolutionInfo.screenWidth, resolutionInfo.screenHeight, flags ); @@ -1343,7 +1343,6 @@ namespace fheroes2 && info.screenHeight == _screenSize.height ) // nothing to resize return; - _engine->setDisplayId( _displayId ); const bool isFullScreen = _engine->isFullScreen(); // deallocate engine resources diff --git a/src/engine/screen.h b/src/engine/screen.h index b18daf8e2f8..58a47346c34 100644 --- a/src/engine/screen.h +++ b/src/engine/screen.h @@ -147,14 +147,20 @@ namespace fheroes2 return _displayId; } - void setDisplayId( const int monitor ) + void setDisplayId( const int display ) { - _displayId = monitor; + if ( display > getNumberOfVideoDisplays() ) + // add safeguard for when 2nd display disconnects + _displayId = 0; + else { + _displayId = display; + } } protected: BaseRenderEngine() : _isFullScreen( false ) + , _displayId( 0 ) , _nearestScaling( false ) { @@ -226,16 +232,6 @@ namespace fheroes2 // Do not call this method. It serves as a patch over the basic class. void resize( int32_t width_, int32_t height_ ) override; - void setDisplayId( int monitor ) - { - _displayId = monitor; - } - - int getDisplayId() const - { - return _displayId; - } - void setResolution( ResolutionInfo info ); bool isDefaultSize() const @@ -278,7 +274,6 @@ namespace fheroes2 PostRenderProcessing _postprocessing; uint8_t * _renderSurface; - int _displayId; // Previous area drawn on the screen. Rect _prevRoi; diff --git a/src/fheroes2/dialog/dialog_graphics_settings.cpp b/src/fheroes2/dialog/dialog_graphics_settings.cpp index 056b9cc5be6..5324c823747 100644 --- a/src/fheroes2/dialog/dialog_graphics_settings.cpp +++ b/src/fheroes2/dialog/dialog_graphics_settings.cpp @@ -49,7 +49,7 @@ namespace Mode, VSync, SystemInfo, - MonitorList, + DisplayList, InterfaceType, Exit }; @@ -66,11 +66,10 @@ namespace const fheroes2::Rect interfaceTypeRoi{ optionOffset.x + offsetBetweenOptions.width * 2, optionOffset.y + offsetBetweenOptions.height, optionWindowSize, optionWindowSize }; - void drawMonitor( const fheroes2::Rect & optionRoi ) + void drawDisplay( const fheroes2::Rect & optionRoi ) { - const Settings & conf = Settings::Get(); - fheroes2::drawOption( optionRoi, fheroes2::AGG::GetICN( ICN::GAME_OPTION_ICON, 1 ), "Display Monitor", fheroes2::getDisplayName( conf.getDisplayId() ), - fheroes2::UiOptionTextWidth::TWO_ELEMENTS_ROW ); + fheroes2::drawOption( optionRoi, fheroes2::AGG::GetICN( ICN::GAME_OPTION_ICON, 1 ), _( "Display ID" ), + fheroes2::getDisplayName( fheroes2::engine().getDisplayId() ), fheroes2::UiOptionTextWidth::TWO_ELEMENTS_ROW ); } void drawResolution( const fheroes2::Rect & optionRoi ) @@ -177,15 +176,15 @@ namespace const fheroes2::Rect windowModeRoi( modeRoi + windowRoi.getPosition() ); const fheroes2::Rect windowVSyncRoi( vSyncRoi + windowRoi.getPosition() ); const fheroes2::Rect windowSystemInfoRoi( systemInfoRoi + windowRoi.getPosition() ); - const fheroes2::Rect windowMonitorListRoi( monitorListRoi + windowRoi.getPosition() ); + const fheroes2::Rect windowDisplayListRoi( monitorListRoi + windowRoi.getPosition() ); const fheroes2::Rect windowInterfaceTypeRoi( interfaceTypeRoi + windowRoi.getPosition() ); - const auto drawOptions = [&windowResolutionRoi, &windowModeRoi, &windowVSyncRoi, &windowSystemInfoRoi, &windowMonitorListRoi, &windowInterfaceTypeRoi]() { + const auto drawOptions = [&windowResolutionRoi, &windowModeRoi, &windowVSyncRoi, &windowSystemInfoRoi, &windowDisplayListRoi, &windowInterfaceTypeRoi]() { drawResolution( windowResolutionRoi ); drawMode( windowModeRoi ); drawVSync( windowVSyncRoi ); drawSystemInfo( windowSystemInfoRoi ); - drawMonitor( windowMonitorListRoi ); + drawDisplay( windowDisplayListRoi ); drawInterfaceType( windowInterfaceTypeRoi ); }; @@ -223,8 +222,8 @@ namespace if ( le.MouseClickLeft( windowSystemInfoRoi ) ) { return SelectedWindow::SystemInfo; } - if ( le.MouseClickLeft( windowMonitorListRoi ) ) { - return SelectedWindow::MonitorList; + if ( le.MouseClickLeft( windowDisplayListRoi ) ) { + return SelectedWindow::DisplayList; } if ( le.MouseClickLeft( windowInterfaceTypeRoi ) ) { return SelectedWindow::InterfaceType; @@ -238,7 +237,7 @@ namespace else if ( le.MousePressRight( windowVSyncRoi ) ) { fheroes2::showStandardTextMessage( _( "V-Sync" ), _( "The V-Sync option can be enabled to resolve flickering issues on some monitors." ), 0 ); } - else if ( le.MousePressRight( windowMonitorListRoi ) ) { + else if ( le.MousePressRight( windowDisplayListRoi ) ) { fheroes2::showStandardTextMessage( _( "Monitor Selection" ), _( "Toggle Between available monitors, Restart Required to take Effect" ), 0 ); } else if ( le.MousePressRight( windowSystemInfoRoi ) ) { @@ -300,8 +299,8 @@ namespace fheroes2 conf.Save( Settings::configFileName ); windowType = SelectedWindow::Configuration; break; - case SelectedWindow::MonitorList: - conf.setDisplayId( ( conf.getDisplayId() + 1 ) % fheroes2::getNumberOfVideoDisplays() ); + case SelectedWindow::DisplayList: + fheroes2::engine().setDisplayId( ( fheroes2::engine().getDisplayId() + 1 ) % fheroes2::getNumberOfVideoDisplays() ); conf.Save( Settings::configFileName ); windowType = SelectedWindow::Configuration; break; diff --git a/src/fheroes2/game/fheroes2.cpp b/src/fheroes2/game/fheroes2.cpp index 0ff5f9923db..3957c87fe7b 100644 --- a/src/fheroes2/game/fheroes2.cpp +++ b/src/fheroes2/game/fheroes2.cpp @@ -167,11 +167,9 @@ namespace } } // set display monitor to first monitor available - display.setDisplayId( 0 ); display.setResolution( bestResolution ); } else { - display.setDisplayId( conf.getDisplayId() ); display.setResolution( conf.currentResolutionInfo() ); } diff --git a/src/fheroes2/system/settings.cpp b/src/fheroes2/system/settings.cpp index 2a8aa485074..0a437115247 100644 --- a/src/fheroes2/system/settings.cpp +++ b/src/fheroes2/system/settings.cpp @@ -91,7 +91,6 @@ std::string Settings::GetVersion() Settings::Settings() : _resolutionInfo( fheroes2::Display::DEFAULT_WIDTH, fheroes2::Display::DEFAULT_HEIGHT ) - , _displayId( 0 ) , game_difficulty( Difficulty::NORMAL ) , sound_volume( 6 ) , music_volume( 6 ) @@ -327,8 +326,8 @@ bool Settings::Read( const std::string & filePath ) _optGlobal.SetModes( GLOBAL_ENABLE_EDITOR ); } - if ( config.Exists( "monitor" ) ) { - setDisplayId( std::max( config.IntParams( "monitor" ), 0 ) ); + if ( config.Exists( "display" ) ) { + fheroes2::engine().setDisplayId( std::max( config.IntParams( "display" ), 0 ) ); } return true; @@ -376,6 +375,9 @@ std::string Settings::String() const os << std::endl << "# video mode: in-game width x in-game height : on-screen width x on-screen height" << std::endl; os << "videomode = " << display.width() << "x" << display.height() << ":" << display.screenSize().width << "x" << display.screenSize().height << std::endl; + os << std::endl << "# Display ID (defaults to First Display)" << std::endl; + os << "display = " << fheroes2::engine().getDisplayId() << std::endl; + os << std::endl << "# music: original, expansion, external" << std::endl; os << "music = " << musicType << std::endl; @@ -482,9 +484,6 @@ std::string Settings::String() const os << "editor = beta" << std::endl; } - os << std::endl << "# Display Monitor for Multi-Monitor Setups (defaults to first monitor)" << std::endl; - os << "monitor = " << getDisplayId() << std::endl; - return os.str(); } @@ -963,11 +962,6 @@ void Settings::setDebug( int debug ) Logging::setDebugLevel( debug ); } -void Settings::setDisplayId( int monitor ) -{ - _displayId = monitor; -} - void Settings::SetSoundVolume( int v ) { sound_volume = std::clamp( v, 0, 10 ); diff --git a/src/fheroes2/system/settings.h b/src/fheroes2/system/settings.h index 3ccd5d418e7..7eb0f87f2af 100644 --- a/src/fheroes2/system/settings.h +++ b/src/fheroes2/system/settings.h @@ -249,7 +249,6 @@ class Settings void setHideInterface( const bool enable ); void setEvilInterface( const bool enable ); void setScreenScalingTypeNearest( const bool enable ); - void setDisplayId( int monitor ); void SetSoundVolume( int v ); void SetMusicVolume( int v ); @@ -260,11 +259,6 @@ class Settings bool setGameLanguage( const std::string & language ); - int getDisplayId() const - { - return _displayId; - } - int SoundVolume() const { return sound_volume; @@ -448,7 +442,6 @@ class Settings BitModes _optGlobal; fheroes2::ResolutionInfo _resolutionInfo; - int _displayId; int game_difficulty; From d805b6ddec6ef8c12c22b03a00332520086b46a8 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Mon, 11 Dec 2023 03:02:04 +0330 Subject: [PATCH 25/55] styling fix --- src/engine/screen.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/screen.h b/src/engine/screen.h index 58a47346c34..392c54611f2 100644 --- a/src/engine/screen.h +++ b/src/engine/screen.h @@ -150,7 +150,7 @@ namespace fheroes2 void setDisplayId( const int display ) { if ( display > getNumberOfVideoDisplays() ) - // add safeguard for when 2nd display disconnects + // add safeguard for when 2nd display disconnects _displayId = 0; else { _displayId = display; From adf13d6547e40003786260fdf365f3c8bd8251d0 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Mon, 11 Dec 2023 04:22:17 +0330 Subject: [PATCH 26/55] Fix Safeguard --- src/engine/screen.cpp | 16 +++++++++++----- src/engine/screen.h | 7 +------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/engine/screen.cpp b/src/engine/screen.cpp index a187813ebff..aebfc96ef39 100644 --- a/src/engine/screen.cpp +++ b/src/engine/screen.cpp @@ -46,6 +46,7 @@ #include "image_palette.h" #include "logging.h" #include "screen.h" +#include "settings.h" #include "tools.h" namespace @@ -1055,8 +1056,14 @@ namespace ERROR_LOG( "Failed to set a hint for screen orientation." ) } #endif - uint32_t flags = SDL_WINDOW_SHOWN; + + // SDL number starts from 1 so we add 1 to our variable + if ( getDisplayId() + 1 > SDL_GetNumVideoDisplays() ) { + setDisplayId( 0 ); + Settings::Get().Save( Settings::configFileName ); + } + if ( isFullScreen ) { #if defined( _WIN32 ) if ( fheroes2::cursor().isSoftwareEmulation() ) { @@ -1073,10 +1080,9 @@ namespace flags |= SDL_WINDOW_RESIZABLE; #if defined( _WIN32 ) - SDL_Rect displayRect; - SDL_GetDisplayBounds( getDisplayId(), &displayRect ); - _window = SDL_CreateWindow( _previousWindowTitle.data(), displayRect.x + _prevWindowPos.x, displayRect.y + _prevWindowPos.y, resolutionInfo.screenWidth, - resolutionInfo.screenHeight, flags ); + + _window = SDL_CreateWindow( _previousWindowTitle.data(), SDL_WINDOWPOS_CENTERED_DISPLAY( getDisplayId() ), SDL_WINDOWPOS_CENTERED_DISPLAY( getDisplayId() ), + resolutionInfo.screenWidth, resolutionInfo.screenHeight, flags ); #else _window = SDL_CreateWindow( _previousWindowTitle.data(), _prevWindowPos.x, _prevWindowPos.y, resolutionInfo.screenWidth, resolutionInfo.screenHeight, flags ); #endif diff --git a/src/engine/screen.h b/src/engine/screen.h index 392c54611f2..466aaf14756 100644 --- a/src/engine/screen.h +++ b/src/engine/screen.h @@ -149,12 +149,7 @@ namespace fheroes2 void setDisplayId( const int display ) { - if ( display > getNumberOfVideoDisplays() ) - // add safeguard for when 2nd display disconnects - _displayId = 0; - else { - _displayId = display; - } + _displayId = display; } protected: From ff368c5fb713fa879babbd1e6f01c23dbcbae9b9 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Mon, 11 Dec 2023 04:23:48 +0330 Subject: [PATCH 27/55] Style Fix --- src/engine/screen.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/engine/screen.cpp b/src/engine/screen.cpp index aebfc96ef39..11e1c40aa0f 100644 --- a/src/engine/screen.cpp +++ b/src/engine/screen.cpp @@ -1057,8 +1057,8 @@ namespace } #endif uint32_t flags = SDL_WINDOW_SHOWN; - - // SDL number starts from 1 so we add 1 to our variable + + // SDL_GetNumVideoDisplays starts from 1 so we add 1 to our variable if ( getDisplayId() + 1 > SDL_GetNumVideoDisplays() ) { setDisplayId( 0 ); Settings::Get().Save( Settings::configFileName ); From 52f7a53885f35537250db9374061a65969d7d0b9 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Mon, 11 Dec 2023 04:30:38 +0330 Subject: [PATCH 28/55] Remove settings.h --- src/engine/screen.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/engine/screen.cpp b/src/engine/screen.cpp index 11e1c40aa0f..7de863a1471 100644 --- a/src/engine/screen.cpp +++ b/src/engine/screen.cpp @@ -46,7 +46,6 @@ #include "image_palette.h" #include "logging.h" #include "screen.h" -#include "settings.h" #include "tools.h" namespace @@ -1061,7 +1060,6 @@ namespace // SDL_GetNumVideoDisplays starts from 1 so we add 1 to our variable if ( getDisplayId() + 1 > SDL_GetNumVideoDisplays() ) { setDisplayId( 0 ); - Settings::Get().Save( Settings::configFileName ); } if ( isFullScreen ) { From 4444c85c3511aaa0ea8ce0e6698eabc894e6197d Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Tue, 12 Dec 2023 18:07:54 +0330 Subject: [PATCH 29/55] Addressing Reviews --- src/engine/screen.cpp | 16 +++++++++--- src/engine/screen.h | 12 ++++----- .../dialog/dialog_graphics_settings.cpp | 25 ++++++++++--------- src/fheroes2/game/fheroes2.cpp | 1 - src/fheroes2/system/settings.h | 1 - 5 files changed, 31 insertions(+), 24 deletions(-) diff --git a/src/engine/screen.cpp b/src/engine/screen.cpp index 7de863a1471..d29fa44cd0e 100644 --- a/src/engine/screen.cpp +++ b/src/engine/screen.cpp @@ -1055,10 +1055,11 @@ namespace ERROR_LOG( "Failed to set a hint for screen orientation." ) } #endif + uint32_t flags = SDL_WINDOW_SHOWN; // SDL_GetNumVideoDisplays starts from 1 so we add 1 to our variable - if ( getDisplayId() + 1 > SDL_GetNumVideoDisplays() ) { + if ( getDisplayId() + 1 > getNumberOfVideoDisplays() ) { setDisplayId( 0 ); } @@ -1484,12 +1485,19 @@ namespace fheroes2 return *( Display::instance()._cursor ); } - int getNumberOfVideoDisplays() + int BaseRenderEngine::getNumberOfVideoDisplays() { - return SDL_GetNumVideoDisplays(); + if ( int displayCount = SDL_GetNumVideoDisplays(); displayCount > 0 ) { + return displayCount; + } + else { + ERROR_LOG( "Failed to Get Number of Displays:" << displayCount << ", description: " << SDL_GetError() ); + // there should be one display at least + return 1; + } } - const char * getDisplayName( const int display ) + const char * BaseRenderEngine::getDisplayName( const int display ) { return SDL_GetDisplayName( display ); } diff --git a/src/engine/screen.h b/src/engine/screen.h index 466aaf14756..c74b5fa6dbb 100644 --- a/src/engine/screen.h +++ b/src/engine/screen.h @@ -35,9 +35,6 @@ namespace fheroes2 class Cursor; class Display; - int getNumberOfVideoDisplays(); - const char * getDisplayName( const int display ); - struct ResolutionInfo { ResolutionInfo() = default; @@ -152,11 +149,14 @@ namespace fheroes2 _displayId = display; } + int getNumberOfVideoDisplays(); + const char * getDisplayName( const int display ); + protected: BaseRenderEngine() : _isFullScreen( false ) - , _displayId( 0 ) , _nearestScaling( false ) + , _displayId( 0 ) { // Do nothing. @@ -193,9 +193,9 @@ namespace fheroes2 private: bool _isFullScreen; - int _displayId; - bool _nearestScaling; + + int _displayId; }; class Display : public Image diff --git a/src/fheroes2/dialog/dialog_graphics_settings.cpp b/src/fheroes2/dialog/dialog_graphics_settings.cpp index 5324c823747..64161c8c84c 100644 --- a/src/fheroes2/dialog/dialog_graphics_settings.cpp +++ b/src/fheroes2/dialog/dialog_graphics_settings.cpp @@ -49,7 +49,7 @@ namespace Mode, VSync, SystemInfo, - DisplayList, + SwitchDisplay, InterfaceType, Exit }; @@ -62,14 +62,14 @@ namespace const fheroes2::Rect modeRoi{ optionOffset.x + offsetBetweenOptions.width, optionOffset.y, optionWindowSize, optionWindowSize }; const fheroes2::Rect vSyncRoi{ optionOffset.x, optionOffset.y + offsetBetweenOptions.height, optionWindowSize, optionWindowSize }; const fheroes2::Rect systemInfoRoi{ optionOffset.x + offsetBetweenOptions.width, optionOffset.y + offsetBetweenOptions.height, optionWindowSize, optionWindowSize }; - const fheroes2::Rect monitorListRoi{ optionOffset.x + offsetBetweenOptions.width * 2, optionOffset.y, optionWindowSize, optionWindowSize }; + const fheroes2::Rect switchDisplayRoi{ optionOffset.x + offsetBetweenOptions.width * 2, optionOffset.y, optionWindowSize, optionWindowSize }; const fheroes2::Rect interfaceTypeRoi{ optionOffset.x + offsetBetweenOptions.width * 2, optionOffset.y + offsetBetweenOptions.height, optionWindowSize, optionWindowSize }; void drawDisplay( const fheroes2::Rect & optionRoi ) { fheroes2::drawOption( optionRoi, fheroes2::AGG::GetICN( ICN::GAME_OPTION_ICON, 1 ), _( "Display ID" ), - fheroes2::getDisplayName( fheroes2::engine().getDisplayId() ), fheroes2::UiOptionTextWidth::TWO_ELEMENTS_ROW ); + fheroes2::engine().getDisplayName( fheroes2::engine().getDisplayId() ), fheroes2::UiOptionTextWidth::TWO_ELEMENTS_ROW ); } void drawResolution( const fheroes2::Rect & optionRoi ) @@ -176,15 +176,15 @@ namespace const fheroes2::Rect windowModeRoi( modeRoi + windowRoi.getPosition() ); const fheroes2::Rect windowVSyncRoi( vSyncRoi + windowRoi.getPosition() ); const fheroes2::Rect windowSystemInfoRoi( systemInfoRoi + windowRoi.getPosition() ); - const fheroes2::Rect windowDisplayListRoi( monitorListRoi + windowRoi.getPosition() ); + const fheroes2::Rect windowSwitchDisplayRoi( switchDisplayRoi + windowRoi.getPosition() ); const fheroes2::Rect windowInterfaceTypeRoi( interfaceTypeRoi + windowRoi.getPosition() ); - const auto drawOptions = [&windowResolutionRoi, &windowModeRoi, &windowVSyncRoi, &windowSystemInfoRoi, &windowDisplayListRoi, &windowInterfaceTypeRoi]() { + const auto drawOptions = [&windowResolutionRoi, &windowModeRoi, &windowVSyncRoi, &windowSystemInfoRoi, &windowSwitchDisplayRoi, &windowInterfaceTypeRoi]() { drawResolution( windowResolutionRoi ); drawMode( windowModeRoi ); drawVSync( windowVSyncRoi ); drawSystemInfo( windowSystemInfoRoi ); - drawDisplay( windowDisplayListRoi ); + drawDisplay( windowSwitchDisplayRoi ); drawInterfaceType( windowInterfaceTypeRoi ); }; @@ -222,8 +222,8 @@ namespace if ( le.MouseClickLeft( windowSystemInfoRoi ) ) { return SelectedWindow::SystemInfo; } - if ( le.MouseClickLeft( windowDisplayListRoi ) ) { - return SelectedWindow::DisplayList; + if ( le.MouseClickLeft( windowSwitchDisplayRoi ) ) { + return SelectedWindow::SwitchDisplay; } if ( le.MouseClickLeft( windowInterfaceTypeRoi ) ) { return SelectedWindow::InterfaceType; @@ -237,8 +237,8 @@ namespace else if ( le.MousePressRight( windowVSyncRoi ) ) { fheroes2::showStandardTextMessage( _( "V-Sync" ), _( "The V-Sync option can be enabled to resolve flickering issues on some monitors." ), 0 ); } - else if ( le.MousePressRight( windowDisplayListRoi ) ) { - fheroes2::showStandardTextMessage( _( "Monitor Selection" ), _( "Toggle Between available monitors, Restart Required to take Effect" ), 0 ); + else if ( le.MousePressRight( windowSwitchDisplayRoi ) ) { + fheroes2::showStandardTextMessage( _( "Display Selection" ), _( "Toggle Between available Displays, Restart Required to take Effect" ), 0 ); } else if ( le.MousePressRight( windowSystemInfoRoi ) ) { fheroes2::showStandardTextMessage( _( "System Info" ), _( "Show extra information such as FPS and current time." ), 0 ); @@ -299,8 +299,9 @@ namespace fheroes2 conf.Save( Settings::configFileName ); windowType = SelectedWindow::Configuration; break; - case SelectedWindow::DisplayList: - fheroes2::engine().setDisplayId( ( fheroes2::engine().getDisplayId() + 1 ) % fheroes2::getNumberOfVideoDisplays() ); + case SelectedWindow::SwitchDisplay: + fheroes2::engine().setDisplayId( ( fheroes2::engine().getDisplayId() + 1 ) % fheroes2::engine().getNumberOfVideoDisplays() ); + updateUI(); conf.Save( Settings::configFileName ); windowType = SelectedWindow::Configuration; break; diff --git a/src/fheroes2/game/fheroes2.cpp b/src/fheroes2/game/fheroes2.cpp index 3957c87fe7b..d2108fb1eff 100644 --- a/src/fheroes2/game/fheroes2.cpp +++ b/src/fheroes2/game/fheroes2.cpp @@ -166,7 +166,6 @@ namespace bestResolution = info; } } - // set display monitor to first monitor available display.setResolution( bestResolution ); } else { diff --git a/src/fheroes2/system/settings.h b/src/fheroes2/system/settings.h index 7eb0f87f2af..1a1ed1ed999 100644 --- a/src/fheroes2/system/settings.h +++ b/src/fheroes2/system/settings.h @@ -442,7 +442,6 @@ class Settings BitModes _optGlobal; fheroes2::ResolutionInfo _resolutionInfo; - int game_difficulty; std::string path_program; From c2f1f5e10fd55067e4f255a52e0d7d174ece9109 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Wed, 13 Dec 2023 22:51:32 +0330 Subject: [PATCH 30/55] - Add function to change display in runtime - Add Number to display text - fix some logic --- src/engine/screen.cpp | 28 +++++++++++++++---- src/engine/screen.h | 2 ++ .../dialog/dialog_graphics_settings.cpp | 10 ++++--- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/engine/screen.cpp b/src/engine/screen.cpp index d29fa44cd0e..04b11724959 100644 --- a/src/engine/screen.cpp +++ b/src/engine/screen.cpp @@ -1367,6 +1367,26 @@ namespace fheroes2 std::fill( transform(), transform() + width() * height(), static_cast( 1 ) ); } + void Display::changeDisplayEngine( int displayId ) + { + _engine->setDisplayId( displayId ); + + const bool isFullScreen = _engine->isFullScreen(); + + Size currentRes = _engine->getCurrentScreenResolution(); + ResolutionInfo resInfo( currentRes.width, currentRes.height ); + + // deallocate engine resources + _engine->clear(); + + _engine->allocate( resInfo, isFullScreen ); + + Image::resize( resInfo.gameWidth, resInfo.gameHeight ); + _screenSize = { resInfo.screenWidth, resInfo.screenHeight }; + + std::fill( transform(), transform() + width() * height(), static_cast( 1 ) ); + } + Display & Display::instance() { static Display display; @@ -1490,11 +1510,9 @@ namespace fheroes2 if ( int displayCount = SDL_GetNumVideoDisplays(); displayCount > 0 ) { return displayCount; } - else { - ERROR_LOG( "Failed to Get Number of Displays:" << displayCount << ", description: " << SDL_GetError() ); - // there should be one display at least - return 1; - } + ERROR_LOG( "Failed to Get Number of Displays, description: " << SDL_GetError() ); + // there should be one display at least + return 1; } const char * BaseRenderEngine::getDisplayName( const int display ) diff --git a/src/engine/screen.h b/src/engine/screen.h index c74b5fa6dbb..0a49a5b8015 100644 --- a/src/engine/screen.h +++ b/src/engine/screen.h @@ -229,6 +229,8 @@ namespace fheroes2 void setResolution( ResolutionInfo info ); + void changeDisplayEngine( int displayId ); + bool isDefaultSize() const { return width() == DEFAULT_WIDTH && height() == DEFAULT_HEIGHT; diff --git a/src/fheroes2/dialog/dialog_graphics_settings.cpp b/src/fheroes2/dialog/dialog_graphics_settings.cpp index 64161c8c84c..26e93e1a62d 100644 --- a/src/fheroes2/dialog/dialog_graphics_settings.cpp +++ b/src/fheroes2/dialog/dialog_graphics_settings.cpp @@ -68,8 +68,9 @@ namespace void drawDisplay( const fheroes2::Rect & optionRoi ) { + int displayId = fheroes2::engine().getDisplayId(); fheroes2::drawOption( optionRoi, fheroes2::AGG::GetICN( ICN::GAME_OPTION_ICON, 1 ), _( "Display ID" ), - fheroes2::engine().getDisplayName( fheroes2::engine().getDisplayId() ), fheroes2::UiOptionTextWidth::TWO_ELEMENTS_ROW ); + std::to_string( displayId + 1 ) + ": " + fheroes2::engine().getDisplayName( displayId ), fheroes2::UiOptionTextWidth::TWO_ELEMENTS_ROW ); } void drawResolution( const fheroes2::Rect & optionRoi ) @@ -270,6 +271,7 @@ namespace fheroes2 void openGraphicsSettingsDialog( const std::function & updateUI ) { Settings & conf = Settings::Get(); + fheroes2::Display & display = fheroes2::Display::instance(); SelectedWindow windowType = SelectedWindow::Configuration; while ( windowType != SelectedWindow::Exit ) { @@ -299,12 +301,12 @@ namespace fheroes2 conf.Save( Settings::configFileName ); windowType = SelectedWindow::Configuration; break; - case SelectedWindow::SwitchDisplay: - fheroes2::engine().setDisplayId( ( fheroes2::engine().getDisplayId() + 1 ) % fheroes2::engine().getNumberOfVideoDisplays() ); - updateUI(); + case SelectedWindow::SwitchDisplay: { + display.changeDisplayEngine( ( fheroes2::engine().getDisplayId() + 1 ) % fheroes2::engine().getNumberOfVideoDisplays() ); conf.Save( Settings::configFileName ); windowType = SelectedWindow::Configuration; break; + } case SelectedWindow::InterfaceType: conf.setEvilInterface( !conf.isEvilInterfaceEnabled() ); updateUI(); From cec93b109c0b96355317d5a171ba86c46a58c9bf Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Thu, 14 Dec 2023 00:22:12 +0330 Subject: [PATCH 31/55] Changing dialog_graphics_settings to 5 item layout with both good and evil interface type --- .../dialog/dialog_graphics_settings.cpp | 52 +++++-------------- 1 file changed, 12 insertions(+), 40 deletions(-) diff --git a/src/fheroes2/dialog/dialog_graphics_settings.cpp b/src/fheroes2/dialog/dialog_graphics_settings.cpp index 26e93e1a62d..6e567085764 100644 --- a/src/fheroes2/dialog/dialog_graphics_settings.cpp +++ b/src/fheroes2/dialog/dialog_graphics_settings.cpp @@ -50,21 +50,20 @@ namespace VSync, SystemInfo, SwitchDisplay, - InterfaceType, Exit }; const fheroes2::Size offsetBetweenOptions{ 92, 110 }; const fheroes2::Point optionOffset{ 36, 47 }; const int32_t optionWindowSize{ 65 }; + const int32_t centerAlignmentOffset{ offsetBetweenOptions.width / 2 }; const fheroes2::Rect resolutionRoi{ optionOffset.x, optionOffset.y, optionWindowSize, optionWindowSize }; const fheroes2::Rect modeRoi{ optionOffset.x + offsetBetweenOptions.width, optionOffset.y, optionWindowSize, optionWindowSize }; - const fheroes2::Rect vSyncRoi{ optionOffset.x, optionOffset.y + offsetBetweenOptions.height, optionWindowSize, optionWindowSize }; - const fheroes2::Rect systemInfoRoi{ optionOffset.x + offsetBetweenOptions.width, optionOffset.y + offsetBetweenOptions.height, optionWindowSize, optionWindowSize }; + const fheroes2::Rect vSyncRoi{ optionOffset.x + centerAlignmentOffset, optionOffset.y + offsetBetweenOptions.height, optionWindowSize, optionWindowSize }; + const fheroes2::Rect systemInfoRoi{ optionOffset.x + offsetBetweenOptions.width + centerAlignmentOffset, optionOffset.y + offsetBetweenOptions.height, + optionWindowSize, optionWindowSize }; const fheroes2::Rect switchDisplayRoi{ optionOffset.x + offsetBetweenOptions.width * 2, optionOffset.y, optionWindowSize, optionWindowSize }; - const fheroes2::Rect interfaceTypeRoi{ optionOffset.x + offsetBetweenOptions.width * 2, optionOffset.y + offsetBetweenOptions.height, optionWindowSize, - optionWindowSize }; void drawDisplay( const fheroes2::Rect & optionRoi ) { @@ -132,26 +131,6 @@ namespace fheroes2::drawOption( optionRoi, image, _( "System Info" ), isSystemInfoDisplayed ? _( "on" ) : _( "off" ), fheroes2::UiOptionTextWidth::TWO_ELEMENTS_ROW ); } - void drawInterfaceType( const fheroes2::Rect & optionRoi ) - { - fheroes2::Sprite goodInterface = fheroes2::AGG::GetICN( ICN::SPANEL, 16 ); - fheroes2::Sprite evilInterface = fheroes2::AGG::GetICN( ICN::SPANEL, 17 ); - const Settings & conf = Settings::Get(); - const bool isEvilInterface = conf.isEvilInterfaceEnabled(); - - std::string value; - if ( isEvilInterface ) { - value = _( "Evil" ); - } - else { - value = _( "Good" ); - } - goodInterface = fheroes2::Crop( goodInterface, 0, 0, goodInterface.width() / 2, goodInterface.height() ); - fheroes2::Blit( goodInterface, evilInterface ); - - fheroes2::drawOption( optionRoi, evilInterface, _( "Interface Type" ), std::move( value ), fheroes2::UiOptionTextWidth::TWO_ELEMENTS_ROW ); - } - SelectedWindow showConfigurationWindow() { fheroes2::Display & display = fheroes2::Display::instance(); @@ -161,6 +140,11 @@ namespace const fheroes2::Sprite & dialog = fheroes2::AGG::GetICN( ( isEvilInterface ? ICN::CSPANBKE : ICN::CSPANBKG ), 0 ); const fheroes2::Sprite & dialogShadow = fheroes2::AGG::GetICN( ( isEvilInterface ? ICN::CSPANBKE : ICN::CSPANBKG ), 1 ); + fheroes2::Sprite placeholder = fheroes2::AGG::GetICN( Settings::Get().isEvilInterfaceEnabled() ? ICN::SURDRBKE : ICN::SURDRBKG, 0 ); + // the image taken from other big ICN and cropping it's background with adequate size + // the offsets are staticly fixed based on original image + placeholder = fheroes2::Crop( placeholder, 50, 30, dialog.width() - BORDERWIDTH * 2 - 20, optionWindowSize + 20 ); + const fheroes2::Point dialogOffset( ( display.width() - dialog.width() ) / 2, ( display.height() - dialog.height() ) / 2 ); const fheroes2::Point shadowOffset( dialogOffset.x - BORDERWIDTH, dialogOffset.y ); @@ -170,6 +154,8 @@ namespace fheroes2::Blit( dialogShadow, display, windowRoi.x - BORDERWIDTH, windowRoi.y + BORDERWIDTH ); fheroes2::Blit( dialog, display, windowRoi.x, windowRoi.y ); + // filling the empty spaces on the second row alongside with it's shadow + fheroes2::Blit( placeholder, display, windowRoi.x + BORDERWIDTH + 10, windowRoi.y + optionOffset.y - 10 + offsetBetweenOptions.height ); fheroes2::ImageRestorer emptyDialogRestorer( display, windowRoi.x, windowRoi.y, windowRoi.width, windowRoi.height ); @@ -178,15 +164,13 @@ namespace const fheroes2::Rect windowVSyncRoi( vSyncRoi + windowRoi.getPosition() ); const fheroes2::Rect windowSystemInfoRoi( systemInfoRoi + windowRoi.getPosition() ); const fheroes2::Rect windowSwitchDisplayRoi( switchDisplayRoi + windowRoi.getPosition() ); - const fheroes2::Rect windowInterfaceTypeRoi( interfaceTypeRoi + windowRoi.getPosition() ); - const auto drawOptions = [&windowResolutionRoi, &windowModeRoi, &windowVSyncRoi, &windowSystemInfoRoi, &windowSwitchDisplayRoi, &windowInterfaceTypeRoi]() { + const auto drawOptions = [&windowResolutionRoi, &windowModeRoi, &windowVSyncRoi, &windowSystemInfoRoi, &windowSwitchDisplayRoi]() { drawResolution( windowResolutionRoi ); drawMode( windowModeRoi ); drawVSync( windowVSyncRoi ); drawSystemInfo( windowSystemInfoRoi ); drawDisplay( windowSwitchDisplayRoi ); - drawInterfaceType( windowInterfaceTypeRoi ); }; drawOptions(); @@ -226,9 +210,6 @@ namespace if ( le.MouseClickLeft( windowSwitchDisplayRoi ) ) { return SelectedWindow::SwitchDisplay; } - if ( le.MouseClickLeft( windowInterfaceTypeRoi ) ) { - return SelectedWindow::InterfaceType; - } if ( le.MousePressRight( windowResolutionRoi ) ) { fheroes2::showStandardTextMessage( _( "Select Game Resolution" ), _( "Change the resolution of the game." ), 0 ); } @@ -244,9 +225,6 @@ namespace else if ( le.MousePressRight( windowSystemInfoRoi ) ) { fheroes2::showStandardTextMessage( _( "System Info" ), _( "Show extra information such as FPS and current time." ), 0 ); } - else if ( le.MousePressRight( windowInterfaceTypeRoi ) ) { - fheroes2::showStandardTextMessage( _( "Interface Type" ), _( "Toggle Between Evil and Good Interface." ), 0 ); - } else if ( le.MousePressRight( okayButton.area() ) ) { fheroes2::showStandardTextMessage( _( "Okay" ), _( "Exit this menu." ), 0 ); } @@ -307,12 +285,6 @@ namespace fheroes2 windowType = SelectedWindow::Configuration; break; } - case SelectedWindow::InterfaceType: - conf.setEvilInterface( !conf.isEvilInterfaceEnabled() ); - updateUI(); - conf.Save( Settings::configFileName ); - windowType = SelectedWindow::Configuration; - break; default: return; } From 662c474117a5dd879a56b62609aeb3b4e9d55db2 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Sat, 13 Jan 2024 18:24:10 +0330 Subject: [PATCH 32/55] Adressing Reviews - fixing Space in 2 file - Updating Text --- src/fheroes2/dialog/dialog_graphics_settings.cpp | 2 +- src/fheroes2/game/fheroes2.cpp | 1 + src/fheroes2/system/settings.h | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/fheroes2/dialog/dialog_graphics_settings.cpp b/src/fheroes2/dialog/dialog_graphics_settings.cpp index 6e567085764..77d263b6287 100644 --- a/src/fheroes2/dialog/dialog_graphics_settings.cpp +++ b/src/fheroes2/dialog/dialog_graphics_settings.cpp @@ -220,7 +220,7 @@ namespace fheroes2::showStandardTextMessage( _( "V-Sync" ), _( "The V-Sync option can be enabled to resolve flickering issues on some monitors." ), 0 ); } else if ( le.MousePressRight( windowSwitchDisplayRoi ) ) { - fheroes2::showStandardTextMessage( _( "Display Selection" ), _( "Toggle Between available Displays, Restart Required to take Effect" ), 0 ); + fheroes2::showStandardTextMessage( _( "Display Selection" ), _( "Toggle Between available Displays" ), 0 ); } else if ( le.MousePressRight( windowSystemInfoRoi ) ) { fheroes2::showStandardTextMessage( _( "System Info" ), _( "Show extra information such as FPS and current time." ), 0 ); diff --git a/src/fheroes2/game/fheroes2.cpp b/src/fheroes2/game/fheroes2.cpp index d2108fb1eff..29b75cd2cca 100644 --- a/src/fheroes2/game/fheroes2.cpp +++ b/src/fheroes2/game/fheroes2.cpp @@ -166,6 +166,7 @@ namespace bestResolution = info; } } + display.setResolution( bestResolution ); } else { diff --git a/src/fheroes2/system/settings.h b/src/fheroes2/system/settings.h index 1a1ed1ed999..cb58d93496c 100644 --- a/src/fheroes2/system/settings.h +++ b/src/fheroes2/system/settings.h @@ -249,6 +249,7 @@ class Settings void setHideInterface( const bool enable ); void setEvilInterface( const bool enable ); void setScreenScalingTypeNearest( const bool enable ); + void SetSoundVolume( int v ); void SetMusicVolume( int v ); From 7f36dd5387a65be4da1f7579cd062c0fd9fe5dd9 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Sat, 13 Jan 2024 18:34:05 +0330 Subject: [PATCH 33/55] Removing display Instantiation --- src/fheroes2/dialog/dialog_graphics_settings.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/fheroes2/dialog/dialog_graphics_settings.cpp b/src/fheroes2/dialog/dialog_graphics_settings.cpp index 77d263b6287..ebb9fd9faae 100644 --- a/src/fheroes2/dialog/dialog_graphics_settings.cpp +++ b/src/fheroes2/dialog/dialog_graphics_settings.cpp @@ -249,7 +249,6 @@ namespace fheroes2 void openGraphicsSettingsDialog( const std::function & updateUI ) { Settings & conf = Settings::Get(); - fheroes2::Display & display = fheroes2::Display::instance(); SelectedWindow windowType = SelectedWindow::Configuration; while ( windowType != SelectedWindow::Exit ) { @@ -280,7 +279,7 @@ namespace fheroes2 windowType = SelectedWindow::Configuration; break; case SelectedWindow::SwitchDisplay: { - display.changeDisplayEngine( ( fheroes2::engine().getDisplayId() + 1 ) % fheroes2::engine().getNumberOfVideoDisplays() ); + fheroes2::Display::instance().changeDisplayEngine( ( fheroes2::engine().getDisplayId() + 1 ) % fheroes2::engine().getNumberOfVideoDisplays() ); conf.Save( Settings::configFileName ); windowType = SelectedWindow::Configuration; break; From d19573b3cb2c2db83722ac1e4a4b7a8adc3c075b Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Sat, 13 Jan 2024 18:37:51 +0330 Subject: [PATCH 34/55] Changing Required Headers Date to 2024 --- src/engine/screen.cpp | 2 +- src/engine/screen.h | 2 +- src/fheroes2/dialog/dialog_graphics_settings.cpp | 2 +- src/fheroes2/system/settings.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/engine/screen.cpp b/src/engine/screen.cpp index 04b11724959..d6d65e8b76e 100644 --- a/src/engine/screen.cpp +++ b/src/engine/screen.cpp @@ -1,6 +1,6 @@ /*************************************************************************** * fheroes2: https://github.com/ihhub/fheroes2 * - * Copyright (C) 2020 - 2023 * + * Copyright (C) 2020 - 2024 * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * diff --git a/src/engine/screen.h b/src/engine/screen.h index 0a49a5b8015..e61ea5db662 100644 --- a/src/engine/screen.h +++ b/src/engine/screen.h @@ -1,6 +1,6 @@ /*************************************************************************** * fheroes2: https://github.com/ihhub/fheroes2 * - * Copyright (C) 2020 - 2023 * + * Copyright (C) 2020 - 2024 * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * diff --git a/src/fheroes2/dialog/dialog_graphics_settings.cpp b/src/fheroes2/dialog/dialog_graphics_settings.cpp index ebb9fd9faae..8990ca6c53c 100644 --- a/src/fheroes2/dialog/dialog_graphics_settings.cpp +++ b/src/fheroes2/dialog/dialog_graphics_settings.cpp @@ -1,6 +1,6 @@ /*************************************************************************** * fheroes2: https://github.com/ihhub/fheroes2 * - * Copyright (C) 2022 - 2023 * + * Copyright (C) 2022 - 2024 * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * diff --git a/src/fheroes2/system/settings.cpp b/src/fheroes2/system/settings.cpp index 0a437115247..ff02aa41fc9 100644 --- a/src/fheroes2/system/settings.cpp +++ b/src/fheroes2/system/settings.cpp @@ -1,6 +1,6 @@ /*************************************************************************** * fheroes2: https://github.com/ihhub/fheroes2 * - * Copyright (C) 2019 - 2023 * + * Copyright (C) 2019 - 2024 * * * * Free Heroes2 Engine: http://sourceforge.net/projects/fheroes2 * * Copyright (C) 2009 by Andrey Afletdinov * From 051f5e8bf79e39c832b12cce211f9d7cb5149402 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Sat, 13 Jan 2024 19:33:47 +0330 Subject: [PATCH 35/55] Addressing Reviews - Adding Static to getNumberOfVideoDisplays function - Reverting C++17 if-initilizer style --- src/engine/screen.cpp | 3 ++- src/engine/screen.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/engine/screen.cpp b/src/engine/screen.cpp index d6d65e8b76e..aead2b60d07 100644 --- a/src/engine/screen.cpp +++ b/src/engine/screen.cpp @@ -1507,7 +1507,8 @@ namespace fheroes2 int BaseRenderEngine::getNumberOfVideoDisplays() { - if ( int displayCount = SDL_GetNumVideoDisplays(); displayCount > 0 ) { + int displayCount = SDL_GetNumVideoDisplays(); + if ( displayCount > 0 ) { return displayCount; } ERROR_LOG( "Failed to Get Number of Displays, description: " << SDL_GetError() ); diff --git a/src/engine/screen.h b/src/engine/screen.h index e61ea5db662..454903c80ec 100644 --- a/src/engine/screen.h +++ b/src/engine/screen.h @@ -149,7 +149,7 @@ namespace fheroes2 _displayId = display; } - int getNumberOfVideoDisplays(); + static int getNumberOfVideoDisplays(); const char * getDisplayName( const int display ); protected: From 76c9b98519bfaf772c6faf540a0f93fa4a42a8b4 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Mon, 15 Jan 2024 03:19:50 +0330 Subject: [PATCH 36/55] - Changing displayId name to displayIndex - Changing methods in BaseRenderEngine to virtual - Adding isAllocated methods - Adding actual implementation in RenderEngine - Removing ChangeDisplayEngine - Altering display changing routine --- src/engine/screen.cpp | 83 ++++++++++--------- src/engine/screen.h | 29 ++++--- .../dialog/dialog_graphics_settings.cpp | 12 ++- src/fheroes2/system/settings.cpp | 6 +- 4 files changed, 73 insertions(+), 57 deletions(-) diff --git a/src/engine/screen.cpp b/src/engine/screen.cpp index aead2b60d07..8c3b0897dc1 100644 --- a/src/engine/screen.cpp +++ b/src/engine/screen.cpp @@ -938,6 +938,34 @@ namespace } } + uint8_t getCurrentDisplayIndex() const override + { + return _displayIndex; + } + + void setDisplayIndex( const uint8_t display ) override + { + _displayIndex = display; + + clear(); + } + + uint8_t getMaximumDisplays() const override + { + int displayCount = SDL_GetNumVideoDisplays(); + if ( displayCount > 0 ) { + return static_cast( displayCount ); + } + ERROR_LOG( "Failed to Get Number of Displays, description: " << SDL_GetError() ); + // there should be one display at least + return 1; + } + + const char * getDisplayName( const uint8_t display ) override + { + return SDL_GetDisplayName( display ); + } + protected: RenderEngine() : _window( nullptr ) @@ -945,8 +973,10 @@ namespace , _renderer( nullptr ) , _texture( nullptr ) , _driverIndex( -1 ) + , _displayIndex( 0 ) , _prevWindowPos( SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED ) , _isVSyncEnabled( false ) + { // Do nothing. } @@ -1059,8 +1089,8 @@ namespace uint32_t flags = SDL_WINDOW_SHOWN; // SDL_GetNumVideoDisplays starts from 1 so we add 1 to our variable - if ( getDisplayId() + 1 > getNumberOfVideoDisplays() ) { - setDisplayId( 0 ); + if ( getCurrentDisplayIndex() + 1 > getMaximumDisplays() ) { + setDisplayIndex( 0 ); } if ( isFullScreen ) { @@ -1080,8 +1110,8 @@ namespace #if defined( _WIN32 ) - _window = SDL_CreateWindow( _previousWindowTitle.data(), SDL_WINDOWPOS_CENTERED_DISPLAY( getDisplayId() ), SDL_WINDOWPOS_CENTERED_DISPLAY( getDisplayId() ), - resolutionInfo.screenWidth, resolutionInfo.screenHeight, flags ); + _window = SDL_CreateWindow( _previousWindowTitle.data(), SDL_WINDOWPOS_CENTERED_DISPLAY( getCurrentDisplayIndex() ), + SDL_WINDOWPOS_CENTERED_DISPLAY( getCurrentDisplayIndex() ), resolutionInfo.screenWidth, resolutionInfo.screenHeight, flags ); #else _window = SDL_CreateWindow( _previousWindowTitle.data(), _prevWindowPos.x, _prevWindowPos.y, resolutionInfo.screenWidth, resolutionInfo.screenHeight, flags ); #endif @@ -1167,12 +1197,19 @@ namespace return ( _window != nullptr ) && ( ( SDL_GetWindowFlags( _window ) & SDL_WINDOW_MOUSE_FOCUS ) == SDL_WINDOW_MOUSE_FOCUS ); } + bool isAllocated() const override + { + // we should check for at least one of the variables destroyed in clear function + return _window != nullptr; + } + private: SDL_Window * _window; SDL_Surface * _surface; SDL_Renderer * _renderer; SDL_Texture * _texture; int _driverIndex; + uint8_t _displayIndex; std::string _previousWindowTitle; fheroes2::Point _prevWindowPos; @@ -1345,7 +1382,7 @@ namespace fheroes2 void Display::setResolution( ResolutionInfo info ) { if ( width() > 0 && height() > 0 && info.gameWidth == width() && info.gameHeight == height() && info.screenWidth == _screenSize.width - && info.screenHeight == _screenSize.height ) // nothing to resize + && info.screenHeight == _screenSize.height && _engine->isAllocated() ) // nothing to resize return; const bool isFullScreen = _engine->isFullScreen(); @@ -1367,26 +1404,6 @@ namespace fheroes2 std::fill( transform(), transform() + width() * height(), static_cast( 1 ) ); } - void Display::changeDisplayEngine( int displayId ) - { - _engine->setDisplayId( displayId ); - - const bool isFullScreen = _engine->isFullScreen(); - - Size currentRes = _engine->getCurrentScreenResolution(); - ResolutionInfo resInfo( currentRes.width, currentRes.height ); - - // deallocate engine resources - _engine->clear(); - - _engine->allocate( resInfo, isFullScreen ); - - Image::resize( resInfo.gameWidth, resInfo.gameHeight ); - _screenSize = { resInfo.screenWidth, resInfo.screenHeight }; - - std::fill( transform(), transform() + width() * height(), static_cast( 1 ) ); - } - Display & Display::instance() { static Display display; @@ -1504,20 +1521,4 @@ namespace fheroes2 { return *( Display::instance()._cursor ); } - - int BaseRenderEngine::getNumberOfVideoDisplays() - { - int displayCount = SDL_GetNumVideoDisplays(); - if ( displayCount > 0 ) { - return displayCount; - } - ERROR_LOG( "Failed to Get Number of Displays, description: " << SDL_GetError() ); - // there should be one display at least - return 1; - } - - const char * BaseRenderEngine::getDisplayName( const int display ) - { - return SDL_GetDisplayName( display ); - } } diff --git a/src/engine/screen.h b/src/engine/screen.h index 454903c80ec..19bd3a3e90c 100644 --- a/src/engine/screen.h +++ b/src/engine/screen.h @@ -139,24 +139,30 @@ namespace fheroes2 return _nearestScaling; } - int getDisplayId() const + virtual uint8_t getCurrentDisplayIndex() const { - return _displayId; + return 0; } - void setDisplayId( const int display ) + virtual void setDisplayIndex( const uint8_t ) { - _displayId = display; + // Do Nothing } - static int getNumberOfVideoDisplays(); - const char * getDisplayName( const int display ); + virtual uint8_t getMaximumDisplays() const + { + return 1; + } + + virtual const char * getDisplayName( const uint8_t ) + { + return ""; + } protected: BaseRenderEngine() : _isFullScreen( false ) , _nearestScaling( false ) - , _displayId( 0 ) { // Do nothing. @@ -177,6 +183,11 @@ namespace fheroes2 return false; } + virtual bool isAllocated() const + { + return true; + } + virtual bool isMouseCursorActive() const { return false; @@ -194,8 +205,6 @@ namespace fheroes2 bool _isFullScreen; bool _nearestScaling; - - int _displayId; }; class Display : public Image @@ -229,7 +238,7 @@ namespace fheroes2 void setResolution( ResolutionInfo info ); - void changeDisplayEngine( int displayId ); + void changeDisplayEngine( uint8_t displayId ); bool isDefaultSize() const { diff --git a/src/fheroes2/dialog/dialog_graphics_settings.cpp b/src/fheroes2/dialog/dialog_graphics_settings.cpp index 8990ca6c53c..d1a9672cb15 100644 --- a/src/fheroes2/dialog/dialog_graphics_settings.cpp +++ b/src/fheroes2/dialog/dialog_graphics_settings.cpp @@ -67,9 +67,9 @@ namespace void drawDisplay( const fheroes2::Rect & optionRoi ) { - int displayId = fheroes2::engine().getDisplayId(); + uint8_t displayIndex = fheroes2::engine().getCurrentDisplayIndex(); fheroes2::drawOption( optionRoi, fheroes2::AGG::GetICN( ICN::GAME_OPTION_ICON, 1 ), _( "Display ID" ), - std::to_string( displayId + 1 ) + ": " + fheroes2::engine().getDisplayName( displayId ), fheroes2::UiOptionTextWidth::TWO_ELEMENTS_ROW ); + std::to_string( displayIndex + 1 ) + ": " + fheroes2::engine().getDisplayName( displayIndex ), fheroes2::UiOptionTextWidth::TWO_ELEMENTS_ROW ); } void drawResolution( const fheroes2::Rect & optionRoi ) @@ -279,7 +279,13 @@ namespace fheroes2 windowType = SelectedWindow::Configuration; break; case SelectedWindow::SwitchDisplay: { - fheroes2::Display::instance().changeDisplayEngine( ( fheroes2::engine().getDisplayId() + 1 ) % fheroes2::engine().getNumberOfVideoDisplays() ); + fheroes2::BaseRenderEngine & engine = fheroes2::engine(); + engine.setDisplayIndex( ( engine.getCurrentDisplayIndex() + 1 ) % engine.getMaximumDisplays() ); + + fheroes2::Display & display = fheroes2::Display::instance(); + const fheroes2::ResolutionInfo currentResolution{ display.width(), display.height(), display.screenSize().width, display.screenSize().height }; + display.setResolution( currentResolution ); + conf.Save( Settings::configFileName ); windowType = SelectedWindow::Configuration; break; diff --git a/src/fheroes2/system/settings.cpp b/src/fheroes2/system/settings.cpp index ff02aa41fc9..4d579bb8e05 100644 --- a/src/fheroes2/system/settings.cpp +++ b/src/fheroes2/system/settings.cpp @@ -327,7 +327,7 @@ bool Settings::Read( const std::string & filePath ) } if ( config.Exists( "display" ) ) { - fheroes2::engine().setDisplayId( std::max( config.IntParams( "display" ), 0 ) ); + fheroes2::engine().setDisplayIndex( static_cast( std::max( config.IntParams( "display" ), 0 ) ) ); } return true; @@ -375,8 +375,8 @@ std::string Settings::String() const os << std::endl << "# video mode: in-game width x in-game height : on-screen width x on-screen height" << std::endl; os << "videomode = " << display.width() << "x" << display.height() << ":" << display.screenSize().width << "x" << display.screenSize().height << std::endl; - os << std::endl << "# Display ID (defaults to First Display)" << std::endl; - os << "display = " << fheroes2::engine().getDisplayId() << std::endl; + os << std::endl << "# Display Index (defaults to First Display)" << std::endl; + os << "display = " << fheroes2::engine().getCurrentDisplayIndex() << std::endl; os << std::endl << "# music: original, expansion, external" << std::endl; os << "music = " << musicType << std::endl; From 5865c2419c930ddd2f09a16cd54f3cd52abec591 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Mon, 15 Jan 2024 03:38:09 +0330 Subject: [PATCH 37/55] - Changing Description - Fixing Saving output variable to int --- src/fheroes2/system/settings.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fheroes2/system/settings.cpp b/src/fheroes2/system/settings.cpp index 4d579bb8e05..62d6b2831e4 100644 --- a/src/fheroes2/system/settings.cpp +++ b/src/fheroes2/system/settings.cpp @@ -375,8 +375,8 @@ std::string Settings::String() const os << std::endl << "# video mode: in-game width x in-game height : on-screen width x on-screen height" << std::endl; os << "videomode = " << display.width() << "x" << display.height() << ":" << display.screenSize().width << "x" << display.screenSize().height << std::endl; - os << std::endl << "# Display Index (defaults to First Display)" << std::endl; - os << "display = " << fheroes2::engine().getCurrentDisplayIndex() << std::endl; + os << std::endl << "# Display Index" << std::endl; + os << "display = " << static_cast(fheroes2::engine().getCurrentDisplayIndex()) << std::endl; os << std::endl << "# music: original, expansion, external" << std::endl; os << "music = " << musicType << std::endl; From b1a9987c62ea5243e6c12ba7c5b59a3145660272 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Mon, 15 Jan 2024 03:43:14 +0330 Subject: [PATCH 38/55] in Graphics Settings: Changing How Background of 2nd Row is created (using Blit on Original Image) --- src/fheroes2/dialog/dialog_graphics_settings.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/fheroes2/dialog/dialog_graphics_settings.cpp b/src/fheroes2/dialog/dialog_graphics_settings.cpp index d1a9672cb15..a4d027108db 100644 --- a/src/fheroes2/dialog/dialog_graphics_settings.cpp +++ b/src/fheroes2/dialog/dialog_graphics_settings.cpp @@ -69,7 +69,8 @@ namespace { uint8_t displayIndex = fheroes2::engine().getCurrentDisplayIndex(); fheroes2::drawOption( optionRoi, fheroes2::AGG::GetICN( ICN::GAME_OPTION_ICON, 1 ), _( "Display ID" ), - std::to_string( displayIndex + 1 ) + ": " + fheroes2::engine().getDisplayName( displayIndex ), fheroes2::UiOptionTextWidth::TWO_ELEMENTS_ROW ); + std::to_string( displayIndex + 1 ) + ": " + fheroes2::engine().getDisplayName( displayIndex ), + fheroes2::UiOptionTextWidth::TWO_ELEMENTS_ROW ); } void drawResolution( const fheroes2::Rect & optionRoi ) @@ -140,10 +141,7 @@ namespace const fheroes2::Sprite & dialog = fheroes2::AGG::GetICN( ( isEvilInterface ? ICN::CSPANBKE : ICN::CSPANBKG ), 0 ); const fheroes2::Sprite & dialogShadow = fheroes2::AGG::GetICN( ( isEvilInterface ? ICN::CSPANBKE : ICN::CSPANBKG ), 1 ); - fheroes2::Sprite placeholder = fheroes2::AGG::GetICN( Settings::Get().isEvilInterfaceEnabled() ? ICN::SURDRBKE : ICN::SURDRBKG, 0 ); - // the image taken from other big ICN and cropping it's background with adequate size - // the offsets are staticly fixed based on original image - placeholder = fheroes2::Crop( placeholder, 50, 30, dialog.width() - BORDERWIDTH * 2 - 20, optionWindowSize + 20 ); + const fheroes2::Sprite secondRowBackground = fheroes2::AGG::GetICN( Settings::Get().isEvilInterfaceEnabled() ? ICN::SURDRBKE : ICN::SURDRBKG, 0 ); const fheroes2::Point dialogOffset( ( display.width() - dialog.width() ) / 2, ( display.height() - dialog.height() ) / 2 ); const fheroes2::Point shadowOffset( dialogOffset.x - BORDERWIDTH, dialogOffset.y ); @@ -154,8 +152,12 @@ namespace fheroes2::Blit( dialogShadow, display, windowRoi.x - BORDERWIDTH, windowRoi.y + BORDERWIDTH ); fheroes2::Blit( dialog, display, windowRoi.x, windowRoi.y ); + + // the image taken from other big ICN and cropping it's background with adequate size + // the offsets are staticly fixed based on original image // filling the empty spaces on the second row alongside with it's shadow - fheroes2::Blit( placeholder, display, windowRoi.x + BORDERWIDTH + 10, windowRoi.y + optionOffset.y - 10 + offsetBetweenOptions.height ); + fheroes2::Blit( secondRowBackground, 50, 30, display, windowRoi.x + BORDERWIDTH + 10, windowRoi.y + optionOffset.y - 10 + offsetBetweenOptions.height, + dialog.width() - BORDERWIDTH * 2 - 20, optionWindowSize + 20 ); fheroes2::ImageRestorer emptyDialogRestorer( display, windowRoi.x, windowRoi.y, windowRoi.width, windowRoi.height ); From 0a70c349adacbaa775bf5e2e98e75b9a9deeff0b Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Mon, 15 Jan 2024 03:45:50 +0330 Subject: [PATCH 39/55] style fix --- src/fheroes2/system/settings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fheroes2/system/settings.cpp b/src/fheroes2/system/settings.cpp index 62d6b2831e4..d3848ed3279 100644 --- a/src/fheroes2/system/settings.cpp +++ b/src/fheroes2/system/settings.cpp @@ -376,7 +376,7 @@ std::string Settings::String() const os << "videomode = " << display.width() << "x" << display.height() << ":" << display.screenSize().width << "x" << display.screenSize().height << std::endl; os << std::endl << "# Display Index" << std::endl; - os << "display = " << static_cast(fheroes2::engine().getCurrentDisplayIndex()) << std::endl; + os << "display = " << static_cast( fheroes2::engine().getCurrentDisplayIndex() ) << std::endl; os << std::endl << "# music: original, expansion, external" << std::endl; os << "music = " << musicType << std::endl; From 3ce899812c2ba81870b4ee3b4f7c7242b0f97687 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Thu, 18 Jan 2024 02:09:59 +0330 Subject: [PATCH 40/55] Addressing Reviews --- src/engine/screen.cpp | 36 ++++++++++--------- src/engine/screen.h | 5 +-- .../dialog/dialog_graphics_settings.cpp | 25 +++++++------ 3 files changed, 32 insertions(+), 34 deletions(-) diff --git a/src/engine/screen.cpp b/src/engine/screen.cpp index 8c3b0897dc1..6fe0dd7bf68 100644 --- a/src/engine/screen.cpp +++ b/src/engine/screen.cpp @@ -945,14 +945,25 @@ namespace void setDisplayIndex( const uint8_t display ) override { - _displayIndex = display; + if ( display == _displayIndex ) + return; + + SDL_GetWindowPosition( _window, &_prevWindowPos.x, &_prevWindowPos.y ); + + // SDL_GetNumVideoDisplays starts from 1 instead of 0 + if ( display + 1 > getMaximumDisplays() ) { + _displayIndex = 0; + } + else { + _displayIndex = display; + } clear(); } uint8_t getMaximumDisplays() const override { - int displayCount = SDL_GetNumVideoDisplays(); + const int displayCount = SDL_GetNumVideoDisplays(); if ( displayCount > 0 ) { return static_cast( displayCount ); } @@ -976,7 +987,6 @@ namespace , _displayIndex( 0 ) , _prevWindowPos( SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED ) , _isVSyncEnabled( false ) - { // Do nothing. } @@ -1088,11 +1098,6 @@ namespace uint32_t flags = SDL_WINDOW_SHOWN; - // SDL_GetNumVideoDisplays starts from 1 so we add 1 to our variable - if ( getCurrentDisplayIndex() + 1 > getMaximumDisplays() ) { - setDisplayIndex( 0 ); - } - if ( isFullScreen ) { #if defined( _WIN32 ) if ( fheroes2::cursor().isSoftwareEmulation() ) { @@ -1108,13 +1113,8 @@ namespace flags |= SDL_WINDOW_RESIZABLE; -#if defined( _WIN32 ) - _window = SDL_CreateWindow( _previousWindowTitle.data(), SDL_WINDOWPOS_CENTERED_DISPLAY( getCurrentDisplayIndex() ), SDL_WINDOWPOS_CENTERED_DISPLAY( getCurrentDisplayIndex() ), resolutionInfo.screenWidth, resolutionInfo.screenHeight, flags ); -#else - _window = SDL_CreateWindow( _previousWindowTitle.data(), _prevWindowPos.x, _prevWindowPos.y, resolutionInfo.screenWidth, resolutionInfo.screenHeight, flags ); -#endif if ( _window == nullptr ) { ERROR_LOG( "Failed to create an application window of " << resolutionInfo.screenWidth << " x " << resolutionInfo.screenHeight << " size. The error: " << SDL_GetError() ) @@ -1199,7 +1199,7 @@ namespace bool isAllocated() const override { - // we should check for at least one of the variables destroyed in clear function + // We Should Check for at Least One of the Variables Destroyed in Clear() return _window != nullptr; } @@ -1382,17 +1382,19 @@ namespace fheroes2 void Display::setResolution( ResolutionInfo info ) { if ( width() > 0 && height() > 0 && info.gameWidth == width() && info.gameHeight == height() && info.screenWidth == _screenSize.width - && info.screenHeight == _screenSize.height && _engine->isAllocated() ) // nothing to resize + && info.screenHeight == _screenSize.height && _engine->isAllocated() ) { + // Nothing to resize return; + } const bool isFullScreen = _engine->isFullScreen(); - // deallocate engine resources + // Deallocate engine resources _engine->clear(); _prevRoi = {}; - // allocate engine resources + // Allocate engine resources if ( !_engine->allocate( info, isFullScreen ) ) { clear(); } diff --git a/src/engine/screen.h b/src/engine/screen.h index 19bd3a3e90c..9dca5db61f2 100644 --- a/src/engine/screen.h +++ b/src/engine/screen.h @@ -146,7 +146,7 @@ namespace fheroes2 virtual void setDisplayIndex( const uint8_t ) { - // Do Nothing + // Do Nothing. } virtual uint8_t getMaximumDisplays() const @@ -163,7 +163,6 @@ namespace fheroes2 BaseRenderEngine() : _isFullScreen( false ) , _nearestScaling( false ) - { // Do nothing. } @@ -238,8 +237,6 @@ namespace fheroes2 void setResolution( ResolutionInfo info ); - void changeDisplayEngine( uint8_t displayId ); - bool isDefaultSize() const { return width() == DEFAULT_WIDTH && height() == DEFAULT_HEIGHT; diff --git a/src/fheroes2/dialog/dialog_graphics_settings.cpp b/src/fheroes2/dialog/dialog_graphics_settings.cpp index a4d027108db..bde2aee7949 100644 --- a/src/fheroes2/dialog/dialog_graphics_settings.cpp +++ b/src/fheroes2/dialog/dialog_graphics_settings.cpp @@ -65,14 +65,6 @@ namespace optionWindowSize, optionWindowSize }; const fheroes2::Rect switchDisplayRoi{ optionOffset.x + offsetBetweenOptions.width * 2, optionOffset.y, optionWindowSize, optionWindowSize }; - void drawDisplay( const fheroes2::Rect & optionRoi ) - { - uint8_t displayIndex = fheroes2::engine().getCurrentDisplayIndex(); - fheroes2::drawOption( optionRoi, fheroes2::AGG::GetICN( ICN::GAME_OPTION_ICON, 1 ), _( "Display ID" ), - std::to_string( displayIndex + 1 ) + ": " + fheroes2::engine().getDisplayName( displayIndex ), - fheroes2::UiOptionTextWidth::TWO_ELEMENTS_ROW ); - } - void drawResolution( const fheroes2::Rect & optionRoi ) { const fheroes2::Display & display = fheroes2::Display::instance(); @@ -132,6 +124,14 @@ namespace fheroes2::drawOption( optionRoi, image, _( "System Info" ), isSystemInfoDisplayed ? _( "on" ) : _( "off" ), fheroes2::UiOptionTextWidth::TWO_ELEMENTS_ROW ); } + void drawDisplay( const fheroes2::Rect & optionRoi ) + { + const uint8_t displayIndex = fheroes2::engine().getCurrentDisplayIndex(); + fheroes2::drawOption( optionRoi, fheroes2::AGG::GetICN( ICN::GAME_OPTION_ICON, 1 ), _( "Display Index" ), + std::to_string( displayIndex + 1 ) + ": " + fheroes2::engine().getDisplayName( displayIndex ), + fheroes2::UiOptionTextWidth::TWO_ELEMENTS_ROW ); + } + SelectedWindow showConfigurationWindow() { fheroes2::Display & display = fheroes2::Display::instance(); @@ -141,7 +141,7 @@ namespace const fheroes2::Sprite & dialog = fheroes2::AGG::GetICN( ( isEvilInterface ? ICN::CSPANBKE : ICN::CSPANBKG ), 0 ); const fheroes2::Sprite & dialogShadow = fheroes2::AGG::GetICN( ( isEvilInterface ? ICN::CSPANBKE : ICN::CSPANBKG ), 1 ); - const fheroes2::Sprite secondRowBackground = fheroes2::AGG::GetICN( Settings::Get().isEvilInterfaceEnabled() ? ICN::SURDRBKE : ICN::SURDRBKG, 0 ); + const fheroes2::Sprite & secondRowBackground = fheroes2::AGG::GetICN( Settings::Get().isEvilInterfaceEnabled() ? ICN::SURDRBKE : ICN::SURDRBKG, 0 ); const fheroes2::Point dialogOffset( ( display.width() - dialog.width() ) / 2, ( display.height() - dialog.height() ) / 2 ); const fheroes2::Point shadowOffset( dialogOffset.x - BORDERWIDTH, dialogOffset.y ); @@ -153,9 +153,8 @@ namespace fheroes2::Blit( dialogShadow, display, windowRoi.x - BORDERWIDTH, windowRoi.y + BORDERWIDTH ); fheroes2::Blit( dialog, display, windowRoi.x, windowRoi.y ); - // the image taken from other big ICN and cropping it's background with adequate size - // the offsets are staticly fixed based on original image - // filling the empty spaces on the second row alongside with it's shadow + // The Image is taken from another big ICN and cropped its background with adequate size + // The Offsets are staticly fixed based on original image to Fill the empty spaces on the second row alongside with it's shadow fheroes2::Blit( secondRowBackground, 50, 30, display, windowRoi.x + BORDERWIDTH + 10, windowRoi.y + optionOffset.y - 10 + offsetBetweenOptions.height, dialog.width() - BORDERWIDTH * 2 - 20, optionWindowSize + 20 ); @@ -167,7 +166,7 @@ namespace const fheroes2::Rect windowSystemInfoRoi( systemInfoRoi + windowRoi.getPosition() ); const fheroes2::Rect windowSwitchDisplayRoi( switchDisplayRoi + windowRoi.getPosition() ); - const auto drawOptions = [&windowResolutionRoi, &windowModeRoi, &windowVSyncRoi, &windowSystemInfoRoi, &windowSwitchDisplayRoi]() { + const auto drawOptions = [&windowResolutionRoi, &windowModeRoi, &windowVSyncRoi, &windowSwitchDisplayRoi, &windowSystemInfoRoi]() { drawResolution( windowResolutionRoi ); drawMode( windowModeRoi ); drawVSync( windowVSyncRoi ); From deed982c58d358438699717d54565fa72722c448 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Fri, 19 Jan 2024 18:43:29 +0330 Subject: [PATCH 41/55] Addressing Reviews --- src/engine/screen.cpp | 9 ++++----- src/engine/screen.h | 2 +- src/fheroes2/dialog/dialog_graphics_settings.cpp | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/engine/screen.cpp b/src/engine/screen.cpp index 6fe0dd7bf68..716ed646274 100644 --- a/src/engine/screen.cpp +++ b/src/engine/screen.cpp @@ -950,12 +950,11 @@ namespace SDL_GetWindowPosition( _window, &_prevWindowPos.x, &_prevWindowPos.y ); - // SDL_GetNumVideoDisplays starts from 1 instead of 0 - if ( display + 1 > getMaximumDisplays() ) { - _displayIndex = 0; + if ( display < getMaximumDisplays() ) { + _displayIndex = display; } else { - _displayIndex = display; + _displayIndex = 0; } clear(); @@ -1199,7 +1198,7 @@ namespace bool isAllocated() const override { - // We Should Check for at Least One of the Variables Destroyed in Clear() + // We should check for at least one of the variables destroyed in Clear() return _window != nullptr; } diff --git a/src/engine/screen.h b/src/engine/screen.h index 9dca5db61f2..dcf8c1d8c59 100644 --- a/src/engine/screen.h +++ b/src/engine/screen.h @@ -146,7 +146,7 @@ namespace fheroes2 virtual void setDisplayIndex( const uint8_t ) { - // Do Nothing. + // Do nothing. } virtual uint8_t getMaximumDisplays() const diff --git a/src/fheroes2/dialog/dialog_graphics_settings.cpp b/src/fheroes2/dialog/dialog_graphics_settings.cpp index bde2aee7949..104995420f0 100644 --- a/src/fheroes2/dialog/dialog_graphics_settings.cpp +++ b/src/fheroes2/dialog/dialog_graphics_settings.cpp @@ -153,8 +153,8 @@ namespace fheroes2::Blit( dialogShadow, display, windowRoi.x - BORDERWIDTH, windowRoi.y + BORDERWIDTH ); fheroes2::Blit( dialog, display, windowRoi.x, windowRoi.y ); - // The Image is taken from another big ICN and cropped its background with adequate size - // The Offsets are staticly fixed based on original image to Fill the empty spaces on the second row alongside with it's shadow + // The image is taken from another big ICN and cropped, with its background at an adequate size. + // The offsets are statically fixed based on the original image to fill the empty spaces on the second row alongside it's shadow. fheroes2::Blit( secondRowBackground, 50, 30, display, windowRoi.x + BORDERWIDTH + 10, windowRoi.y + optionOffset.y - 10 + offsetBetweenOptions.height, dialog.width() - BORDERWIDTH * 2 - 20, optionWindowSize + 20 ); From d5cbd89c8a6203cbfd33f1168079dbd1a4747b21 Mon Sep 17 00:00:00 2001 From: Ihar Hubchyk Date: Sat, 20 Jan 2024 11:06:52 +0800 Subject: [PATCH 42/55] Update screen.cpp --- src/engine/screen.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/engine/screen.cpp b/src/engine/screen.cpp index 716ed646274..e32fd41076c 100644 --- a/src/engine/screen.cpp +++ b/src/engine/screen.cpp @@ -966,8 +966,9 @@ namespace if ( displayCount > 0 ) { return static_cast( displayCount ); } + ERROR_LOG( "Failed to Get Number of Displays, description: " << SDL_GetError() ); - // there should be one display at least + // There should be one display at least. return 1; } From 7ff712c1a21bcf07859ce35b851e56ffd3be2f65 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Tue, 6 Feb 2024 19:30:20 +0330 Subject: [PATCH 43/55] Fix main menu not generating after the display change --- src/fheroes2/dialog/dialog_graphics_settings.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/fheroes2/dialog/dialog_graphics_settings.cpp b/src/fheroes2/dialog/dialog_graphics_settings.cpp index 104995420f0..108c5431e6a 100644 --- a/src/fheroes2/dialog/dialog_graphics_settings.cpp +++ b/src/fheroes2/dialog/dialog_graphics_settings.cpp @@ -286,6 +286,7 @@ namespace fheroes2 fheroes2::Display & display = fheroes2::Display::instance(); const fheroes2::ResolutionInfo currentResolution{ display.width(), display.height(), display.screenSize().width, display.screenSize().height }; display.setResolution( currentResolution ); + updateUI(); conf.Save( Settings::configFileName ); windowType = SelectedWindow::Configuration; From 0287e22ecbc30188946a6c91b590743dc1972599 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Tue, 6 Feb 2024 19:33:40 +0330 Subject: [PATCH 44/55] Checking for supported display --- src/engine/screen.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/engine/screen.cpp b/src/engine/screen.cpp index 5fda14814c0..c254f1e20c9 100644 --- a/src/engine/screen.cpp +++ b/src/engine/screen.cpp @@ -851,15 +851,16 @@ namespace std::vector getAvailableResolutions() const override { - static const std::vector filteredResolutions = []() { + int currentIndex = static_cast( getCurrentDisplayIndex() ); + static const std::vector filteredResolutions = [=]() { std::set resolutionSet; const int displayCount = SDL_GetNumVideoDisplays(); if ( displayCount > 0 ) { - const int displayModeCount = SDL_GetNumDisplayModes( 0 ); + const int displayModeCount = SDL_GetNumDisplayModes( currentIndex ); for ( int i = 0; i < displayModeCount; ++i ) { SDL_DisplayMode videoMode; - const int returnCode = SDL_GetDisplayMode( 0, i, &videoMode ); + const int returnCode = SDL_GetDisplayMode( currentIndex, i, &videoMode ); if ( returnCode < 0 ) { ERROR_LOG( "Failed to get display mode. The error value: " << returnCode << ", description: " << SDL_GetError() ) } @@ -966,7 +967,6 @@ namespace if ( displayCount > 0 ) { return static_cast( displayCount ); } - ERROR_LOG( "Failed to Get Number of Displays, description: " << SDL_GetError() ); // There should be one display at least. return 1; @@ -1085,9 +1085,7 @@ namespace const std::vector resolutions = getAvailableResolutions(); assert( !resolutions.empty() ); - if ( !resolutions.empty() ) { - resolutionInfo = GetNearestResolution( resolutionInfo, resolutions ); - } + resolutionInfo = GetNearestResolution( resolutionInfo, resolutions ); #if defined( ANDROID ) // Same as ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE From c2bc9d7b32e6b92161c55d50128021554069e5be Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Mon, 4 Mar 2024 20:23:37 +0330 Subject: [PATCH 45/55] Fixing error for display index on startup --- src/engine/screen.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/engine/screen.cpp b/src/engine/screen.cpp index c254f1e20c9..99f2125e45c 100644 --- a/src/engine/screen.cpp +++ b/src/engine/screen.cpp @@ -963,6 +963,10 @@ namespace uint8_t getMaximumDisplays() const override { + if ( !isAllocated() ) + // If engine is not allocated returning highest uint8_t number + return 255; + const int displayCount = SDL_GetNumVideoDisplays(); if ( displayCount > 0 ) { return static_cast( displayCount ); @@ -1110,7 +1114,8 @@ namespace } flags |= SDL_WINDOW_RESIZABLE; - + int tmp = getCurrentDisplayIndex(); + _CRT_UNUSED( tmp ); _window = SDL_CreateWindow( _previousWindowTitle.data(), SDL_WINDOWPOS_CENTERED_DISPLAY( getCurrentDisplayIndex() ), SDL_WINDOWPOS_CENTERED_DISPLAY( getCurrentDisplayIndex() ), resolutionInfo.screenWidth, resolutionInfo.screenHeight, flags ); if ( _window == nullptr ) { From 6c06be69a5378fbd7579f58d5aae6139b45605f0 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Mon, 4 Mar 2024 20:35:54 +0330 Subject: [PATCH 46/55] remove unused variable --- src/engine/screen.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/engine/screen.cpp b/src/engine/screen.cpp index 99f2125e45c..230ee4b518c 100644 --- a/src/engine/screen.cpp +++ b/src/engine/screen.cpp @@ -1114,8 +1114,6 @@ namespace } flags |= SDL_WINDOW_RESIZABLE; - int tmp = getCurrentDisplayIndex(); - _CRT_UNUSED( tmp ); _window = SDL_CreateWindow( _previousWindowTitle.data(), SDL_WINDOWPOS_CENTERED_DISPLAY( getCurrentDisplayIndex() ), SDL_WINDOWPOS_CENTERED_DISPLAY( getCurrentDisplayIndex() ), resolutionInfo.screenWidth, resolutionInfo.screenHeight, flags ); if ( _window == nullptr ) { From 3af1d73c00a5a912dc726fd282b2886d28612953 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Mon, 4 Mar 2024 20:51:58 +0330 Subject: [PATCH 47/55] Fix lambda to calculate on every function call instead of only once --- src/engine/screen.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/screen.cpp b/src/engine/screen.cpp index 230ee4b518c..b4e768cf092 100644 --- a/src/engine/screen.cpp +++ b/src/engine/screen.cpp @@ -852,7 +852,7 @@ namespace std::vector getAvailableResolutions() const override { int currentIndex = static_cast( getCurrentDisplayIndex() ); - static const std::vector filteredResolutions = [=]() { + std::vector filteredResolutions = [=]() { std::set resolutionSet; const int displayCount = SDL_GetNumVideoDisplays(); From e6e80503f1b05b06222ea1fc7c1c2d5708c2cdea Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Thu, 28 Mar 2024 16:54:59 +0330 Subject: [PATCH 48/55] return last available display in case cureent display is out of bound --- src/engine/screen.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/engine/screen.cpp b/src/engine/screen.cpp index b4e768cf092..cb837d79d7a 100644 --- a/src/engine/screen.cpp +++ b/src/engine/screen.cpp @@ -941,6 +941,9 @@ namespace uint8_t getCurrentDisplayIndex() const override { + if ( uint8_t maxDis = getMaximumDisplays(); _displayIndex >= maxDis ) { + return maxDis - 1; + } return _displayIndex; } From 2f8e5ef55b61d497a170efe415326333049177bc Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Thu, 28 Mar 2024 17:42:06 +0330 Subject: [PATCH 49/55] handiling SDL_DISPLAYEVENT in a display is disconnected --- src/engine/localevent.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/engine/localevent.cpp b/src/engine/localevent.cpp index eb13d2e01b5..d59a6312671 100644 --- a/src/engine/localevent.cpp +++ b/src/engine/localevent.cpp @@ -48,6 +48,7 @@ #include "render_processor.h" #include "screen.h" #include "tools.h" +#include namespace { @@ -737,6 +738,7 @@ bool LocalEvent::HandleEvents( const bool sleepAfterEventProcessing, const bool _mouseCursorRenderArea = {}; fheroes2::Display & display = fheroes2::Display::instance(); + fheroes2::BaseRenderEngine & engine = fheroes2::engine(); if ( fheroes2::RenderProcessor::instance().isCyclingUpdateRequired() ) { // To maintain color cycling animation we need to render the whole frame with an updated palette. @@ -852,6 +854,27 @@ bool LocalEvent::HandleEvents( const bool sleepAfterEventProcessing, const bool // As of now we have no logic for this so we at least log this event. DEBUG_LOG( DBG_ENGINE, DBG_WARN, "OS indicates low memory. Release some resources." ) break; + case SDL_DISPLAYEVENT: + if ( event.display.event == SDL_DISPLAYEVENT_DISCONNECTED ) { + + DEBUG_LOG( DBG_ENGINE, DBG_INFO, "The display with id %d was disconnected " << event.display.display ); + engine.setDisplayIndex( engine.getCurrentDisplayIndex() ); + + fheroes2::Image temp; + assert( display.singleLayer() ); + temp._disableTransformLayer(); + fheroes2::Copy( display, temp ); + + const fheroes2::ResolutionInfo currentResolution{ display.width(), display.height(), display.screenSize().width, display.screenSize().height }; + + display.setResolution( currentResolution ); + fheroes2::Copy( temp, display ); + + // Save new index in conf as well + Settings & conf = Settings::Get(); + conf.Save( Settings::configFileName ); + } + break; default: // If this assertion blows up then we included an event type but we didn't add logic for it. assert( eventTypeStatus.count( event.type ) == 0 ); @@ -1526,7 +1549,7 @@ void LocalEvent::setEventProcessingStates() setEventProcessingState( SDL_APP_DIDENTERFOREGROUND, false ); // SDL_LOCALECHANGED is supported from SDL 2.0.14 // TODO: we don't process this event. Add the logic. - setEventProcessingState( SDL_DISPLAYEVENT, false ); + setEventProcessingState( SDL_DISPLAYEVENT, true ); setEventProcessingState( SDL_WINDOWEVENT, true ); // TODO: verify why disabled processing of this event. setEventProcessingState( SDL_SYSWMEVENT, false ); From 028e3b4b34a60326fac1ed9098a090c2839368f5 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Thu, 28 Mar 2024 17:44:40 +0330 Subject: [PATCH 50/55] fix format --- src/engine/localevent.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/engine/localevent.cpp b/src/engine/localevent.cpp index d59a6312671..fccce25318d 100644 --- a/src/engine/localevent.cpp +++ b/src/engine/localevent.cpp @@ -30,6 +30,8 @@ #include #include +#include + #include #include #include @@ -48,7 +50,6 @@ #include "render_processor.h" #include "screen.h" #include "tools.h" -#include namespace { @@ -856,7 +857,6 @@ bool LocalEvent::HandleEvents( const bool sleepAfterEventProcessing, const bool break; case SDL_DISPLAYEVENT: if ( event.display.event == SDL_DISPLAYEVENT_DISCONNECTED ) { - DEBUG_LOG( DBG_ENGINE, DBG_INFO, "The display with id %d was disconnected " << event.display.display ); engine.setDisplayIndex( engine.getCurrentDisplayIndex() ); From 0bc0b0fa06ceb0ef9fb54b1e830d2be7b7f92ff9 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Thu, 28 Mar 2024 17:47:07 +0330 Subject: [PATCH 51/55] fix header --- src/engine/localevent.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/engine/localevent.cpp b/src/engine/localevent.cpp index fccce25318d..8bd0ec981c2 100644 --- a/src/engine/localevent.cpp +++ b/src/engine/localevent.cpp @@ -30,8 +30,6 @@ #include #include -#include - #include #include #include @@ -49,6 +47,7 @@ #include "logging.h" #include "render_processor.h" #include "screen.h" +#include "settings.h" #include "tools.h" namespace From c2af17ed728a6da79ae0a31dbf2d69ac562e9aeb Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Thu, 28 Mar 2024 17:54:32 +0330 Subject: [PATCH 52/55] remove settings from localevent source --- src/engine/localevent.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/engine/localevent.cpp b/src/engine/localevent.cpp index 8bd0ec981c2..7fa5eda854b 100644 --- a/src/engine/localevent.cpp +++ b/src/engine/localevent.cpp @@ -47,7 +47,6 @@ #include "logging.h" #include "render_processor.h" #include "screen.h" -#include "settings.h" #include "tools.h" namespace @@ -868,10 +867,6 @@ bool LocalEvent::HandleEvents( const bool sleepAfterEventProcessing, const bool display.setResolution( currentResolution ); fheroes2::Copy( temp, display ); - - // Save new index in conf as well - Settings & conf = Settings::Get(); - conf.Save( Settings::configFileName ); } break; default: From 89b99007f3e8b6ac65aba0bb8550a9ae82fe28dc Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Thu, 28 Mar 2024 18:03:23 +0330 Subject: [PATCH 53/55] add Header asked by IWYU --- src/engine/localevent.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/engine/localevent.cpp b/src/engine/localevent.cpp index 7fa5eda854b..a6aff33df29 100644 --- a/src/engine/localevent.cpp +++ b/src/engine/localevent.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include From 593b967e74de598c4bd5af679e84414a50d55f56 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Thu, 28 Mar 2024 18:32:13 +0330 Subject: [PATCH 54/55] fix enum --- src/engine/localevent.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/localevent.cpp b/src/engine/localevent.cpp index a6aff33df29..b8a97627aeb 100644 --- a/src/engine/localevent.cpp +++ b/src/engine/localevent.cpp @@ -855,7 +855,7 @@ bool LocalEvent::HandleEvents( const bool sleepAfterEventProcessing, const bool DEBUG_LOG( DBG_ENGINE, DBG_WARN, "OS indicates low memory. Release some resources." ) break; case SDL_DISPLAYEVENT: - if ( event.display.event == SDL_DISPLAYEVENT_DISCONNECTED ) { + if ( event.display.event == SDL_DisplayEventID::SDL_DISPLAYEVENT_DISCONNECTED ) { DEBUG_LOG( DBG_ENGINE, DBG_INFO, "The display with id %d was disconnected " << event.display.display ); engine.setDisplayIndex( engine.getCurrentDisplayIndex() ); From 222d1ad4bafd68d64d188def25b1ba64c86337fc Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Thu, 28 Mar 2024 19:28:52 +0330 Subject: [PATCH 55/55] replacing enum SDL_DISPLAYEVENT_DISCONNECTED with it's value --- src/engine/localevent.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/localevent.cpp b/src/engine/localevent.cpp index b8a97627aeb..0be2f9752c6 100644 --- a/src/engine/localevent.cpp +++ b/src/engine/localevent.cpp @@ -855,7 +855,7 @@ bool LocalEvent::HandleEvents( const bool sleepAfterEventProcessing, const bool DEBUG_LOG( DBG_ENGINE, DBG_WARN, "OS indicates low memory. Release some resources." ) break; case SDL_DISPLAYEVENT: - if ( event.display.event == SDL_DisplayEventID::SDL_DISPLAYEVENT_DISCONNECTED ) { + if ( event.display.event == 3 ) { DEBUG_LOG( DBG_ENGINE, DBG_INFO, "The display with id %d was disconnected " << event.display.display ); engine.setDisplayIndex( engine.getCurrentDisplayIndex() );