diff --git a/library.json b/library.json index 48f392e..b655a0a 100644 --- a/library.json +++ b/library.json @@ -7,7 +7,7 @@ "type": "git", "url": "https://github.com/MLXXXp/Arduboy2.git" }, - "version": "2.0.1", + "version": "2.0.2", "exclude": "extras", "frameworks": "arduino", "platforms": "atmelavr" diff --git a/library.properties b/library.properties index 820e474..f8caa00 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduboy2 -version=2.0.1 +version=2.0.2 author=Chris J. Martinez, Kevin Bates, Josh Goebel, Scott Allen, Ross O. Shoger maintainer=Scott Allen saydisp-git@yahoo.ca sentence=An alternative library for use with the Arduboy game system. diff --git a/src/Arduboy2.cpp b/src/Arduboy2.cpp index faab6ca..f79e5a1 100644 --- a/src/Arduboy2.cpp +++ b/src/Arduboy2.cpp @@ -202,7 +202,7 @@ void Arduboy2Base::clear() fillScreen(BLACK); } -void Arduboy2Base::drawPixel(int x, int y, uint8_t color) +void Arduboy2Base::drawPixel(int16_t x, int16_t y, uint8_t color) { #ifdef PIXEL_SAFE_MODE if (x < 0 || x > (WIDTH-1) || y < 0 || y > (HEIGHT-1)) @@ -428,46 +428,50 @@ void Arduboy2Base::drawFastVLine void Arduboy2Base::drawFastHLine (int16_t x, int16_t y, uint8_t w, uint8_t color) { - // Do bounds/limit checks - if (y < 0 || y >= HEIGHT) { - return; - } + int16_t xEnd; // last x point + 1 - // make sure we don't try to draw below 0 - if (x < 0) { - w += x; + // Do y bounds checks + if (y < 0 || y >= HEIGHT) + return; + + xEnd = x + w; + + // Check if the entire line is not on the display + if (xEnd <= 0 || x >= WIDTH) + return; + + // Don't start before the left edge + if (x < 0) x = 0; - } - // make sure we don't go off the edge of the display - if ((x + w) > WIDTH) { - w = (WIDTH - x); - } + // Don't end past the right edge + if (xEnd > WIDTH) + xEnd = WIDTH; - // if our width is now negative, punt - if (w <= 0) { - return; - } + // calculate actual width (even if unchanged) + w = xEnd - x; // buffer pointer plus row offset + x offset - register uint8_t *pBuf = sBuffer + ((y/8) * WIDTH) + x; + register uint8_t *pBuf = sBuffer + ((y / 8) * WIDTH) + x; // pixel mask - register uint8_t mask = 1 << (y&7); + register uint8_t mask = 1 << (y & 7); switch (color) { case WHITE: - while(w--) { + while (w--) + { *pBuf++ |= mask; - }; + } break; case BLACK: mask = ~mask; - while(w--) { + while (w--) + { *pBuf++ &= mask; - }; + } break; } } diff --git a/src/Arduboy2.h b/src/Arduboy2.h index 315526a..7ef79b6 100644 --- a/src/Arduboy2.h +++ b/src/Arduboy2.h @@ -9,7 +9,7 @@ // For a version number in the form of x.y.z the value of the define will be // ((x * 10000) + (y * 100) + (z)) as a decimal number. // So, it will read as xxxyyzz, with no leading zeros on x. -#define ARDUBOY_LIB_VER 20001 +#define ARDUBOY_LIB_VER 20002 // EEPROM settings #define EEPROM_VERSION 0 @@ -108,7 +108,7 @@ public: void display(); /// Sets a single pixel on the screen buffer to white or black. - void drawPixel(int x, int y, uint8_t color = WHITE); + void drawPixel(int16_t x, int16_t y, uint8_t color = WHITE); /// Returns the state of the given pixel in the screen buffer. /**