seeing debug mouse events and mouse consumption

This commit is contained in:
Allen Webster 2016-06-07 14:52:40 -04:00
parent b41bdc9995
commit 412ad98864
8 changed files with 164 additions and 84 deletions

View File

@ -11,6 +11,8 @@ key_end = 11,
key_page_up = 12, key_page_up = 12,
key_page_down = 13, key_page_down = 13,
key_esc = 14, key_esc = 14,
key_mouse_left = 15,
key_mouse_right = 16,
key_f1 = 127, key_f1 = 127,
key_f2 = 128, key_f2 = 128,
key_f3 = 129, key_f3 = 129,
@ -44,6 +46,8 @@ case key_end: result = "end"; *size = sizeof("end")-1; break;
case key_page_up: result = "page_up"; *size = sizeof("page_up")-1; break; case key_page_up: result = "page_up"; *size = sizeof("page_up")-1; break;
case key_page_down: result = "page_down"; *size = sizeof("page_down")-1; break; case key_page_down: result = "page_down"; *size = sizeof("page_down")-1; break;
case key_esc: result = "esc"; *size = sizeof("esc")-1; break; case key_esc: result = "esc"; *size = sizeof("esc")-1; break;
case key_mouse_left: result = "mouse_left"; *size = sizeof("mouse_left")-1; break;
case key_mouse_right: result = "mouse_right"; *size = sizeof("mouse_right")-1; break;
case key_f1: result = "f1"; *size = sizeof("f1")-1; break; case key_f1: result = "f1"; *size = sizeof("f1")-1; break;
case key_f2: result = "f2"; *size = sizeof("f2")-1; break; case key_f2: result = "f2"; *size = sizeof("f2")-1; break;
case key_f3: result = "f3"; *size = sizeof("f3")-1; break; case key_f3: result = "f3"; *size = sizeof("f3")-1; break;

View File

@ -151,8 +151,8 @@ FSTRING_LINK uint32_t hexstr_to_int(String s);
FSTRING_LINK fstr_bool color_to_hexstr(uint32_t color, String *s_out); FSTRING_LINK fstr_bool color_to_hexstr(uint32_t color, String *s_out);
FSTRING_LINK fstr_bool hexstr_to_color(String s, uint32_t *color); FSTRING_LINK fstr_bool hexstr_to_color(String s, uint32_t *color);
FSTRING_LINK int32_t copy_fast_unsafe(char *dest, char *src); FSTRING_LINK int32_t copy_fast_unsafe(char *dest, char *src);
FSTRING_LINK void copy_fast_unsafe(char *dest, String src); FSTRING_LINK void copy_fast_unsafe(char *dest, String src);
FSTRING_LINK fstr_bool copy_checked(String *dest, String src); FSTRING_LINK fstr_bool copy_checked(String *dest, String src);
FSTRING_LINK fstr_bool copy_partial(String *dest, char *src); FSTRING_LINK fstr_bool copy_partial(String *dest, char *src);
FSTRING_LINK fstr_bool copy_partial(String *dest, String src); FSTRING_LINK fstr_bool copy_partial(String *dest, String src);

83
4ed.cpp
View File

