summaryrefslogtreecommitdiff
path: root/kms++util/src
diff options
context:
space:
mode:
authorTomi Valkeinen <tomi.valkeinen@ti.com>2018-08-03 14:54:25 +0300
committerTomi Valkeinen <tomi.valkeinen@ti.com>2018-08-03 14:55:18 +0300
commited8343cb576fc04b9e24e413534d41e0c5d9f2d0 (patch)
treea3fa6a7f660cfdf31b682b9c775ef5baa7612d53 /kms++util/src
parent2cfc1d86771a0835abdef86a6f6fcd914506da86 (diff)
add a simple draw_circle()
Diffstat (limited to 'kms++util/src')
-rw-r--r--kms++util/src/drawing.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/kms++util/src/drawing.cpp b/kms++util/src/drawing.cpp
index 4e5c6c1..8885112 100644
--- a/kms++util/src/drawing.cpp
+++ b/kms++util/src/drawing.cpp
@@ -1,4 +1,6 @@
+#include <cmath>
+
#include <kms++/kms++.h>
#include <kms++util/kms++util.h>
@@ -198,6 +200,22 @@ void draw_rect(IFramebuffer &fb, uint32_t x, uint32_t y, uint32_t w, uint32_t h,
}
}
+void draw_horiz_line(IFramebuffer& fb, uint32_t x1, uint32_t x2, uint32_t y, RGB color)
+{
+ for (uint32_t x = x1; x <= x2; ++x)
+ draw_rgb_pixel(fb, x, y, color);
+}
+
+void draw_circle(IFramebuffer& fb, int32_t xCenter, int32_t yCenter, int32_t radius, RGB color)
+{
+ int32_t r2 = radius * radius;
+
+ for (int y = -radius; y <= radius; y++) {
+ int32_t x = (int)(sqrt(r2 - y * y) + 0.5);
+ draw_horiz_line(fb, xCenter - x, xCenter + x, yCenter - y, color);
+ }
+}
+
static bool get_char_pixel(char c, uint32_t x, uint32_t y)
{
#include "font_8x8.h"