Skip to content

Commit a1fff32

Browse files
committed
add location property to vectorshape and all composed shapes
1 parent bb25aee commit a1fff32

File tree

7 files changed

+86
-18
lines changed

7 files changed

+86
-18
lines changed

locale/circuitpython.pot

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,10 @@ msgstr ""
318318
msgid "'yield' outside function"
319319
msgstr ""
320320

321+
#: shared-module/vectorio/VectorShape.c
322+
msgid "(x,y) integers required"
323+
msgstr ""
324+
321325
#: py/compile.c
322326
msgid "*x must be assignment target"
323327
msgstr ""
@@ -1185,11 +1189,6 @@ msgstr ""
11851189
msgid "Input/output error"
11861190
msgstr ""
11871191

1188-
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
1189-
#, c-format
1190-
msgid "Missing jmp_pin. Instruction %d jumps on pin"
1191-
msgstr ""
1192-
11931192
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
11941193
#, c-format
11951194
msgid "Instruction %d shifts in more bits than pin count"
@@ -1506,6 +1505,11 @@ msgstr ""
15061505
msgid "Missing first_set_pin. Instruction %d sets pin(s)"
15071506
msgstr ""
15081507

1508+
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
1509+
#, c-format
1510+
msgid "Missing jmp_pin. Instruction %d jumps on pin"
1511+
msgstr ""
1512+
15091513
#: shared-bindings/busio/UART.c shared-bindings/displayio/Group.c
15101514
msgid "Must be a %q subclass."
15111515
msgstr ""
@@ -2063,7 +2067,6 @@ msgid "Size not supported"
20632067
msgstr ""
20642068

20652069
#: ports/raspberrypi/common-hal/alarm/SleepMemory.c
2066-
#: ports/stm/common-hal/alarm/SleepMemory.c
20672070
msgid "Sleep Memory not available"
20682071
msgstr ""
20692072

@@ -2510,7 +2513,7 @@ msgid "argument name reused"
25102513
msgstr ""
25112514

25122515
#: py/argcheck.c shared-bindings/_stage/__init__.c
2513-
#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c
2516+
#: shared-bindings/digitalio/DigitalInOut.c
25142517
msgid "argument num/types mismatch"
25152518
msgstr ""
25162519

@@ -3594,10 +3597,6 @@ msgstr ""
35943597
msgid "no active exception to reraise"
35953598
msgstr ""
35963599

3597-
#: shared-bindings/socket/__init__.c shared-module/network/__init__.c
3598-
msgid "no available NIC"
3599-
msgstr ""
3600-
36013600
#: py/compile.c
36023601
msgid "no binding for nonlocal found"
36033602
msgstr ""
@@ -4299,7 +4298,7 @@ msgid "unreadable attribute"
42994298
msgstr ""
43004299

43014300
#: shared-bindings/displayio/TileGrid.c shared-bindings/vectorio/VectorShape.c
4302-
#: shared-module/vectorio/Polygon.c
4301+
#: shared-module/vectorio/Polygon.c shared-module/vectorio/VectorShape.c
43034302
msgid "unsupported %q type"
43044303
msgstr ""
43054304

shared-bindings/vectorio/Circle.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ STATIC const mp_rom_map_elem_t vectorio_circle_locals_dict_table[] = {
8686
{ MP_ROM_QSTR(MP_QSTR_radius), MP_ROM_PTR(&vectorio_circle_radius_obj) },
8787
{ MP_ROM_QSTR(MP_QSTR_x), MP_ROM_PTR(&vectorio_vector_shape_x_obj) },
8888
{ MP_ROM_QSTR(MP_QSTR_y), MP_ROM_PTR(&vectorio_vector_shape_y_obj) },
89+
{ MP_ROM_QSTR(MP_QSTR_location), MP_ROM_PTR(&vectorio_vector_shape_location_obj) },
8990
{ MP_ROM_QSTR(MP_QSTR_pixel_shader), MP_ROM_PTR(&vectorio_vector_shape_pixel_shader_obj) },
9091
};
9192
STATIC MP_DEFINE_CONST_DICT(vectorio_circle_locals_dict, vectorio_circle_locals_dict_table);

shared-bindings/vectorio/Polygon.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ STATIC const mp_rom_map_elem_t vectorio_polygon_locals_dict_table[] = {
9191
{ MP_ROM_QSTR(MP_QSTR_points), MP_ROM_PTR(&vectorio_polygon_points_obj) },
9292
{ MP_ROM_QSTR(MP_QSTR_x), MP_ROM_PTR(&vectorio_vector_shape_x_obj) },
9393
{ MP_ROM_QSTR(MP_QSTR_y), MP_ROM_PTR(&vectorio_vector_shape_y_obj) },
94+
{ MP_ROM_QSTR(MP_QSTR_location), MP_ROM_PTR(&vectorio_vector_shape_location_obj) },
9495
{ MP_ROM_QSTR(MP_QSTR_pixel_shader), MP_ROM_PTR(&vectorio_vector_shape_pixel_shader_obj) },
9596
};
9697
STATIC MP_DEFINE_CONST_DICT(vectorio_polygon_locals_dict, vectorio_polygon_locals_dict_table);

