From 662f1d902754b50ff255cebd2976447440dcefca Mon Sep 17 00:00:00 2001 From: Matthew Date: Wed, 5 Mar 2025 19:08:16 +1100 Subject: [PATCH] few windows changes --- src/platform.c | 11 ++++++ src/platform.h | 2 ++ src/platform_windows.c | 80 ++++++++++++++---------------------------- src/platform_windows.h | 2 ++ 4 files changed, 42 insertions(+), 53 deletions(-) diff --git a/src/platform.c b/src/platform.c index 92e802a..5ed0216 100644 --- a/src/platform.c +++ b/src/platform.c @@ -106,3 +106,14 @@ WindowSize GetWindowSize() { return _GetWindowSize(); } + +b32 ShouldQuit() +{ + return _ShouldQuit(); +} + +b32 NeedWindowResize() +{ + return _NeedWindowResize(); +} + diff --git a/src/platform.h b/src/platform.h index e7114c7..0be156f 100644 --- a/src/platform.h +++ b/src/platform.h @@ -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 *); diff --git a/src/platform_windows.c b/src/platform_windows.c index da91bd8..05b1306 100644 --- a/src/platform_windows.c +++ b/src/platform_windows.c @@ -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 }; } diff --git a/src/platform_windows.h b/src/platform_windows.h index db6d141..31543fd 100644 --- a/src/platform_windows.h +++ b/src/platform_windows.h @@ -44,6 +44,8 @@ typedef struct { HINSTANCE instance; HWND handle; + u16 h, w; + b32 resize_requested; } Window; typedef struct