Fix unsigned/signed compare bug in drawFastHLine

Also change int arguments to int16_t in drawPixel for consistency
This commit is contained in:
Scott Allen 2016-09-14 17:50:05 -04:00
parent 9f9691d546
commit fd4cef7025
4 changed files with 31 additions and 27 deletions

View File

@ -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"

View File

@ -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.

View File

@ -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,26 +428,28 @@ 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;
@ -458,16 +460,18 @@ void Arduboy2Base::drawFastHLine
switch (color)
{
case WHITE:
while(w--) {
while (w--)
{
*pBuf++ |= mask;
};
}
break;
case BLACK:
mask = ~mask;
while(w--) {
while (w--)
{
*pBuf++ &= mask;
};
}
break;
}
}

View File

@ -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.
/**