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
This commit is contained in:
Yves Rizoud 2010-08-19 00:33:06 +00:00
parent 858bab41c4
commit 520da7d168
11 changed files with 101 additions and 205 deletions

View File

@ -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

View File

@ -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 (now<end);
Need_timer_for_tool=0;
}
// ======== Timer stuff =========
// This system is installed whenever Grafx2 needs to wait
// for some input, but wants to be called back anyway
// if a specified amount of time has elapsed.
/// Pointer to the current timer, NULL if disabled at the moment.
static SDL_TimerID Current_timer=NULL;
///
/// This callback is meant to post SDL_USEREVENT in the event queue.
/// It is designed especially to "wake" grafx2 in some situations where
/// an animation or something is running, even if the mouse and keyboard
/// are untouched.
Uint32 Push_timer_event(Uint32 i, __attribute__((unused)) void* p)
{
if (Need_timer_for_tool || Need_timer_for_cursor)
{
SDL_Event event;
SDL_UserEvent user_event;
user_event.type = SDL_USEREVENT;
user_event.code = 0;
user_event.data1 = NULL;
user_event.data2 = NULL;
event.type = SDL_USEREVENT;
event.user = user_event;
SDL_PushEvent(&event);
}
return i;
}
///
/// Activate the timer that runs Push_timer_event()
/// This function can safely be called while it's active.
void Activate_timer(int speed)
{
if (Current_timer)
{
if (SDL_RemoveTimer(Current_timer)==SDL_FALSE)
// Problem ?... keep running.
return;
}
Current_timer = SDL_AddTimer(speed, Push_timer_event, NULL);
}
///
/// Remove the running timer that runs Push_timer_event()
/// This function can safely be called while it's disabled.
void Disable_timer(void)
{
if (Current_timer)
{
if (SDL_RemoveTimer(Current_timer)==SDL_FALSE)
// Problem ?... can't really do anything.
return;
}
Current_timer=NULL;
Get_input(20);
} while (Mouse_K == original_mouse_k && SDL_GetTicks()<end);
}

View File

@ -116,13 +116,4 @@ void Status_print_palette_color(byte color);
/// though the mouse still works.
void Delay_with_active_mouse(int delay);
///
/// Activate the timer that runs Push_timer_event()
/// This function can safely be called while it's active.
void Activate_timer(int speed);
///
/// Remove the running timer that runs Push_timer_event()
/// This function can safely be called while it's disabled.
void Disable_timer(void);
#endif

View File

@ -94,7 +94,7 @@ void Redefine_control(word *shortcut, int x_pos, int y_pos)
Display_cursor();
while (1)
{
Get_input();
Get_input(20);
if (Key==KEY_ESC)
return;
if (Key!=0)

View File

@ -43,6 +43,7 @@
void Handle_window_resize(SDL_ResizeEvent event);
void Handle_window_exit(SDL_QuitEvent event);
int Color_cycling(__attribute__((unused)) void* useless);
// public Globals (available as extern)
@ -51,9 +52,6 @@ int Snap_axis = 0;
int Snap_axis_origin_X;
int Snap_axis_origin_Y;
volatile int Need_timer_for_tool;
volatile int Need_timer_for_cursor;
char * Drop_file_name = NULL;
// --
@ -234,8 +232,6 @@ int Move_cursor_with_constraints()
if (Input_new_mouse_K == 0)
{
Input_sticky_control = 0;
Need_timer_for_tool=0;
Need_timer_for_cursor=0;
}
}
// Hide cursor, because even just a click change needs it
@ -678,7 +674,7 @@ int Cursor_displace(short delta_x, short delta_y)
// Main input handling function
int Get_input(void)
int Get_input(int sleep_time)
{
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
@ -687,6 +683,7 @@ int Get_input(void)
// This is done in this function because it's called after reading
// some user input.
Flush_update();
Color_cycling(NULL);
Key_ANSI = 0;
Key = 0;
@ -695,7 +692,8 @@ int Get_input(void)
Input_new_mouse_Y = Mouse_Y;
if (!SDL_PollEvent(&event))
{
SDL_WaitEvent(&event);
SDL_Delay(sleep_time);
return 0;
}
// Process as much events as possible without redrawing the screen.
// This mostly allows us to merge mouse events for people with an high
@ -735,7 +733,6 @@ int Get_input(void)
case SDL_KEYUP:
Handle_key_release(event.key);
user_feedback_required = 1; // new
break;
// Start of Joystik handling
@ -802,9 +799,6 @@ int Get_input(void)
#endif
break;
case SDL_USEREVENT:
//user_feedback_required = 1;
break;
default:
//DEBUG("Unhandled SDL event number : ",event.type);
break;
@ -822,7 +816,6 @@ int Get_input(void)
Directional_left||Directional_up_left))
{
Directional_delay=-1;
Need_timer_for_cursor=1;
Directional_last_move=SDL_GetTicks();
}
else
@ -913,3 +906,74 @@ void Set_mouse_position(void)
Mouse_virtual_y_position = 12*Mouse_Y*Pixel_height;
}
}
int Color_cycling(__attribute__((unused)) void* useless)
{
static 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;
static long start=0;
if (start==0)
{
// First run
start = SDL_GetTicks();
return 1;
}
if (!Allow_colorcycling)
return 1;
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);
}
return 0;
}

View File

@ -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.

View File

@ -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);

View File

@ -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)

View File

@ -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();
}

View File

@ -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();

View File

@ -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) )