Skip to content

Commit

Permalink
Begin converting the game window into a zwidget window
Browse files Browse the repository at this point in the history
  • Loading branch information
dpjudas committed Feb 27, 2025
1 parent 92b08a5 commit 2f8b59a
Show file tree
Hide file tree
Showing 34 changed files with 215 additions and 278 deletions.
2 changes: 2 additions & 0 deletions libraries/ZWidget/include/zwidget/core/rect.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

#include <algorithm>
#undef min
#undef max

class Point
{
Expand Down
1 change: 1 addition & 0 deletions src/common/engine/i_net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
/* [Petteri] Use Winsock for Win32: */
#ifdef __WIN32__
# define WIN32_LEAN_AND_MEAN
# define NOMINMAX
# include <windows.h>
# include <winsock.h>
#else
Expand Down
1 change: 1 addition & 0 deletions src/common/filesystem/source/critsec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

#ifndef _WINNT_
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h>
#endif

Expand Down
1 change: 1 addition & 0 deletions src/common/filesystem/source/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1440,6 +1440,7 @@ bool FileSystem::CreatePathlessCopy(const char *name, int id, int /*flags*/)

#ifdef _WIN32
//#define WIN32_LEAN_AND_MEAN
//#define NOMINMAX
//#include <windows.h>

extern "C" {
Expand Down
3 changes: 3 additions & 0 deletions src/common/filesystem/source/fs_findfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@

#else

#define WIN32_LEAN_AND_MEAN
#define NOMINMAX

#include <windows.h>
#include <direct.h>

Expand Down
1 change: 1 addition & 0 deletions src/common/fonts/schrift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#if defined(_WIN32)
# define WIN32_LEAN_AND_MEAN 1
# define NOMINMAX
# include <windows.h>
#else
//# define _POSIX_C_SOURCE 1
Expand Down
2 changes: 2 additions & 0 deletions src/common/objects/autosegs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
#include "autosegs.h"

#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h>
#include <dbghelp.h>
#elif defined __MACH__
Expand Down
18 changes: 0 additions & 18 deletions src/common/platform/posix/cocoa/i_video.mm
Original file line number Diff line number Diff line change
Expand Up @@ -745,24 +745,6 @@ void I_SetWindowTitle(const char* title)


#ifdef HAVE_VULKAN
void I_GetVulkanDrawableSize(int *width, int *height)
{
NSWindow* const window = CocoaVideo::GetWindow();
assert(window != nil);

const NSSize size = I_GetContentViewSize(window);

if (width != nullptr)
{
*width = int(size.width);
}

if (height != nullptr)
{
*height = int(size.height);
}
}

bool I_CreateVulkanSurface(VkInstance instance, VkSurfaceKHR *surface)
{
NSView *const view = CocoaVideo::GetWindow().contentView;
Expand Down
6 changes: 0 additions & 6 deletions src/common/platform/posix/sdl/base_sysfb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,6 @@ class SDLVideo : public IVideo
// CODE --------------------------------------------------------------------

#ifdef HAVE_VULKAN
void I_GetVulkanDrawableSize(int *width, int *height)
{
assert(Priv::window != nullptr);
SDL_Vulkan_GetDrawableSize(Priv::window, width, height);
}

bool I_GetVulkanPlatformExtensions(unsigned int *count, const char **names)
{
assert(Priv::window != nullptr);
Expand Down
69 changes: 31 additions & 38 deletions src/common/platform/win32/base_sysfb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
*/

#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h>
#include <GL/gl.h>
#include "wglext.h"
Expand Down Expand Up @@ -73,22 +74,18 @@ EXTERN_CVAR(Int, vid_defheight)

void SystemBaseFrameBuffer::GetCenteredPos(int in_w, int in_h, int &winx, int &winy, int &winw, int &winh, int &scrwidth, int &scrheight)
{
DEVMODE displaysettings;
RECT rect;
int cx, cy;

memset(&displaysettings, 0, sizeof(displaysettings));
DEVMODE displaysettings = {};
displaysettings.dmSize = sizeof(displaysettings);
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &displaysettings);
EnumDisplaySettings(nullptr, ENUM_CURRENT_SETTINGS, &displaysettings);
scrwidth = (int)displaysettings.dmPelsWidth;
scrheight = (int)displaysettings.dmPelsHeight;
GetWindowRect(mainwindow.GetHandle(), &rect);
cx = scrwidth / 2;
cy = scrheight / 2;

int cx = scrwidth / 2;
int cy = scrheight / 2;
if (in_w > 0) winw = in_w;
else winw = rect.right - rect.left;
else winw = mainwindow->GetNativePixelWidth();
if (in_h > 0) winh = in_h;
else winh = rect.bottom - rect.top;
else winh = mainwindow->GetNativePixelHeight();
winx = cx - winw / 2;
winy = cy - winh / 2;
}
Expand Down Expand Up @@ -136,11 +133,11 @@ void SystemBaseFrameBuffer::SaveWindowedPos()
}
// Make sure we only save the window position if it's not fullscreen.
static const int WINDOW_STYLE = WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX;
if ((GetWindowLong(mainwindow.GetHandle(), GWL_STYLE) & WINDOW_STYLE) == WINDOW_STYLE)
if ((GetWindowLong(mainwindow->GetHandle(), GWL_STYLE) & WINDOW_STYLE) == WINDOW_STYLE)
{
RECT wrect;

if (GetWindowRect(mainwindow.GetHandle(), &wrect))
if (GetWindowRect(mainwindow->GetHandle(), &wrect))
{
// If (win_x,win_y) specify to center the window, don't change them
// if the window is still centered.
Expand Down Expand Up @@ -168,7 +165,7 @@ void SystemBaseFrameBuffer::SaveWindowedPos()
win_h = wrect.bottom - wrect.top;
}

win_maximized = IsZoomed(mainwindow.GetHandle()) == TRUE;
win_maximized = IsZoomed(mainwindow->GetHandle()) == TRUE;
}
}

Expand Down Expand Up @@ -201,10 +198,10 @@ void SystemBaseFrameBuffer::RestoreWindowedPos()
}
KeepWindowOnScreen(winx, winy, winw, winh, scrwidth, scrheight);
}
SetWindowPos(mainwindow.GetHandle(), nullptr, winx, winy, winw, winh, SWP_NOZORDER | SWP_FRAMECHANGED);
SetWindowPos(mainwindow->GetHandle(), nullptr, winx, winy, winw, winh, SWP_NOZORDER | SWP_FRAMECHANGED);

