Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Window mode fix #51

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions src/GameFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,23 @@ void GameFrame::UpdateWindow() const {
SDL_SetWindowFullscreen(m_hWnd, SDL_TRUE);
break;
case (1): // Windowed
SDL_SetWindowFullscreen(m_hWnd, 0);
SDL_SetWindowResizable(m_hWnd, SDL_TRUE);
SDL_SetWindowBordered(m_hWnd, SDL_TRUE);
SDL_SetWindowSize(m_hWnd, width, height);
SDL_SetWindowPosition(m_hWnd, screenWidth / 2 - width / 2, screenHeight / 2 - height / 2);
// check if default window size, if so set to MaximizeWindow else set as from last session
if (Sim.Options.OptionScreenWindowedWidth == 640 && Sim.Options.OptionScreenWindowedHeight == 480)
{
SDL_SetWindowFullscreen(m_hWnd, 0);
SDL_SetWindowResizable(m_hWnd, SDL_TRUE);
SDL_SetWindowBordered(m_hWnd, SDL_TRUE);
SDL_SetWindowSize(m_hWnd, screenWidth, screenHeight);
SDL_MaximizeWindow(m_hWnd);
SDL_SetWindowPosition(m_hWnd, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
} else {
SDL_SetWindowFullscreen(m_hWnd, 0);
SDL_SetWindowResizable(m_hWnd, SDL_TRUE);
SDL_SetWindowBordered(m_hWnd, SDL_TRUE);
SDL_SetWindowSize(m_hWnd, Sim.Options.OptionScreenWindowedWidth, Sim.Options.OptionScreenWindowedHeight);
SDL_SetWindowPosition(m_hWnd, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
}

break;
case (2): // Borderless Fullscreen
SDL_SetWindowFullscreen(m_hWnd, SDL_FALSE);
Expand All @@ -192,7 +204,9 @@ void GameFrame::UpdateFrameSize() const {
SLONG screenW = 0, screenH = 0;
SDL_GetWindowSize(m_hWnd, &screenW, &screenH);
SDL_RenderSetLogicalSize(lpDD, screenW, screenH);

// update setting file
Sim.Options.OptionScreenWindowedWidth = screenW;
Sim.Options.OptionScreenWindowedHeight = screenH;
if (Sim.Options.OptionKeepAspectRatio == 0) {
PrimaryBm.PrimaryBm.SetTarget(XY{0, 0}, XY{screenW, screenH});
} else {
Expand Down Expand Up @@ -267,8 +281,9 @@ GameFrame::GameFrame() {
}

// Base backup screen size - only used in windowed mode
SLONG width = 640;
SLONG height = 480;
SLONG width = Sim.Options.OptionScreenWindowedWidth;
SLONG height = Sim.Options.OptionScreenWindowedHeight;


if (!static_cast<bool>(bFullscreen) || Sim.Options.OptionFullscreen == 0 || Sim.Options.OptionFullscreen == 2) {
SDL_DisplayMode DM;
Expand Down
4 changes: 4 additions & 0 deletions src/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,10 @@ void Options::OnLButtonDown(UINT /*nFlags*/, CPoint point) {
ChangedDisplay = 1;

Sim.Options.OptionFullscreen++;
if (Sim.Options.OptionFullscreen == 1) {
Sim.Options.OptionScreenWindowedWidth = 640;
Sim.Options.OptionScreenWindowedHeight = 480;
}
if (Sim.Options.OptionFullscreen > 2) {
Sim.Options.OptionFullscreen = 0;
}
Expand Down
10 changes: 9 additions & 1 deletion src/Sim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4152,7 +4152,12 @@ void COptions::ReadOptions() {
if (!reg.ReadRegistryKey_u(OptionRentOfficeMaxAvailable)) {
OptionRentOfficeMaxAvailable = 3;
}

if (!reg.ReadRegistryKey_l(OptionScreenWindowedWidth)) {
OptionScreenWindowedWidth = 640; // default window width
}
if (!reg.ReadRegistryKey_l(OptionScreenWindowedHeight)) {
OptionScreenWindowedHeight = 480; // default window height
}
// Falls Setup nicht geladen wurde dann Standard-Parameter initialisieren
if (!reg.ReadRegistryKey_b(OptionPlanes)) {
OptionPlanes = TRUE;
Expand Down Expand Up @@ -4379,6 +4384,7 @@ void COptions::ReadOptions() {
if (!reg.ReadRegistryKey_u(Sim.GameSpeed)) {
Sim.GameSpeed = 30;
}

}
}

Expand Down Expand Up @@ -4407,6 +4413,8 @@ void COptions::WriteOptions() {


// Regular
reg.WriteRegistryKey_l(OptionScreenWindowedWidth);
reg.WriteRegistryKey_l(OptionScreenWindowedHeight);
reg.WriteRegistryKey_b(OptionPlanes);
reg.WriteRegistryKey_b(OptionPassengers);
reg.WriteRegistryKey_l(OptionMusicType);
Expand Down
2 changes: 2 additions & 0 deletions src/class.h
Original file line number Diff line number Diff line change
Expand Up @@ -2362,6 +2362,8 @@ class COptions {
public:
SLONG OptionFullscreen{};
BOOL OptionKeepAspectRatio{};
SLONG OptionScreenWindowedWidth{};
SLONG OptionScreenWindowedHeight{};
BOOL OptionPlanes{};
BOOL OptionPassengers{};
SLONG OptionMusicType{};
Expand Down
Loading