Skip to content

Free games for graphing calculators: NumWorks, TI-Nspire CX, Casio fx-CG50 and soon TI-84 Plus CE. Balatro, Celeste, Hollow Knight, Minecraft and more.

3.4 KB
Raw Blame
/* Frames are drawn in horizontal strips: a scene function is called once per
 * strip and every primitive clips itself to the strip's rows. The whole screen
 * never has to fit in RAM. */
#ifndef NP_GFX_H
#define NP_GFX_H
#include "font.h"
#include "np.h"

#define STRIP_H 16
extern color_t *gfx_buf;     /* SCREEN_W x STRIP_H pixels */
extern int gfx_y0, gfx_y1;   /* rows of the strip being drawn */

typedef void (*gfx_scene_t)(void *ctx);
void gfx_init(void);         /* takes the strip buffer from the arena */
void gfx_render(gfx_scene_t scene, void *ctx, int y0, int y1);
#ifdef __TICE__
/* The TI-84 Plus CE draws a strip only when its list of gfx_* calls changed: the scene runs with gfx_listing
 * set to list them, once for each strip, or once for all when gfx_pure says it draws only with gfx_*. Drawing of
 * a scene's own adds what it depends on, or makes its strips drawn every time (platform/ti84ce/gfx_ce.c). */
extern bool gfx_listing, gfx_pure;
void gfx_list(const void *p, unsigned bytes);
void gfx_list_always(void);
void gfx_list_rows(int top, int bottom); /* the strips over these rows: drawn every time */
/* fn(a) draws (with gfx_*) in the box x, y, w, h what a[0..n) say (8 at most): one call in the strips' lists */
void gfx_call(void (*fn)(const int *a), const int *a, int n, int x, int y, int w, int h);
#endif

color_t gfx_mix(color_t a, color_t b, int t32);   /* t32 = 0..32 */
color_t gfx_rgb(uint32_t rgb888);
uint32_t gfx_lerp888(uint32_t a, uint32_t b, int t256);

void gfx_fill(int x, int y, int w, int h, color_t c);
void gfx_fill_alpha(int x, int y, int w, int h, color_t c, int a256);
void gfx_vgrad(int x, int y, int w, int h, uint32_t top, uint32_t bottom);
void gfx_rrect(int x, int y, int w, int h, int r, color_t c, int a256);
void gfx_rrect_outline(int x, int y, int w, int h, int r, int t, color_t c, int a256);
void gfx_shadow(int x, int y, int w, int h, int r, int blur, int a256);
void gfx_circle(int cx, int cy, int r, color_t c, int a256);
/* Palette image scaled into (dx, dy, dw, dh), with rounded corners. `dim`
 * darkens it (0..256). */
void gfx_image(const uint8_t *idx, const color_t *pal, int ncolors, int sw, int sh, int dx, int dy, int dw, int dh,
               int radius, int dim);
void gfx_mask(const uint8_t *mask, int w, int h, int x, int y, color_t c, int a256);
/* Paints the outside of the rounded corners of (x, y, w, h) with c. */
void gfx_corners(int x, int y, int w, int h, int r, color_t c);
/* Horizontal clip for gfx_image (defaults to the whole screen). */
extern int gfx_clip_x0, gfx_clip_x1;

int gfx_text(const np_font_t *f, int x, int baseline, const char *s, color_t c, int a256);
int gfx_text_width(const np_font_t *f, const char *s);
void gfx_text_center(const np_font_t *f, int cx, int baseline, const char *s, color_t c, int a256);
void gfx_text_right(const np_font_t *f, int rx, int baseline, const char *s, color_t c, int a256);
/* Word-wrapped paragraph, centred; returns the baseline after the last line. */
int gfx_paragraph(const np_font_t *f, int cx, int baseline, int width, int line, const char *s, color_t c, int a256);

/* Icons (icons.c, generated by tools/icongen.py): 4-bit masks. */
typedef struct {
  uint8_t w, h;
  const uint8_t *data;
} np_icon_t;
extern const np_icon_t np_icon_gear, np_icon_warning, np_icon_trash, np_icon_play, np_icon_check, np_icon_back,
    np_icon_left, np_icon_right, np_icon_logo, np_icon_heart;
void gfx_icon(const np_icon_t *icon, int x, int y, color_t c, int a256);
#endif