Skip to content

Commit fe8b972

Browse files
committed
color index for vectorio shapes.
1 parent 90fadc5 commit fe8b972

File tree

12 files changed

+128
-39
lines changed

12 files changed

+128
-39
lines changed

shared-bindings/vectorio/Circle.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@
2121
//| :param int y: Initial y position of the axis."""
2222
//|
2323
static mp_obj_t vectorio_circle_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
24-
enum { ARG_pixel_shader, ARG_radius, ARG_x, ARG_y };
24+
enum { ARG_pixel_shader, ARG_radius, ARG_x, ARG_y, ARG_color_index };
2525
static const mp_arg_t allowed_args[] = {
2626
{ MP_QSTR_pixel_shader, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
2727
{ MP_QSTR_radius, MP_ARG_REQUIRED | MP_ARG_INT },
2828
{ MP_QSTR_x, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} },
2929
{ MP_QSTR_y, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} },
30+
{ MP_QSTR_color_index, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} },
3031
};
3132
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
3233
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
@@ -38,7 +39,8 @@ static mp_obj_t vectorio_circle_make_new(const mp_obj_type_t *type, size_t n_arg
3839

3940
vectorio_circle_t *self = m_new_obj(vectorio_circle_t);
4041
self->base.type = &vectorio_circle_type;
41-
common_hal_vectorio_circle_construct(self, radius);
42+
uint16_t color_index = args[ARG_color_index].u_int;
43+
common_hal_vectorio_circle_construct(self, radius, color_index);
4244

4345
// VectorShape parts
4446
mp_obj_t pixel_shader = args[ARG_pixel_shader].u_obj;
@@ -80,6 +82,29 @@ const mp_obj_property_t vectorio_circle_radius_obj = {
8082
MP_ROM_NONE},
8183
};
8284

85+
//| color_index : int
86+
//| """The color_index of the circle as 0 based index of the palette."""
87+
//|
88+
STATIC mp_obj_t vectorio_circle_obj_get_color_index(mp_obj_t self_in) {
89+
vectorio_circle_t *self = MP_OBJ_TO_PTR(self_in);
90+
return mp_obj_new_int(common_hal_vectorio_circle_get_color_index(self));
91+
}
92+
MP_DEFINE_CONST_FUN_OBJ_1(vectorio_circle_get_color_index_obj, vectorio_circle_obj_get_color_index);
93+
94+
STATIC mp_obj_t vectorio_circle_obj_set_color_index(mp_obj_t self_in, mp_obj_t color_index) {
95+
vectorio_circle_t *self = MP_OBJ_TO_PTR(self_in);
96+
common_hal_vectorio_circle_set_color_index(self, mp_obj_get_int(color_index));
97+
return mp_const_none;
98+
}
99+
MP_DEFINE_CONST_FUN_OBJ_2(vectorio_circle_set_color_index_obj, vectorio_circle_obj_set_color_index);
100+
101+
const mp_obj_property_t vectorio_circle_color_index_obj = {
102+
.base.type = &mp_type_property,
103+
.proxy = {(mp_obj_t)&vectorio_circle_get_color_index_obj,
104+
(mp_obj_t)&vectorio_circle_set_color_index_obj,
105+
MP_ROM_NONE},
106+
};
107+
83108

84109
// Documentation for properties inherited from VectorShape.
85110

@@ -103,6 +128,7 @@ STATIC const mp_rom_map_elem_t vectorio_circle_locals_dict_table[] = {
103128
{ MP_ROM_QSTR(MP_QSTR_radius), MP_ROM_PTR(&vectorio_circle_radius_obj) },
104129
{ MP_ROM_QSTR(MP_QSTR_x), MP_ROM_PTR(&vectorio_vector_shape_x_obj) },
105130
{ MP_ROM_QSTR(MP_QSTR_y), MP_ROM_PTR(&vectorio_vector_shape_y_obj) },
131+
{ MP_ROM_QSTR(MP_QSTR_color_index), MP_ROM_PTR(&vectorio_circle_color_index_obj) },
106132
{ MP_ROM_QSTR(MP_QSTR_location), MP_ROM_PTR(&vectorio_vector_shape_location_obj) },
107133
{ MP_ROM_QSTR(MP_QSTR_pixel_shader), MP_ROM_PTR(&vectorio_vector_shape_pixel_shader_obj) },
108134
};

shared-bindings/vectorio/Circle.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
extern const mp_obj_type_t vectorio_circle_type;
99

10-
void common_hal_vectorio_circle_construct(vectorio_circle_t *self, uint16_t radius);
10+
void common_hal_vectorio_circle_construct(vectorio_circle_t *self, uint16_t radius, uint16_t color_index);
1111

