From f616cfc78632fde437cfe15c7066bc8f31370d87 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 29 Feb 2024 00:43:41 +0100 Subject: Extracted window states out of GameWinDX9 --- StarsEx/GameWinDX9.cpp | 33 +++++++++++++++++---------------- StarsEx/GameWinDX9.h | 4 +--- StarsEx/WndProc.cpp | 34 ++++++++++++++++++---------------- 3 files changed, 36 insertions(+), 35 deletions(-) (limited to 'StarsEx') diff --git a/StarsEx/GameWinDX9.cpp b/StarsEx/GameWinDX9.cpp index d49dfdb..78bdefe 100644 --- a/StarsEx/GameWinDX9.cpp +++ b/StarsEx/GameWinDX9.cpp @@ -45,11 +45,8 @@ GameWinDX9::GameWinDX9() : video_settings {nullptr}, soundcard {nullptr}, screen {nullptr}, - is_windowed {false}, is_active {false}, is_device_lost {false}, - is_minimized {false}, - is_maximized {false}, ignore_size_change {false}, is_device_initialized {false}, is_device_restored {false} @@ -283,7 +280,6 @@ GameWinDX9::InitVideo() // save a copy of the device-specific video settings: else if (video->GetVideoSettings()) { *video_settings = *video->GetVideoSettings(); - is_windowed = video_settings->IsWindowed(); } } @@ -319,7 +315,6 @@ GameWinDX9::ResetVideo() // save a copy of the device-specific video settings: if (video->GetVideoSettings()) { *video_settings = *video->GetVideoSettings(); - is_windowed = video_settings->IsWindowed(); } Color::UseVideo(video); @@ -349,7 +344,7 @@ bool GameWinDX9::ResizeVideo() { if (!video || !video_settings) return false; - if (!is_windowed) return false; + if (!IsWindowed()) return false; if (ignore_size_change) return true; HRESULT hr = S_OK; @@ -386,7 +381,6 @@ GameWinDX9::ResizeVideo() // save a copy of the device-specific video settings: if (video->GetVideoSettings()) { *video_settings = *video->GetVideoSettings(); - is_windowed = video_settings->IsWindowed(); } screen->Resize(video_settings->window_width, video_settings->window_height); @@ -405,8 +399,7 @@ GameWinDX9::ToggleFullscreen() ignore_size_change = true; // Toggle the windowed state - is_windowed = !is_windowed; - video_settings->is_windowed = is_windowed; + video_settings->is_windowed = !video_settings->is_windowed; // Prepare window for windowed/fullscreen change AdjustWindowForChange(); @@ -416,10 +409,9 @@ GameWinDX9::ToggleFullscreen() // reset failed, try to restore... ignore_size_change = false; - if (!is_windowed) { + if (!IsWindowed()) { // Restore window type to windowed mode - is_windowed = !is_windowed; - video_settings->is_windowed = is_windowed; + video_settings->is_windowed = !video_settings->is_windowed; AdjustWindowForChange(); @@ -432,7 +424,7 @@ GameWinDX9::ToggleFullscreen() SWP_SHOWWINDOW); } - ::Print("Unable to toggle %s fullscreen mode.\n", is_windowed ? "into" : "out of"); + ::Print("Unable to toggle %s fullscreen mode.\n", IsWindowed() ? "into" : "out of"); } else { @@ -447,7 +439,7 @@ GameWinDX9::ToggleFullscreen() // changed to 1024x768, because windows cannot be larger than the // desktop. - if (is_windowed) { + if (IsWindowed()) { SetWindowPos(hwnd, HWND_NOTOPMOST, bounds_rect.left, @@ -460,7 +452,7 @@ GameWinDX9::ToggleFullscreen() GetClientRect(hwnd, &client_rect); // Update our copy Pause(false); - if (is_windowed) + if (IsWindowed()) screen->Resize(video_settings->window_width, video_settings->window_height); @@ -479,7 +471,7 @@ GameWinDX9::ToggleFullscreen() bool GameWinDX9::AdjustWindowForChange() { - if (is_windowed) { + if (IsWindowed()) { // Set windowed-mode style SetWindowLong(hwnd, GWL_STYLE, window_style); if (hmenu != NULL) { @@ -501,6 +493,15 @@ GameWinDX9::AdjustWindowForChange() bool +GameWinDX9::IsWindowed() +{ + if (video_settings) + return video_settings->IsWindowed(); + return true; +} + + +bool GameWinDX9::SetupPalette() { if (LoadPalette(standard_palette, inverse_palette)) { diff --git a/StarsEx/GameWinDX9.h b/StarsEx/GameWinDX9.h index 065db57..99b1a39 100644 --- a/StarsEx/GameWinDX9.h +++ b/StarsEx/GameWinDX9.h @@ -36,6 +36,7 @@ public: virtual bool ResetVideo(); virtual bool ToggleFullscreen(); virtual bool AdjustWindowForChange(); + virtual bool IsWindowed(); virtual bool SetupPalette(); virtual bool LoadPalette(PALETTEENTRY* pal, BYTE* inv); @@ -82,11 +83,8 @@ protected: SoundCard* soundcard; Screen* screen; - bool is_windowed; bool is_active; bool is_device_lost; - bool is_minimized; - bool is_maximized; bool ignore_size_change; bool is_device_initialized; bool is_device_restored; diff --git a/StarsEx/WndProc.cpp b/StarsEx/WndProc.cpp index ae91a9a..0c48236 100644 --- a/StarsEx/WndProc.cpp +++ b/StarsEx/WndProc.cpp @@ -17,6 +17,12 @@ #endif +static struct { + bool maximized = false; + bool minimized = false; +} window_state; + + LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM uParam, LPARAM lParam) { @@ -54,31 +60,27 @@ WndProc(HWND hwnd, UINT message, WPARAM uParam, LPARAM lParam) // Pick up possible changes to window style due to maximize, etc. if (game && game->hwnd != NULL ) { game->window_style = GetWindowLong(game->hwnd, GWL_STYLE ); - if (uParam == SIZE_MINIMIZED) { - game->Pause(true); // Pause while we're minimized - game->is_minimized = true; - game->is_maximized = false; + game->Pause(true); + window_state.minimized = true; + window_state.maximized = false; } - else if (uParam == SIZE_MAXIMIZED) { - if (game->is_minimized) - game->Pause(false); // Unpause since we're no longer minimized - - game->is_minimized = false; - game->is_maximized = true; + if (window_state.minimized) + game->Pause(false); + window_state.minimized = false; + window_state.maximized = true; game->ResizeVideo(); } else if (uParam == SIZE_RESTORED) { - if (game->is_maximized) { - game->is_maximized = false; + if (window_state.maximized) { + window_state.maximized = false; game->ResizeVideo(); } - - else if (game->is_minimized) { - game->Pause(false); // Unpause since we're no longer minimized - game->is_minimized = false; + else if (window_state.minimized) { + game->Pause(false); + window_state.minimized = false; game->ResizeVideo(); } else { -- cgit v1.1