10 static const char *
const TAG =
"display";
19 const int32_t dx = abs(x2 - x1), sx = x1 < x2 ? 1 : -1;
20 const int32_t dy = -abs(y2 - y1), sy = y1 < y2 ? 1 : -1;
21 int32_t err = dx + dy;
25 if (x1 == x2 && y1 == y2)
40 for (
int i = x; i < x + width; i++)
45 for (
int i = y; i < y + height; i++)
56 for (
int i = y1; i < y1 + height; i++) {
63 int err = 2 - 2 * radius;
74 if (-dx == dy && e2 <= dx) {
84 int dx = -int32_t(radius);
86 int err = 2 - 2 * radius;
94 int hline_width = 2 * (-dx) + 1;
95 this->
horizontal_line(center_x + dx, center_y + dy, hline_width, color);
96 this->
horizontal_line(center_x + dx, center_y - dy, hline_width, color);
100 if (-dx == dy && e2 <= dx) {
111 int x_start, y_start;
113 this->
get_text_bounds(x, y, text, font, align, &x_start, &y_start, &width, &height);
114 font->
print(x_start, y_start,
this, color, text);
118 int ret = vsnprintf(buffer,
sizeof(buffer), format, arg);
120 this->
print(x, y, font, color, align, buffer);
155 image->
draw(x, y,
this, color_on, color_off);
165 qr_code->
draw(
this, x, y, color_on, scale);
167 #endif // USE_QR_CODE 170 int *width,
int *height) {
171 int x_offset, baseline;
172 font->
measure(text, width, &x_offset, &baseline, height);
174 auto x_align =
TextAlign(
int(align) & 0x18);
175 auto y_align =
TextAlign(
int(align) & 0x07);
182 *x1 = x - (*width) / 2;
199 *y1 = y - (*height) / 2;
211 this->
print(x, y, font, COLOR_ON, align, text);
218 va_start(arg, format);
219 this->
vprintf_(x, y, font, color, align, format, arg);
224 va_start(arg, format);
230 va_start(arg, format);
231 this->
vprintf_(x, y, font, COLOR_ON, align, format, arg);
236 va_start(arg, format);
242 for (
auto *page : pages)
243 page->set_parent(
this);
245 for (uint32_t i = 0; i < pages.size() - 1; i++) {
246 pages[i]->set_next(pages[i + 1]);
247 pages[i + 1]->set_prev(pages[i]);
249 pages[0]->set_prev(pages[pages.size() - 1]);
250 pages[pages.size() - 1]->set_next(pages[0]);
267 if (this->
page_ !=
nullptr) {
275 if ((this->from_ ==
nullptr || this->from_ == from) && (this->to_ ==
nullptr || this->to_ == to))
276 this->trigger(from, to);
280 size_t ret = time.
strftime(buffer,
sizeof(buffer), format);
282 this->
print(x, y, font, color, align, buffer);
288 this->
strftime(x, y, font, COLOR_ON, align, format, time);
303 ESP_LOGE(TAG,
"clear: Clipping is not set.");
310 ESP_LOGE(TAG,
"add: Clipping is not set.");
317 ESP_LOGE(TAG,
"add: Clipping is not set.");
338 min_x = std::max(x, 0);
339 max_x = std::min(x + w, this->
get_width());
346 min_x = std::max(min_x, (
int) rect.x);
347 max_x = std::min(max_x, (
int) rect.x2());
350 return min_x < max_x;
353 min_y = std::max(y, 0);
361 min_y = std::max(min_y, (
int) rect.y);
362 max_y = std::min(max_y, (
int) rect.y2());
365 return min_y < max_y;
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...
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.
optional< display_writer_t > writer_
std::vector< DisplayOnPageChangeTrigger * > on_page_change_triggers_
void set_pages(std::vector< DisplayPage *> pages)
bool clamp_x_(int x, int w, int &min_x, int &max_x)
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...
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.
void set_next(DisplayPage *next)
void set_parent(Display *parent)
A more user-friendly version of struct tm from time.h.
void set_rotation(DisplayRotation rotation)
Internal method to set the display rotation with.
const Color COLOR_OFF(0, 0, 0, 0)
Turn the pixel OFF.
void extend_clipping(Rect rect)
Add a rectangular region to the invalidation region.
void shrink_clipping(Rect rect)
substract a rectangular region to the invalidation region
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...
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...
void printf(int x, int y, BaseFont *font, Color color, TextAlign align, const char *format,...) __attribute__((format(printf
Evaluate the printf-format format and print the result with the anchor point at [x,y] with font.
virtual int get_width()=0
Get the width of the image in pixels with rotation applied.
virtual void fill(Color color)
Fill the entire screen with the given color.
DisplayPage(display_writer_t writer)
Rect get_clipping() const
Get the current the clipping rectangle.
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.
bool clamp_y_(int y, int h, int &min_y, int &max_y)
virtual void draw(int x, int y, Display *display, Color color_on, Color color_off)=0
const display_writer_t & get_writer() const
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+...
TextAlign
TextAlign is used to tell the display class how to position a piece of text.
std::function< void(Display &)> display_writer_t
void process(DisplayPage *from, DisplayPage *to)
void start_clipping(Rect rect)
Set the clipping rectangle for further drawing.
ImageAlign
ImageAlign is used to tell the display class how to position a image.
void clear()
Clear the entire screen by filling it with OFF pixels.
void draw_legend(display::Display *buff, uint16_t x_offset, uint16_t y_offset, Color color)
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.
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.
void draw(display::Display *buff, uint16_t x_offset, uint16_t y_offset, Color color, int scale)
DisplayRotation rotation_
void end_clipping()
Reset the invalidation region.
DisplayPage * previous_page_
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.
const Color COLOR_ON(255, 255, 255, 255)
Turn the pixel ON.
void print(int x, int y, BaseFont *font, Color color, TextAlign align, const char *text)
Print text with the anchor point at [x,y] with font.
void vprintf_(int x, int y, BaseFont *font, Color color, TextAlign align, const char *format, va_list arg)
virtual int get_width() const =0
bool clip(int x, int y)
Check if pixel is within region of display.
void void void void void strftime(int x, int y, BaseFont *font, Color color, 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...
virtual void print(int x, int y, Display *display, Color color, const char *text)=0
void draw_pixel_at(int x, int y)
Set a single pixel at the specified coordinates to default color.
Implementation of SPI Controller mode.
void draw(display::Display *buff, uint16_t x_offset, uint16_t y_offset, Color color)
virtual void measure(const char *str, int *width, int *x_offset, int *baseline, int *height)=0
std::vector< Rect > clipping_rectangle_
void set_writer(display_writer_t &&writer)
Internal method to set the display writer lambda.
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.
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.
void show_page(DisplayPage *page)
void set_prev(DisplayPage *prev)
virtual int get_height() const =0
virtual int get_height()=0
Get the height of the image in pixels with rotation applied.