2 |
2 |
3 |
3 |
4 class Application |
4 class Application |
5 { |
5 { |
6 public: |
6 public: |
7 Terminal term; |
7 Terminal term; |
8 bool done; |
8 bool done; |
9 |
9 |
10 Application() : term(), done(false) {}; |
10 Application() : term(), done(false) {}; |
11 |
11 |
12 void init(); |
12 void init(); |
13 void wait_and_process_event(); |
13 void wait_and_process_event(); |
14 }; |
14 }; |
15 |
15 |
16 |
16 |
17 void Application::init() |
17 void Application::init() |
18 { |
18 { |
19 term.resize(800, 600); |
19 term.resize(800, 600); |
20 term.select_font("font/DejaVuSansMono.ttf", "font/DejaVuSansMono-Bold.ttf", 12); |
20 term.select_font("font/DejaVuSansMono.ttf", "font/DejaVuSansMono-Bold.ttf", 12); |
21 term.erase(); |
21 term.erase(); |
22 term.set_attr( term.prepare_attr(14, 1, 1) ); |
22 term.set_attr( term.prepare_attr(14, 1, 1) ); |
23 |
23 |
24 char hello[] = "Hello World!"; |
24 char hello[] = "Hello World!"; |
25 for (char *c = hello; *c; c++) |
25 for (char *c = hello; *c; c++) |
26 { |
26 { |
27 term.putch(5 + (c - hello), 5, *c); |
27 term.putch(5 + (c - hello), 5, *c); |
28 } |
28 } |
29 term.commit(); |
29 term.commit(); |
30 } |
30 } |
31 |
31 |
32 |
32 |
33 void Application::wait_and_process_event() |
33 void Application::wait_and_process_event() |
34 { |
34 { |
35 Event event; |
35 Event event; |
36 term.get_next_event(event); |
36 term.get_next_event(event); |
37 |
37 |
38 switch (event.type) |
38 switch (event.type) |
39 { |
39 { |
40 case Event::QUIT: |
40 case Event::QUIT: |
41 done = true; |
41 done = true; |
42 break; |
42 break; |
43 |
43 |
44 default: |
44 default: |
45 break; |
45 break; |
46 } |
46 } |
47 } |
47 } |
48 |
48 |
49 |
49 |
50 int main(int argc, char *argv[]) |
50 int main(int argc, char *argv[]) |
51 { |
51 { |
52 Application app; |
52 Application app; |
53 app.init(); |
53 app.init(); |
54 |
54 |
55 while (!app.done) |
55 while (!app.done) |
56 { |
56 { |
57 app.wait_and_process_event(); |
57 app.wait_and_process_event(); |
58 } |
58 } |
59 |
59 |
60 return 0; |
60 return 0; |
61 } |
61 } |
62 |
62 |