1212
void common_hal_vectorio_circle_set_on_dirty(vectorio_circle_t *self, vectorio_event_t notification);
1313

@@ -19,6 +19,9 @@ void common_hal_vectorio_circle_get_area(void *circle, displayio_area_t *out_are
1919
int16_t common_hal_vectorio_circle_get_radius(void *circle);
2020
void common_hal_vectorio_circle_set_radius(void *circle, int16_t radius);
2121

22+
uint16_t common_hal_vectorio_circle_get_color_index(void *obj);
23+
void common_hal_vectorio_circle_set_color_index(void *obj, uint16_t color_index);
24+
2225
mp_obj_t common_hal_vectorio_circle_get_draw_protocol(void *circle);
2326

2427
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_VECTORIO_CIRCLE_H

shared-bindings/vectorio/Polygon.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@
2828
//| :param int y: Initial screen y position of the 0,0 origin in the points list."""
2929
//|
3030
static mp_obj_t vectorio_polygon_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
31-
enum { ARG_pixel_shader, ARG_points_list, ARG_x, ARG_y };
31+
enum { ARG_pixel_shader, ARG_points_list, ARG_x, ARG_y, ARG_color_index };
3232
static const mp_arg_t allowed_args[] = {
3333
{ MP_QSTR_pixel_shader, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
3434
{ MP_QSTR_points, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
3535
{ MP_QSTR_x, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} },
3636
{ MP_QSTR_y, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} },
37+
{ MP_QSTR_color_index, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} },
3738
};
3839
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
3940
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
@@ -43,7 +44,8 @@ static mp_obj_t vectorio_polygon_make_new(const mp_obj_type_t *type, size_t n_ar
4344
vectorio_polygon_t *self = m_new_obj(vectorio_polygon_t);
4445
self->base.type = &vectorio_polygon_type;
4546

46-
common_hal_vectorio_polygon_construct(self, points_list);
47+
uint16_t color_index = args[ARG_color_index].u_int;
48+
common_hal_vectorio_polygon_construct(self, points_list, color_index);
4749

4850
// VectorShape parts
4951
mp_obj_t pixel_shader = args[ARG_pixel_shader].u_obj;
@@ -86,6 +88,29 @@ const mp_obj_property_t vectorio_polygon_points_obj = {
8688
MP_ROM_NONE},
8789
};
8890

91+
//| color_index : int
92+
//| """The color_index of the polygon as 0 based index of the palette."""
93+
//|
94+
STATIC mp_obj_t vectorio_polygon_obj_get_color_index(mp_obj_t self_in) {
95+
vectorio_polygon_t *self = MP_OBJ_TO_PTR(self_in);
96+
return mp_obj_new_int(common_hal_vectorio_polygon_get_color_index(self));
97+
}
98+
MP_DEFINE_CONST_FUN_OBJ_1(vectorio_polygon_get_color_index_obj, vectorio_polygon_obj_get_color_index);
99+
100+
STATIC mp_obj_t vectorio_polygon_obj_set_color_index(mp_obj_t self_in, mp_obj_t color_index) {
101+
vectorio_polygon_t *self = MP_OBJ_TO_PTR(self_in);
102+
common_hal_vectorio_polygon_set_color_index(self, mp_obj_get_int(color_index));
103+
return mp_const_none;
104+
}
105+
MP_DEFINE_CONST_FUN_OBJ_2(vectorio_polygon_set_color_index_obj, vectorio_polygon_obj_set_color_index);
106+
107+
const mp_obj_property_t vectorio_polygon_color_index_obj = {
108+
.base.type = &mp_type_property,
109+
.proxy = {(mp_obj_t)&vectorio_polygon_get_color_index_obj,
110+
(mp_obj_t)&vectorio_polygon_set_color_index_obj,
111+
MP_ROM_NONE},
112+
};
113+
89114

90115
// Documentation for properties inherited from VectorShape.
91116

@@ -109,6 +134,7 @@ STATIC const mp_rom_map_elem_t vectorio_polygon_locals_dict_table[] = {
109134
{ MP_ROM_QSTR(MP_QSTR_points), MP_ROM_PTR(&vectorio_polygon_points_obj) },
110135
{ MP_ROM_QSTR(MP_QSTR_x), MP_ROM_PTR(&vectorio_vector_shape_x_obj) },
111136
{ MP_ROM_QSTR(MP_QSTR_y), MP_ROM_PTR(&vectorio_vector_shape_y_obj) },
137+
{ MP_ROM_QSTR(MP_QSTR_color_index), MP_ROM_PTR(&vectorio_polygon_color_index_obj) },
112138
{ MP_ROM_QSTR(MP_QSTR_location), MP_ROM_PTR(&vectorio_vector_shape_location_obj) },
113139
{ MP_ROM_QSTR(MP_QSTR_pixel_shader), MP_ROM_PTR(&vectorio_vector_shape_pixel_shader_obj) },
114140
};

