author | Radek Brich <radek.brich@devl.cz> |
Wed, 30 Jan 2013 00:38:48 +0100 | |
changeset 71 | cfd3445107b4 |
parent 57 | 911927edbdde |
permissions | -rw-r--r-- |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
1 |
#include "sdlterm.h" |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
2 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
3 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
4 |
class Application |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
5 |
{ |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
6 |
public: |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
7 |
Terminal term; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
8 |
bool done; |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
9 |
|
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
10 |
Application() : term(), done(false) {}; |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
11 |
|
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
12 |
void init(); |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
13 |
void wait_and_process_event(); |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
14 |
}; |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
15 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
16 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
17 |
void Application::init() |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
18 |
{ |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
19 |
term.resize(800, 600); |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
20 |
term.select_font("font/DejaVuSansMono.ttf", "font/DejaVuSansMono-Bold.ttf", 12); |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
21 |
term.erase(); |
50
c5b8b9d2da95
DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
22 |
|
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
23 |
char hello[] = "Hello World!"; |
52
50a1857557da
Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents:
51
diff
changeset
|
24 |
for (int bg = 0; bg < 16; bg++) |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
25 |
{ |
52
50a1857557da
Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents:
51
diff
changeset
|
26 |
for (int fg = 0; fg < 16; fg++) |
50a1857557da
Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents:
51
diff
changeset
|
27 |
{ |
50a1857557da
Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents:
51
diff
changeset
|
28 |
for (char *c = hello; *c; c++) |
50a1857557da
Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents:
51
diff
changeset
|
29 |
{ |
50a1857557da
Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents:
51
diff
changeset
|
30 |
term.set_attr( term.prepare_attr(fg, bg, 1) ); |
50a1857557da
Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents:
51
diff
changeset
|
31 |
term.putch(5 + 6 * bg + (c - hello), 5 + fg, *c); |
50a1857557da
Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents:
51
diff
changeset
|
32 |
} |
50a1857557da
Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents:
51
diff
changeset
|
33 |
} |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
34 |
} |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
35 |
term.commit(); |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
36 |
} |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
37 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
38 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
39 |
void Application::wait_and_process_event() |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
40 |
{ |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
41 |
Event event; |
57
911927edbdde
DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
42 |
term.wait_event(event, 0); |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
43 |
|
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
44 |
switch (event.type) |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
45 |
{ |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
46 |
case Event::QUIT: |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
47 |
done = true; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
48 |
break; |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
49 |
|
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
50 |
default: |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
51 |
break; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
52 |
} |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
53 |
} |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
54 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
55 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
56 |
int main(int argc, char *argv[]) |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
57 |
{ |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
58 |
Application app; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
59 |
app.init(); |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
60 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
61 |
while (!app.done) |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
62 |
{ |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
63 |
app.wait_and_process_event(); |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
64 |
} |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
65 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
66 |
return 0; |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
67 |
} |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
68 |