Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multi-display device support #8072

Open
wants to merge 57 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
aacae0d
Upon file deletion scroll to previous file or 0 if first on the list
MaMadDl Nov 22, 2023
fddf90f
styling fix
MaMadDl Nov 23, 2023
622ccc3
_displayMonitor Property Decleration
MaMadDl Nov 23, 2023
086cbcb
adding _displayMonitor Property to BaseRenderEngine and Display Class
MaMadDl Nov 23, 2023
2c42c9c
passing Display Count to render Engine from Display
MaMadDl Nov 23, 2023
b9be3e0
- Changing GraphicsSetting Dialog to 6 Button ICN
MaMadDl Nov 23, 2023
1f49b72
Setting Display Before Create the Window either from setting or default
MaMadDl Nov 23, 2023
3651946
styling fix
MaMadDl Nov 23, 2023
0fcc4ea
more sudden style fix
MaMadDl Nov 23, 2023
64aa1cf
More Sudden styles fixes from Visual studio
MaMadDl Nov 23, 2023
e121a1d
Reordering for the Analyzers
MaMadDl Nov 23, 2023
d88c6fd
More Reordering For Analyzers
MaMadDl Nov 23, 2023
604f0df
Update src/engine/screen.h
MaMadDl Nov 23, 2023
04dc878
Update src/engine/screen.h
MaMadDl Nov 23, 2023
20f480e
Update screen.h
MaMadDl Nov 23, 2023
53b5b46
Update dialog_graphics_settings.cpp
MaMadDl Nov 24, 2023
2aa5eae
Resolving Some Reviews For PR #8072
MaMadDl Nov 25, 2023
6f62708
Adding InterfaceType to Graphic Settings
MaMadDl Dec 1, 2023
d1b65a2
rename _displayMonitor property to _displayId with it's getter and se…
MaMadDl Dec 1, 2023
5566d2d
remove inplace initilization
MaMadDl Dec 1, 2023
1fc9224
fix to style
MaMadDl Dec 1, 2023
a193e3e
Limiting Screen Switch Ability to windows only
MaMadDl Dec 7, 2023
8989928
Changing Mistaken Variable
MaMadDl Dec 7, 2023
714d867
Addressing Reviews
MaMadDl Dec 10, 2023
d805b6d
styling fix
MaMadDl Dec 10, 2023
adf13d6
Fix Safeguard
MaMadDl Dec 11, 2023
ff368c5
Style Fix
MaMadDl Dec 11, 2023
52f7a53
Remove settings.h
MaMadDl Dec 11, 2023
4444c85
Addressing Reviews
MaMadDl Dec 12, 2023
c2f1f5e
- Add function to change display in runtime
MaMadDl Dec 13, 2023
cec93b1
Changing dialog_graphics_settings to 5 item layout with both good and…
MaMadDl Dec 13, 2023
662c474
Adressing Reviews
MaMadDl Jan 13, 2024
7f36dd5
Removing display Instantiation
MaMadDl Jan 13, 2024
d19573b
Changing Required Headers Date to 2024
MaMadDl Jan 13, 2024
051f5e8
Addressing Reviews
MaMadDl Jan 13, 2024
76c9b98
- Changing displayId name to displayIndex
MaMadDl Jan 14, 2024
5865c24
- Changing Description
MaMadDl Jan 15, 2024
b1a9987
in Graphics Settings: Changing How Background of 2nd Row is created
MaMadDl Jan 15, 2024
0a70c34
style fix
MaMadDl Jan 15, 2024
3ce8998
Addressing Reviews
MaMadDl Jan 17, 2024
deed982
Addressing Reviews
MaMadDl Jan 19, 2024
d5cbd89
Update screen.cpp
ihhub Jan 20, 2024
6f11a10
Merge branch 'master' into pr/8072
ihhub Jan 20, 2024
70fd633
Merge branch 'multiMonitorSupport' of https://github.com/MaMadDl/fher…
ihhub Jan 20, 2024
7ff712c
Fix main menu not generating after the display change
MaMadDl Feb 6, 2024
0287e22
Checking for supported display
MaMadDl Feb 6, 2024
c2bc9d7
Fixing error for display index on startup
MaMadDl Mar 4, 2024
6c06be6
remove unused variable
MaMadDl Mar 4, 2024
3af1d73
Fix lambda to calculate on every function call instead of only once
MaMadDl Mar 4, 2024
e6e8050
return last available display in case cureent display is out of bound
MaMadDl Mar 28, 2024
2f8e5ef
handiling SDL_DISPLAYEVENT in a display is disconnected
MaMadDl Mar 28, 2024
028e3b4
fix format
MaMadDl Mar 28, 2024
0bc0b0f
fix header
MaMadDl Mar 28, 2024
c2af17e
remove settings from localevent source
MaMadDl Mar 28, 2024
89b9900
add Header asked by IWYU
MaMadDl Mar 28, 2024
593b967
fix enum
MaMadDl Mar 28, 2024
222d1ad
replacing enum SDL_DISPLAYEVENT_DISCONNECTED with it's value
MaMadDl Mar 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/engine/screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1071,8 +1071,10 @@ namespace
}