shared-bindings/vectorio/Polygon.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
extern const mp_obj_type_t vectorio_polygon_type;
99

10-
void common_hal_vectorio_polygon_construct(vectorio_polygon_t *self, mp_obj_t points_list);
10+
void common_hal_vectorio_polygon_construct(vectorio_polygon_t *self, mp_obj_t points_list, uint16_t color_index);
1111
void common_hal_vectorio_polygon_set_on_dirty(vectorio_polygon_t *self, vectorio_event_t notification);
1212

1313

@@ -20,6 +20,9 @@ void common_hal_vectorio_polygon_get_area(void *polygon, displayio_area_t *out_a
2020
mp_obj_t common_hal_vectorio_polygon_get_points(vectorio_polygon_t *self);
2121
void common_hal_vectorio_polygon_set_points(vectorio_polygon_t *self, mp_obj_t points_list);
2222

23+
uint16_t common_hal_vectorio_polygon_get_color_index(void *obj);
24+
void common_hal_vectorio_polygon_set_color_index(void *obj, uint16_t color_index);
25+
2326
mp_obj_t common_hal_vectorio_polygon_get_draw_protocol(void *polygon);
2427

2528

shared-bindings/vectorio/Rectangle.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@
1818
//| :param int height: The number of pixels high
1919
//| :param int x: Initial x position of the top left corner.
2020
//| :param int y: Initial y position of the top left corner.
21-
//| :param int color_number: Initial color_number to use when selecting color from the palette."""
21+
//| :param int color_index: Initial color_index to use when selecting color from the palette."""
2222
//|
2323
static mp_obj_t vectorio_rectangle_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
24-
enum { ARG_pixel_shader, ARG_width, ARG_height, ARG_x, ARG_y, ARG_color_number };
24+
enum { ARG_pixel_shader, ARG_width, ARG_height, ARG_x, ARG_y, ARG_color_index };
2525
static const mp_arg_t allowed_args[] = {
2626
{ MP_QSTR_pixel_shader, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
2727
{ MP_QSTR_width, MP_ARG_REQUIRED | MP_ARG_INT },
2828
{ MP_QSTR_height, MP_ARG_REQUIRED | MP_ARG_INT },
2929
{ MP_QSTR_x, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} },
3030
{ MP_QSTR_y, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} },
31-
{ MP_QSTR_color_number, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 1} },
31+
{ MP_QSTR_color_index, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} },
3232
};
3333
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
3434
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
@@ -44,8 +44,8 @@ static mp_obj_t vectorio_rectangle_make_new(const mp_obj_type_t *type, size_t n_
4444

4545
vectorio_rectangle_t *self = m_new_obj(vectorio_rectangle_t);
4646
self->base.type = &vectorio_rectangle_type;
47-
int32_t color_number = args[ARG_color_number].u_int;
48-
common_hal_vectorio_rectangle_construct(self, width, height, color_number);
47+
uint16_t color_index = args[ARG_color_index].u_int;
48+
common_hal_vectorio_rectangle_construct(self, width, height, color_index);
4949

5050
// VectorShape parts
5151
mp_obj_t pixel_shader = args[ARG_pixel_shader].u_obj;
@@ -109,26 +109,26 @@ const mp_obj_property_t vectorio_rectangle_height_obj = {
109109
MP_ROM_NONE},
110110
};
111111