@ -3252,7 +3252,10 @@ App_Step_Sig(app_step){
String clipboard = input->clipboard; String clipboard = input->clipboard;
if (clipboard.str){ if (clipboard.str){
String *dest = working_set_next_clipboard_string(&models->mem.general, &models->working_set, clipboard.size); String *dest =
working_set_next_clipboard_string(&models->mem.general,
&models->working_set,
clipboard.size);
dest->size = eol_convert_in(dest->str, clipboard.str, clipboard.size); dest->size = eol_convert_in(dest->str, clipboard.str, clipboard.size);
} }
@ -3266,7 +3269,8 @@ App_Step_Sig(app_step){
for (dll_items(node, used_nodes)){ for (dll_items(node, used_nodes)){
file = (Editing_File*)node; file = (Editing_File*)node;
time_stamp = system->file_time_stamp(make_c_str(file->name.source_path)); time_stamp =
system->file_time_stamp(make_c_str(file->name.source_path));
if (time_stamp > 0){ if (time_stamp > 0){
file->state.last_sys_write_time = time_stamp; file->state.last_sys_write_time = time_stamp;
@ -3314,14 +3318,33 @@ App_Step_Sig(app_step){
// NOTE(allen): prepare input information // NOTE(allen): prepare input information
Key_Summary key_summary = {0}; Key_Summary key_summary = {0};
for (i32 i = 0; i < input->keys.press_count; ++i){
key_summary.keys[key_summary.count++] = input->keys.press[i];
}
for (i32 i = 0; i < input->keys.hold_count; ++i){
key_summary.keys[key_summary.count++] = input->keys.hold[i];
}
input->mouse.wheel = -input->mouse.wheel; {
for (i32 i = 0; i < input->keys.press_count; ++i){
key_summary.keys[key_summary.count++] = input->keys.press[i];
}
for (i32 i = 0; i < input->keys.hold_count; ++i){
key_summary.keys[key_summary.count++] = input->keys.hold[i];
}
Key_Event_Data mouse_event = {0};
if (input->mouse.press_l ||
input->mouse.press_r){
memcpy(mouse_event.modifiers, input->keys.modifiers, sizeof(input->keys.modifiers));
}
if (input->mouse.press_l){
mouse_event.keycode = key_mouse_left;
key_summary.keys[key_summary.count++] = mouse_event;
}
if (input->mouse.press_r){
mouse_event.keycode = key_mouse_right;
key_summary.keys[key_summary.count++] = mouse_event;
}
input->mouse.wheel = -input->mouse.wheel;
}
// NOTE(allen): detect mouse hover status // NOTE(allen): detect mouse hover status
i32 mx = input->mouse.x; i32 mx = input->mouse.x;
@ -3377,7 +3400,7 @@ App_Step_Sig(app_step){
mouse_divider_id = panel->parent; mouse_divider_id = panel->parent;
which_child = panel->which_child; which_child = panel->which_child;
for (;;){ for (;;){
Divider_And_ID div = layout_get_divider(&models->layout, mouse_divider_id); Divider_And_ID div =layout_get_divider(&models->layout, mouse_divider_id);
if (which_child == mouse_divider_side && if (which_child == mouse_divider_side &&
div.divider->v_divider == mouse_divider_vertical){ div.divider->v_divider == mouse_divider_vertical){
@ -3781,11 +3804,11 @@ App_Step_Sig(app_step){
} }
if (result.consume_keys){ if (result.consume_keys){
consume_input(&available_input, Input_AnyKey, consume_input(&available_input, Input_AnyKey,
"step_file_view"); "file view step");
} }
if (result.consume_keys || result.consume_esc){ if (result.consume_keys || result.consume_esc){
consume_input(&available_input, Input_Esc, consume_input(&available_input, Input_Esc,
"step_file_view"); "file view step");
} }
if (view->changed_context_in_step == 0){ if (view->changed_context_in_step == 0){
@ -3802,6 +3825,14 @@ App_Step_Sig(app_step){
if (ip_result.is_animating){ if (ip_result.is_animating){
app_result.animating = 1; app_result.animating = 1;
} }
if (ip_result.consumed_l){
consume_input(&available_input, Input_MouseLeftButton,
"file view step");
}
if (ip_result.consumed_r){
consume_input(&available_input, Input_MouseRightButton,
"file view step");
}
Assert(view->current_scroll == vars); Assert(view->current_scroll == vars);
*vars = ip_result.vars; *vars = ip_result.vars;
view->scroll_region = ip_result.region; view->scroll_region = ip_result.region;
@ -3888,12 +3919,36 @@ App_Step_Sig(app_step){
Debug_Data *debug = &models->debug; Debug_Data *debug = &models->debug;
i32 count = debug->this_frame_count; i32 count = debug->this_frame_count;
Consumption_Record *record = &available_input.records[Input_Esc]; Consumption_Record *record = 0;
record = &available_input.records[Input_MouseLeftButton];
if (record->consumed && record->consumer[0] != 0){ if (record->consumed && record->consumer[0] != 0){
Debug_Input_Event *event = debug->input_events; Debug_Input_Event *event = debug->input_events;
for (i32 i = 0; i < count; ++i, ++event){ for (i32 i = 0; i < count; ++i, ++event){
if (event->key == key_esc){ if (event->key == key_mouse_left &&
event->consumer[0] == 0){
memcpy(event->consumer, record->consumer, sizeof(record->consumer));
}
}
}
record = &available_input.records[Input_MouseRightButton];
if (record->consumed && record->consumer[0] != 0){
Debug_Input_Event *event = debug->input_events;
for (i32 i = 0; i < count; ++i, ++event){
if (event->key == key_mouse_right &&
event->consumer[0] == 0){
memcpy(event->consumer, record->consumer, sizeof(record->consumer));
}
}
}
record = &available_input.records[Input_Esc];
if (record->consumed && record->consumer[0] != 0){
Debug_Input_Event *event = debug->input_events;
for (i32 i = 0; i < count; ++i, ++event){
if (event->key == key_esc &&
event->consumer[0] == 0){
memcpy(event->consumer, record->consumer, sizeof(record->consumer)); memcpy(event->consumer, record->consumer, sizeof(record->consumer));
} }
} }

4
4ed.h
View File

@ -31,6 +31,8 @@ struct Key_Input_Data{
Key_Event_Data hold[KEY_INPUT_BUFFER_SIZE]; Key_Event_Data hold[KEY_INPUT_BUFFER_SIZE];
i32 press_count; i32 press_count;
i32 hold_count; i32 hold_count;
char modifiers[MDFR_INDEX_COUNT];
}; };
inline Key_Input_Data inline Key_Input_Data
key_input_data_zero(){ key_input_data_zero(){
@ -40,7 +42,7 @@ key_input_data_zero(){
struct Key_Summary{ struct Key_Summary{
i32 count; i32 count;
Key_Event_Data keys[KEY_INPUT_BUFFER_DSIZE]; Key_Event_Data keys[KEY_INPUT_BUFFER_DSIZE + 2];
}; };
inline Key_Event_Data inline Key_Event_Data

View File

@ -24,7 +24,7 @@ struct App_Settings{
}; };
struct Debug_Input_Event{ struct Debug_Input_Event{
char key; Code key;
char consumer[32]; char consumer[32];

View File

@ -3582,7 +3582,7 @@ view_end_cursor_scroll_updates(View *view){
} }
internal b32 internal b32
file_step(View *view, i32_Rect region, Input_Summary *user_input, b32 is_active){ file_step(View *view, i32_Rect region, Input_Summary *user_input, b32 is_active, b32 *consumed_l){
i32 is_animating = 0; i32 is_animating = 0;
Editing_File *file = view->file_data.file; Editing_File *file = view->file_data.file;
if (file && !file->is_loading){ if (file && !file->is_loading){
@ -3602,6 +3602,7 @@ file_step(View *view, i32_Rect region, Input_Summary *user_input, b32 is_active)
if (ry >= 0){ if (ry >= 0){
if (rx >= 0 && rx < max_x && ry >= 0 && ry < max_visible_y){ if (rx >= 0 && rx < max_x && ry >= 0 && ry < max_visible_y){
*consumed_l = true;
view_cursor_move(view, view_cursor_move(view,
rx + scroll_vars.scroll_x, rx + scroll_vars.scroll_x,
ry + scroll_vars.scroll_y, ry + scroll_vars.scroll_y,
@ -4612,9 +4613,10 @@ view_get_scroll_y(View *view){
return(v); return(v);
} }
internal void internal b32
click_button_input(GUI_Target *target, GUI_Session *session, Input_Summary *user_input, click_button_input(GUI_Target *target, GUI_Session *session, Input_Summary *user_input,
GUI_Interactive *b, b32 *is_animating){ GUI_Interactive *b, b32 *is_animating){
b32 result = 0;
i32 mx = user_input->mouse.x; i32 mx = user_input->mouse.x;
i32 my = user_input->mouse.y; i32 my = user_input->mouse.y;
@ -4623,6 +4625,7 @@ click_button_input(GUI_Target *target, GUI_Session *session, Input_Summary *user
if (user_input->mouse.press_l){ if (user_input->mouse.press_l){
target->mouse_hot = b->id; target->mouse_hot = b->id;
*is_animating = 1; *is_animating = 1;
result = 1;
} }
if (user_input->mouse.release_l && gui_id_eq(target->mouse_hot, b->id)){ if (user_input->mouse.release_l && gui_id_eq(target->mouse_hot, b->id)){
target->active = b->id; target->active = b->id;
@ -4633,6 +4636,7 @@ click_button_input(GUI_Target *target, GUI_Session *session, Input_Summary *user
else if (gui_id_eq(target->hover, b->id)){ else if (gui_id_eq(target->hover, b->id)){
target->hover = gui_id_zero(); target->hover = gui_id_zero();
} }
return(result);
} }
internal b32 internal b32
@ -4661,6 +4665,8 @@ struct Input_Process_Result{
GUI_Scroll_Vars vars; GUI_Scroll_Vars vars;
i32_Rect region; i32_Rect region;
b32 is_animating; b32 is_animating;
b32 consumed_l;
b32 consumed_r;
}; };
internal Input_Process_Result internal Input_Process_Result
@ -4706,12 +4712,12 @@ do_step_file_view(System_Functions *system,
if (interpret_result.auto_activate){ if (interpret_result.auto_activate){
target->auto_hot = gui_id_zero(); target->auto_hot = gui_id_zero();
target->active = b->id; target->active = b->id;
result.is_animating = 1; result.is_animating = true;
} }
else if (interpret_result.auto_hot){ else if (interpret_result.auto_hot){
if (!gui_id_eq(target->auto_hot, b->id)){ if (!gui_id_eq(target->auto_hot, b->id)){
target->auto_hot = b->id; target->auto_hot = b->id;
result.is_animating = 1; result.is_animating = true;
} }
} }
}break; }break;
@ -4730,10 +4736,10 @@ do_step_file_view(System_Functions *system,
if (view->reinit_scrolling){ if (view->reinit_scrolling){
view_reinit_scrolling(view); view_reinit_scrolling(view);
result.is_animating = 1; result.is_animating = true;
} }
if (file_step(view, gui_session.rect, user_input, is_active)){ if (file_step(view, gui_session.rect, user_input, is_active, &result.consumed_l)){
result.is_animating = 1; result.is_animating = true;
} }
is_file_scroll = 1; is_file_scroll = 1;
}break; }break;
@ -4746,7 +4752,10 @@ do_step_file_view(System_Functions *system,
{ {
GUI_Interactive *b = (GUI_Interactive*)h; GUI_Interactive *b = (GUI_Interactive*)h;
click_button_input(target, &gui_session, user_input, b, &result.is_animating); if (click_button_input(target, &gui_session, user_input,
b, &result.is_animating)){
result.consumed_l = true;
}
}break; }break;
case guicom_fixed_option: case guicom_fixed_option:
@ -4754,7 +4763,10 @@ do_step_file_view(System_Functions *system,
{ {
GUI_Interactive *b = (GUI_Interactive*)h; GUI_Interactive *b = (GUI_Interactive*)h;
click_button_input(target, &gui_session, user_input, b, &result.is_animating); if (click_button_input(target, &gui_session, user_input,
b, &result.is_animating)){
result.consumed_l = true;
}
{ {
Key_Event_Data key; Key_Event_Data key;
@ -4774,7 +4786,7 @@ do_step_file_view(System_Functions *system,
key = get_single_key(keys, i); key = get_single_key(keys, i);
if (char_to_upper(key.character) == char_to_upper(activation_key)){ if (char_to_upper(key.character) == char_to_upper(activation_key)){
target->active = b->id; target->active = b->id;
result.is_animating = 1; result.is_animating = true;
break; break;
} }
} }
@ -4792,7 +4804,8 @@ do_step_file_view(System_Functions *system,
target->hover = id; target->hover = id;
if (user_input->mouse.press_l){ if (user_input->mouse.press_l){
target->mouse_hot = id; target->mouse_hot = id;
result.is_animating = 1; result.is_animating = true;
result.consumed_l = true;
} }
} }
else if (gui_id_eq(target->hover, id)){ else if (gui_id_eq(target->hover, id)){
@ -4806,7 +4819,7 @@ do_step_file_view(System_Functions *system,
result.vars.target_y = lerp(0.f, v, result.vars.max_y); result.vars.target_y = lerp(0.f, v, result.vars.max_y);
gui_activate_scrolling(target); gui_activate_scrolling(target);
result.is_animating = 1; result.is_animating = true;
} }
} }
// NOTE(allen): NO BREAK HERE!! // NOTE(allen): NO BREAK HERE!!
@ -4819,7 +4832,7 @@ do_step_file_view(System_Functions *system,
result.vars.target_y = result.vars.target_y =
clamp(0.f, result.vars.target_y, result.vars.max_y); clamp(0.f, result.vars.target_y, result.vars.max_y);
gui_activate_scrolling(target); gui_activate_scrolling(target);
result.is_animating = 1; result.is_animating = true;
} }
}break; }break;
@ -4830,6 +4843,7 @@ do_step_file_view(System_Functions *system,
if (scroll_button_input(target, &gui_session, user_input, id, &result.is_animating)){ if (scroll_button_input(target, &gui_session, user_input, id, &result.is_animating)){
result.vars.target_y -= target->delta * 0.25f; result.vars.target_y -= target->delta * 0.25f;
result.vars.target_y = clamp_bottom(0.f, result.vars.target_y); result.vars.target_y = clamp_bottom(0.f, result.vars.target_y);
result.consumed_l = true;
} }
}break; }break;
@ -4840,6 +4854,7 @@ do_step_file_view(System_Functions *system,
if (scroll_button_input(target, &gui_session, user_input, id, &result.is_animating)){ if (scroll_button_input(target, &gui_session, user_input, id, &result.is_animating)){
result.vars.target_y += target->delta * 0.25f; result.vars.target_y += target->delta * 0.25f;
result.vars.target_y = clamp_top(result.vars.target_y, result.vars.max_y); result.vars.target_y = clamp_top(result.vars.target_y, result.vars.max_y);
result.consumed_l = true;
} }
}break; }break;
@ -4857,20 +4872,20 @@ do_step_file_view(System_Functions *system,
if (!user_input->mouse.l){ if (!user_input->mouse.l){
if (!gui_id_is_null(target->mouse_hot)){ if (!gui_id_is_null(target->mouse_hot)){
target->mouse_hot = gui_id_zero(); target->mouse_hot = gui_id_zero();
result.is_animating = 1; result.is_animating = true;
} }
} }
{ {
GUI_Scroll_Vars scroll_vars = result.vars; GUI_Scroll_Vars scroll_vars = result.vars;
b32 is_new_target = 0; b32 is_new_target = false;
if (scroll_vars.target_x != scroll_vars.prev_target_x) is_new_target = 1; if (scroll_vars.target_x != scroll_vars.prev_target_x) is_new_target = true;
if (scroll_vars.target_y != scroll_vars.prev_target_y) is_new_target = 1; if (scroll_vars.target_y != scroll_vars.prev_target_y) is_new_target = true;
if (view->persistent.models->scroll_rule(scroll_vars.target_x, scroll_vars.target_y, if (view->persistent.models->scroll_rule(scroll_vars.target_x, scroll_vars.target_y,
&scroll_vars.scroll_x, &scroll_vars.scroll_y, &scroll_vars.scroll_x, &scroll_vars.scroll_y,
(view->persistent.id) + 1, is_new_target, user_input->dt)){ (view->persistent.id) + 1, is_new_target, user_input->dt)){
result.is_animating = 1; result.is_animating = true;
} }
scroll_vars.prev_target_x = scroll_vars.target_x; scroll_vars.prev_target_x = scroll_vars.target_x;

View File

@ -1,11 +1,11 @@
/* /*
* Mr. 4th Dimention - Allen Webster * Mr. 4th Dimention - Allen Webster
* *
* 25.02.2016 * 25.02.2016
* *
* File editing view for 4coder * File editing view for 4coder
* *
*/ */
// TOP // TOP
@ -84,18 +84,21 @@ void enum_begin(FILE *file, char *name){
char *keys_that_need_codes[] = { char *keys_that_need_codes[] = {
"back", "back",
"up", "up",
"down", "down",
"left", "left",
"right", "right",
"del", "del",
"insert", "insert",
"home", "home",
"end", "end",
"page_up", "page_up",
"page_down", "page_down",
"esc", "esc",
"mouse_left",
"mouse_right",
"f1", "f1",
"f2", "f2",
@ -130,12 +133,12 @@ char* generate_keycode_enum(){
code = 0x7F; code = 0x7F;
} }
switch (code){ switch (code){
case '\n': code++; break; case '\n': code++; break;
case '\t': code++; break; case '\t': code++; break;
case 0x20: code = 0x7F; break; case 0x20: code = 0x7F; break;
default: default:
fprintf(file, "key_%s = %d,\n", keys_that_need_codes[i++], code++); fprintf(file, "key_%s = %d,\n", keys_that_need_codes[i++], code++);
break; break;
} }
} }
fprintf(file, "};\n"); fprintf(file, "};\n");
@ -175,27 +178,27 @@ char* bar_style_fields[] = {
char* main_style_fields[] = { char* main_style_fields[] = {
"back", "back",
"margin", "margin",
"margin_hover", "margin_hover",
"margin_active", "margin_active",
"cursor", "cursor",
"at_cursor", "at_cursor",
"highlight", "highlight",
"at_highlight", "at_highlight",
"mark", "mark",
"default", "default",
"comment", "comment",
"keyword", "keyword",
"str_constant", "str_constant",
"char_constant", "char_constant",
"int_constant", "int_constant",
"float_constant", "float_constant",
"bool_constant", "bool_constant",
"preproc", "preproc",
"include", "include",
"special_character", "special_character",
"highlight_junk", "highlight_junk",
"highlight_white", "highlight_white",
"paste", "paste",
"undo", "undo",
"next_undo", "next_undo",
@ -210,7 +213,7 @@ make_style_tag(char *tag){
str = (char*)malloc(len + 1); str = (char*)malloc(len + 1);
to_camel(tag, str); to_camel(tag, str);
str[len] = 0; str[len] = 0;
return(str); return(str);
} }
@ -235,7 +238,7 @@ char* generate_style(){
FILE *file; FILE *file;
char *tag; char *tag;
int count, i; int count, i;
file = fopen(filename_4coder, "wb"); file = fopen(filename_4coder, "wb");
enum_begin(file, "Style_Tag"); enum_begin(file, "Style_Tag");
{ {
@ -514,7 +517,7 @@ generate_custom_headers(){
name_buffer); name_buffer);
} }
#endif #endif
fclose(file); fclose(file);
return(filename); return(filename);

View File

@ -2197,6 +2197,7 @@ WinMain(HINSTANCE hInstance,
input.dt = frame_useconds / 1000000.f; input.dt = frame_useconds / 1000000.f;
input.keys = input_chunk.trans.key_data; input.keys = input_chunk.trans.key_data;
memcpy(input.keys.modifiers, input_chunk.pers.control_keys, sizeof(input_chunk.pers.control_keys));
input.mouse.out_of_window = input_chunk.trans.out_of_window; input.mouse.out_of_window = input_chunk.trans.out_of_window;