diff -r dce7325109c1 -r 50a1857557da sdlterm/src/sdlterm.h --- a/sdlterm/src/sdlterm.h Sat Jan 05 18:56:45 2013 +0100 +++ b/sdlterm/src/sdlterm.h Sat Jan 05 23:00:41 2013 +0100 @@ -5,12 +5,12 @@ #include -enum class Style: Uint16 +namespace Style { - BOLD = 1 << 0, // bold font - UNDERLINE = 1 << 1, // underline text - STANDOUT = 1 << 2, // inverse bg/fg - BLINK = 1 << 3, // blinking + const int BOLD = 1 << 0; // bold font + const int UNDERLINE = 1 << 1; // underline text + const int STANDOUT = 1 << 2; // inverse bg/fg + const int BLINK = 1 << 3; // blinking }; @@ -44,12 +44,13 @@ class GlyphCache { public: - SDL_Surface *lookup_glyph(Uint16 ch); - void put_glyph(Uint16 ch, SDL_Surface *srf); + // lookup glyph in cache, id is combined char and attr + SDL_Surface *lookup_glyph(Uint64 id); + void put_glyph(Uint64 id, SDL_Surface *srf); void flush(); private: - std::map _glyph_map; + std::map _glyph_map; }; @@ -63,7 +64,7 @@ void close_font(); // do not free surface returned! - SDL_Surface *render_cell(Uint16 ch, Uint16 attr); + SDL_Surface *render_cell(Uint32 ch, Uint32 attr); int get_cell_width() { return _cell_width; }; int get_cell_height() { return _cell_height; }; @@ -75,13 +76,30 @@ int _cell_height; GlyphCache _cache; ColorMap _colormap; + + void _render_glyph(SDL_Surface *cell_surface, TTF_Font *font, Uint32 ch, + SDL_Color fgcolor, SDL_Color bgcolor); }; +/* One cell of terminal window + * + * Each cell contains one character, its color and attributes. + * Character is encoded in 32bit unicode. + * Other 32 bits are attributes: + * 0-7 (8b) - foreground color index + * 8-15 (8b) - background color index + * 16-23 (8b) - RESERVED for alpha channel + * 24 (1b) - bold font + * 25 (1b) - underline + * 26 (1b) - standout (swap fg/bg color) + * 27 (1b) - blink + * 28-31 (4b) - RESERVED + */ struct TerminalCell { - Uint16 ch; - Uint16 attr; + Uint32 ch; + Uint32 attr; bool operator !=(const TerminalCell &rhs) const { return ch != rhs.ch || attr != rhs.attr; }; }; @@ -99,7 +117,7 @@ void resize(int pxwidth, int pxheight); void erase(); - void putch(int x, int y, Uint16 ch, Uint16 attr); + void putch(int x, int y, Uint32 ch, Uint32 attr); void commit(); int get_width() { return _width; }; @@ -134,7 +152,7 @@ struct { char keyname[10]; - Uint16 unicode; + Uint32 unicode; } key; struct { @@ -156,11 +174,11 @@ void resize(int pxwidth, int pxheight) { _screen.resize(pxwidth, pxheight); }; void erase() { _screen.erase(); }; - void putch(int x, int y, Uint16 ch) { _screen.putch(x, y, ch, _attr); }; + void putch(int x, int y, Uint32 ch) { _screen.putch(x, y, ch, _attr); }; void commit() { _screen.commit(); }; - Uint16 prepare_attr(Uint8 fg, Uint8 bg, Uint8 style) { return fg | bg << 4 | style << 8; }; - void set_attr(Uint16 value) { _attr = value; }; + Uint32 prepare_attr(Uint8 fg, Uint8 bg, Uint8 style) { return (Uint32)fg | (Uint32)bg << 8 | (Uint32)style << 24; }; + void set_attr(Uint32 value) { _attr = value; }; void set_cursor(int x, int y) { _cursor_x = x; _cursor_y = y; }; void show_cursor(bool visible) { _cursor_visible = visible; }; @@ -172,7 +190,7 @@ private: TerminalScreen _screen; - Uint16 _attr; + Uint32 _attr; int _cursor_x; int _cursor_y; bool _cursor_visible;