From a3bcd64198a2cd0a28b2f2a08b56fc884062816e Mon Sep 17 00:00:00 2001 From: Lake Jee Date: Wed, 23 Nov 2022 11:17:25 -0500 Subject: [PATCH] Add simple maximize window command --- custom/4coder_default_framework.cpp | 6 ++++ custom/generated/command_metadata.h | 48 +++++++++++++++-------------- custom/generated/system_api.cpp | 4 +++ custom/generated/system_api.h | 10 ++++++ platform_win32/win32_4ed.cpp | 42 +++++++++++++++++++++++++ ship_files/bindings.4coder | 1 + 6 files changed, 88 insertions(+), 23 deletions(-) diff --git a/custom/4coder_default_framework.cpp b/custom/4coder_default_framework.cpp index 3000a39d..74c31b62 100644 --- a/custom/4coder_default_framework.cpp +++ b/custom/4coder_default_framework.cpp @@ -532,6 +532,12 @@ CUSTOM_DOC("Toggle fullscreen mode on or off. The change(s) do not take effect system_set_fullscreen(!system_is_fullscreen()); } +CUSTOM_COMMAND_SIG(toggle_maximize) +CUSTOM_DOC("Toggle maximized mode on or off. The change(s) do not take effect until the next frame.") +{ + system_set_maximized(!system_is_maximized()); +} + CUSTOM_COMMAND_SIG(load_themes_default_folder) CUSTOM_DOC("Loads all the theme files in the default theme folder.") { diff --git a/custom/generated/command_metadata.h b/custom/generated/command_metadata.h index 2f6ea9c5..d19e1d3e 100644 --- a/custom/generated/command_metadata.h +++ b/custom/generated/command_metadata.h @@ -2,7 +2,7 @@ #define command_id(c) (fcoder_metacmd_ID_##c) #define command_metadata(c) (&fcoder_metacmd_table[command_id(c)]) #define command_metadata_by_id(id) (&fcoder_metacmd_table[id]) -#define command_one_past_last_id 268 +#define command_one_past_last_id 269 #if defined(CUSTOM_COMMAND_SIG) #define PROC_LINKS(x,y) x #else @@ -255,6 +255,7 @@ CUSTOM_COMMAND_SIG(toggle_highlight_enclosing_scopes); CUSTOM_COMMAND_SIG(toggle_highlight_line_at_cursor); CUSTOM_COMMAND_SIG(toggle_line_numbers); CUSTOM_COMMAND_SIG(toggle_line_wrap); +CUSTOM_COMMAND_SIG(toggle_maximize); CUSTOM_COMMAND_SIG(toggle_mouse); CUSTOM_COMMAND_SIG(toggle_paren_matching_helper); CUSTOM_COMMAND_SIG(toggle_show_whitespace); @@ -805,26 +806,27 @@ static i32 fcoder_metacmd_ID_toggle_highlight_enclosing_scopes = 242; static i32 fcoder_metacmd_ID_toggle_highlight_line_at_cursor = 243; static i32 fcoder_metacmd_ID_toggle_line_numbers = 244; static i32 fcoder_metacmd_ID_toggle_line_wrap = 245; -static i32 fcoder_metacmd_ID_toggle_mouse = 246; -static i32 fcoder_metacmd_ID_toggle_paren_matching_helper = 247; -static i32 fcoder_metacmd_ID_toggle_show_whitespace = 248; -static i32 fcoder_metacmd_ID_toggle_virtual_whitespace = 249; -static i32 fcoder_metacmd_ID_tutorial_maximize = 250; -static i32 fcoder_metacmd_ID_tutorial_minimize = 251; -static i32 fcoder_metacmd_ID_uncomment_line = 252; -static i32 fcoder_metacmd_ID_undo = 253; -static i32 fcoder_metacmd_ID_undo_all_buffers = 254; -static i32 fcoder_metacmd_ID_view_buffer_other_panel = 255; -static i32 fcoder_metacmd_ID_view_jump_list_with_lister = 256; -static i32 fcoder_metacmd_ID_word_complete = 257; -static i32 fcoder_metacmd_ID_word_complete_drop_down = 258; -static i32 fcoder_metacmd_ID_write_block = 259; -static i32 fcoder_metacmd_ID_write_hack = 260; -static i32 fcoder_metacmd_ID_write_note = 261; -static i32 fcoder_metacmd_ID_write_space = 262; -static i32 fcoder_metacmd_ID_write_text_and_auto_indent = 263; -static i32 fcoder_metacmd_ID_write_text_input = 264; -static i32 fcoder_metacmd_ID_write_todo = 265; -static i32 fcoder_metacmd_ID_write_underscore = 266; -static i32 fcoder_metacmd_ID_write_zero_struct = 267; +static i32 fcoder_metacmd_ID_toggle_maximize = 246; +static i32 fcoder_metacmd_ID_toggle_mouse = 247; +static i32 fcoder_metacmd_ID_toggle_paren_matching_helper = 248; +static i32 fcoder_metacmd_ID_toggle_show_whitespace = 249; +static i32 fcoder_metacmd_ID_toggle_virtual_whitespace = 250; +static i32 fcoder_metacmd_ID_tutorial_maximize = 251; +static i32 fcoder_metacmd_ID_tutorial_minimize = 252; +static i32 fcoder_metacmd_ID_uncomment_line = 253; +static i32 fcoder_metacmd_ID_undo = 254; +static i32 fcoder_metacmd_ID_undo_all_buffers = 255; +static i32 fcoder_metacmd_ID_view_buffer_other_panel = 256; +static i32 fcoder_metacmd_ID_view_jump_list_with_lister = 257; +static i32 fcoder_metacmd_ID_word_complete = 258; +static i32 fcoder_metacmd_ID_word_complete_drop_down = 259; +static i32 fcoder_metacmd_ID_write_block = 260; +static i32 fcoder_metacmd_ID_write_hack = 261; +static i32 fcoder_metacmd_ID_write_note = 262; +static i32 fcoder_metacmd_ID_write_space = 263; +static i32 fcoder_metacmd_ID_write_text_and_auto_indent = 264; +static i32 fcoder_metacmd_ID_write_text_input = 265; +static i32 fcoder_metacmd_ID_write_todo = 266; +static i32 fcoder_metacmd_ID_write_underscore = 267; +static i32 fcoder_metacmd_ID_write_zero_struct = 268; #endif diff --git a/custom/generated/system_api.cpp b/custom/generated/system_api.cpp index bed7685d..6e75956a 100644 --- a/custom/generated/system_api.cpp +++ b/custom/generated/system_api.cpp @@ -53,6 +53,8 @@ vtable->memory_annotation = system_memory_annotation; vtable->show_mouse_cursor = system_show_mouse_cursor; vtable->set_fullscreen = system_set_fullscreen; vtable->is_fullscreen = system_is_fullscreen; +vtable->set_maximized = system_set_maximized; +vtable->is_maximized = system_is_maximized; vtable->get_keyboard_modifiers = system_get_keyboard_modifiers; vtable->set_key_mode = system_set_key_mode; vtable->set_source_mixer = system_set_source_mixer; @@ -114,6 +116,8 @@ system_memory_annotation = vtable->memory_annotation; system_show_mouse_cursor = vtable->show_mouse_cursor; system_set_fullscreen = vtable->set_fullscreen; system_is_fullscreen = vtable->is_fullscreen; +system_set_maximized = vtable->set_maximized; +system_is_maximized = vtable->is_maximized; system_get_keyboard_modifiers = vtable->get_keyboard_modifiers; system_set_key_mode = vtable->set_key_mode; system_set_source_mixer = vtable->set_source_mixer; diff --git a/custom/generated/system_api.h b/custom/generated/system_api.h index 5430d5d8..b0a62a8f 100644 --- a/custom/generated/system_api.h +++ b/custom/generated/system_api.h @@ -51,6 +51,8 @@ #define system_show_mouse_cursor_sig() void system_show_mouse_cursor(i32 show) #define system_set_fullscreen_sig() b32 system_set_fullscreen(b32 full_screen) #define system_is_fullscreen_sig() b32 system_is_fullscreen(void) +#define system_set_maximized_sig() b32 system_set_maximized(b32 maximized) +#define system_is_maximized_sig() b32 system_is_maximized(void) #define system_get_keyboard_modifiers_sig() Input_Modifier_Set system_get_keyboard_modifiers(Arena* arena) #define system_set_key_mode_sig() void system_set_key_mode(Key_Mode mode) #define system_set_source_mixer_sig() void system_set_source_mixer(void* ctx, Audio_Mix_Sources_Function* mix_func) @@ -108,6 +110,8 @@ typedef Memory_Annotation system_memory_annotation_type(Arena* arena); typedef void system_show_mouse_cursor_type(i32 show); typedef b32 system_set_fullscreen_type(b32 full_screen); typedef b32 system_is_fullscreen_type(void); +typedef b32 system_set_maximized_type(b32 maximized); +typedef b32 system_is_maximized_type(void); typedef Input_Modifier_Set system_get_keyboard_modifiers_type(Arena* arena); typedef void system_set_key_mode_type(Key_Mode mode); typedef void system_set_source_mixer_type(void* ctx, Audio_Mix_Sources_Function* mix_func); @@ -166,6 +170,8 @@ system_memory_annotation_type *memory_annotation; system_show_mouse_cursor_type *show_mouse_cursor; system_set_fullscreen_type *set_fullscreen; system_is_fullscreen_type *is_fullscreen; +system_set_maximized_type *set_maximized; +system_is_maximized_type *is_maximized; system_get_keyboard_modifiers_type *get_keyboard_modifiers; system_set_key_mode_type *set_key_mode; system_set_source_mixer_type *set_source_mixer; @@ -225,6 +231,8 @@ internal Memory_Annotation system_memory_annotation(Arena* arena); internal void system_show_mouse_cursor(i32 show); internal b32 system_set_fullscreen(b32 full_screen); internal b32 system_is_fullscreen(void); +internal b32 system_set_maximized(b32 maximized); +internal b32 system_is_maximized(void); internal Input_Modifier_Set system_get_keyboard_modifiers(Arena* arena); internal void system_set_key_mode(Key_Mode mode); internal void system_set_source_mixer(void* ctx, Audio_Mix_Sources_Function* mix_func); @@ -284,6 +292,8 @@ global system_memory_annotation_type *system_memory_annotation = 0; global system_show_mouse_cursor_type *system_show_mouse_cursor = 0; global system_set_fullscreen_type *system_set_fullscreen = 0; global system_is_fullscreen_type *system_is_fullscreen = 0; +global system_set_maximized_type *system_set_maximized = 0; +global system_is_maximized_type *system_is_maximized = 0; global system_get_keyboard_modifiers_type *system_get_keyboard_modifiers = 0; global system_set_key_mode_type *system_set_key_mode = 0; global system_set_source_mixer_type *system_set_source_mixer = 0; diff --git a/platform_win32/win32_4ed.cpp b/platform_win32/win32_4ed.cpp index dd9d1209..fbda3876 100644 --- a/platform_win32/win32_4ed.cpp +++ b/platform_win32/win32_4ed.cpp @@ -158,6 +158,8 @@ struct Win32_Vars{ HKL kl_universal; b8 full_screen; + b8 maximized; + b8 do_toggle_maximize; b8 do_toggle; WINDOWPLACEMENT bordered_win_pos; b32 send_exit_signal; @@ -380,6 +382,40 @@ system_is_fullscreen_sig(){ return(result); } + +//////////////////////////////// +// NOTE(lake): Simple Window Maximization so the user still has full window header controls (minimize, maximize/restore down, close) + +internal void +win32_toggle_maximized() { + HWND win = win32vars.window_handle; + DWORD style = GetWindowLongW(win, GWL_STYLE); + + if (!win32vars.maximized) { + ShowWindow(win, SW_MAXIMIZE); + win32vars.maximized = true; + } else { + ShowWindow(win, SW_RESTORE); + win32vars.maximized = false; + } +} + +internal +system_set_maximized_sig() { + win32vars.do_toggle_maximize = (win32vars.maximized != maximized); + b32 success = true; + return(success); +} + +internal +system_is_maximized_sig() { + b32 result = (win32vars.maximized != win32vars.do_toggle_maximize); + return(result); +} + +///////////////////////////////// +// NOTE(lake): Some keyboard modifier stuff by allen im pretty sure + internal system_get_keyboard_modifiers_sig(){ return(copy_modifier_set(arena, &win32vars.input_chunk.pers.modifiers)); @@ -2245,6 +2281,12 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS win32_toggle_fullscreen(); win32vars.do_toggle = false; } + + // Note(lake): toggle maximize + if (win32vars.do_toggle_maximize) { + win32_toggle_maximized(); + win32vars.do_toggle_maximize = false; + } // NOTE(allen): schedule another step if needed if (result.animating){ diff --git a/ship_files/bindings.4coder b/ship_files/bindings.4coder index d07a2c84..0c730676 100644 --- a/ship_files/bindings.4coder +++ b/ship_files/bindings.4coder @@ -19,6 +19,7 @@ keys_global = { { "build_in_build_panel", "M", "Alt" }, { "goto_first_jump", "M", "Alt", "Shift" }, { "toggle_filebar", "B", "Alt" }, + { "toggle_maximized", "Semicolon", "Alt" }, { "execute_any_cli", "Z", "Alt" }, { "execute_previous_cli", "Z", "Alt", "Shift" }, { "command_lister", "X", "Alt" },