Skip to content

Commit 04168d0

Browse files
Replace bool fullscreen parameter with bitset enum
1 parent 6d9ca64 commit 04168d0

File tree

21 files changed

+118
-84
lines changed

21 files changed

+118
-84
lines changed

extras/videoDrivers/SDL2/VideoSDL2.cpp

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void VideoSDL2::UpdateCurrentSizes()
103103
SetNewSize(VideoMode(w, h), Extent(w2, h2));
104104
}
105105

106-
bool VideoSDL2::CreateScreen(const std::string& title, const VideoMode& size, bool fullscreen)
106+
bool VideoSDL2::CreateScreen(const std::string& title, const VideoMode& size, DisplayMode displayMode)
107107
{
108108
if(!initialized)
109109
return false;
@@ -125,18 +125,19 @@ bool VideoSDL2::CreateScreen(const std::string& title, const VideoMode& size, bo
125125
CHECK_SDL(SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8));
126126
CHECK_SDL(SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1));
127127

128-
int wndPos = SDL_WINDOWPOS_CENTERED;
129-
128+
const int wndPos = SDL_WINDOWPOS_CENTERED;
129+
const auto fullscreen = bitset::isSet(displayMode, DisplayMode::Fullscreen);
130130
const auto requestedSize = fullscreen ? FindClosestVideoMode(size) : size;
131-
131+
const unsigned commonFlags = SDL_WINDOW_OPENGL;
132+
const unsigned fullscreenFlag = (fullscreen ? SDL_WINDOW_FULLSCREEN : 0);
132133
window = SDL_CreateWindow(title.c_str(), wndPos, wndPos, requestedSize.width, requestedSize.height,
133-
SDL_WINDOW_OPENGL | (fullscreen ? SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE));
134+
commonFlags | fullscreenFlag);
134135

