aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / native / kernel / ui / canvas.h
| 1 | /* canvas.h -- Allen's canvas, the light side: what a scene (svc/allen_scene.h) |
| 2 | * says is shown, painted into the night round Allen in his own style. |
| 3 | * |
| 4 | * Nothing here is a window. A thing is light and type on the sky: a soft |
| 5 | * pool of shade behind its words (no edge, no frame), a thread of light down |
| 6 | * its side, Allen's stroke typeface; a number is drawn large in thin strokes, |
| 7 | * a timer is a ring of light that empties, a person is a ring round their |
| 8 | * initial, a picture or a video still on its way is a place of gathering |
| 9 | * light. Allen stays alone in the centre; things sit to his left and right |
| 10 | * or above him, at most CK_SCENE_THINGS at once. |
| 11 | * |
| 12 | * Every change eases in: by default a spark leaves Allen's heart, flies to |
| 13 | * where the thing will be, touches the water there, and the thing opens line |
| 14 | * by line (bloom); `rise` floats up, `fade` simply comes. A new scene sends |
| 15 | * the old things away over 0.7 s while the new ones come; the sky's tone |
| 16 | * blends over 0.7 s. Nothing cuts. |
| 17 | * |
| 18 | * Integer only (16.16 and 1/256 steps), freestanding, no allocation (one |
| 19 | * static pool for the large digits). ck_allen_canvas_at moves it on (one |
| 20 | * caller, between frames); ck_allen_canvas_draw only reads, so several |
| 21 | * cores can draw different parts of the screen at once. Host tested in |
| 22 | * ui/tests/canvas_test.c. */ |
| 23 | #ifndef AIENOS_CANVAS_H |
| 24 | #define AIENOS_CANVAS_H |
| 25 | #include <stddef.h> |
| 26 | #include <stdint.h> |
| 27 | |
| 28 | #include "../svc/allen_scene.h" |
| 29 | #include "allen_font.h" |
| 30 | #include "flow.h" |
| 31 | #include "paint.h" |
| 32 | |
| 33 | #define CK_CANVAS_SLOTS (2u * CK_SCENE_THINGS) /* the things here now, and those on their way out */ |
| 34 | #define CK_CANVAS_TEXT 512u |
| 35 | #define CK_CANVAS_ROWS 12u |
| 36 | #define CK_CANVAS_HOLD_MS 90000u /* a thing left alone this long goes on its own (a running timer stays) */ |
| 37 | |
| 38 | /* One line of type in a thing: which face and colour, where its baseline sits. */ |
| 39 | typedef struct { |
| 40 | uint16_t off, len; /* in the thing's text */ |
| 41 | int32_t dx, dy; /* from the thing's top left to the line's start and baseline, px */ |
| 42 | uint8_t face, role; /* face: 0 voice, 1 body, 2 small, 3 large digits; role: 0 text, 1 mist, 2 hint, 3 warm */ |
| 43 | uint8_t dot; /* a point of light before it (a list's items) */ |
| 44 | } ck_canvas_row; |
| 45 | |
| 46 | typedef struct { |
| 47 | uint8_t live, kind, warm, quiet, arrive, way, nf, nrows, landed; |
| 48 | uint16_t f[CK_SCENE_FIELDS]; |
| 49 | char text[CK_CANVAS_TEXT]; |
| 50 | uint16_t used, base; /* text used; where the fields end (a lay-out adds after them) */ |
| 51 | ck_canvas_row row[CK_CANVAS_ROWS]; |
| 52 | int32_t x, y, w, h; /* its own area, px */ |
| 53 | int32_t rx, ry, rr; /* a ring (timer, person) or the picture's place (rx, ry, w x rr), px; rr 0: none */ |
| 54 | ck_rect box; /* all it may light, px */ |
| 55 | ck_rect spark_was; /* where its spark was drawn last frame */ |
| 56 | int32_t ax, ay; /* where its spark lands, 16ths of a pixel */ |
| 57 | uint32_t born, gone; /* ms; gone 0 while it stays */ |
| 58 | uint32_t dur; /* a timer's length, ms (0: a clock time, shown as written) */ |
| 59 | uint32_t tq; /* the moment its moving part (a timer's ring, a picture's light) is drawn at, ms */ |
| 60 | } ck_canvas_item; |
| 61 | |
| 62 | typedef struct { |
| 63 | int32_t w, h, cx, cy; |
| 64 | uint32_t k; |
| 65 | ck_af_face *voice, *body, *small; |
| 66 | ck_af_face big; |
| 67 | ck_canvas_item item[CK_CANVAS_SLOTS]; |
| 68 | uint8_t tone_from, tone_to, water; |
| 69 | uint32_t tone_t, tone_w; /* the tone's blend began at tone_t; how far it is, 0..256 */ |
| 70 | uint32_t stir_t, t; |
| 71 | int32_t hx, hy; /* Allen's heart now, 16ths of a pixel */ |
| 72 | uint32_t shown, dropped; |
| 73 | } ck_allen_canvas; |
| 74 | |
| 75 | /* A w x h screen at scale k (1/256 px per design px on 1920 x 1080), Allen at |
| 76 | * (cx, cy); his three faces are borrowed (already rasterized: drawing never |
| 77 | * writes to them). 0, or -1 when the large digits do not fit their pool. */ |
| 78 | int ck_allen_canvas_init(ck_allen_canvas *c, int32_t w, int32_t h, uint32_t k, int32_t cx, int32_t cy, |
| 79 | ck_af_face *voice, ck_af_face *body, ck_af_face *small); |
| 80 | /* A new scene from time t: what is here goes, its things come. */ |
| 81 | void ck_allen_canvas_show(ck_allen_canvas *c, const ck_scene *s, uint32_t t); |
| 82 | /* Everything goes (the guest started a new line). */ |
| 83 | void ck_allen_canvas_clear(ck_allen_canvas *c, uint32_t t); |
| 84 | /* Moves to t; (hx, hy) is Allen's heart (16ths of a pixel); touches the water |
| 85 | * (flow may be NULL); calls mark for every part of the screen that changes. */ |
| 86 | void ck_allen_canvas_at(ck_allen_canvas *c, uint32_t t, int32_t hx, int32_t hy, ck_flow *flow, void (*mark)(ck_rect)); |
| 87 | /* The sky's tone and the things, into the part r of cv (after the sky and the water, before Allen). */ |
| 88 | void ck_allen_canvas_draw(const ck_allen_canvas *c, ck_canvas *cv, const ck_rect *r); |
| 89 | /* Things on the screen now (arriving or staying, not leaving). */ |
| 90 | unsigned ck_allen_canvas_count(const ck_allen_canvas *c); |
| 91 | #endif |