From 951ec2d48af94ecc01e826302e231c67784c5603 Mon Sep 17 00:00:00 2001 From: Yves Rizoud Date: Sun, 8 Aug 2010 19:59:17 +0000 Subject: [PATCH] Still work on SDL events. Airbrush seems to work. Need to do repeatable buttons. git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1565 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- src/buttons.c | 9 ++++----- src/engine.c | 35 ++++++++++++----------------------- src/help.c | 2 +- src/input.c | 17 ++++++++++------- src/input.h | 3 +++ src/main.c | 31 ++++++++++++++++++------------- src/misc.c | 3 ++- src/operatio.c | 4 ++++ src/readline.c | 2 +- 9 files changed, 55 insertions(+), 51 deletions(-) diff --git a/src/buttons.c b/src/buttons.c index d8e3d829..c8fa5cfc 100644 --- a/src/buttons.c +++ b/src/buttons.c @@ -166,7 +166,8 @@ void Button_Message_initial(void) Display_cursor(); - while(!Mouse_K && !Key) if(!Get_input()) SDL_Delay(20); + while(!Mouse_K && !Key) + Get_input(); if (Mouse_K) Wait_end_of_click(); @@ -336,8 +337,7 @@ void Button_Select_forecolor(void) // Wait loop after initial click while(Mouse_K) { - if(!Get_input()) - SDL_Delay(20); + Get_input(); if (Button_under_mouse()==BUTTON_CHOOSE_COL) { @@ -373,8 +373,7 @@ void Button_Select_backcolor(void) // Wait loop after initial click do { - if(!Get_input()) - SDL_Delay(20); + Get_input(); if (Button_under_mouse()==BUTTON_CHOOSE_COL) break; // This will repeat this button's action diff --git a/src/engine.c b/src/engine.c index 6946dafe..6534b680 100644 --- a/src/engine.c +++ b/src/engine.c @@ -598,7 +598,7 @@ void Move_separator(void) Display_cursor(); } } - if(!Get_input())SDL_Delay(20); + Get_input(); } // Effacer la barre en XOR @@ -1299,21 +1299,7 @@ void Main_handler(void) } else { - // No event : we go asleep for a while, but we try to get waked up at constant intervals of time - // no matter the machine speed or system load. The time is fixed to 10ms (that should be about a cpu slice on most systems) - // This allows nice smooth mouse movement. - const int delay = 10; - - Uint32 debut; - debut = SDL_GetTicks(); - // Première attente : le complément de "delay" millisecondes - SDL_Delay(delay - (debut % delay)); - // Si ça ne suffit pas, on complète par des attentes successives de "1ms". - // (Remarque, Windows arrondit généralement aux 10ms supérieures) - while ( SDL_GetTicks()/delay <= debut/delay) - { - SDL_Delay(1); - } + // Removed all SDL_Delay() timing here: relying on Get_input() } // Gestion de la souris @@ -2272,7 +2258,7 @@ short Wait_click_in_palette(T_Palette_button * button) for (;;) { - while(!Get_input())SDL_Delay(20); + Get_input(); if (Mouse_K==LEFT_SIDE) { @@ -2353,7 +2339,7 @@ void Get_color_behind_window(byte * color, byte * click) do { - if(!Get_input())SDL_Delay(20); + Get_input(); if ((Mouse_X!=old_x) || (Mouse_Y!=old_y)) { @@ -2440,7 +2426,10 @@ void Move_window(short dx, short dy) old_x=new_x; old_y=new_y; - while(!Get_input() && new_x==Mouse_X-dx && new_y==Mouse_Y-dy) SDL_Delay(20); + do + { + Get_input(); + } while(new_x==Mouse_X-dx && new_y==Mouse_Y-dy); new_x=Mouse_X-dx; @@ -2642,7 +2631,7 @@ T_Dropdown_choice * Dropdown_activate(T_Dropdown_button *button, short off_x, sh do { // Attente - if(!Get_input()) SDL_Delay(20); + Get_input(); // Mise à jour du survol selected_index=Window_click_in_rectangle(2,2,button->Dropdown_width-2,box_height-1)? (((Mouse_Y-Window_pos_Y)/Menu_factor_Y-2)>>3) : -1; @@ -2713,7 +2702,7 @@ short Window_normal_button_onclick(word x_pos, word y_pos, word width, word heig Display_cursor(); while (Window_click_in_rectangle(x_pos,y_pos,x_pos+width-1,y_pos+height-1)) { - if(!Get_input()) SDL_Delay(20); + Get_input(); if (!Mouse_K) { Hide_cursor(); @@ -2727,7 +2716,7 @@ short Window_normal_button_onclick(word x_pos, word y_pos, word width, word heig Display_cursor(); while (!(Window_click_in_rectangle(x_pos,y_pos,x_pos+width-1,y_pos+height-1))) { - if(!Get_input()) SDL_Delay(20); + Get_input(); if (!Mouse_K) return 0; } @@ -2991,7 +2980,7 @@ short Window_clicked_button(void) { short Button; - if(!Get_input())SDL_Delay(20); + Get_input(); // Handle clicks if (Mouse_K) diff --git a/src/help.c b/src/help.c index b55c805c..4200822a 100644 --- a/src/help.c +++ b/src/help.c @@ -94,7 +94,7 @@ void Redefine_control(word *shortcut, int x_pos, int y_pos) Display_cursor(); while (1) { - while(!Get_input())SDL_Delay(20); + Get_input(); if (Key==KEY_ESC) return; if (Key!=0) diff --git a/src/input.c b/src/input.c index 2b657b83..177e5e70 100644 --- a/src/input.c +++ b/src/input.c @@ -51,6 +51,8 @@ int Snap_axis = 0; int Snap_axis_origin_X; int Snap_axis_origin_Y; +volatile int Need_Timer_events; + // -- byte Directional_up; @@ -675,6 +677,11 @@ int Get_input(void) SDL_Event event; int user_feedback_required = 0; // Flag qui indique si on doit arrêter de traiter les évènements ou si on peut enchainer + // Commit any pending screen update. + // This is done in this function because it's called after reading + // some user input. + Flush_update(); + Key_ANSI = 0; Key = 0; Mouse_moved=0; @@ -719,6 +726,7 @@ int Get_input(void) case SDL_KEYUP: Handle_key_release(event.key); + user_feedback_required = 1; // new break; // Start of Joystik handling @@ -772,7 +780,7 @@ int Get_input(void) user_feedback_required = 1; break; default: - // DEBUG("Unhandled SDL event number : ",event.type); + //DEBUG("Unhandled SDL event number : ",event.type); break; } } @@ -839,13 +847,8 @@ int Get_input(void) Compute_paintbrush_coordinates(); Display_cursor(); } - // Commit any pending screen update. - // This is done in this function because it's called after reading - // some user input. - Flush_update(); - - return (Mouse_moved!=0) || user_feedback_required; + return 1;//(Mouse_moved!=0) || user_feedback_required; } void Adjust_mouse_sensitivity(word fullscreen) diff --git a/src/input.h b/src/input.h index 38ff4b95..928a15ce 100644 --- a/src/input.h +++ b/src/input.h @@ -59,3 +59,6 @@ extern int Snap_axis; extern int Snap_axis_origin_X; /// For the :Snap_axis mode, sets the origin's point (in image coordinates) extern int Snap_axis_origin_Y; + +/// Boolean, true if Push_timer_event() should put "ticks" in the SDL queue +extern volatile int Need_Timer_events; diff --git a/src/main.c b/src/main.c index 8850518b..a3bedae9 100644 --- a/src/main.c +++ b/src/main.c @@ -65,6 +65,7 @@ #include "brush.h" #include "palette.h" #include "realpath.h" +#include "input.h" #if defined(__WIN32__) #include @@ -149,6 +150,12 @@ void Error_function(int error_code, const char *filename, int line_number, const temp_palette[index].R=255; Set_palette(temp_palette); SDL_Delay(500); + // TODO: Replace the above by a loop where cursor is active: + // Need_Timer_events=1 + // Compute target=now+500 + // Do + // Get_input() + // While now