Skip to content

Commit c7891b2

Browse files
committed
alt-enter first version
1 parent 6317722 commit c7891b2

7 files changed

Lines changed: 118 additions & 15 deletions

File tree

Core/GameEngine/Include/Common/OptionPreferences.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ class OptionPreferences : public UserPreferences
8888
Real getGammaValue();
8989
Int getTextureReduction();
9090
void getResolution(Int *xres, Int *yres);
91+
Bool getWindowed() const;
92+
void setWindowed(Bool windowed);
9193
Bool get3DShadowsEnabled();
9294
Bool get2DShadowsEnabled();
9395
Bool getCloudShadowsEnabled();

Core/GameEngine/Source/Common/OptionPreferences.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,23 @@ void OptionPreferences::getResolution(Int *xres, Int *yres)
714714
*yres=selectedYRes;
715715
}
716716

717+
Bool OptionPreferences::getWindowed() const
718+
{
719+
OptionPreferences::const_iterator it = find("Windowed");
720+
if (it == end())
721+
return FALSE;
722+
723+
if (stricmp(it->second.str(), "yes") == 0) {
724+
return TRUE;
725+
}
726+
return FALSE;
727+
}
728+
729+
void OptionPreferences::setWindowed(Bool windowed)
730+
{
731+
insert(std::make_pair(AsciiString("Windowed"), AsciiString(windowed ? "yes" : "no")));
732+
}
733+
717734
Real OptionPreferences::getMusicVolume()
718735
{
719736
OptionPreferences::const_iterator it = find("MusicVolume");

Core/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,20 +1241,16 @@ const char * DX8Wrapper::Get_Render_Device_Name(int device_index)
12411241
bool DX8Wrapper::Set_Device_Resolution(int width,int height,int bits,int windowed, bool resize_window)
12421242
{
12431243
if (D3DDevice != nullptr) {
1244-
1245-
if (width != -1) {
1246-
_PresentParameters.BackBufferWidth = ResolutionWidth = width;
1247-
}
1248-
if (height != -1) {
1249-
_PresentParameters.BackBufferHeight = ResolutionHeight = height;
1250-
}
1251-
if (resize_window)
1252-
{
1253-
Resize_And_Position_Window();
1254-
}
1255-
#pragma message("TODO: support changing windowed status and changing the bit depth")
1256-
WWDEBUG_SAY(("DX8Wrapper::Set_Device_Resolution is resetting the device."));
1257-
return Reset_Device();
1244+
// If parameters are -1, use current values.
1245+
int w = (width == -1) ? ResolutionWidth : width;
1246+
int h = (height == -1) ? ResolutionHeight : height;
1247+
int b = (bits == -1) ? BitDepth : bits;
1248+
int win = (windowed == -1) ? IsWindowed : windowed;
1249+
1250+
// TheSuperHackers @bugfix valeronm 16/04/2026
1251+
// Set_Render_Device handles all the presentation parameter changes and the reset.
1252+
// Previous implementation was stubbed and ignored windowed/bits changes.
1253+
return Set_Render_Device(CurRenderDevice, w, h, b, win, resize_window, true, true);
12581254
} else {
12591255
return false;
12601256
}

GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,20 @@ constexpr const Int MAX_GLOBAL_LIGHTS = 3;
5454
constexpr const Int SIMULATE_REPLAYS_SEQUENTIAL = -1;
5555

5656
//-------------------------------------------------------------------------------------------------
57-
class CommandLineData
57+
struct CommandLineData
5858
{
5959
friend class CommandLine;
6060
friend class GlobalData;
6161

6262
CommandLineData()
6363
: m_hasParsedCommandLineForStartup(false)
6464
, m_hasParsedCommandLineForEngineInit(false)
65+
, m_windowedCommandLineSpecified(false)
6566
{}
6667

6768
Bool m_hasParsedCommandLineForStartup;
6869
Bool m_hasParsedCommandLineForEngineInit;
70+
Bool m_windowedCommandLineSpecified;
6971
};
7072

7173
//-------------------------------------------------------------------------------------------------

GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
#include "GameClient/GameText.h"
3737
#include "GameNetwork/NetworkDefs.h"
3838
#include "trim.h"
39+
#include "Common/OptionPreferences.h"
40+
3941

4042

4143

@@ -118,6 +120,7 @@ Int parseNoLogOrCrash(char *args[], int)
118120
Int parseWin(char *args[], int)
119121
{
120122
TheWritableGlobalData->m_windowed = true;
123+
TheWritableGlobalData->m_commandLineData.m_windowedCommandLineSpecified = true;
121124

122125
return 1;
123126
}
@@ -377,6 +380,7 @@ Int parseNoAudio(char *args[], int)
377380
Int parseNoWin(char *args[], int)
378381
{
379382
TheWritableGlobalData->m_windowed = false;
383+
TheWritableGlobalData->m_commandLineData.m_windowedCommandLineSpecified = true;
380384

381385
return 1;
382386
}
@@ -1450,6 +1454,9 @@ void CommandLine::parseCommandLineForStartup()
14501454
return;
14511455
TheWritableGlobalData->m_commandLineData.m_hasParsedCommandLineForStartup = true;
14521456

1457+
OptionPreferences optionPref;
1458+
TheWritableGlobalData->m_windowed = optionPref.getWindowed();
1459+
14531460
parseCommandLine(paramsForStartup, ARRAY_SIZE(paramsForStartup));
14541461
}
14551462

GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,9 @@ void GlobalData::reset()
11621162
//-------------------------------------------------------------------------------------------------
11631163
void GlobalData::parseGameDataDefinition( INI* ini )
11641164
{
1165+
// Capture command-line intent before any INI overrides happen
1166+
Bool cmdWindowed = TheGlobalData->m_windowed;
1167+
11651168
if( TheWritableGlobalData && ini->getLoadType() != INI_LOAD_MULTIFILE)
11661169
{
11671170

@@ -1211,6 +1214,15 @@ void GlobalData::parseGameDataDefinition( INI* ini )
12111214
TheWritableGlobalData->m_playerInfoListFontSize = optionPref.getPlayerInfoListFontSize();
12121215
TheWritableGlobalData->m_showMoneyPerMinute = optionPref.getShowMoneyPerMinute();
12131216

1217+
if (TheGlobalData->m_commandLineData.m_windowedCommandLineSpecified)
1218+
{
1219+
TheWritableGlobalData->m_windowed = cmdWindowed;
1220+
}
1221+
else
1222+
{
1223+
TheWritableGlobalData->m_windowed = optionPref.getWindowed();
1224+
}
1225+
12141226
Int val=optionPref.getGammaValue();
12151227
//generate a value between 0.6 and 2.0.
12161228
if (val < 50)

GeneralsMD/Code/Main/WinMain.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@
5151
#include "Common/GameMemory.h"
5252
#include "Common/StackDump.h"
5353
#include "Common/MessageStream.h"
54+
#include "Common/OptionPreferences.h"
5455
#include "Common/Registry.h"
5556
#include "Common/Team.h"
5657
#include "GameClient/ClientInstance.h"
58+
#include "GameClient/Display.h"
5759
#include "GameClient/InGameUI.h"
5860
#include "GameClient/GameClient.h"
5961
#include "GameLogic/GameLogic.h" ///< @todo for demo, remove
@@ -655,6 +657,71 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message,
655657
break;
656658
}
657659
#endif
660+
case WM_SYSKEYDOWN:
661+
{
662+
if (wParam == VK_RETURN && (lParam & (1 << 29))) // Alt + Enter
663+
{
664+
if (TheGameEngine && !TheGameEngine->getQuitting() && TheDisplay)
665+
{
666+
TheWritableGlobalData->m_windowed = !TheGlobalData->m_windowed;
667+
668+
// Determine desired client resolution
669+
Int resX = TheGlobalData->m_xResolution;
670+
Int resY = TheGlobalData->m_yResolution;
671+
672+
// Update window style and calculate correct window size
673+
DWORD windowStyle = WS_POPUP | WS_VISIBLE;
674+
DWORD exStyle = 0;
675+
if (TheGlobalData->m_windowed)
676+
{
677+
// Standard windowed style with caption and fixed dialog border
678+
windowStyle |= WS_MINIMIZEBOX | WS_SYSMENU | WS_DLGFRAME | WS_CAPTION;
679+
}
680+
else
681+
{
682+
// Fullscreen style (borderless popup)
683+
windowStyle |= WS_SYSMENU;
684+
exStyle |= WS_EX_TOPMOST;
685+
}
686+
687+
// Let Windows calculate the required window size for our desired client resolution
688+
RECT windowRect = { 0, 0, resX, resY };
689+
AdjustWindowRect(&windowRect, windowStyle, FALSE);
690+
int width = windowRect.right - windowRect.left;
691+
int height = windowRect.bottom - windowRect.top;
692+
693+
// Determine position (center it if windowed)
694+
int x = 0, y = 0;
695+
if (TheGlobalData->m_windowed)
696+
{
697+
x = (GetSystemMetrics(SM_CXSCREEN) - width) / 2;
698+
y = (GetSystemMetrics(SM_CYSCREEN) - height) / 2;
699+
if (x < 0) x = 0;
700+
if (y < 0) y = 0;
701+
}
702+
703+
// Apply styles and size
704+
SetWindowLong(hWnd, GWL_STYLE, windowStyle);
705+
SetWindowLong(hWnd, GWL_EXSTYLE, exStyle);
706+
SetWindowPos(hWnd, TheGlobalData->m_windowed ? HWND_NOTOPMOST : HWND_TOPMOST,
707+
x, y, width, height, SWP_FRAMECHANGED | SWP_SHOWWINDOW);
708+
709+
// Toggle and save
710+
TheDisplay->setDisplayMode(resX, resY, 32, TheGlobalData->m_windowed);
711+
712+
OptionPreferences optionPref;
713+
optionPref.setWindowed(TheGlobalData->m_windowed);
714+
optionPref.write();
715+
716+
// Re-apply refresh just in case reset messed it up
717+
SetWindowPos(hWnd, TheGlobalData->m_windowed ? HWND_NOTOPMOST : HWND_TOPMOST,
718+
x, y, width, height, SWP_FRAMECHANGED | SWP_SHOWWINDOW);
719+
UpdateWindow(hWnd);
720+
}
721+
return 0;
722+
}
723+
break;
724+
}
658725
}
659726

660727
}

0 commit comments

Comments
 (0)