aboutsummaryrefslogtreecommitdiff
path: root/demo/fullcolor/fullcolor.ha
diff options
context:
space:
mode:
Diffstat (limited to 'demo/fullcolor/fullcolor.ha')
-rw-r--r--demo/fullcolor/fullcolor.ha59
1 files changed, 59 insertions, 0 deletions
diff --git a/demo/fullcolor/fullcolor.ha b/demo/fullcolor/fullcolor.ha
new file mode 100644
index 0000000..5d46c7c
--- /dev/null
+++ b/demo/fullcolor/fullcolor.ha
@@ -0,0 +1,59 @@
1use fmt;
2use tb = termbox2;
3
4fn paint_cell(x: size, y: size, c: tb::uattr) void =
5 tb::set_cell(x: int, y: int, ' ', tb::COLOR.DEFAULT, c)!;
6
7fn show_colors(wmin: size, hmin: size, wmax: size, hmax: size) void = {
8 tb::set_output_mode(tb::OUTPUT.TRUECOLOR)!;
9 tb::print(wmin: int, hmin: int, tb::COLOR.DEFAULT, tb::COLOR.DEFAULT,
10 "Color palette sample:")!;
11 hmin = hmin + 1;
12
13 let nsamples = (wmax - wmin +1) * (hmax - hmin + 1);
14 let step = 0xffffff / nsamples;
15 for (let y = hmin; y < hmax; y += 1) {
16 for (let x = wmin; x < wmax; x += 1) {
17 let c: tb::uattr = ((y - hmin) * wmax + (x - wmin)) * step;
18 paint_cell(x, y, c);
19 };
20 };
21};
22
23export fn main() int = {
24 let e = tb::init();
25 if (e is tb::err)
26 fmt::fatalf(tb::strerror(e as tb::err));
27 defer tb::shutdown()!;
28
29 let w = tb::width()!;
30 let h = tb::height()!;
31 tb::print(0, (h - 1): int, tb::COLOR.DEFAULT, tb::COLOR.DEFAULT,
32 "Press any key to exit")!;
33
34 switch (tb::OPT_ATTR_W) {
35 case 64 => show_colors(0, 0, w, h-1);
36 case => tb::print(0, ((h+1)/2): int, tb::COLOR.DEFAULT, tb::COLOR.DEFAULT,
37 "This demo is only available with truecolor support, here "
38 "tb::OPT_ATTR_W is {}", tb::OPT_ATTR_W)!;
39 };
40
41 for (true) {
42 let e = tb::present();
43 if (e is tb::err)
44 fmt::fatalf(tb::strerror(e as tb::err));
45 match (tb::poll_event()) {
46 case let e: tb::err => {
47 if (e == tb::ERR.NO_EVENT)
48 continue
49 else
50 tb::print(0, h:int -1,
51 tb::COLOR.DEFAULT, tb::COLOR.DEFAULT,
52 "Unexpected error {}!", tb::strerror(e))!;
53 };
54 case tb::key_event => break;
55 case (tb::mouse_event | tb::resize_event) => continue;
56 };
57 };
58 return 0;
59};

Generated with cgit - Back to sebastiano.tronto.net