added mouse suppression mode

master
Allen Webster 2016-06-29 15:11:37 -04:00
parent cb6d1d8953
commit 4023b96560
13 changed files with 111 additions and 10 deletions

View File

@ -164,6 +164,9 @@ This is the documentation for alpha 4.0.9 super! The documentation has been made
<li>
<a href='#get_4ed_path_doc'>get_4ed_path</a>
</li>
<li>
<a href='#show_mouse_cursor_doc'>show_mouse_cursor</a>
</li>
</ul>
<h3 style='margin-top: 5mm; margin-bottom: 5mm;'>&sect;2.2 Descriptions</h3>
<div id='exec_command_doc' style='margin-bottom: 1cm;'>
@ -983,6 +986,16 @@ also be used with rel set to ".." to traverse to parent folders.</div></div><hr>
<div style='margin-bottom: 6mm;'><div style='margin-left: 5mm; margin-right: 5mm;'>the maximum capacity of the output buffer</div></div>
</div>
<div style='margin-top: 3mm; margin-bottom: 3mm; color: #309030;'><b><i>Return</i></b></div><div style='margin-left: 5mm; margin-right: 5mm;'>returns non-zero on success, returns zero on failure</div></div><hr>
<div id='show_mouse_cursor_doc' style='margin-bottom: 1cm;'>
<h4>&sect;2.2.46: show_mouse_cursor</h4>
<div style='font-family: "Courier New", Courier, monospace; text-align: left; margin-top: 3mm; margin-bottom: 3mm; font-size: .95em; background: #DFDFDF; padding: 0.25em;'>void app->show_mouse_cursor(
<div style='margin-left: 4mm;'>Application_Links *app,<br>int show<br></div>)
</div>
<div style='margin-top: 3mm; margin-bottom: 3mm; color: #309030;'><b><i>Parameters</i></b></div><div>
<div style='font-weight: 600;'>show</div>
<div style='margin-bottom: 6mm;'><div style='margin-left: 5mm; margin-right: 5mm;'>The show state to put the mouse cursor into. If this is non-zero the mouse cursor is shown.</div></div>
</div>
</div><hr>
</div>
</body>
</html>

View File

@ -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;

View File

@ -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)

View File

@ -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);

View File

@ -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;

14
4ed.cpp
View File

@ -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"
"-<F2> 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"

View File

@ -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)/*

View File

@ -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;

View File

@ -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;

View File

@ -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"));

View File

@ -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);

View File

@ -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;

View File

@ -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