summaryrefslogtreecommitdiff
path: root/shared-module/vectorio/Rectangle.c
diff options
context:
space:
mode:
authorwarriorofwire <3454741+WarriorOfWire@users.noreply.github.com>2020-05-02 02:21:35 -0700
committerwarriorofwire <3454741+WarriorOfWire@users.noreply.github.com>2020-05-09 15:38:22 -0700
commit206d0e598adb66e2b23a39a7d11e2f5087513205 (patch)
treecea5a2e50ec96edd8b4c0bfc09e0d9570694a2ee /shared-module/vectorio/Rectangle.c
parent90bd931808fa797938b723e8d30889ec4a0f1654 (diff)
Add vectorio: for drawing shapes
vectorio builds on m4 express feather Concrete shapes are composed into a VectorShape which is put into a displayio Group for display. VectorShape provides transpose and x/y positioning for shape implementations. Included Shapes: * Circle - A radius; Circle is positioned at its axis in the VectorShape. - You can freely modify the radius to grow and shrink the circle in-place. * Polygon - An ordered list of points. - Beteween each successive point an edge is inferred. A final edge closing the shape is inferred between the last point and the first point. - You can modify the points in a Polygon. The points' coordinate system is relative to (0, 0) so if you'd like a top-center justified 10x20 rectangle you can do points [(-5, 0), (5, 0), (5, 20), (0, 20)] and your VectorShape x and y properties will position the rectangle relative to its top center point * Rectangle A width and a height.
Diffstat (limited to 'shared-module/vectorio/Rectangle.c')
-rw-r--r--shared-module/vectorio/Rectangle.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/shared-module/vectorio/Rectangle.c b/shared-module/vectorio/Rectangle.c
new file mode 100644
index 000000000..dfad58a4d
--- /dev/null
+++ b/shared-module/vectorio/Rectangle.c
@@ -0,0 +1,35 @@
+#include "shared-bindings/vectorio/Rectangle.h"
+#include "shared-module/displayio/area.h"
+
+#include "py/runtime.h"
+
+
+void common_hal_vectorio_rectangle_construct(vectorio_rectangle_t *self, uint32_t width, uint32_t height) {
+ self->width = width;
+ self->height = height;
+}
+
+
+uint32_t common_hal_vectorio_rectangle_get_pixel(void *obj, int16_t x, int16_t y) {
+ vectorio_rectangle_t *self = obj;
+ if (x < 0 || x >= self->width || y >= self->height || y < 0) {
+ return 0;
+ }
+ return 1;
+}
+
+
+void common_hal_vectorio_rectangle_get_area(void *rectangle, displayio_area_t *out_area) {
+ vectorio_rectangle_t *self = rectangle;
+ out_area->x1 = 0;
+ out_area->y1 = 0;
+ out_area->x2 = self->width;
+ out_area->y2 = self->height;
+}
+
+
+uint32_t common_hal_vectorio_rectangle_get_height(void *rectangle) {
+ vectorio_rectangle_t *self = rectangle;
+ return self->height;
+}
+