Skip to content

Commit 4086600

Browse files
committed
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.
1 parent 1c6e646 commit 4086600

File tree

5 files changed

+38
-34
lines changed

5 files changed

+38
-34
lines changed

shared-bindings/vectorio/VectorShape.c

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,12 @@
3232
//| :param int y: Initial y position of the center axis of the shape within the parent.
3333
//|
3434
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) {
35-
enum { ARG_shape, ARG_pixel_shader, ARG_x, ARG_y, ARG_transpose_xy };
35+
enum { ARG_shape, ARG_pixel_shader, ARG_x, ARG_y };
3636
static const mp_arg_t allowed_args[] = {
3737
{ MP_QSTR_shape, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
3838
{ MP_QSTR_pixel_shader, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
3939
{ MP_QSTR_x, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} },
4040
{ MP_QSTR_y, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} },
41-
{ MP_QSTR_transpose_xy, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} },
4241
};
4342
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
4443
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
7473
vectorio_vector_shape_t *self = m_new_obj(vectorio_vector_shape_t);
7574
self->base.type = &vectorio_vector_shape_type;
7675
common_hal_vectorio_vector_shape_construct(self,
77-
ishape, pixel_shader, x, y, args[ARG_transpose_xy].u_bool
76+
ishape, pixel_shader, x, y
7877
);
7978

8079
// Wire up event callbacks
@@ -150,23 +149,6 @@ const mp_obj_property_t vectorio_vector_shape_y_obj = {
150149
};
151150

152151

153-
//| .. attribute:: transpose_xy
154-
//|
155-
//| true if the object is to be flipped.
156-
//|
157-
STATIC mp_obj_t vectorio_vector_shape_obj_get_transpose_xy(mp_obj_t self_in) {
158-
vectorio_vector_shape_t *self = MP_OBJ_TO_PTR(self_in);
159-
return mp_obj_new_bool(common_hal_vectorio_vector_shape_get_transpose_xy(self));
160-
}
161-
MP_DEFINE_CONST_FUN_OBJ_1(vectorio_vector_shape_get_transpose_xy_obj, vectorio_vector_shape_obj_get_transpose_xy);
162-
163-
const mp_obj_property_t vectorio_vector_shape_transpose_xy_obj = {
164-
.base.type = &mp_type_property,
165-
.proxy = {(mp_obj_t)&vectorio_vector_shape_get_transpose_xy_obj,
166-
(mp_obj_t)&mp_const_none_obj,
167-
(mp_obj_t)&mp_const_none_obj},
168-
};
169-
170152
//| .. attribute:: pixel_shader
171153
//|
172154
//| The pixel shader of the shape.

shared-bindings/vectorio/VectorShape.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
#define MICROPY_INCLUDED_SHARED_BINDINGS_VECTORIO_SHAPE_H
33

44
#include "shared-module/vectorio/VectorShape.h"
5+
#include "shared-module/displayio/area.h"
56

67
extern const mp_obj_type_t vectorio_vector_shape_type;
78

89
void common_hal_vectorio_vector_shape_construct(vectorio_vector_shape_t *self,
910
vectorio_ishape_t ishape,
10-
mp_obj_t pixel_shader, uint16_t x, uint16_t y, bool transpose_xy);
11+
mp_obj_t pixel_shader, uint16_t x, uint16_t y);
1112

1213
void common_hal_vectorio_vector_shape_set_dirty(void *self);
1314

