2021-08-01 16:01:57 -04:00
|
|
|
#include "shared-bindings/vectorio/__init__.h"
|
2020-05-02 05:21:35 -04:00
|
|
|
#include "shared-module/vectorio/__init__.h"
|
|
|
|
#include "shared-bindings/vectorio/Polygon.h"
|
2021-08-01 16:01:57 -04:00
|
|
|
#include "shared-bindings/vectorio/VectorShape.h"
|
2020-05-02 05:21:35 -04:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "py/obj.h"
|
|
|
|
#include "py/objproperty.h"
|
|
|
|
#include "py/objtype.h"
|
|
|
|
#include "py/runtime.h"
|
|
|
|
#include "supervisor/shared/translate.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define VECTORIO_POLYGON_DEBUG(...) (void)0
|
|
|
|
// #define VECTORIO_POLYGON_DEBUG(...) mp_printf(&mp_plat_print __VA_OPT__(,) __VA_ARGS__)
|
|
|
|
|
|
|
|
|
2020-05-12 21:40:02 -04:00
|
|
|
//| class Polygon:
|
2021-08-05 03:13:10 -04:00
|
|
|
//| def __init__(self, pixel_shader: Union[displayio.ColorConverter, displayio.Palette], points: List[Tuple[int, int]], x: int, y: int) -> None:
|
2020-05-12 21:40:02 -04:00
|
|
|
//| """Represents a closed shape by ordered vertices
|
2020-05-02 05:21:35 -04:00
|
|
|
//|
|
2021-08-01 16:01:57 -04:00
|
|
|
//| :param pixel_shader: The pixel shader that produces colors from values
|
|
|
|
//| :param points: Vertices for the polygon
|
|
|
|
//| :param x: Initial screen x position of the 0,0 origin in the points list.
|
|
|
|
//| :param y: Initial screen y position of the 0,0 origin in the points list."""
|
2020-05-02 05:21:35 -04:00
|
|
|
//|
|
|
|
|
static mp_obj_t vectorio_polygon_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
2021-08-01 16:01:57 -04:00
|
|
|
enum { ARG_pixel_shader, ARG_points_list, ARG_x, ARG_y };
|
2020-05-02 05:21:35 -04:00
|
|
|
static const mp_arg_t allowed_args[] = {
|
2021-08-01 16:01:57 -04:00
|
|
|
{ MP_QSTR_pixel_shader, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
|
2020-05-02 05:21:35 -04:00
|
|
|
{ MP_QSTR_points, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
|
2021-08-01 16:01:57 -04:00
|
|
|
{ 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} },
|
2020-05-02 05:21:35 -04:00
|
|
|
};
|
|
|
|
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);
|
|
|
|
|
2021-04-22 20:55:39 -04:00
|
|
|
if (!mp_obj_is_type(args[ARG_points_list].u_obj, &mp_type_list)) {
|
2020-05-02 05:21:35 -04:00
|
|
|
mp_raise_TypeError_varg(translate("%q list must be a list"), MP_QSTR_point);
|
|
|
|
}
|
|
|
|
|
|
|
|
vectorio_polygon_t *self = m_new_obj(vectorio_polygon_t);
|
|
|
|
self->base.type = &vectorio_polygon_type;
|
|
|
|
|
2020-05-13 00:55:18 -04:00
|
|
|
common_hal_vectorio_polygon_construct(self, args[ARG_points_list].u_obj);
|
2020-05-02 05:21:35 -04:00
|
|
|
|
2021-08-01 16:01:57 -04:00
|
|
|
// VectorShape parts
|
|
|
|
mp_obj_t pixel_shader = args[ARG_pixel_shader].u_obj;
|
|
|
|
int16_t x = args[ARG_x].u_int;
|
|
|
|
int16_t y = args[ARG_y].u_int;
|
|
|
|
mp_obj_t vector_shape = vectorio_vector_shape_make_new(self, pixel_shader, x, y);
|
|
|
|
self->draw_protocol_instance = vector_shape;
|
|
|
|
|
2020-05-02 05:21:35 -04:00
|
|
|
return MP_OBJ_FROM_PTR(self);
|
|
|
|
}
|
|
|
|
|
2021-08-01 16:01:57 -04:00
|
|
|
STATIC const vectorio_draw_protocol_t polygon_draw_protocol = {
|
|
|
|
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_draw)
|
|
|
|
.draw_get_protocol_self = (draw_get_protocol_self_fun)common_hal_vectorio_polygon_get_draw_protocol,
|
|
|
|
.draw_protocol_impl = &vectorio_vector_shape_draw_protocol_impl
|
|
|
|
};
|
|
|
|
|
2020-05-02 05:21:35 -04:00
|
|
|
|
2020-07-25 04:58:37 -04:00
|
|
|
//| points: List[Tuple[int, int]]
|
2020-05-12 21:40:02 -04:00
|
|
|
//| """Set a new look and shape for this polygon"""
|
2020-05-02 05:21:35 -04:00
|
|
|
//|
|
|
|
|
STATIC mp_obj_t vectorio_polygon_obj_get_points(mp_obj_t self_in) {
|
|
|
|
vectorio_polygon_t *self = MP_OBJ_TO_PTR(self_in);
|
2020-07-19 15:27:35 -04:00
|
|
|
return common_hal_vectorio_polygon_get_points(self);
|
2020-05-02 05:21:35 -04:00
|
|
|
}
|
|
|
|
MP_DEFINE_CONST_FUN_OBJ_1(vectorio_polygon_get_points_obj, vectorio_polygon_obj_get_points);
|
|
|
|
|
|
|
|
STATIC mp_obj_t vectorio_polygon_obj_set_points(mp_obj_t self_in, mp_obj_t points) {
|
|
|
|
vectorio_polygon_t *self = MP_OBJ_TO_PTR(self_in);
|
|
|
|
|
2020-05-13 00:55:18 -04:00
|
|
|
common_hal_vectorio_polygon_set_points(self, points);
|
2020-05-02 05:21:35 -04:00
|
|
|
return mp_const_none;
|
|
|
|
}
|
|
|
|
MP_DEFINE_CONST_FUN_OBJ_2(vectorio_polygon_set_points_obj, vectorio_polygon_obj_set_points);
|
|
|
|
|
|
|
|
const mp_obj_property_t vectorio_polygon_points_obj = {
|
|
|
|
.base.type = &mp_type_property,
|
|
|
|
.proxy = {(mp_obj_t)&vectorio_polygon_get_points_obj,
|
|
|
|
(mp_obj_t)&vectorio_polygon_set_points_obj,
|
2021-05-05 20:51:52 -04:00
|
|
|
MP_ROM_NONE},
|
2020-05-02 05:21:35 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
STATIC const mp_rom_map_elem_t vectorio_polygon_locals_dict_table[] = {
|
2021-08-01 16:01:57 -04:00
|
|
|
// Properties
|
2020-05-02 05:21:35 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_points), MP_ROM_PTR(&vectorio_polygon_points_obj) },
|
2021-08-01 16:01:57 -04:00
|
|
|
{ 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) },
|
2021-08-08 03:14:53 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_location), MP_ROM_PTR(&vectorio_vector_shape_location_obj) },
|
2021-08-01 16:01:57 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_pixel_shader), MP_ROM_PTR(&vectorio_vector_shape_pixel_shader_obj) },
|
2020-05-02 05:21:35 -04:00
|
|
|
};
|
|
|
|
STATIC MP_DEFINE_CONST_DICT(vectorio_polygon_locals_dict, vectorio_polygon_locals_dict_table);
|
|
|
|
|
|
|
|
const mp_obj_type_t vectorio_polygon_type = {
|
|
|
|
{ &mp_type_type },
|
|
|
|
.name = MP_QSTR_Polygon,
|
2021-08-01 16:01:57 -04:00
|
|
|
.flags = MP_TYPE_FLAG_EXTENDED,
|
2020-05-02 05:21:35 -04:00
|
|
|
.make_new = vectorio_polygon_make_new,
|
2021-03-15 09:57:36 -04:00
|
|
|
.locals_dict = (mp_obj_dict_t *)&vectorio_polygon_locals_dict,
|
2021-08-01 16:01:57 -04:00
|
|
|
MP_TYPE_EXTENDED_FIELDS(
|
|
|
|
.protocol = &polygon_draw_protocol,
|
|
|
|
),
|
2020-05-02 05:21:35 -04:00
|
|
|
};
|