Code C graphic LCD#2

/////////////////////////////////////////////////////////////////////////
// Purpose: Draw a rectangle on a graphic LCD
// Inputs: (x1, y1) – the start coordinate
// (x2, y2) – the end coordinate
// fill – YES or NO
// color – ON or OFF
// Dependencies: glcd_pixel(), glcd_line()
/////////////////////////////////////////////////////////////////////////
#ifdef LARGE_LCD
void glcd_rect(int16 x1, int16 y1, int16 x2, int16 y2, int1 fill, int1 color)
#else
void glcd_rect(int8 x1, int8 y1, int8 x2, int8 y2, int1 fill, int1 color)
#endif
{
if(fill)
{
#ifdef LARGE_LCD
int16 i, xmin, xmax, ymin, ymax;
#else
int8 i, xmin, xmax, ymin, ymax;
#endif

if(x1 < x2) // Find x min and max
{
xmin = x1;
xmax = x2;
}
else
{
xmin = x2;
xmax = x1;
}

if(y1 < y2) // Find the y min and max
{
ymin = y1;
ymax = y2;
}
else
{
ymin = y2;
ymax = y1;
}

for(; xmin <= xmax; ++xmin)
{
for(i=ymin; i<=ymax; ++i)
{
glcd_pixel(xmin, i, color);
}
}
}
else
{
glcd_line(x1, y1, x2, y1, color); // Draw the 4 sides
glcd_line(x1, y2, x2, y2, color);
glcd_line(x1, y1, x1, y2, color);
glcd_line(x2, y1, x2, y2, color);
}

}

Programming Click Now

ใส่ความเห็น

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: