managing frame lock around GetMessage

master
Allen Webster 2016-05-09 13:11:54 -04:00
parent 375a9883c0
commit 9fb8ebbf3a
2 changed files with 51 additions and 55 deletions

View File

@ -3643,6 +3643,29 @@ view_get_scroll_y(View *view){
return(v); return(v);
} }
internal void
click_button_input(GUI_Target *target, GUI_Session *session, Input_Summary *user_input,
GUI_Interactive *b, b32 *is_animating){
i32 mx = user_input->mouse.x;
i32 my = user_input->mouse.y;
if (hit_check(mx, my, session->rect)){
target->hover = b->id;
if (user_input->mouse.press_l){
target->mouse_hot = b->id;
*is_animating = 1;
}
if (user_input->mouse.release_l && gui_id_eq(target->mouse_hot, b->id)){
target->active = b->id;
target->mouse_hot = {0};
*is_animating = 1;
}
}
else if (gui_id_eq(target->hover, b->id)){
target->hover = {0};
}
}
internal b32 internal b32
scroll_button_input(GUI_Target *target, GUI_Session *session, Input_Summary *user_input, scroll_button_input(GUI_Target *target, GUI_Session *session, Input_Summary *user_input,
GUI_id id, b32 *is_animating){ GUI_id id, b32 *is_animating){
@ -3737,61 +3760,28 @@ do_input_file_view(System_Functions *system, Exchange *exchange,
case guicom_file_option: case guicom_file_option:
case guicom_style_preview: case guicom_style_preview:
{ {
// TODO(allen): deduplicate button related stuff
GUI_Interactive *b = (GUI_Interactive*)h; GUI_Interactive *b = (GUI_Interactive*)h;
i32 mx = user_input->mouse.x;
i32 my = user_input->mouse.y;
if (hit_check(mx, my, gui_session.rect)){ click_button_input(target, &gui_session, user_input, b, &is_animating);
target->hover = b->id;
if (user_input->mouse.press_l){
target->mouse_hot = b->id;
is_animating = 1;
}
if (user_input->mouse.release_l && gui_id_eq(target->mouse_hot, b->id)){
target->active = b->id;
target->mouse_hot = {0};
is_animating = 1;
}
}
else if (gui_id_eq(target->hover, b->id)){
target->hover = {0};
}
}break; }break;
case guicom_fixed_option: case guicom_fixed_option:
case guicom_fixed_option_checkbox: case guicom_fixed_option_checkbox:
{ {
// TODO(allen): deduplicate GUI_Interactive *b = (GUI_Interactive*)h;
click_button_input(target, &gui_session, user_input, b, &is_animating);
{
Key_Event_Data key; Key_Event_Data key;
Key_Summary *keys = &user_input->keys; Key_Summary *keys = &user_input->keys;
GUI_Interactive *b = (GUI_Interactive*)h;
void *ptr = (b + 1); void *ptr = (b + 1);
String string; String string;
char activation_key; char activation_key;
i32 mx = user_input->mouse.x;
i32 my = user_input->mouse.y;
i32 i, count; i32 i, count;
if (hit_check(mx, my, gui_session.rect)){
target->hover = b->id;
if (user_input->mouse.press_l){
target->mouse_hot = b->id;
is_animating = 1;
}
if (user_input->mouse.release_l && gui_id_eq(target->mouse_hot, b->id)){
target->active = b->id;
target->mouse_hot = {0};
is_animating = 1;
}
}
else if (gui_id_eq(target->hover, b->id)){
target->hover = {0};
}
string = gui_read_string(&ptr); string = gui_read_string(&ptr);
activation_key = *(char*)ptr; activation_key = *(char*)ptr;
@ -3804,6 +3794,7 @@ do_input_file_view(System_Functions *system, Exchange *exchange,
break; break;
} }
} }
}
}break; }break;
case guicom_scrollable_slider: case guicom_scrollable_slider:

View File

@ -2074,7 +2074,9 @@ int main(int argc, char **argv){
for (;win32vars.input_chunk.pers.keep_playing;){ for (;win32vars.input_chunk.pers.keep_playing;){
win32vars.got_useful_event = 0; win32vars.got_useful_event = 0;
for (;win32vars.got_useful_event == 0;){ for (;win32vars.got_useful_event == 0;){
system_release_lock(FRAME_LOCK);
if (GetMessage(&msg, 0, 0, 0)){ if (GetMessage(&msg, 0, 0, 0)){
system_acquire_lock(FRAME_LOCK);
if (msg.message == WM_QUIT){ if (msg.message == WM_QUIT){
win32vars.input_chunk.pers.keep_playing = 0; win32vars.input_chunk.pers.keep_playing = 0;
}else{ }else{
@ -2082,6 +2084,9 @@ int main(int argc, char **argv){
DispatchMessage(&msg); DispatchMessage(&msg);
} }
} }
else{
system_acquire_lock(FRAME_LOCK);
}
} }
while (PeekMessage(&msg, 0, 0, 0, 1)){ while (PeekMessage(&msg, 0, 0, 0, 1)){