add location property to vectorshape and all composed shapes
This commit is contained in:
parent
bb25aeee51
commit
a1fff320fb
|
@ -318,6 +318,10 @@ msgstr ""
|
|||
msgid "'yield' outside function"
|
||||
msgstr ""
|
||||
|
||||
#: shared-module/vectorio/VectorShape.c
|
||||
msgid "(x,y) integers required"
|
||||
msgstr ""
|
||||
|
||||
#: py/compile.c
|
||||
msgid "*x must be assignment target"
|
||||
msgstr ""
|
||||
|
@ -1185,11 +1189,6 @@ msgstr ""
|
|||
msgid "Input/output error"
|
||||
msgstr ""
|
||||
|
||||
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
|
||||
#, c-format
|
||||
msgid "Missing jmp_pin. Instruction %d jumps on pin"
|
||||
msgstr ""
|
||||
|
||||
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
|
||||
#, c-format
|
||||
msgid "Instruction %d shifts in more bits than pin count"
|
||||
|
@ -1506,6 +1505,11 @@ msgstr ""
|
|||
msgid "Missing first_set_pin. Instruction %d sets pin(s)"
|
||||
msgstr ""
|
||||
|
||||
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
|
||||
#, c-format
|
||||
msgid "Missing jmp_pin. Instruction %d jumps on pin"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/busio/UART.c shared-bindings/displayio/Group.c
|
||||
msgid "Must be a %q subclass."
|
||||
msgstr ""
|
||||
|
@ -2063,7 +2067,6 @@ msgid "Size not supported"
|
|||
msgstr ""
|
||||
|
||||
#: ports/raspberrypi/common-hal/alarm/SleepMemory.c
|
||||
#: ports/stm/common-hal/alarm/SleepMemory.c
|
||||
msgid "Sleep Memory not available"
|
||||
msgstr ""
|
||||
|
||||
|
@ -2510,7 +2513,7 @@ msgid "argument name reused"
|
|||
msgstr ""
|
||||
|
||||
#: py/argcheck.c shared-bindings/_stage/__init__.c
|
||||
#: shared-bindings/digitalio/DigitalInOut.c shared-bindings/gamepad/GamePad.c
|
||||
#: shared-bindings/digitalio/DigitalInOut.c
|
||||
msgid "argument num/types mismatch"
|
||||
msgstr ""
|
||||
|
||||
|
@ -3594,10 +3597,6 @@ msgstr ""
|
|||
msgid "no active exception to reraise"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/socket/__init__.c shared-module/network/__init__.c
|
||||
msgid "no available NIC"
|
||||
msgstr ""
|
||||
|
||||
#: py/compile.c
|
||||
msgid "no binding for nonlocal found"
|
||||
msgstr ""
|
||||
|
@ -4299,7 +4298,7 @@ msgid "unreadable attribute"
|
|||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/TileGrid.c shared-bindings/vectorio/VectorShape.c
|
||||
#: shared-module/vectorio/Polygon.c
|
||||
#: shared-module/vectorio/Polygon.c shared-module/vectorio/VectorShape.c
|
||||
msgid "unsupported %q type"
|
||||
msgstr ""
|
||||
|
||||
|
|
|
@ -86,6 +86,7 @@ STATIC const mp_rom_map_elem_t vectorio_circle_locals_dict_table[] = {
|
|||
{ MP_ROM_QSTR(MP_QSTR_radius), MP_ROM_PTR(&vectorio_circle_radius_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_x), MP_ROM_PTR(&vectorio_vector_shape_x_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_y), MP_ROM_PTR(&vectorio_vector_shape_y_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_location), MP_ROM_PTR(&vectorio_vector_shape_location_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_pixel_shader), MP_ROM_PTR(&vectorio_vector_shape_pixel_shader_obj) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(vectorio_circle_locals_dict, vectorio_circle_locals_dict_table);
|
||||
|
|
|
@ -91,6 +91,7 @@ STATIC const mp_rom_map_elem_t vectorio_polygon_locals_dict_table[] = {
|
|||
{ MP_ROM_QSTR(MP_QSTR_points), MP_ROM_PTR(&vectorio_polygon_points_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_x), MP_ROM_PTR(&vectorio_vector_shape_x_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_y), MP_ROM_PTR(&vectorio_vector_shape_y_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_location), MP_ROM_PTR(&vectorio_vector_shape_location_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_pixel_shader), MP_ROM_PTR(&vectorio_vector_shape_pixel_shader_obj) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(vectorio_polygon_locals_dict, vectorio_polygon_locals_dict_table);
|
||||
|
|
|
@ -64,6 +64,7 @@ STATIC const mp_rom_map_elem_t vectorio_rectangle_locals_dict_table[] = {
|
|||
// Properties
|
||||
{ MP_ROM_QSTR(MP_QSTR_x), MP_ROM_PTR(&vectorio_vector_shape_x_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_y), MP_ROM_PTR(&vectorio_vector_shape_y_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_location), MP_ROM_PTR(&vectorio_vector_shape_location_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_pixel_shader), MP_ROM_PTR(&vectorio_vector_shape_pixel_shader_obj) },
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(vectorio_rectangle_locals_dict, vectorio_rectangle_locals_dict_table);
|
||||
|
|
|
@ -143,6 +143,36 @@ const mp_obj_property_t vectorio_vector_shape_y_obj = {
|
|||
};
|
||||
|
||||
|
||||
// location: Tuple[int, int]
|
||||
// """location of the center point of the shape in the parent."""
|
||||
//
|
||||
STATIC mp_obj_t vectorio_vector_shape_obj_get_location(mp_obj_t wrapper_shape) {
|
||||
// Relies on the fact that only vector_shape impl gets matched with a VectorShape.
|
||||
const vectorio_draw_protocol_t *draw_protocol = mp_proto_get(MP_QSTR_protocol_draw, wrapper_shape);
|
||||
vectorio_vector_shape_t *self = MP_OBJ_TO_PTR(draw_protocol->draw_get_protocol_self(wrapper_shape));
|
||||
|
||||
return MP_OBJ_TO_PTR(common_hal_vectorio_vector_shape_get_location(self));
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorio_vector_shape_get_location_obj, vectorio_vector_shape_obj_get_location);
|
||||
|
||||
STATIC mp_obj_t vectorio_vector_shape_obj_set_location(mp_obj_t wrapper_shape, mp_obj_t location_obj) {
|
||||
// Relies on the fact that only vector_shape impl gets matched with a VectorShape.
|
||||
const vectorio_draw_protocol_t *draw_protocol = mp_proto_get(MP_QSTR_protocol_draw, wrapper_shape);
|
||||
vectorio_vector_shape_t *self = MP_OBJ_TO_PTR(draw_protocol->draw_get_protocol_self(wrapper_shape));
|
||||
|
||||
common_hal_vectorio_vector_shape_set_location(self, location_obj);
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(vectorio_vector_shape_set_location_obj, vectorio_vector_shape_obj_set_location);
|
||||
|
||||
const mp_obj_property_t vectorio_vector_shape_location_obj = {
|
||||
.base.type = &mp_type_property,
|
||||
.proxy = {(mp_obj_t)&vectorio_vector_shape_get_location_obj,
|
||||
(mp_obj_t)&vectorio_vector_shape_set_location_obj,
|
||||
MP_ROM_NONE},
|
||||
};
|
||||
|
||||
|
||||
// pixel_shader: Union[ColorConverter, Palette]
|
||||
// """The pixel shader of the shape."""
|
||||
//
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define MICROPY_INCLUDED_SHARED_BINDINGS_VECTORIO_SHAPE_H
|
||||
|
||||
#include "py/objproperty.h"
|
||||
#include "py/objtuple.h"
|
||||
|
||||
#include "shared-bindings/vectorio/__init__.h"
|
||||
#include "shared-module/vectorio/VectorShape.h"
|
||||
|
@ -22,6 +23,9 @@ void common_hal_vectorio_vector_shape_set_dirty(void *self);
|
|||
mp_int_t common_hal_vectorio_vector_shape_get_x(vectorio_vector_shape_t *self);
|
||||
void common_hal_vectorio_vector_shape_set_x(vectorio_vector_shape_t *self, mp_int_t x);
|
||||
|
||||
mp_obj_tuple_t *common_hal_vectorio_vector_shape_get_location(vectorio_vector_shape_t *self);
|
||||
void common_hal_vectorio_vector_shape_set_location(vectorio_vector_shape_t *self, mp_obj_t xy);
|
||||
|
||||
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);
|
||||
|
||||
|
@ -34,6 +38,7 @@ void vectorio_vector_shape_update_transform(vectorio_vector_shape_t *self, displ
|
|||
extern vectorio_draw_protocol_impl_t vectorio_vector_shape_draw_protocol_impl;
|
||||
extern const mp_obj_property_t vectorio_vector_shape_x_obj;
|
||||
extern const mp_obj_property_t vectorio_vector_shape_y_obj;
|
||||
extern const mp_obj_property_t vectorio_vector_shape_location_obj;
|
||||
extern const mp_obj_property_t vectorio_vector_shape_pixel_shader_obj;
|
||||
|
||||
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_VECTORIO_SHAPE_H
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
#include "shared-bindings/vectorio/Rectangle.h"
|
||||
|
||||
// Lifecycle actions.
|
||||
#define VECTORIO_SHAPE_DEBUG(...) (void)0
|
||||
// #define VECTORIO_SHAPE_DEBUG(...) mp_printf(&mp_plat_print, __VA_ARGS__)
|
||||
//#define VECTORIO_SHAPE_DEBUG(...) (void)0
|
||||
#define VECTORIO_SHAPE_DEBUG(...) mp_printf(&mp_plat_print, __VA_ARGS__)
|
||||
|
||||
|
||||
// Used in both logging and ifdefs, for extra variables
|
||||
|
@ -23,8 +23,8 @@
|
|||
|
||||
|
||||
// Really verbose.
|
||||
#define VECTORIO_SHAPE_PIXEL_DEBUG(...) (void)0
|
||||
// #define VECTORIO_SHAPE_PIXEL_DEBUG(...) mp_printf(&mp_plat_print, __VA_ARGS__)
|
||||
//#define VECTORIO_SHAPE_PIXEL_DEBUG(...) (void)0
|
||||
#define VECTORIO_SHAPE_PIXEL_DEBUG(...) mp_printf(&mp_plat_print, __VA_ARGS__)
|
||||
|
||||
#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"
|
||||
#define U32_TO_BINARY(u32) \
|
||||
|
@ -192,6 +192,37 @@ void common_hal_vectorio_vector_shape_set_y(vectorio_vector_shape_t *self, mp_in
|
|||
common_hal_vectorio_vector_shape_set_dirty(self);
|
||||
}
|
||||
|
||||
mp_obj_tuple_t *common_hal_vectorio_vector_shape_get_location(vectorio_vector_shape_t *self) {
|
||||
VECTORIO_SHAPE_DEBUG("%p get_location\n", self);
|
||||
mp_obj_tuple_t *pair = MP_OBJ_TO_PTR(mp_obj_new_tuple(2, NULL));
|
||||
pair->items[0] = mp_obj_new_int((mp_int_t)self->x);
|
||||
pair->items[1] = mp_obj_new_int((mp_int_t)self->y);
|
||||
return pair;
|
||||
}
|
||||
|
||||
|
||||
void common_hal_vectorio_vector_shape_set_location(vectorio_vector_shape_t *self, mp_obj_t xy) {
|
||||
VECTORIO_SHAPE_DEBUG("%p set_location\n", self);
|
||||
size_t tuple_len = 0;
|
||||
mp_obj_t *tuple_items;
|
||||
mp_obj_tuple_get(xy, &tuple_len, &tuple_items);
|
||||
if (tuple_len != 2) {
|
||||
mp_raise_TypeError_varg(translate("(x,y) integers required"));
|
||||
}
|
||||
|
||||
mp_int_t x;
|
||||
mp_int_t y;
|
||||
if (!mp_obj_get_int_maybe(tuple_items[ 0 ], &x)
|
||||
|| !mp_obj_get_int_maybe(tuple_items[ 1 ], &y)
|
||||
|| x < SHRT_MIN || x > SHRT_MAX || y < SHRT_MIN || y > SHRT_MAX
|
||||
) {
|
||||
mp_raise_ValueError_varg(translate("unsupported %q type"), MP_QSTR_point);
|
||||
}
|
||||
self->x = (int16_t)x;
|
||||
self->y = (int16_t)y;
|
||||
common_hal_vectorio_vector_shape_set_dirty(self);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
|
@ -271,10 +302,10 @@ bool vectorio_vector_shape_fill_area(vectorio_vector_shape_t *self, const _displ
|
|||
VECTORIO_SHAPE_PIXEL_DEBUG(" a(%3d, %3d)", pixel_to_get_x, pixel_to_get_y);
|
||||
|
||||
if (self->absolute_transform->mirror_x) {
|
||||
pixel_to_get_y = shape_area.y2 - 1 - (pixel_to_get_y - shape_area.y1);
|
||||
pixel_to_get_y = shape_area.y2 - 1 - pixel_to_get_y;
|
||||
}
|
||||
if (self->absolute_transform->mirror_y) {
|
||||
pixel_to_get_x = shape_area.x2 - 1 - (pixel_to_get_x - shape_area.x1);
|
||||
pixel_to_get_x = shape_area.x2 - 1 - pixel_to_get_x;
|
||||
}
|
||||
} else {
|
||||
pixel_to_get_x = input_pixel.x - self->absolute_transform->x - self->absolute_transform->dx * self->x;
|
||||
|
|
Loading…
Reference in New Issue