@@ -17,9 +18,10 @@ void common_hal_vectorio_vector_shape_set_x(vectorio_vector_shape_t *self, mp_in
1718
mp_int_t common_hal_vectorio_vector_shape_get_y(vectorio_vector_shape_t *self);
1819
void common_hal_vectorio_vector_shape_set_y(vectorio_vector_shape_t *self, mp_int_t y);
1920

20-
bool common_hal_vectorio_vector_shape_get_transpose_xy(vectorio_vector_shape_t *self);
21-
2221
mp_obj_t common_hal_vectorio_vector_shape_get_pixel_shader(vectorio_vector_shape_t *self);
2322
void common_hal_vectorio_vector_shape_set_pixel_shader(vectorio_vector_shape_t *self, mp_obj_t pixel_shader);
2423

24+
25+
void vectorio_vector_shape_update_transform(vectorio_vector_shape_t *self, displayio_buffer_transform_t *group_transform);
26+
2527
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_VECTORIO_SHAPE_H

shared-module/displayio/Group.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ static void _update_child_transforms(displayio_group_t* self) {
122122
}
123123
for (size_t i = 0; i < self->size; i++) {
124124
mp_obj_t layer = self->children[i].native;
125+
#if CIRCUITPY_VECTORIO
126+
if (MP_OBJ_IS_TYPE(layer, &vectorio_vector_shape_type)) {
127+
vectorio_vector_shape_update_transform(layer, &self->absolute_transform);
128+
}
129+
else
130+
#endif
125131
if (MP_OBJ_IS_TYPE(layer, &displayio_tilegrid_type)) {
126132
displayio_tilegrid_update_transform(layer, &self->absolute_transform);
127133
} else if (MP_OBJ_IS_TYPE(layer, &displayio_group_type)) {

shared-module/vectorio/VectorShape.c

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ inline __attribute__((always_inline))
5050
static void _get_screen_area(vectorio_vector_shape_t *self, displayio_area_t *out_area) {
5151
VECTORIO_SHAPE_DEBUG("%p get_screen_area\n", self);
5252
self->ishape.get_area(self->ishape.shape, out_area);
53-
if (self->transpose_xy) {
53+
if (self->absolute_transform->transpose_xy) {
5454
_transpose_area(out_area);
5555
displayio_area_shift(out_area, self->y, self->x);
5656
} else {
@@ -76,18 +76,32 @@ void common_hal_vectorio_vector_shape_set_dirty(void *vector_shape) {
7676
}
7777

7878

79+
static displayio_buffer_transform_t null_transform = {
80+
.x = 0,
81+
.y = 0,
82+
.dx = 0,
83+
.dy = 0,
84+
.scale = 1,
85+
.width = 0,
86+
.height = 0,
87+
.mirror_x = false,
88+
.mirror_y = false,
89+
.transpose_xy = false
90+
};
91+
92+
7993
void common_hal_vectorio_vector_shape_construct(vectorio_vector_shape_t *self,
8094
vectorio_ishape_t ishape,
81-
mp_obj_t pixel_shader, uint16_t x, uint16_t y, bool transpose_xy) {
95+
mp_obj_t pixel_shader, uint16_t x, uint16_t y) {
8296
VECTORIO_SHAPE_DEBUG("%p vector_shape_construct x:%3d, y:%3d\n", self, x, y);
8397
self->x = x;
8498
self->y = y;
8599
self->pixel_shader = pixel_shader;
86100
self->ishape = ishape;
87-
self->transpose_xy = transpose_xy;
88101
self->dirty = true;
89102
_get_screen_area(self, &self->ephemeral_dirty_area);
90103
self->ephemeral_dirty_area.next = NULL;
104+
self->absolute_transform = &null_transform;
91105
}
92106

93107

@@ -123,12 +137,6 @@ void common_hal_vectorio_vector_shape_set_y(vectorio_vector_shape_t *self, mp_in
123137
}
124138

125139

126-
bool common_hal_vectorio_vector_shape_get_transpose_xy(vectorio_vector_shape_t *self) {
127-
VECTORIO_SHAPE_DEBUG("%p get_transpose_xy\n", self);
128-
return self->transpose_xy;
129-
}
130-
131-
132140
mp_obj_t common_hal_vectorio_vector_shape_get_pixel_shader(vectorio_vector_shape_t *self) {
133141
VECTORIO_SHAPE_DEBUG("%p get_pixel_shader\n", self);
134142
return self->pixel_shader;
@@ -191,7 +199,7 @@ bool vectorio_vector_shape_fill_area(vectorio_vector_shape_t *self, const _displ
191199
// Get the target pixel based on the shape's coordinate space
192200
int16_t pixel_to_get_x;
193201
int16_t pixel_to_get_y;
194-
if (self->transpose_xy) {
202+
if (self->absolute_transform->transpose_xy) {
195203
pixel_to_get_x = input_pixel.y - self->x;
196204
pixel_to_get_y = input_pixel.x - self->y;
197205
} else {
@@ -280,3 +288,9 @@ displayio_area_t* vectorio_vector_shape_get_refresh_areas(vectorio_vector_shape_
280288
return tail;
281289
}
282290

291+
void vectorio_vector_shape_update_transform(vectorio_vector_shape_t *self, displayio_buffer_transform_t *group_transform) {
292+
self->absolute_transform = group_transform;
293+
common_hal_vectorio_vector_shape_set_dirty(self);
294+
}
295+
296+

shared-module/vectorio/VectorShape.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ typedef struct {
3030
mp_obj_t pixel_shader;
3131
int16_t x;
3232
int16_t y;
33-
bool transpose_xy;
33+
displayio_buffer_transform_t *absolute_transform;
3434
bool dirty; // True if we need to draw
3535
// Tracks current shape footprint and expands outward as the shape dirties and changes.
3636
// This is suboptimal if you move your shape far. Could add more state to only redraw

0 commit comments

Comments
 (0)