few windows changes

This commit is contained in:
Matthew 2025-03-05 19:08:16 +11:00
parent ddcdf479a2
commit 662f1d9027
4 changed files with 42 additions and 53 deletions

View File

@ -106,3 +106,14 @@ WindowSize GetWindowSize()
{
return _GetWindowSize();
}
b32 ShouldQuit()
{
return _ShouldQuit();
}
b32 NeedWindowResize()
{
return _NeedWindowResize();
}

View File

@ -65,6 +65,8 @@ b32 CreateSystemWindow();
b32 GetWindowEvent(WindowEvent *event);
void WaitForWindowEvent(WindowEvent *event);
WindowSize GetWindowSize();
b32 NeedWindowResize()
b32 ShouldQuit();
// Directory Functions
b32 ChangeWorkingDir(const char *);

View File

@ -1,6 +1,6 @@
HINSTANCE win32_instance = {};
Window win32_window = {};
b32 global_quit = false;
LRESULT CALLBACK WindowProc(HWND window, UINT message, WPARAM w_param, LPARAM l_param)
{
@ -10,15 +10,14 @@ LRESULT CALLBACK WindowProc(HWND window, UINT message, WPARAM w_param, LPARAM l_
{
case WM_SIZE:
{
OutputDebugStringA("WM_SIZE\n");
win32_window.w = LOWORD(l_param);
win32_window.h = HIWORD(l_param);
win32_window.resize_requested = true;
} break;
case WM_DESTROY:
{
OutputDebugStringA("WM_DESTROY\n");
} break;
case WM_DESTROY: // TODO(MA): Probably handle these separately but for now, they're together
case WM_CLOSE:
{
OutputDebugStringA("WM_CLOSE\n");
global_quit = true;
} break;
case WM_ACTIVATEAPP:
{
@ -37,48 +36,9 @@ int CALLBACK WinMain(HINSTANCE instance, HINSTANCE prev_instance, LPSTR cmd_line
{
win32_instance = instance;
WNDCLASS window_class = {
.style = CS_OWNDC|CS_HREDRAW|CS_VREDRAW,
.lpfnWndProc = WindowProc,
.hInstance = instance,
.lpszClassName = "GearsWindowClass",
};
int result = main(__argc, __argv);
if (RegisterClass(&window_class))
{
HWND window_handle = CreateWindowEx(
0,
window_class.lpszClassName,
"Video Game",
WS_OVERLAPPEDWINDOW|WS_VISIBLE,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
0,
0,
instance,
0
);
if (window_handle)
{
while (true)
{
MSG message;
BOOL message_result = GetMessage(&message, 0, 0, 0);
if (message_result > 0)
{
TranslateMessage(&message);
DispatchMessage(&message);
}
else
{
break;
}
}
}
}
PostQuitMessage(result);
}
b32 _LoadLib(const char *name, Library *out_lib)
@ -188,23 +148,37 @@ b32 _CreateWindow()
Window *_GetWindow()
{
return NULL;
return &win32_window;
}
b32 _GetWindowEvent(WindowEvent *event)
void _ProcessWindowEvents()
{
b32 success = true;
return success;
}
void _WaitForWindowEvent(WindowEvent *event)
{
MSG message;
BOOL message_result = GetMessageA(&message, 0, 0, 0);
if (message_result > 0)
{
TranslateMessage(&message);
DispatchMessage(&message);
}
}
b32 _ShouldQuit()
{
return global_quit;
}
b32 _NeedWindowResize()
{
return win32_window.resize_requested;
}
WindowSize _GetWindowSize()
{
return (WindowSize){ .w = 0, .h = 0 };
return (WindowSize){ .w = win32_window.w, .h = win32_window.h };
}

View File

@ -44,6 +44,8 @@ typedef struct
{
HINSTANCE instance;
HWND handle;
u16 h, w;
b32 resize_requested;
} Window;
typedef struct