Improved mouse experiment: Mouse merging is automatically off when drawing and on when not drawing.(ignores ini setting). Tools that paste the brush along a shape (lines, cont'freehand, circles, splines) now force a screen update about 10 times per second, but no more than once every 8 pixels drawn. See issue 183.

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@990 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Yves Rizoud 2009-08-15 01:15:39 +00:00
parent 6cdc5e3042
commit 562099f17f
4 changed files with 69 additions and 29 deletions

28
graph.c
View File

@ -1011,11 +1011,32 @@ void Fill_general(byte fill_color)
////////////////////////// avec gestion de previews //////////////////////////
//////////////////////////////////////////////////////////////////////////////
// Data used by ::Init_permanent_draw() and ::Pixel_figure_permanent()
static Uint32 Permanent_draw_next_refresh=0;
static int Permanent_draw_count=0;
void Init_permanent_draw(void)
{
Permanent_draw_count = 0;
Permanent_draw_next_refresh = SDL_GetTicks() + 100;
}
// Affichage d'un point de façon définitive (utilisation du pinceau)
void Pixel_figure_permanent(word x_pos,word y_pos,byte color)
{
Display_paintbrush(x_pos,y_pos,color,0);
Permanent_draw_count ++;
// Check every 8 pixels
if (! (Permanent_draw_count&7))
{
Uint32 now = SDL_GetTicks();
if (now>= Permanent_draw_next_refresh)
{
Permanent_draw_next_refresh = now+100;
Flush_update();
}
}
}
// Affichage d'un point de façon définitive
@ -1157,6 +1178,7 @@ void Draw_empty_circle_general(short center_x,short center_y,short radius,byte c
void Draw_empty_circle_permanent(short center_x,short center_y,short radius,byte color)
{
Pixel_figure=Pixel_figure_permanent;
Init_permanent_draw();
Draw_empty_circle_general(center_x,center_y,radius,color);
Update_part_of_screen(center_x - radius, center_y - radius, 2* radius+1, 2*radius+1);
}
@ -1299,6 +1321,7 @@ void Draw_empty_ellipse_general(short center_x,short center_y,short horizontal_r
void Draw_empty_ellipse_permanent(short center_x,short center_y,short horizontal_radius,short vertical_radius,byte color)
{
Pixel_figure=Pixel_figure_permanent;
Init_permanent_draw();
Draw_empty_ellipse_general(center_x,center_y,horizontal_radius,vertical_radius,color);
Update_part_of_screen(center_x - horizontal_radius, center_y - vertical_radius, 2* horizontal_radius+1, 2*vertical_radius+1);
}
@ -1499,7 +1522,6 @@ void Draw_line_general(short start_x,short start_y,short end_x,short end_y, byte
short i,cumul;
short delta_x,delta_y;
x_pos=start_x;
y_pos=start_y;
@ -1563,11 +1585,12 @@ void Draw_line_general(short start_x,short start_y,short end_x,short end_y, byte
// -- Tracer définitif d'une ligne --
void Draw_line_permanet(short start_x,short start_y,short end_x,short end_y, byte color)
void Draw_line_permanent(short start_x,short start_y,short end_x,short end_y, byte color)
{
int w = end_x-start_x, h = end_y - start_y;
Pixel_figure=Pixel_figure_permanent;
Init_permanent_draw();
Draw_line_general(start_x,start_y,end_x,end_y,color);
Update_part_of_screen((start_x<end_x)?start_x:end_x,(start_y<end_y)?start_y:end_y,abs(w)+1,abs(h)+1);
}
@ -1762,6 +1785,7 @@ void Draw_curve_permanent(short x1, short y1,
byte color)
{
Pixel_figure=Pixel_figure_permanent;
Init_permanent_draw();
Draw_curve_general(x1,y1,x2,y2,x3,y3,x4,y4,color);
}

View File

@ -68,7 +68,7 @@ void Draw_filled_ellipse (short center_x,short center_y,short horizontal_
void Clamp_coordinates_regular_angle(short ax, short ay, short* bx, short* by);
void Draw_line_general(short start_x,short start_y,short end_x,short end_y, byte color);
void Draw_line_permanet (short start_x,short start_y,short end_x,short end_y,byte color);
void Draw_line_permanent (short start_x,short start_y,short end_x,short end_y,byte color);
void Draw_line_preview (short start_x,short start_y,short end_x,short end_y,byte color);
void Draw_line_preview_xor(short start_x,short start_y,short end_x,short end_y,byte color);
void Draw_line_preview_xorback(short start_x,short start_y,short end_x,short end_y,byte color);

50
input.c
View File

@ -53,7 +53,8 @@ byte Directional_click;
long Directional_delay;
long Directional_last_move;
long Directional_step;
short Mouse_count; // Number of mouse movements received in the current Get_input()
int Mouse_moved; ///< Boolean, Set to true if any cursor movement occurs.
int Mouse_blocked; ///< Boolean, Set to true if mouse movement was clipped.
word Input_new_mouse_X;
word Input_new_mouse_Y;
@ -112,19 +113,18 @@ int Is_shortcut(word Key, word function)
int Move_cursor_with_constraints()
{
int feedback=0;
byte bl=0;//BL va indiquer si on doit corriger la position du curseur
// Clip mouse to the editing area. There can be a border when using big
// pixels, if the SDL screen dimensions are not factors of the pixel size.
if (Input_new_mouse_Y>=Screen_height)
{
Input_new_mouse_Y=Screen_height-1;
bl=1;
Mouse_blocked=1;
}
if (Input_new_mouse_X>=Screen_width)
{
Input_new_mouse_X=Screen_width-1;
bl=1;
Mouse_blocked=1;
}
//Gestion "avancée" du curseur: interdire la descente du curseur dans le
//menu lorsqu'on est en train de travailler dans l'image
@ -136,7 +136,7 @@ int Move_cursor_with_constraints()
if(Menu_Y<=Input_new_mouse_Y)
{
//On bloque le curseur en fin d'image
bl++;
Mouse_blocked=1;
Input_new_mouse_Y=Menu_Y-1; //La ligne !!au-dessus!! du menu
}
@ -146,7 +146,7 @@ int Move_cursor_with_constraints()
{
if(Input_new_mouse_X>=Main_separator_position)
{
bl++;
Mouse_blocked=1;
Input_new_mouse_X=Main_separator_position-1;
}
}
@ -154,7 +154,7 @@ int Move_cursor_with_constraints()
{
if(Input_new_mouse_X<Main_X_zoom)
{
bl++;
Mouse_blocked=1;
Input_new_mouse_X=Main_X_zoom;
}
}
@ -172,20 +172,24 @@ int Move_cursor_with_constraints()
if (Input_new_mouse_K == 0)
Input_sticky_control = 0;
}
Hide_cursor(); // On efface le curseur AVANT de le déplacer...
// Hide cursor, because even just a click change needs it
if (!Mouse_moved)
{
Mouse_moved=1;
// Hide cursor (erasing icon and brush on screen
// before changing the coordinates.
Hide_cursor();
}
if (Input_new_mouse_X != Mouse_X || Input_new_mouse_Y != Mouse_Y)
{
Mouse_X=Input_new_mouse_X;
Mouse_Y=Input_new_mouse_Y;
if (bl)
if (Mouse_blocked)
Set_mouse_position();
}
Mouse_K=Input_new_mouse_K;
Compute_paintbrush_coordinates();
Display_cursor();
Mouse_count++;
if (Mouse_count>Config.Mouse_merge_movement)
if (Operation_stack_size != 0)
feedback=1;
}
@ -653,7 +657,10 @@ int Get_input(void)
Key_ANSI = 0;
Key = 0;
Mouse_count=0;
Mouse_moved=0;
Mouse_blocked=0;
Input_new_mouse_X = Mouse_X;
Input_new_mouse_Y = Mouse_Y;
// Process as much events as possible without redrawing the screen.
// This mostly allows us to merge mouse events for people with an high
@ -770,11 +777,20 @@ int Get_input(void)
}
}
}
// Vidage de toute mise à jour de l'affichage à l'écran qui serait encore en attente.
// (c'est fait ici car on est sur que cette function est apellée partout ou on a besoin d'interragir avec l'utilisateur)
// If the cursor was moved since last update,
// it was erased, so we need to redraw it (with the preview brush)
if (Mouse_moved)
{
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 user_feedback_required;
return Mouse_moved || user_feedback_required;
}
void Adjust_mouse_sensitivity(word fullscreen)

View File

@ -224,7 +224,7 @@ void Freehand_mode1_1_2(void)
{
Hide_cursor();
Print_coordinates();
Draw_line_permanet(start_x,start_y,Paintbrush_X,Paintbrush_Y,Fore_color);
Draw_line_permanent(start_x,start_y,Paintbrush_X,Paintbrush_Y,Fore_color);
Display_cursor();
}
@ -279,7 +279,7 @@ void Freehand_mode1_2_2(void)
{
Print_coordinates();
Hide_cursor();
Draw_line_permanet(start_x,start_y,Paintbrush_X,Paintbrush_Y,Back_color);
Draw_line_permanent(start_x,start_y,Paintbrush_X,Paintbrush_Y,Back_color);
Display_cursor();
}
@ -572,7 +572,7 @@ void Line_0_5(void)
Pixel_figure_preview_auto (start_x,start_y);
Hide_line_preview (start_x,start_y,end_x,end_y);
Display_paintbrush (start_x,start_y,color,0);
Draw_line_permanet(start_x,start_y,end_x,end_y,color);
Draw_line_permanent(start_x,start_y,end_x,end_y,color);
End_of_modification();
if ( (Config.Coords_rel) && (Menu_is_visible) )
@ -695,7 +695,7 @@ void K_line_0_6(void)
Display_paintbrush(start_x,start_y,color,0);
direction=(direction & 0x7F);
}
Draw_line_permanet(start_x,start_y,Paintbrush_X,Paintbrush_Y,color);
Draw_line_permanent(start_x,start_y,Paintbrush_X,Paintbrush_Y,color);
Paintbrush_shape=PAINTBRUSH_SHAPE_POINT;
Operation_push(direction);
@ -2242,7 +2242,7 @@ void Polygon_12_9(void)
Paintbrush_shape=Paintbrush_shape_before_operation;
// Le pied aurait été de ne pas repasser sur le 1er point de la 1ère ligne
// mais c'est pas possible :(
Draw_line_permanet(start_x,start_y,end_x,end_y,color);
Draw_line_permanent(start_x,start_y,end_x,end_y,color);
Paintbrush_shape=PAINTBRUSH_SHAPE_POINT;
Display_cursor();
@ -2534,7 +2534,7 @@ void Polyform_12_8(void)
Hide_line_preview(start_x,start_y,end_x,end_y);
// On l'affiche de façon définitive:
Draw_line_permanet(start_x,start_y,Paintbrush_X,Paintbrush_Y,color);
Draw_line_permanent(start_x,start_y,Paintbrush_X,Paintbrush_Y,color);
// Et on affiche un pixel de preview en (Paintbrush_X,Paintbrush_Y):
Pixel_figure_preview(Paintbrush_X,Paintbrush_Y,color);
@ -2565,7 +2565,7 @@ void Polyform_12_8(void)
Hide_line_preview(start_x,start_y,end_x,end_y);
// On affiche de façon définitive le bouclage du polygone:
Draw_line_permanet(start_x,start_y,initial_x,initial_y,color);
Draw_line_permanent(start_x,start_y,initial_x,initial_y,color);
Display_cursor();
End_of_modification();
@ -5056,7 +5056,7 @@ void Centered_lines_12_7(void)
Smear_start=1;
Display_paintbrush (start_x,start_y,color,0);
Draw_line_permanet(start_x,start_y,Paintbrush_X,Paintbrush_Y,color);
Draw_line_permanent(start_x,start_y,Paintbrush_X,Paintbrush_Y,color);
Paintbrush_shape=PAINTBRUSH_SHAPE_POINT;
Pixel_figure_preview(Paintbrush_X,Paintbrush_Y,color);