diff --git a/4coder_API.html b/4coder_API.html index 04f1c9e5..ba52a143 100644 --- a/4coder_API.html +++ b/4coder_API.html @@ -164,6 +164,9 @@ This is the documentation for alpha 4.0.9 super! The documentation has been made
  • get_4ed_path
  • +
  • +show_mouse_cursor +
  • §2.2 Descriptions

    @@ -983,6 +986,16 @@ also be used with rel set to ".." to traverse to parent folders.

    the maximum capacity of the output buffer
    Return
    returns non-zero on success, returns zero on failure

    +
    +

    §2.2.46: show_mouse_cursor

    +
    void app->show_mouse_cursor( +
    Application_Links *app,
    int show
    ) +
    +
    Parameters
    +
    show
    +
    The show state to put the mouse cursor into. If this is non-zero the mouse cursor is shown.
    +
    +

    diff --git a/4coder_custom.h b/4coder_custom.h index 1ff2e008..f9067322 100644 --- a/4coder_custom.h +++ b/4coder_custom.h @@ -49,11 +49,6 @@ typedef struct Key_Event_Data{ Code character_no_caps_lock; char modifiers[MDFR_INDEX_COUNT]; } Key_Event_Data; -inline Key_Event_Data -key_event_data_zero(){ - Key_Event_Data data={0}; - return(data); -} typedef struct Mouse_State{ char l, r; @@ -73,6 +68,16 @@ typedef union Range{ }; } Range; +inline Key_Event_Data +key_event_data_zero(){ + Key_Event_Data data={0}; + return(data); +} +inline Mouse_State +mouse_state_zero(){ + Mouse_State data={0}; + return(data); +} inline Range make_range(int p1, int p2){ Range range; @@ -179,6 +184,7 @@ enum Special_Hook_ID{ _hook_new_file, _hook_open_file, _hook_command_caller, + _hook_input_filter, }; // None of the members of *_Summary structs nor any of the data pointed @@ -342,6 +348,7 @@ enum Input_Type_Flag{ #define HOOK_SIG(name) int name(struct Application_Links *app) #define OPEN_FILE_HOOK_SIG(name) int name(struct Application_Links *app, int buffer_id) #define SCROLL_RULE_SIG(name) int name(float target_x, float target_y, float *scroll_x, float *scroll_y, int view_id, int is_new_target, float dt) +#define INPUT_FILTER_SIG(name) void name(Mouse_State *mouse) typedef VIEW_ROUTINE_SIG(View_Routine_Function); typedef CUSTOM_COMMAND_SIG(Custom_Command_Function); @@ -350,6 +357,7 @@ typedef HOOK_SIG(Hook_Function); typedef OPEN_FILE_HOOK_SIG(Open_File_Hook_Function); typedef SCROLL_RULE_SIG(Scroll_Rule_Function); +typedef INPUT_FILTER_SIG(Input_Filter_Function); union Generic_Command{ Command_ID cmdid; diff --git a/4coder_custom_api.h b/4coder_custom_api.h index 4fda4445..84aa0753 100644 --- a/4coder_custom_api.h +++ b/4coder_custom_api.h @@ -44,6 +44,7 @@ #define FILE_EXISTS_SIG(n) int n(Application_Links *app, char *filename, int len) #define DIRECTORY_CD_SIG(n) int n(Application_Links *app, char *dir, int *len, int capacity, char *rel_path, int rel_len) #define GET_4ED_PATH_SIG(n) int n(Application_Links *app, char *out, int capacity) +#define SHOW_MOUSE_CURSOR_SIG(n) void n(Application_Links *app, int show) extern "C"{ typedef EXEC_COMMAND_SIG(Exec_Command_Function); typedef EXEC_SYSTEM_COMMAND_SIG(Exec_System_Command_Function); @@ -91,6 +92,7 @@ extern "C"{ typedef FILE_EXISTS_SIG(File_Exists_Function); typedef DIRECTORY_CD_SIG(Directory_CD_Function); typedef GET_4ED_PATH_SIG(Get_4ed_Path_Function); + typedef SHOW_MOUSE_CURSOR_SIG(Show_Mouse_Cursor_Function); } struct Application_Links{ void *memory; @@ -141,6 +143,7 @@ struct Application_Links{ File_Exists_Function *file_exists; Directory_CD_Function *directory_cd; Get_4ed_Path_Function *get_4ed_path; + Show_Mouse_Cursor_Function *show_mouse_cursor; void *cmd_context; void *system_links; void *current_coroutine; @@ -192,4 +195,5 @@ app_links->get_file_list = Get_File_List;\ app_links->free_file_list = Free_File_List;\ app_links->file_exists = File_Exists;\ app_links->directory_cd = Directory_CD;\ -app_links->get_4ed_path = Get_4ed_Path; } while(false) +app_links->get_4ed_path = Get_4ed_Path;\ +app_links->show_mouse_cursor = Show_Mouse_Cursor; } while(false) diff --git a/4coder_default_bindings.cpp b/4coder_default_bindings.cpp index 706cf08f..81c56727 100644 --- a/4coder_default_bindings.cpp +++ b/4coder_default_bindings.cpp @@ -199,6 +199,42 @@ COMMAND_CALLER_HOOK(my_command_caller){ return(0); } +// NOTE(allen|a4.0.9): The input filter allows you to modify the input +// to a frame before 4coder starts processing it at all. +// +// Right now it only has access to the mouse state, but it will be +// extended to have access to the key presses soon. +static int suppressing_mouse = false; + +INPUT_FILTER_SIG(my_suppress_mouse_filter){ + if (suppressing_mouse){ + *mouse = mouse_state_zero(); + mouse->x = -100; + mouse->y = -100; + } +} + +CUSTOM_COMMAND_SIG(suppress_mouse){ + suppressing_mouse = true; + app->show_mouse_cursor(app, false); +} + +CUSTOM_COMMAND_SIG(allow_mouse){ + suppressing_mouse = false; + app->show_mouse_cursor(app, true); +} + +CUSTOM_COMMAND_SIG(toggle_mouse){ + if (suppressing_mouse){ + suppressing_mouse = false; + app->show_mouse_cursor(app, true); + } + else{ + suppressing_mouse = true; + app->show_mouse_cursor(app, false); + } +} + void default_keys(Bind_Helper *context){ begin_map(context, mapid_global); @@ -221,6 +257,8 @@ default_keys(Bind_Helper *context){ bind(context, 'z', MDFR_ALT, execute_any_cli); bind(context, 'Z', MDFR_ALT, execute_previous_cli); + bind(context, key_f2, MDFR_NONE, toggle_mouse); + end_map(context); begin_map(context, my_code_map); @@ -354,6 +392,7 @@ get_bindings(void *data, int size){ set_open_file_hook(context, my_file_settings); set_command_caller(context, my_command_caller); + set_input_filter(context, my_suppress_mouse_filter); set_scroll_rule(context, smooth_scroll_rule); default_keys(context); diff --git a/4coder_helper.h b/4coder_helper.h index 00c9997b..32a99363 100644 --- a/4coder_helper.h +++ b/4coder_helper.h @@ -206,6 +206,16 @@ set_command_caller(Bind_Helper *helper, Command_Caller_Hook_Function *func){ write_unit(helper, unit); } +inline void +set_input_filter(Bind_Helper *helper, Input_Filter_Function *func){ + Binding_Unit unit; + unit.type = unit_hook; + unit.hook.hook_id = _hook_input_filter; + unit.hook.func = (void*) func; + + write_unit(helper, unit); +} + inline void set_scroll_rule(Bind_Helper *helper, Scroll_Rule_Function *func){ Binding_Unit unit; diff --git a/4ed.cpp b/4ed.cpp index f17dfdf4..5c3e838e 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -1779,6 +1779,10 @@ App_Init_Sig(app_init){ case _hook_scroll_rule: models->scroll_rule = (Scroll_Rule_Function*)unit->hook.func; break; + + case _hook_input_filter: + models->input_filter = (Input_Filter_Function*)unit->hook.func; + break; } } } @@ -2012,6 +2016,10 @@ App_Step_Sig(app_step){ key_summary.keys[key_summary.count++] = input->keys.hold[i]; } + if (models->input_filter){ + models->input_filter(&input->mouse); + } + Key_Event_Data mouse_event = {0}; if (input->mouse.press_l || input->mouse.press_r){ @@ -2690,6 +2698,12 @@ App_Step_Sig(app_step){ "and if you load README.txt you'll find all the key combos there are.\n" "\n" "Newest features:\n" + "-A scratch buffer is now opened with 4coder automatically\n" + "- toggels mouse suppression mode\n" + "-Experimental new work-flow for building a jumping to errors\n" + " (only available in power for this version)\n" + "\n" + "New in alpha 4.0.8:\n" "-Eliminated the parameter stack\n" "\n" "New in alpha 4.0.7:\n" diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index f14f64e3..1187cfa7 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -947,7 +947,7 @@ DOC_SEE(Buffer_Kill_Flags) try_kill_file(system, models, file, vptr, string_zero()); } else{ - // TODO(allen): message + app->print_message(app, literal("buffer is dirty and no view was specified for a dialogue.")); } } } @@ -1621,6 +1621,7 @@ directories controlled by the custom side. #define Get_4ed_Path system->get_4ed_path #define File_Exists system->file_exists #define Directory_CD system->directory_cd +#define Show_Mouse_Cursor system->show_mouse_cursor API_EXPORT File_List Get_File_List(Application_Links *app, char *dir, int len)/* diff --git a/4ed_app_models.h b/4ed_app_models.h index 24a9865b..75f3a13a 100644 --- a/4ed_app_models.h +++ b/4ed_app_models.h @@ -80,6 +80,7 @@ struct Models{ Open_File_Hook_Function *hook_open_file; Open_File_Hook_Function *hook_new_file; Command_Caller_Hook_Function *command_caller; + Input_Filter_Function *input_filter; Scroll_Rule_Function *scroll_rule; b32 keep_playing; diff --git a/4ed_system.h b/4ed_system.h index 82f12bdd..8f526d73 100644 --- a/4ed_system.h +++ b/4ed_system.h @@ -231,10 +231,11 @@ struct System_Functions{ System_File_Load_End *file_load_end; System_File_Save *file_save; - // file system navigation (4coder_custom.h): 3 + // 4coder_custom.h: 3 File_Exists_Function *file_exists; Directory_CD_Function *directory_cd; Get_4ed_Path_Function *get_4ed_path; + Show_Mouse_Cursor_Function *show_mouse_cursor; // clipboard: 1 System_Post_Clipboard *post_clipboard; diff --git a/power/4coder_casey.cpp b/power/4coder_casey.cpp index 4eb3aa8c..ec484992 100644 --- a/power/4coder_casey.cpp +++ b/power/4coder_casey.cpp @@ -1457,9 +1457,9 @@ win32_toggle_fullscreen(void) HOOK_SIG(casey_start) { - exec_command(app, cmdid_hide_scrollbar); + exec_command(app, hide_scrollbar); exec_command(app, cmdid_open_panel_vsplit); - exec_command(app, cmdid_hide_scrollbar); + exec_command(app, hide_scrollbar); exec_command(app, cmdid_change_active_panel); app->change_theme(app, literal("Handmade Hero")); diff --git a/power/4coder_experiments.cpp b/power/4coder_experiments.cpp index 09435c06..ed6ebe9f 100644 --- a/power/4coder_experiments.cpp +++ b/power/4coder_experiments.cpp @@ -273,6 +273,7 @@ get_bindings(void *data, int size){ set_hook(context, hook_start, experimental_start_hook); set_open_file_hook(context, my_file_settings); + set_input_filter(context, my_suppress_mouse_filter); set_command_caller(context, my_command_caller); set_scroll_rule(context, smooth_scroll_rule); diff --git a/win32_4ed.cpp b/win32_4ed.cpp index e18905f4..0e8ce163 100644 --- a/win32_4ed.cpp +++ b/win32_4ed.cpp @@ -1228,6 +1228,7 @@ Win32LoadSystemCode(){ win32vars.system.file_exists = File_Exists; win32vars.system.directory_cd = Directory_CD; win32vars.system.get_4ed_path = Get_4ed_Path; + win32vars.system.show_mouse_cursor = Show_Mouse_Cursor; win32vars.system.post_clipboard = system_post_clipboard; diff --git a/win32_api_impl.cpp b/win32_api_impl.cpp index fae43fae..38260e2c 100644 --- a/win32_api_impl.cpp +++ b/win32_api_impl.cpp @@ -107,5 +107,13 @@ DOC_RETURN(returns non-zero on success, returns zero on failure) return(system_get_binary_path(&str)); } +// TODO(allen): add a "shown but auto-hides on timer" setting here. +API_EXPORT void +Show_Mouse_Cursor(Application_Links *app, int show)/* +DOC_PARAM(show, The show state to put the mouse cursor into. If this is 1 the mouse cursor is shown. If it is 0 the mouse cursor is hidden.) +*/{ + ShowCursor(show); +} + // BOTTOM