diff options
| author | WormHeamer | 2025-11-06 22:58:25 -0500 |
|---|---|---|
| committer | WormHeamer | 2025-11-06 22:58:25 -0500 |
| commit | d7479de95b8c4e8ada7db3676424fb0b2e1713cf (patch) | |
| tree | c12c6a7c0252397442934adce78c83abf74c7062 /vui.h | |
| parent | 1f31f94c16eab34b931cc8a8973a36a78ea74046 (diff) | |
separate vui.c, vui.h
Diffstat (limited to 'vui.h')
| -rw-r--r-- | vui.h | 144 |
1 files changed, 144 insertions, 0 deletions
@@ -0,0 +1,144 @@ +#ifndef VUI_H +#define VUI_H + +#include <stdarg.h> + +#include "wrmr.h" + +typedef enum { + KEY_EOF = 0, + KEY_BKSP = 0x08, + KEY_RET = 0x0d, + KEY_ESC = 0x1b, + KEY_DEL = 0x7f, + KEY_UTF8_MAX = 0x10ffff, + + KEY_LEFT, KEY_RIGHT, KEY_UP, KEY_DOWN, + KEY_HOME, KEY_END, KEY_PGUP, KEY_PGDN, + + KEY_F1, KEY_F2, KEY_F3, KEY_F4, + KEY_F5, KEY_F6, KEY_F7, KEY_F8, + KEY_F9, KEY_F10, KEY_F11, KEY_F12, + + KEY_SHIFT_BIT = 0x200000, + KEY_CTRL_BIT = 0x400000, + KEY_ALT_BIT = 0x800000, + KEY_META_BIT = 0x1000000, + KEY_INVALID = 0x7fffffff, + + KEY_CTRL_MASK = 0xe000000, + KEY_BASE_MASK = ~KEY_CTRL_MASK, +} VuiKey; + +typedef enum { + FG_BLACK = 0, + FG_RED = 1, + FG_GREEN = 2, + FG_YELLOW = 3, + FG_BLUE = 4, + FG_MAGENTA = 5, + FG_CYAN = 6, + FG_WHITE = 7, + + FG_BBLACK = FG_BLACK + 8, + FG_BRED = FG_RED + 8, + FG_BGREEN = FG_GREEN + 8, + FG_BYELLOW = FG_YELLOW + 8, + FG_BBLUE = FG_BLUE + 8, + FG_BMAGENTA = FG_MAGENTA + 8, + FG_BCYAN = FG_CYAN + 8, + FG_BWHITE = FG_WHITE + 8, + + BG_BLACK = FG_BLACK << 4, + BG_RED = FG_RED << 4, + BG_GREEN = FG_GREEN << 4, + BG_YELLOW = FG_YELLOW << 4, + BG_BLUE = FG_BLUE << 4, + BG_MAGENTA = FG_MAGENTA << 4, + BG_CYAN = FG_CYAN << 4, + BG_WHITE = FG_WHITE << 4, + + BG_BBLACK = FG_BBLACK << 4, + BG_BRED = FG_BRED << 4, + BG_BGREEN = FG_BGREEN << 4, + BG_BYELLOW = FG_BYELLOW << 4, + BG_BBLUE = FG_BBLUE << 4, + BG_BMAGENTA = FG_BMAGENTA << 4, + BG_BCYAN = FG_BCYAN << 4, + BG_BWHITE = FG_BWHITE << 4, + + A_BOLD = 1 << 8, + A_DIM = 1 << 9, + A_ITALIC = 1 << 10, + A_UNDERSCORE = 1 << 11, + A_BLINK = 1 << 12, + A_REVERSE = 1 << 13, +} VuiAttr; + +#define ATTR_FG(a) ((a) & 0xf) +#define ATTR_BG(a) (((a)>>4) & 0xf) +#define ATTR_A(a) ((a) & ~0xff) +#define ATTR_DEFAULT (FG_WHITE | BG_BLACK) + +typedef uint32_t VuiChar; + +typedef struct { + unsigned width, height; + VuiChar *chr; + uint16_t *attr; +} VuiBuffer; + +typedef struct { + unsigned width, height; + VuiBuffer buf1, buf2; + VuiBuffer *front, *back; + void (*redraw_fn)(void *ctx); + void *redraw_ctx; + int redraw_all; + int scroll_x, scroll_y; + int curs_vis, curs_x, curs_y; +} VuiWindow; + +VuiWindow *vui_win(void); + +#define LINES (vui_win()->height) +#define COLS (vui_win()->width) + +#define BCHR(b,x,y) ((b)->chr[(x) + (y) * (b)->width]) +#define BATTR(b,x,y) ((b)->attr[(x) + (y) * (b)->width]) +#define CHR(x,y) BCHR(vui_win()->front, x, y) +#define ATTR(x,y) BATTR(vui_win()->front, x, y) + +void vui_init(void); +void vui_fini(void); + +void vui_blit(void); +void vui_clear(void); +void vui_scroll(int dx, int dy); + +void vui_chr(int x, int y, VuiChar c); +void vui_chra(int x, int y, VuiChar c, VuiAttr a); + +void vui_puts(int x, int y, const char *s); +void vui_putsa(int x, int y, const char *s, VuiAttr a); +void vui_putsn(int x, int y, const char *s, unsigned n); +void vui_putsna(int x, int y, const char *s, unsigned n, VuiAttr a); + +int vui_avprintf(int x, int y, VuiAttr a, const char *fmt, va_list ap); +int vui_aprintf(int x, int y, VuiAttr a, const char *fmt, ...); +int vui_printf(int x, int y, const char *fmt, ...); + +void vui_fill(VuiChar c, VuiAttr a); +void vui_fill_rect(VuiChar c, VuiAttr a, int x0, int y0, int width, int height); + +void vui_curs_vis(int vis); +void vui_curs_pos(int x, int y); + +void vui_redraw_fn(void (*fn)(void *ctx)); +void vui_redraw_ctx(void *ctx); + +int vui_wait_for_input(int ms); +int vui_has_input(void); +VuiKey vui_key(void); + +#endif |
