summaryrefslogtreecommitdiff
path: root/shared-module/vectorio/VectorShape.h
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/VectorShape.h
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/VectorShape.h')
-rw-r--r--shared-module/vectorio/VectorShape.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/shared-module/vectorio/VectorShape.h b/shared-module/vectorio/VectorShape.h
new file mode 100644
index 000000000..ac60e5b98
--- /dev/null
+++ b/shared-module/vectorio/VectorShape.h
@@ -0,0 +1,51 @@
+
+#ifndef MICROPY_INCLUDED_SHARED_MODULE_VECTORIO_SHAPE_H
+#define MICROPY_INCLUDED_SHARED_MODULE_VECTORIO_SHAPE_H
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#include "py/obj.h"
+#include "shared-module/displayio/area.h"
+#include "shared-module/displayio/Palette.h"
+
+typedef void get_area_function(mp_obj_t shape, displayio_area_t *out_area);
+typedef uint32_t get_pixel_function(mp_obj_t shape, int16_t x, int16_t y);
+
+// This struct binds a shape's common Shape support functions (its vector shape interface)
+// to its instance pointer. We only check at construction time what the type of the
+// associated shape is and link the correct functions up.
+// Later when using the shape for drawing logic these functions may be invoked
+// unconditionally. This simplifies the addition of new types and restricts the
+// respective responsibilities of VectorShape and actual shape implementations.
+typedef struct {
+ mp_obj_t shape;
+ get_area_function *get_area;
+ get_pixel_function *get_pixel;
+} vectorio_ishape_t;
+
+typedef struct {
+ mp_obj_base_t base;
+ vectorio_ishape_t ishape;
+ mp_obj_t pixel_shader;
+ int16_t x;
+ int16_t y;
+ bool transpose_xy;
+ bool dirty; // True if we need to draw
+ // Tracks current shape footprint and expands outward as the shape dirties and changes.
+ // This is suboptimal if you move your shape far. Could add more state to only redraw
+ // exactly what we left behind.
+ displayio_area_t ephemeral_dirty_area;
+} vectorio_vector_shape_t;
+
+displayio_area_t* vectorio_vector_shape_get_refresh_areas(vectorio_vector_shape_t *self, displayio_area_t* tail);
+
+// Area is always in absolute screen coordinates.
+bool vectorio_vector_shape_fill_area(vectorio_vector_shape_t *self, const _displayio_colorspace_t *colorspace, const displayio_area_t *area, uint32_t *mask, uint32_t *buffer);
+
+// Fills in out_area with the maximum bounds of all related pixels in the last rendered frame. Returns
+// false if the vector shape wasn't rendered in the last frame.
+bool vectorio_vector_shape_get_previous_area(vectorio_vector_shape_t *self, displayio_area_t *out_area);
+void vectorio_vector_shape_finish_refresh(vectorio_vector_shape_t *self);
+
+#endif // MICROPY_INCLUDED_SHARED_MODULE_VECTORIO_SHAPE_H