Continued the line clamping. Seems to work perfectly for all 16 directions, but I discovered an older problem in the input handler when you release a key that participates in cursor emulation. Not completely fixed.
git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@895 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
parent
19a2892e88
commit
9e9fd506b6
94
graph.c
94
graph.c
@ -1358,65 +1358,57 @@ void Draw_filled_ellipse(short center_x,short center_y,short horizontal_radius,s
|
||||
|
||||
/// Alters bx and by so the (AX,AY)-(BX,BY) segment becomes either horizontal,
|
||||
/// vertical, 45degrees, or isometrical for pixelart (ie 2:1 ratio)
|
||||
void Clamp_coordinates_45_degrees(short ax, short ay, short* bx, short* by)
|
||||
void Clamp_coordinates_regular_angle(short ax, short ay, short* bx, short* by)
|
||||
{
|
||||
int dx, dy;
|
||||
float tan;
|
||||
float angle;
|
||||
float length;
|
||||
|
||||
dx = (*bx)-ax;
|
||||
dy = ay- *by;
|
||||
// On prend l'opposée car à l'écran les Y sont positifs en bas, et en
|
||||
// maths, positifs en haut
|
||||
dx = *bx-ax;
|
||||
dy = *by-ay;
|
||||
|
||||
if (dx==0) return;
|
||||
if (dx==0 || dy == 0) return;
|
||||
// On est en lockx et de toutes façons le X n'a pas bougé, on sort tout
|
||||
// de suite pour éviter une méchante division par 0
|
||||
|
||||
tan = (float)dy/(float)dx;
|
||||
angle = atan2(dx, dy);
|
||||
|
||||
// These equation look a bit more complex than they should, but that's
|
||||
// because we have to balance the line length to make it end near the
|
||||
// cursor
|
||||
if (tan <= 0.25 && tan >= -0.25)
|
||||
{
|
||||
// horizontal (OK)
|
||||
*by = ay;
|
||||
}
|
||||
else if ( tan > 0.25 && tan < 0.75)
|
||||
{
|
||||
// dx=2dy, iso (ok)
|
||||
*bx = (2* *bx + ax + 2*dy)/3;
|
||||
*by = ay - (*bx-ax)/2;
|
||||
}
|
||||
else if ( tan >=0.75 && tan <= 1.5 )
|
||||
{
|
||||
// dy=-dx, diagonal upright (ok)
|
||||
*by = (*by + ay - dx)/2;
|
||||
*bx = ax + ay - *by;
|
||||
}
|
||||
else if ( tan > 1.5 && tan <= 3 )
|
||||
{
|
||||
// "vertical iso"
|
||||
}
|
||||
else if (tan < -0.25 && tan >= -0.75)
|
||||
{
|
||||
// iso to bottom
|
||||
}
|
||||
else if ( tan <-0.75 && tan > -1.5 )
|
||||
{
|
||||
// dy=dx, downright diagonal (ok)
|
||||
*by = (*by + ay + dx)/2;
|
||||
*bx = ax - ay + *by;
|
||||
}
|
||||
else if ( tan < -1.5 && tan >= -3 )
|
||||
{
|
||||
// vertical iso to bottom
|
||||
}
|
||||
else
|
||||
{
|
||||
// vertical (ok)
|
||||
*bx = ax;
|
||||
}
|
||||
if (angle < M_PI*(-15.0/16.0) || angle > M_PI*(15.0/16.0))
|
||||
angle = M_PI*(16.0/16.0);
|
||||
else if (angle < M_PI*(-13.0/16.0))
|
||||
angle = -2.677945045;
|
||||
else if (angle < M_PI*(-11.0/16.0))
|
||||
angle = M_PI*(-12.0/16.0);
|
||||
else if (angle < M_PI*(-9.0/16.0))
|
||||
angle = -2.034443936;
|
||||
else if (angle < M_PI*(-7.0/16.0))
|
||||
angle = M_PI*(-8.0/16.0);
|
||||
else if (angle < M_PI*(-5.0/16.0))
|
||||
angle = -1.107148718;
|
||||
else if (angle < M_PI*(-3.0/16.0))
|
||||
angle = M_PI*(-4.0/16.0);
|
||||
else if (angle < M_PI*(-1.0/16.0))
|
||||
angle = -0.463647609;
|
||||
else if (angle < M_PI*(1.0/16.0))
|
||||
angle = M_PI*(0.0/16.0);
|
||||
else if (angle < M_PI*(3.0/16.0))
|
||||
angle = 0.463647609;
|
||||
else if (angle < M_PI*(5.0/16.0))
|
||||
angle = M_PI*(4.0/16.0);
|
||||
else if (angle < M_PI*(7.0/16.0))
|
||||
angle = 1.107148718;
|
||||
else if (angle < M_PI*(9.0/16.0))
|
||||
angle = M_PI*(8.0/16.0);
|
||||
else if (angle < M_PI*(11.0/16.0))
|
||||
angle = 2.034443936;
|
||||
else if (angle < M_PI*(13.0/16.0))
|
||||
angle = M_PI*(12.0/16.0);
|
||||
else //if (angle < M_PI*(15.0/16.0))
|
||||
angle = 2.677945045;
|
||||
|
||||
length = sqrt((float)(dx)*(float)(dx)+(float)(dy)*(float)(dy));
|
||||
*bx=ax + lrintf(sin(angle)*length);
|
||||
*by=ay + lrintf(cos(angle)*length);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
2
graph.h
2
graph.h
@ -66,7 +66,7 @@ void Draw_empty_ellipse_preview (short center_x,short center_y,short horizontal
|
||||
void Hide_empty_ellipse_preview (short center_x,short center_y,short horizontal_radius,short vertical_radius);
|
||||
void Draw_filled_ellipse (short center_x,short center_y,short horizontal_radius,short vertical_radius,byte color);
|
||||
|
||||
void Clamp_coordinates_45_degrees(short ax, short ay, short* bx, short* by);
|
||||
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_preview (short start_x,short start_y,short end_x,short end_y,byte color);
|
||||
|
||||
24
input.c
24
input.c
@ -345,34 +345,34 @@ int Handle_key_press(SDL_KeyboardEvent event)
|
||||
int Release_control(int key_code, int modifier)
|
||||
{
|
||||
|
||||
if(key_code == (Config_Key[SPECIAL_MOUSE_UP][0]&0x0FFF) || (Config_Key[SPECIAL_MOUSE_UP][0]&modifier) ||
|
||||
key_code == (Config_Key[SPECIAL_MOUSE_UP][1]&0x0FFF) || (Config_Key[SPECIAL_MOUSE_UP][1]&modifier))
|
||||
if((key_code && key_code == (Config_Key[SPECIAL_MOUSE_UP][0]&0x0FFF)) || (Config_Key[SPECIAL_MOUSE_UP][0]&modifier) ||
|
||||
(key_code && key_code == (Config_Key[SPECIAL_MOUSE_UP][1]&0x0FFF)) || (Config_Key[SPECIAL_MOUSE_UP][1]&modifier))
|
||||
{
|
||||
Directional_up=0;
|
||||
}
|
||||
if(key_code == (Config_Key[SPECIAL_MOUSE_DOWN][0]&0x0FFF) || (Config_Key[SPECIAL_MOUSE_DOWN][0]&modifier) ||
|
||||
key_code == (Config_Key[SPECIAL_MOUSE_DOWN][1]&0x0FFF) || (Config_Key[SPECIAL_MOUSE_DOWN][1]&modifier))
|
||||
if((key_code && key_code == (Config_Key[SPECIAL_MOUSE_DOWN][0]&0x0FFF)) || (Config_Key[SPECIAL_MOUSE_DOWN][0]&modifier) ||
|
||||
(key_code && key_code == (Config_Key[SPECIAL_MOUSE_DOWN][1]&0x0FFF)) || (Config_Key[SPECIAL_MOUSE_DOWN][1]&modifier))
|
||||
{
|
||||
Directional_down=0;
|
||||
}
|
||||
if(key_code == (Config_Key[SPECIAL_MOUSE_LEFT][0]&0x0FFF) || (Config_Key[SPECIAL_MOUSE_LEFT][0]&modifier) ||
|
||||
key_code == (Config_Key[SPECIAL_MOUSE_LEFT][1]&0x0FFF) || (Config_Key[SPECIAL_MOUSE_LEFT][1]&modifier))
|
||||
if((key_code && key_code == (Config_Key[SPECIAL_MOUSE_LEFT][0]&0x0FFF)) || (Config_Key[SPECIAL_MOUSE_LEFT][0]&modifier) ||
|
||||
(key_code && key_code == (Config_Key[SPECIAL_MOUSE_LEFT][1]&0x0FFF)) || (Config_Key[SPECIAL_MOUSE_LEFT][1]&modifier))
|
||||
{
|
||||
Directional_left=0;
|
||||
}
|
||||
if(key_code == (Config_Key[SPECIAL_MOUSE_RIGHT][0]&0x0FFF) || (Config_Key[SPECIAL_MOUSE_RIGHT][0]&modifier) ||
|
||||
key_code == (Config_Key[SPECIAL_MOUSE_RIGHT][1]&0x0FFF) || (Config_Key[SPECIAL_MOUSE_RIGHT][1]&modifier))
|
||||
if((key_code && key_code == (Config_Key[SPECIAL_MOUSE_RIGHT][0]&0x0FFF)) || (Config_Key[SPECIAL_MOUSE_RIGHT][0]&modifier) ||
|
||||
(key_code && key_code == (Config_Key[SPECIAL_MOUSE_RIGHT][1]&0x0FFF)) || (Config_Key[SPECIAL_MOUSE_RIGHT][1]&modifier))
|
||||
{
|
||||
Directional_right=0;
|
||||
}
|
||||
if(key_code == (Config_Key[SPECIAL_CLICK_LEFT][0]&0x0FFF) || (Config_Key[SPECIAL_CLICK_LEFT][0]&modifier) ||
|
||||
key_code == (Config_Key[SPECIAL_CLICK_LEFT][1]&0x0FFF) || (Config_Key[SPECIAL_CLICK_LEFT][1]&modifier))
|
||||
if((key_code && key_code == (Config_Key[SPECIAL_CLICK_LEFT][0]&0x0FFF)) || (Config_Key[SPECIAL_CLICK_LEFT][0]&modifier) ||
|
||||
(key_code && key_code == (Config_Key[SPECIAL_CLICK_LEFT][1]&0x0FFF)) || (Config_Key[SPECIAL_CLICK_LEFT][1]&modifier))
|
||||
{
|
||||
Input_new_mouse_K &= ~1;
|
||||
return Move_cursor_with_constraints();
|
||||
}
|
||||
if(key_code == (Config_Key[SPECIAL_CLICK_RIGHT][0]&0x0FFF) || (Config_Key[SPECIAL_CLICK_RIGHT][0]&modifier) ||
|
||||
key_code == (Config_Key[SPECIAL_CLICK_RIGHT][1]&0x0FFF) || (Config_Key[SPECIAL_CLICK_RIGHT][1]&modifier))
|
||||
if((key_code && key_code == (Config_Key[SPECIAL_CLICK_RIGHT][0]&0x0FFF)) || (Config_Key[SPECIAL_CLICK_RIGHT][0]&modifier) ||
|
||||
(key_code && key_code == (Config_Key[SPECIAL_CLICK_RIGHT][1]&0x0FFF)) || (Config_Key[SPECIAL_CLICK_RIGHT][1]&modifier))
|
||||
{
|
||||
Input_new_mouse_K &= ~2;
|
||||
return Move_cursor_with_constraints();
|
||||
|
||||
34
operatio.c
34
operatio.c
@ -491,19 +491,25 @@ void Line_12_5(void)
|
||||
short end_x;
|
||||
short end_y;
|
||||
|
||||
short cursor_x;
|
||||
short cursor_y;
|
||||
|
||||
Operation_pop(&end_y);
|
||||
Operation_pop(&end_x);
|
||||
Operation_pop(&start_y);
|
||||
Operation_pop(&start_x);
|
||||
|
||||
cursor_x = Paintbrush_X;
|
||||
cursor_y = Paintbrush_Y;
|
||||
|
||||
// On corrige les coordonnées de la ligne si la touche shift est appuyée...
|
||||
if(SDL_GetModState() & KMOD_SHIFT)
|
||||
{
|
||||
Clamp_coordinates_45_degrees(start_x,start_y,&Paintbrush_X,&Paintbrush_Y);
|
||||
Clamp_coordinates_regular_angle(start_x,start_y,&cursor_x,&cursor_y);
|
||||
}
|
||||
|
||||
// On vient de bouger
|
||||
if ((Paintbrush_X!=end_x) || (Paintbrush_Y!=end_y))
|
||||
if ((cursor_x!=end_x) || (cursor_y!=end_y))
|
||||
{
|
||||
Hide_cursor();
|
||||
|
||||
@ -513,18 +519,18 @@ void Line_12_5(void)
|
||||
if (Mouse_K==LEFT_SIDE)
|
||||
{
|
||||
Pixel_figure_preview (start_x,start_y,Fore_color);
|
||||
Draw_line_preview (start_x,start_y,Paintbrush_X,Paintbrush_Y,Fore_color);
|
||||
Draw_line_preview (start_x,start_y,cursor_x,cursor_y,Fore_color);
|
||||
}
|
||||
else
|
||||
{
|
||||
Pixel_figure_preview (start_x,start_y,Back_color);
|
||||
Draw_line_preview (start_x,start_y,Paintbrush_X,Paintbrush_Y,Back_color);
|
||||
Draw_line_preview (start_x,start_y,cursor_x,cursor_y,Back_color);
|
||||
}
|
||||
|
||||
Operation_push(start_x);
|
||||
Operation_push(start_y);
|
||||
Operation_push(Paintbrush_X);
|
||||
Operation_push(Paintbrush_Y);
|
||||
Operation_push(cursor_x);
|
||||
Operation_push(cursor_y);
|
||||
|
||||
Display_cursor();
|
||||
}
|
||||
@ -559,10 +565,6 @@ void Line_0_5(void)
|
||||
Operation_pop(&start_x);
|
||||
Operation_pop(&color);
|
||||
|
||||
// On corrige les coordonnées de la ligne si la touche shift est appuyée...
|
||||
if(SDL_GetModState() & KMOD_SHIFT)
|
||||
Clamp_coordinates_45_degrees(start_x,start_y,&end_x,&end_y);
|
||||
|
||||
Paintbrush_shape=Paintbrush_shape_before_operation;
|
||||
|
||||
Pixel_figure_preview_auto (start_x,start_y);
|
||||
@ -4760,22 +4762,26 @@ void Grad_rectangle_12_9(void)
|
||||
short start_y;
|
||||
short end_x;
|
||||
short end_y;
|
||||
short cursor_x;
|
||||
short cursor_y;
|
||||
|
||||
Operation_pop(&end_y);
|
||||
Operation_pop(&end_x);
|
||||
Operation_pop(&start_y);
|
||||
Operation_pop(&start_x);
|
||||
|
||||
if ((Paintbrush_X!=end_x) || (Paintbrush_Y!=end_y))
|
||||
{
|
||||
cursor_x = Paintbrush_X;
|
||||
cursor_y = Paintbrush_Y;
|
||||
// On corrige les coordonnées de la ligne si la touche shift est appuyée...
|
||||
if(SDL_GetModState() & KMOD_SHIFT)
|
||||
Clamp_coordinates_45_degrees(start_x,start_y,&Paintbrush_X,&Paintbrush_Y);
|
||||
Clamp_coordinates_regular_angle(start_x,start_y,&cursor_x,&cursor_y);
|
||||
|
||||
if ((cursor_x!=end_x) || (cursor_y!=end_y))
|
||||
{
|
||||
Display_coords_rel_or_abs(start_x,start_y);
|
||||
|
||||
Draw_line_preview_xor(start_x,start_y,end_x,end_y,0);
|
||||
Draw_line_preview_xor(start_x,start_y,Paintbrush_X,Paintbrush_Y,0);
|
||||
Draw_line_preview_xor(start_x,start_y,cursor_x,cursor_y,0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user