-
Notifications
You must be signed in to change notification settings - Fork 0
/
pixel_dual.h
157 lines (89 loc) · 2.59 KB
/
pixel_dual.h
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#ifndef __PIXEL_DUAL_H__
#define __PIXEL_DUAL_H__
#include "pixel_array.h"
class pixelDual {
public:
pixelDual(uint16_t led_width, uint16_t led_height, pixelArray *left, pixelArray *right)
: grid_width( led_width),
grid_height(led_height),
grid_total( led_width*led_height),
grid_left(left),
grid_right(right) {}
int16_t index(int8_t x, int8_t y) const {
if (x >= half()) {
return grid_right->index(x-half(), y) + total();
} else {
return grid_left->index(x, y);
}
}
INLINE void setPixelColor(uint16_t pos, color_t color) {
if (pos >= total()) return;
color_t *grid = grid_left->getPixels();
grid[pos] = color;
}
INLINE color_t getPixelColor(uint16_t pos) const {
if (pos >= total()) return color_t::black();
color_t *grid = grid_left->getPixels();
return grid[pos];
}
INLINE void draw(int8_t x, int8_t y) {
if (x >= half()) {
grid_right->draw(x-half(), y);
} else {
grid_left->draw(x, y);
}
}
INLINE void draw(int8_t x, int8_t y, color_t color) {
if (x >= half()) {
grid_right->draw(x-half(), y, color);
} else {
grid_left->draw(x, y, color);
}
}
INLINE void draw_clone(int8_t x, int8_t y) {
grid_left->draw(x, y);
grid_right->draw(x, y);
}
INLINE void draw_clone(int8_t x, int8_t y, color_t color) {
grid_left->draw(x, y, color);
grid_right->draw(x, y, color);
}
INLINE void draw_mirror(int8_t x, int8_t y) {
grid_left->draw(x, y);
grid_right->draw(half()-x-1, y);
}
INLINE void draw_mirror(int8_t x, int8_t y, color_t color) {
grid_left->draw(x, y, color);
grid_right->draw(half()-x-1, y, color);
}
INLINE color_t read(int8_t x, int8_t y) const {
if (x >= half()) {
return grid_right->read(x-half(), y);
} else {
return grid_left->read(x, y);
}
}
color_t swap(int8_t x, int8_t y, color_t color);
INLINE void symbol(uint8_t c, int8_t x, int8_t y, color_t color) {
const char z[2] = {c, 0};
string(z, x, y, color);
}
INLINE void clear() {
grid_left->clear();
grid_right->clear();
}
void string(const char *text, int16_t x_offset, int16_t y_offset);
void string(const char *text, int16_t x_offset, int16_t y_offset, color_t color);
INLINE uint16_t half() const { return grid_width >> 1; }
INLINE uint16_t width() const { return grid_width; }
INLINE uint16_t height() const { return grid_height; }
INLINE uint16_t total() const { return grid_total; }
protected:
const uint16_t grid_width;
const uint16_t grid_height;
const uint16_t grid_total;
pixelArray *grid_left;
pixelArray *grid_right;
};
extern pixelDual *dual;
#endif //__PIXEL_DUAL_H__