From b46c17078baf5d5f2a2da048c5756119bc186d76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Krupi=C4=8Dka?= Date: Wed, 7 Mar 2018 02:01:59 +0100 Subject: [PATCH] Adjust left limit for drawing (#219) * adjust left limit for drawing do draw area also if part just of it is visible - e.g. do not skip whole letter in rolling description if half of it can be shown * render just visible area part * fix visible area part computation --- workspace/TS100/src/OLED.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/workspace/TS100/src/OLED.cpp b/workspace/TS100/src/OLED.cpp index b7527cd2..46850485 100644 --- a/workspace/TS100/src/OLED.cpp +++ b/workspace/TS100/src/OLED.cpp @@ -286,25 +286,32 @@ void OLED::drawSymbol(uint8_t symbolID) { void OLED::drawArea(int16_t x, int8_t y, uint8_t wide, uint8_t height, const uint8_t* ptr) { // Splat this from x->x+wide in two strides - if (x < 0) + if (x <= -wide) return; //cutoffleft - if ((x) > 96) + if (x > 96) return; //cutoff right - uint8_t width = wide; - if ((x + wide) > 96) - width = 96 - x; // trimming to draw partials + + uint8_t visibleStart = 0; + uint8_t visibleEnd = wide; + + // trimming to draw partials + if(x < 0) { + visibleStart -= x; //subtract negative value == add absolute value + } + if(x + wide > 96) { + visibleEnd = 96 - x; + } if (y == 0) { //Splat first line of data - for (uint8_t xx = 0; xx < (width); xx++) { + for (uint8_t xx = visibleStart; xx < visibleEnd; xx++) { firstStripPtr[xx + x] = ptr[xx]; } } if (y == 8 || height == 16) { // Splat the second line - for (uint8_t xx = 0; xx < width; xx++) { + for (uint8_t xx = visibleStart; xx < visibleEnd; xx++) { secondStripPtr[x + xx] = ptr[xx + (height == 16 ? wide : 0)]; - } } }