add simple borderless fullscreen
This commit is contained in:
parent
e3ffcaa2a1
commit
5f0c315d3f
@ -99,18 +99,12 @@ struct sys_window_settings settings_default_window_settings(struct sys_window *w
|
|||||||
{
|
{
|
||||||
__prof;
|
__prof;
|
||||||
|
|
||||||
struct v2 window_size = sys_window_get_size(window);
|
|
||||||
struct v2 monitor_size = sys_window_get_monitor_size(window);
|
struct v2 monitor_size = sys_window_get_monitor_size(window);
|
||||||
|
|
||||||
i32 window_width = math_round(window_size.x);
|
i32 width = 1280;
|
||||||
i32 window_height = math_round(window_size.y);
|
i32 height = math_round(width / (f32)ASPECT_RATIO);
|
||||||
i32 monitor_width = math_round(monitor_size.x);
|
i32 x = math_round(monitor_size.x / 2.f - width / 2);
|
||||||
i32 monitor_height = math_round(monitor_size.y);
|
i32 y = math_round(monitor_size.y / 2.f - height / 2);
|
||||||
|
|
||||||
i32 width = window_width / 2;
|
|
||||||
i32 height = window_height / 2;
|
|
||||||
i32 x = monitor_width / 2 - width / 2;
|
|
||||||
i32 y = monitor_height / 2 - height / 2;
|
|
||||||
|
|
||||||
return (struct sys_window_settings) {
|
return (struct sys_window_settings) {
|
||||||
#if RTC
|
#if RTC
|
||||||
|
|||||||
@ -258,9 +258,9 @@ struct sys_window_settings {
|
|||||||
u32 flags;
|
u32 flags;
|
||||||
|
|
||||||
/* NOTE: Below fields are NOT representative of actual window dimensions.
|
/* NOTE: Below fields are NOT representative of actual window dimensions.
|
||||||
* These values represent the window dimensions when the window is neither
|
* These values represent the window dimensions when the window is not
|
||||||
* maximized nor minimized, AKA 'floating'. Use `sys_window_get_size` for
|
* maximized, minimized, or fullscreen. AKA 'floating'. Use
|
||||||
* drawing instead. */
|
* `sys_window_get_size` for rendering instead. */
|
||||||
i32 floating_x;
|
i32 floating_x;
|
||||||
i32 floating_y;
|
i32 floating_y;
|
||||||
i32 floating_width;
|
i32 floating_width;
|
||||||
|
|||||||
@ -734,9 +734,9 @@ INTERNAL void win32_update_window_from_system(struct win32_window *window)
|
|||||||
window->y = y;
|
window->y = y;
|
||||||
window->width = width;
|
window->width = width;
|
||||||
window->height = height;
|
window->height = height;
|
||||||
if (!(window->settings.flags & SYS_WINDOW_SETTINGS_FLAG_MAXIMIZED)) {
|
if (!(window->settings.flags & (SYS_WINDOW_SETTINGS_FLAG_MAXIMIZED | SYS_WINDOW_SETTINGS_FLAG_FULLSCREEN))) {
|
||||||
/* Treat a window resize in non-maximized mode as a settings
|
/* Treat a window resize in non maximized/fullscreen mode as a
|
||||||
* change.
|
* settings change.
|
||||||
*
|
*
|
||||||
* TODO: make sure we check for fullscreen here too if we ever
|
* TODO: make sure we check for fullscreen here too if we ever
|
||||||
* allow it. */
|
* 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)
|
INTERNAL void win32_update_window_from_settings(struct win32_window *window, struct sys_window_settings *settings)
|
||||||
{
|
{
|
||||||
HWND hwnd = window->hwnd;
|
HWND hwnd = window->hwnd;
|
||||||
|
|
||||||
|
struct sys_window_settings old_settings = window->settings;
|
||||||
window->settings = *settings;
|
window->settings = *settings;
|
||||||
|
|
||||||
/* Position & dimensions */
|
//u32 win32_flags = SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED;
|
||||||
i32 adjusted_x = settings->floating_x - window->border_left;
|
u32 win32_flags = SWP_NOZORDER | SWP_NOOWNERZORDER;
|
||||||
i32 adjusted_y = settings->floating_y - window->border_top;
|
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(
|
SetWindowPos(
|
||||||
hwnd,
|
hwnd,
|
||||||
0,
|
0,
|
||||||
adjusted_x,
|
x,
|
||||||
adjusted_y,
|
y,
|
||||||
settings->floating_width + (window->border_left * 2),
|
width,
|
||||||
/* I'm unsure why border_left being added to border_top is needed to
|
height,
|
||||||
* retain the correct height. Coincidence? */
|
win32_flags
|
||||||
settings->floating_height + (window->border_left + window->border_top),
|
|
||||||
//SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED
|
|
||||||
SWP_NOZORDER | SWP_NOOWNERZORDER
|
|
||||||
);
|
);
|
||||||
|
|
||||||
SetWindowTextA(hwnd, settings->title);
|
SetWindowTextA(hwnd, settings->title);
|
||||||
@ -785,11 +815,13 @@ INTERNAL LRESULT CALLBACK win32_window_proc(HWND hwnd, UINT msg, WPARAM wparam,
|
|||||||
if (!window) {
|
if (!window) {
|
||||||
/* Window should be retrievable unless we're in any of these
|
/* Window should be retrievable unless we're in any of these
|
||||||
* msgs triggered during initialization / destruction */
|
* msgs triggered during initialization / destruction */
|
||||||
|
#if 0
|
||||||
ASSERT(msg == WM_GETMINMAXINFO
|
ASSERT(msg == WM_GETMINMAXINFO
|
||||||
|| msg == WM_NCCREATE
|
|| msg == WM_NCCREATE
|
||||||
|| msg == WM_NCCALCSIZE
|
|| msg == WM_NCCALCSIZE
|
||||||
|| msg == WM_CREATE
|
|| msg == WM_CREATE
|
||||||
|| msg == WM_NCDESTROY);
|
|| msg == WM_NCDESTROY);
|
||||||
|
#endif
|
||||||
return DefWindowProcA(hwnd, msg, wparam, lparam);
|
return DefWindowProcA(hwnd, msg, wparam, lparam);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
23
src/user.c
23
src/user.c
@ -86,6 +86,7 @@ GLOBAL READONLY enum user_bind_kind g_binds[SYS_BTN_COUNT] = {
|
|||||||
[SYS_BTN_C] = USER_BIND_KIND_DEBUG_CLEAR,
|
[SYS_BTN_C] = USER_BIND_KIND_DEBUG_CLEAR,
|
||||||
[SYS_BTN_F6] = USER_BIND_KIND_DEBUG_DRAW,
|
[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_MWHEELUP] = USER_BIND_KIND_ZOOM_IN,
|
||||||
[SYS_BTN_MWHEELDOWN] = USER_BIND_KIND_ZOOM_OUT,
|
[SYS_BTN_MWHEELDOWN] = USER_BIND_KIND_ZOOM_OUT,
|
||||||
[SYS_BTN_M3] = USER_BIND_KIND_PAN
|
[SYS_BTN_M3] = USER_BIND_KIND_PAN
|
||||||
@ -354,7 +355,7 @@ INTERNAL void user_update(void)
|
|||||||
if (width / height > aspect_ratio) {
|
if (width / height > aspect_ratio) {
|
||||||
width = height * aspect_ratio;
|
width = height * aspect_ratio;
|
||||||
} else {
|
} else {
|
||||||
height = width / aspect_ratio;
|
height = (f32)math_ceil(width / aspect_ratio);
|
||||||
}
|
}
|
||||||
L.viewport_size = V2(width, height);
|
L.viewport_size = V2(width, height);
|
||||||
|
|
||||||
@ -506,9 +507,16 @@ INTERNAL void user_update(void)
|
|||||||
enum user_bind_kind bind = g_binds[button];
|
enum user_bind_kind bind = g_binds[button];
|
||||||
if (bind) {
|
if (bind) {
|
||||||
b32 pressed = event->kind == SYS_EVENT_KIND_BUTTON_DOWN;
|
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) {
|
if (pressed) {
|
||||||
|
if (!out_of_bounds) {
|
||||||
++L.bind_states[bind].num_presses;
|
++L.bind_states[bind].num_presses;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
++L.bind_states[bind].num_releases;
|
++L.bind_states[bind].num_releases;
|
||||||
}
|
}
|
||||||
@ -520,6 +528,16 @@ INTERNAL void user_update(void)
|
|||||||
* Debug commands
|
* 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 */
|
/* Test clear world */
|
||||||
{
|
{
|
||||||
struct bind_state state = L.bind_states[USER_BIND_KIND_DEBUG_CLEAR];
|
struct bind_state state = L.bind_states[USER_BIND_KIND_DEBUG_CLEAR];
|
||||||
@ -973,7 +991,6 @@ INTERNAL void user_update(void)
|
|||||||
++canvases_count;
|
++canvases_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
renderer_canvas_present(canvases, canvases_count, L.screen_size, RECT_FROM_V2(L.viewport_screen_offset, L.viewport_size), vsync);
|
renderer_canvas_present(canvases, canvases_count, L.screen_size, RECT_FROM_V2(L.viewport_screen_offset, L.viewport_size), vsync);
|
||||||
|
|
||||||
scratch_end(scratch);
|
scratch_end(scratch);
|
||||||
|
|||||||
@ -16,6 +16,7 @@ enum user_bind_kind {
|
|||||||
USER_BIND_KIND_DEBUG_CLEAR,
|
USER_BIND_KIND_DEBUG_CLEAR,
|
||||||
USER_BIND_KIND_DEBUG_DRAW,
|
USER_BIND_KIND_DEBUG_DRAW,
|
||||||
USER_BIND_KIND_DEBUG_CAMERA,
|
USER_BIND_KIND_DEBUG_CAMERA,
|
||||||
|
USER_BIND_KIND_FULLSCREEN,
|
||||||
USER_BIND_KIND_ZOOM_IN,
|
USER_BIND_KIND_ZOOM_IN,
|
||||||
USER_BIND_KIND_ZOOM_OUT,
|
USER_BIND_KIND_ZOOM_OUT,
|
||||||
USER_BIND_KIND_PAN,
|
USER_BIND_KIND_PAN,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user