flags |= SDL_WINDOW_RESIZABLE;

_window = SDL_CreateWindow( _previousWindowTitle.data(), _prevWindowPos.x, _prevWindowPos.y, resolutionInfo.screenWidth, resolutionInfo.screenHeight, flags );
SDL_Rect monRect;
MaMadDl marked this conversation as resolved.
Show resolved Hide resolved
SDL_GetDisplayBounds( DisplayMonitor(), &monRect );
_window = SDL_CreateWindow( _previousWindowTitle.data(), monRect.x + _prevWindowPos.x, monRect.y + _prevWindowPos.y, resolutionInfo.screenWidth,
resolutionInfo.screenHeight, flags );
MaMadDl marked this conversation as resolved.
Show resolved Hide resolved
MaMadDl marked this conversation as resolved.
Show resolved Hide resolved
if ( _window == nullptr ) {
ERROR_LOG( "Failed to create an application window of " << resolutionInfo.screenWidth << " x " << resolutionInfo.screenHeight
<< " size. The error: " << SDL_GetError() )
Expand Down Expand Up @@ -1161,7 +1163,6 @@ namespace
SDL_Renderer * _renderer;
SDL_Texture * _texture;
int _driverIndex;

MaMadDl marked this conversation as resolved.
Show resolved Hide resolved
std::string _previousWindowTitle;
fheroes2::Point _prevWindowPos;
fheroes2::Size _currentScreenResolution;
Expand Down Expand Up @@ -1336,11 +1337,11 @@ namespace fheroes2
&& info.screenHeight == _screenSize.height ) // nothing to resize
return;

_engine->setDisplayMonitor( _displayMonitor );
const bool isFullScreen = _engine->isFullScreen();

// deallocate engine resources
_engine->clear();

MaMadDl marked this conversation as resolved.
Show resolved Hide resolved
_prevRoi = {};

// allocate engine resources
Expand Down
24 changes: 24 additions & 0 deletions src/engine/screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,21 @@ namespace fheroes2
return _nearestScaling;
}

int DisplayMonitor() const
MaMadDl marked this conversation as resolved.
Show resolved Hide resolved
{
return _displayMonitor;
}

void setDisplayMonitor( int monitor )
MaMadDl marked this conversation as resolved.
Show resolved Hide resolved
{
_displayMonitor = monitor;
}

protected:
BaseRenderEngine()
: _isFullScreen( false )
, _nearestScaling( false )

MaMadDl marked this conversation as resolved.
Show resolved Hide resolved
MaMadDl marked this conversation as resolved.
Show resolved Hide resolved
{
// Do nothing.
}
Expand Down Expand Up @@ -178,6 +189,8 @@ namespace fheroes2
private:
bool _isFullScreen;

int _displayMonitor{ 0 };

bool _nearestScaling;
MaMadDl marked this conversation as resolved.
Show resolved Hide resolved
};

