}
//»-Ïßoˉêy£¬ê1óÃBresenham »-ÏßËã·¨
void Gui_DrawLine(u16 x0, u16 y0,u16 x1, u16 y1,u16 Color)
{
int dx, // difference in x's
dy, // difference in y's
dx2, // dx,dy * 2
dy2,
x_inc, // amount in pixel space to move during drawing
y_inc, // amount in pixel space to move during drawing
error, // the discriminant i.e. error i.e. decision variable
index; // used for looping
Lcd_SetXY(x0,y0);
dx = x1-x0;//¼ÆËãx¾ààë
dy = y1-y0;//¼ÆËãy¾ààë
if (dy>=0)
{
y_inc = 1;
}
else
{
y_inc = -1;
dy = -dy;
}
dx2 = dx << 1;
dy2 = dy << 1;
if (dx > dy)//x¾ààë′óóúy¾àà룬ÄÇÃ′ÿ¸öxÖáéÏÖ»óDò»¸öμ㣬ÿ¸öyÖáéÏóDèô¸é¸öμã
{//ÇòÏßμÄμãêyμèóúx¾àà룬òÔxÖáμYÔö»-μã
// initialize error term
error = dy2 - dx;
// draw the line
for (index=0; index <= dx; index++)//òa»-μÄμãêy2»»á3¬1yx¾ààë
{
//»-μã
Gui_DrawPoint(x0,y0,Color);
// test if error has overflowed
if (error >= 0) //êÇ·ñDèòaÔö¼óy×ø±êÖμ
{
error-=dx2;
// move to next line
y0+=y_inc;//Ôö¼óy×ø±êÖμ
} // end if error overflowed
// adjust the error term
error+=dy2;
// move to the next pixel
x0+=x_inc;//x×ø±êÖμÿ′λ-μãoó¶¼μYÔö1
} // end for
} // end if |slope| <= 1
else//yÖá′óóúxÖᣬÔòÿ¸öyÖáéÏÖ»óDò»¸öμ㣬xÖáèô¸é¸öμã
{//òÔyÖáÎaμYÔö»-μã
// initialize error term
error = dx2 - dy;
// draw the line
for (index=0; index <= dy; index++)
{
// set the pixel
Gui_DrawPoint(x0,y0,Color);
// test if error overflowed
if (error >= 0)
{
error-=dy2;
// move to next line
x0+=x_inc;
} // end if error overflowed
// adjust the error term
error+=dx2;
// move to the next pixel
y0+=y_inc;
} // end for
} // end else |slope| > 1
}