if (win_maximized && !Args->CheckParm("-0"))
ShowWindow(mainwindow.GetHandle(), SW_MAXIMIZE);
ShowWindow(mainwindow->GetHandle(), SW_MAXIMIZE);
}

//==========================================================================
Expand All @@ -223,8 +220,8 @@ void SystemBaseFrameBuffer::SetWindowSize(int w, int h)
{
LONG style = WS_VISIBLE | WS_CLIPSIBLINGS | WS_OVERLAPPEDWINDOW;
LONG exStyle = WS_EX_WINDOWEDGE;
SetWindowLong(mainwindow.GetHandle(), GWL_STYLE, style);
SetWindowLong(mainwindow.GetHandle(), GWL_EXSTYLE, exStyle);
SetWindowLong(mainwindow->GetHandle(), GWL_STYLE, style);
SetWindowLong(mainwindow->GetHandle(), GWL_EXSTYLE, exStyle);

int winx, winy, winw, winh, scrwidth, scrheight;

Expand All @@ -247,8 +244,8 @@ void SystemBaseFrameBuffer::SetWindowSize(int w, int h)

if (!vid_fullscreen)
{
ShowWindow(mainwindow.GetHandle(), SW_SHOWNORMAL);
SetWindowPos(mainwindow.GetHandle(), nullptr, winx, winy, winw, winh, SWP_NOZORDER | SWP_FRAMECHANGED);
ShowWindow(mainwindow->GetHandle(), SW_SHOWNORMAL);
SetWindowPos(mainwindow->GetHandle(), nullptr, winx, winy, winw, winh, SWP_NOZORDER | SWP_FRAMECHANGED);
win_maximized = false;
SetSize(GetClientWidth(), GetClientHeight());
SaveWindowedPos();
Expand Down Expand Up @@ -299,9 +296,9 @@ void SystemBaseFrameBuffer::PositionWindow(bool fullscreen, bool initialcall)
}
}

