1717//| :param int width: The number of pixels wide
1818//| :param int height: The number of pixels high
1919//| :param int x: Initial x position of the top left corner.
20- //| :param int y: Initial y position of the top left corner."""
20+ //| :param int y: Initial y position of the top left corner.
21+ //| :param int color_index: Initial color_index to use when selecting color from the palette."""
2122//|
2223static 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 ) {
23- enum { ARG_pixel_shader , ARG_width , ARG_height , ARG_x , ARG_y };
24+ enum { ARG_pixel_shader , ARG_width , ARG_height , ARG_x , ARG_y , ARG_color_index };
2425 static const mp_arg_t allowed_args [] = {
2526 { MP_QSTR_pixel_shader , MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
2627 { MP_QSTR_width , MP_ARG_REQUIRED | MP_ARG_INT },
2728 { MP_QSTR_height , MP_ARG_REQUIRED | MP_ARG_INT },
2829 { MP_QSTR_x , MP_ARG_INT | MP_ARG_KW_ONLY , {.u_int = 0 } },
2930 { MP_QSTR_y , MP_ARG_INT | MP_ARG_KW_ONLY , {.u_int = 0 } },
31+ { MP_QSTR_color_index , MP_ARG_INT | MP_ARG_KW_ONLY , {.u_int = 0 } },
3032 };
3133 mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
3234 mp_arg_parse_all_kw_array (n_args , n_kw , all_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
@@ -42,7 +44,8 @@ static mp_obj_t vectorio_rectangle_make_new(const mp_obj_type_t *type, size_t n_
4244
4345 vectorio_rectangle_t * self = m_new_obj (vectorio_rectangle_t );
4446 self -> base .type = & vectorio_rectangle_type ;
45- common_hal_vectorio_rectangle_construct (self , width , height );
47+ uint16_t color_index = args [ARG_color_index ].u_int ;
48+ common_hal_vectorio_rectangle_construct (self , width , height , color_index );
4649
4750 // VectorShape parts
4851 mp_obj_t pixel_shader = args [ARG_pixel_shader ].u_obj ;
@@ -106,6 +109,29 @@ const mp_obj_property_t vectorio_rectangle_height_obj = {
106109 MP_ROM_NONE },
107110};
108111
112+ //| color_index : int
113+ //| """The color_index of the rectangle in 1 based index of the palette."""
114+ //|
115+ STATIC mp_obj_t vectorio_rectangle_obj_get_color_index (mp_obj_t self_in ) {
116+ vectorio_rectangle_t * self = MP_OBJ_TO_PTR (self_in );
117+ return mp_obj_new_int (common_hal_vectorio_rectangle_get_color_index (self ));
118+ }
119+ MP_DEFINE_CONST_FUN_OBJ_1 (vectorio_rectangle_get_color_index_obj , vectorio_rectangle_obj_get_color_index );
120+
121+ STATIC mp_obj_t vectorio_rectangle_obj_set_color_index (mp_obj_t self_in , mp_obj_t color_index ) {
122+ vectorio_rectangle_t * self = MP_OBJ_TO_PTR (self_in );
123+ common_hal_vectorio_rectangle_set_color_index (self , mp_obj_get_int (color_index ));
124+ return mp_const_none ;
125+ }
126+ MP_DEFINE_CONST_FUN_OBJ_2 (vectorio_rectangle_set_color_index_obj , vectorio_rectangle_obj_set_color_index );
127+
128+ const mp_obj_property_t vectorio_rectangle_color_index_obj = {
129+ .base .type = & mp_type_property ,
130+ .proxy = {(mp_obj_t )& vectorio_rectangle_get_color_index_obj ,
131+ (mp_obj_t )& vectorio_rectangle_set_color_index_obj ,
132+ MP_ROM_NONE },
133+ };
134+
109135// Documentation for properties inherited from VectorShape.
110136
111137//| x : int
@@ -127,6 +153,7 @@ STATIC const mp_rom_map_elem_t vectorio_rectangle_locals_dict_table[] = {
127153 // Properties
128154 { MP_ROM_QSTR (MP_QSTR_x ), MP_ROM_PTR (& vectorio_vector_shape_x_obj ) },
129155 { MP_ROM_QSTR (MP_QSTR_y ), MP_ROM_PTR (& vectorio_vector_shape_y_obj ) },
156+ { MP_ROM_QSTR (MP_QSTR_color_index ), MP_ROM_PTR (& vectorio_rectangle_color_index_obj ) },
130157 { MP_ROM_QSTR (MP_QSTR_width ), MP_ROM_PTR (& vectorio_rectangle_width_obj ) },
131158 { MP_ROM_QSTR (MP_QSTR_height ), MP_ROM_PTR (& vectorio_rectangle_height_obj ) },
132159 { MP_ROM_QSTR (MP_QSTR_location ), MP_ROM_PTR (& vectorio_vector_shape_location_obj ) },
0 commit comments