shared-bindings/vectorio/Rectangle.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ STATIC const mp_rom_map_elem_t vectorio_rectangle_locals_dict_table[] = {
6464
// Properties
6565
{ MP_ROM_QSTR(MP_QSTR_x), MP_ROM_PTR(&vectorio_vector_shape_x_obj) },
6666
{ MP_ROM_QSTR(MP_QSTR_y), MP_ROM_PTR(&vectorio_vector_shape_y_obj) },
67+
{ MP_ROM_QSTR(MP_QSTR_location), MP_ROM_PTR(&vectorio_vector_shape_location_obj) },
6768
{ MP_ROM_QSTR(MP_QSTR_pixel_shader), MP_ROM_PTR(&vectorio_vector_shape_pixel_shader_obj) },
6869
};
6970
STATIC MP_DEFINE_CONST_DICT(vectorio_rectangle_locals_dict, vectorio_rectangle_locals_dict_table);

shared-bindings/vectorio/VectorShape.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,36 @@ const mp_obj_property_t vectorio_vector_shape_y_obj = {
143143
};
144144

145145

146+
// location: Tuple[int, int]
147+
// """location of the center point of the shape in the parent."""
148+
//
149+
STATIC mp_obj_t vectorio_vector_shape_obj_get_location(mp_obj_t wrapper_shape) {
150+
// Relies on the fact that only vector_shape impl gets matched with a VectorShape.
151+
const vectorio_draw_protocol_t *draw_protocol = mp_proto_get(MP_QSTR_protocol_draw, wrapper_shape);
152+
vectorio_vector_shape_t *self = MP_OBJ_TO_PTR(draw_protocol->draw_get_protocol_self(wrapper_shape));
153+
154+
return MP_OBJ_TO_PTR(common_hal_vectorio_vector_shape_get_location(self));
155+
}
156+
MP_DEFINE_CONST_FUN_OBJ_1(vectorio_vector_shape_get_location_obj, vectorio_vector_shape_obj_get_location);
157+
158+
STATIC mp_obj_t vectorio_vector_shape_obj_set_location(mp_obj_t wrapper_shape, mp_obj_t location_obj) {
159+
// Relies on the fact that only vector_shape impl gets matched with a VectorShape.
160+
const vectorio_draw_protocol_t *draw_protocol = mp_proto_get(MP_QSTR_protocol_draw, wrapper_shape);
161+
vectorio_vector_shape_t *self = MP_OBJ_TO_PTR(draw_protocol->draw_get_protocol_self(wrapper_shape));
162+
163+
common_hal_vectorio_vector_shape_set_location(self, location_obj);
164+
return mp_const_none;
165+
}
166+
MP_DEFINE_CONST_FUN_OBJ_2(vectorio_vector_shape_set_location_obj, vectorio_vector_shape_obj_set_location);
167+
168+
const mp_obj_property_t vectorio_vector_shape_location_obj = {
169+
.base.type = &mp_type_property,
170+
.proxy = {(mp_obj_t)&vectorio_vector_shape_get_location_obj,
171+
(mp_obj_t)&vectorio_vector_shape_set_location_obj,
172+
MP_ROM_NONE},
173+
};
174+
175+
146176
// pixel_shader: Union[ColorConverter, Palette]
147177
// """The pixel shader of the shape."""
148178
//

shared-bindings/vectorio/VectorShape.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define MICROPY_INCLUDED_SHARED_BINDINGS_VECTORIO_SHAPE_H
33

44
#include "py/objproperty.h"
5+
#include "py/objtuple.h"
56

67
#include "shared-bindings/vectorio/__init__.h"
78
#include "shared-module/vectorio/VectorShape.h"
@@ -22,6 +23,9 @@ void common_hal_vectorio_vector_shape_set_dirty(void *self);
2223
mp_int_t common_hal_vectorio_vector_shape_get_x(vectorio_vector_shape_t *self);
2324
void common_hal_vectorio_vector_shape_set_x(vectorio_vector_shape_t *self, mp_int_t x);
2425

26+
mp_obj_tuple_t *common_hal_vectorio_vector_shape_get_location(vectorio_vector_shape_t *self);
27+
void common_hal_vectorio_vector_shape_set_location(vectorio_vector_shape_t *self, mp_obj_t xy);
28+
2529
mp_int_t common_hal_vectorio_vector_shape_get_y(vectorio_vector_shape_t *self);
2630
void common_hal_vectorio_vector_shape_set_y(vectorio_vector_shape_t *self, mp_int_t y);
2731

