Skip to content

Commit 866ff5b

Browse files
authored
Merge pull request #7197 from FoamyGuy/vectorio_hidden
implement self hidden property for vectorio shapes
2 parents 6689b9a + 5b64a62 commit 866ff5b

File tree

7 files changed

+59
-0
lines changed

7 files changed

+59
-0
lines changed

shared-bindings/vectorio/Circle.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ MP_PROPERTY_GETSET(vectorio_circle_color_index_obj,
109109
//| y: int
110110
//| """Y position of the center point of the circle in the parent."""
111111
//|
112+
//| hidden: bool
113+
//| """Hide the circle or not."""
114+
//|
112115
//| location: Tuple[int, int]
113116
//| """(X,Y) position of the center point of the circle in the parent."""
114117
//|
@@ -123,6 +126,7 @@ STATIC const mp_rom_map_elem_t vectorio_circle_locals_dict_table[] = {
123126
{ MP_ROM_QSTR(MP_QSTR_radius), MP_ROM_PTR(&vectorio_circle_radius_obj) },
124127
{ MP_ROM_QSTR(MP_QSTR_x), MP_ROM_PTR(&vectorio_vector_shape_x_obj) },
125128
{ MP_ROM_QSTR(MP_QSTR_y), MP_ROM_PTR(&vectorio_vector_shape_y_obj) },
129+
{ MP_ROM_QSTR(MP_QSTR_hidden), MP_ROM_PTR(&vectorio_vector_shape_hidden_obj) },
126130
{ MP_ROM_QSTR(MP_QSTR_color_index), MP_ROM_PTR(&vectorio_circle_color_index_obj) },
127131
{ MP_ROM_QSTR(MP_QSTR_location), MP_ROM_PTR(&vectorio_vector_shape_location_obj) },
128132
{ MP_ROM_QSTR(MP_QSTR_pixel_shader), MP_ROM_PTR(&vectorio_vector_shape_pixel_shader_obj) },

shared-bindings/vectorio/Polygon.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ MP_PROPERTY_GETSET(vectorio_polygon_color_index_obj,
118118
//| y: int
119119
//| """Y position of the 0,0 origin in the points list."""
120120
//|
121+
//| hidden: bool
122+
//| """Hide the polygon or not."""
123+
//|
121124
//| location: Tuple[int, int]
122125
//| """(X,Y) position of the 0,0 origin in the points list."""
123126
//|
@@ -132,6 +135,7 @@ STATIC const mp_rom_map_elem_t vectorio_polygon_locals_dict_table[] = {
132135
{ MP_ROM_QSTR(MP_QSTR_points), MP_ROM_PTR(&vectorio_polygon_points_obj) },
133136
{ MP_ROM_QSTR(MP_QSTR_x), MP_ROM_PTR(&vectorio_vector_shape_x_obj) },
134137
{ MP_ROM_QSTR(MP_QSTR_y), MP_ROM_PTR(&vectorio_vector_shape_y_obj) },
138+
{ MP_ROM_QSTR(MP_QSTR_hidden), MP_ROM_PTR(&vectorio_vector_shape_hidden_obj) },
135139
{ MP_ROM_QSTR(MP_QSTR_color_index), MP_ROM_PTR(&vectorio_polygon_color_index_obj) },
136140
{ MP_ROM_QSTR(MP_QSTR_location), MP_ROM_PTR(&vectorio_vector_shape_location_obj) },
137141
{ MP_ROM_QSTR(MP_QSTR_pixel_shader), MP_ROM_PTR(&vectorio_vector_shape_pixel_shader_obj) },

shared-bindings/vectorio/Rectangle.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ const mp_obj_property_t vectorio_rectangle_color_index_obj = {
139139
//| y: int
140140
//| """Y position of the top left corner of the rectangle in the parent."""
141141
//|
142+
//| hidden: bool
143+
//| """Hide the rectangle or not."""
144+
//|
142145
//| location: Tuple[int, int]
143146
//| """(X,Y) position of the top left corner of the rectangle in the parent."""
144147
//|
@@ -152,6 +155,7 @@ STATIC const mp_rom_map_elem_t vectorio_rectangle_locals_dict_table[] = {
152155
// Properties
153156
{ MP_ROM_QSTR(MP_QSTR_x), MP_ROM_PTR(&vectorio_vector_shape_x_obj) },
154157
{ MP_ROM_QSTR(MP_QSTR_y), MP_ROM_PTR(&vectorio_vector_shape_y_obj) },
158+
{ MP_ROM_QSTR(MP_QSTR_hidden), MP_ROM_PTR(&vectorio_vector_shape_hidden_obj) },
155159
{ MP_ROM_QSTR(MP_QSTR_color_index), MP_ROM_PTR(&vectorio_rectangle_color_index_obj) },
156160
{ MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&vectorio_rectangle_width_obj) },
157161
{ MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&vectorio_rectangle_height_obj) },

shared-bindings/vectorio/VectorShape.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,33 @@ MP_PROPERTY_GETSET(vectorio_vector_shape_location_obj,
181181
(mp_obj_t)&vectorio_vector_shape_set_location_obj);
182182

183183

184+
// Stub checker does not approve of these shared properties.
185+
// hidden: bool
186+
// """Hide the shape or not."""
187+
//
188+
STATIC mp_obj_t vectorio_vector_shape_obj_get_hidden(mp_obj_t wrapper_shape) {
189+
// Relies on the fact that only vector_shape impl gets matched with a VectorShape.
190+
const vectorio_draw_protocol_t *draw_protocol = mp_proto_get(MP_QSTR_protocol_draw, wrapper_shape);
191+
vectorio_vector_shape_t *self = MP_OBJ_TO_PTR(draw_protocol->draw_get_protocol_self(wrapper_shape));
192+
return mp_obj_new_bool(common_hal_vectorio_vector_shape_get_hidden(self));
193+
}
194+
MP_DEFINE_CONST_FUN_OBJ_1(vectorio_vector_shape_get_hidden_obj, vectorio_vector_shape_obj_get_hidden);
195+
196+
STATIC mp_obj_t vectorio_vector_shape_obj_set_hidden(mp_obj_t wrapper_shape, mp_obj_t hidden_obj) {
197+
// Relies on the fact that only vector_shape impl gets matched with a VectorShape.
198+
const vectorio_draw_protocol_t *draw_protocol = mp_proto_get(MP_QSTR_protocol_draw, wrapper_shape);
199+
vectorio_vector_shape_t *self = MP_OBJ_TO_PTR(draw_protocol->draw_get_protocol_self(wrapper_shape));
200+
201+
common_hal_vectorio_vector_shape_set_hidden(self, mp_obj_is_true(hidden_obj));
202+
return mp_const_none;
203+
}
204+
MP_DEFINE_CONST_FUN_OBJ_2(vectorio_vector_shape_set_hidden_obj, vectorio_vector_shape_obj_set_hidden);
205+
206+
MP_PROPERTY_GETSET(vectorio_vector_shape_hidden_obj,
207+
(mp_obj_t)&vectorio_vector_shape_get_hidden_obj,
208+
(mp_obj_t)&vectorio_vector_shape_set_hidden_obj);
209+
210+
184211
// pixel_shader: Union[ColorConverter, Palette]
185212
// """The pixel shader of the shape."""
186213
//

shared-bindings/vectorio/VectorShape.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ void common_hal_vectorio_vector_shape_set_location(vectorio_vector_shape_t *self
3131
mp_int_t common_hal_vectorio_vector_shape_get_y(vectorio_vector_shape_t *self);
3232
void common_hal_vectorio_vector_shape_set_y(vectorio_vector_shape_t *self, mp_int_t y);
3333

34+
mp_int_t common_hal_vectorio_vector_shape_get_hidden(vectorio_vector_shape_t *self);
35+
void common_hal_vectorio_vector_shape_set_hidden(vectorio_vector_shape_t *self, bool hidden);
36+
3437
mp_obj_t common_hal_vectorio_vector_shape_get_pixel_shader(vectorio_vector_shape_t *self);
3538
void common_hal_vectorio_vector_shape_set_pixel_shader(vectorio_vector_shape_t *self, mp_obj_t pixel_shader);
3639

@@ -40,6 +43,7 @@ void vectorio_vector_shape_update_transform(vectorio_vector_shape_t *self, displ
4043
extern vectorio_draw_protocol_impl_t vectorio_vector_shape_draw_protocol_impl;
4144
extern const mp_obj_property_getset_t vectorio_vector_shape_x_obj;
4245
extern const mp_obj_property_getset_t vectorio_vector_shape_y_obj;
46+
extern const mp_obj_property_getset_t vectorio_vector_shape_hidden_obj;
4347
extern const mp_obj_property_getset_t vectorio_vector_shape_location_obj;
4448
extern const mp_obj_property_getset_t vectorio_vector_shape_pixel_shader_obj;
4549
extern const mp_obj_fun_builtin_fixed_t vectorio_vector_shape_contains_obj;

shared-module/vectorio/VectorShape.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,16 @@ void common_hal_vectorio_vector_shape_set_location(vectorio_vector_shape_t *self
293293
}
294294
}
295295

296+
mp_int_t common_hal_vectorio_vector_shape_get_hidden(vectorio_vector_shape_t *self) {
297+
VECTORIO_SHAPE_DEBUG("%p get_hidden\n", self);
298+
return self->hidden;
299+
}
300+
301+
void common_hal_vectorio_vector_shape_set_hidden(vectorio_vector_shape_t *self, bool hidden) {
302+
VECTORIO_SHAPE_DEBUG("%p set_hidden %d\n", self, x);
303+
self->hidden = hidden;
304+
common_hal_vectorio_vector_shape_set_dirty(self);
305+
}
296306

297307
mp_obj_t common_hal_vectorio_vector_shape_get_pixel_shader(vectorio_vector_shape_t *self) {
298308
VECTORIO_SHAPE_DEBUG("%p get_pixel_shader\n", self);
@@ -315,6 +325,11 @@ bool vectorio_vector_shape_fill_area(vectorio_vector_shape_t *self, const _displ
315325
uint64_t start = common_hal_time_monotonic_ns();
316326
uint64_t pixel_time = 0;
317327
#endif
328+
329+
if (self->hidden) {
330+
return false;
331+
}
332+
318333
VECTORIO_SHAPE_DEBUG("%p fill_area: fill: {(%5d,%5d), (%5d,%5d)}",
319334
self,
320335
area->x1, area->y1, area->x2, area->y2

shared-module/vectorio/VectorShape.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ typedef struct {
3737
displayio_area_t ephemeral_dirty_area;
3838
displayio_area_t current_area;
3939
bool current_area_dirty;
40+
bool hidden;
4041
} vectorio_vector_shape_t;
4142

4243
displayio_area_t *vectorio_vector_shape_get_refresh_areas(vectorio_vector_shape_t *self, displayio_area_t *tail);

0 commit comments

Comments
 (0)