setup consumer tracking on consumer's side

This commit is contained in:
Allen Webster 2016-06-07 13:49:18 -04:00
parent e49249c7e4
commit 86f0537690
3 changed files with 82 additions and 36 deletions

70
4ed.cpp
View File

@ -3160,10 +3160,15 @@ enum Input_Types{
Input_Count
};
struct Consumption_Record{
b32 consumed;
char consumer[32];
};
struct Available_Input{
Key_Summary *keys;
Mouse_State *mouse;
b32 consumed[Input_Count];
Consumption_Record records[Input_Count];
};
Available_Input
@ -3178,10 +3183,10 @@ Key_Summary
get_key_data(Available_Input *available){
Key_Summary result = {0};
if (!available->consumed[Input_AnyKey]){
if (!available->records[Input_AnyKey].consumed){
result = *available->keys;
}
else if (!available->consumed[Input_Esc]){
else if (!available->records[Input_Esc].consumed){
i32 i = 0;
i32 count = available->keys->count;
Key_Event_Data key = {0};
@ -3202,19 +3207,19 @@ get_key_data(Available_Input *available){
Mouse_State
get_mouse_state(Available_Input *available){
Mouse_State mouse = *available->mouse;
if (available->consumed[Input_MouseLeftButton]){
if (available->records[Input_MouseLeftButton].consumed){
mouse.l = 0;
mouse.press_l = 0;
mouse.release_l = 0;
}
if (available->consumed[Input_MouseRightButton]){
if (available->records[Input_MouseRightButton].consumed){
mouse.r = 0;
mouse.press_r = 0;
mouse.release_r = 0;
}
if (available->consumed[Input_MouseWheel]){
if (available->records[Input_MouseWheel].consumed){
mouse.wheel = 0;
}
@ -3222,8 +3227,14 @@ get_mouse_state(Available_Input *available){
}
void
consume_input(Available_Input *available, i32 input_type){
available->consumed[input_type] = 1;
consume_input(Available_Input *available, i32 input_type, char *consumer){
Consumption_Record *record = &available->records[input_type];
record->consumed = 1;
if (consumer){
String str = make_fixed_width_string(record->consumer);
copy(&str, consumer);
terminate_with_null(&str);
}
}
App_Step_Sig(app_step){
@ -3559,7 +3570,7 @@ App_Step_Sig(app_step){
}
}
// NOTE(allen): Pass keyboard events to debug
// NOTE(allen): pass events to debug
Available_Input available_input = init_available_input(&key_summary, &input->mouse);
#if FRED_INTERNAL
@ -3572,6 +3583,7 @@ App_Step_Sig(app_step){
i32 count = key_data.count;
i32 preserved_inputs = ArrayCount(debug->input_events) - count;
debug->this_frame_count = count;
memmove(events + count, events,
sizeof(Debug_Input_Event)*preserved_inputs);
@ -3579,6 +3591,8 @@ App_Step_Sig(app_step){
Key_Event_Data key = get_single_key(&key_data, i);
events[i].key = key.keycode;
events[i].consumer[0] = 0;
events[i].is_hold = key.modifiers[MDFR_HOLD_INDEX];
events[i].is_ctrl = key.modifiers[MDFR_CONTROL_INDEX];
events[i].is_alt = key.modifiers[MDFR_ALT_INDEX];
@ -3625,13 +3639,15 @@ App_Step_Sig(app_step){
if (EventOnAnyKey & get_flags){
pass_in = 1;
consume_input(&available_input, Input_AnyKey);
consume_input(&available_input, Input_AnyKey,
"command coroutine");
}
if (key.keycode == key_esc){
if (EventOnEsc & get_flags){
pass_in = 1;
}
consume_input(&available_input, Input_Esc);
consume_input(&available_input, Input_Esc,
"command coroutine");
}
if (pass_in){
@ -3670,7 +3686,8 @@ App_Step_Sig(app_step){
}
if (get_flags & EventOnMouseMove){
pass_in = 1;
consume_input(&available_input, Input_MouseMove);
consume_input(&available_input, Input_MouseMove,
"command coroutine");
}
if (input->mouse.press_l || input->mouse.release_l || input->mouse.l){
@ -3679,7 +3696,8 @@ App_Step_Sig(app_step){
}
if (get_flags & EventOnLeftButton){
pass_in = 1;
consume_input(&available_input, Input_MouseLeftButton);
consume_input(&available_input, Input_MouseLeftButton,
"command coroutine");
}
}
@ -3689,7 +3707,8 @@ App_Step_Sig(app_step){
}
if (get_flags & EventOnRightButton){
pass_in = 1;
consume_input(&available_input, Input_MouseRightButton);
consume_input(&available_input, Input_MouseRightButton,
"command coroutine");
}
}
@ -3699,7 +3718,8 @@ App_Step_Sig(app_step){
}
if (get_flags & EventOnWheel){
pass_in = 1;
consume_input(&available_input, Input_MouseWheel);
consume_input(&available_input, Input_MouseWheel,
"command coroutine");
}
}
@ -3757,10 +3777,12 @@ App_Step_Sig(app_step){
app_result.animating = 1;
}
if (result.consume_keys){
consume_input(&available_input, Input_AnyKey);
consume_input(&available_input, Input_AnyKey,
"step_file_view");
}
if (result.consume_keys || result.consume_esc){
consume_input(&available_input, Input_Esc);
consume_input(&available_input, Input_Esc,
"step_file_view");
}
if (view->changed_context_in_step == 0){
@ -3846,15 +3868,25 @@ App_Step_Sig(app_step){
}
if (hit_something){
consume_input(&available_input, Input_AnyKey);
consume_input(&available_input, Input_AnyKey,
"command dispatcher");
}
if (hit_esc){
consume_input(&available_input, Input_Esc);
consume_input(&available_input, Input_Esc,
"command dispatcher");
}
}
update_command_data(vars, cmd);
// NOTE(allen): pass consumption data to debug
#if FRED_INTERNAL
{
//Debug_Data *debug = &models->debug;
}
#endif
// NOTE(allen): initialize message
if (input->first_step){
String welcome =

View File

@ -26,6 +26,8 @@ struct App_Settings{
struct Debug_Input_Event{
char key;
char consumer[32];
b8 is_hold;
b8 is_ctrl;
b8 is_alt;
@ -34,6 +36,7 @@ struct Debug_Input_Event{
struct Debug_Data{
Debug_Input_Event input_events[16];
i32 this_frame_count;
};
struct Models{

View File

@ -4163,7 +4163,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
}break;
}
}break;
case VUI_Interactive:
{
b32 complete = 0;
@ -4175,10 +4175,10 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
GUI_id id = {0};
id.id[1] = VUI_Interactive + ((u64)view->interaction << 32);
GUI_id scroll_context = {0};
scroll_context.id[1] = VUI_Interactive + ((u64)view->interaction << 32);
switch (view->interaction){
case IInt_Sys_File_List:
{
@ -4330,7 +4330,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
gui_standard_list(target, id, view->current_scroll, view->scroll_region,
&keys, &view->list_i, &update);
}
{
Partition *part = &models->mem.part;
Temp_Memory temp = begin_temp_memory(part);
@ -4338,15 +4338,15 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
Editing_File **reserved_files = 0;
i32 reserved_top = 0, i = 0;
View_Iter iter = {0};
partition_align(part, sizeof(i32));
reserved_files = (Editing_File**)partition_current(part);
used_nodes = &working_set->used_sentinel;
for (dll_items(node, used_nodes)){
file = (Editing_File*)node;
Assert(!file->is_dummy);
if (filename_match(view->dest, &absolutes, file->name.live_name, 1)){
iter = file_view_iter_init(layout, file, 0);
if (file_view_iter_good(iter)){
@ -4358,11 +4358,14 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
}
else{
message = string_zero();
switch (buffer_get_sync(file)){
case SYNC_BEHIND_OS: message = message_unsynced; break;
case SYNC_UNSAVED: message = message_unsaved; break;
if (!file->settings.unimportant){
switch (buffer_get_sync(file)){
case SYNC_BEHIND_OS: message = message_unsynced; break;
case SYNC_UNSAVED: message = message_unsaved; break;
}
}
id.id[0] = (u64)(file);
if (gui_do_file_option(target, id, file->name.live_name, 0, message)){
complete = 1;
@ -4372,16 +4375,16 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
}
}
}
for (i = 0; i < reserved_top; ++i){
file = reserved_files[i];
message = string_zero();
switch (buffer_get_sync(file)){
case SYNC_BEHIND_OS: message = message_unsynced; break;
case SYNC_UNSAVED: message = message_unsaved; break;
}
id.id[0] = (u64)(file);
if (gui_do_file_option(target, id, file->name.live_name, 0, message)){
complete = 1;
@ -4480,8 +4483,11 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
// - Command maps inspection
String empty_str = string_zero();
char space[512];
String string = make_fixed_width_string(space);
char space1[512];
String string = make_fixed_width_string(space1);
String message = string_zero();
// Time Watcher
{
@ -4572,7 +4578,12 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
}
}
gui_do_text_field(target, string, empty_str);
message.size = 0;
if (input_event->consumer[0] != 0){
message = make_string_slowly(input_event->consumer);
}
gui_do_text_field(target, string, message);
}
}
}break;