25#include "px_gfx_disp.h"
26#include "px_gfx_fonts.h"
62 .color_bg = PX_GFX_COLOR_OFF,
63 .align = PX_GFX_ALIGN_TOP_LEFT,
69 .width = PX_GFX_DISP_SIZE_X,
70 .height = PX_GFX_DISP_SIZE_Y,
73 .font = &PX_GFX_CFG_DEFAULT_FONT,
79static void px_gfx_update_area_reset(
void)
87static bool px_gfx_update_area_is_set(
void)
108 if((x1 < PX_GFX_X_MIN) && (x2 < PX_GFX_X_MIN))
return;
109 if((x1 > PX_GFX_X_MAX) && (x2 > PX_GFX_X_MAX))
return;
110 if((y1 < PX_GFX_Y_MIN) && (y2 < PX_GFX_Y_MIN))
return;
111 if((y1 > PX_GFX_Y_MAX) && (y2 > PX_GFX_Y_MAX))
return;
113 if(x1 < PX_GFX_X_MIN) x1 = PX_GFX_X_MIN;
114 if(x2 > PX_GFX_X_MAX) x2 = PX_GFX_X_MAX;
115 if(y1 < PX_GFX_Y_MIN) y1 = PX_GFX_Y_MIN;
116 if(y2 > PX_GFX_Y_MAX) y2 = PX_GFX_Y_MAX;
128 return (x + px_gfx.draw_prop.
vp.
x);
140 return (y + px_gfx.draw_prop.
vp.
y);
154 if( (x < px_gfx.draw_prop.
vp.
x )
155 ||(x >= px_gfx.draw_prop.
vp.
x + px_gfx.draw_prop.
vp.
width )
156 ||(y < px_gfx.draw_prop.
vp.
y )
157 ||(y >= px_gfx.draw_prop.
vp.
y + px_gfx.draw_prop.
vp.
height) )
164 if( (x < PX_GFX_X_MIN)
167 ||(y > PX_GFX_Y_MAX) )
173 px_gfx_disp_buf_pixel(x, y, color);
185 px_gfx_update_area_reset();
186 px_gfx_update_area(0, 0, PX_GFX_X_MAX, PX_GFX_DISP_SIZE_Y);
187 px_gfx_disp_buf_clear();
192 px_gfx_update_area(0, 0, PX_GFX_X_MAX, PX_GFX_DISP_SIZE_Y);
194 px_gfx_update_area_reset();
199 if(px_gfx_update_area_is_set())
202 px_gfx_update_area_reset();
210 return px_gfx_update_area_is_set();
215 memcpy(&px_gfx.draw_prop, &px_gfx_draw_prop_default,
sizeof(px_gfx.draw_prop));
237 px_gfx.draw_prop.
align = align;
244 px_gfx.draw_prop.
vp.
x = x;
245 px_gfx.draw_prop.
vp.
y = y;
246 px_gfx.draw_prop.
vp.
width = width;
247 px_gfx.draw_prop.
vp.
height = height;
248 px_gfx.draw_prop.
vp.
xy_ref = xy_ref;
254 memcpy(&px_gfx.draw_prop.
vp, &px_gfx_draw_prop_default.
vp,
sizeof(px_gfx.draw_prop.
vp));
261 px_gfx.draw_prop.
font = font;
269 x = px_gfx_vp_adjust_x(x);
270 y = px_gfx_vp_adjust_y(y);
272 px_gfx_update_area(x, y, x, y);
274 px_gfx_vp_draw_pixel(x, y, px_gfx.draw_prop.
color_fg);
308 x1 = px_gfx_vp_adjust_x(x1);
309 y1 = px_gfx_vp_adjust_y(y1);
310 x2 = px_gfx_vp_adjust_x(x2);
311 y2 = px_gfx_vp_adjust_y(y2);
313 px_gfx_update_area(x1, y1, x2, y2);
368 for(x = x1; x <= x2; x++)
374 px_gfx_vp_draw_pixel(y, x, px_gfx.draw_prop.
color_fg);
379 px_gfx_vp_draw_pixel(x, y, px_gfx.draw_prop.
color_fg);
409 x = px_gfx_vp_adjust_x(x);
410 y = px_gfx_vp_adjust_y(y);
412 px_gfx_update_area(x, y, x + width - 1, y);
414 for(i = 0; i < width; i++)
416 px_gfx_vp_draw_pixel(x, y, px_gfx.draw_prop.
color_fg);
426 x = px_gfx_vp_adjust_x(x);
427 y = px_gfx_vp_adjust_y(y);
429 px_gfx_update_area(x, y, x, y + height - 1);
431 for(j = 0; j < height; j++)
433 px_gfx_vp_draw_pixel(x, y, px_gfx.draw_prop.
color_fg);
451 x = px_gfx_vp_adjust_x(x);
452 y = px_gfx_vp_adjust_y(y);
454 px_gfx_update_area(x, y, x + width - 1, y + height - 1);
456 for(j = y; j < y + height; j++)
458 for(i = x; i < x + width; i++)
460 px_gfx_vp_draw_pixel(i, j, px_gfx.draw_prop.
color_fg);
470 x = px_gfx_vp_adjust_x(x);
471 y = px_gfx_vp_adjust_y(y);
473 px_gfx_update_area(x, y, x + width - 1, y + height - 1);
475 for(j = y; j < y + height; j++)
477 for(i = x; i < x + width; i++)
479 px_gfx_vp_draw_pixel(i, j, px_gfx.draw_prop.
color_bg);
495 x = px_gfx_vp_adjust_x(x);
496 y = px_gfx_vp_adjust_y(y);
498 px_gfx_update_area(x - radius, y - radius,
499 x + radius, y + radius);
501 px_gfx_vp_draw_pixel(x, y + radius, px_gfx.draw_prop.
color_fg);
503 px_gfx_vp_draw_pixel(x + radius, y, px_gfx.draw_prop.
color_fg);
505 px_gfx_vp_draw_pixel(x, y - radius, px_gfx.draw_prop.
color_fg);
507 px_gfx_vp_draw_pixel(x - radius, y, px_gfx.draw_prop.
color_fg);
526 px_gfx_vp_draw_pixel(x + dx, y + dy, px_gfx.draw_prop.
color_fg);
527 px_gfx_vp_draw_pixel(x - dx, y + dy, px_gfx.draw_prop.
color_fg);
528 px_gfx_vp_draw_pixel(x + dx, y - dy, px_gfx.draw_prop.
color_fg);
529 px_gfx_vp_draw_pixel(x - dx, y - dy, px_gfx.draw_prop.
color_fg);
530 px_gfx_vp_draw_pixel(x + dy, y + dx, px_gfx.draw_prop.
color_fg);
531 px_gfx_vp_draw_pixel(x - dy, y + dx, px_gfx.draw_prop.
color_fg);
532 px_gfx_vp_draw_pixel(x + dy, y - dx, px_gfx.draw_prop.
color_fg);
533 px_gfx_vp_draw_pixel(x - dy, y - dx, px_gfx.draw_prop.
color_fg);
542 const uint8_t * data = img->data;
547 x -= (img->width + 1) / 2 - 1;
555 y -= img->height / 2 - 1;
559 y -= img->height - 1;
562 x = px_gfx_vp_adjust_x(x);
563 y = px_gfx_vp_adjust_y(y);
565 px_gfx_update_area(x, y, x + img->width - 1, y + img->height - 1);
567 for(j = 0; j < img->height; j++)
572 for(i = 0; i < img->width; i++)
577 px_gfx_vp_draw_pixel(x + i, y + j, px_gfx.draw_prop.
color_fg);
582 if(px_gfx.draw_prop.
color_bg != PX_GFX_COLOR_TRANSPARENT)
585 px_gfx_vp_draw_pixel(x + i, y + j, px_gfx.draw_prop.
color_bg);
612 const uint8_t * data = font->data;
613 int width_bytes = (font->width + 7) / 8;
624 data += (width_bytes * font->height) + 1;
634 img.width = font->width;
635 img.height = font->height;
648 if((str ==
NULL) || (strlen(str) == 0))
663 y -= (font->height - 1) / 2;
667 y -= font->height - 2;
669 px_gfx.draw_prop.
align = PX_GFX_ALIGN_TOP_LEFT;
677 px_gfx.draw_prop.
align = align;
683 char str[PX_GFX_CFG_STR_BUFFER_SIZE];
686 va_start(args, format);
687 vsnprintf(str, PX_GFX_CFG_STR_BUFFER_SIZE, format, args);
690 str[PX_GFX_CFG_STR_BUFFER_SIZE-1] =
'\0';
#define PX_SWAP(type_t, i, j)
Swap the value of two variables.
#define NULL
NULL pointer.
px_gfx_xy_ref_t xy_ref
Coordinate reference.
px_gfx_xy_t height
Height.
void px_gfx_draw_line_hor(px_gfx_xy_t x, px_gfx_xy_t y, px_gfx_xy_t width)
Draw a horizontal line using the current foreground color.
px_gfx_color_t
Foreground and background color definitions.
void px_gfx_printf(px_gfx_xy_t x, px_gfx_xy_t y, const char *format,...)
Draw a formatted font string using the current foreground color.
void px_gfx_view_port_set(px_gfx_xy_t x, px_gfx_xy_t y, px_gfx_xy_t width, px_gfx_xy_t height, px_gfx_xy_ref_t xy_ref)
Set a drawing view port.
px_gfx_align_t px_gfx_align_set(px_gfx_align_t align)
Set the new alignment.
px_gfx_xy_ref_t
X Y coordinate reference.
void px_gfx_draw(void)
Redraw whole display using display buffer.
void px_gfx_draw_char(px_gfx_xy_t x, px_gfx_xy_t y, char glyph)
Draw a font character using the current foreground color.
px_gfx_color_t px_gfx_color_bg_set(px_gfx_color_t color)
Set the new background drawing color.
px_gfx_align_t
Alignment definition.
void px_gfx_view_port_reset(void)
Reset view port.
void px_gfx_draw_img(px_gfx_xy_t x, px_gfx_xy_t y, const px_gfx_img_t *img)
Draw a graphic image using the current foreground and background color.
void px_gfx_draw_line(px_gfx_xy_t x1, px_gfx_xy_t y1, px_gfx_xy_t x2, px_gfx_xy_t y2)
Draw a line using the current foreground color.
int16_t px_gfx_xy_t
Size definition of an X or Y coordinate.
bool px_gfx_update_area_get(px_gfx_area_t *area)
Get total area of frame that has changed.
void px_gfx_draw_fill_fg(px_gfx_xy_t x, px_gfx_xy_t y, px_gfx_xy_t width, px_gfx_xy_t height)
Draw a solid rectangular fill in the current foreground color.
void px_gfx_draw_str(px_gfx_xy_t x, px_gfx_xy_t y, const char *str)
Draw a font string using the current foreground color.
void px_gfx_draw_rect(px_gfx_xy_t x, px_gfx_xy_t y, px_gfx_xy_t width, px_gfx_xy_t height)
Draw a rectangle using the current foreground color.
void px_gfx_draw_prop_reset(void)
Reset drawing properties to default.
void px_gfx_draw_update(void)
Update display with total area that has changed in display buffer.
void px_gfx_buf_clear(void)
Clear display buffer.
void px_gfx_draw_pixel(px_gfx_xy_t x, px_gfx_xy_t y)
Draw a pixel using the current foreground color.
void px_gfx_draw_circ(px_gfx_xy_t x, px_gfx_xy_t y, px_gfx_xy_t radius)
Draw a circle using the current foreground color.
void px_gfx_draw_fill_bg(px_gfx_xy_t x, px_gfx_xy_t y, px_gfx_xy_t width, px_gfx_xy_t height)
Draw a solid rectangular fill in the current background color.
void px_gfx_init(void)
Initialise graphics library.
px_gfx_color_t px_gfx_color_fg_set(px_gfx_color_t color)
Set the new foreground drawing color.
const px_gfx_font_t * px_gfx_font_set(const px_gfx_font_t *font)
Set the new font.
void px_gfx_draw_line_ver(px_gfx_xy_t x, px_gfx_xy_t y, px_gfx_xy_t height)
Draw a vertical line using the current foreground color.
@ PX_GFX_XY_REF_REL
Coordinate references are relative to view port.
@ PX_GFX_ALIGN_V_BOT
Vertical (y) bottom.
@ PX_GFX_ALIGN_V_MID
Vertical (y) middle.
@ PX_GFX_ALIGN_H_MID
Horizontal (x) middle.
@ PX_GFX_ALIGN_H_RIGHT
Horizontal (x) right.
#define PX_LOG_NAME(name)
Macro to declare a log name string once for each file to reduce code size.
Graphic drawing properties.
bool vp_active
View port active flag.
px_gfx_color_t color_fg
Foreground color.
px_gfx_color_t color_bg
Background color.
px_gfx_view_port_t vp
View port.
px_gfx_align_t align
Alignment.
const px_gfx_font_t * font
Current font.
Graphics state definition.
px_gfx_area_t update_area
Area of frame to be updated.