Merge pull request #9 from raphaelcoeffic/drawfilledrect

fix offset applied twice in drawFilledRect()
This commit is contained in:
Bertrand Songis
2021-04-05 17:21:10 +02:00
committed by GitHub
2 changed files with 19 additions and 3 deletions
+18 -3
View File
@@ -45,13 +45,20 @@ void BitmapBuffer::drawHorizontalLine(coord_t x, coord_t y, coord_t w, uint8_t p
{ {
APPLY_OFFSET(); APPLY_OFFSET();
// line is off-screen
if (y >= _height || y >= ymax || y < ymin) if (y >= _height || y >= ymax || y < ymin)
return; return;
// clip width
if (x + w > _width) { if (x + w > _width) {
w = _width - x; w = _width - x;
} }
drawHorizontalLineAbs(x, y, w, pat, flags);
}
void BitmapBuffer::drawHorizontalLineAbs(coord_t x, coord_t y, coord_t w, uint8_t pat, LcdFlags flags)
{
pixel_t * p = getPixelPtr(x, y); pixel_t * p = getPixelPtr(x, y);
pixel_t color = lcdColorTable[COLOR_IDX(flags)]; pixel_t color = lcdColorTable[COLOR_IDX(flags)];
uint8_t opacity = 0x0F - (flags >> 24); uint8_t opacity = 0x0F - (flags >> 24);
@@ -221,28 +228,36 @@ void BitmapBuffer::drawFilledRect(coord_t x, coord_t y, coord_t w, coord_t h, ui
{ {
APPLY_OFFSET(); APPLY_OFFSET();
// start is off-screen
if (x >= xmax || y >= ymax) if (x >= xmax || y >= ymax)
return; return;
// make height positive
if (h < 0) { if (h < 0) {
y += h; y += h;
h = -h; h = -h;
} }
// clip y
if (y < ymin) { if (y < ymin) {
h += y-ymin; h += y-ymin;
y = ymin; y = ymin;
} }
if (y + h > ymax)
h = ymax - y;
// clip x
if (x < xmin) { if (x < xmin) {
w += x - xmin; w += x - xmin;
x = xmin; x = xmin;
} }
if (y + h > ymax)
h = ymax - y;
if (x + w > xmax) if (x + w > xmax)
w = xmax - x; w = xmax - x;
for (coord_t i = y; i < y + h; i++) { for (coord_t i = y; i < y + h; i++) {
drawHorizontalLine(x, i, w, pat, flags); drawHorizontalLineAbs(x, i, w, pat, flags);
} }
} }
+1
View File
@@ -516,6 +516,7 @@ class BitmapBuffer: public BitmapBufferBase<pixel_t>
static BitmapBuffer * load_bmp(const char * filename); static BitmapBuffer * load_bmp(const char * filename);
static BitmapBuffer * load_stb(const char * filename); static BitmapBuffer * load_stb(const char * filename);
uint8_t drawChar(coord_t x, coord_t y, const uint8_t * font, const uint16_t * spec, unsigned int index, LcdFlags flags); uint8_t drawChar(coord_t x, coord_t y, const uint8_t * font, const uint16_t * spec, unsigned int index, LcdFlags flags);
void drawHorizontalLineAbs(coord_t x, coord_t y, coord_t w, uint8_t pat, LcdFlags flags);
}; };
extern BitmapBuffer * lcd; extern BitmapBuffer * lcd;