Code C graphic LCD #3

/////////////////////////////////////////////////////////////////////////
// Purpose: Draw a bar (wide line) on a graphic LCD
// Inputs: (x1, y1) – the start coordinate
// (x2, y2) – the end coordinate
// width – The number of pixels wide
// color – ON or OFF
/////////////////////////////////////////////////////////////////////////
#ifdef LARGE_LCD
void glcd_bar(int16 x1, int16 y1, int16 x2, int16 y2, int8 width, int1 color)
#else
void glcd_bar(int8 x1, int8 y1, int8 x2, int8 y2, int8 width, int1 color)
#endif
{
int8 half_width;
signed int16 dy, dx;
signed int8 addx=1, addy=1, j;
signed int16 P, diff, c1, c2;

#ifdef LARGE_LCD
int16 i=0;
dx = abs((signed int16)(x2 – x1));
dy = abs((signed int16)(y2 – y1));
#else
int8 i=0;
dx = abs((signed int8)(x2 – x1));
dy = abs((signed int8)(y2 – y1));
#endif

half_width = width/2;
c1 = -(dx*x1 + dy*y1);
c2 = -(dx*x2 + dy*y2);

if(x1 > x2)
{
signed int16 temp;
temp = c1;
c1 = c2;
c2 = temp;
addx = -1;
}
if(y1 > y2)
{
signed int16 temp;
temp = c1;
c1 = c2;
c2 = temp;
addy = -1;
}

if(dx >= dy)
{
P = 2*dy – dx;
diff = P – dx;

for(i=0; i<=dx; ++i)
{
for(j=-half_width; j<half_width+width%2; ++j)
{
#ifdef LARGE_LCD
int16 temp;
#else
int8 temp;
#endif

temp = dx*x1+dy*(y1+j); // Use more RAM to increase speed
if(temp+c1 >= 0 && temp+c2 <=0)
glcd_pixel(x1, y1+j, color);
}
if(P < 0)
{
P += 2*dy;
x1 += addx;
}
else
{
P += diff;
x1 += addx;
y1 += addy;
}
}
}
else
{
P = 2*dx – dy;
diff = P – dy;

for(i=0; i<=dy; ++i)
{
if(P < 0)
{
P += 2*dx;
y1 += addy;
}
else
{
P += diff;
x1 += addx;
y1 += addy;
}
for(j=-half_width; j<half_width+width%2; ++j)
{
#ifdef LARGE_LCD
int16 temp;
#else
int8 temp;
#endif

temp = dx*x1+dy*(y1+j); // Use more RAM to increase speed
if(temp+c1 >= 0 && temp+c2 <=0)
glcd_pixel(x1+j, y1, color);
}
}
}
}

ใส่ความเห็น

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / เปลี่ยนแปลง )

Twitter picture

You are commenting using your Twitter account. Log Out / เปลี่ยนแปลง )

Facebook photo

You are commenting using your Facebook account. Log Out / เปลี่ยนแปลง )

Google+ photo

You are commenting using your Google+ account. Log Out / เปลี่ยนแปลง )

Connecting to %s

%d bloggers like this: