summaryrefslogtreecommitdiff
path: root/plugingui
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2016-09-05 11:45:29 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2016-09-05 11:45:29 +0200
commitea4435f8ca32639ad2c516cd89123b8e88b666bc (patch)
treef19b830f55124a80c6ec259b123f25ba96f99adb /plugingui
parent257a769685d380e7a6fc5f154e03f5e127de4e39 (diff)
Added painter unit test and fixed image and text rendering boundaries.
Diffstat (limited to 'plugingui')
-rw-r--r--plugingui/painter.cc42
1 files changed, 38 insertions, 4 deletions
diff --git a/plugingui/painter.cc b/plugingui/painter.cc
index db67a0e..3c290f3 100644
--- a/plugingui/painter.cc
+++ b/plugingui/painter.cc
@@ -27,6 +27,7 @@
#include "painter.h"
#include <cmath>
+#include <cassert>
namespace GUI
{
@@ -203,24 +204,48 @@ void Painter::drawText(int x0, int y0, const Font& font,
if(nocolour)
{
- for(int y = 0; y < renderHeight; ++y)
+ for(int y = -1 * std::min(0, y0); y < renderHeight; ++y)
{
- for(int x = 0; x < renderWidth; ++x)
+ for(int x = -1 * std::min(0, x0); x < renderWidth; ++x)
{
unsigned char r, g, b, a;
+
+ assert(x >= 0);
+ assert(y >= 0);
+ assert(x < (int)textbuf->width);
+ assert(y < (int)textbuf->height);
+
textbuf->pixel(x, y, &r, &g, &b, &a);
+
+ assert(x + x0 >= 0);
+ assert(y + y0 >= 0);
+ assert(x + x0 < (int)pixbuf.width);
+ assert(y + y0 < (int)pixbuf.height);
+
pixbuf.addPixel(x + x0, y + y0, r, g, b, a);
}
}
}
else
{
- for(int y = 0; y < renderHeight; ++y)
+ for(int y = -1 * std::min(0, y0); y < renderHeight; ++y)
{
- for(int x = 0; x < renderWidth; ++x)
+ for(int x = -1 * std::min(0, x0); x < renderWidth; ++x)
{
unsigned char r,g,b,a;
+
+ assert(x >= 0);
+ assert(y >= 0);
+ assert(x < (int)textbuf->width);
+ assert(y < (int)textbuf->height);
+
textbuf->pixel(x, y, &r, &g, &b, &a);
+
+ assert(x + x0 >= 0);
+ assert(y + y0 >= 0);
+ assert(x + x0 < (int)pixbuf.width);
+ assert(y + y0 < (int)pixbuf.height);
+
pixbuf.addPixel(x + x0, y + y0,
colour.red() * 255,
colour.green() * 255,
@@ -361,7 +386,16 @@ void Painter::drawImage(int x0, int y0, const Drawable& image)
{
for(std::size_t x = -1 * std::min(0, x0); x < (std::size_t)fw; ++x)
{
+ assert(x >= 0);
+ assert(y >= 0);
+ assert(x < image.width());
+ assert(y < image.height());
auto& c = image.getPixel(x, y);
+
+ assert(x0 + x >= 0);
+ assert(y0 + y >= 0);
+ assert(x0 + x < pixbuf.width);
+ assert(y0 + y < pixbuf.height);
pixbuf.addPixel(x0 + x, y0 + y, c);
}
}