ShowWindow(mainwindow.GetHandle(), SW_SHOW);
ShowWindow(mainwindow->GetHandle(), SW_SHOW);

GetWindowRect(mainwindow.GetHandle(), &r);
GetWindowRect(mainwindow->GetHandle(), &r);
style = WS_VISIBLE | WS_CLIPSIBLINGS;
exStyle = 0;

Expand All @@ -313,13 +310,13 @@ void SystemBaseFrameBuffer::PositionWindow(bool fullscreen, bool initialcall)
exStyle |= WS_EX_WINDOWEDGE;
}

SetWindowLong(mainwindow.GetHandle(), GWL_STYLE, style);
SetWindowLong(mainwindow.GetHandle(), GWL_EXSTYLE, exStyle);
SetWindowLong(mainwindow->GetHandle(), GWL_STYLE, style);
SetWindowLong(mainwindow->GetHandle(), GWL_EXSTYLE, exStyle);

if (fullscreen)
{
SetWindowPos(mainwindow.GetHandle(), 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
MoveWindow(mainwindow.GetHandle(), monRect.left, monRect.top, monRect.right-monRect.left, monRect.bottom-monRect.top, FALSE);
SetWindowPos(mainwindow->GetHandle(), 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
MoveWindow(mainwindow->GetHandle(), monRect.left, monRect.top, monRect.right-monRect.left, monRect.bottom-monRect.top, FALSE);

// And now, seriously, it IS in the right place. Promise.
}
Expand Down Expand Up @@ -349,9 +346,9 @@ SystemBaseFrameBuffer::SystemBaseFrameBuffer(void *hMonitor, bool fullscreen) :
m_displayDeviceName = 0;
PositionWindow(fullscreen, true);

HDC hDC = GetDC(mainwindow.GetHandle());
HDC hDC = GetDC(mainwindow->GetHandle());

ReleaseDC(mainwindow.GetHandle(), hDC);
ReleaseDC(mainwindow->GetHandle(), hDC);
}

//==========================================================================
Expand All @@ -364,10 +361,10 @@ SystemBaseFrameBuffer::~SystemBaseFrameBuffer()
{
if (!m_Fullscreen) SaveWindowedPos();

ShowWindow (mainwindow.GetHandle(), SW_SHOW);
SetWindowLong(mainwindow.GetHandle(), GWL_STYLE, WS_VISIBLE | WS_CLIPSIBLINGS | WS_OVERLAPPEDWINDOW);
SetWindowLong(mainwindow.GetHandle(), GWL_EXSTYLE, WS_EX_WINDOWEDGE);
SetWindowPos(mainwindow.GetHandle(), 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
ShowWindow (mainwindow->GetHandle(), SW_SHOW);
SetWindowLong(mainwindow->GetHandle(), GWL_STYLE, WS_VISIBLE | WS_CLIPSIBLINGS | WS_OVERLAPPEDWINDOW);
SetWindowLong(mainwindow->GetHandle(), GWL_EXSTYLE, WS_EX_WINDOWEDGE);
SetWindowPos(mainwindow->GetHandle(), 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);

static_cast<Win32BaseVideo *>(Video)->Shutdown();
}
Expand Down Expand Up @@ -403,14 +400,10 @@ void SystemBaseFrameBuffer::ToggleFullscreen(bool yes)

int SystemBaseFrameBuffer::GetClientWidth()
{
RECT rect = { 0 };
GetClientRect(mainwindow.GetHandle(), &rect);
return rect.right - rect.left;
return mainwindow->GetNativePixelWidth();
}

int SystemBaseFrameBuffer::GetClientHeight()
{
RECT rect = { 0 };
GetClientRect(mainwindow.GetHandle(), &rect);
return rect.bottom - rect.top;
return mainwindow->GetNativePixelHeight();
}
6 changes: 3 additions & 3 deletions src/common/platform/win32/hardware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ void I_InitGraphics ()
{
// If the focus window is destroyed, it doesn't go back to the active window.
// (e.g. because the net pane was up, and a button on it had focus)
if (GetFocus() == NULL && GetActiveWindow() == mainwindow.GetHandle())
if (GetFocus() == NULL && GetActiveWindow() == mainwindow->GetHandle())
{
// Make sure it's in the foreground and focused. (It probably is
// already foregrounded but may not be focused.)
SetForegroundWindow(mainwindow.GetHandle());
SetFocus(mainwindow.GetHandle());
SetForegroundWindow(mainwindow->GetHandle());
SetFocus(mainwindow->GetHandle());
// Note that when I start a 2-player game on the same machine, the
// window for the game that isn't focused, active, or foregrounded
// still receives a WM_ACTIVATEAPP message telling it that it's the
Expand Down
2 changes: 1 addition & 1 deletion src/common/platform/win32/i_crash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void CrashReporter::create_dump(DumpParams* dump_params, bool launch_uploader)
written = tmp;
return result == TRUE;
};
mainwindow.GetLog(writeFile);
GetLog(writeFile);
CloseHandle(file);

if (launch_uploader && !uploader_exe.empty())
Expand Down
2 changes: 1 addition & 1 deletion src/common/platform/win32/i_dijoy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ bool FDInputJoystick::GetDevice()
Printf(TEXTCOLOR_ORANGE "Setting data format for %s failed.\n", Name.GetChars());
return false;
}
hr = Device->SetCooperativeLevel(mainwindow.GetHandle(), DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
hr = Device->SetCooperativeLevel(mainwindow->GetHandle(), DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
if (FAILED(hr))
{
Printf(TEXTCOLOR_ORANGE "Setting cooperative level for %s failed.\n", Name.GetChars());
Expand Down
6 changes: 3 additions & 3 deletions src/common/platform/win32/i_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ static void I_CheckGUICapture ()

void I_SetMouseCapture()
{
SetCapture(mainwindow.GetHandle());
SetCapture(mainwindow->GetHandle());
}

void I_ReleaseMouseCapture()
Expand Down Expand Up @@ -697,7 +697,7 @@ IJoystickConfig *I_UpdateDeviceList()

void I_PutInClipboard (const char *str)
{
if (str == NULL || !OpenClipboard (mainwindow.GetHandle()))
if (str == NULL || !OpenClipboard (mainwindow->GetHandle()))
return;
EmptyClipboard ();

Expand All @@ -722,7 +722,7 @@ FString I_GetFromClipboard (bool return_nothing)
HGLOBAL cliphandle;
wchar_t *clipstr;

if (return_nothing || !IsClipboardFormatAvailable (CF_UNICODETEXT) || !OpenClipboard (mainwindow.GetHandle()))
if (return_nothing || !IsClipboardFormatAvailable (CF_UNICODETEXT) || !OpenClipboard (mainwindow->GetHandle()))
return retstr;

cliphandle = GetClipboardData (CF_UNICODETEXT);
Expand Down
6 changes: 3 additions & 3 deletions src/common/platform/win32/i_keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ bool FDInputKeyboard::GetDevice()
return false;
}

hr = Device->SetCooperativeLevel(mainwindow.GetHandle(), DISCL_NONEXCLUSIVE | DISCL_BACKGROUND);
hr = Device->SetCooperativeLevel(mainwindow->GetHandle(), DISCL_NONEXCLUSIVE | DISCL_BACKGROUND);
if (FAILED(hr))
{
goto ufailit;
Expand Down Expand Up @@ -374,7 +374,7 @@ void FDInputKeyboard::ProcessInput()
DIDEVICEOBJECTDATA od;
DWORD dwElements;
HRESULT hr;
bool foreground = (GetForegroundWindow() == mainwindow.GetHandle());
bool foreground = (GetForegroundWindow() == mainwindow->GetHandle());

for (;;)
{
Expand Down Expand Up @@ -443,7 +443,7 @@ bool FRawKeyboard::GetDevice()
rid.usUsagePage = HID_GENERIC_DESKTOP_PAGE;
rid.usUsage = HID_GDP_KEYBOARD;
rid.dwFlags = RIDEV_INPUTSINK;
rid.hwndTarget = mainwindow.GetHandle();
rid.hwndTarget = mainwindow->GetHandle();
if (!RegisterRawInputDevices(&rid, 1, sizeof(rid)))
{
return false;
Expand Down
Loading

0 comments on commit 2f8b59a

Please sign in to comment.