graphics_rgb565.c: Implement drawing empty rectangles

This commit is contained in:
Federico Amedeo Izzo 2020-10-09 13:56:28 +02:00 committed by Niccolò Izzo
parent dac60a7be5
commit 09602387b2
2 changed files with 6 additions and 2 deletions

View File

@ -152,7 +152,7 @@ void graphics_drawLine(point_t start, point_t end, color_t color);
* @param width: rectangle width, in pixels, borders included.
* @param height: rectangle height, in pixels, borders included.
* @param color: border and fill color, in color_t format.
* @param fill: if true the rectangle will be solid, otherwise it will have a 1-pixel border
* @param fill: if true the rectangle will be solid, otherwise it will be empty with a 1-pixel border
*/
void graphics_drawRect(point_t start, uint16_t width, uint16_t height, color_t color, bool fill);

View File

@ -136,13 +136,17 @@ void graphics_drawRect(point_t start, uint16_t width, uint16_t height, color_t c
rgb565_t color_565 = _true2highColor(color);
uint16_t x_max = start.x + width;
uint16_t y_max = start.y + height;
bool perimeter = 0;
if(x_max > (screen_width - 1)) x_max = screen_width - 1;
if(y_max > (screen_height - 1)) y_max = screen_height - 1;
for(int y=start.y; y < y_max; y++)
{
for(int x=start.x; x < x_max; x++)
{
buf[x + y*screen_width] = color_565;
if(y == start.y || y == y_max-1 || x == start.x || x == x_max-1) perimeter = 1;
else perimeter = 0;
// If fill is false, draw only rectangle perimeter
if(fill || perimeter) buf[x + y*screen_width] = color_565;
}
}
}