From 0324a95051563ca8a863b5f25b8af681d1281dbe Mon Sep 17 00:00:00 2001 From: Rudo Thomas Date: Thu, 2 Apr 2020 16:23:07 +0200 Subject: [PATCH] DrawFrame: Draw corners just once, fixes XOR mode. --- csrc/u8g2_box.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/csrc/u8g2_box.c b/csrc/u8g2_box.c index 38ae83fe..539bfd55 100644 --- a/csrc/u8g2_box.c +++ b/csrc/u8g2_box.c @@ -57,8 +57,6 @@ void u8g2_DrawBox(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g /* draw a frame (empty box) restriction: does not work for w = 0 or h = 0 - ToDo: - pixel in the corners are drawn twice. This could be optimized. */ void u8g2_DrawFrame(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h) { @@ -70,13 +68,18 @@ void u8g2_DrawFrame(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u #endif /* U8G2_WITH_INTERSECTION */ u8g2_DrawHVLine(u8g2, x, y, w, 0); - u8g2_DrawHVLine(u8g2, x, y, h, 1); - x+=w; - x--; - u8g2_DrawHVLine(u8g2, x, y, h, 1); - y+=h; - y--; - u8g2_DrawHVLine(u8g2, xtmp, y, w, 0); + if (h >= 2) { + h-=2; + y++; + if (h > 0) { + u8g2_DrawHVLine(u8g2, x, y, h, 1); + x+=w; + x--; + u8g2_DrawHVLine(u8g2, x, y, h, 1); + y+=h; + } + u8g2_DrawHVLine(u8g2, xtmp, y, w, 0); + } }