gfx.h (3063B)
1 /* gfx.h - renderer de pixeles portable (GUI de Linux, PicoCalc, tableros de la TUI). 2 * Dibuja sobre una Surface abstracta que solo sabe pintar tramos horizontales. */ 3 #ifndef COMUN_GFX_H 4 #define COMUN_GFX_H 5 6 #include <stdint.h> 7 #include <stdbool.h> 8 #include "input.h" 9 #include "lang.h" 10 #include "str.h" 11 12 typedef uint16_t Color; /* RGB565 */ 13 #define RGB(r, g, b) ((Color)((((r) & 0xF8) << 8) | (((g) & 0xFC) << 3) | ((b) >> 3))) 14 15 typedef struct Surface Surface; 16 struct Surface { 17 int w, h; 18 int cx0, cy0, cx1, cy1; /* recorte */ 19 int hy0, hy1; /* franja fija (PicoCalc dibuja por franjas) */ 20 void (*span)(Surface *s, int x, int y, int n, Color c); 21 void *user; 22 }; 23 24 typedef struct { int8_t w, h; const uint8_t *bits; } Font; 25 extern const Font font_small, font_normal, font_bold; 26 27 void surf_init(Surface *s, int w, int h, void (*span)(Surface *, int, int, int, Color), void *user); 28 void gfx_clip(Surface *s, int x, int y, int w, int h); 29 void gfx_noclip(Surface *s); 30 void gfx_band(Surface *s, int y0, int y1); /* limita todo el dibujo a esas filas */ 31 void gfx_rect(Surface *s, int x, int y, int w, int h, Color c); 32 void gfx_frame(Surface *s, int x, int y, int w, int h, Color c); 33 void gfx_poly16(Surface *s, const int32_t *xs, const int32_t *ys, int n, Color c); /* coords en 1/16 px */ 34 void gfx_line(Surface *s, int x0, int y0, int x1, int y1, int thick, Color c); 35 void gfx_disc(Surface *s, int cx, int cy, int r, Color c); 36 void gfx_ring(Surface *s, int cx, int cy, int r, int thick, Color c); 37 int gfx_text(Surface *s, const Font *f, int x, int y, const char *utf8, Color c); 38 int gfx_text_w(const Font *f, const char *utf8); 39 int gfx_text_fit(Surface *s, const Font *f, int x, int y, int maxw, const char *utf8, Color c); 40 int utf8_next(const char **s); /* devuelve codigo Latin-1 (o sustituto) */ 41 int isqrt(int v); 42 43 /* utilidades de interfaz */ 44 void gfx_box(Surface *s, int x, int y, int w, int h, Color bg, Color border); 45 int gfx_text_center(Surface *s, const Font *f, int x, int y, int w, const char *t, Color c); 46 Color gfx_dim(Color c); /* mitad de brillo */ 47 48 /* ------------------------------------------------------------- colores de interfaz */ 49 #define C_BLACK RGB(0, 0, 0) 50 #define C_WHITE RGB(255, 255, 255) 51 #define C_RED RGB(200, 30, 30) 52 #define C_OUTLINE RGB(24, 20, 16) 53 #define C_CURSOR RGB(255, 226, 0) 54 #define C_PANEL RGB(34, 38, 48) 55 #define C_PANEL2 RGB(48, 54, 68) 56 #define C_TEXT RGB(230, 230, 230) 57 #define C_DIM RGB(140, 146, 160) 58 #define C_ACCENT RGB(255, 200, 60) 59 #define C_ERR RGB(255, 90, 80) 60 #define C_OK RGB(110, 220, 110) 61 62 /* ------------------------------------------------------------- formularios */ 63 struct Form; 64 void gfx_form(Surface *s, const struct Form *f, HitList *hits); 65 /* Fondo y logo de los formularios, lo pone cada juego. Pinta toda la superficie y 66 * devuelve la fila desde la que se puede dibujar el cuadro. NULL: fondo liso. */ 67 extern int (*gfx_form_backdrop)(Surface *s, bool compact); 68 69 #endif