2021-12-12 22:50:00 -05:00
|
|
|
#include "shared-module/vectorio/__init__.h"
|
2020-05-02 05:21:35 -04:00
|
|
|
#include "shared-bindings/vectorio/Rectangle.h"
|
|
|
|
#include "shared-module/displayio/area.h"
|
|
|
|
|
|
|
|
#include "py/runtime.h"
|
2021-12-12 22:50:00 -05:00
|
|
|
#include "stdlib.h"
|
2020-05-02 05:21:35 -04:00
|
|
|
|
|
|
|
|
2022-03-19 12:30:37 -04:00
|
|
|
void common_hal_vectorio_rectangle_construct(vectorio_rectangle_t *self, uint32_t width, uint32_t height, uint16_t color_index) {
|
2020-05-02 05:21:35 -04:00
|
|
|
self->width = width;
|
|
|
|
self->height = height;
|
2022-03-19 12:30:37 -04:00
|
|
|
self->color_index = color_index + 1;
|
2020-05-02 05:21:35 -04:00
|
|
|
}
|
|
|
|
|
2021-12-12 22:50:00 -05:00
|
|
|
void common_hal_vectorio_rectangle_set_on_dirty(vectorio_rectangle_t *self, vectorio_event_t on_dirty) {
|
|
|
|
if (self->on_dirty.obj != NULL) {
|
2023-10-30 04:49:06 -04:00
|
|
|
mp_raise_TypeError(MP_ERROR_TEXT("can only have one parent"));
|
2021-12-12 22:50:00 -05:00
|
|
|
}
|
|
|
|
self->on_dirty = on_dirty;
|
|
|
|
}
|
2020-05-02 05:21:35 -04:00
|
|
|
|
|
|
|
uint32_t common_hal_vectorio_rectangle_get_pixel(void *obj, int16_t x, int16_t y) {
|
|
|
|
vectorio_rectangle_t *self = obj;
|
2021-08-02 23:38:37 -04:00
|
|
|
if (x >= 0 && y >= 0 && x < self->width && y < self->height) {
|
2022-03-19 12:30:37 -04:00
|
|
|
return self->color_index;
|
2020-05-02 05:21:35 -04:00
|
|
|
}
|
2021-08-01 16:01:57 -04:00
|
|
|
return 0;
|
2020-05-02 05:21:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void common_hal_vectorio_rectangle_get_area(void *rectangle, displayio_area_t *out_area) {
|
|
|
|
vectorio_rectangle_t *self = rectangle;
|
2021-03-25 10:36:40 -04:00
|
|
|
out_area->x1 = 0;
|
|
|
|
out_area->y1 = 0;
|
2020-05-02 05:21:35 -04:00
|
|
|
out_area->x2 = self->width;
|
|
|
|
out_area->y2 = self->height;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-01 16:01:57 -04:00
|
|
|
mp_obj_t common_hal_vectorio_rectangle_get_draw_protocol(void *rectangle) {
|
|
|
|
vectorio_rectangle_t *self = rectangle;
|
|
|
|
return self->draw_protocol_instance;
|
|
|
|
}
|
2021-12-12 22:50:00 -05:00
|
|
|
|
|
|
|
int16_t common_hal_vectorio_rectangle_get_width(void *obj) {
|
|
|
|
vectorio_rectangle_t *self = obj;
|
|
|
|
return self->width;
|
|
|
|
}
|
|
|
|
|
|
|
|
void common_hal_vectorio_rectangle_set_width(void *obj, int16_t width) {
|
|
|
|
vectorio_rectangle_t *self = obj;
|
|
|
|
self->width = abs(width);
|
|
|
|
if (self->on_dirty.obj != NULL) {
|
|
|
|
self->on_dirty.event(self->on_dirty.obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int16_t common_hal_vectorio_rectangle_get_height(void *obj) {
|
|
|
|
vectorio_rectangle_t *self = obj;
|
|
|
|
return self->height;
|
|
|
|
}
|
|
|
|
|
|
|
|
void common_hal_vectorio_rectangle_set_height(void *obj, int16_t height) {
|
|
|
|
vectorio_rectangle_t *self = obj;
|
|
|
|
self->height = abs(height);
|
|
|
|
if (self->on_dirty.obj != NULL) {
|
|
|
|
self->on_dirty.event(self->on_dirty.obj);
|
|
|
|
}
|
|
|
|
}
|
2022-03-18 19:28:29 -04:00
|
|
|
|
2022-03-19 12:30:37 -04:00
|
|
|
uint16_t common_hal_vectorio_rectangle_get_color_index(void *obj) {
|
2022-03-18 19:28:29 -04:00
|
|
|
vectorio_rectangle_t *self = obj;
|
2022-03-19 12:30:37 -04:00
|
|
|
return self->color_index - 1;
|
2022-03-18 19:28:29 -04:00
|
|
|
}
|
|
|
|
|
2022-03-19 12:30:37 -04:00
|
|
|
void common_hal_vectorio_rectangle_set_color_index(void *obj, uint16_t color_index) {
|
2022-03-18 19:28:29 -04:00
|
|
|
vectorio_rectangle_t *self = obj;
|
2022-03-19 12:30:37 -04:00
|
|
|
self->color_index = abs(color_index + 1);
|
2022-03-18 19:28:29 -04:00
|
|
|
if (self->on_dirty.obj != NULL) {
|
|
|
|
self->on_dirty.event(self->on_dirty.obj);
|
|
|
|
}
|
|
|
|
}
|