From 5ee0b4943fd80015dc638ff2fd230e3980bf6c0c Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Fri, 6 Aug 2010 15:40:01 +0000 Subject: [PATCH] * Use SDL_WaitEvent instead of SDL_PollEvent. * To avoid the program getting 'locked' when there is no user input (sliders, colorspray), we use a timer that queues events to make grafX2 act (and refresh the screen) TODO : * To reduce cpu usage when idle even more, start the timer only when it's needed (colorspray is drawing, or a scrollbar is scrolling) * For now everyone uses the same timer, so the same delay. This means there is no fast-scroll and slow-scroll for sliders. Starting the timer with a different speed in each case would solve that * The event handling for sliders will currently react to any mouse event. Thismeans the slider will move faster if you slightly move the mouse while keeping in the button. Not what wewant, so weshoud all a timer_expired global and the slider should wait for that (and reset it when acknowledged). git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1556 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- src/engine.c | 10 +++++----- src/input.c | 10 +++++++--- src/main.c | 25 +++++++++++++++++++++++++ src/misc.c | 11 ----------- src/misc.h | 1 - 5 files changed, 37 insertions(+), 20 deletions(-) diff --git a/src/engine.c b/src/engine.c index 9057bea3..6946dafe 100644 --- a/src/engine.c +++ b/src/engine.c @@ -2759,7 +2759,7 @@ short Window_get_clicked_button(void) Hide_cursor(); Window_select_normal_button(temp1->Pos_X,temp1->Pos_Y,temp1->Width,temp1->Height); Display_cursor(); - Slider_timer((Mouse_K==1)? Config.Delay_left_click_on_slider : Config.Delay_right_click_on_slider); + // Slider_timer((Mouse_K==1)? Config.Delay_left_click_on_slider : Config.Delay_right_click_on_slider); Hide_cursor(); Window_unselect_normal_button(temp1->Pos_X,temp1->Pos_Y,temp1->Width,temp1->Height); Display_cursor(); @@ -2783,7 +2783,7 @@ short Window_get_clicked_button(void) } } - // Test click oin slider/scroller bars + // Test click on slider/scroller bars for (temp3=Window_scroller_button_list; temp3; temp3=temp3->Next) { // Button Up arrow @@ -2806,7 +2806,7 @@ short Window_get_clicked_button(void) Display_cursor(); - Slider_timer((Mouse_K==1)? Config.Delay_left_click_on_slider : Config.Delay_right_click_on_slider); + // Slider_timer((Mouse_K==1)? Config.Delay_left_click_on_slider : Config.Delay_right_click_on_slider); Hide_cursor(); Window_unselect_normal_button(temp3->Pos_X,temp3->Pos_Y,11,11); @@ -2835,7 +2835,7 @@ short Window_get_clicked_button(void) Display_cursor(); - Slider_timer((Mouse_K==1)? Config.Delay_left_click_on_slider : Config.Delay_right_click_on_slider); + // Slider_timer((Mouse_K==1)? Config.Delay_left_click_on_slider : Config.Delay_right_click_on_slider); Hide_cursor(); Window_unselect_normal_button(temp3->Pos_X,temp3->Pos_Y+temp3->Height-11,11,11); @@ -2941,7 +2941,7 @@ short Window_get_button_shortcut(void) Window_select_normal_button(temp->Pos_X,temp->Pos_Y,temp->Width,temp->Height); Display_cursor(); - Slider_timer(Config.Delay_right_click_on_slider); + // Slider_timer(Config.Delay_right_click_on_slider); Hide_cursor(); Window_unselect_normal_button(temp->Pos_X,temp->Pos_Y,temp->Width,temp->Height); diff --git a/src/input.c b/src/input.c index 720bfaef..c11472e7 100644 --- a/src/input.c +++ b/src/input.c @@ -243,8 +243,9 @@ int Move_cursor_with_constraints() Mouse_K=Input_new_mouse_K; if (Mouse_moved > Config.Mouse_merge_movement) - if (! Operation[Current_operation][Mouse_K_unique] - [Operation_stack_size].Fast_mouse) + // TODO : not sure what that was meant to do, but it prevents moving the default cursor when there is no operation. + // if (! Operation[Current_operation][Mouse_K_unique] + // [Operation_stack_size].Fast_mouse) feedback=1; } if (mouse_blocked) @@ -681,7 +682,7 @@ int Get_input(void) // Process as much events as possible without redrawing the screen. // This mostly allows us to merge mouse events for people with an high // resolution mouse - while( (!user_feedback_required) && SDL_PollEvent(&event)) // Try to cumulate for a full VBL except if there is a required feedback + while( (!user_feedback_required) && SDL_WaitEvent(&event)) // Try to cumulate for a full VBL except if there is a required feedback { switch(event.type) { @@ -765,6 +766,9 @@ int Get_input(void) #endif break; + case SDL_USEREVENT: + user_feedback_required = 1; + break; default: // DEBUG("Unhandled SDL event number : ",event.type); break; diff --git a/src/main.c b/src/main.c index 696fbbb9..1bd92065 100644 --- a/src/main.c +++ b/src/main.c @@ -409,6 +409,30 @@ int Analyze_command_line(int argc, char * argv[], char *main_filename, char *mai return file_in_command_line; } + +Uint32 putTimerEvent(Uint32 i, void* p) +{ + SDL_Event event; + SDL_UserEvent userevent; + + /* Dans cet exemple, notre fonction de rappel pousse + un evenement SDL_USEREVENT dans la file... */ + + userevent.type = SDL_USEREVENT; + userevent.code = 0; + userevent.data1 = NULL; + userevent.data2 = NULL; + + event.type = SDL_USEREVENT; + event.user = userevent; + + SDL_PushEvent(&event); + + + return i; +} + + // ------------------------ Initialiser le programme ------------------------- // Returns 0 on fail int Init_program(int argc,char * argv[]) @@ -521,6 +545,7 @@ int Init_program(int argc,char * argv[]) printf("Couldn't initialize SDL.\n"); return(0); } + SDL_TimerID tid = SDL_AddTimer(10, putTimerEvent, NULL); Joystick = SDL_JoystickOpen(0); SDL_EnableKeyRepeat(250, 32); diff --git a/src/misc.c b/src/misc.c index ffc268d6..e5e74625 100644 --- a/src/misc.c +++ b/src/misc.c @@ -675,17 +675,6 @@ void Rescale(byte *src_buffer, short src_width, short src_height, byte *dst_buff } } -void Slider_timer(byte speed) - //Boucle d'attente pour faire bouger les scrollbars à une vitesse correcte -{ - Uint32 end; - byte original_mouse_k = Mouse_K; - end = SDL_GetTicks() + speed*10; - do - { - if (!Get_input()) SDL_Delay(20); - } while (Mouse_K == original_mouse_k && SDL_GetTicks()