author | Radek Brich <radek.brich@devl.cz> |
Fri, 01 Feb 2013 00:24:02 +0100 | |
changeset 74 | 23767a33a781 |
parent 73 | 85a282b5e4fc |
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 |
|
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
|
3 |
#include <algorithm> |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
4 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
5 |
|
54
86b84535726e
DriverSDL: system font lookup.
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
6 |
void ColorMap::index_to_rgb(int index, SDL_Color &color) const |
50
c5b8b9d2da95
DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
7 |
{ |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
8 |
color.r = _map[index][0]; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
9 |
color.g = _map[index][1]; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
10 |
color.b = _map[index][2]; |
50
c5b8b9d2da95
DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
11 |
} |
c5b8b9d2da95
DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
12 |
|
c5b8b9d2da95
DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
13 |
|
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
|
14 |
SDL_Surface *GlyphCache::lookup_glyph(Uint64 id) |
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
|
15 |
{ |
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
|
16 |
auto iter = _glyph_map.find(id); |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
17 |
if (iter == _glyph_map.end()) |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
18 |
{ |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
19 |
return NULL; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
20 |
} |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
21 |
return iter->second; |
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
|
22 |
} |
1f00e90fd72a
Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents:
47
diff
changeset
|
23 |
|
1f00e90fd72a
Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents:
47
diff
changeset
|
24 |
|
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
|
25 |
void GlyphCache::put_glyph(Uint64 id, SDL_Surface *srf) |
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
|
26 |
{ |
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
|
27 |
_glyph_map[id] = srf; |
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
|
28 |
} |
1f00e90fd72a
Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents:
47
diff
changeset
|
29 |
|
1f00e90fd72a
Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents:
47
diff
changeset
|
30 |
|
1f00e90fd72a
Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents:
47
diff
changeset
|
31 |
void GlyphCache::flush() |
1f00e90fd72a
Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents:
47
diff
changeset
|
32 |
{ |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
33 |
for (auto iter = _glyph_map.begin(); iter != _glyph_map.end(); iter++) |
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 |
SDL_FreeSurface(iter->second); |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
36 |
} |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
37 |
_glyph_map.clear(); |
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
|
38 |
} |
1f00e90fd72a
Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents:
47
diff
changeset
|
39 |
|
1f00e90fd72a
Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents:
47
diff
changeset
|
40 |
|
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
41 |
GlyphRenderer::GlyphRenderer() |
50
c5b8b9d2da95
DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
42 |
: _font_regular(NULL), _font_bold(NULL), _cell_width(0), _cell_height(0), _cache(), _colormap() |
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 |
if (TTF_Init() == -1) |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
45 |
{ |
58
50308ed5e4f9
sdlterm: Cleanup exceptions.
Radek Brich <radek.brich@devl.cz>
parents:
57
diff
changeset
|
46 |
throw SDLTermError(std::string("TTF_Init: ") + TTF_GetError()); |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
47 |
} |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
48 |
} |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
49 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
50 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
51 |
GlyphRenderer::~GlyphRenderer() |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
52 |
{ |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
53 |
_cache.flush(); |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
54 |
close_font(); |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
55 |
TTF_Quit(); |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
56 |
} |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
57 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
58 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
59 |
void GlyphRenderer::open_font(const char *fname_regular, const char *fname_bold, int ptsize) |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
60 |
{ |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
61 |
close_font(); |
47
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 |
// open regular font |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
64 |
_font_regular = TTF_OpenFont(fname_regular, ptsize); |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
65 |
if (!_font_regular) |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
66 |
{ |
58
50308ed5e4f9
sdlterm: Cleanup exceptions.
Radek Brich <radek.brich@devl.cz>
parents:
57
diff
changeset
|
67 |
throw SDLTermError(std::string("TTF_OpenFont: ") + TTF_GetError()); |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
68 |
} |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
69 |
|
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
70 |
// open bold font |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
71 |
_font_bold = TTF_OpenFont(fname_bold, ptsize); |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
72 |
if (!_font_bold) |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
73 |
{ |
58
50308ed5e4f9
sdlterm: Cleanup exceptions.
Radek Brich <radek.brich@devl.cz>
parents:
57
diff
changeset
|
74 |
throw SDLTermError(std::string("TTF_OpenFont: ") + TTF_GetError()); |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
75 |
} |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
76 |
|
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
77 |
// update metrics for regular font |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
78 |
int advance; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
79 |
if (TTF_GlyphMetrics(_font_regular, 'M', NULL, NULL, NULL, NULL, &advance) == -1) |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
80 |
{ |
58
50308ed5e4f9
sdlterm: Cleanup exceptions.
Radek Brich <radek.brich@devl.cz>
parents:
57
diff
changeset
|
81 |
throw SDLTermError(std::string("TTF_GlyphMetrics: ") + TTF_GetError()); |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
82 |
} |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
83 |
_cell_width = advance; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
84 |
_cell_height = TTF_FontHeight(_font_regular); |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
85 |
|
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
86 |
// read metrics for bold font |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
87 |
if (TTF_GlyphMetrics(_font_bold, 'M', NULL, NULL, NULL, NULL, &advance) == -1) |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
88 |
{ |
58
50308ed5e4f9
sdlterm: Cleanup exceptions.
Radek Brich <radek.brich@devl.cz>
parents:
57
diff
changeset
|
89 |
throw SDLTermError(std::string("TTF_GlyphMetrics: ") + TTF_GetError()); |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
90 |
} |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
91 |
if (advance > _cell_width) |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
92 |
{ |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
93 |
_cell_width = advance; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
94 |
} |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
95 |
int height = TTF_FontHeight(_font_bold); |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
96 |
if (height > _cell_height) |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
97 |
{ |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
98 |
_cell_height = height; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
99 |
} |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
100 |
} |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
101 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
102 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
103 |
void GlyphRenderer::close_font() |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
104 |
{ |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
105 |
if (_font_regular) |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
106 |
{ |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
107 |
TTF_CloseFont(_font_regular); |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
108 |
_font_regular = NULL; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
109 |
} |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
110 |
if (_font_bold) |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
111 |
{ |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
112 |
TTF_CloseFont(_font_bold); |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
113 |
_font_bold = NULL; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
114 |
} |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
115 |
} |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
116 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
117 |
|
60
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
118 |
SDL_Surface *GlyphRenderer::render_cell(Uint32 ch, Uint32 attr, bool blink_state) |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
119 |
{ |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
120 |
SDL_Surface *cell_surface; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
121 |
TTF_Font *font; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
122 |
SDL_Color fgcolor, bgcolor; |
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
|
123 |
|
60
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
124 |
// blink affects cache lookup, must be processed first |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
125 |
if ((attr & Style::BLINK) && !blink_state) |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
126 |
{ |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
127 |
ch = ' '; |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
128 |
} |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
129 |
|
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
130 |
// try cache |
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
|
131 |
Uint64 id = (Uint64)ch | (Uint64)attr << 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
|
132 |
cell_surface = _cache.lookup_glyph(id); |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
133 |
if (cell_surface) |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
134 |
{ |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
135 |
return cell_surface; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
136 |
} |
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
|
137 |
|
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
138 |
// load attributes |
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
|
139 |
_colormap.index_to_rgb((attr & 0x000000FF), fgcolor); |
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
|
140 |
_colormap.index_to_rgb((attr & 0x0000FF00) >> 8, bgcolor); |
60
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
141 |
font = (attr & Style::BOLD) ? _font_bold : _font_regular; |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
142 |
if (attr & Style::STANDOUT) |
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
|
143 |
{ |
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
|
144 |
std::swap(fgcolor, bgcolor); |
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
|
145 |
} |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
146 |
|
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
147 |
// create surface for whole cell and fill it with bg color |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
148 |
cell_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
149 |
_cell_width, _cell_height, 32, 0, 0, 0, 0); |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
150 |
SDL_Rect dst_rect; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
151 |
dst_rect.x = 0; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
152 |
dst_rect.y = 0; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
153 |
dst_rect.w = _cell_width; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
154 |
dst_rect.h = _cell_height; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
155 |
Uint32 bgcolor_mapped = SDL_MapRGB(cell_surface->format, bgcolor.r, bgcolor.g, bgcolor.b); |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
156 |
SDL_FillRect(cell_surface, &dst_rect, bgcolor_mapped); |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
157 |
|
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
158 |
// render glyph, blit it onto cell surface |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
159 |
if (ch) |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
160 |
{ |
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
|
161 |
// when glyph is not provided by BOLD font but is provided by REGULAR font, use that (better than nothing) |
60
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
162 |
if ((attr & Style::BOLD) && !TTF_GlyphIsProvided(font, ch) && TTF_GlyphIsProvided(_font_regular, ch)) |
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
|
163 |
{ |
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
|
164 |
// use bold style of regular font instead of 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
|
165 |
TTF_SetFontStyle(_font_regular, TTF_STYLE_BOLD); |
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
|
166 |
_render_glyph(cell_surface, _font_regular, ch, fgcolor, bgcolor); |
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
|
167 |
TTF_SetFontStyle(_font_regular, TTF_STYLE_NORMAL); |
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
|
168 |
} |
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
|
169 |
else |
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
|
170 |
{ |
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
|
171 |
// normal case |
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
|
172 |
_render_glyph(cell_surface, font, ch, fgcolor, bgcolor); |
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 |
} |
60
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
174 |
if (attr & Style::UNDERLINE) |
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
|
175 |
{ |
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
|
176 |
// draw 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
|
177 |
SDL_LockSurface(cell_surface); |
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
|
178 |
int y = 1 + TTF_FontAscent(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
|
179 |
Uint32 fgcolor_mapped = SDL_MapRGB(cell_surface->format, fgcolor.r, fgcolor.g, fgcolor.b); |
53
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
180 |
Uint32 *p = (Uint32 *)((Uint8 *)cell_surface->pixels + y * cell_surface->pitch); |
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
|
181 |
for (int x = 0; x < _cell_width; x++) |
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
|
182 |
*p++ = fgcolor_mapped; |
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
|
183 |
SDL_UnlockSurface(cell_surface); |
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
|
184 |
} |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
185 |
} |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
186 |
|
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
187 |
// convert to display format |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
188 |
SDL_Surface *tmp_surface = cell_surface; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
189 |
cell_surface = SDL_DisplayFormat(tmp_surface); |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
190 |
SDL_FreeSurface(tmp_surface); |
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
|
191 |
|
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
192 |
// put to cache |
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
|
193 |
_cache.put_glyph(id, cell_surface); |
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
|
194 |
|
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
195 |
return cell_surface; |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
196 |
} |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
197 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
198 |
|
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
|
199 |
void GlyphRenderer::_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
|
200 |
SDL_Color fgcolor, SDL_Color bgcolor) |
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
|
201 |
{ |
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
|
202 |
int minx, maxy; |
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
|
203 |
SDL_Rect dst_rect; |
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
|
204 |
SDL_Surface *glyph_surface = TTF_RenderGlyph_Shaded(font, ch, fgcolor, bgcolor); |
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
|
205 |
TTF_GlyphMetrics(font, ch, &minx, NULL, NULL, &maxy, NULL); |
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
|
206 |
dst_rect.x = minx; |
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
|
207 |
dst_rect.y = TTF_FontAscent(font) - maxy; |
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
|
208 |
SDL_BlitSurface(glyph_surface, NULL, cell_surface, &dst_rect); |
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
|
209 |
SDL_FreeSurface(glyph_surface); |
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
|
210 |
} |
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
|
211 |
|
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
|
212 |
|
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
213 |
void TerminalScreen::select_font(const char *fname_regular, const char *fname_bold, int ptsize) |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
214 |
{ |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
215 |
_render.open_font(fname_regular, fname_bold, ptsize); |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
216 |
_reset_cells(); |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
217 |
} |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
218 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
219 |
void TerminalScreen::resize(int pxwidth, int pxheight) |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
220 |
{ |
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
|
221 |
_screen_surface = SDL_SetVideoMode(pxwidth, pxheight, 0, SDL_SWSURFACE|SDL_ANYFORMAT|SDL_RESIZABLE); |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
222 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
223 |
if (_screen_surface == NULL) |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
224 |
{ |
58
50308ed5e4f9
sdlterm: Cleanup exceptions.
Radek Brich <radek.brich@devl.cz>
parents:
57
diff
changeset
|
225 |
throw SDLTermError(std::string("SDL_SetVideoMode: ") + SDL_GetError()); |
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 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
228 |
_pixel_width = pxwidth; |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
229 |
_pixel_height = pxheight; |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
230 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
231 |
_reset_cells(); |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
232 |
} |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
233 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
234 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
235 |
void TerminalScreen::erase() |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
236 |
{ |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
237 |
std::fill(_cells_front.begin(), _cells_front.end(), TerminalCell()); |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
238 |
} |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
239 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
240 |
|
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
|
241 |
void TerminalScreen::putch(int x, int y, Uint32 ch, Uint32 attr) |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
242 |
{ |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
243 |
TerminalCell &cell = _cells_front[y * _width + x]; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
244 |
cell.ch = ch; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
245 |
cell.attr = attr; |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
246 |
} |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
247 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
248 |
|
53
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
249 |
void TerminalScreen::toggle_cursor(int x, int y) |
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
250 |
{ |
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
251 |
TerminalCell &cell = _cells_front[y * _width + x]; |
60
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
252 |
cell.attr ^= Style::STANDOUT; |
53
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
253 |
} |
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
254 |
|
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
255 |
|
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
256 |
void TerminalScreen::commit() |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
257 |
{ |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
258 |
auto front_iter = _cells_front.begin(); |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
259 |
auto back_iter = _cells_back.begin(); |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
260 |
SDL_Surface *cell_surface; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
261 |
SDL_Rect dst_rect; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
262 |
for (int y = 0; y < _height; y++) |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
263 |
{ |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
264 |
for (int x = 0; x < _width; x++) |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
265 |
{ |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
266 |
if (*front_iter != *back_iter) |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
267 |
{ |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
268 |
dst_rect.x = x * _cell_width; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
269 |
dst_rect.y = y * _cell_height; |
60
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
270 |
cell_surface = _render.render_cell(front_iter->ch, front_iter->attr, _blink_state); |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
271 |
SDL_BlitSurface(cell_surface, NULL, _screen_surface, &dst_rect); |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
272 |
*back_iter = *front_iter; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
273 |
} |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
274 |
front_iter++; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
275 |
back_iter++; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
276 |
} |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
277 |
} |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
278 |
|
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
279 |
SDL_UpdateRect(_screen_surface, 0, 0, 0, 0); |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
280 |
} |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
281 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
282 |
|
53
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
283 |
void TerminalScreen::redraw() |
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
284 |
{ |
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
285 |
// clear back buffer, current screen is considered blank |
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
286 |
std::fill(_cells_back.begin(), _cells_back.end(), TerminalCell()); |
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
287 |
} |
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
288 |
|
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
289 |
|
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
290 |
void TerminalScreen::_reset_cells() |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
291 |
{ |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
292 |
_cell_width = _render.get_cell_width(); |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
293 |
_cell_height = _render.get_cell_height(); |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
294 |
if (!_cell_width || !_cell_height) |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
295 |
return; |
50
c5b8b9d2da95
DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
296 |
|
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
297 |
_width = _pixel_width / _cell_width; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
298 |
_height = _pixel_height / _cell_height; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
299 |
if (!_width || !_height) |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
300 |
return; |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
301 |
|
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
302 |
int num_cells = _width * _height; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
303 |
_cells_front.resize(num_cells, TerminalCell()); |
53
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
304 |
_cells_back.resize(num_cells); |
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
305 |
redraw(); |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
306 |
} |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
307 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
308 |
|
60
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
309 |
void TerminalScreen::_draw_blink() |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
310 |
{ |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
311 |
// Use back buffer which contains commited changes. |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
312 |
// This is called from timer while application may draw into front_buffer. |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
313 |
auto back_iter = _cells_back.begin(); |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
314 |
SDL_Surface *cell_surface; |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
315 |
SDL_Rect dst_rect; |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
316 |
for (int y = 0; y < _height; y++) |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
317 |
{ |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
318 |
for (int x = 0; x < _width; x++) |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
319 |
{ |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
320 |
// draw only blinking characters |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
321 |
if (back_iter->attr & Style::BLINK) |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
322 |
{ |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
323 |
dst_rect.x = x * _cell_width; |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
324 |
dst_rect.y = y * _cell_height; |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
325 |
cell_surface = _render.render_cell(back_iter->ch, back_iter->attr, _blink_state); |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
326 |
SDL_BlitSurface(cell_surface, NULL, _screen_surface, &dst_rect); |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
327 |
} |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
328 |
back_iter++; |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
329 |
} |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
330 |
} |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
331 |
|
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
332 |
SDL_UpdateRect(_screen_surface, 0, 0, 0, 0); |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
333 |
} |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
334 |
|
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
335 |
|
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
336 |
Terminal::Terminal() |
55
1ab0edd5d784
DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents:
54
diff
changeset
|
337 |
: _screen(), _attr(7), _cursor_x(0), _cursor_y(0), _cursor_visible(false), |
1ab0edd5d784
DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents:
54
diff
changeset
|
338 |
_mousemove_last_x(-1), _mousemove_last_y(-1) |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
339 |
{ |
57
911927edbdde
DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents:
55
diff
changeset
|
340 |
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1) |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
341 |
{ |
58
50308ed5e4f9
sdlterm: Cleanup exceptions.
Radek Brich <radek.brich@devl.cz>
parents:
57
diff
changeset
|
342 |
throw SDLTermError(std::string("SDL_Init: ") + SDL_GetError()); |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
343 |
} |
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
|
344 |
SDL_EnableUNICODE(1); |
55
1ab0edd5d784
DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents:
54
diff
changeset
|
345 |
SDL_EnableKeyRepeat(250, SDL_DEFAULT_REPEAT_INTERVAL); |
53
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
346 |
SDL_WM_SetCaption("terminal", NULL); |
60
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
347 |
SDL_AddTimer(500, _blink_toggle_callback, NULL); |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
348 |
} |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
349 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
350 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
351 |
Terminal::~Terminal() |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
352 |
{ |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
353 |
SDL_Quit(); |
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
354 |
} |
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
355 |
|
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
356 |
|
53
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
357 |
void Terminal::commit() |
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
358 |
{ |
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
359 |
if (_cursor_visible) |
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
360 |
{ |
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
361 |
_screen.toggle_cursor(_cursor_x, _cursor_y); |
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
362 |
_screen.commit(); |
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
363 |
_screen.toggle_cursor(_cursor_x, _cursor_y); |
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
364 |
} |
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
365 |
else |
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
366 |
{ |
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
367 |
_screen.commit(); |
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
368 |
} |
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
369 |
} |
c4263588b716
DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
370 |
|
57
911927edbdde
DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents:
55
diff
changeset
|
371 |
|
911927edbdde
DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents:
55
diff
changeset
|
372 |
bool Terminal::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
|
373 |
{ |
72
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
374 |
SDL_Event sdl_event; |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
375 |
bool translated; |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
376 |
|
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
377 |
// any events pending? |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
378 |
while (SDL_PollEvent(&sdl_event)) |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
379 |
{ |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
380 |
translated = _handle_event(sdl_event, event); |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
381 |
if (translated) |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
382 |
return true; |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
383 |
} |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
384 |
|
57
911927edbdde
DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents:
55
diff
changeset
|
385 |
// use timer to simulate SDL_WaitEventTimeout, which is not available in SDL 1.2 |
911927edbdde
DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents:
55
diff
changeset
|
386 |
SDL_TimerID timer_id = NULL; |
911927edbdde
DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents:
55
diff
changeset
|
387 |
if (timeout) |
911927edbdde
DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents:
55
diff
changeset
|
388 |
{ |
911927edbdde
DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents:
55
diff
changeset
|
389 |
timer_id = SDL_AddTimer(timeout, _wait_event_callback, NULL); |
911927edbdde
DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents:
55
diff
changeset
|
390 |
} |
911927edbdde
DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents:
55
diff
changeset
|
391 |
|
62
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
61
diff
changeset
|
392 |
// loop until we have something to return |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
61
diff
changeset
|
393 |
bool event_ready = false; |
72
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
394 |
while (!event_ready && SDL_WaitEvent(&sdl_event)) |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
395 |
{ |
72
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
396 |
do |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
397 |
{ |
72
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
398 |
translated = _handle_event(sdl_event, event); |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
399 |
if (translated) |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
400 |
{ |
61 | 401 |
event_ready = true; |
402 |
break; |
|
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
403 |
} |
72
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
404 |
// timeout? |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
405 |
if (sdl_event.type == SDL_USEREVENT && sdl_event.user.code == 1) |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
406 |
{ |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
407 |
SDL_RemoveTimer(timer_id); |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
408 |
return false; |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
409 |
} |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
410 |
} |
72
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
411 |
while (!event_ready && SDL_PollEvent(&sdl_event)); |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
412 |
} |
61 | 413 |
|
414 |
// remove timer when other event came before timeout |
|
415 |
if (timeout) |
|
416 |
{ |
|
417 |
SDL_RemoveTimer(timer_id); |
|
418 |
} |
|
419 |
||
420 |
// ok or error? |
|
421 |
if (event_ready) |
|
422 |
{ |
|
423 |
return true; |
|
424 |
} |
|
425 |
else |
|
426 |
{ |
|
427 |
throw SDLTermError(std::string("SDL_WaitEvent: ") + SDL_GetError()); |
|
428 |
} |
|
47
537d7c6b48a2
Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
429 |
} |
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
|
430 |
|
1f00e90fd72a
Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents:
47
diff
changeset
|
431 |
|
72
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
432 |
// return true when SDL_Event was translated to our Event |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
433 |
bool Terminal::_handle_event(const SDL_Event &sdl_event, Event &event) |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
434 |
{ |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
435 |
switch (sdl_event.type) |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
436 |
{ |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
437 |
case SDL_USEREVENT: |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
438 |
// toggle blink |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
439 |
if (sdl_event.user.code == 2) |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
440 |
{ |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
441 |
_screen.toggle_blink(); |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
442 |
} |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
443 |
return false; |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
444 |
|
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
445 |
case SDL_QUIT: |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
446 |
event.type = Event::QUIT; |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
447 |
return true; |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
448 |
|
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
449 |
case SDL_VIDEORESIZE: |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
450 |
event.type = Event::RESIZE; |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
451 |
_screen.resize(sdl_event.resize.w, sdl_event.resize.h); |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
452 |
return true; |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
453 |
|
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
454 |
case SDL_VIDEOEXPOSE: |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
455 |
_screen.redraw(); |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
456 |
return false; |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
457 |
|
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
458 |
case SDL_KEYDOWN: |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
459 |
{ |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
460 |
//switch(event.key.keysym.sym) |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
461 |
event.type = Event::KEYPRESS; |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
462 |
const char *keyname = _translate_keyname(sdl_event.key.keysym.sym); |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
463 |
// return only keyname or unicode, never both |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
464 |
if (keyname) |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
465 |
{ |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
466 |
strncpy(event.key.keyname, keyname, 10); |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
467 |
event.key.unicode = 0; |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
468 |
} |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
469 |
else |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
470 |
{ |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
471 |
event.key.keyname[0] = 0; |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
472 |
event.key.unicode = sdl_event.key.keysym.unicode; |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
473 |
if (!event.key.unicode) |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
474 |
{ |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
475 |
// unknown key |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
476 |
return false; |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
477 |
} |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
478 |
} |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
479 |
event.key.mod = _translate_mod(sdl_event.key.keysym.mod); |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
480 |
return true; |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
481 |
} |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
482 |
|
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
483 |
case SDL_MOUSEBUTTONDOWN: |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
484 |
case SDL_MOUSEBUTTONUP: |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
485 |
event.type = (sdl_event.type == SDL_MOUSEBUTTONDOWN) ? Event::MOUSEDOWN : Event::MOUSEUP; |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
486 |
event.mouse.x = sdl_event.button.x / _screen.get_cell_width(); |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
487 |
event.mouse.y = sdl_event.button.y / _screen.get_cell_height(); |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
488 |
event.mouse.button = sdl_event.button.button; |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
489 |
if (sdl_event.button.button == SDL_BUTTON_WHEELUP || sdl_event.button.button == SDL_BUTTON_WHEELDOWN) |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
490 |
{ |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
491 |
if (sdl_event.type == SDL_MOUSEBUTTONUP) |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
492 |
{ |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
493 |
// do not report button-up events for mouse wheel |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
494 |
return false; |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
495 |
} |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
496 |
event.type = Event::MOUSEWHEEL; |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
497 |
} |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
498 |
_mousemove_last_x = event.mouse.x; |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
499 |
_mousemove_last_y = event.mouse.y; |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
500 |
return true; |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
501 |
|
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
502 |
case SDL_MOUSEMOTION: |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
503 |
event.mouse.x = sdl_event.motion.x / _screen.get_cell_width(); |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
504 |
event.mouse.y = sdl_event.motion.y / _screen.get_cell_height(); |
73
85a282b5e4fc
Add mousehover event (only SDL).
Radek Brich <radek.brich@devl.cz>
parents:
72
diff
changeset
|
505 |
if (_mousemove_last_x == event.mouse.x && |
85a282b5e4fc
Add mousehover event (only SDL).
Radek Brich <radek.brich@devl.cz>
parents:
72
diff
changeset
|
506 |
_mousemove_last_y == event.mouse.y) |
85a282b5e4fc
Add mousehover event (only SDL).
Radek Brich <radek.brich@devl.cz>
parents:
72
diff
changeset
|
507 |
{ |
85a282b5e4fc
Add mousehover event (only SDL).
Radek Brich <radek.brich@devl.cz>
parents:
72
diff
changeset
|
508 |
// mouse position did not change |
85a282b5e4fc
Add mousehover event (only SDL).
Radek Brich <radek.brich@devl.cz>
parents:
72
diff
changeset
|
509 |
return false; |
85a282b5e4fc
Add mousehover event (only SDL).
Radek Brich <radek.brich@devl.cz>
parents:
72
diff
changeset
|
510 |
} |
85a282b5e4fc
Add mousehover event (only SDL).
Radek Brich <radek.brich@devl.cz>
parents:
72
diff
changeset
|
511 |
if (sdl_event.motion.state == 0 || _mousemove_last_x == -1) |
72
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
512 |
{ |
73
85a282b5e4fc
Add mousehover event (only SDL).
Radek Brich <radek.brich@devl.cz>
parents:
72
diff
changeset
|
513 |
// no button is pressed or last pos not initialized |
85a282b5e4fc
Add mousehover event (only SDL).
Radek Brich <radek.brich@devl.cz>
parents:
72
diff
changeset
|
514 |
event.type = Event::MOUSEHOVER; |
85a282b5e4fc
Add mousehover event (only SDL).
Radek Brich <radek.brich@devl.cz>
parents:
72
diff
changeset
|
515 |
} |
85a282b5e4fc
Add mousehover event (only SDL).
Radek Brich <radek.brich@devl.cz>
parents:
72
diff
changeset
|
516 |
else |
85a282b5e4fc
Add mousehover event (only SDL).
Radek Brich <radek.brich@devl.cz>
parents:
72
diff
changeset
|
517 |
{ |
85a282b5e4fc
Add mousehover event (only SDL).
Radek Brich <radek.brich@devl.cz>
parents:
72
diff
changeset
|
518 |
// some button pressed |
85a282b5e4fc
Add mousehover event (only SDL).
Radek Brich <radek.brich@devl.cz>
parents:
72
diff
changeset
|
519 |
event.type = Event::MOUSEMOVE; |
72
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
520 |
event.mouse.relx = event.mouse.x - _mousemove_last_x; |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
521 |
event.mouse.rely = event.mouse.y - _mousemove_last_y; |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
522 |
} |
73
85a282b5e4fc
Add mousehover event (only SDL).
Radek Brich <radek.brich@devl.cz>
parents:
72
diff
changeset
|
523 |
_mousemove_last_x = event.mouse.x; |
85a282b5e4fc
Add mousehover event (only SDL).
Radek Brich <radek.brich@devl.cz>
parents:
72
diff
changeset
|
524 |
_mousemove_last_y = event.mouse.y; |
85a282b5e4fc
Add mousehover event (only SDL).
Radek Brich <radek.brich@devl.cz>
parents:
72
diff
changeset
|
525 |
return true; |
72
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
526 |
|
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
527 |
default: |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
528 |
// unknown event |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
529 |
return false; |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
530 |
} |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
531 |
} |
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
532 |
|
6e0656600754
DriverSDL: Fix event dispatching. Add SDL events test.
Radek Brich <radek.brich@devl.cz>
parents:
71
diff
changeset
|
533 |
|
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
|
534 |
const char *Terminal::_translate_keyname(SDLKey sym) |
1f00e90fd72a
Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents:
47
diff
changeset
|
535 |
{ |
51
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
536 |
switch (sym) |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
537 |
{ |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
538 |
case SDLK_BACKSPACE: return "backspace"; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
539 |
case SDLK_TAB: return "tab"; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
540 |
case SDLK_RETURN: return "enter"; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
541 |
case SDLK_KP_ENTER: return "enter"; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
542 |
case SDLK_ESCAPE: return "escape"; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
543 |
case SDLK_DELETE: return "delete"; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
544 |
case SDLK_INSERT: return "insert"; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
545 |
case SDLK_UP: return "up"; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
546 |
case SDLK_DOWN: return "down"; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
547 |
case SDLK_LEFT: return "left"; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
548 |
case SDLK_RIGHT: return "right"; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
549 |
case SDLK_HOME: return "home"; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
550 |
case SDLK_END: return "end"; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
551 |
case SDLK_PAGEUP: return "pageup"; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
552 |
case SDLK_PAGEDOWN: return "pagedown"; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
553 |
case SDLK_F1: return "f1"; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
554 |
case SDLK_F2: return "f2"; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
555 |
case SDLK_F3: return "f3"; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
556 |
case SDLK_F4: return "f4"; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
557 |
case SDLK_F5: return "f5"; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
558 |
case SDLK_F6: return "f6"; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
559 |
case SDLK_F7: return "f7"; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
560 |
case SDLK_F8: return "f8"; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
561 |
case SDLK_F9: return "f9"; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
562 |
case SDLK_F10: return "f10"; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
563 |
case SDLK_F11: return "f11"; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
564 |
case SDLK_F12: return "f12"; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
565 |
case SDLK_PRINT: return "print"; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
566 |
case SDLK_SCROLLOCK: return "scrllock"; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
567 |
case SDLK_PAUSE: return "pause"; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
568 |
default: return NULL; |
dce7325109c1
Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
569 |
} |
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
|
570 |
} |
1f00e90fd72a
Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents:
47
diff
changeset
|
571 |
|
57
911927edbdde
DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents:
55
diff
changeset
|
572 |
|
67
71f60bf6ebb7
DriverSDL: add support for key modifiers.
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
573 |
int Terminal::_translate_mod(SDLMod mod) |
71f60bf6ebb7
DriverSDL: add support for key modifiers.
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
574 |
{ |
71f60bf6ebb7
DriverSDL: add support for key modifiers.
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
575 |
int res = 0; |
71f60bf6ebb7
DriverSDL: add support for key modifiers.
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
576 |
if (mod & KMOD_SHIFT) res |= KeyMod::SHIFT; |
71f60bf6ebb7
DriverSDL: add support for key modifiers.
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
577 |
if (mod & KMOD_ALT) res |= KeyMod::ALT; |
71f60bf6ebb7
DriverSDL: add support for key modifiers.
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
578 |
if (mod & KMOD_CTRL) res |= KeyMod::CTRL; |
71f60bf6ebb7
DriverSDL: add support for key modifiers.
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
579 |
if (mod & KMOD_META) res |= KeyMod::META; |
71f60bf6ebb7
DriverSDL: add support for key modifiers.
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
580 |
return res; |
71f60bf6ebb7
DriverSDL: add support for key modifiers.
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
581 |
} |
71f60bf6ebb7
DriverSDL: add support for key modifiers.
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
582 |
|
71f60bf6ebb7
DriverSDL: add support for key modifiers.
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
583 |
|
57
911927edbdde
DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents:
55
diff
changeset
|
584 |
Uint32 Terminal::_wait_event_callback(Uint32 interval, void *param) |
911927edbdde
DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents:
55
diff
changeset
|
585 |
{ |
911927edbdde
DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents:
55
diff
changeset
|
586 |
SDL_Event event; |
911927edbdde
DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents:
55
diff
changeset
|
587 |
event.type = SDL_USEREVENT; |
911927edbdde
DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents:
55
diff
changeset
|
588 |
event.user.code = 1; |
911927edbdde
DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents:
55
diff
changeset
|
589 |
SDL_PushEvent(&event); |
911927edbdde
DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents:
55
diff
changeset
|
590 |
return 0; |
911927edbdde
DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents:
55
diff
changeset
|
591 |
} |
911927edbdde
DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents:
55
diff
changeset
|
592 |
|
60
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
593 |
|
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
594 |
Uint32 Terminal::_blink_toggle_callback(Uint32 interval, void *param) |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
595 |
{ |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
596 |
SDL_Event event; |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
597 |
event.type = SDL_USEREVENT; |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
598 |
event.user.code = 2; |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
599 |
SDL_PushEvent(&event); |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
600 |
return interval; |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
601 |
} |
fccca2a60492
DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents:
58
diff
changeset
|
602 |