Expand Down Expand Up @@ -210,6 +223,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 )
MaMadDl marked this conversation as resolved.
Show resolved Hide resolved
{
_displayMonitor = monitor;
}

int DisplayMonitor() const
{
return _displayMonitor;
}

void setResolution( ResolutionInfo info );

bool isDefaultSize() const
Expand Down Expand Up @@ -252,6 +275,7 @@ namespace fheroes2
PostRenderProcessing _postprocessing;

uint8_t * _renderSurface;
int _displayMonitor;

// Previous area drawn on the screen.
Rect _prevRoi;
Expand Down
40 changes: 35 additions & 5 deletions src/fheroes2/dialog/dialog_graphics_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <string>
#include <utility>

#include <SDL_video.h>
MaMadDl marked this conversation as resolved.
Show resolved Hide resolved

#include "agg_image.h"
#include "dialog_resolution.h"
#include "game_hotkeys.h"
Expand All @@ -49,17 +51,27 @@ 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 )
{
Expand Down Expand Up @@ -126,8 +138,11 @@ 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 );
Expand All @@ -138,19 +153,23 @@ 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 );

const fheroes2::Rect windowResolutionRoi( resolutionRoi + windowRoi.getPosition() );
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();
Expand Down Expand Up @@ -187,6 +206,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 );
Expand All @@ -197,6 +219,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 );
MaMadDl marked this conversation as resolved.
Show resolved Hide resolved
}
if ( le.MousePressRight( windowSystemInfoRoi ) ) {
fheroes2::showStandardTextMessage( _( "System Info" ), _( "Show extra information such as FPS and current time." ), 0 );
}
Expand Down Expand Up @@ -253,6 +278,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;
}
Expand Down
1 change: 1 addition & 0 deletions src/fheroes2/dialog/dialog_selectfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ namespace
listbox.updateScrollBarImage();

listbox.SetListContent( lists );
listbox.SetCurrent( std::max( listId - 1, 0 ) );
MaMadDl marked this conversation as resolved.
Show resolved Hide resolved
}

needRedraw = true;
Expand Down
4 changes: 3 additions & 1 deletion src/fheroes2/game/fheroes2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,12 @@ namespace
bestResolution = info;
}
}

MaMadDl marked this conversation as resolved.
Show resolved Hide resolved
// set display monitor to first monitor available
MaMadDl marked this conversation as resolved.
Show resolved Hide resolved
display.setDisplayMonitor( 0 );
MaMadDl marked this conversation as resolved.
Show resolved Hide resolved
display.setResolution( bestResolution );
}
else {
display.setDisplayMonitor( conf.DisplayMonitor() );
display.setResolution( conf.currentResolutionInfo() );
}

Expand Down
13 changes: 13 additions & 0 deletions src/fheroes2/system/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
MaMadDl marked this conversation as resolved.
Show resolved Hide resolved
os << "monitor = " << DisplayMonitor() << std::endl;

return os.str();
}

Expand Down Expand Up @@ -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 );
Expand Down
9 changes: 8 additions & 1 deletion src/fheroes2/system/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class Settings
void setHideInterface( const bool enable );
void setEvilInterface( const bool enable );
void setScreenScalingTypeNearest( const bool enable );

MaMadDl marked this conversation as resolved.
Show resolved Hide resolved
void setDisplayMonitor( int monitor );
void SetSoundVolume( int v );
void SetMusicVolume( int v );

Expand All @@ -260,6 +260,11 @@ class Settings

bool setGameLanguage( const std::string & language );

int DisplayMonitor() const
{
return _displayMonitor;
}

int SoundVolume() const
{
return sound_volume;
Expand Down Expand Up @@ -443,6 +448,8 @@ class Settings
BitModes _optGlobal;

fheroes2::ResolutionInfo _resolutionInfo;
int _displayMonitor;

MaMadDl marked this conversation as resolved.
Show resolved Hide resolved
int game_difficulty;

std::string path_program;
Expand Down