Skip to content

Commit 74f9cda

Browse files
committed
Add constant for minimum window size
1 parent cf50229 commit 74f9cda

5 files changed

Lines changed: 18 additions & 13 deletions

File tree

libs/driver/include/driver/VideoMode.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ struct VideoMode
1010
unsigned short width;
1111
unsigned short height;
1212

13-
VideoMode() : width(0), height(0) {}
14-
VideoMode(unsigned short width, unsigned short height) : width(width), height(height) {}
15-
bool operator==(const VideoMode& o) const { return (width == o.width && height == o.height); }
16-
bool operator!=(const VideoMode& o) const { return !(*this == o); }
13+
constexpr VideoMode() : width(0), height(0) {}
14+
constexpr VideoMode(unsigned short width, unsigned short height) : width(width), height(height) {}
15+
constexpr bool operator==(const VideoMode& o) const { return (width == o.width && height == o.height); }
16+
constexpr bool operator!=(const VideoMode& o) const { return !(*this == o); }
1717
};
1818

1919
// Enum like type with extra flag

libs/s25main/Settings.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,14 @@ void Settings::LoadDefaults()
9696
// {
9797
if(VIDEODRIVER.IsLoaded())
9898
{
99-
video.fullscreenSize = VIDEODRIVER.GetWindowSize();
100-
video.windowedSize =
101-
(VIDEODRIVER.GetDisplayMode() == DisplayMode::Fullscreen) ? video.fullscreenSize : VideoMode(800, 600);
99+
video.fullscreenSize = (VIDEODRIVER.GetDisplayMode() == DisplayMode::Fullscreen) ? VIDEODRIVER.GetWindowSize() :
100+
VIDEODRIVER.MinWindowSize;
101+
video.windowedSize = (VIDEODRIVER.GetDisplayMode() == DisplayMode::Windowed) ? VIDEODRIVER.GetWindowSize() :
102+
VIDEODRIVER.MinWindowSize;
102103
video.displayMode = VIDEODRIVER.GetDisplayMode();
103104
} else
104105
{
105-
video.windowedSize = video.fullscreenSize = VideoMode(800, 600);
106+
video.windowedSize = video.fullscreenSize = VIDEODRIVER.MinWindowSize;
106107
video.displayMode = DisplayMode::Windowed;
107108
}
108109
video.framerate = 0; // Special value for HW vsync

libs/s25main/WindowManager.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,8 @@ void WindowManager::Msg_ScreenResize(const Extent& newSize)
412412
if(newSize == curRenderSize)
413413
return;
414414

415-
ScreenResizeEvent sr(curRenderSize, elMax(Extent(800, 600), newSize));
415+
constexpr Extent minSize(VideoDriverWrapper::MinWindowSize.width, VideoDriverWrapper::MinWindowSize.height);
416+
ScreenResizeEvent sr(curRenderSize, elMax(minSize, newSize));
416417
curRenderSize = sr.newSize;
417418

418419
// Don't change fullscreen size (only in menu)

libs/s25main/drivers/VideoDriverWrapper.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,8 @@ std::vector<VideoMode> VideoDriverWrapper::ListVideoModes() const
435435

436436
auto videoModes = videodriver->ListVideoModes();
437437
// Remove everything below 800x600
438-
helpers::erase_if(videoModes, [](const auto& m) { return m.width < 800 && m.height < 600; });
438+
helpers::erase_if(videoModes,
439+
[](const auto& m) { return m.width < MinWindowSize.width && m.height < MinWindowSize.height; });
439440
return videoModes;
440441
}
441442

@@ -465,10 +466,10 @@ void* VideoDriverWrapper::GetMapPointer() const
465466

466467
VideoMode VideoDriverWrapper::GetWindowSize() const
467468
{
468-
// Always return at least 800x600 even if real window is smaller
469+
// Always return at least MinWindowSize even if real window is smaller
469470
VideoMode windowSize = videodriver->GetWindowSize();
470-
windowSize.width = std::max<unsigned>(800, windowSize.width);
471-
windowSize.height = std::max<unsigned>(600, windowSize.height);
471+
windowSize.width = std::max(MinWindowSize.width, windowSize.width);
472+
windowSize.height = std::max(MinWindowSize.height, windowSize.height);
472473
return windowSize;
473474
}
474475

libs/s25main/drivers/VideoDriverWrapper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ class VideoDriverWrapper : public Singleton<VideoDriverWrapper, SingletonPolicie
111111
/// Calculate the size of the texture which is optimal for the driver and at least minSize
112112
Extent calcPreferredTextureSize(const Extent& minSize) const;
113113

114+
static constexpr VideoMode MinWindowSize{800, 600};
115+
114116
private:
115117
bool Initialize();
116118
bool setHwVSync(bool enabled);

0 commit comments

Comments
 (0)