Files
esp-gfx/include/gfx.h
2026-08-07 10:20:12 +02:00

44 lines
1.6 KiB
C

#pragma once
#include <stdint.h>
#include <stdbool.h>
// compatibility for adafruit fonts
#ifndef PROGMEM
#define PROGMEM
#endif
typedef struct {
uint16_t bitmapOffset;
uint8_t width, height;
uint8_t xAdvance;
int8_t xOffset, yOffset;
} GFXglyph;
typedef struct {
const uint8_t *bitmap;
const GFXglyph *glyph;
uint8_t first, last;
uint8_t yAdvance;
} GFXfont;
/**
* @brief Canvas struct for the gfx library
* Functions take the context and x,y coordinates of a pixel
*
* @param ctx any context that the draw/clear functions might need, ie display device
* @param draw_pixel_callback function that gets called to draw a pixel
* @param clear_pixel_callback function that gets called to clear a pixel
*/
typedef struct {
void (*draw_pixel_callback)(void *ctx, uint8_t x, uint8_t y);
void (*clear_pixel_callback)(void *ctx, uint8_t x, uint8_t y);
void *ctx;
} gfx_canvas_t;
int16_t gfx_string_width(const GFXfont *f, const char *s);
int16_t gfx_draw_string(const gfx_canvas_t *canvas, const GFXfont* f, int16_t x, int16_t y, const char *s, bool inverted);
int16_t gfx_draw_string_centered(const gfx_canvas_t *canvas, const GFXfont *f, int16_t centerpoint, int16_t y, const char *s, bool inverted);
void gfx_draw_line(const gfx_canvas_t *canvas, uint8_t start_x, uint8_t start_y, uint8_t end_x, uint8_t end_y, bool inverted);
void gfx_draw_box(const gfx_canvas_t *canvas, uint8_t pos_x, uint8_t pos_y, uint8_t size_x, uint8_t size_y, bool inverted);
void gfx_fill_box(const gfx_canvas_t *canvas, uint8_t pos_x, uint8_t pos_y, uint8_t size_x, uint8_t size_y, bool inverted);