px-fwlib 0.10.0
Cross-platform embedded library and documentation for 8/16/32-bit microcontrollers generated with Doxygen 1.9.2
px_gfx.h
1#ifndef __PX_GFX_H__
2#define __PX_GFX_H__
3/* =============================================================================
4 ____ ___ ____ ___ _ _ ___ __ __ ___ __ __ TM
5 | _ \ |_ _| / ___| / _ \ | \ | | / _ \ | \/ | |_ _| \ \/ /
6 | |_) | | | | | | | | | | \| | | | | | | |\/| | | | \ /
7 | __/ | | | |___ | |_| | | |\ | | |_| | | | | | | | / \
8 |_| |___| \____| \___/ |_| \_| \___/ |_| |_| |___| /_/\_\
9
10 Copyright (c) 2018 Pieter Conradie <https://piconomix.com>
11
12 License: MIT
13 https://github.com/piconomix/px-fwlib/blob/master/LICENSE.md
14
15 Title: px_gfx.h : Basic monochrome graphics library
16 Author(s): Pieter Conradie
17 Creation Date: 2018-05-07
18
19============================================================================= */
20
21/**
22 * @ingroup GFX
23 * @defgroup PX_GFX px_gfx.h : Basic monochrome graphics library
24 *
25 * A basic monochrome (1 bit per pixel) graphics library.
26 *
27 * File(s):
28 * - gfx/inc/px_gfx.h
29 * - gfx/inc/px_gfx_cfg_template.h
30 * - gfx/src/px_gfx.c
31 * - gfx/inc/px_gfx_disp.h
32 * - gfx/src/px_gfx_disp_st7567_jhd12864.c
33 *
34 * Tool to convert images and fonts:
35 * [Ruison.com LCD Image Converter](https://github.com/riuson/lcd-image-converter)
36 *
37 * Tool template files:
38 * - gfx/px_gfx_font.tmpl
39 * - gfx/px_gfx_image.tmpl
40 *
41 * Tool preset file:
42 * - px_gfx_preset.xml
43 *
44 * @{
45 */
46
47/* _____STANDARD INCLUDES____________________________________________________ */
48
49/* _____PROJECT INCLUDES_____________________________________________________ */
50#include "px_defs.h"
51
52// Include project specific configuration. See "px_gfx_cfg_template.h"
53#include "px_gfx_cfg.h"
54
55// Check that all project specific options have been specified in "px_gfx_cfg.h"
56#if ( !defined(PX_GFX_DISP_SIZE_X ) \
57 || !defined(PX_GFX_DISP_SIZE_Y ) \
58 || !defined(PX_GFX_CFG_STR_BUFFER_SIZE) \
59 || !defined(PX_GFX_CFG_DEFAULT_FONT ) )
60#error "One or more options not defined in 'px_gfx_cfg.h'"
61#endif
62
63#ifdef __cplusplus
64extern "C"
65{
66#endif
67/* _____DEFINITIONS__________________________________________________________ */
68
69/* _____TYPE DEFINITIONS_____________________________________________________ */
70/// Size definition of an X or Y coordinate
71typedef int16_t px_gfx_xy_t;
72
73/// @name Convenience coordinate definitions
74/// @{
75#define PX_GFX_X_MIN 0
76#define PX_GFX_X_MID (PX_GFX_DISP_SIZE_X / 2)
77#define PX_GFX_X_MAX (PX_GFX_DISP_SIZE_X - 1)
78#define PX_GFX_Y_MIN 0
79#define PX_GFX_Y_MID (PX_GFX_DISP_SIZE_Y / 2)
80#define PX_GFX_Y_MAX (PX_GFX_DISP_SIZE_Y - 1)
81/// @}
82
83/// Foreground and background color definitions
84typedef enum
85{
86 PX_GFX_COLOR_OFF,
87 PX_GFX_COLOR_ON,
88 PX_GFX_COLOR_INVERT,
89 PX_GFX_COLOR_TRANSPARENT,
91
92/// Alignment definition
93typedef enum
94{
95 PX_GFX_ALIGN_V_TOP = 0x00, ///< Vertical (y) top
96 PX_GFX_ALIGN_V_MID = 0x01, ///< Vertical (y) middle
97 PX_GFX_ALIGN_V_BOT = 0x02, ///< Vertical (y) bottom
98 PX_GFX_ALIGN_H_LEFT = 0x00, ///< Horizontal (x) left
99 PX_GFX_ALIGN_H_MID = 0x10, ///< Horizontal (x) middle
100 PX_GFX_ALIGN_H_RIGHT = 0x20, ///< Horizontal (x) right
102
103/// @name Convenience alignment combination definitions
104/// @{
105#define PX_GFX_ALIGN_TOP_LEFT (px_gfx_align_t)(PX_GFX_ALIGN_V_TOP | PX_GFX_ALIGN_H_LEFT )
106#define PX_GFX_ALIGN_TOP_MID (px_gfx_align_t)(PX_GFX_ALIGN_V_TOP | PX_GFX_ALIGN_H_MID )
107#define PX_GFX_ALIGN_TOP_RIGHT (px_gfx_align_t)(PX_GFX_ALIGN_V_TOP | PX_GFX_ALIGN_H_RIGHT)
108#define PX_GFX_ALIGN_MID (px_gfx_align_t)(PX_GFX_ALIGN_V_MID | PX_GFX_ALIGN_H_MID )
109#define PX_GFX_ALIGN_BOT_LEFT (px_gfx_align_t)(PX_GFX_ALIGN_V_BOT | PX_GFX_ALIGN_H_LEFT )
110#define PX_GFX_ALIGN_BOT_MID (px_gfx_align_t)(PX_GFX_ALIGN_V_BOT | PX_GFX_ALIGN_H_MID )
111#define PX_GFX_ALIGN_BOT_RIGHT (px_gfx_align_t)(PX_GFX_ALIGN_V_BOT | PX_GFX_ALIGN_H_RIGHT)
112/// @}
113
114/// Image definition
115typedef struct
116{
117 px_gfx_xy_t width;
118 px_gfx_xy_t height;
119 const uint8_t * data;
121
122/// Font definition
123typedef struct
124{
125 px_gfx_xy_t width;
126 px_gfx_xy_t height;
127 const uint8_t * data;
129
130/// Area definition
131typedef struct
132{
133 px_gfx_xy_t x1; ///< Left
134 px_gfx_xy_t y1; ///< Top
135 px_gfx_xy_t x2; ///< Right
136 px_gfx_xy_t y2; ///< Bottom
138
139/// X Y coordinate reference
140typedef enum
141{
142 PX_GFX_XY_REF_REL = 0, ///< Coordinate references are relative to view port
143 PX_GFX_XY_REF_ABS, ///< Coordinate references are absolute (relative to display)
145
146/// View port definition
147typedef struct
148{
149 px_gfx_xy_t x; ///< Left
150 px_gfx_xy_t y; ///< Top
151 px_gfx_xy_t width; ///< Width
152 px_gfx_xy_t height; ///< Height
153 px_gfx_xy_ref_t xy_ref; ///< Coordinate reference
155
156/* _____GLOBAL VARIABLES_____________________________________________________ */
157
158/* _____GLOBAL FUNCTION DECLARATIONS_________________________________________ */
159/**
160 * Initialise graphics library.
161 */
162void px_gfx_init(void);
163
164/**
165 * Clear display buffer.
166 */
167void px_gfx_buf_clear(void);
168
169/**
170 * Redraw whole display using display buffer.
171 */
172void px_gfx_draw(void);
173
174/**
175 * Update display with total area that has changed in display buffer.
176 */
177void px_gfx_draw_update(void);
178
179/**
180 * Get total area of frame that has changed.
181 *
182 * @param area Pointer to structure to contain area that has changed
183 *
184 * @retval true frame buffer has changed
185 * @retval false frame buffer has stayed the same (no change)
186 */
188
189/**
190 * Reset drawing properties to default.
191 */
192void px_gfx_draw_prop_reset(void);
193
194/**
195 * Set the new foreground drawing color.
196 *
197 * @param color New drawing color
198 *
199 * @return px_gfx_color_t Old drawing color
200 */
202
203/**
204 * Set the new background drawing color.
205 *
206 * @param color New drawing color
207 *
208 * @return px_gfx_color_t Old drawing color
209 */
211
212/**
213 * Set the new alignment.
214 *
215 * @param align New alignment
216 *
217 * @return px_gfx_align_t Old alignment
218 */
220
221/**
222 * Set a drawing view port.
223 *
224 * Pixels outside the view port is clipped. Drawing coordinates can relative to
225 * the top left corner of the view port with the #PX_GFX_XY_REF_REL option or
226 * absolute (relative to the top left corner of the display) using the
227 * #PX_GFX_XY_REF_ABS option.
228 *
229 * @param x Top left X coordinate of view port
230 * @param y Top left Y coordinate of view port
231 * @param width Width of view port
232 * @param height Height of view port
233 * @param xy_ref Coordinate are absolute (to display) or relative to view port
234 */
236 px_gfx_xy_t y,
237 px_gfx_xy_t width,
238 px_gfx_xy_t height,
239 px_gfx_xy_ref_t xy_ref);
240
241/**
242 * Reset view port.
243 *
244 * The view port is set to the whole display.
245 */
246void px_gfx_view_port_reset(void);
247
248/**
249 * Set the new font.
250 *
251 * @param font New font
252 *
253 * @return px_gfx_font_t * Old font
254 */
255const px_gfx_font_t * px_gfx_font_set(const px_gfx_font_t * font);
256
257/**
258 * Draw a pixel using the current foreground color.
259 *
260 * @param x X coordinate of pixel
261 * @param y Y coordinate of pixel
262 */
264 px_gfx_xy_t y);
265
266/**
267 * Draw a line using the current foreground color.
268 *
269 * @param x1 X coordinate of start point of the line
270 * @param y1 Y coordinate of start point of the line
271 * @param x2 X coordinate of end point of the line
272 * @param y2 Y coordinate of end point of the line
273 */
275 px_gfx_xy_t y1,
276 px_gfx_xy_t x2,
277 px_gfx_xy_t y2);
278
279/**
280 * Draw a horizontal line using the current foreground color.
281 *
282 * @param x X coordinate of left point of the line
283 * @param y X coordinate of left point of the line
284 * @param width Width of the line (right)
285 */
287 px_gfx_xy_t y,
288 px_gfx_xy_t width);
289
290/**
291 * Draw a vertical line using the current foreground color.
292 *
293 * @param x X coordinate of top point of the line
294 * @param y X coordinate of top point of the line
295 * @param height Height of the line (down)
296 */
298 px_gfx_xy_t y,
299 px_gfx_xy_t height);
300
301/**
302 * Draw a rectangle using the current foreground color.
303 *
304 * @param x X coordinate of top left point of rectangle
305 * @param y Y coordinate of top left point of rectangle
306 * @param width Width of rectangle (right)
307 * @param height Height of rectangle (down)
308 */
310 px_gfx_xy_t y,
311 px_gfx_xy_t width,
312 px_gfx_xy_t height);
313
314/**
315 * Draw a solid rectangular fill in the current foreground color.
316 *
317 * @param x X coordinate of top left point of fill
318 * @param y Y coordinate of top left point of fill
319 * @param width Width of fill (right)
320 * @param height Height of fill (down)
321 */
323 px_gfx_xy_t y,
324 px_gfx_xy_t width,
325 px_gfx_xy_t height);
326
327/**
328 * Draw a solid rectangular fill in the current background color.
329 *
330 * @param x X coordinate of top left point of fill
331 * @param y Y coordinate of top left point of fill
332 * @param width Width of fill (right)
333 * @param height Height of fill (down)
334 */
336 px_gfx_xy_t y,
337 px_gfx_xy_t width,
338 px_gfx_xy_t height);
339
340/**
341 * Draw a circle using the current foreground color.
342 *
343 * @param x X coordinate of the circle center.
344 * @param y X coordinate of the circle center.
345 * @param radius Radius of the circle.
346 */
348 px_gfx_xy_t y,
349 px_gfx_xy_t radius);
350
351/**
352 * Draw a graphic image using the current foreground and background color.
353 *
354 * @param x X coordinate of image
355 * @param y Y coordinate of image
356 * @param img Pointer to image structure
357 */
359 px_gfx_xy_t y,
360 const px_gfx_img_t * img);
361
362/**
363 * Draw a font character using the current foreground color.
364 *
365 * @param x X coordinate of font character
366 * @param y Y coordinate of font character
367 * @param glyph Character in font to draw
368 */
370 px_gfx_xy_t y,
371 char glyph);
372
373/**
374 * Draw a font string using the current foreground color.
375 *
376 * @param x X coordinate of starting point of string
377 * @param y Y coordinate of starting point of string
378 * @param str String to draw
379 */
381 px_gfx_xy_t y,
382 const char * str);
383
384/**
385 * Draw a formatted font string using the current foreground color.
386 *
387 * @param x X coordinate of starting point of string
388 * @param y Y coordinate of starting point of string
389 * @param format Format string
390 */
392 px_gfx_xy_t y,
393 const char * format, ...);
394
395/* _____MACROS_______________________________________________________________ */
396
397#ifdef __cplusplus
398}
399#endif
400
401/// @}
402#endif
px_gfx_xy_t x
Left.
Definition: px_gfx.h:149
px_gfx_xy_t y
Top.
Definition: px_gfx.h:150
px_gfx_xy_ref_t xy_ref
Coordinate reference.
Definition: px_gfx.h:153
px_gfx_xy_t y2
Bottom.
Definition: px_gfx.h:136
px_gfx_xy_t x1
Left.
Definition: px_gfx.h:133
px_gfx_xy_t x2
Right.
Definition: px_gfx.h:135
px_gfx_xy_t width
Width.
Definition: px_gfx.h:151
px_gfx_xy_t height
Height.
Definition: px_gfx.h:152
px_gfx_xy_t y1
Top.
Definition: px_gfx.h:134
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.
Definition: px_gfx.c:404
px_gfx_color_t
Foreground and background color definitions.
Definition: px_gfx.h:85
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.
Definition: px_gfx.c:680
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.
Definition: px_gfx.c:242
px_gfx_align_t px_gfx_align_set(px_gfx_align_t align)
Set the new alignment.
Definition: px_gfx.c:234
px_gfx_xy_ref_t
X Y coordinate reference.
Definition: px_gfx.h:141
void px_gfx_draw(void)
Redraw whole display using display buffer.
Definition: px_gfx.c:190
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.
Definition: px_gfx.c:608
px_gfx_color_t px_gfx_color_bg_set(px_gfx_color_t color)
Set the new background drawing color.
Definition: px_gfx.c:226
px_gfx_align_t
Alignment definition.
Definition: px_gfx.h:94
void px_gfx_view_port_reset(void)
Reset view port.
Definition: px_gfx.c:252
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.
Definition: px_gfx.c:537
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.
Definition: px_gfx.c:277
int16_t px_gfx_xy_t
Size definition of an X or Y coordinate.
Definition: px_gfx.h:71
bool px_gfx_update_area_get(px_gfx_area_t *area)
Get total area of frame that has changed.
Definition: px_gfx.c:206
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.
Definition: px_gfx.c:446
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.
Definition: px_gfx.c:641
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.
Definition: px_gfx.c:438
void px_gfx_draw_prop_reset(void)
Reset drawing properties to default.
Definition: px_gfx.c:213
void px_gfx_draw_update(void)
Update display with total area that has changed in display buffer.
Definition: px_gfx.c:197
void px_gfx_buf_clear(void)
Clear display buffer.
Definition: px_gfx.c:183
void px_gfx_draw_pixel(px_gfx_xy_t x, px_gfx_xy_t y)
Draw a pixel using the current foreground color.
Definition: px_gfx.c:266
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.
Definition: px_gfx.c:484
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.
Definition: px_gfx.c:465
void px_gfx_init(void)
Initialise graphics library.
Definition: px_gfx.c:177
px_gfx_color_t px_gfx_color_fg_set(px_gfx_color_t color)
Set the new foreground drawing color.
Definition: px_gfx.c:218
const px_gfx_font_t * px_gfx_font_set(const px_gfx_font_t *font)
Set the new font.
Definition: px_gfx.c:258
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.
Definition: px_gfx.c:421
@ PX_GFX_XY_REF_ABS
Coordinate references are absolute (relative to display)
Definition: px_gfx.h:143
@ PX_GFX_XY_REF_REL
Coordinate references are relative to view port.
Definition: px_gfx.h:142
@ PX_GFX_ALIGN_V_BOT
Vertical (y) bottom.
Definition: px_gfx.h:97
@ PX_GFX_ALIGN_H_LEFT
Horizontal (x) left.
Definition: px_gfx.h:98
@ PX_GFX_ALIGN_V_MID
Vertical (y) middle.
Definition: px_gfx.h:96
@ PX_GFX_ALIGN_H_MID
Horizontal (x) middle.
Definition: px_gfx.h:99
@ PX_GFX_ALIGN_V_TOP
Vertical (y) top.
Definition: px_gfx.h:95
@ PX_GFX_ALIGN_H_RIGHT
Horizontal (x) right.
Definition: px_gfx.h:100
Area definition.
Definition: px_gfx.h:132
Font definition.
Definition: px_gfx.h:124
Image definition.
Definition: px_gfx.h:116
View port definition.
Definition: px_gfx.h:148