MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / setDisplayMode

Function setDisplayMode

src/OpenLoco/src/Ui.cpp:575–706  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

573 }
574
575 bool setDisplayMode(Config::ScreenMode mode, Config::Resolution newResolution)
576 {
577 _isChangingDisplayMode = true;
578
579 // *HACK* Set window to non fullscreen before switching resolution.
580 // This fixes issues with high dpi and Windows scaling affecting the GUI size.
581 if (!SDL_SetWindowFullscreen(_window, false))
582 {
583 Logging::error("SDL_SetWindowFullscreen(false) failed: {}", SDL_GetError());
584 _isChangingDisplayMode = false;
585 return false;
586 }
587 if (!SDL_SyncWindow(_window))
588 {
589 Logging::error("SDL_SyncWindow failed after leaving fullscreen: {}", SDL_GetError());
590 _isChangingDisplayMode = false;
591 return false;
592 }
593
594 if (!SDL_RestoreWindow(_window))
595 {
596 Logging::error("SDL_RestoreWindow failed: {}", SDL_GetError());
597 }
598
599 if (!SDL_SetWindowBordered(_window, true))
600 {
601 Logging::error("SDL_SetWindowBordered(true) failed: {}", SDL_GetError());
602 _isChangingDisplayMode = false;
603 return false;
604 }
605 if (!SDL_SyncWindow(_window))
606 {
607 Logging::error("SDL_SyncWindow failed after restoring window chrome: {}", SDL_GetError());
608 _isChangingDisplayMode = false;
609 return false;
610 }
611
612 auto& config = Config::get();
613 if (config.display.mode == Config::ScreenMode::window)
614 {
615 int32_t currentWidth = 0;
616 int32_t currentHeight = 0;
617 SDL_GetWindowSize(_window, &currentWidth, &currentHeight);
618 if (currentWidth > 0 && currentHeight > 0)
619 {
620 _lastWindowedResolution = { currentWidth, currentHeight };
621 }
622 }
623
624 // Set the new dimensions of the screen.
625 if (mode == Config::ScreenMode::window)
626 {
627 if (_lastWindowedResolution.isPositive())
628 {
629 newResolution = _lastWindowedResolution;
630 }
631
632 if (!SDL_SetWindowSize(_window, newResolution.width, newResolution.height))

Callers 5

createWindowFunction · 0.85
toggleFullscreenDesktopFunction · 0.85
startFunction · 0.85
screenModeDropdownFunction · 0.85
resolutionDropdownFunction · 0.85

Calls 8

errorFunction · 0.85
centerWindowOnDisplayFunction · 0.85
writeFunction · 0.85
triggerResizeFunction · 0.85
invalidateScreenFunction · 0.85
isPositiveMethod · 0.80
getFunction · 0.70

Tested by

no test coverage detected