blob: 2ec11fe1bbf4883715f1f59b529337a6e7679aa5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
#include "shared-bindings/vectorio/Circle.h"
#include "shared-module/vectorio/__init__.h"
#include "shared-module/displayio/area.h"
#include "py/runtime.h"
#include "stdlib.h"
void common_hal_vectorio_circle_construct(vectorio_circle_t *self, uint16_t radius, uint16_t color_index) {
self->radius = radius;
self->on_dirty.obj = NULL;
self->color_index = color_index + 1;
}
void common_hal_vectorio_circle_set_on_dirty(vectorio_circle_t *self, vectorio_event_t on_dirty) {
if (self->on_dirty.obj != NULL) {
mp_raise_TypeError(translate("circle can only be registered in one parent"));
}
self->on_dirty = on_dirty;
}
uint32_t common_hal_vectorio_circle_get_pixel(void *obj, int16_t x, int16_t y) {
vectorio_circle_t *self = obj;
int16_t radius = abs(self->radius);
x = abs(x);
y = abs(y);
if (x + y <= radius) {
return self->color_index;
}
if (x > radius) {
return 0;
}
if (y > radius) {
return 0;
}
const bool pythagorasSmallerThanRadius = (int32_t)x * x + (int32_t)y * y <= (int32_t)radius * radius;
return pythagorasSmallerThanRadius ? self->color_index : 0;
}
void common_hal_vectorio_circle_get_area(void *circle, displayio_area_t *out_area) {
vectorio_circle_t *self = circle;
out_area->x1 = -1 * self->radius - 1;
out_area->y1 = -1 * self->radius - 1;
out_area->x2 = self->radius + 1;
out_area->y2 = self->radius + 1;
}
int16_t common_hal_vectorio_circle_get_radius(void *obj) {
vectorio_circle_t *self = obj;
return self->radius;
}
void common_hal_vectorio_circle_set_radius(void *obj, int16_t radius) {
vectorio_circle_t *self = obj;
self->radius = abs(radius);
if (self->on_dirty.obj != NULL) {
self->on_dirty.event(self->on_dirty.obj);
}
}
uint16_t common_hal_vectorio_circle_get_color_index(void *obj) {
vectorio_circle_t *self = obj;
return self->color_index - 1;
}
void common_hal_vectorio_circle_set_color_index(void *obj, uint16_t color_index) {
vectorio_circle_t *self = obj;
self->color_index = abs(color_index + 1);
if (self->on_dirty.obj != NULL) {
self->on_dirty.event(self->on_dirty.obj);
}
}
mp_obj_t common_hal_vectorio_circle_get_draw_protocol(void *circle) {
vectorio_circle_t *self = circle;
return self->draw_protocol_instance;
}
|