112-
//| color_number : int
113-
//| """The color_number of the rectangle in 1 based index of the palette."""
112+
//| color_index : int
113+
//| """The color_index of the rectangle in 1 based index of the palette."""
114114
//|
115-
STATIC mp_obj_t vectorio_rectangle_obj_get_color_number(mp_obj_t self_in) {
115+
STATIC mp_obj_t vectorio_rectangle_obj_get_color_index(mp_obj_t self_in) {
116116
vectorio_rectangle_t *self = MP_OBJ_TO_PTR(self_in);
117-
return mp_obj_new_int(common_hal_vectorio_rectangle_get_color_number(self));
117+
return mp_obj_new_int(common_hal_vectorio_rectangle_get_color_index(self));
118118
}
119-
MP_DEFINE_CONST_FUN_OBJ_1(vectorio_rectangle_get_color_number_obj, vectorio_rectangle_obj_get_color_number);
119+
MP_DEFINE_CONST_FUN_OBJ_1(vectorio_rectangle_get_color_index_obj, vectorio_rectangle_obj_get_color_index);
120120

121-
STATIC mp_obj_t vectorio_rectangle_obj_set_color_number(mp_obj_t self_in, mp_obj_t color_number) {
121+
STATIC mp_obj_t vectorio_rectangle_obj_set_color_index(mp_obj_t self_in, mp_obj_t color_index) {
122122
vectorio_rectangle_t *self = MP_OBJ_TO_PTR(self_in);
123-
common_hal_vectorio_rectangle_set_color_number(self, mp_obj_get_int(color_number));
123+
common_hal_vectorio_rectangle_set_color_index(self, mp_obj_get_int(color_index));
124124
return mp_const_none;
125125
}
126-
MP_DEFINE_CONST_FUN_OBJ_2(vectorio_rectangle_set_color_number_obj, vectorio_rectangle_obj_set_color_number);
126+
MP_DEFINE_CONST_FUN_OBJ_2(vectorio_rectangle_set_color_index_obj, vectorio_rectangle_obj_set_color_index);
127127

128-
const mp_obj_property_t vectorio_rectangle_color_number_obj = {
128+
const mp_obj_property_t vectorio_rectangle_color_index_obj = {
129129
.base.type = &mp_type_property,
130-
.proxy = {(mp_obj_t)&vectorio_rectangle_get_color_number_obj,
131-
(mp_obj_t)&vectorio_rectangle_set_color_number_obj,
130+
.proxy = {(mp_obj_t)&vectorio_rectangle_get_color_index_obj,
131+
(mp_obj_t)&vectorio_rectangle_set_color_index_obj,
132132
MP_ROM_NONE},
133133
};
134134

@@ -153,7 +153,7 @@ STATIC const mp_rom_map_elem_t vectorio_rectangle_locals_dict_table[] = {
153153
// Properties
154154
{ MP_ROM_QSTR(MP_QSTR_x), MP_ROM_PTR(&vectorio_vector_shape_x_obj) },
155155
{ MP_ROM_QSTR(MP_QSTR_y), MP_ROM_PTR(&vectorio_vector_shape_y_obj) },
156-
{ MP_ROM_QSTR(MP_QSTR_color_number), MP_ROM_PTR(&vectorio_rectangle_color_number_obj) },
156+
{ MP_ROM_QSTR(MP_QSTR_color_index), MP_ROM_PTR(&vectorio_rectangle_color_index_obj) },
157157
{ MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&vectorio_rectangle_width_obj) },
158158
{ MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&vectorio_rectangle_height_obj) },
159159
{ MP_ROM_QSTR(MP_QSTR_location), MP_ROM_PTR(&vectorio_vector_shape_location_obj) },

shared-bindings/vectorio/Rectangle.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
extern const mp_obj_type_t vectorio_rectangle_type;
99

10-
void common_hal_vectorio_rectangle_construct(vectorio_rectangle_t *self, uint32_t width, uint32_t height, uint32_t color_index);
10+
void common_hal_vectorio_rectangle_construct(vectorio_rectangle_t *self, uint32_t width, uint32_t height, uint16_t color_index);
1111
void common_hal_vectorio_rectangle_set_on_dirty(vectorio_rectangle_t *self, vectorio_event_t on_dirty);
1212

1313
uint32_t common_hal_vectorio_rectangle_get_pixel(void *rectangle, int16_t x, int16_t y);
@@ -18,8 +18,9 @@ mp_obj_t common_hal_vectorio_rectangle_get_draw_protocol(void *rectangle);
1818

1919
int16_t common_hal_vectorio_rectangle_get_width(void *obj);
2020
void common_hal_vectorio_rectangle_set_width(void *obj, int16_t width);
21-
int16_t common_hal_vectorio_rectangle_get_color_number(void *obj);
22-
void common_hal_vectorio_rectangle_set_color_number(void *obj, int16_t color_number);
21+
22+
uint16_t common_hal_vectorio_rectangle_get_color_index(void *obj);
23+
void common_hal_vectorio_rectangle_set_color_index(void *obj, uint16_t color_index);
2324

2425
int16_t common_hal_vectorio_rectangle_get_height(void *obj);
2526
void common_hal_vectorio_rectangle_set_height(void *obj, int16_t height);

shared-module/vectorio/Circle.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
#include "stdlib.h"
88

99

10-
void common_hal_vectorio_circle_construct(vectorio_circle_t *self, uint16_t radius) {
10+
void common_hal_vectorio_circle_construct(vectorio_circle_t *self, uint16_t radius, uint16_t color_index) {
1111
self->radius = radius;
1212
self->on_dirty.obj = NULL;
13+
self->color_index = color_index + 1;
1314
}
1415

1516
void common_hal_vectorio_circle_set_on_dirty(vectorio_circle_t *self, vectorio_event_t on_dirty) {
@@ -26,7 +27,7 @@ uint32_t common_hal_vectorio_circle_get_pixel(void *obj, int16_t x, int16_t y) {
2627
x = abs(x);
2728
y = abs(y);
2829
if (x + y <= radius) {
29-
return 1;
30+
return self->color_index;
3031
}
3132
if (x > radius) {
3233
return 0;
@@ -35,7 +36,7 @@ uint32_t common_hal_vectorio_circle_get_pixel(void *obj, int16_t x, int16_t y) {
3536
return 0;
3637
}
3738
const bool pythagorasSmallerThanRadius = (int32_t)x * x + (int32_t)y * y <= (int32_t)radius * radius;
38-
return pythagorasSmallerThanRadius ? 1 : 0;
39+
return pythagorasSmallerThanRadius ? self->color_index : 0;
3940
}
4041

4142

@@ -60,6 +61,19 @@ void common_hal_vectorio_circle_set_radius(void *obj, int16_t radius) {
6061
}
6162
}
6263

64+
uint16_t common_hal_vectorio_circle_get_color_index(void *obj) {
65+
vectorio_circle_t *self = obj;
66+
return self->color_index - 1;
67+
}
68+
69+
void common_hal_vectorio_circle_set_color_index(void *obj, uint16_t color_index) {
70+
vectorio_circle_t *self = obj;
71+
self->color_index = abs(color_index + 1);
72+
if (self->on_dirty.obj != NULL) {
73+
self->on_dirty.event(self->on_dirty.obj);
74+
}
75+
}
76+
6377
mp_obj_t common_hal_vectorio_circle_get_draw_protocol(void *circle) {
6478
vectorio_circle_t *self = circle;
6579
return self->draw_protocol_instance;

shared-module/vectorio/Circle.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
typedef struct {
1111
mp_obj_base_t base;
1212
uint16_t radius;
13+
uint16_t color_index;
1314
vectorio_event_t on_dirty;
1415
mp_obj_t draw_protocol_instance;
1516
} vectorio_circle_t;

shared-module/vectorio/Polygon.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,12 @@ static void _clobber_points_list(vectorio_polygon_t *self, mp_obj_t points_tuple
6161

6262

6363

64-
void common_hal_vectorio_polygon_construct(vectorio_polygon_t *self, mp_obj_t points_list) {
64+
void common_hal_vectorio_polygon_construct(vectorio_polygon_t *self, mp_obj_t points_list, uint16_t color_index) {
6565
VECTORIO_POLYGON_DEBUG("%p polygon_construct: ", self);
6666
self->points_list = NULL;
6767
self->len = 0;
6868
self->on_dirty.obj = NULL;
69+
self->color_index = color_index + 1;
6970
_clobber_points_list(self, points_list);
7071
VECTORIO_POLYGON_DEBUG("\n");
7172
}
@@ -181,10 +182,23 @@ uint32_t common_hal_vectorio_polygon_get_pixel(void *obj, int16_t x, int16_t y)
181182
x1 = x2;
182183
y1 = y2;
183184
}
184-
return winding_number == 0 ? 0 : 1;
185+
return winding_number == 0 ? 0 : self->color_index;
185186
}
186187

187188
mp_obj_t common_hal_vectorio_polygon_get_draw_protocol(void *polygon) {
188189
vectorio_polygon_t *self = polygon;
189190
return self->draw_protocol_instance;
190191
}
192+
193+
uint16_t common_hal_vectorio_polygon_get_color_index(void *obj) {
194+
vectorio_polygon_t *self = obj;
195+
return self->color_index - 1;
196+
}
197+
198+
void common_hal_vectorio_polygon_set_color_index(void *obj, uint16_t color_index) {
199+
vectorio_polygon_t *self = obj;
200+
self->color_index = abs(color_index + 1);
201+
if (self->on_dirty.obj != NULL) {
202+
self->on_dirty.event(self->on_dirty.obj);
203+
}
204+
}

shared-module/vectorio/Polygon.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ typedef struct {
1111
// An int array[ x, y, ... ]
1212
int16_t *points_list;
1313
uint16_t len;
14+
uint16_t color_index;
1415
vectorio_event_t on_dirty;
1516
mp_obj_t draw_protocol_instance;
1617
} vectorio_polygon_t;

0 commit comments

Comments
 (0)