From ceb9b6d2177a064723d4341d3631f2022cadcc80 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Thu, 25 Feb 2016 18:52:11 -0500 Subject: [PATCH] replaced Key_Codes with generated enum --- 4coder_custom.cpp | 44 ++++++++++----------- 4coder_custom.h | 44 +-------------------- 4coder_helper.h | 1 - 4coder_keycodes.h | 30 +++++++++++++++ 4ed.cpp | 34 ++++++++-------- 4ed.h | 3 -- 4ed_color_view.cpp | 9 ++--- 4ed_file_view.cpp | 6 +-- 4ed_gui.cpp | 30 ++++++--------- 4ed_interactive_view.cpp | 2 +- 4ed_keyboard.cpp | 15 -------- 4ed_keycodes.h | 30 +++++++++++++++ 4ed_layout.cpp | 6 +-- 4ed_metagen.cpp | 83 ++++++++++++++++++++++++++++++++++++++++ 4ed_win32_keyboard.cpp | 64 +++++++++++++++---------------- win32_4ed.cpp | 14 +++---- 16 files changed, 240 insertions(+), 175 deletions(-) create mode 100644 4coder_keycodes.h create mode 100644 4ed_keycodes.h create mode 100644 4ed_metagen.cpp diff --git a/4coder_custom.cpp b/4coder_custom.cpp index 330ab1d5..4cdb5d96 100644 --- a/4coder_custom.cpp +++ b/4coder_custom.cpp @@ -418,8 +418,8 @@ extern "C" GET_BINDING_DATA(get_bindings){ inherit_map(context, mapid_file); // NOTE(allen|a3.1): Children can override parent's bindings. - bind(context, codes->right, MDFR_CTRL, cmdid_seek_alphanumeric_or_camel_right); - bind(context, codes->left, MDFR_CTRL, cmdid_seek_alphanumeric_or_camel_left); + bind(context, key_right, MDFR_CTRL, cmdid_seek_alphanumeric_or_camel_right); + bind(context, key_left, MDFR_CTRL, cmdid_seek_alphanumeric_or_camel_left); // NOTE(allen|a3.2): Specific keys can override vanilla keys, // and write character writes whichever character corresponds @@ -456,26 +456,26 @@ extern "C" GET_BINDING_DATA(get_bindings){ // It is possible to override this binding for individual keys. bind_vanilla_keys(context, cmdid_write_character); - bind(context, codes->left, MDFR_NONE, cmdid_move_left); - bind(context, codes->right, MDFR_NONE, cmdid_move_right); - bind(context, codes->del, MDFR_NONE, cmdid_delete); - bind(context, codes->back, MDFR_NONE, cmdid_backspace); - bind(context, codes->up, MDFR_NONE, cmdid_move_up); - bind(context, codes->down, MDFR_NONE, cmdid_move_down); - bind(context, codes->end, MDFR_NONE, cmdid_seek_end_of_line); - bind(context, codes->home, MDFR_NONE, cmdid_seek_beginning_of_line); - bind(context, codes->page_up, MDFR_NONE, cmdid_page_up); - bind(context, codes->page_down, MDFR_NONE, cmdid_page_down); + bind(context, key_left, MDFR_NONE, cmdid_move_left); + bind(context, key_right, MDFR_NONE, cmdid_move_right); + bind(context, key_del, MDFR_NONE, cmdid_delete); + bind(context, key_back, MDFR_NONE, cmdid_backspace); + bind(context, key_up, MDFR_NONE, cmdid_move_up); + bind(context, key_down, MDFR_NONE, cmdid_move_down); + bind(context, key_end, MDFR_NONE, cmdid_seek_end_of_line); + bind(context, key_home, MDFR_NONE, cmdid_seek_beginning_of_line); + bind(context, key_page_up, MDFR_NONE, cmdid_page_up); + bind(context, key_page_down, MDFR_NONE, cmdid_page_down); - bind(context, codes->right, MDFR_CTRL, cmdid_seek_whitespace_right); - bind(context, codes->left, MDFR_CTRL, cmdid_seek_whitespace_left); - bind(context, codes->up, MDFR_CTRL, cmdid_seek_whitespace_up); - bind(context, codes->down, MDFR_CTRL, cmdid_seek_whitespace_down); + bind(context, key_right, MDFR_CTRL, cmdid_seek_whitespace_right); + bind(context, key_left, MDFR_CTRL, cmdid_seek_whitespace_left); + bind(context, key_up, MDFR_CTRL, cmdid_seek_whitespace_up); + bind(context, key_down, MDFR_CTRL, cmdid_seek_whitespace_down); - bind(context, codes->up, MDFR_ALT, move_up_10); - bind(context, codes->down, MDFR_ALT, move_down_10); + bind(context, key_up, MDFR_ALT, move_up_10); + bind(context, key_down, MDFR_ALT, move_down_10); - bind(context, codes->back, MDFR_CTRL, backspace_word); + bind(context, key_back, MDFR_CTRL, backspace_word); bind(context, ' ', MDFR_CTRL, cmdid_set_mark); bind(context, 'm', MDFR_CTRL, cmdid_cursor_mark_swap); @@ -486,9 +486,9 @@ extern "C" GET_BINDING_DATA(get_bindings){ bind(context, 'Z', MDFR_CTRL, cmdid_timeline_scrub); bind(context, 'z', MDFR_CTRL, cmdid_undo); bind(context, 'y', MDFR_CTRL, cmdid_redo); - bind(context, codes->left, MDFR_ALT, cmdid_increase_rewind_speed); - bind(context, codes->right, MDFR_ALT, cmdid_increase_fastforward_speed); - bind(context, codes->down, MDFR_ALT, cmdid_stop_rewind_fastforward); + bind(context, key_left, MDFR_ALT, cmdid_increase_rewind_speed); + bind(context, key_right, MDFR_ALT, cmdid_increase_fastforward_speed); + bind(context, key_down, MDFR_ALT, cmdid_stop_rewind_fastforward); bind(context, 'h', MDFR_CTRL, cmdid_history_backward); bind(context, 'H', MDFR_CTRL, cmdid_history_forward); bind(context, 'd', MDFR_CTRL, cmdid_delete_range); diff --git a/4coder_custom.h b/4coder_custom.h index a5eb4e06..96cca109 100644 --- a/4coder_custom.h +++ b/4coder_custom.h @@ -1,54 +1,14 @@ +#include "4coder_keycodes.h" #include "4coder_buffer_types.h" #define MDFR_NONE 0 #define MDFR_CTRL 1 #define MDFR_ALT 2 #define MDFR_SHIFT 4 -#define MDFR_NUMPAD 8 typedef unsigned char Code; -struct Key_Codes{ - Code back; - Code up; - Code down; - Code left; - Code right; - Code del; - Code insert; - Code home; - Code end; - Code page_up; - Code page_down; - Code esc; - -#if 0 // TODO(allen): Get these working sometime - union{ - struct{ - Code f1; - Code f2; - Code f3; - Code f4; - Code f5; - Code f6; - Code f7; - Code f8; - - Code f9; - Code f10; - Code f11; - Code f12; - Code f13; - Code f14; - Code f15; - Code f16; - }; - Code f[16]; - }; -#endif -}; - enum Command_ID{ cmdid_null, cmdid_write_character, @@ -261,7 +221,7 @@ struct String{ }; #endif -#define GET_BINDING_DATA(name) int name(void *data, int size, Key_Codes *codes) +#define GET_BINDING_DATA(name) int name(void *data, int size) #define SET_EXTRA_FONT_SIG(name) void name(Extra_Font *font_out) #define CUSTOM_COMMAND_SIG(name) void name(void *cmd_context, struct Application_Links *app) #define HOOK_SIG(name) void name(void *cmd_context, struct Application_Links *app) diff --git a/4coder_helper.h b/4coder_helper.h index 992c0b2c..2b8c01fb 100644 --- a/4coder_helper.h +++ b/4coder_helper.h @@ -226,7 +226,6 @@ get_range(File_View_Summary *view){ range.max = view->cursor.pos; range.min = view->mark.pos; } - return(range); } diff --git a/4coder_keycodes.h b/4coder_keycodes.h new file mode 100644 index 00000000..7ecafcc6 --- /dev/null +++ b/4coder_keycodes.h @@ -0,0 +1,30 @@ +enum Key_Code{ +key_back = 1, +key_up = 2, +key_down = 3, +key_left = 4, +key_right = 5, +key_del = 6, +key_insert = 7, +key_home = 8, +key_end = 11, +key_page_up = 12, +key_page_down = 13, +key_esc = 14, +key_f1 = 127, +key_f2 = 128, +key_f3 = 129, +key_f4 = 130, +key_f5 = 131, +key_f6 = 132, +key_f7 = 133, +key_f8 = 134, +key_f9 = 135, +key_f10 = 136, +key_f11 = 137, +key_f12 = 138, +key_f13 = 139, +key_f14 = 140, +key_f15 = 141, +key_f16 = 142, +}; diff --git a/4ed.cpp b/4ed.cpp index 0aa810d3..3220020d 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -2495,7 +2495,7 @@ app_links_init(System_Functions *system){ #if FRED_INTERNAL internal void -setup_debug_commands(Command_Map *commands, Partition *part, Key_Codes *codes, Command_Map *parent){ +setup_debug_commands(Command_Map *commands, Partition *part, Command_Map *parent){ map_init(commands, part, 6, parent); map_add(commands, 'm', MDFR_NONE, command_debug_memory); @@ -2504,7 +2504,7 @@ setup_debug_commands(Command_Map *commands, Partition *part, Key_Codes *codes, C #endif internal void -setup_ui_commands(Command_Map *commands, Partition *part, Key_Codes *codes, Command_Map *parent){ +setup_ui_commands(Command_Map *commands, Partition *part, Command_Map *parent){ map_init(commands, part, 32, parent); commands->vanilla_keyboard_default.function = command_null; @@ -2515,22 +2515,22 @@ setup_ui_commands(Command_Map *commands, Partition *part, Key_Codes *codes, Comm u8 mdfr_array[] = {MDFR_NONE, MDFR_SHIFT, MDFR_CTRL, MDFR_SHIFT | MDFR_CTRL}; for (i32 i = 0; i < 4; ++i){ mdfr = mdfr_array[i]; - map_add(commands, codes->left, mdfr, command_null); - map_add(commands, codes->right, mdfr, command_null); - map_add(commands, codes->up, mdfr, command_null); - map_add(commands, codes->down, mdfr, command_null); - map_add(commands, codes->back, mdfr, command_null); - map_add(commands, codes->esc, mdfr, command_close_minor_view); + map_add(commands, key_left, mdfr, command_null); + map_add(commands, key_right, mdfr, command_null); + map_add(commands, key_up, mdfr, command_null); + map_add(commands, key_down, mdfr, command_null); + map_add(commands, key_back, mdfr, command_null); + map_add(commands, key_esc, mdfr, command_close_minor_view); } } internal void -setup_file_commands(Command_Map *commands, Partition *part, Key_Codes *codes, Command_Map *parent){ +setup_file_commands(Command_Map *commands, Partition *part, Command_Map *parent){ map_init(commands, part, 10, parent); } internal void -setup_top_commands(Command_Map *commands, Partition *part, Key_Codes *codes, Command_Map *parent){ +setup_top_commands(Command_Map *commands, Partition *part, Command_Map *parent){ map_init(commands, part, 5, parent); } @@ -3107,7 +3107,7 @@ App_Init_Sig(app_init){ // TODO(allen): Use a giant bubble of general memory for this. // So that it doesn't interfere with the command maps as they allocate // their own memory. - i32 wanted_size = vars->config_api.get_bindings(data, size, codes); + i32 wanted_size = vars->config_api.get_bindings(data, size); b32 did_top = 0; b32 did_file = 0; @@ -3212,16 +3212,16 @@ App_Init_Sig(app_init){ } } - if (!did_top) setup_top_commands(&vars->map_top, &vars->mem.part, codes, global); - if (!did_file) setup_file_commands(&vars->map_file, &vars->mem.part, codes, global); + if (!did_top) setup_top_commands(&vars->map_top, &vars->mem.part, global); + if (!did_file) setup_file_commands(&vars->map_file, &vars->mem.part, global); #if !defined(FRED_SUPER) vars->hooks[hook_start] = 0; #endif - setup_ui_commands(&vars->map_ui, &vars->mem.part, codes, global); + setup_ui_commands(&vars->map_ui, &vars->mem.part, global); #if FRED_INTERNAL - setup_debug_commands(&vars->map_debug, &vars->mem.part, codes, global); + setup_debug_commands(&vars->map_debug, &vars->mem.part, global); #endif if (vars->hooks[hook_open_file] == 0){ @@ -3785,7 +3785,7 @@ App_Step_Sig(app_step){ Handle_Command_Function *handle_command = 0; if (view) handle_command = view->handle_command; if (handle_command){ - handle_command(system, view, &command_data, cmd, key, codes); + handle_command(system, view, &command_data, cmd, key); app_result.redraw = 1; } else{ @@ -3815,13 +3815,11 @@ App_Step_Sig(app_step){ Input_Summary dead_input = {}; dead_input.mouse.mx = mouse_data.mx; dead_input.mouse.my = mouse_data.my; - dead_input.codes = codes; Input_Summary active_input = {}; dead_input.mouse.mx = mouse_data.mx; dead_input.mouse.my = mouse_data.my; active_input.keys = key_data; - active_input.codes = codes; // NOTE(allen): pass raw input to the panels { diff --git a/4ed.h b/4ed.h index ce063968..4d96a602 100644 --- a/4ed.h +++ b/4ed.h @@ -81,7 +81,6 @@ struct Mouse_Summary{ struct Input_Summary{ Mouse_Summary mouse; Key_Summary keys; - Key_Codes *codes; }; struct Command_Line_Parameters{ @@ -115,7 +114,6 @@ name(System_Functions *system, \ Render_Target *target, \ Application_Memory *memory, \ Exchange *exchange, \ - Key_Codes *codes, \ String clipboard, \ String current_directory, \ Custom_API api) @@ -140,7 +138,6 @@ struct Application_Step_Result{ #define App_Step_Sig(name) void \ name(System_Functions *system, \ - Key_Codes *codes, \ Key_Input_Data *input, \ Mouse_State *mouse, \ Render_Target *target, \ diff --git a/4ed_color_view.cpp b/4ed_color_view.cpp index 2b170a67..d6b3601c 100644 --- a/4ed_color_view.cpp +++ b/4ed_color_view.cpp @@ -452,21 +452,20 @@ do_channel_field(i32 sub_id, Color_UI *ui, u8 *channel, Channel_Field_Type ftype i32 indx = ui->state.selected.sub_id2; if (ui->state.input_stage){ Key_Summary *keys = ui->state.keys; - Key_Codes *codes = ui->state.codes; for (i32 key_i = 0; key_i < keys->count; ++key_i){ Key_Event_Data key = get_single_key(keys, key_i); - if (key.keycode == codes->right){ + if (key.keycode == key_right){ ++indx; if (indx > digit_count-1) indx = 0; } - if (key.keycode == codes->left){ + if (key.keycode == key_left){ --indx; if (indx < 0) indx = digit_count-1; } i32 new_value = *channel; - if (key.keycode == codes->up || key.keycode == codes->down){ + if (key.keycode == key_up || key.keycode == key_down){ i32 place = digit_count-1-indx; i32 base = (ftype == CF_DEC)?10:0x10; i32 step_amount = 1; @@ -474,7 +473,7 @@ do_channel_field(i32 sub_id, Color_UI *ui, u8 *channel, Channel_Field_Type ftype step_amount *= base; --place; } - if (key.keycode == codes->down){ + if (key.keycode == key_down){ step_amount = 0 - step_amount; } new_value += step_amount; diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index cd7a8968..feac1325 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -3406,7 +3406,7 @@ HANDLE_COMMAND_SIG(handle_command_file_view){ if (binding.function) binding.function(system, command, binding); file_view->mode = file_view->next_mode; - if (key.keycode == codes->esc) + if (key.keycode == key_esc) view_set_widget(file_view, FWIDG_NONE); }break; @@ -3415,7 +3415,7 @@ HANDLE_COMMAND_SIG(handle_command_file_view){ #if BUFFER_EXPERIMENT_SCALPEL <= 3 String *string = &file_view->isearch.str; Single_Line_Input_Step result = - app_single_line_input_step(system, codes, key, string); + app_single_line_input_step(system, key, string); if (result.made_a_change || binding.function == command_search || @@ -3500,7 +3500,7 @@ HANDLE_COMMAND_SIG(handle_command_file_view){ { String *string = &file_view->gotoline.str; Single_Line_Input_Step result = - app_single_number_input_step(system, codes, key, string); + app_single_number_input_step(system, key, string); if (result.hit_newline || result.hit_ctrl_newline){ i32 line_number = str_to_int(*string); diff --git a/4ed_gui.cpp b/4ed_gui.cpp index d0c26e44..9ed08e17 100644 --- a/4ed_gui.cpp +++ b/4ed_gui.cpp @@ -149,12 +149,11 @@ struct Single_Line_Mode{ }; internal Single_Line_Input_Step -app_single_line_input_core(System_Functions *system, - Key_Codes *codes, Working_Set *working_set, +app_single_line_input_core(System_Functions *system, Working_Set *working_set, Key_Event_Data key, Single_Line_Mode mode){ Single_Line_Input_Step result = {}; - if (key.keycode == codes->back){ + if (key.keycode == key_back){ result.hit_backspace = 1; if (mode.string->size > 0){ result.made_a_change = 1; @@ -221,7 +220,7 @@ app_single_line_input_core(System_Functions *system, } } - else if (key.keycode == codes->esc){ + else if (key.keycode == key_esc){ result.hit_esc = 1; result.made_a_change = 1; } @@ -251,16 +250,15 @@ app_single_line_input_core(System_Functions *system, } inline Single_Line_Input_Step -app_single_line_input_step(System_Functions *system, - Key_Codes *codes, Key_Event_Data key, String *string){ +app_single_line_input_step(System_Functions *system, Key_Event_Data key, String *string){ Single_Line_Mode mode = {}; mode.type = SINGLE_LINE_STRING; mode.string = string; - return app_single_line_input_core(system, codes, 0, key, mode); + return app_single_line_input_core(system, 0, key, mode); } inline Single_Line_Input_Step -app_single_file_input_step(System_Functions *system, Key_Codes *codes, +app_single_file_input_step(System_Functions *system, Working_Set *working_set, Key_Event_Data key, String *string, Hot_Directory *hot_directory, b32 fast_folder_select, b32 try_to_match, b32 case_sensitive){ @@ -271,12 +269,11 @@ app_single_file_input_step(System_Functions *system, Key_Codes *codes, mode.fast_folder_select = fast_folder_select; mode.try_to_match = try_to_match; mode.case_sensitive = case_sensitive; - return app_single_line_input_core(system, codes, working_set, key, mode); + return app_single_line_input_core(system, working_set, key, mode); } inline Single_Line_Input_Step -app_single_number_input_step(System_Functions *system, Key_Codes *codes, - Key_Event_Data key, String *string){ +app_single_number_input_step(System_Functions *system, Key_Event_Data key, String *string){ Single_Line_Input_Step result = {}; Single_Line_Mode mode = {}; mode.type = SINGLE_LINE_STRING; @@ -284,7 +281,7 @@ app_single_number_input_step(System_Functions *system, Key_Codes *codes, char c = (char)key.character; if (c == 0 || c == '\n' || char_is_numeric(c)) - result = app_single_line_input_core(system, codes, 0, key, mode); + result = app_single_line_input_core(system, 0, key, mode); return result; } @@ -307,7 +304,6 @@ struct UI_State{ Font_Set *font_set; Mouse_Summary *mouse; Key_Summary *keys; - Key_Codes *codes; Working_Set *working_set; i16 font_id; @@ -509,7 +505,6 @@ ui_state_init(UI_State *state_in, Render_Target *target, Input_Summary *user_inp if (user_input){ state.mouse = &user_input->mouse; state.keys = &user_input->keys; - state.codes = user_input->codes; } state.selected = state_in->selected; state.hot = state_in->hot; @@ -678,7 +673,7 @@ ui_do_text_field_input(UI_State *state, String *str){ else if (c == '\n'){ result = 1; } - else if (key.keycode == state->codes->back && str->size > 0){ + else if (key.keycode == key_back && str->size > 0){ str->str[--str->size] = 0; } } @@ -700,8 +695,7 @@ ui_do_file_field_input(System_Functions *system, UI_State *state, for (key_i = 0; key_i < keys->count; ++key_i){ key = get_single_key(keys, key_i); step = - app_single_file_input_step(system, state->codes, - state->working_set, key, str, + app_single_file_input_step(system, state->working_set, key, str, hot_dir, 1, try_to_match, case_sensitive); if ((step.hit_newline || step.hit_ctrl_newline) && !step.no_file_match) result = 1; } @@ -717,7 +711,7 @@ ui_do_line_field_input(System_Functions *system, Key_Event_Data key = get_single_key(keys, key_i); terminate_with_null(string); Single_Line_Input_Step step = - app_single_line_input_step(system, state->codes, key, string); + app_single_line_input_step(system, key, string); if (step.hit_newline || step.hit_ctrl_newline) result = 1; } return result; diff --git a/4ed_interactive_view.cpp b/4ed_interactive_view.cpp index 3cdfcde4..32d8643b 100644 --- a/4ed_interactive_view.cpp +++ b/4ed_interactive_view.cpp @@ -170,7 +170,7 @@ step_draw_int_view(System_Functions *system, Interactive_View *view, case 'n': case 'N': action = 1; break; case 's': case 'S': action = 2; break; } - if (action == -1 && key.keycode == state.codes->esc) action = 1; + if (action == -1 && key.keycode == key_esc) action = 1; if (action != -1) break; } } diff --git a/4ed_keyboard.cpp b/4ed_keyboard.cpp index 2db8ccd7..54975f49 100644 --- a/4ed_keyboard.cpp +++ b/4ed_keyboard.cpp @@ -11,21 +11,6 @@ globalvar u8 keycode_lookup_table[255]; -internal void -set_dynamic_key_names(Key_Codes *codes){ - u8 code = 1; - u8 *codes_array = (u8*)codes; - for (i32 i = 0; i < sizeof(*codes)/sizeof(codes->up);){ - switch (code){ - case '\n': code++; break; - case '\t': code++; break; - case 0x20: code = 0x7F; break; - default: - codes_array[i++] = code++; - } - } -} - inline u8 keycode_lookup(u8 system_code){ return keycode_lookup_table[system_code]; diff --git a/4ed_keycodes.h b/4ed_keycodes.h new file mode 100644 index 00000000..c8d6b77f --- /dev/null +++ b/4ed_keycodes.h @@ -0,0 +1,30 @@ +enum Key_Code{ +key_back = 1, +key_up = 2, +key_down = 3, +key_left = 4, +key_right = 5, +key_del = 6, +key_insert = 7, +key_home = 8, +key_end = 11, +key_page_up = 12, +key_page_down = 13, +key_esc = 14, +key_f1 = 127, +key_f2 = 128, +key_f3 = 129, +key_f4 = 130, +key_f5 = 131, +key_f6 = 132, +key_f7 = 133, +key_f8 = 134, +key_f9 = 135, +key_f10 = 136, +key_f11 = 137, +key_f12 = 138, +key_f13 = 139, +key_f14 = 140, +key_f15 = 141, +key_f15 = 142, +} diff --git a/4ed_layout.cpp b/4ed_layout.cpp index 4a973db1..3e947178 100644 --- a/4ed_layout.cpp +++ b/4ed_layout.cpp @@ -8,10 +8,6 @@ */ // TOP -// TODO(allen): -// -// BUGS -// struct Interactive_Style{ u32 bar_color; @@ -49,7 +45,7 @@ typedef Do_View_Sig(Do_View_Function); #define HANDLE_COMMAND_SIG(name) \ void (name)(System_Functions *system, View *view, \ Command_Data *command, Command_Binding binding, \ - Key_Event_Data key, Key_Codes *codes) + Key_Event_Data key) typedef HANDLE_COMMAND_SIG(Handle_Command_Function); diff --git a/4ed_metagen.cpp b/4ed_metagen.cpp new file mode 100644 index 00000000..c9a82877 --- /dev/null +++ b/4ed_metagen.cpp @@ -0,0 +1,83 @@ +/* + * Mr. 4th Dimention - Allen Webster + * + * 25.02.2016 + * + * File editing view for 4coder + * + */ + +// TOP + +#define ArrayCount(a) (sizeof(a)/sizeof(*a)) + +#include +#include +#include + +char *keys_that_need_codes[] = { + "back", + "up", + "down", + "left", + "right", + "del", + "insert", + "home", + "end", + "page_up", + "page_down", + "esc", + + "f1", + "f2", + "f3", + "f4", + "f5", + "f6", + "f7", + "f8", + + "f9", + "f10", + "f11", + "f12", + "f13", + "f14", + "f15", + "f16", +}; + +void generate_keycode_enum(){ + FILE *file; + char filename[] = "4coder_keycodes.h"; + int i, count; + unsigned char code = 1; + + file = fopen(filename, "wb"); + fprintf(file, "enum Key_Code{\n"); + count = ArrayCount(keys_that_need_codes); + for (i = 0; i < count;){ + if (strcmp(keys_that_need_codes[i], "f1") == 0 && code < 0x7F){ + code = 0x7F; + } + switch (code){ + case '\n': code++; break; + case '\t': code++; break; + case 0x20: code = 0x7F; break; + default: + fprintf(file, "key_%s = %d,\n", keys_that_need_codes[i++], code++); + break; + } + } + fprintf(file, "};\n"); + fclose(file); + printf("gen success: %s\n", filename); +} + +int main(){ + generate_keycode_enum(); +} + +// BOTTOM + diff --git a/4ed_win32_keyboard.cpp b/4ed_win32_keyboard.cpp index ae1fd7b0..dbe837c1 100644 --- a/4ed_win32_keyboard.cpp +++ b/4ed_win32_keyboard.cpp @@ -1,33 +1,31 @@ -/* - * Mr. 4th Dimention - Allen Webster - * - * 12.17.2014 - * - * Win32-US Keyboard layer for 4coder - * - */ - -// TOP - -#include "4ed_keyboard.cpp" - -internal void -keycode_init(Key_Codes *codes){ - set_dynamic_key_names(codes); - - keycode_lookup_table[VK_BACK] = codes->back; - keycode_lookup_table[VK_DELETE] = codes->del; - keycode_lookup_table[VK_UP] = codes->up; - keycode_lookup_table[VK_DOWN] = codes->down; - keycode_lookup_table[VK_LEFT] = codes->left; - keycode_lookup_table[VK_RIGHT] = codes->right; - keycode_lookup_table[VK_INSERT] = codes->insert; - keycode_lookup_table[VK_HOME] = codes->home; - keycode_lookup_table[VK_END] = codes->end; - keycode_lookup_table[VK_PRIOR] = codes->page_up; - keycode_lookup_table[VK_NEXT] = codes->page_down; - keycode_lookup_table[VK_ESCAPE] = codes->esc; -} - -// BOTTOM - +/* + * Mr. 4th Dimention - Allen Webster + * + * 12.17.2014 + * + * Win32-US Keyboard layer for 4coder + * + */ + +// TOP + +#include "4ed_keyboard.cpp" + +internal void +keycode_init(){ + keycode_lookup_table[VK_BACK] = key_back; + keycode_lookup_table[VK_DELETE] = key_del; + keycode_lookup_table[VK_UP] = key_up; + keycode_lookup_table[VK_DOWN] = key_down; + keycode_lookup_table[VK_LEFT] = key_left; + keycode_lookup_table[VK_RIGHT] = key_right; + keycode_lookup_table[VK_INSERT] = key_insert; + keycode_lookup_table[VK_HOME] = key_home; + keycode_lookup_table[VK_END] = key_end; + keycode_lookup_table[VK_PRIOR] = key_page_up; + keycode_lookup_table[VK_NEXT] = key_page_down; + keycode_lookup_table[VK_ESCAPE] = key_esc; +} + +// BOTTOM + diff --git a/win32_4ed.cpp b/win32_4ed.cpp index 86229644..8ebce089 100644 --- a/win32_4ed.cpp +++ b/win32_4ed.cpp @@ -107,7 +107,6 @@ struct Win32_Vars{ HANDLE update_loop_thread; DWORD update_loop_thread_id; - Key_Codes key_codes; Win32_Input_Chunk input_chunk; b32 lctrl_lalt_is_altgr; @@ -1385,7 +1384,6 @@ UpdateLoop(LPVOID param){ result.lctrl_lalt_is_altgr = win32vars.lctrl_lalt_is_altgr; win32vars.app.step(win32vars.system, - &win32vars.key_codes, &input_data, &mouse, &win32vars.target, @@ -1586,8 +1584,6 @@ main(int argc, char **argv){ win32vars.start_time = ((u64)filetime.dwHighDateTime << 32) | (filetime.dwLowDateTime); win32vars.start_time /= 10; - keycode_init(&win32vars.key_codes); - #ifdef FRED_SUPER char *custom_file_default = "4coder_custom.dll"; char *custom_file; @@ -1787,12 +1783,12 @@ main(int argc, char **argv){ Font_Load_Parameters params[32]; sysshared_init_font_params(&win32vars.fnt, params, ArrayCount(params)); - + win32vars.app.init(win32vars.system, &win32vars.target, - &memory_vars, &exchange_vars, &win32vars.key_codes, - win32vars.clipboard_contents, current_directory, - win32vars.custom_api); - + &memory_vars, &exchange_vars, + win32vars.clipboard_contents, current_directory, + win32vars.custom_api); + system_free_memory(current_directory.str); win32vars.input_chunk.pers.keep_playing = 1;