author | Radek Brich <radek.brich@devl.cz> |
Tue, 08 Jan 2013 23:36:01 +0100 | |
changeset 58 | 50308ed5e4f9 |
parent 57 | 911927edbdde |
child 60 | fccca2a60492 |
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 "SDL.h" |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
2 |
#include "SDL_ttf.h" |
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 |
#include <map> |
58
50308ed5e4f9
sdlterm: Cleanup exceptions.
Radek Brich <radek.brich@devl.cz>
parents:
57
diff
changeset
|
5 |
#include <string> |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
6 |
#include <vector> |
58
50308ed5e4f9
sdlterm: Cleanup exceptions.
Radek Brich <radek.brich@devl.cz>
parents:
57
diff
changeset
|
7 |
#include <exception> |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
8 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
9 |
|
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
|
10 |
namespace Style |
50
c5b8b9d2da95
DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
11 |
{ |
54
86b84535726e
DriverSDL: system font lookup.
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
12 |
enum { |
86b84535726e
DriverSDL: system font lookup.
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
13 |
BOLD = 1 << 0, // bold font |
86b84535726e
DriverSDL: system font lookup.
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
14 |
UNDERLINE = 1 << 1, // underline text |
86b84535726e
DriverSDL: system font lookup.
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
15 |
STANDOUT = 1 << 2, // inverse bg/fg |
86b84535726e
DriverSDL: system font lookup.
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
16 |
BLINK = 1 << 3, // blinking |
86b84535726e
DriverSDL: system font lookup.
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
17 |
}; |
50
c5b8b9d2da95
DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
18 |
}; |
c5b8b9d2da95
DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
19 |
|
c5b8b9d2da95
DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
20 |
|
c5b8b9d2da95
DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
21 |
class ColorMap |
c5b8b9d2da95
DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
22 |
{ |
c5b8b9d2da95
DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
23 |
private: |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
24 |
Uint8 _map[16][3] = { |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
25 |
{0,0,0}, // 0 - black |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
26 |
{23,23,178}, // 1 - blue |
50
c5b8b9d2da95
DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
27 |
{23,178,23}, // 2 - green |
c5b8b9d2da95
DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
28 |
{23,178,178}, // 3 - cyan |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
29 |
{178,23,23}, // 4 - red |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
30 |
{178,23,178}, // 5 - magenta |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
31 |
{178,103,23}, // 6 - brown |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
32 |
{178,178,178}, // 7 - light gray |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
33 |
{104,104,104}, // 8 - gray |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
34 |
{84,84,255}, // 9 - light blue |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
35 |
{84,255,84}, // 10 - light green |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
36 |
{84,255,255}, // 11 - light cyan |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
37 |
{255,84,84}, // 12 - light red |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
38 |
{255,84,255}, // 13 - light magenta |
50
c5b8b9d2da95
DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
39 |
{255,255,84}, // 14 - yellow |
c5b8b9d2da95
DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
40 |
{255,255,255}, // 15 - white |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
41 |
}; |
50
c5b8b9d2da95
DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
42 |
|
c5b8b9d2da95
DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
43 |
public: |
53
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
44 |
void index_to_rgb(int index, SDL_Color &color) const; |
50
c5b8b9d2da95
DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
45 |
}; |
c5b8b9d2da95
DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
46 |
|
c5b8b9d2da95
DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
47 |
|
48
1f00e90fd72a
Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents:
47
diff
changeset
|
48 |
class GlyphCache |
1f00e90fd72a
Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents:
47
diff
changeset
|
49 |
{ |
1f00e90fd72a
Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents:
47
diff
changeset
|
50 |
public: |
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
|
51 |
// lookup glyph in cache, id is combined char and attr |
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
|
52 |
SDL_Surface *lookup_glyph(Uint64 id); |
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
|
53 |
void put_glyph(Uint64 id, SDL_Surface *srf); |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
54 |
void flush(); |
48
1f00e90fd72a
Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents:
47
diff
changeset
|
55 |
|
1f00e90fd72a
Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents:
47
diff
changeset
|
56 |
private: |
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
|
57 |
std::map<Uint64, SDL_Surface*> _glyph_map; |
48
1f00e90fd72a
Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents:
47
diff
changeset
|
58 |
}; |
1f00e90fd72a
Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents:
47
diff
changeset
|
59 |
|
1f00e90fd72a
Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents:
47
diff
changeset
|
60 |
|
54
86b84535726e
DriverSDL: system font lookup.
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
61 |
/* TTF font glyph renderer |
86b84535726e
DriverSDL: system font lookup.
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
62 |
* |
86b84535726e
DriverSDL: system font lookup.
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
63 |
* Renders uniformly sized cells with single character. |
86b84535726e
DriverSDL: system font lookup.
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
64 |
* Wraps SDL_ttf functions, see its documentation here: |
86b84535726e
DriverSDL: system font lookup.
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
65 |
* |
86b84535726e
DriverSDL: system font lookup.
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
66 |
* http://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html |
86b84535726e
DriverSDL: system font lookup.
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
67 |
* |
86b84535726e
DriverSDL: system font lookup.
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
68 |
*/ |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
69 |
class GlyphRenderer |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
70 |
{ |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
71 |
public: |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
72 |
GlyphRenderer(); |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
73 |
~GlyphRenderer(); |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
74 |
|
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
75 |
void open_font(const char *fname_regular, const char *fname_bold, int ptsize); |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
76 |
void close_font(); |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
77 |
|
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
78 |
// do not free surface returned! |
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
|
79 |
SDL_Surface *render_cell(Uint32 ch, Uint32 attr); |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
80 |
|
53
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
81 |
int get_cell_width() const { return _cell_width; }; |
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
82 |
int get_cell_height() const { return _cell_height; }; |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
83 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
84 |
private: |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
85 |
TTF_Font *_font_regular; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
86 |
TTF_Font *_font_bold; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
87 |
int _cell_width; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
88 |
int _cell_height; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
89 |
GlyphCache _cache; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
90 |
ColorMap _colormap; |
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
|
91 |
|
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
|
92 |
void _render_glyph(SDL_Surface *cell_surface, TTF_Font *font, Uint32 ch, |
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
|
93 |
SDL_Color fgcolor, SDL_Color bgcolor); |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
94 |
}; |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
95 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
96 |
|
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
|
97 |
/* One cell of terminal window |
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
|
98 |
* |
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
|
99 |
* Each cell contains one character, its color and attributes. |
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
|
100 |
* Character is encoded in 32bit unicode. |
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
|
101 |
* Other 32 bits are attributes: |
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
|
102 |
* 0-7 (8b) - foreground color index |
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
|
103 |
* 8-15 (8b) - background color index |
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
|
104 |
* 16-23 (8b) - RESERVED for alpha channel |
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
|
105 |
* 24 (1b) - bold font |
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
|
106 |
* 25 (1b) - underline |
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
|
107 |
* 26 (1b) - standout (swap fg/bg color) |
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
|
108 |
* 27 (1b) - blink |
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
|
109 |
* 28-31 (4b) - RESERVED |
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
|
110 |
*/ |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
111 |
struct TerminalCell |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
112 |
{ |
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
|
113 |
Uint32 ch; |
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
|
114 |
Uint32 attr; |
53
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
115 |
|
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
116 |
TerminalCell() : ch(0), attr(7) {}; |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
117 |
bool operator !=(const TerminalCell &rhs) const { return ch != rhs.ch || attr != rhs.attr; }; |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
118 |
}; |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
119 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
120 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
121 |
class TerminalScreen |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
122 |
{ |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
123 |
public: |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
124 |
TerminalScreen(): |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
125 |
_screen_surface(NULL), _cells_front(0), _cells_back(0), _render(), |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
126 |
_pixel_width(0), _pixel_height(0), _width(0), _height(0), |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
127 |
_cell_width(0), _cell_height(0) {}; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
128 |
~TerminalScreen() {}; |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
129 |
|
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
130 |
void select_font(const char *fname_regular, const char *fname_bold, int ptsize); |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
131 |
void resize(int pxwidth, int pxheight); |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
132 |
|
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
133 |
void erase(); |
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
|
134 |
void putch(int x, int y, Uint32 ch, Uint32 attr); |
53
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
135 |
void toggle_cursor(int x, int y); |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
136 |
void commit(); |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
137 |
|
53
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
138 |
// force full redraw on next commit() |
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
139 |
void redraw(); |
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
140 |
|
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
141 |
int get_width() const { return _width; }; |
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
142 |
int get_height() const { return _height; }; |
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
143 |
int get_cell_width() const { return _cell_width; }; |
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
144 |
int get_cell_height() const { return _cell_height; }; |
48
1f00e90fd72a
Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents:
47
diff
changeset
|
145 |
|
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
146 |
private: |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
147 |
SDL_Surface *_screen_surface; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
148 |
std::vector<TerminalCell> _cells_front; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
149 |
std::vector<TerminalCell> _cells_back; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
150 |
GlyphRenderer _render; |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
151 |
|
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
152 |
int _pixel_width; // terminal window width in pixels |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
153 |
int _pixel_height; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
154 |
int _width; // width in characters |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
155 |
int _height; // height in characters |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
156 |
int _cell_width; // character cell width in pixels |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
157 |
int _cell_height; |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
158 |
|
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
159 |
void _reset_cells(); |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
160 |
}; |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
161 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
162 |
|
48
1f00e90fd72a
Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents:
47
diff
changeset
|
163 |
struct Event |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
164 |
{ |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
165 |
enum { QUIT, RESIZE, KEYPRESS, MOUSEDOWN, MOUSEUP, MOUSEMOVE, MOUSEWHEEL }; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
166 |
int type; |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
167 |
|
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
168 |
union |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
169 |
{ |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
170 |
struct |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
171 |
{ |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
172 |
char keyname[10]; |
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
|
173 |
Uint32 unicode; |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
174 |
} key; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
175 |
struct |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
176 |
{ |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
177 |
int x, y; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
178 |
int button; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
179 |
} mouse; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
180 |
}; |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
181 |
}; |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
182 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
183 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
184 |
class Terminal |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
185 |
{ |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
186 |
public: |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
187 |
Terminal(); |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
188 |
~Terminal(); |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
189 |
|
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
190 |
void select_font(const char *fname_regular, const char *fname_bold, int ptsize) |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
191 |
{ _screen.select_font(fname_regular, fname_bold, ptsize); }; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
192 |
void resize(int pxwidth, int pxheight) { _screen.resize(pxwidth, pxheight); }; |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
193 |
|
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
194 |
void erase() { _screen.erase(); }; |
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
|
195 |
void putch(int x, int y, Uint32 ch) { _screen.putch(x, y, ch, _attr); }; |
53
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
196 |
void commit(); |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
197 |
|
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
|
198 |
Uint32 prepare_attr(Uint8 fg, Uint8 bg, Uint8 style) { return (Uint32)fg | (Uint32)bg << 8 | (Uint32)style << 24; }; |
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
|
199 |
void set_attr(Uint32 value) { _attr = value; }; |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
200 |
|
53
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
201 |
void show_cursor(int x, int y) { _cursor_x = x; _cursor_y = y; _cursor_visible = true; }; |
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
202 |
void hide_cursor() { _cursor_visible = false; }; |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
203 |
|
57
911927edbdde
DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents:
54
diff
changeset
|
204 |
/* Wait for an event. |
911927edbdde
DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents:
54
diff
changeset
|
205 |
* |
911927edbdde
DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents:
54
diff
changeset
|
206 |
* Timeout is in miliseconds, zero means wait indefinitely. |
911927edbdde
DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents:
54
diff
changeset
|
207 |
* Returns false on timeout, true on event. |
911927edbdde
DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents:
54
diff
changeset
|
208 |
*/ |
911927edbdde
DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents:
54
diff
changeset
|
209 |
bool wait_event(Event &event, Uint32 timeout); |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
210 |
|
53
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
211 |
int get_width() const { return _screen.get_width(); }; |
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
212 |
int get_height() const { return _screen.get_height(); }; |
48
1f00e90fd72a
Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents:
47
diff
changeset
|
213 |
|
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
214 |
private: |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
215 |
TerminalScreen _screen; |
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
|
216 |
Uint32 _attr; |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
217 |
int _cursor_x; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
218 |
int _cursor_y; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
219 |
bool _cursor_visible; |
48
1f00e90fd72a
Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents:
47
diff
changeset
|
220 |
|
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
221 |
int _mousemove_last_x; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
222 |
int _mousemove_last_y; |
49
1611c462c3e3
Update sdlterm: Optimize commit() - use two cell buffers, redraw only dirty cells, not everything. Fix keypress event, filter mousemove.
Radek Brich <radek.brich@devl.cz>
parents:
48
diff
changeset
|
223 |
|
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
224 |
const char *_translate_keyname(SDLKey sym); |
57
911927edbdde
DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents:
54
diff
changeset
|
225 |
static Uint32 _wait_event_callback(Uint32 interval, void *param); |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
226 |
}; |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
227 |
|
58
50308ed5e4f9
sdlterm: Cleanup exceptions.
Radek Brich <radek.brich@devl.cz>
parents:
57
diff
changeset
|
228 |
|
50308ed5e4f9
sdlterm: Cleanup exceptions.
Radek Brich <radek.brich@devl.cz>
parents:
57
diff
changeset
|
229 |
class SDLTermError: public std::exception |
50308ed5e4f9
sdlterm: Cleanup exceptions.
Radek Brich <radek.brich@devl.cz>
parents:
57
diff
changeset
|
230 |
{ |
50308ed5e4f9
sdlterm: Cleanup exceptions.
Radek Brich <radek.brich@devl.cz>
parents:
57
diff
changeset
|
231 |
public: |
50308ed5e4f9
sdlterm: Cleanup exceptions.
Radek Brich <radek.brich@devl.cz>
parents:
57
diff
changeset
|
232 |
SDLTermError(const std::string &a_msg) |
50308ed5e4f9
sdlterm: Cleanup exceptions.
Radek Brich <radek.brich@devl.cz>
parents:
57
diff
changeset
|
233 |
: std::exception(), _msg(a_msg) {}; |
50308ed5e4f9
sdlterm: Cleanup exceptions.
Radek Brich <radek.brich@devl.cz>
parents:
57
diff
changeset
|
234 |
virtual ~SDLTermError() throw() {}; |
50308ed5e4f9
sdlterm: Cleanup exceptions.
Radek Brich <radek.brich@devl.cz>
parents:
57
diff
changeset
|
235 |
|
50308ed5e4f9
sdlterm: Cleanup exceptions.
Radek Brich <radek.brich@devl.cz>
parents:
57
diff
changeset
|
236 |
virtual const char *what() const throw() { return _msg.c_str(); }; |
50308ed5e4f9
sdlterm: Cleanup exceptions.
Radek Brich <radek.brich@devl.cz>
parents:
57
diff
changeset
|
237 |
|
50308ed5e4f9
sdlterm: Cleanup exceptions.
Radek Brich <radek.brich@devl.cz>
parents:
57
diff
changeset
|
238 |
private: |
50308ed5e4f9
sdlterm: Cleanup exceptions.
Radek Brich <radek.brich@devl.cz>
parents:
57
diff
changeset
|
239 |
std::string _msg; |
50308ed5e4f9
sdlterm: Cleanup exceptions.
Radek Brich <radek.brich@devl.cz>
parents:
57
diff
changeset
|
240 |
}; |
50308ed5e4f9
sdlterm: Cleanup exceptions.
Radek Brich <radek.brich@devl.cz>
parents:
57
diff
changeset
|
241 |