diff --git a/src/settings.c b/src/settings.c index 20968bd0..62b1f098 100644 --- a/src/settings.c +++ b/src/settings.c @@ -99,18 +99,12 @@ struct sys_window_settings settings_default_window_settings(struct sys_window *w { __prof; - struct v2 window_size = sys_window_get_size(window); struct v2 monitor_size = sys_window_get_monitor_size(window); - i32 window_width = math_round(window_size.x); - i32 window_height = math_round(window_size.y); - i32 monitor_width = math_round(monitor_size.x); - i32 monitor_height = math_round(monitor_size.y); - - i32 width = window_width / 2; - i32 height = window_height / 2; - i32 x = monitor_width / 2 - width / 2; - i32 y = monitor_height / 2 - height / 2; + i32 width = 1280; + i32 height = math_round(width / (f32)ASPECT_RATIO); + i32 x = math_round(monitor_size.x / 2.f - width / 2); + i32 y = math_round(monitor_size.y / 2.f - height / 2); return (struct sys_window_settings) { #if RTC diff --git a/src/sys.h b/src/sys.h index 49d03236..48fbbc23 100644 --- a/src/sys.h +++ b/src/sys.h @@ -258,9 +258,9 @@ struct sys_window_settings { u32 flags; /* NOTE: Below fields are NOT representative of actual window dimensions. - * These values represent the window dimensions when the window is neither - * maximized nor minimized, AKA 'floating'. Use `sys_window_get_size` for - * drawing instead. */ + * These values represent the window dimensions when the window is not + * maximized, minimized, or fullscreen. AKA 'floating'. Use + * `sys_window_get_size` for rendering instead. */ i32 floating_x; i32 floating_y; i32 floating_width; diff --git a/src/sys_win32.c b/src/sys_win32.c index f8fc7e60..08334c79 100644 --- a/src/sys_win32.c +++ b/src/sys_win32.c @@ -734,9 +734,9 @@ INTERNAL void win32_update_window_from_system(struct win32_window *window) window->y = y; window->width = width; window->height = height; - if (!(window->settings.flags & SYS_WINDOW_SETTINGS_FLAG_MAXIMIZED)) { - /* Treat a window resize in non-maximized mode as a settings - * change. + if (!(window->settings.flags & (SYS_WINDOW_SETTINGS_FLAG_MAXIMIZED | SYS_WINDOW_SETTINGS_FLAG_FULLSCREEN))) { + /* Treat a window resize in non maximized/fullscreen mode as a + * settings change. * * TODO: make sure we check for fullscreen here too if we ever * allow it. */ @@ -751,22 +751,52 @@ INTERNAL void win32_update_window_from_system(struct win32_window *window) INTERNAL void win32_update_window_from_settings(struct win32_window *window, struct sys_window_settings *settings) { HWND hwnd = window->hwnd; + + struct sys_window_settings old_settings = window->settings; window->settings = *settings; - /* Position & dimensions */ - i32 adjusted_x = settings->floating_x - window->border_left; - i32 adjusted_y = settings->floating_y - window->border_top; + //u32 win32_flags = SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED; + u32 win32_flags = SWP_NOZORDER | SWP_NOOWNERZORDER; + i32 x = 0; + i32 y = 0; + i32 width = 0; + i32 height = 0; + + b32 old_fullscreen = old_settings.flags & SYS_WINDOW_SETTINGS_FLAG_FULLSCREEN; + b32 fullscreen = settings->flags & SYS_WINDOW_SETTINGS_FLAG_FULLSCREEN; + + /* FIXME: Window in wrong size when coming out of fullscreen */ + if (fullscreen) { + x = 0; + y = 0; + width = window->monitor_width; + height = window->monitor_height; + } else { + x = settings->floating_x - window->border_left; + y = settings->floating_y - window->border_top; + width = settings->floating_width + (window->border_left * 2); + /* I'm unsure why border_left being added to border_top is needed to + * retain the correct height. Coincidence? */ + height = settings->floating_height + (window->border_left + window->border_top); + } + + if (fullscreen != old_fullscreen) { + if (fullscreen) { + SetWindowLongPtrA(hwnd, GWL_STYLE, WS_POPUP); + } else { + SetWindowLongPtrA(hwnd, GWL_STYLE, WS_OVERLAPPEDWINDOW); + } + win32_flags |= SWP_SHOWWINDOW; + } + SetWindowPos( hwnd, 0, - adjusted_x, - adjusted_y, - settings->floating_width + (window->border_left * 2), - /* I'm unsure why border_left being added to border_top is needed to - * retain the correct height. Coincidence? */ - settings->floating_height + (window->border_left + window->border_top), - //SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED - SWP_NOZORDER | SWP_NOOWNERZORDER + x, + y, + width, + height, + win32_flags ); SetWindowTextA(hwnd, settings->title); @@ -785,11 +815,13 @@ INTERNAL LRESULT CALLBACK win32_window_proc(HWND hwnd, UINT msg, WPARAM wparam, if (!window) { /* Window should be retrievable unless we're in any of these * msgs triggered during initialization / destruction */ +#if 0 ASSERT(msg == WM_GETMINMAXINFO || msg == WM_NCCREATE || msg == WM_NCCALCSIZE || msg == WM_CREATE || msg == WM_NCDESTROY); +#endif return DefWindowProcA(hwnd, msg, wparam, lparam); } diff --git a/src/user.c b/src/user.c index 1dd84921..23c3a022 100644 --- a/src/user.c +++ b/src/user.c @@ -85,7 +85,8 @@ GLOBAL READONLY enum user_bind_kind g_binds[SYS_BTN_COUNT] = { [SYS_BTN_C] = USER_BIND_KIND_DEBUG_CLEAR, [SYS_BTN_F6] = USER_BIND_KIND_DEBUG_DRAW, - [SYS_BTN_F7] = USER_BIND_KIND_DEBUG_CAMERA, + [SYS_BTN_F7] = USER_BIND_KIND_DEBUG_CAMERA, + [SYS_BTN_F11] = USER_BIND_KIND_FULLSCREEN, [SYS_BTN_MWHEELUP] = USER_BIND_KIND_ZOOM_IN, [SYS_BTN_MWHEELDOWN] = USER_BIND_KIND_ZOOM_OUT, [SYS_BTN_M3] = USER_BIND_KIND_PAN @@ -354,7 +355,7 @@ INTERNAL void user_update(void) if (width / height > aspect_ratio) { width = height * aspect_ratio; } else { - height = width / aspect_ratio; + height = (f32)math_ceil(width / aspect_ratio); } L.viewport_size = V2(width, height); @@ -506,9 +507,16 @@ INTERNAL void user_update(void) enum user_bind_kind bind = g_binds[button]; if (bind) { b32 pressed = event->kind == SYS_EVENT_KIND_BUTTON_DOWN; - L.bind_states[bind].is_held = pressed; + b32 out_of_bounds = button >= SYS_BTN_M1 && button <= SYS_BTN_M5 && + (L.viewport_cursor.x < 0 || + L.viewport_cursor.y < 0 || + L.viewport_cursor.x > L.viewport_size.x || + L.viewport_cursor.y > L.viewport_size.y); + L.bind_states[bind].is_held = pressed && !out_of_bounds; if (pressed) { - ++L.bind_states[bind].num_presses; + if (!out_of_bounds) { + ++L.bind_states[bind].num_presses; + } } else { ++L.bind_states[bind].num_releases; } @@ -520,6 +528,16 @@ INTERNAL void user_update(void) * Debug commands * ========================== */ + /* Test fullscreen */ + { + struct bind_state state = L.bind_states[USER_BIND_KIND_FULLSCREEN]; + if (state.num_presses) { + struct sys_window_settings settings = sys_window_get_settings(L.window); + settings.flags ^= SYS_WINDOW_SETTINGS_FLAG_FULLSCREEN; + sys_window_update_settings(L.window, &settings); + } + } + /* Test clear world */ { struct bind_state state = L.bind_states[USER_BIND_KIND_DEBUG_CLEAR]; @@ -973,7 +991,6 @@ INTERNAL void user_update(void) ++canvases_count; } - renderer_canvas_present(canvases, canvases_count, L.screen_size, RECT_FROM_V2(L.viewport_screen_offset, L.viewport_size), vsync); scratch_end(scratch); diff --git a/src/user.h b/src/user.h index 6d09dcdc..415f57ed 100644 --- a/src/user.h +++ b/src/user.h @@ -16,6 +16,7 @@ enum user_bind_kind { USER_BIND_KIND_DEBUG_CLEAR, USER_BIND_KIND_DEBUG_DRAW, USER_BIND_KIND_DEBUG_CAMERA, + USER_BIND_KIND_FULLSCREEN, USER_BIND_KIND_ZOOM_IN, USER_BIND_KIND_ZOOM_OUT, USER_BIND_KIND_PAN,