From 520da7d16884049ff519588e84550c861f9679ad Mon Sep 17 00:00:00 2001 From: Yves Rizoud Date: Thu, 19 Aug 2010 00:33:06 +0000 Subject: [PATCH] Reverted the change of input system (mostly, still needs more testing) Changed color cycling so it no longer needs a separate thread. git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1581 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- src/buttons.c | 6 ++-- src/engine.c | 93 ++++++++------------------------------------------ src/engine.h | 9 ----- src/help.c | 2 +- src/input.c | 88 ++++++++++++++++++++++++++++++++++++++++------- src/input.h | 11 +----- src/main.c | 88 ++--------------------------------------------- src/misc.c | 2 +- src/operatio.c | 3 -- src/readline.c | 2 +- src/shade.c | 2 +- 11 files changed, 101 insertions(+), 205 deletions(-) diff --git a/src/buttons.c b/src/buttons.c index a3de80e2..4b6e0d4b 100644 --- a/src/buttons.c +++ b/src/buttons.c @@ -167,7 +167,7 @@ void Button_Message_initial(void) Display_cursor(); while(!Mouse_K && !Key) - Get_input(); + Get_input(20); if (Mouse_K) Wait_end_of_click(); @@ -337,7 +337,7 @@ void Button_Select_forecolor(void) // Wait loop after initial click while(Mouse_K) { - Get_input(); + Get_input(20); if (Button_under_mouse()==BUTTON_CHOOSE_COL) { @@ -373,7 +373,7 @@ void Button_Select_backcolor(void) // Wait loop after initial click do { - Get_input(); + Get_input(20); 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 1c177b1c..4a6a6d4b 100644 --- a/src/engine.c +++ b/src/engine.c @@ -599,7 +599,7 @@ void Move_separator(void) Display_cursor(); } } - Get_input(); + Get_input(20); } // Effacer la barre en XOR @@ -709,7 +709,7 @@ void Main_handler(void) Drop_file_name=NULL; } - if(Get_input()) + if(Get_input(0)) { action = 0; @@ -1350,6 +1350,7 @@ void Main_handler(void) else { // Removed all SDL_Delay() timing here: relying on Get_input() + SDL_Delay(10); } // Gestion de la souris @@ -2310,7 +2311,8 @@ short Wait_click_in_palette(T_Palette_button * button) for (;;) { - Get_input(); + while (Get_input(20)) + ; if (Mouse_K==LEFT_SIDE) { @@ -2391,7 +2393,7 @@ void Get_color_behind_window(byte * color, byte * click) do { - Get_input(); + Get_input(20); if ((Mouse_X!=old_x) || (Mouse_Y!=old_y)) { @@ -2480,7 +2482,7 @@ void Move_window(short dx, short dy) do { - Get_input(); + Get_input(20); } while(new_x==Mouse_X-dx && new_y==Mouse_Y-dy); new_x=Mouse_X-dx; @@ -2683,7 +2685,7 @@ T_Dropdown_choice * Dropdown_activate(T_Dropdown_button *button, short off_x, sh do { // Attente - Get_input(); + Get_input(20); // 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; @@ -2754,7 +2756,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)) { - Get_input(); + Get_input(20); if (!Mouse_K) { Hide_cursor(); @@ -2768,7 +2770,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))) { - Get_input(); + Get_input(20); if (!Mouse_K) return 0; } @@ -2802,7 +2804,6 @@ short Window_get_clicked_button(void) Display_cursor(); Delay_with_active_mouse((Mouse_K==1)? Config.Delay_left_click_on_slider : Config.Delay_right_click_on_slider); Hide_cursor(); - Need_timer_for_tool=1; Window_unselect_normal_button(temp1->Pos_X,temp1->Pos_Y,temp1->Width,temp1->Height); Display_cursor(); return temp1->Number; @@ -3033,7 +3034,7 @@ short Window_clicked_button(void) { short Button; - Get_input(); + Get_input(20); // Handle clicks if (Mouse_K) @@ -3345,77 +3346,13 @@ void Remap_window_backgrounds(byte * conversion_table, int Min_Y, int Max_Y) void Delay_with_active_mouse(int speed) { - Uint32 now; Uint32 end; + byte original_mouse_k = Mouse_K; + end = SDL_GetTicks()+speed*10; - Need_timer_for_tool=1; do { - Get_input(); - now = SDL_GetTicks(); - } while (now1 && Gradient_array[i].Speed) + { + int new_offset; + + new_offset=(now-start)/(int)(1000.0/(Gradient_array[i].Speed*0.2856)) % len; + if (!Gradient_array[i].Inverse) + new_offset=len - new_offset; + + if (new_offset!=offset[i]) + changed=1; + offset[i]=new_offset; + } + } + if (changed) + { + // Initialize the palette + for(color=0;color<256;color++) + { + PaletteSDL[color].r=Main_palette[color].R; + PaletteSDL[color].g=Main_palette[color].G; + PaletteSDL[color].b=Main_palette[color].B; + } + for (i=0; i<16; i++) + { + int len; + + len=Gradient_array[i].End-Gradient_array[i].Start+1; + if (len>1 && Gradient_array[i].Speed) + { + for(color=Gradient_array[i].Start;color<=Gradient_array[i].End;color++) + { + PaletteSDL[color].r=Main_palette[Gradient_array[i].Start+((color-Gradient_array[i].Start+offset[i])%len)].R; + PaletteSDL[color].g=Main_palette[Gradient_array[i].Start+((color-Gradient_array[i].Start+offset[i])%len)].G; + PaletteSDL[color].b=Main_palette[Gradient_array[i].Start+((color-Gradient_array[i].Start+offset[i])%len)].B; + } + } + } + SDL_SetPalette(Screen_SDL, SDL_PHYSPAL | SDL_LOGPAL, PaletteSDL,0,256); + } + return 0; +} diff --git a/src/input.h b/src/input.h index 41e8e853..8ab7440a 100644 --- a/src/input.h +++ b/src/input.h @@ -33,7 +33,7 @@ /// The latest input variables are held in ::Key, ::Key_ANSI, ::Mouse_X, ::Mouse_Y, ::Mouse_K. /// Note that ::Key and ::Key_ANSI are not persistent, they will be reset to 0 /// on subsequent calls to ::Get_input(). -int Get_input(void); +int Get_input(int sleep_time); /// Returns true if the keycode has been set as a keyboard shortcut for the function. int Is_shortcut(word key, word function); @@ -60,15 +60,6 @@ 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 the timer should put "ticks" in the SDL queue. -/// This one flag is for tools (airbrush) or windows (repeatable button) that require it. -extern volatile int Need_timer_for_tool; -/// -/// Boolean, true if the timer should put "ticks" in the SDL queue. -/// This one flag is for the mouse emulation, by keyboard/joystick. -extern volatile int Need_timer_for_cursor; - /// /// This malloced string is set when a drag-and-drop event /// brings a file to Grafx2's window. diff --git a/src/main.c b/src/main.c index 6972f0c5..ba440214 100644 --- a/src/main.c +++ b/src/main.c @@ -86,86 +86,6 @@ extern DECLSPEC int SDLCALL SDL_putenv(const char *variable); #endif -int Color_cycling(__attribute__((unused)) void* useless) -{ - byte offset[16]; - int i, color; - static SDL_Color PaletteSDL[256]; - int changed; // boolean : true if the palette needs a change in this tick. - - long now; - long start; - - while(!Quitting) - { - start = SDL_GetTicks(); - memset(offset, 0, sizeof(offset)); - - // Init palette - while (Allow_colorcycling) - { - now = SDL_GetTicks(); - changed=0; - - // Check all cycles for a change at this tick - for (i=0; i<16; i++) - { - int len; - - len=Gradient_array[i].End-Gradient_array[i].Start+1; - if (len>1 && Gradient_array[i].Speed) - { - int new_offset; - - new_offset=(now-start)/(int)(1000.0/(Gradient_array[i].Speed*0.2856)) % len; - if (!Gradient_array[i].Inverse) - new_offset=len - new_offset; - - if (new_offset!=offset[i]) - changed=1; - offset[i]=new_offset; - } - } - - if (changed) - { - // Initialize the palette - for(color=0;color<256;color++) - { - PaletteSDL[color].r=Main_palette[color].R; - PaletteSDL[color].g=Main_palette[color].G; - PaletteSDL[color].b=Main_palette[color].B; - } - for (i=0; i<16; i++) - { - int len; - - len=Gradient_array[i].End-Gradient_array[i].Start+1; - if (len>1 && Gradient_array[i].Speed) - { - for(color=Gradient_array[i].Start;color<=Gradient_array[i].End;color++) - { - PaletteSDL[color].r=Main_palette[Gradient_array[i].Start+((color-Gradient_array[i].Start+offset[i])%len)].R; - PaletteSDL[color].g=Main_palette[Gradient_array[i].Start+((color-Gradient_array[i].Start+offset[i])%len)].G; - PaletteSDL[color].b=Main_palette[Gradient_array[i].Start+((color-Gradient_array[i].Start+offset[i])%len)].B; - } - } - } - SDL_SetPalette(Screen_SDL, SDL_PHYSPAL | SDL_LOGPAL, PaletteSDL,0,256); - } - SDL_Delay(20); - } - // Restore normal palette - Set_palette(Main_palette); - while (!Allow_colorcycling) - { - SDL_Delay(20); - } - } - return 0; -} - - //--- Affichage de la syntaxe, et de la liste des modes vidéos disponibles --- void Display_syntax(void) { @@ -588,17 +508,13 @@ int Init_program(int argc,char * argv[]) // SDL - if(SDL_Init(SDL_INIT_TIMER|SDL_INIT_VIDEO|SDL_INIT_JOYSTICK) < 0) + if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK) < 0) { // The program can't continue without that anyway printf("Couldn't initialize SDL.\n"); return(0); } - // Start the timer that will push about 60 "wake up" events - // per second in the event queue. - Activate_timer(16); - Joystick = SDL_JoystickOpen(0); SDL_EnableKeyRepeat(250, 32); SDL_EnableUNICODE(SDL_ENABLE); @@ -905,7 +821,7 @@ int Init_program(int argc,char * argv[]) } } -#if 1 +#if 0 // Color cycling test { SDL_Thread* t = SDL_CreateThread(Color_cycling, NULL); diff --git a/src/misc.c b/src/misc.c index 3ae0c8a6..aaae4e61 100644 --- a/src/misc.c +++ b/src/misc.c @@ -178,7 +178,7 @@ void Wait_end_of_click(void) // On désactive tous les raccourcis clavier while(Mouse_K) - Get_input(); + Get_input(20); } void Clear_current_image_with_stencil(byte color, byte * stencil) diff --git a/src/operatio.c b/src/operatio.c index b0032bb4..778666b8 100644 --- a/src/operatio.c +++ b/src/operatio.c @@ -1908,7 +1908,6 @@ void Airbrush_1_0(void) Backup(); Shade_table=Shade_table_left; - Need_timer_for_tool=1; if (SDL_GetTicks()>Airbrush_next_time) { Airbrush(LEFT_SIDE); @@ -1934,7 +1933,6 @@ void Airbrush_2_0(void) Init_start_operation(); Backup(); Shade_table=Shade_table_right; - Need_timer_for_tool=1; if (SDL_GetTicks()>Airbrush_next_time) { Airbrush(RIGHT_SIDE); @@ -1991,7 +1989,6 @@ void Airbrush_0_2(void) // { Operation_stack_size-=2; - //Need_timer_for_tool=0; // Not needed, mouse release did it in Get_input() End_of_modification(); } diff --git a/src/readline.c b/src/readline.c index e49ead48..e3cef989 100644 --- a/src/readline.c +++ b/src/readline.c @@ -196,7 +196,7 @@ byte Readline_ex(word x_pos,word y_pos,char * str,byte visible_size,byte max_siz Display_cursor(); do { - Get_input(); + Get_input(20); input_key=Key_ANSI; } while(input_key==0 && Mouse_K == 0); Hide_cursor(); diff --git a/src/shade.c b/src/shade.c index 117bec89..bab856db 100644 --- a/src/shade.c +++ b/src/shade.c @@ -348,7 +348,7 @@ short Wait_click_in_shade_table() while (selected_cell<0) { - Get_input(); + Get_input(20); if ( (Mouse_K==LEFT_SIDE) && ( ( (Window_click_in_rectangle(8,127,263,179)) && (((((Mouse_Y-Window_pos_Y)/Menu_factor_Y)-127)%7)<4) )