ESPHome 2026.12.0-dev
Loading...
Searching...
No Matches
display.cpp
Go to the documentation of this file.
1#include "display.h"
2#include <cmath>
3#include <utility>
4#include <numbers>
7#include "esphome/core/hal.h"
9#include "esphome/core/log.h"
10
12ESPHOME_LOG_TAG(TAG, "display");
13
14// COLOR_OFF and COLOR_ON are now inline constexpr in display.h
15
16void Display::fill(Color color) { this->filled_rectangle(0, 0, this->get_width(), this->get_height(), color); }
17void Display::clear() { this->fill(COLOR_OFF); }
18
19void HOT Display::line(int x1, int y1, int x2, int y2, Color color) {
20 const int32_t dx = abs(x2 - x1), sx = x1 < x2 ? 1 : -1;
21 const int32_t dy = -abs(y2 - y1), sy = y1 < y2 ? 1 : -1;
22 int32_t err = dx + dy;
23
24 while (true) {
25 this->draw_pixel_at(x1, y1, color);
26 if (x1 == x2 && y1 == y2)
27 break;
28 int32_t e2 = 2 * err;
29 if (e2 >= dy) {
30 err += dy;
31 x1 += sx;
32 }
33 if (e2 <= dx) {
34 err += dx;
35 y1 += sy;
36 }
37 }
38}
39
40void Display::line_at_angle(int x, int y, int angle, int length, Color color) {
41 this->line_at_angle(x, y, angle, 0, length, color);
42}
43
44void Display::line_at_angle(int x, int y, int angle, int start_radius, int stop_radius, Color color) {
45 // Calculate start and end points
46 int x1 = (start_radius * std::cos(angle * std::numbers::pi_v<float> / 180)) + x;
47 int y1 = (start_radius * std::sin(angle * std::numbers::pi_v<float> / 180)) + y;
48 int x2 = (stop_radius * std::cos(angle * std::numbers::pi_v<float> / 180)) + x;
49 int y2 = (stop_radius * std::sin(angle * std::numbers::pi_v<float> / 180)) + y;
50
51 // Draw line
52 this->line(x1, y1, x2, y2, color);
53}
54
55// flatten keeps to_color() inlined in the pixel loop; in PSRAM builds GCC at
56// -Os stops inlining it once there are two call sites, which costs a call and
57// spills per pixel. Without PSRAM there is one call site and it changes
58// nothing, and draw_pixel_at() stays a virtual call either way.
59// HIGH_BYTE_FIRST (big endian) only matters for 565; as a template argument its test leaves the pixel loop.
60template<ColorBitness BITNESS, bool HIGH_BYTE_FIRST = false>
61static void __attribute__((flatten)) draw_packed_pixels(Display *display, int x_start, int y_start, int w, int h,
62 const uint8_t *ptr, int x_offset, int y_offset, int x_pad) {
63 const size_t line_stride = x_offset + w + x_pad; // length of each source line in pixels
64 // BITNESS is a constant here, so to_color()'s three per pixel divisions
65 // become a multiply and shift and its bitness switch folds.
66 const auto draw_source_pixel = [&](int x, int y, size_t source_idx) ESPHOME_ALWAYS_INLINE {
67 display->draw_pixel_at(
68 x + x_start, y + y_start,
69 ColorUtil::to_color(ColorUtil::read_packed<BITNESS>(ptr, source_idx, HIGH_BYTE_FIRST), BITNESS));
70 };
71 // The source and frame buffers are row-major, so walking rows keeps the read
72 // and the write sequential. When the display swaps the axes before writing,
73 // walking columns keeps the write sequential instead; with the frame buffer
74 // in PSRAM a strided write costs more than a strided read.
75#ifdef USE_PSRAM
76 if (display->pixel_axes_swapped()) {
77 size_t column_idx = y_offset * line_stride + x_offset;
78 for (int x = 0; x != w; x++, column_idx++) {
79 size_t source_idx = column_idx;
80 for (int y = 0; y != h; y++, source_idx += line_stride) {
81 draw_source_pixel(x, y, source_idx);
82 }
83 }
84 return;
85 }
86#endif
87 // Row walk: builds without PSRAM, and PSRAM builds whose axes are not swapped.
88 for (int y = 0; y != h; y++) {
89 size_t source_idx = (y_offset + y) * line_stride + x_offset;
90 for (int x = 0; x != w; x++, source_idx++) {
91 draw_source_pixel(x, y, source_idx);
92 }
93 }
94}
95
96// Remove before 2027.5.0. Draws a block in the deprecated BGR or GRB order, pixel by pixel. Not inlined, so
97// the RGB loops above compile as tightly as before.
98static void __attribute__((noinline)) draw_ordered_pixels(Display *display, int x_start, int y_start, int w, int h,
100 bool big_endian, int x_offset, int y_offset, int x_pad) {
101 const size_t line_stride = x_offset + w + x_pad;
102 for (int y = 0; y != h; y++) {
103 size_t source_idx = (y_offset + y) * line_stride + x_offset;
104 for (int x = 0; x != w; x++, source_idx++) {
105 uint32_t code;
106 if (bitness == COLOR_BITNESS_565) {
108 } else if (bitness == COLOR_BITNESS_888) {
110 } else {
112 }
113 display->draw_pixel_at(x + x_start, y + y_start, apply_color_order(ColorUtil::to_color(code, bitness), order));
114 }
115 }
116}
117
118void Display::draw_pixels_internal(int x_start, int y_start, int w, int h, const uint8_t *ptr, ColorBitness bitness,
119 bool big_endian, int x_offset, int y_offset, int x_pad) {
120 // Through the deprecated form, so a driver that still overrides only that one keeps its fast path.
121 // Remove before 2027.5.0, when the per pixel drawing below moves here.
122#pragma GCC diagnostic push
123#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
125#pragma GCC diagnostic pop
126}
127
128// Must not call draw_pixels_at() without a color order or draw_pixels_internal(): those call this, and a legacy
129// override's fallback ends up here.
130void Display::draw_pixels_at(int x_start, int y_start, int w, int h, const uint8_t *ptr, ColorOrder order,
131 ColorBitness bitness, bool big_endian, int x_offset, int y_offset, int x_pad) {
132 if (order != COLOR_ORDER_RGB) {
133 draw_ordered_pixels(this, x_start, y_start, w, h, ptr, order, bitness, big_endian, x_offset, y_offset, x_pad);
134 return;
135 }
136 switch (bitness) {
138 if (big_endian) {
139 draw_packed_pixels<COLOR_BITNESS_565, true>(this, x_start, y_start, w, h, ptr, x_offset, y_offset, x_pad);
140 } else {
141 draw_packed_pixels<COLOR_BITNESS_565, false>(this, x_start, y_start, w, h, ptr, x_offset, y_offset, x_pad);
142 }
143 break;
145 draw_packed_pixels<COLOR_BITNESS_888>(this, x_start, y_start, w, h, ptr, x_offset, y_offset, x_pad);
146 break;
147 default:
148 draw_packed_pixels<COLOR_BITNESS_332>(this, x_start, y_start, w, h, ptr, x_offset, y_offset, x_pad);
149 break;
150 }
151}
152
153void HOT Display::horizontal_line(int x, int y, int width, Color color) {
154 // Future: Could be made more efficient by manipulating buffer directly in certain rotations.
155 for (int i = x; i < x + width; i++)
156 this->draw_pixel_at(i, y, color);
157}
158
159void HOT Display::vertical_line(int x, int y, int height, Color color) {
160 // Future: Could be made more efficient by manipulating buffer directly in certain rotations.
161 for (int i = y; i < y + height; i++)
162 this->draw_pixel_at(x, i, color);
163}
164
165void Display::rectangle(int x1, int y1, int width, int height, Color color) {
166 this->horizontal_line(x1, y1, width, color);
167 this->horizontal_line(x1, y1 + height - 1, width, color);
168 this->vertical_line(x1, y1, height, color);
169 this->vertical_line(x1 + width - 1, y1, height, color);
170}
171
172void Display::filled_rectangle(int x1, int y1, int width, int height, Color color) {
173 // Future: Use vertical_line and horizontal_line methods depending on rotation to reduce memory accesses.
174 for (int i = y1; i < y1 + height; i++) {
175 this->horizontal_line(x1, i, width, color);
176 }
177}
178
179void HOT Display::circle(int center_x, int center_xy, int radius, Color color) {
180 int dx = -radius;
181 int dy = 0;
182 int err = 2 - 2 * radius;
183 int e2;
184
185 do {
186 this->draw_pixel_at(center_x - dx, center_xy + dy, color);
187 this->draw_pixel_at(center_x + dx, center_xy + dy, color);
188 this->draw_pixel_at(center_x + dx, center_xy - dy, color);
189 this->draw_pixel_at(center_x - dx, center_xy - dy, color);
190 e2 = err;
191 if (e2 < dy) {
192 err += ++dy * 2 + 1;
193 if (-dx == dy && e2 <= dx) {
194 e2 = 0;
195 }
196 }
197 if (e2 > dx) {
198 err += ++dx * 2 + 1;
199 }
200 } while (dx <= 0);
201}
202
203void Display::filled_circle(int center_x, int center_y, int radius, Color color) {
204 int dx = -int32_t(radius);
205 int dy = 0;
206 int err = 2 - 2 * radius;
207 int e2;
208
209 do {
210 this->draw_pixel_at(center_x - dx, center_y + dy, color);
211 this->draw_pixel_at(center_x + dx, center_y + dy, color);
212 this->draw_pixel_at(center_x + dx, center_y - dy, color);
213 this->draw_pixel_at(center_x - dx, center_y - dy, color);
214 int hline_width = 2 * (-dx) + 1;
215 this->horizontal_line(center_x + dx, center_y + dy, hline_width, color);
216 this->horizontal_line(center_x + dx, center_y - dy, hline_width, color);
217 e2 = err;
218 if (e2 < dy) {
219 err += ++dy * 2 + 1;
220 if (-dx == dy && e2 <= dx) {
221 e2 = 0;
222 }
223 }
224 if (e2 > dx) {
225 err += ++dx * 2 + 1;
226 }
227 } while (dx <= 0);
228}
229
230void Display::filled_ring(int center_x, int center_y, int radius1, int radius2, Color color) {
231 int rmax = radius1 > radius2 ? radius1 : radius2;
232 int rmin = radius1 < radius2 ? radius1 : radius2;
233 int dxmax = -int32_t(rmax), dxmin = -int32_t(rmin);
234 int dymax = 0, dymin = 0;
235 int errmax = 2 - 2 * rmax, errmin = 2 - 2 * rmin;
236 int e2max, e2min;
237 do {
238 // 8 dots for borders
239 this->draw_pixel_at(center_x - dxmax, center_y + dymax, color);
240 this->draw_pixel_at(center_x + dxmax, center_y + dymax, color);
241 this->draw_pixel_at(center_x - dxmin, center_y + dymin, color);
242 this->draw_pixel_at(center_x + dxmin, center_y + dymin, color);
243 this->draw_pixel_at(center_x + dxmax, center_y - dymax, color);
244 this->draw_pixel_at(center_x - dxmax, center_y - dymax, color);
245 this->draw_pixel_at(center_x + dxmin, center_y - dymin, color);
246 this->draw_pixel_at(center_x - dxmin, center_y - dymin, color);
247 if (dymin < rmin) {
248 // two parts - four lines
249 int hline_width = -(dxmax - dxmin) + 1;
250 this->horizontal_line(center_x + dxmax, center_y + dymax, hline_width, color);
251 this->horizontal_line(center_x - dxmin, center_y + dymax, hline_width, color);
252 this->horizontal_line(center_x + dxmax, center_y - dymax, hline_width, color);
253 this->horizontal_line(center_x - dxmin, center_y - dymax, hline_width, color);
254 } else {
255 // one part - top and bottom
256 int hline_width = 2 * (-dxmax) + 1;
257 this->horizontal_line(center_x + dxmax, center_y + dymax, hline_width, color);
258 this->horizontal_line(center_x + dxmax, center_y - dymax, hline_width, color);
259 }
260 e2max = errmax;
261 // tune external
262 if (e2max < dymax) {
263 errmax += ++dymax * 2 + 1;
264 if (-dxmax == dymax && e2max <= dxmax) {
265 e2max = 0;
266 }
267 }
268 if (e2max > dxmax) {
269 errmax += ++dxmax * 2 + 1;
270 }
271 // tune internal
272 while (dymin < dymax && dymin < rmin) {
273 e2min = errmin;
274 if (e2min < dymin) {
275 errmin += ++dymin * 2 + 1;
276 if (-dxmin == dymin && e2min <= dxmin) {
277 e2min = 0;
278 }
279 }
280 if (e2min > dxmin) {
281 errmin += ++dxmin * 2 + 1;
282 }
283 }
284 } while (dxmax <= 0);
285}
286
287void Display::filled_gauge(int center_x, int center_y, int radius1, int radius2, int progress, Color color) {
288 int rmax = radius1 > radius2 ? radius1 : radius2;
289 int rmin = radius1 < radius2 ? radius1 : radius2;
290 int dxmax = -int32_t(rmax), dxmin = -int32_t(rmin), upd_dxmax, upd_dxmin;
291 int dymax = 0, dymin = 0;
292 int errmax = 2 - 2 * rmax, errmin = 2 - 2 * rmin;
293 int e2max, e2min;
294 progress = std::max(0, std::min(progress, 100)); // 0..100
295 int draw_progress = progress > 50 ? (100 - progress) : progress;
296 float tan_a = (progress == 50) ? 65535 : tanf(float(draw_progress) * std::numbers::pi_v<float> / 100); // slope
297
298 do {
299 // outer dots
300 this->draw_pixel_at(center_x + dxmax, center_y - dymax, color);
301 this->draw_pixel_at(center_x - dxmax, center_y - dymax, color);
302 if (dymin < rmin) {
303 // side parts
304 int lhline_width = -(dxmax - dxmin) + 1;
305 if (progress >= 50) {
306 upd_dxmax = float(dymax) < float(-dxmax) * tan_a ? std::ceil(float(dymax) / tan_a) : -dxmax;
307 this->horizontal_line(center_x + dxmax, center_y - dymax, lhline_width, color); // left
308 if (!dymax)
309 this->horizontal_line(center_x - dxmin, center_y, lhline_width, color); // right horizontal border
310 if (upd_dxmax > -dxmin) {
311 // right
312 int rhline_width = (upd_dxmax + dxmin) + 1;
313 this->horizontal_line(center_x - dxmin, center_y - dymax,
314 rhline_width > lhline_width ? lhline_width : rhline_width, color);
315 }
316 } else {
317 upd_dxmin = float(dymin) > float(-dxmin) * tan_a ? std::ceil(float(dymin) / tan_a) : -dxmin;
318 lhline_width = -(dxmax + upd_dxmin) + 1;
319 if (!dymax)
320 this->horizontal_line(center_x - dxmin, center_y, lhline_width, color); // right horizontal border
321 if (lhline_width > 0)
322 this->horizontal_line(center_x + dxmax, center_y - dymax, lhline_width, color);
323 }
324 } else {
325 // top part
326 int hline_width = 2 * (-dxmax) + 1;
327 if (progress >= 50) {
328 if (dymax < float(-dxmax) * tan_a) {
329 upd_dxmax = std::ceil(float(dymax) / tan_a);
330 hline_width = -dxmax + upd_dxmax + 1;
331 }
332 } else {
333 if (dymax < float(-dxmax) * tan_a) {
334 upd_dxmax = std::ceil(float(dymax) / tan_a);
335 hline_width = -dxmax - upd_dxmax + 1;
336 } else {
337 hline_width = 0;
338 }
339 }
340 if (hline_width > 0)
341 this->horizontal_line(center_x + dxmax, center_y - dymax, hline_width, color);
342 }
343 e2max = errmax;
344 if (e2max < dymax) {
345 errmax += ++dymax * 2 + 1;
346 if (-dxmax == dymax && e2max <= dxmax) {
347 e2max = 0;
348 }
349 }
350 if (e2max > dxmax) {
351 errmax += ++dxmax * 2 + 1;
352 }
353 while (dymin <= dymax && dymin <= rmin && dxmin <= 0) {
354 this->draw_pixel_at(center_x + dxmin, center_y - dymin, color);
355 this->draw_pixel_at(center_x - dxmin, center_y - dymin, color);
356 e2min = errmin;
357 if (e2min < dymin) {
358 errmin += ++dymin * 2 + 1;
359 if (-dxmin == dymin && e2min <= dxmin) {
360 e2min = 0;
361 }
362 }
363 if (e2min > dxmin) {
364 errmin += ++dxmin * 2 + 1;
365 }
366 }
367 } while (dxmax <= 0);
368}
369
370void HOT Display::triangle(int x1, int y1, int x2, int y2, int x3, int y3, Color color) {
371 this->line(x1, y1, x2, y2, color);
372 this->line(x1, y1, x3, y3, color);
373 this->line(x2, y2, x3, y3, color);
374}
375
376void Display::sort_triangle_points_by_y_(int *x1, int *y1, int *x2, int *y2, int *x3, int *y3) {
377 if (*y1 > *y2) {
378 int x_temp = *x1, y_temp = *y1;
379 *x1 = *x2, *y1 = *y2;
380 *x2 = x_temp, *y2 = y_temp;
381 }
382 if (*y1 > *y3) {
383 int x_temp = *x1, y_temp = *y1;
384 *x1 = *x3, *y1 = *y3;
385 *x3 = x_temp, *y3 = y_temp;
386 }
387 if (*y2 > *y3) {
388 int x_temp = *x2, y_temp = *y2;
389 *x2 = *x3, *y2 = *y3;
390 *x3 = x_temp, *y3 = y_temp;
391 }
392}
393
394void Display::filled_flat_side_triangle_(int x1, int y1, int x2, int y2, int x3, int y3, Color color) {
395 // y2 must be equal to y3 (same horizontal line)
396
397 // Initialize Bresenham's algorithm for side 1
398 int s1_current_x = x1;
399 int s1_current_y = y1;
400 bool s1_axis_swap = false;
401 int s1_dx = abs(x2 - x1);
402 int s1_dy = abs(y2 - y1);
403 int s1_sign_x = ((x2 - x1) >= 0) ? 1 : -1;
404 int s1_sign_y = ((y2 - y1) >= 0) ? 1 : -1;
405 if (s1_dy > s1_dx) {
406 // swap values
407 int tmp = s1_dx;
408 s1_dx = s1_dy;
409 s1_dy = tmp;
410 s1_axis_swap = true;
411 }
412 int s1_error = 2 * s1_dy - s1_dx;
413
414 // Initialize Bresenham's algorithm for side 2
415 int s2_current_x = x1;
416 int s2_current_y = y1;
417 bool s2_axis_swap = false;
418 int s2_dx = abs(x3 - x1);
419 int s2_dy = abs(y3 - y1);
420 int s2_sign_x = ((x3 - x1) >= 0) ? 1 : -1;
421 int s2_sign_y = ((y3 - y1) >= 0) ? 1 : -1;
422 if (s2_dy > s2_dx) {
423 // swap values
424 int tmp = s2_dx;
425 s2_dx = s2_dy;
426 s2_dy = tmp;
427 s2_axis_swap = true;
428 }
429 int s2_error = 2 * s2_dy - s2_dx;
430
431 // Iterate on side 1 and allow side 2 to be processed to match the advance of the y-axis.
432 for (int i = 0; i <= s1_dx; i++) {
433 if (s1_current_x <= s2_current_x) {
434 this->horizontal_line(s1_current_x, s1_current_y, s2_current_x - s1_current_x + 1, color);
435 } else {
436 this->horizontal_line(s2_current_x, s2_current_y, s1_current_x - s2_current_x + 1, color);
437 }
438
439 // Bresenham's #1
440 // Side 1 s1_current_x and s1_current_y calculation
441 while (s1_error >= 0) {
442 if (s1_axis_swap) {
443 s1_current_x += s1_sign_x;
444 } else {
445 s1_current_y += s1_sign_y;
446 }
447 s1_error = s1_error - 2 * s1_dx;
448 }
449 if (s1_axis_swap) {
450 s1_current_y += s1_sign_y;
451 } else {
452 s1_current_x += s1_sign_x;
453 }
454 s1_error = s1_error + 2 * s1_dy;
455
456 // Bresenham's #2
457 // Side 2 s2_current_x and s2_current_y calculation
458 while (s2_current_y != s1_current_y) {
459 while (s2_error >= 0) {
460 if (s2_axis_swap) {
461 s2_current_x += s2_sign_x;
462 } else {
463 s2_current_y += s2_sign_y;
464 }
465 s2_error = s2_error - 2 * s2_dx;
466 }
467 if (s2_axis_swap) {
468 s2_current_y += s2_sign_y;
469 } else {
470 s2_current_x += s2_sign_x;
471 }
472 s2_error = s2_error + 2 * s2_dy;
473 }
474 }
475}
476
477void Display::filled_triangle(int x1, int y1, int x2, int y2, int x3, int y3, Color color) {
478 // Sort the three points by y-coordinate ascending, so [x1,y1] is the topmost point
479 this->sort_triangle_points_by_y_(&x1, &y1, &x2, &y2, &x3, &y3);
480
481 if (y2 == y3) {
482 // Check for special case of a bottom-flat triangle
483 this->filled_flat_side_triangle_(x1, y1, x2, y2, x3, y3, color);
484 } else if (y1 == y2) {
485 // Check for special case of a top-flat triangle
486 this->filled_flat_side_triangle_(x3, y3, x1, y1, x2, y2, color);
487 } else {
488 // General case: split the no-flat-side triangle in a top-flat triangle and bottom-flat triangle
489 int x_temp = (int) (x1 + ((float) (y2 - y1) / (float) (y3 - y1)) * (x3 - x1)), y_temp = y2;
490 this->filled_flat_side_triangle_(x1, y1, x2, y2, x_temp, y_temp, color);
491 this->filled_flat_side_triangle_(x3, y3, x2, y2, x_temp, y_temp, color);
492 }
493}
494
495void HOT Display::get_regular_polygon_vertex(int vertex_id, int *vertex_x, int *vertex_y, int center_x, int center_y,
496 int radius, int edges, RegularPolygonVariation variation,
497 float rotation_degrees) {
498 if (edges >= 2) {
499 // Given the orientation of the display component, an angle is measured clockwise from the x axis.
500 // For a regular polygon, the human reference would be the top of the polygon,
501 // hence we rotate the shape by 270° to orient the polygon up.
502 rotation_degrees += ROTATION_270_DEGREES;
503 // Convert the rotation to radians, easier to use in trigonometrical calculations
504 float rotation_radians = rotation_degrees * std::numbers::pi_v<float> / 180;
505 // A pointy top variation means the first vertex of the polygon is at the top center of the shape, this requires no
506 // additional rotation of the shape.
507 // A flat top variation means the first point of the polygon has to be rotated so that the first edge is horizontal,
508 // this requires to rotate the shape by π/edges radians counter-clockwise so that the first point is located on the
509 // left side of the first horizontal edge.
510 rotation_radians -= (variation == VARIATION_FLAT_TOP) ? std::numbers::pi_v<float> / edges : 0.0f;
511
512 float vertex_angle = ((float) vertex_id) / edges * 2 * std::numbers::pi_v<float> + rotation_radians;
513 *vertex_x = (int) std::round(std::cos(vertex_angle) * radius) + center_x;
514 *vertex_y = (int) std::round(std::sin(vertex_angle) * radius) + center_y;
515 }
516}
517
518void HOT Display::regular_polygon(int x, int y, int radius, int edges, RegularPolygonVariation variation,
519 float rotation_degrees, Color color, RegularPolygonDrawing drawing) {
520 if (edges >= 2) {
521 int previous_vertex_x, previous_vertex_y;
522 for (int current_vertex_id = 0; current_vertex_id <= edges; current_vertex_id++) {
523 int current_vertex_x, current_vertex_y;
524 get_regular_polygon_vertex(current_vertex_id, &current_vertex_x, &current_vertex_y, x, y, radius, edges,
525 variation, rotation_degrees);
526 if (current_vertex_id > 0) {
527 // Start drawing after the 2nd vertex coordinates has been calculated
528 if (drawing == DRAWING_FILLED) {
529 this->filled_triangle(x, y, previous_vertex_x, previous_vertex_y, current_vertex_x, current_vertex_y, color);
530 } else if (drawing == DRAWING_OUTLINE) {
531 this->line(previous_vertex_x, previous_vertex_y, current_vertex_x, current_vertex_y, color);
532 }
533 }
534 previous_vertex_x = current_vertex_x;
535 previous_vertex_y = current_vertex_y;
536 }
537 }
538}
539
540void HOT Display::regular_polygon(int x, int y, int radius, int edges, RegularPolygonVariation variation, Color color,
541 RegularPolygonDrawing drawing) {
542 regular_polygon(x, y, radius, edges, variation, ROTATION_0_DEGREES, color, drawing);
543}
544
545void HOT Display::regular_polygon(int x, int y, int radius, int edges, Color color, RegularPolygonDrawing drawing) {
546 regular_polygon(x, y, radius, edges, VARIATION_POINTY_TOP, ROTATION_0_DEGREES, color, drawing);
547}
548
549void Display::filled_regular_polygon(int x, int y, int radius, int edges, RegularPolygonVariation variation,
550 float rotation_degrees, Color color) {
551 regular_polygon(x, y, radius, edges, variation, rotation_degrees, color, DRAWING_FILLED);
552}
553
554void Display::filled_regular_polygon(int x, int y, int radius, int edges, RegularPolygonVariation variation,
555 Color color) {
556 regular_polygon(x, y, radius, edges, variation, ROTATION_0_DEGREES, color, DRAWING_FILLED);
557}
558
559void Display::filled_regular_polygon(int x, int y, int radius, int edges, Color color) {
561}
562
563void Display::print(int x, int y, BaseFont *font, Color color, TextAlign align, const char *text, Color background) {
564 int x_start, y_start;
565 int width, height;
566 this->get_text_bounds(x, y, text, font, align, &x_start, &y_start, &width, &height);
567 font->print(x_start, y_start, this, color, text, background);
568}
569
570void Display::vprintf_(int x, int y, BaseFont *font, Color color, Color background, TextAlign align, const char *format,
571 va_list arg) {
572 char buffer[256];
573 int ret = vsnprintf(buffer, sizeof(buffer), format, arg);
574 if (ret > 0)
575 this->print(x, y, font, color, align, buffer, background);
576}
577
578void Display::image(int x, int y, BaseImage *image, Color color_on, Color color_off) {
579 this->image(x, y, image, ImageAlign::TOP_LEFT, color_on, color_off);
580}
581
582void Display::image(int x, int y, BaseImage *image, ImageAlign align, Color color_on, Color color_off) {
583 auto x_align = ImageAlign(int(align) & (int(ImageAlign::HORIZONTAL_ALIGNMENT)));
584 auto y_align = ImageAlign(int(align) & (int(ImageAlign::VERTICAL_ALIGNMENT)));
585
586 switch (x_align) {
588 x -= image->get_width();
589 break;
591 x -= image->get_width() / 2;
592 break;
593 case ImageAlign::LEFT:
594 default:
595 break;
596 }
597
598 switch (y_align) {
600 y -= image->get_height();
601 break;
603 y -= image->get_height() / 2;
604 break;
605 case ImageAlign::TOP:
606 default:
607 break;
608 }
609
610 image->draw(x, y, this, color_on, color_off);
611}
612
613#ifdef USE_GRAPH
614void Display::graph(int x, int y, graph::Graph *graph, Color color_on) { graph->draw(this, x, y, color_on); }
615void Display::legend(int x, int y, graph::Graph *graph, Color color_on) { graph->draw_legend(this, x, y, color_on); }
616#endif // USE_GRAPH
617
618#ifdef USE_QR_CODE
619void Display::qr_code(int x, int y, qr_code::QrCode *qr_code, Color color_on, int scale) {
620 qr_code->draw(this, x, y, color_on, scale);
621}
622#endif // USE_QR_CODE
623
624#ifdef USE_GRAPHICAL_DISPLAY_MENU
625void Display::menu(int x, int y, graphical_display_menu::GraphicalDisplayMenu *menu, int width, int height) {
626 Rect rect(x, y, width, height);
627 menu->draw(this, &rect);
628}
629#endif // USE_GRAPHICAL_DISPLAY_MENU
630
631void Display::get_text_bounds(int x, int y, const char *text, BaseFont *font, TextAlign align, int *x1, int *y1,
632 int *width, int *height) {
633 int x_offset, baseline;
634 font->measure(text, width, &x_offset, &baseline, height);
635
636 auto x_align = TextAlign(int(align) & 0x18);
637 auto y_align = TextAlign(int(align) & 0x07);
638
639 switch (x_align) {
640 case TextAlign::RIGHT:
641 *x1 = x - *width - x_offset;
642 break;
644 *x1 = x - (*width + x_offset) / 2;
645 break;
646 case TextAlign::LEFT:
647 default:
648 // LEFT
649 *x1 = x;
650 break;
651 }
652
653 switch (y_align) {
655 *y1 = y - *height;
656 break;
658 *y1 = y - baseline;
659 break;
661 *y1 = y - (*height) / 2;
662 break;
663 case TextAlign::TOP:
664 default:
665 *y1 = y;
666 break;
667 }
668}
669
670void Display::print(int x, int y, BaseFont *font, Color color, const char *text, Color background) {
671 this->print(x, y, font, color, TextAlign::TOP_LEFT, text, background);
672}
673
674void Display::print(int x, int y, BaseFont *font, TextAlign align, const char *text) {
675 this->print(x, y, font, COLOR_ON, align, text);
676}
677
678void Display::print(int x, int y, BaseFont *font, const char *text) {
679 this->print(x, y, font, COLOR_ON, TextAlign::TOP_LEFT, text);
680}
681
682void Display::printf(int x, int y, BaseFont *font, Color color, Color background, TextAlign align, const char *format,
683 ...) {
684 va_list arg;
685 va_start(arg, format);
686 this->vprintf_(x, y, font, color, background, align, format, arg);
687 va_end(arg);
688}
689
690void Display::printf(int x, int y, BaseFont *font, Color color, TextAlign align, const char *format, ...) {
691 va_list arg;
692 va_start(arg, format);
693 this->vprintf_(x, y, font, color, COLOR_OFF, align, format, arg);
694 va_end(arg);
695}
696
697void Display::printf(int x, int y, BaseFont *font, Color color, const char *format, ...) {
698 va_list arg;
699 va_start(arg, format);
700 this->vprintf_(x, y, font, color, COLOR_OFF, TextAlign::TOP_LEFT, format, arg);
701 va_end(arg);
702}
703
704void Display::printf(int x, int y, BaseFont *font, TextAlign align, const char *format, ...) {
705 va_list arg;
706 va_start(arg, format);
707 this->vprintf_(x, y, font, COLOR_ON, COLOR_OFF, align, format, arg);
708 va_end(arg);
709}
710
711void Display::printf(int x, int y, BaseFont *font, const char *format, ...) {
712 va_list arg;
713 va_start(arg, format);
714 this->vprintf_(x, y, font, COLOR_ON, COLOR_OFF, TextAlign::TOP_LEFT, format, arg);
715 va_end(arg);
716}
717
718void Display::set_pages(std::vector<DisplayPage *> pages) {
719 if (pages.empty())
720 return;
721
722 for (auto *page : pages)
723 page->set_parent(this);
724
725 for (uint32_t i = 0; i < pages.size() - 1; i++) {
726 pages[i]->set_next(pages[i + 1]);
727 pages[i + 1]->set_prev(pages[i]);
728 }
729 pages[0]->set_prev(pages[pages.size() - 1]);
730 pages[pages.size() - 1]->set_next(pages[0]);
731 this->show_page(pages[0]);
732}
733
735#ifdef DISPLAY_PAGE_CHANGE_CALLBACK_COUNT
736 DisplayPage *previous = this->page_;
737 this->page_ = page;
738 if (previous != page)
739 this->page_change_callback_.call(previous, page);
740#else
741 this->page_ = page;
742#endif
743}
744
746 if (this->auto_clear_enabled_) {
747 this->clear();
748 }
749 if (this->show_test_card_) {
750 this->test_card();
751 } else if (this->page_ != nullptr) {
752 this->page_->get_writer()(*this);
753 } else if (this->writer_.has_value()) {
754 (*this->writer_)(*this);
755 }
756 this->clear_clipping_();
757}
758
759void Display::strftime(int x, int y, BaseFont *font, Color color, Color background, TextAlign align, const char *format,
760 ESPTime time) {
761 char buffer[64];
762 size_t ret = time.strftime(buffer, sizeof(buffer), format);
763 if (ret > 0)
764 this->print(x, y, font, color, align, buffer, background);
765}
766
767void Display::strftime(int x, int y, BaseFont *font, Color color, TextAlign align, const char *format, ESPTime time) {
768 this->strftime(x, y, font, color, COLOR_OFF, align, format, time);
769}
770
771void Display::strftime(int x, int y, BaseFont *font, Color color, const char *format, ESPTime time) {
772 this->strftime(x, y, font, color, COLOR_OFF, TextAlign::TOP_LEFT, format, time);
773}
774
775void Display::strftime(int x, int y, BaseFont *font, TextAlign align, const char *format, ESPTime time) {
776 this->strftime(x, y, font, COLOR_ON, COLOR_OFF, align, format, time);
777}
778
779void Display::strftime(int x, int y, BaseFont *font, const char *format, ESPTime time) {
780 this->strftime(x, y, font, COLOR_ON, COLOR_OFF, TextAlign::TOP_LEFT, format, time);
781}
782
784 if (!this->clipping_rectangle_.empty()) {
785 Rect r = this->clipping_rectangle_.back();
786 rect.shrink(r);
787 }
788 this->clipping_rectangle_.push_back(rect);
789}
790
792 if (this->clipping_rectangle_.empty()) {
793 ESP_LOGE(TAG, "clear: Clipping is not set.");
794 } else {
795 this->clipping_rectangle_.pop_back();
796 }
797}
798
800 if (this->clipping_rectangle_.empty()) {
801 ESP_LOGE(TAG, "add: Clipping is not set.");
802 } else {
803 this->clipping_rectangle_.back().extend(add_rect);
804 }
805}
806
808 if (this->clipping_rectangle_.empty()) {
809 ESP_LOGE(TAG, "add: Clipping is not set.");
810 } else {
811 this->clipping_rectangle_.back().shrink(add_rect);
812 }
813}
814
816 if (this->clipping_rectangle_.empty()) {
817 return Rect();
818 } else {
819 return this->clipping_rectangle_.back();
820 }
821}
822
824
826
827bool Display::clip(int x, int y) {
828 if (x < 0 || x >= this->get_width() || y < 0 || y >= this->get_height())
829 return false;
830 if (this->is_point_clipped(x, y))
831 return false;
832 return true;
833}
834
835bool Display::clamp_x_(int x, int w, int &min_x, int &max_x) {
836 min_x = std::max(x, 0);
837 max_x = std::min(x + w, this->get_width());
838
839 if (!this->clipping_rectangle_.empty()) {
840 const auto &rect = this->clipping_rectangle_.back();
841 if (!rect.is_set())
842 return false;
843
844 min_x = std::max(min_x, (int) rect.x);
845 max_x = std::min(max_x, (int) rect.x2());
846 }
847
848 return min_x < max_x;
849}
850
851bool Display::clamp_y_(int y, int h, int &min_y, int &max_y) {
852 min_y = std::max(y, 0);
853 max_y = std::min(y + h, this->get_height());
854
855 if (!this->clipping_rectangle_.empty()) {
856 const auto &rect = this->clipping_rectangle_.back();
857 if (!rect.is_set())
858 return false;
859
860 min_y = std::max(min_y, (int) rect.y);
861 max_y = std::min(max_y, (int) rect.y2());
862 }
863
864 return min_y < max_y;
865}
866
867constexpr uint8_t TESTCARD_FONT[3][8] PROGMEM = {{0x41, 0x7F, 0x7F, 0x09, 0x19, 0x7F, 0x66, 0x00}, // 'R'
868 {0x1C, 0x3E, 0x63, 0x41, 0x51, 0x73, 0x72, 0x00}, // 'G'
869 {0x41, 0x7F, 0x7F, 0x49, 0x49, 0x7F, 0x36, 0x00}}; // 'B'
870
872 int w = get_width(), h = get_height(), image_w, image_h;
873 this->clear();
874 image_w = std::min(w - 20, 310);
875 image_h = std::min(h - 20, 255);
876 int shift_x = (w - image_w) / 2;
877 int shift_y = (h - image_h) / 2;
878 int line_w = (image_w - 6) / 6;
879 int image_c = image_w / 2;
880 if (this->get_display_type() == DISPLAY_TYPE_COLOR) {
881 Color r(255, 0, 0), g(0, 255, 0), b(0, 0, 255);
882
883 for (auto i = 0; i != image_h; i++) {
884 int c = esp_scale(i, image_h);
885 this->horizontal_line(shift_x + 0, shift_y + i, line_w, r.fade_to_white(c));
886 this->horizontal_line(shift_x + line_w, shift_y + i, line_w, r.fade_to_black(c)); //
887
888 this->horizontal_line(shift_x + image_c - line_w, shift_y + i, line_w, g.fade_to_white(c));
889 this->horizontal_line(shift_x + image_c, shift_y + i, line_w, g.fade_to_black(c));
890
891 this->horizontal_line(shift_x + image_w - (line_w * 2), shift_y + i, line_w, b.fade_to_white(c));
892 this->horizontal_line(shift_x + image_w - line_w, shift_y + i, line_w, b.fade_to_black(c));
893 }
894 }
895 this->rectangle(shift_x, shift_y, image_w, image_h, Color(127, 127, 0));
896
897 uint16_t shift_r = shift_x + line_w - (8 * 3);
898 uint16_t shift_g = shift_x + image_c - (8 * 3);
899 uint16_t shift_b = shift_x + image_w - line_w - (8 * 3);
900 shift_y = h / 2 - (8 * 3);
901 for (auto i = 0; i < 8; i++) {
902 uint8_t ftr = progmem_read_byte(&TESTCARD_FONT[0][i]);
903 uint8_t ftg = progmem_read_byte(&TESTCARD_FONT[1][i]);
904 uint8_t ftb = progmem_read_byte(&TESTCARD_FONT[2][i]);
905 for (auto k = 0; k < 8; k++) {
906 if ((ftr & (1 << k)) != 0) {
907 this->filled_rectangle(shift_r + (i * 6), shift_y + (k * 6), 6, 6, COLOR_OFF);
908 }
909 if ((ftg & (1 << k)) != 0) {
910 this->filled_rectangle(shift_g + (i * 6), shift_y + (k * 6), 6, 6, COLOR_OFF);
911 }
912 if ((ftb & (1 << k)) != 0) {
913 this->filled_rectangle(shift_b + (i * 6), shift_y + (k * 6), 6, 6, COLOR_OFF);
914 }
915 }
916 }
917 this->filled_rectangle(0, 0, 10, 10, Color(255, 0, 255));
918 this->filled_rectangle(w - 10, 0, 10, 10, Color(255, 0, 255));
919 this->filled_rectangle(0, h - 10, 10, 10, Color(255, 0, 255));
920 this->filled_rectangle(w - 10, h - 10, 10, 10, Color(255, 0, 255));
921 this->rectangle(0, 0, w, h, Color(255, 255, 255));
922 this->stop_poller();
923}
924
925DisplayPage::DisplayPage(display_writer_t writer) : writer_(std::move(writer)) {}
926
927void DisplayPage::show() { this->parent_->show_page(this); }
928
930 if (this->next_ == nullptr) {
931 ESP_LOGE(TAG, "no next page");
932 return;
933 }
934 this->next_->show();
935}
936
938 if (this->prev_ == nullptr) {
939 ESP_LOGE(TAG, "no previous page");
940 return;
941 }
942 this->prev_->show();
943}
944
945const display_writer_t &DisplayPage::get_writer() const { return this->writer_; }
946
947const LogString *text_align_to_string(TextAlign textalign) {
948 switch (textalign) {
950 return LOG_STR("TOP_LEFT");
952 return LOG_STR("TOP_CENTER");
954 return LOG_STR("TOP_RIGHT");
956 return LOG_STR("CENTER_LEFT");
958 return LOG_STR("CENTER");
960 return LOG_STR("CENTER_RIGHT");
962 return LOG_STR("BASELINE_LEFT");
964 return LOG_STR("BASELINE_CENTER");
966 return LOG_STR("BASELINE_RIGHT");
968 return LOG_STR("BOTTOM_LEFT");
970 return LOG_STR("BOTTOM_CENTER");
972 return LOG_STR("BOTTOM_RIGHT");
973 default:
974 return LOG_STR("UNKNOWN");
975 }
976}
977} // namespace esphome::display
void feed_wdt()
Feed the task watchdog.
virtual void measure(const char *str, int *width, int *x_offset, int *baseline, int *height)=0
virtual void print(int x, int y, Display *display, Color color, const char *text, Color background)=0
virtual int get_height() const =0
virtual int get_width() const =0
virtual void draw(int x, int y, Display *display, Color color_on, Color color_off)=0
static Color to_color(uint32_t colorcode, ColorBitness color_bitness=ColorBitness::COLOR_BITNESS_888, bool right_bit_aligned=true)
Unpacks a color of the given bitness, red in the most significant bits.
static ESPHOME_ALWAYS_INLINE uint32_t read_packed(const uint8_t *ptr, size_t index, bool big_endian)
Reads one packed pixel of the given bitness from a source buffer into the value to_color() takes.
void show_page(DisplayPage *page)
Definition display.cpp:734
virtual bool pixel_axes_swapped() const
True when draw_pixel_at() swaps x and y before writing, so pixels that are neighbours along x land a ...
Definition display.h:759
StaticCallbackManager< DISPLAY_PAGE_CHANGE_CALLBACK_COUNT, void(DisplayPage *, DisplayPage *)> page_change_callback_
Definition display.h:869
bool clip(int x, int y)
Check if pixel is within region of display.
Definition display.cpp:827
void get_regular_polygon_vertex(int vertex_id, int *vertex_x, int *vertex_y, int center_x, int center_y, int radius, int edges, RegularPolygonVariation variation=VARIATION_POINTY_TOP, float rotation_degrees=ROTATION_0_DEGREES)
Get the specified vertex (x,y) coordinates for the regular polygon inscribed in the circle centered o...
Definition display.cpp:495
display_writer_t writer_
Definition display.h:866
int int int const uint8_t ColorOrder ColorBitness bitness
Definition display.h:394
virtual void clear()
Clear the entire screen by filling it with OFF pixels.
Definition display.cpp:17
void end_clipping()
Reset the invalidation region.
Definition display.cpp:791
void start_clipping(Rect rect)
Set the clipping rectangle for further drawing.
Definition display.cpp:783
void set_pages(std::vector< DisplayPage * > pages)
Definition display.cpp:718
void vprintf_(int x, int y, BaseFont *font, Color color, Color background, TextAlign align, const char *format, va_list arg)
Definition display.cpp:570
virtual int get_height()
Get the calculated height of the display in pixels with rotation applied.
Definition display.h:340
int int int const uint8_t ColorOrder ColorBitness bool int int y_offset
Definition display.h:394
virtual void fill(Color color)
Fill the entire screen with the given color.
Definition display.cpp:16
int int int const uint8_t ColorOrder ColorBitness bool int int int x_pad
Definition display.h:394
void horizontal_line(int x, int y, int width, Color color=COLOR_ON)
Draw a horizontal line from the point [x,y] to [x+width,y] with the given color.
Definition display.cpp:153
void sort_triangle_points_by_y_(int *x1, int *y1, int *x2, int *y2, int *x3, int *y3)
Definition display.cpp:376
int int int const uint8_t * ptr
Definition display.h:393
int int int const uint8_t ColorOrder order
Definition display.h:393
virtual int get_width()
Get the calculated width of the display in pixels with rotation applied.
Definition display.h:338
void circle(int center_x, int center_xy, int radius, Color color=COLOR_ON)
Draw the outline of a circle centered around [center_x,center_y] with the radius radius with the give...
Definition display.cpp:179
void filled_triangle(int x1, int y1, int x2, int y2, int x3, int y3, Color color=COLOR_ON)
Fill a triangle contained between the points [x1,y1], [x2,y2] and [x3,y3] with the given color.
Definition display.cpp:477
void print(int x, int y, BaseFont *font, Color color, TextAlign align, const char *text, Color background=COLOR_OFF)
Print text with the anchor point at [x,y] with font.
Definition display.cpp:563
void filled_regular_polygon(int x, int y, int radius, int edges, RegularPolygonVariation variation=VARIATION_POINTY_TOP, float rotation_degrees=ROTATION_0_DEGREES, Color color=COLOR_ON)
Fill a regular polygon inscribed in the circle centered on [x,y] with the given radius and color.
Definition display.cpp:549
void qr_code(int x, int y, qr_code::QrCode *qr_code, Color color_on=COLOR_ON, int scale=1)
Draw the qr_code with the top-left corner at [x,y] to the screen.
Definition display.cpp:619
bool clamp_x_(int x, int w, int &min_x, int &max_x)
Definition display.cpp:835
bool ESPHOME_ALWAYS_INLINE is_point_clipped(int x, int y) const
Whether (x, y) falls outside the active clipping rectangle.
Definition display.h:812
void line(int x1, int y1, int x2, int y2, Color color=COLOR_ON)
Draw a straight line from the point [x1,y1] to [x2,y2] with the given color.
Definition display.cpp:19
bool clamp_y_(int y, int h, int &min_y, int &max_y)
Definition display.cpp:851
void filled_gauge(int center_x, int center_y, int radius1, int radius2, int progress, Color color=COLOR_ON)
Fill a half-ring "gauge" centered around [center_x,center_y] between two circles with the radius1 and...
Definition display.cpp:287
virtual DisplayType get_display_type()=0
Get the type of display that the buffer corresponds to.
void void void void void void void void void void void image(int x, int y, BaseImage *image, Color color_on=COLOR_ON, Color color_off=COLOR_OFF)
Draw the image with the top-left corner at [x,y] to the screen.
Definition display.cpp:578
void legend(int x, int y, graph::Graph *graph, Color color_on=COLOR_ON)
Draw the legend for graph with the top-left corner at [x,y] to the screen.
Definition display.cpp:615
void rectangle(int x1, int y1, int width, int height, Color color=COLOR_ON)
Draw the outline of a rectangle with the top left point at [x1,y1] and the bottom right point at [x1+...
Definition display.cpp:165
void filled_circle(int center_x, int center_y, int radius, Color color=COLOR_ON)
Fill a circle centered around [center_x,center_y] with the radius radius with the given color.
Definition display.cpp:203
void void void void void void strftime(int x, int y, BaseFont *font, Color color, Color background, TextAlign align, const char *format, ESPTime time) __attribute__((format(strftime
Evaluate the strftime-format format and print the result with the anchor point at [x,...
Definition display.cpp:759
void triangle(int x1, int y1, int x2, int y2, int x3, int y3, Color color=COLOR_ON)
Draw the outline of a triangle contained between the points [x1,y1], [x2,y2] and [x3,...
Definition display.cpp:370
void printf(int x, int y, BaseFont *font, Color color, Color background, TextAlign align, const char *format,...) __attribute__((format(printf
Evaluate the printf-format format and print the result with the anchor point at [x,...
Definition display.cpp:682
DisplayPage * page_
Definition display.h:867
void draw_pixel_at(int x, int y)
Set a single pixel at the specified coordinates to default color.
Definition display.h:348
void draw_pixels_at(int x_start, int y_start, int w, int h, const uint8_t *ptr, ColorBitness bitness, bool big_endian, int x_offset, int y_offset, int x_pad)
Given an array of pixels encoded in the nominated format, draw these into the display's buffer.
Definition display.h:372
void vertical_line(int x, int y, int height, Color color=COLOR_ON)
Draw a vertical line from the point [x,y] to [x,y+width] with the given color.
Definition display.cpp:159
int int int const uint8_t ColorOrder ColorBitness bool big_endian
Definition display.h:394
void graph(int x, int y, graph::Graph *graph, Color color_on=COLOR_ON)
Draw the graph with the top-left corner at [x,y] to the screen.
Definition display.cpp:614
Rect get_clipping() const
Get the current the clipping rectangle.
Definition display.cpp:815
void filled_ring(int center_x, int center_y, int radius1, int radius2, Color color=COLOR_ON)
Fill a ring centered around [center_x,center_y] between two circles with the radius1 and radius2 with...
Definition display.cpp:230
void extend_clipping(Rect rect)
Add a rectangular region to the invalidation region.
Definition display.cpp:799
int int int const uint8_t ColorOrder ColorBitness bool int x_offset
Definition display.h:394
void menu(int x, int y, graphical_display_menu::GraphicalDisplayMenu *menu, int width, int height)
Definition display.cpp:625
void line_at_angle(int x, int y, int angle, int length, Color color=COLOR_ON)
Draw a straight line at the given angle based on the origin [x, y] for a specified length with the gi...
Definition display.cpp:40
void get_text_bounds(int x, int y, const char *text, BaseFont *font, TextAlign align, int *x1, int *y1, int *width, int *height)
Get the text bounds of the given string.
Definition display.cpp:631
void regular_polygon(int x, int y, int radius, int edges, RegularPolygonVariation variation=VARIATION_POINTY_TOP, float rotation_degrees=ROTATION_0_DEGREES, Color color=COLOR_ON, RegularPolygonDrawing drawing=DRAWING_OUTLINE)
Draw the outline of a regular polygon inscribed in the circle centered on [x,y] with the given radius...
Definition display.cpp:518
void filled_flat_side_triangle_(int x1, int y1, int x2, int y2, int x3, int y3, Color color)
This method fills a triangle using only integer variables by using a modified bresenham algorithm.
Definition display.cpp:394
virtual void draw_pixels_internal(int x_start, int y_start, int w, int h, const uint8_t *ptr, ColorBitness bitness, bool big_endian, int x_offset, int y_offset, int x_pad)
Draws a block for draw_pixels_at(); the parameters are the same.
Definition display.cpp:118
void shrink_clipping(Rect rect)
subtract a rectangular region to the invalidation region
Definition display.cpp:807
void filled_rectangle(int x1, int y1, int width, int height, Color color=COLOR_ON)
Fill a rectangle with the top left point at [x1,y1] and the bottom right point at [x1+width,...
Definition display.cpp:172
std::vector< Rect > clipping_rectangle_
Definition display.h:872
display_writer_t writer_
Definition display.h:890
const display_writer_t & get_writer() const
Definition display.cpp:945
DisplayPage(display_writer_t writer)
Definition display.cpp:925
void shrink(Rect rect)
Definition rect.cpp:41
void draw(display::Display *buff, uint16_t x_offset, uint16_t y_offset, Color color)
Definition graph.cpp:55
void draw_legend(display::Display *buff, uint16_t x_offset, uint16_t y_offset, Color color)
Definition graph.cpp:330
void draw(display::Display *buff, uint16_t x_offset, uint16_t y_offset, Color color, int scale)
Definition qr_code.cpp:46
struct @65::@66 __attribute__
Wake the main loop task from an ISR. ISR-safe.
Definition main_task.h:45
uint32_t buffer
Definition gif.cpp:50
int ret
constexpr uint8_t TESTCARD_FONT[3][8] PROGMEM
Definition display.cpp:867
constexpr Color COLOR_ON(255, 255, 255, 255)
Turn the pixel ON.
constexpr Color COLOR_OFF(0, 0, 0, 0)
Turn the pixel OFF.
static void int int int int const uint8_t ColorOrder ColorBitness bool big_endian
Definition display.cpp:100
static void int int int int const uint8_t ColorOrder ColorBitness bitness
Definition display.cpp:99
static void int x_start
Definition display.cpp:61
const LogString * text_align_to_string(TextAlign textalign)
Definition display.cpp:947
ImageAlign
ImageAlign is used to tell the display class how to position a image.
Definition display.h:105
static void int int int int const uint8_t int x_offset
Definition display.cpp:62
const auto draw_source_pixel
Definition display.cpp:66
static void int int y_start
Definition display.cpp:61
static void int int int int const uint8_t ColorOrder order
Definition display.cpp:99
const float ROTATION_270_DEGREES
Definition display.h:170
static void int int int int const uint8_t int int y_offset
Definition display.cpp:62
static void int int int w
Definition display.cpp:61
ESPHOME_LOG_TAG(TAG, "display")
TextAlign
TextAlign is used to tell the display class how to position a piece of text.
Definition display.h:55
Color apply_color_order(Color color, ColorOrder order)
static void int int int int h
Definition display.cpp:61
static void int int int int const uint8_t * ptr
Definition display.cpp:62
static void int int int int const uint8_t int int int x_pad
Definition display.cpp:62
const float ROTATION_0_DEGREES
Definition display.h:166
va_end(args)
void const char int line
Definition log.h:110
void const char int const char * format
Definition log.h:110
size_t size_t const char va_start(args, fmt)
Application App
Global storage of Application pointer - only one Application can exist.
uint8_t progmem_read_byte(const uint8_t *addr)
Definition hal.h:51
STL namespace.
static void uint32_t
A more user-friendly version of struct tm from time.h.
Definition time.h:23
size_t strftime(char *buffer, size_t buffer_len, const char *format)
Convert this ESPTime struct to a null-terminated c string buffer as specified by the format argument.
Definition time.cpp:116
std::string print()
uint16_t length
Definition tt21100.cpp:0
uint16_t x
Definition tt21100.cpp:5
uint16_t y
Definition tt21100.cpp:6