@@ -132,21 +132,33 @@ bool Renderer::initWindowAndRenderer() {
132132 return false ;
133133 }
134134 SDL_SetWindowMinimumSize (window, 200 , 100 );
135- initFrameBuffer (width, height);
136135
137136 if (!window) {
138137 printf (" Could not initialise SDL opengl\n Error: %s\n " , SDL_GetError ());
139138 SDL_Quit ();
140139 return false ;
141140 }
142- const float x = atof (persistedSettings.getValue (" Renderer" , " windowX" , " -1.0f" )),
143- y = atof (persistedSettings.getValue (" Renderer" , " windowY" , " -1.0f" ));
144- if (x == -1 .0f || y == -1 .0f ) {
145- SDL_SetWindowPosition (window, SDL_WINDOWPOS_CENTERED , SDL_WINDOWPOS_CENTERED );
141+ const char * modeStr = persistedSettings.getValue (" Renderer" , " fullscreen" , " WINDOWED" );
142+ if (strcmp (modeStr, " BORDERLESS_FULLSCREEN" ) == 0 ) {
143+ SDL_SetWindowFullscreen (window, SDL_WINDOW_FULLSCREEN_DESKTOP );
144+ SDL_GetWindowSize (window, &width, &height);
145+ SDL_SetWindowPosition (window, 0 , 0 );
146+ } else if (strcmp (modeStr, " MAXIMIZED" ) == 0 ) {
147+ SDL_MaximizeWindow (window);
148+ SDL_GetWindowSize (window, &width, &height);
149+ SDL_SetWindowPosition (window, 0 , 0 );
146150 } else {
147- SDL_SetWindowPosition (window, x, y);
151+ const float x = atof (persistedSettings.getValue (" Renderer" , " windowX" , " -1.0f" )),
152+ y = atof (persistedSettings.getValue (" Renderer" , " windowY" , " -1.0f" ));
153+ if (x == -1 .0f || y == -1 .0f ) {
154+ SDL_SetWindowPosition (window, SDL_WINDOWPOS_CENTERED , SDL_WINDOWPOS_CENTERED );
155+ } else {
156+ SDL_SetWindowPosition (window, static_cast <int >(x), static_cast <int >(y));
157+ }
148158 }
149- const std::string navKitVersion = NavKit_VERSION_MAJOR
159+ initFrameBuffer (width, height);
160+
161+ constexpr std::string_view navKitVersion = NavKit_VERSION_MAJOR
150162 " ."
151163 NavKit_VERSION_MINOR
152164 " ."
@@ -207,6 +219,9 @@ void Renderer::loadSettings() {
207219
208220void Renderer::handleMoved () {
209221 updateFrameRate ();
222+ if (const Uint32 windowFlags = SDL_GetWindowFlags (window); windowFlags & SDL_WINDOW_FULLSCREEN_DESKTOP || windowFlags & SDL_WINDOW_MAXIMIZED ) {
223+ return ;
224+ }
210225 PersistedSettings& persistedSettings = PersistedSettings::getInstance ();
211226 int x;
212227 int y;
@@ -217,6 +232,52 @@ void Renderer::handleMoved() {
217232 persistedSettings.save ();
218233}
219234
235+ void Renderer::handleFullscreen (const FullscreenMode mode) const {
236+ if (!window) {
237+ return ;
238+ }
239+ PersistedSettings& persistedSettings = PersistedSettings::getInstance ();
240+ FullscreenMode currentMode = WINDOWED ;
241+ if (const char * modeStr = persistedSettings.getValue (" Renderer" , " fullscreen" , " WINDOWED" ); strcmp (modeStr, " BORDERLESS_FULLSCREEN" ) == 0 ) {
242+ currentMode = BORDERLESS_FULLSCREEN ;
243+ } else if (strcmp (modeStr, " MAXIMIZED" ) == 0 ) {
244+ currentMode = MAXIMIZED ;
245+ }
246+ if (currentMode == mode) {
247+ return ;
248+ }
249+
250+ std::string modeStr = " WINDOWED" ;
251+ switch (mode) {
252+ case BORDERLESS_FULLSCREEN :
253+ SDL_SetWindowPosition (window, 0 , 0 );
254+ SDL_SetWindowFullscreen (window, SDL_WINDOW_FULLSCREEN_DESKTOP );
255+ modeStr = " BORDERLESS_FULLSCREEN" ;
256+ break ;
257+ case MAXIMIZED :
258+ SDL_SetWindowFullscreen (window, 0 );
259+ SDL_MaximizeWindow (window);
260+ modeStr = " MAXIMIZED" ;
261+ break ;
262+ case WINDOWED :
263+ default :
264+ const float x = atof (persistedSettings.getValue (" Renderer" , " windowX" , " -1.0f" )),
265+ y = atof (persistedSettings.getValue (" Renderer" , " windowY" , " -1.0f" ));
266+ if (x == -1 .0f || y == -1 .0f ) {
267+ SDL_SetWindowPosition (window, SDL_WINDOWPOS_CENTERED , SDL_WINDOWPOS_CENTERED );
268+ } else {
269+ SDL_SetWindowPosition (window, static_cast <int >(x), static_cast <int >(y));
270+ }
271+ SDL_SetWindowFullscreen (window, 0 );
272+ SDL_RestoreWindow (window);
273+ break ;
274+ }
275+
276+ Logger::log (NK_INFO , (std::string (" Setting fullscreen mode to: " ) + modeStr).c_str ());
277+ persistedSettings.setValue (" Renderer" , " fullscreen" , modeStr);
278+ persistedSettings.save ();
279+ }
280+
220281void Renderer::initShaders () {
221282 shader = Shader ();
222283 shader.loadShaders (" vertex.glsl" , " fragment.glsl" );
0 commit comments