1-
1+ #include "shared-bindings/vectorio/__init__.h"
22#include "shared-module/vectorio/__init__.h"
33#include "shared-bindings/vectorio/Polygon.h"
4+ #include "shared-bindings/vectorio/VectorShape.h"
45
56#include <stdint.h>
67
1617
1718
1819//| class Polygon:
19- //| def __init__(self, points: List[Tuple[int, int]]) -> None:
20+ //| def __init__(self, pixel_shader: Union[displayio.ColorConverter, displayio.Palette], points: List[Tuple[int, int]], x: int, y: int ) -> None:
2021//| """Represents a closed shape by ordered vertices
2122//|
22- //| :param points: Vertices for the polygon"""
23+ //| :param pixel_shader: The pixel shader that produces colors from values
24+ //| :param points: Vertices for the polygon
25+ //| :param x: Initial screen x position of the 0,0 origin in the points list.
26+ //| :param y: Initial screen y position of the 0,0 origin in the points list."""
2327//|
2428static 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 ) {
25- enum { ARG_points_list };
29+ enum { ARG_pixel_shader , ARG_points_list , ARG_x , ARG_y };
2630 static const mp_arg_t allowed_args [] = {
31+ { MP_QSTR_pixel_shader , MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
2732 { MP_QSTR_points , MP_ARG_REQUIRED | MP_ARG_OBJ , {.u_obj = MP_OBJ_NULL } },
33+ { MP_QSTR_x , MP_ARG_INT | MP_ARG_KW_ONLY , {.u_int = 0 } },
34+ { MP_QSTR_y , MP_ARG_INT | MP_ARG_KW_ONLY , {.u_int = 0 } },
2835 };
2936 mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
3037 mp_arg_parse_all (n_args , pos_args , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
@@ -38,9 +45,22 @@ static mp_obj_t vectorio_polygon_make_new(const mp_obj_type_t *type, size_t n_ar
3845
3946 common_hal_vectorio_polygon_construct (self , args [ARG_points_list ].u_obj );
4047
48+ // VectorShape parts
49+ mp_obj_t pixel_shader = args [ARG_pixel_shader ].u_obj ;
50+ int16_t x = args [ARG_x ].u_int ;
51+ int16_t y = args [ARG_y ].u_int ;
52+ mp_obj_t vector_shape = vectorio_vector_shape_make_new (self , pixel_shader , x , y );
53+ self -> draw_protocol_instance = vector_shape ;
54+
4155 return MP_OBJ_FROM_PTR (self );
4256}
4357
58+ STATIC const vectorio_draw_protocol_t polygon_draw_protocol = {
59+ MP_PROTO_IMPLEMENT (MP_QSTR_protocol_draw )
60+ .draw_get_protocol_self = (draw_get_protocol_self_fun )common_hal_vectorio_polygon_get_draw_protocol ,
61+ .draw_protocol_impl = & vectorio_vector_shape_draw_protocol_impl
62+ };
63+
4464
4565//| points: List[Tuple[int, int]]
4666//| """Set a new look and shape for this polygon"""
@@ -67,13 +87,22 @@ const mp_obj_property_t vectorio_polygon_points_obj = {
6787};
6888
6989STATIC const mp_rom_map_elem_t vectorio_polygon_locals_dict_table [] = {
90+ // Properties
7091 { MP_ROM_QSTR (MP_QSTR_points ), MP_ROM_PTR (& vectorio_polygon_points_obj ) },
92+ { MP_ROM_QSTR (MP_QSTR_x ), MP_ROM_PTR (& vectorio_vector_shape_x_obj ) },
93+ { 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 ) },
95+ { MP_ROM_QSTR (MP_QSTR_pixel_shader ), MP_ROM_PTR (& vectorio_vector_shape_pixel_shader_obj ) },
7196};
7297STATIC MP_DEFINE_CONST_DICT (vectorio_polygon_locals_dict , vectorio_polygon_locals_dict_table );
7398
7499const mp_obj_type_t vectorio_polygon_type = {
75100 { & mp_type_type },
76101 .name = MP_QSTR_Polygon ,
102+ .flags = MP_TYPE_FLAG_EXTENDED ,
77103 .make_new = vectorio_polygon_make_new ,
78104 .locals_dict = (mp_obj_dict_t * )& vectorio_polygon_locals_dict ,
105+ MP_TYPE_EXTENDED_FIELDS (
106+ .protocol = & polygon_draw_protocol ,
107+ ),
79108};
0 commit comments