#include "tim.h" static inline void test_screen(TimEvent* e) { static TimEvent me; static TimEvent ke; static i32 render_us; char buf[64]; ke = (e->type == KEY_EVENT) ? *e : ke; me = (e->type == MOUSE_EVENT) ? *e : me; // positioning tim_label("+", 0, 0, A, A, 0xf); tim_label("+", ~0, 0, A, A, 0xf); tim_label("+", 0, ~0, A, A, 0xf); tim_label("+", ~0, ~0, A, A, 0xf); tim_label("+", A, A, A, A, 0xf); tim_label("-", 0, A, A, A, 0xf); tim_label("-", ~0, A, A, A, 0xf); tim_label("|", A, 0, A, A, 0xf); tim_label("|", A, ~0, A, A, 0xf); // some information sprintf(buf, "screen: %dx%d", tim->w, tim->h); tim_label(buf, 2, 0, A, A, 0xf); sprintf(buf, "frame : [%c] %d", ": "[tim->frame & 1], tim->frame); tim_label(buf, 2, 1, A, A, 0xf); sprintf(buf, "key : [%d] %s", ke.key, ke.s + (ke.key < 32)); tim_label(buf, 2, 2, A, A, 0xf); sprintf(buf, "mouse : [%d] %d:%d", me.key, me.x, me.y); tim_label(buf, 2, 3, A, A, 0xf); sprintf(buf, "input : %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx %02hhx", e->s[0], e->s[1], e->s[2], e->s[3], e->s[4], e->s[5], e->s[6], e->s[7]); tim_label(buf, 2, 4, A, A, 0xf); // lower right render_us += tim->render_us; sprintf(buf, "%d µs (Ø %d µs)", tim->render_us, render_us / MAX(tim->frame, 1)); tim_label(buf, ~2, ~2, A, A, 0xf); sprintf(buf, "%d cells (%.0f %%)", tim->w * tim->h, 100.0 * tim->w * tim->h / TIM_MAX_CELLS); tim_label(buf, ~2, ~1, A, A, 0xf); sprintf(buf, "%d bytes (%.0f %%)", tim->buf_size, 100.0 * tim->buf_size / TIM_MAX_BUF); tim_label(buf, ~2, ~0, A, A, 0xf); // multi line label tim_label("multi\nliñe\nlabël", 24, 1, A, A, 0xf); // colors tim_scope(1, 5, 16, 5) { tim_frame(0, 0, ~0, ~0, 0xf); tim_label(" Red ", 1, 1, 7, A, 0x0900); tim_label(" ", 8, 1, 7, A, 0xc400); tim_label(" Green ", 1, 2, 7, A, 0x0a00); tim_label(" ", 8, 2, 7, A, 0x2e00); tim_label(" Blue ", 1, 3, 7, A, 0x0c00); tim_label(" ", 8, 3, 7, A, 0x1500); } // button static u64 bc = 0x100; if (tim_button("Click Me", 17, 5, 16, 5, bc)) { bc = (bc + 0x100) & 0xff00; } // edit static TimEditState ed1; static TimEditState ed2; TimEditState_init(&ed1, 32, "Edit 1"); TimEditState_init(&ed2, 32, ""); tim_edit(&ed1, 1, 10, 32, 0xff00ff); sprintf(buf, "cursor: %d length: %d", ed1.cursor, ed1.length); tim_label(buf, 2, 13, A, A, 0xf); tim_edit(&ed2, 1, 14, 32, 0xff00ff); tim_label(ed2.s, 2, 17, A, A, 0xf); // checkbox static i32 chk[2] = {-1, 1}; tim_checkbox("Check 1", &chk[0], 1, 18, A, 0xa000f); tim_checkbox("Check 2", &chk[1], 14, 18, A, 0xa000f); // radiobox static i32 rad = 0; tim_radiobutton("Radio 1", &rad, 1, 1, 19, A, 0xa000f); tim_radiobutton("Radio 2", &rad, 2, 14, 19, A, 0xa000f); tim_radiobutton("Radio 3", &rad, 3, 1, 20, A, 0xa000f); tim_radiobutton("Radio 4", &rad, 4, 14, 20, A, 0xa000f); // scope nesting tim_scope(~1, 1, 20, 10) { tim_scope(0, 0, 10, 5) { tim_frame(0, 0, ~0, ~0, 0x9); } tim_scope(~0, 0, 10, 5) { tim_frame(0, 0, ~0, ~0, 0xa); } tim_scope(~0, ~0, 10, 5) { tim_frame(0, 0, ~0, ~0, 0xb); } tim_scope(0, ~0, 10, 5) { tim_frame(0, 0, ~0, ~0, 0xc); } } // funny characters tim_scope(~1, ~3, 11, 5) { tim_frame(0, 0, ~0, ~0, 0xf); tim_label("123456789", 1, 1, 9, A, 0x0f05); tim_label("$£ह€𐍈6789", 1, 2, A, A, 0x0f05); tim_label("圍棋56789", 1, 3, A, A, 0x0f05); } } i32 main(void) { while (tim_run(1.5)) { test_screen(&tim->event); if (tim_is_key_press('q') || tim_is_key_press(TimKey_Escape)) { break; } } }