summaryrefslogtreecommitdiff
path: root/Gfx.cpp
diff options
context:
space:
mode:
authorXaviDCR92 <xavi.dcr@gmail.com>2017-03-12 21:09:29 +0100
committerXaviDCR92 <xavi.dcr@gmail.com>2017-03-12 21:09:29 +0100
commit6628e7de58425b3e93da9ae6fcb7347137d96096 (patch)
tree336d1f74961187aad7c85ba06dcdd0684c003282 /Gfx.cpp
parentf416816883545433ea33ca410983371e657dba18 (diff)
* Player can now select nearest unit or building. Multiple buildings and units can be selected at the same time.
* Unit module moved from C++ to C (only extension change - and compiler - was needed). * GfxGetHeightFromSpriteData and GfxGetWidthFromSpriteData were getting incorrect data! Incorrect memory address was being read when calling pgm_read_byte, and caused unexpected behaviour under real hw.
Diffstat (limited to 'Gfx.cpp')
-rw-r--r--Gfx.cpp39
1 files changed, 27 insertions, 12 deletions
diff --git a/Gfx.cpp b/Gfx.cpp
index e291213..ff58551 100644
--- a/Gfx.cpp
+++ b/Gfx.cpp
@@ -91,14 +91,14 @@ bool GfxIsSpriteInsideScreenArea(TYPE_SPRITE * spr)
uint8_t GfxGetWidthFromSpriteData(const uint8_t * sprData)
{
- // On Gamebuino bitmaps, width is always stored on first byte.
- return pgm_read_byte_near(sprData[0]) << 1;
+ // On Gamebuino bitmaps, width is always stored on first byte.
+ return pgm_read_byte_near(&sprData[0]);
}
uint8_t GfxGetHeightFromSpriteData(const uint8_t * sprData)
{
// On Gamebuino bitmaps, height is always stored on second byte.
- return pgm_read_byte_near(sprData[1]) << 1;
+ return pgm_read_byte_near(&sprData[1]);
}
void GfxPrintText_Flash(const __FlashStringHelper * str)
@@ -187,11 +187,26 @@ void GfxDrawCircle(uint16_t x, uint16_t y, uint8_t radius, int8_t color)
void GfxDrawRectangle(uint8_t x, uint8_t y, uint8_t w, uint8_t h, int8_t color)
{
- int8_t orig_color = gb.display.getColor();
-
- gb.display.setColor(color);
- gb.display.fillRect(x, y, w, h);
- gb.display.setColor(orig_color);
+ if(GfxIsInsideScreenArea(x, y, w, h) == true)
+ {
+ int8_t orig_color = gb.display.getColor();
+
+ gb.display.setColor(color);
+ gb.display.drawRect(x, y, w, h);
+ gb.display.setColor(orig_color);
+ }
+}
+
+void GfxFillRectangle(uint8_t x, uint8_t y, uint8_t w, uint8_t h, int8_t color)
+{
+ if(GfxIsInsideScreenArea(x, y, w, h) == true)
+ {
+ int8_t orig_color = gb.display.getColor();
+
+ gb.display.setColor(color);
+ gb.display.fillRect(x, y, w, h);
+ gb.display.setColor(orig_color);
+ }
}
void GfxShowResources(TYPE_RESOURCES * ptrResources)
@@ -199,17 +214,17 @@ void GfxShowResources(TYPE_RESOURCES * ptrResources)
char str[8];
gb.display.setColor(GFX_WHITE);
- gb.display.fillRect(0, 0, X_SCREEN_RESOLUTION, 8);
+ gb.display.fillRect(0, 0, X_SCREEN_RESOLUTION, 5);
snprintf(str, 8, "W=%d", ptrResources->Wood);
- GfxPrintTextFont(str, font3x3, 4, 4);
+ GfxPrintTextFont(str, font3x3, 4, 1);
snprintf(str, 8, "G=%d", ptrResources->Gold);
- GfxPrintTextFont(str, font3x3, 24, 4);
+ GfxPrintTextFont(str, font3x3, 24, 1);
snprintf(str, 8, "F=%d", ptrResources->Food);
- GfxPrintTextFont(str, font3x3, 48, 4);
+ GfxPrintTextFont(str, font3x3, 48, 1);
}