sdlterm/src/sdlterm.h
author Radek Brich <radek.brich@devl.cz>
Sat, 05 Jan 2013 18:44:56 +0100
changeset 50 c5b8b9d2da95
parent 49 1611c462c3e3
child 51 dce7325109c1
permissions -rw-r--r--
DriverSDL: Implement colors.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     1
#include "SDL.h"
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     2
#include "SDL_ttf.h"
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     3
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
#include <map>
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
#include <vector>
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     6
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     7
50
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
     8
enum class Style: Uint16
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
     9
{
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    10
	BOLD      = 1 << 0,  // bold font
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    11
	UNDERLINE = 1 << 1,  // underline text
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    12
	STANDOUT  = 1 << 2,  // inverse bg/fg
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    13
	BLINK     = 1 << 3,  // blinking
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    14
};
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    15
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    16
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    17
class ColorMap
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    18
{
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    19
private:
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    20
	Uint8 _map[16][3] = {
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    21
		{0,0,0},		// 0 - black
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    22
        {23,23,178},	// 1 - blue
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    23
        {23,178,23},    // 2 - green
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    24
        {23,178,178},   // 3 - cyan
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    25
        {178,23,23},	// 4 - red
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    26
        {178,23,178},	// 5 - magenta
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    27
        {178,103,23},	// 6 - brown
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    28
        {178,178,178},	// 7 - light gray
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    29
        {104,104,104},	// 8 - gray
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    30
        {84,84,255},	// 9 - light blue
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    31
        {84,255,84},	// 10 - light green
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    32
        {84,255,255},	// 11 - light cyan
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    33
        {255,84,84},	// 12 - light red
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    34
        {255,84,255},	// 13 - light magenta
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    35
        {255,255,84},   // 14 - yellow
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    36
        {255,255,255},  // 15 - white
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    37
	};
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    38
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    39
public:
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    40
    void index_to_rgb(int index, SDL_Color &color);
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    41
};
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    42
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    43
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
    44
class GlyphCache
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
    45
{
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
    46
public:
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
    47
	SDL_Surface *lookup_glyph(Uint16 ch);
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
    48
	void put_glyph(Uint16 ch, SDL_Surface *srf);
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
    49
	void 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
    50
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
    51
private:
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
    52
	std::map<Uint16, SDL_Surface*> _glyph_map;
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
    53
};
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
    54
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
    55
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    56
class GlyphRenderer
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
public:
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    59
	GlyphRenderer();
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    60
	~GlyphRenderer();
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    61
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    62
	void 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
    63
	void close_font();
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    64
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
    65
	// do not free surface returned!
50
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    66
	SDL_Surface *render_cell(Uint16 ch, Uint16 attr);
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    67
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    68
	int get_cell_width() { return _cell_width; };
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    69
	int get_cell_height() { return _cell_height; };
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    70
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    71
private:
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    72
	TTF_Font *_font_regular;
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    73
	TTF_Font *_font_bold;
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    74
	int _cell_width;
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    75
	int _cell_height;
48
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
    76
	GlyphCache _cache;
50
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    77
	ColorMap _colormap;
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    78
};
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    79
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    80
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    81
struct TerminalCell
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    82
{
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    83
	Uint16 ch;
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    84
	Uint16 attr;
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
    85
	bool operator !=(const TerminalCell &rhs) const { return ch != rhs.ch || attr != rhs.attr; };
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    86
};
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    87
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    88
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    89
class TerminalScreen
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    90
{
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    91
public:
50
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    92
	TerminalScreen():
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    93
		_screen_surface(NULL), _cells_front(0), _cells_back(0), _render(),
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    94
		_pixel_width(0), _pixel_height(0) {};
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
    95
	~TerminalScreen() {};
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    96
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    97
	void 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
    98
	void resize(int pxwidth, int pxheight);
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    99
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   100
	void erase();
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   101
	void putch(int x, int y, Uint16 ch, Uint16 attr);
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   102
	void commit();
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   103
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
   104
	int get_width() { return _width; };
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
   105
	int get_height() { return _height; };
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
   106
	int get_cell_width() { return _cell_width; };
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
   107
	int get_cell_height() { return _cell_height; };
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
   108
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   109
private:
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   110
	SDL_Surface *_screen_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
   111
	std::vector<TerminalCell> _cells_front;
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
   112
	std::vector<TerminalCell> _cells_back;
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   113
	GlyphRenderer _render;
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   114
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   115
	int _pixel_width;  // terminal window width in pixels
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   116
	int _pixel_height;
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   117
	int _width;  // width in characters
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   118
	int _height; // height in characters
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   119
	int _cell_width;  // character cell width in pixels
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   120
	int _cell_height;
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   121
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   122
	void _reset_cells();
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   123
};
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   124
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   125
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
   126
struct Event
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   127
{
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
   128
	enum { QUIT, RESIZE, KEYPRESS, MOUSEDOWN, MOUSEUP, MOUSEMOVE, MOUSEWHEEL };
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
   129
	int type;
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   130
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
   131
	union
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
   132
	{
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
   133
		struct
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
   134
		{
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
   135
			char keyname[10];
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
   136
			Uint16 unicode;
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
		} key;
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
   138
		struct
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
   139
		{
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
   140
			int x, y;
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
   141
			int button;
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
   142
		} mouse;
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
   143
	};
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   144
};
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   145
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   146
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   147
class Terminal
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   148
{
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   149
public:
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   150
	Terminal();
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   151
	~Terminal();
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   152
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   153
	void 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
   154
		{ _screen.select_font(fname_regular, fname_bold, ptsize); };
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   155
	void resize(int pxwidth, int pxheight) { _screen.resize(pxwidth, pxheight); };
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   156
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   157
	void erase() { _screen.erase(); };
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   158
	void putch(int x, int y, Uint16 ch) { _screen.putch(x, y, ch, _attr); };
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   159
	void commit() { _screen.commit(); };
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   160
50
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
   161
	Uint16 prepare_attr(Uint8 fg, Uint8 bg, Uint8 style) { return fg | bg << 4 | style << 8; };
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   162
	void set_attr(Uint16 value) { _attr = value; };
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   163
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   164
	void set_cursor(int x, int y) { _cursor_x = x; _cursor_y = y; };
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   165
	void show_cursor(bool visible) { _cursor_visible = visible; };
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   166
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   167
	void get_next_event(Event &event);
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   168
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
   169
	int get_width() { return _screen.get_width(); };
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
   170
	int get_height() { return _screen.get_height(); };
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
   171
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   172
private:
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   173
	TerminalScreen _screen;
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   174
	Uint16 _attr;
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   175
	int _cursor_x;
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   176
	int _cursor_y;
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   177
	bool _cursor_visible;
48
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
   178
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
   179
	int _mousemove_last_x;
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
   180
	int _mousemove_last_y;
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
   181
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
   182
	const char *_translate_keyname(SDLKey sym);
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   183
};
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   184