5 memset(
self, 0,
sizeof(*
self));
6 self->_display = display;
7 self->_driver = driver;
9 self->_caps = driver->get_caps(self->_display);
14 return self->_driver->is_ready(self->_display);
24 self->_driver->clear(self->_display);
34 self->_rotation = rotation;
39 return self->_rotation;
46 switch (self->_rotation)
51 x =
self->_caps.width - 1 - y;
57 x =
self->_caps.width - 1 - x;
58 y =
self->_caps.height - 1 - y;
64 y =
self->_caps.height - 1 - x;
78 if (x >= self->_caps.width || y >= self->_caps.height || x < 0 || y < 0)
83 self->_driver->draw_pixel(self->_display, x, y, color);
102 for (i = 0; i < font->length; i++)
104 if (font->chars[i].code == ch)
106 w = font->chars[i].image->width;
107 h = font->chars[i].image->heigth;
111 for (y = 0; y < h; y++)
113 for (x = 0; x < w; x++)
115 uint32_t byteIndex = x / 8;
116 byteIndex += y * bytes;
118 uint8_t bitMask = 1 << (7 - (x % 8));
120 if ((font->chars[i].image->image[byteIndex] & bitMask) == 0)
141 for (
int i = 0; i < font->length; i++)
143 if (font->chars[i].code == ch)
145 return font->chars[i].image->width;
179 va_start(ap, format);
181 vsnprintf(buffer,
sizeof(buffer), format, ap);
201 for (; x0 <= x1; x0++)
217 for (; y0 <= y1; y0++)
225 int16_t step = abs(y1 - y0) > abs(x1 - x0);
249 int16_t dx = x1 - x0;
250 int16_t dy = abs(y1 - y0);
252 int16_t err = dx / 2;
255 ystep = y0 < y1 ? 1 : -1;
257 for (; x0 <= x1; x0++)
289 for (; x0 <= x1; x0++)
291 for (y = y0; y <= y1; y++)
301 for (; x0 <= x1; x0++)
303 for (y = y0; y <= y1; y++)
307 uint32_t d_color = (color & (1 << (dx + 4*dy))) >> (dx + 4*dy);
316 for (; x0 <= x1; x0++)
318 for (y = y0; y <= y1; y++)
322 uint32_t d_color = pattern & (1 << (dx + 4*dy)) ? color_fg : color_bg;
334 int err = dx - (radius << 1);
358 err += (-radius << 1) + dx;
369 int err = dx - (radius << 1);
388 err += (-radius << 1) + dx;
399 int err = dx - (radius << 1);
437 err += (-radius << 1) + dx;
448 int err = dx - (radius << 1);
486 err += (-radius << 1) + dx;
493 return self->_driver->update(self->_display);
void twr_gfx_draw_fill_round_corner(twr_gfx_t *self, int x0, int y0, int radius, twr_gfx_round_corner_t corner, uint32_t color)
Lcd draw fill round corner, using Midpoint circle algorithm.
void twr_gfx_draw_rectangle(twr_gfx_t *self, int x0, int y0, int x1, int y1, uint32_t color)
Display draw rectangle.
void twr_gfx_draw_fill_rectangle(twr_gfx_t *self, int x0, int y0, int x1, int y1, uint32_t color)
Display draw fill rectangle.
void twr_gfx_draw_round_corner(twr_gfx_t *self, int x0, int y0, int radius, twr_gfx_round_corner_t corner, uint32_t color)
Lcd draw round corner, using Midpoint circle algorithm.
void twr_gfx_draw_line(twr_gfx_t *self, int x0, int y0, int x1, int y1, uint32_t color)
Display draw line.
void twr_gfx_set_font(twr_gfx_t *self, const twr_font_t *font)
Set font.
twr_gfx_caps_t twr_gfx_get_caps(twr_gfx_t *self)
Get Display capabilities.
void twr_gfx_set_rotation(twr_gfx_t *self, twr_gfx_rotation_t rotation)
Set rotation.
int twr_gfx_draw_char(twr_gfx_t *self, int left, int top, uint8_t ch, uint32_t color)
Display draw char.
void twr_gfx_init(twr_gfx_t *self, void *display, const twr_gfx_driver_t *driver)
Initialize button.
twr_gfx_rotation_t twr_gfx_get_rotation(twr_gfx_t *self)
Get rotation.
bool twr_gfx_display_is_ready(twr_gfx_t *self)
Check if display driver is ready for commands.
int twr_gfx_calc_string_width(twr_gfx_t *self, char *str)
Calc width string.
void twr_gfx_draw_fill_rectangle_dithering_color(twr_gfx_t *self, int x0, int y0, int x1, int y1, uint16_t pattern, uint32_t color_fg, uint32_t color_bg)
Display draw fill rectangle with a dithering pattern defined in the pattern parameter,...
void twr_gfx_draw_fill_rectangle_dithering(twr_gfx_t *self, int x0, int y0, int x1, int y1, uint32_t color)
Display draw fill rectangle with a dithering pattern defined in the color parameter.
void twr_gfx_draw_circle(twr_gfx_t *self, int x0, int y0, int radius, uint32_t color)
Lcd draw circle, using Midpoint circle algorithm.
twr_gfx_rotation_t
Rotation.
void twr_gfx_draw_pixel(twr_gfx_t *self, int x, int y, uint32_t color)
Draw pixel.
void twr_gfx_clear(twr_gfx_t *self)
Clear.
int twr_gfx_draw_string(twr_gfx_t *self, int left, int top, char *str, uint32_t color)
Display draw string.
void twr_gfx_draw_fill_circle(twr_gfx_t *self, int x0, int y0, int radius, uint32_t color)
Lcd draw fill circle, using Midpoint circle algorithm.
int twr_gfx_printf(twr_gfx_t *self, int left, int top, uint32_t color, char *format,...)
Display string.
bool twr_gfx_update(twr_gfx_t *self)
Display update, send data.
int twr_gfx_calc_char_width(twr_gfx_t *self, uint8_t ch)
Calc width character.
@ TWR_GFX_ROTATION_270
Rotation 270 degrees.
@ TWR_GFX_ROTATION_180
Rotation 180 degrees.
@ TWR_GFX_ROTATION_90
Rotation 90 degrees.
@ TWR_GFX_ROTATION_0
Rotation 0 degrees.
@ TWR_GFX_ROUND_CORNER_RIGHT_TOP
Round corner right top.
@ TWR_GFX_ROUND_CORNER_LEFT_TOP
Round corner left top.
@ TWR_GFX_ROUND_CORNER_RIGHT_BOTTOM
Round corner right bottom.
@ TWR_GFX_ROUND_CORNER_LEFT_BOTTOM
Round corner left bottom.
Display driver interface.