135136
// Fallback to non-fullscreen
136137
if(!window && fullscreen)
137138
{
138-
window = SDL_CreateWindow(title.c_str(), wndPos, wndPos, requestedSize.width, requestedSize.height,
139-
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
139+
window =
140+
SDL_CreateWindow(title.c_str(), wndPos, wndPos, requestedSize.width, requestedSize.height, commonFlags);
140141
}
141142

142143
if(!window)
@@ -145,10 +146,11 @@ bool VideoSDL2::CreateScreen(const std::string& title, const VideoMode& size, bo
145146
return false;
146147
}
147148

148-
isFullscreen_ = (SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN) != 0;
149+
displayMode_ =
150+
bitset::set(displayMode_, DisplayMode::Fullscreen, (SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN) != 0);
149151
UpdateCurrentSizes();
150152

151-
if(!isFullscreen_)
153+
if(!bitset::isSet(displayMode_, DisplayMode::Fullscreen))
152154
MoveWindowToCenter();
153155

154156
SDL_Surface* iconSurf =
@@ -173,16 +175,19 @@ bool VideoSDL2::CreateScreen(const std::string& title, const VideoMode& size, bo
173175
return true;
174176
}
175177

176-
bool VideoSDL2::ResizeScreen(const VideoMode& newSize, bool fullscreen)
178+
bool VideoSDL2::ResizeScreen(const VideoMode& newSize, DisplayMode displayMode)
177179
{
178180
if(!initialized)
179181
return false;
180182

181-
if(isFullscreen_ != fullscreen)
183+
const auto newFullscreen = bitset::isSet(displayMode, DisplayMode::Fullscreen);
184+
auto fullscreen = bitset::isSet(displayMode_, DisplayMode::Fullscreen);
185+
if(fullscreen != newFullscreen)
182186
{
183-
SDL_SetWindowFullscreen(window, fullscreen ? SDL_WINDOW_FULLSCREEN : 0);
184-
isFullscreen_ = (SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN) != 0;
185-
if(!isFullscreen_)
187+
SDL_SetWindowFullscreen(window, newFullscreen ? SDL_WINDOW_FULLSCREEN : 0);
188+
fullscreen = (SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN) != 0;
189+
displayMode_ = bitset::set(displayMode_, DisplayMode::Fullscreen, fullscreen);
190+
if(!fullscreen)
186191
{
187192
#if SDL_VERSION_ATLEAST(2, 0, 5)
188193
SDL_SetWindowResizable(window, SDL_TRUE);
@@ -193,7 +198,7 @@ bool VideoSDL2::ResizeScreen(const VideoMode& newSize, bool fullscreen)
193198

194199
if(newSize != GetWindowSize())
195200
{
196-
if(isFullscreen_)
201+
if(fullscreen)
197202
{
198203
auto const targetMode = FindClosestVideoMode(newSize);
199204
SDL_DisplayMode target;
@@ -267,7 +272,8 @@ bool VideoSDL2::MessageLoop()
267272
{
268273
case SDL_WINDOWEVENT_RESIZED:
269274
{
270-
isFullscreen_ = (SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN) != 0;
275+
displayMode_ = bitset::set(displayMode_, DisplayMode::Fullscreen,
276+
(SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN) != 0);
271277
VideoMode newSize(ev.window.data1, ev.window.data2);
272278
if(newSize != GetWindowSize())
273279
{

extras/videoDrivers/SDL2/VideoSDL2.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class VideoSDL2 final : public VideoDriver
2424

2525
bool Initialize() override;
2626

27-
bool CreateScreen(const std::string& title, const VideoMode& size, bool fullscreen) override;
28-
bool ResizeScreen(const VideoMode& newSize, bool fullscreen) override;
27+
bool CreateScreen(const std::string& title, const VideoMode& size, DisplayMode displayMode) override;
28+
bool ResizeScreen(const VideoMode& newSize, DisplayMode displayMode) override;
2929

3030
void DestroyScreen() override;
3131

extras/videoDrivers/WinAPI/WinAPI.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,18 @@ void VideoWinAPI::CleanUp()
138138
* @bug Hardwarecursor ist bei Fenstermodus sichtbar,
139139
* Cursor deaktivieren ist fehlerhaft
140140
*/
141-
bool VideoWinAPI::CreateScreen(const std::string& title, const VideoMode& newSize, bool fullscreen)
141+
bool VideoWinAPI::CreateScreen(const std::string& title, const VideoMode& newSize, DisplayMode displayMode)
142142
{
143143
if(!initialized)
144144
return false;
145145

146+
const auto fullscreen = bitset::isSet(displayMode, DisplayMode::Fullscreen);
146147
if(!RegisterAndCreateWindow(title, newSize, fullscreen))
147148
return false;
148149

149150
if(fullscreen && !MakeFullscreen(GetWindowSize()))
150151
return false;
151-
isFullscreen_ = fullscreen;
152+
displayMode_ = bitset::set(displayMode_, DisplayMode::Fullscreen);
152153

153154
if(!InitOGL())
154155
return false;
@@ -174,34 +175,37 @@ bool VideoWinAPI::CreateScreen(const std::string& title, const VideoMode& newSiz
174175
*
175176
* @todo Vollbildmodus ggf. wechseln
176177
*/
177-
bool VideoWinAPI::ResizeScreen(const VideoMode& newSize, bool fullscreen)
178+
bool VideoWinAPI::ResizeScreen(const VideoMode& newSize, DisplayMode displayMode)
178179
{
179180
if(!initialized || !isWindowResizable)
180181
return false;
181182

182-
if(isFullscreen_ == fullscreen && newSize == GetWindowSize())
183+
const auto newFullscreen = bitset::isSet(displayMode, DisplayMode::Fullscreen);
184+
auto fullscreen = bitset::isSet(displayMode_, DisplayMode::Fullscreen);
185+
if(fullscreen == newFullscreen && newSize == GetWindowSize())
183186
return true;
184187

185188
ShowWindow(screen, SW_HIDE);
186189

187-
VideoMode windowSize = fullscreen ? FindClosestVideoMode(newSize) : newSize;
190+
VideoMode windowSize = newFullscreen ? FindClosestVideoMode(newSize) : newSize;
188191
// Try to switch full screen first
189-
if(isFullscreen_ && !fullscreen)
192+
if(fullscreen && !newFullscreen)
190193
{
191194
if(ChangeDisplaySettings(nullptr, 0) != DISP_CHANGE_SUCCESSFUL)
192195
return false;
193-
} else if(isFullscreen_ || fullscreen)
196+
} else if(fullscreen || newFullscreen)
194197
{
195198
if(!MakeFullscreen(windowSize))
196199
return false;
197200
}
201+
displayMode_ = bitset::set(displayMode_, DisplayMode::Fullscreen, newFullscreen);
198202

199203
// Fensterstyle ggf. ändern
200-
std::pair<DWORD, DWORD> style = GetStyleFlags(isFullscreen_);
204+
std::pair<DWORD, DWORD> style = GetStyleFlags(newFullscreen);
201205
SetWindowLongPtr(screen, GWL_STYLE, style.first);
202206
SetWindowLongPtr(screen, GWL_EXSTYLE, style.second);
203207

204-
RECT wRect = CalculateWindowRect(isFullscreen_, windowSize);
208+
RECT wRect = CalculateWindowRect(newFullscreen, windowSize);
205209

206210
// Fenstergröße ändern
207211
UINT flags = SWP_SHOWWINDOW | SWP_DRAWFRAME | SWP_FRAMECHANGED;
@@ -405,7 +409,7 @@ void VideoWinAPI::DestroyScreen()
405409

406410
UnregisterClassW(windowClassName.c_str(), GetModuleHandle(nullptr));
407411

408-
isFullscreen_ = false;
412+
displayMode_ = bitset::clear(displayMode_, DisplayMode::Fullscreen);
409413
}
410414

411415
/**

extras/videoDrivers/WinAPI/WinAPI.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ class VideoWinAPI final : public VideoDriver
3030
bool Initialize() override;
3131

3232
/// Erstellt das Fenster mit entsprechenden Werten.
33-
bool CreateScreen(const std::string& title, const VideoMode& newSize, bool fullscreen) override;
33+
bool CreateScreen(const std::string& title, const VideoMode& newSize, DisplayMode displayMode) override;
3434

3535
/// Erstellt oder verändert das Fenster mit entsprechenden Werten.
36-
bool ResizeScreen(const VideoMode& newSize, bool fullscreen) override;
36+
bool ResizeScreen(const VideoMode& newSize, DisplayMode displayMode) override;
3737

3838
/// Schliesst das Fenster.
3939
void DestroyScreen() override;

libs/driver/include/driver/VideoDriver.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class VideoDriver : public IVideoDriver
2929

3030
VideoMode GetWindowSize() const override final { return windowSize_; }
3131
Extent GetRenderSize() const override final { return renderSize_; }
32-
bool IsFullscreen() const override final { return isFullscreen_; }
32+
DisplayMode GetDisplayMode() const override final { return displayMode_; }
3333

3434
/// prüft auf Initialisierung.
3535
bool IsInitialized() const override final { return initialized; }
@@ -43,7 +43,7 @@ class VideoDriver : public IVideoDriver
4343
bool initialized; /// Initialisierungsstatus.
4444
MouseCoords mouse_xy; /// Status der Maus.
4545
std::array<bool, 512> keyboard; /// Status der Tastatur;
46-
bool isFullscreen_; /// Vollbild an/aus?
46+
DisplayMode displayMode_; /// Fullscreen on/off?
4747
private:
4848
// cached as possibly used often
4949
VideoMode windowSize_;

libs/driver/include/driver/VideoInterface.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,20 @@
88
#include "Point.h"
99
#include "VideoMode.h"
1010
#include "exportImport.h"
11+
#include "s25util/enumUtils.h"
1112
#include <string>
1213
#include <vector>
1314

1415
/// Function type for loading OpenGL methods
1516
using OpenGL_Loader_Proc = void* (*)(const char*);
1617

18+
enum class DisplayMode : unsigned
19+
{
20+
None,
21+
Fullscreen = 1 << 0
22+
};
23+
MAKE_BITSET_STRONG(DisplayMode);
24+
1725
class BOOST_SYMBOL_VISIBLE IVideoDriver
1826
{
1927
public:
@@ -25,9 +33,9 @@ class BOOST_SYMBOL_VISIBLE IVideoDriver
2533
virtual bool Initialize() = 0;
2634

2735
/// Erstellt das Fenster mit entsprechenden Werten.
28-
virtual bool CreateScreen(const std::string& title, const VideoMode& newSize, bool fullscreen) = 0;
36+
virtual bool CreateScreen(const std::string& title, const VideoMode& newSize, DisplayMode displayMode) = 0;
2937

30-
virtual bool ResizeScreen(const VideoMode& newSize, bool fullscreen) = 0;
38+
virtual bool ResizeScreen(const VideoMode& newSize, DisplayMode displayMode) = 0;
3139

3240
/// Schliesst das Fenster.
3341
virtual void DestroyScreen() = 0;
@@ -61,7 +69,7 @@ class BOOST_SYMBOL_VISIBLE IVideoDriver
6169
virtual VideoMode GetWindowSize() const = 0;
6270
/// Get the size of the render region in pixels
6371
virtual Extent GetRenderSize() const = 0;
64-
virtual bool IsFullscreen() const = 0;
72+
virtual DisplayMode GetDisplayMode() const = 0;
6573

6674
/// Get state of the modifier keys
6775
virtual KeyEvent GetModKeyState() const = 0;

libs/driver/src/VideoDriver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ IVideoDriver::~IVideoDriver() = default;
1717
* @param[in] CallBack DriverCallback für Rückmeldungen.
1818
*/
1919
VideoDriver::VideoDriver(VideoDriverLoaderInterface* CallBack)
20-
: CallBack(CallBack), initialized(false), isFullscreen_(false), renderSize_(0, 0)
20+
: CallBack(CallBack), initialized(false), displayMode_(DisplayMode::None), renderSize_(0, 0)
2121
{
2222
std::fill(keyboard.begin(), keyboard.end(), false);
2323
}

libs/s25main/GameManager.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ bool GameManager::Start()
4848
}
4949

5050
// Fenster erstellen
51-
const auto screenSize =
52-
settings_.video.fullscreen ? settings_.video.fullscreenSize : settings_.video.windowedSize; //-V807
53-
if(!videoDriver_.CreateScreen(screenSize, settings_.video.fullscreen))
51+
const auto screenSize = bitset::isSet(settings_.video.displayMode, DisplayMode::Fullscreen) ?
52+
settings_.video.fullscreenSize :
53+
settings_.video.windowedSize; //-V807
54+
if(!videoDriver_.CreateScreen(screenSize, settings_.video.displayMode))
5455
return false;
5556
videoDriver_.setTargetFramerate(settings_.video.framerate);
5657
videoDriver_.SetMouseWarping(settings_.global.smartCursor);

libs/s25main/Settings.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ void Settings::LoadDefaults()
8484
{
8585
video.fullscreenSize = VIDEODRIVER.GetWindowSize();
8686
video.windowedSize = VIDEODRIVER.IsFullscreen() ? VideoMode(800, 600) : video.fullscreenSize;
87-
video.fullscreen = VIDEODRIVER.IsFullscreen();
87+
video.displayMode = VIDEODRIVER.GetDisplayMode();
8888
} else
8989
{
9090
video.windowedSize = video.fullscreenSize = VideoMode(800, 600);
91-
video.fullscreen = false;
91+
video.displayMode = DisplayMode::None;
9292
}
9393
video.framerate = 0; // Special value for HW vsync
9494
video.vbo = true;
@@ -223,7 +223,8 @@ void Settings::Load()
223223
video.windowedSize.height = iniVideo->getIntValue("windowed_height");
224224
video.fullscreenSize.width = iniVideo->getIntValue("fullscreen_width");
225225
video.fullscreenSize.height = iniVideo->getIntValue("fullscreen_height");
226-
video.fullscreen = iniVideo->getBoolValue("fullscreen");
226+
video.displayMode =
227+
bitset::set(video.displayMode, DisplayMode::Fullscreen, iniVideo->getBoolValue("fullscreen"));
227228
video.framerate = iniVideo->getValue("framerate", 0);
228229
video.vbo = iniVideo->getBoolValue("vbo");
229230
video.shared_textures = iniVideo->getBoolValue("shared_textures");
@@ -405,7 +406,7 @@ void Settings::Save()
405406
iniVideo->setValue("fullscreen_height", video.fullscreenSize.height);
406407
iniVideo->setValue("windowed_width", video.windowedSize.width);
407408
iniVideo->setValue("windowed_height", video.windowedSize.height);
408-
iniVideo->setValue("fullscreen", video.fullscreen);
409+
iniVideo->setValue("fullscreen", bitset::isSet(video.displayMode, DisplayMode::Fullscreen));
409410
iniVideo->setValue("framerate", video.framerate);
410411
iniVideo->setValue("vbo", video.vbo);
411412
iniVideo->setValue("shared_textures", video.shared_textures);

libs/s25main/Settings.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#pragma once
66

77
#include "DrawPoint.h"
8+
#include "driver/VideoInterface.h"
89
#include "driver/VideoMode.h"
910
#include "s25util/ProxySettings.h"
1011
#include "s25util/Singleton.h"
@@ -59,7 +60,7 @@ class Settings : public Singleton<Settings, SingletonPolicies::WithLongevity>
5960
{
6061
VideoMode fullscreenSize, windowedSize;
6162
signed short framerate; // <0 for unlimited, 0 for HW Vsync
62-
bool fullscreen;
63+
DisplayMode displayMode;
6364
bool vbo;
6465
bool shared_textures;
6566
} video;

0 commit comments

Comments
 (0)