summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwarriorofwire <3454741+WarriorOfWire@users.noreply.github.com>2020-05-08 23:03:15 -0700
committerwarriorofwire <3454741+WarriorOfWire@users.noreply.github.com>2020-05-09 22:15:51 -0700
commit4086600b61f14e043f02c1b8771e7780b82f313c (patch)
tree43845cc9eb946670ec88302d097dfccfe639995c
parent1c6e646f5630a46ea77e848788947c099e2c1f31 (diff)
vectorio: switch per-shape transform to Display
Rather than maintain a transform per-shape, we'll just use whatever settings are on the Display. Currently only transpose is done.
-rw-r--r--shared-bindings/vectorio/VectorShape.c22
-rw-r--r--shared-bindings/vectorio/VectorShape.h8
-rw-r--r--shared-module/displayio/Group.c6
-rw-r--r--shared-module/vectorio/VectorShape.c34
-rw-r--r--shared-module/vectorio/VectorShape.h2
5 files changed, 38 insertions, 34 deletions
diff --git a/shared-bindings/vectorio/VectorShape.c b/shared-bindings/vectorio/VectorShape.c
index 8f99577b4..02a42536d 100644
--- a/shared-bindings/vectorio/VectorShape.c
+++ b/shared-bindings/vectorio/VectorShape.c
@@ -32,13 +32,12 @@
//| :param int y: Initial y position of the center axis of the shape within the parent.
//|
STATIC mp_obj_t vectorio_vector_shape_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
- enum { ARG_shape, ARG_pixel_shader, ARG_x, ARG_y, ARG_transpose_xy };
+ enum { ARG_shape, ARG_pixel_shader, ARG_x, ARG_y };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_shape, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
{ MP_QSTR_pixel_shader, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
{ MP_QSTR_x, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} },
{ MP_QSTR_y, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} },
- { MP_QSTR_transpose_xy, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
};
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
@@ -74,7 +73,7 @@ STATIC mp_obj_t vectorio_vector_shape_make_new(const mp_obj_type_t *type, size_t
vectorio_vector_shape_t *self = m_new_obj(vectorio_vector_shape_t);
self->base.type = &vectorio_vector_shape_type;
common_hal_vectorio_vector_shape_construct(self,
- ishape, pixel_shader, x, y, args[ARG_transpose_xy].u_bool
+ ishape, pixel_shader, x, y
);
// Wire up event callbacks
@@ -150,23 +149,6 @@ const mp_obj_property_t vectorio_vector_shape_y_obj = {
};
-//| .. attribute:: transpose_xy
-//|
-//| true if the object is to be flipped.
-//|
-STATIC mp_obj_t vectorio_vector_shape_obj_get_transpose_xy(mp_obj_t self_in) {
- vectorio_vector_shape_t *self = MP_OBJ_TO_PTR(self_in);
- return mp_obj_new_bool(common_hal_vectorio_vector_shape_get_transpose_xy(self));
-}
-MP_DEFINE_CONST_FUN_OBJ_1(vectorio_vector_shape_get_transpose_xy_obj, vectorio_vector_shape_obj_get_transpose_xy);
-
-const mp_obj_property_t vectorio_vector_shape_transpose_xy_obj = {
- .base.type = &mp_type_property,
- .proxy = {(mp_obj_t)&vectorio_vector_shape_get_transpose_xy_obj,
- (mp_obj_t)&mp_const_none_obj,
- (mp_obj_t)&mp_const_none_obj},
-};
-
//| .. attribute:: pixel_shader
//|
//| The pixel shader of the shape.
diff --git a/shared-bindings/vectorio/VectorShape.h b/shared-bindings/vectorio/VectorShape.h
index ad745b30f..d098504e9 100644
--- a/shared-bindings/vectorio/VectorShape.h
+++ b/shared-bindings/vectorio/VectorShape.h
@@ -2,12 +2,13 @@
#define MICROPY_INCLUDED_SHARED_BINDINGS_VECTORIO_SHAPE_H
#include "shared-module/vectorio/VectorShape.h"
+#include "shared-module/displayio/area.h"
extern const mp_obj_type_t vectorio_vector_shape_type;
void common_hal_vectorio_vector_shape_construct(vectorio_vector_shape_t *self,
vectorio_ishape_t ishape,
- mp_obj_t pixel_shader, uint16_t x, uint16_t y, bool transpose_xy);
+ mp_obj_t pixel_shader, uint16_t x, uint16_t y);
void common_hal_vectorio_vector_shape_set_dirty(void *self);
@@ -17,9 +18,10 @@ void common_hal_vectorio_vector_shape_set_x(vectorio_vector_shape_t *self, mp_in
mp_int_t common_hal_vectorio_vector_shape_get_y(vectorio_vector_shape_t *self);
void common_hal_vectorio_vector_shape_set_y(vectorio_vector_shape_t *self, mp_int_t y);
-bool common_hal_vectorio_vector_shape_get_transpose_xy(vectorio_vector_shape_t *self);
-
mp_obj_t common_hal_vectorio_vector_shape_get_pixel_shader(vectorio_vector_shape_t *self);
void common_hal_vectorio_vector_shape_set_pixel_shader(vectorio_vector_shape_t *self, mp_obj_t pixel_shader);
+
+void vectorio_vector_shape_update_transform(vectorio_vector_shape_t *self, displayio_buffer_transform_t *group_transform);
+
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_VECTORIO_SHAPE_H
diff --git a/shared-module/displayio/Group.c b/shared-module/displayio/Group.c
index 9d50dabec..0c31de532 100644
--- a/shared-module/displayio/Group.c
+++ b/shared-module/displayio/Group.c
@@ -122,6 +122,12 @@ static void _update_child_transforms(displayio_group_t* self) {
}
for (size_t i = 0; i < self->size; i++) {
mp_obj_t layer = self->children[i].native;
+#if CIRCUITPY_VECTORIO
+ if (MP_OBJ_IS_TYPE(layer, &vectorio_vector_shape_type)) {
+ vectorio_vector_shape_update_transform(layer, &self->absolute_transform);
+ }
+ else
+#endif
if (MP_OBJ_IS_TYPE(layer, &displayio_tilegrid_type)) {
displayio_tilegrid_update_transform(layer, &self->absolute_transform);
} else if (MP_OBJ_IS_TYPE(layer, &displayio_group_type)) {
diff --git a/shared-module/vectorio/VectorShape.c b/shared-module/vectorio/VectorShape.c
index 985b77858..6030c1e3d 100644
--- a/shared-module/vectorio/VectorShape.c
+++ b/shared-module/vectorio/VectorShape.c
@@ -50,7 +50,7 @@ inline __attribute__((always_inline))
static void _get_screen_area(vectorio_vector_shape_t *self, displayio_area_t *out_area) {
VECTORIO_SHAPE_DEBUG("%p get_screen_area\n", self);
self->ishape.get_area(self->ishape.shape, out_area);
- if (self->transpose_xy) {
+ if (self->absolute_transform->transpose_xy) {
_transpose_area(out_area);
displayio_area_shift(out_area, self->y, self->x);
} else {
@@ -76,18 +76,32 @@ void common_hal_vectorio_vector_shape_set_dirty(void *vector_shape) {
}
+static displayio_buffer_transform_t null_transform = {
+ .x = 0,
+ .y = 0,
+ .dx = 0,
+ .dy = 0,
+ .scale = 1,
+ .width = 0,
+ .height = 0,
+ .mirror_x = false,
+ .mirror_y = false,
+ .transpose_xy = false
+};
+
+
void common_hal_vectorio_vector_shape_construct(vectorio_vector_shape_t *self,
vectorio_ishape_t ishape,
- mp_obj_t pixel_shader, uint16_t x, uint16_t y, bool transpose_xy) {
+ mp_obj_t pixel_shader, uint16_t x, uint16_t y) {
VECTORIO_SHAPE_DEBUG("%p vector_shape_construct x:%3d, y:%3d\n", self, x, y);
self->x = x;
self->y = y;
self->pixel_shader = pixel_shader;
self->ishape = ishape;
- self->transpose_xy = transpose_xy;
self->dirty = true;
_get_screen_area(self, &self->ephemeral_dirty_area);
self->ephemeral_dirty_area.next = NULL;
+ self->absolute_transform = &null_transform;
}
@@ -123,12 +137,6 @@ void common_hal_vectorio_vector_shape_set_y(vectorio_vector_shape_t *self, mp_in
}
-bool common_hal_vectorio_vector_shape_get_transpose_xy(vectorio_vector_shape_t *self) {
- VECTORIO_SHAPE_DEBUG("%p get_transpose_xy\n", self);
- return self->transpose_xy;
-}
-
-
mp_obj_t common_hal_vectorio_vector_shape_get_pixel_shader(vectorio_vector_shape_t *self) {
VECTORIO_SHAPE_DEBUG("%p get_pixel_shader\n", self);
return self->pixel_shader;
@@ -191,7 +199,7 @@ bool vectorio_vector_shape_fill_area(vectorio_vector_shape_t *self, const _displ
// Get the target pixel based on the shape's coordinate space
int16_t pixel_to_get_x;
int16_t pixel_to_get_y;
- if (self->transpose_xy) {
+ if (self->absolute_transform->transpose_xy) {
pixel_to_get_x = input_pixel.y - self->x;
pixel_to_get_y = input_pixel.x - self->y;
} else {
@@ -280,3 +288,9 @@ displayio_area_t* vectorio_vector_shape_get_refresh_areas(vectorio_vector_shape_
return tail;
}
+void vectorio_vector_shape_update_transform(vectorio_vector_shape_t *self, displayio_buffer_transform_t *group_transform) {
+ self->absolute_transform = group_transform;
+ common_hal_vectorio_vector_shape_set_dirty(self);
+}
+
+
diff --git a/shared-module/vectorio/VectorShape.h b/shared-module/vectorio/VectorShape.h
index ac60e5b98..8fc698dbc 100644
--- a/shared-module/vectorio/VectorShape.h
+++ b/shared-module/vectorio/VectorShape.h
@@ -30,7 +30,7 @@ typedef struct {
mp_obj_t pixel_shader;
int16_t x;
int16_t y;
- bool transpose_xy;
+ displayio_buffer_transform_t *absolute_transform;
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