diff --git a/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp b/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp index 4db3e7ed7..b178dfe04 100755 --- a/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp +++ b/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp @@ -45,13 +45,20 @@ void BitmapBuffer::drawHorizontalLine(coord_t x, coord_t y, coord_t w, uint8_t p { APPLY_OFFSET(); + // line is off-screen if (y >= _height || y >= ymax || y < ymin) return; + // clip width if (x + w > _width) { 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 color = lcdColorTable[COLOR_IDX(flags)]; 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(); + // start is off-screen if (x >= xmax || y >= ymax) return; + // make height positive if (h < 0) { y += h; h = -h; } + + // clip y if (y < ymin) { h += y-ymin; y = ymin; } + + if (y + h > ymax) + h = ymax - y; + + // clip x if (x < xmin) { w += x - xmin; x = xmin; } - if (y + h > ymax) - h = ymax - y; + if (x + w > xmax) w = xmax - x; for (coord_t i = y; i < y + h; i++) { - drawHorizontalLine(x, i, w, pat, flags); + drawHorizontalLineAbs(x, i, w, pat, flags); } } diff --git a/radio/src/thirdparty/libopenui/src/bitmapbuffer.h b/radio/src/thirdparty/libopenui/src/bitmapbuffer.h index e0243e56d..1c0c161d0 100755 --- a/radio/src/thirdparty/libopenui/src/bitmapbuffer.h +++ b/radio/src/thirdparty/libopenui/src/bitmapbuffer.h @@ -516,6 +516,7 @@ class BitmapBuffer: public BitmapBufferBase static BitmapBuffer * load_bmp(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); + void drawHorizontalLineAbs(coord_t x, coord_t y, coord_t w, uint8_t pat, LcdFlags flags); }; extern BitmapBuffer * lcd;