@@ -34,6 +38,7 @@ void vectorio_vector_shape_update_transform(vectorio_vector_shape_t *self, displ
3438
extern vectorio_draw_protocol_impl_t vectorio_vector_shape_draw_protocol_impl;
3539
extern const mp_obj_property_t vectorio_vector_shape_x_obj;
3640
extern const mp_obj_property_t vectorio_vector_shape_y_obj;
41+
extern const mp_obj_property_t vectorio_vector_shape_location_obj;
3742
extern const mp_obj_property_t vectorio_vector_shape_pixel_shader_obj;
3843

3944
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_VECTORIO_SHAPE_H

shared-module/vectorio/VectorShape.c

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@
1414
#include "shared-bindings/vectorio/Rectangle.h"
1515

1616
// Lifecycle actions.
17-
#define VECTORIO_SHAPE_DEBUG(...) (void)0
18-
// #define VECTORIO_SHAPE_DEBUG(...) mp_printf(&mp_plat_print, __VA_ARGS__)
17+
//#define VECTORIO_SHAPE_DEBUG(...) (void)0
18+
#define VECTORIO_SHAPE_DEBUG(...) mp_printf(&mp_plat_print, __VA_ARGS__)
1919

2020

2121
// Used in both logging and ifdefs, for extra variables
2222
// #define VECTORIO_PERF(...) mp_printf(&mp_plat_print, __VA_ARGS__)
2323

2424

2525
// Really verbose.
26-
#define VECTORIO_SHAPE_PIXEL_DEBUG(...) (void)0
27-
// #define VECTORIO_SHAPE_PIXEL_DEBUG(...) mp_printf(&mp_plat_print, __VA_ARGS__)
26+
//#define VECTORIO_SHAPE_PIXEL_DEBUG(...) (void)0
27+
#define VECTORIO_SHAPE_PIXEL_DEBUG(...) mp_printf(&mp_plat_print, __VA_ARGS__)
2828

2929
#define U32_TO_BINARY_FMT "%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c"
3030
#define U32_TO_BINARY(u32) \
@@ -192,6 +192,37 @@ void common_hal_vectorio_vector_shape_set_y(vectorio_vector_shape_t *self, mp_in
192192
common_hal_vectorio_vector_shape_set_dirty(self);
193193
}
194194

195+
mp_obj_tuple_t *common_hal_vectorio_vector_shape_get_location(vectorio_vector_shape_t *self) {
196+
VECTORIO_SHAPE_DEBUG("%p get_location\n", self);
197+
mp_obj_tuple_t *pair = MP_OBJ_TO_PTR(mp_obj_new_tuple(2, NULL));
198+
pair->items[0] = mp_obj_new_int((mp_int_t)self->x);
199+
pair->items[1] = mp_obj_new_int((mp_int_t)self->y);
200+
return pair;
201+
}
202+
203+
204+
void common_hal_vectorio_vector_shape_set_location(vectorio_vector_shape_t *self, mp_obj_t xy) {
205+
VECTORIO_SHAPE_DEBUG("%p set_location\n", self);
206+
size_t tuple_len = 0;
207+
mp_obj_t *tuple_items;
208+
mp_obj_tuple_get(xy, &tuple_len, &tuple_items);
209+
if (tuple_len != 2) {
210+
mp_raise_TypeError_varg(translate("(x,y) integers required"));
211+
}
212+
213+
mp_int_t x;
214+
mp_int_t y;
215+
if (!mp_obj_get_int_maybe(tuple_items[ 0 ], &x)
216+
|| !mp_obj_get_int_maybe(tuple_items[ 1 ], &y)
217+
|| x < SHRT_MIN || x > SHRT_MAX || y < SHRT_MIN || y > SHRT_MAX
218+
) {
219+
mp_raise_ValueError_varg(translate("unsupported %q type"), MP_QSTR_point);
220+
}
221+
self->x = (int16_t)x;
222+
self->y = (int16_t)y;
223+
common_hal_vectorio_vector_shape_set_dirty(self);
224+
}
225+
195226

196227
mp_obj_t common_hal_vectorio_vector_shape_get_pixel_shader(vectorio_vector_shape_t *self) {
197228
VECTORIO_SHAPE_DEBUG("%p get_pixel_shader\n", self);
@@ -271,10 +302,10 @@ bool vectorio_vector_shape_fill_area(vectorio_vector_shape_t *self, const _displ
271302
VECTORIO_SHAPE_PIXEL_DEBUG(" a(%3d, %3d)", pixel_to_get_x, pixel_to_get_y);
272303

273304
if (self->absolute_transform->mirror_x) {
274-
pixel_to_get_y = shape_area.y2 - 1 - (pixel_to_get_y - shape_area.y1);
305+
pixel_to_get_y = shape_area.y2 - 1 - pixel_to_get_y;
275306
}
276307
if (self->absolute_transform->mirror_y) {
277-
pixel_to_get_x = shape_area.x2 - 1 - (pixel_to_get_x - shape_area.x1);
308+
pixel_to_get_x = shape_area.x2 - 1 - pixel_to_get_x;
278309
}
279310
} else {
280311
pixel_to_get_x = input_pixel.x - self->absolute_transform->x - self->absolute_transform->dx * self->x;

0 commit comments

Comments
 (0)