sdlterm/src/sdlterm.h
author Radek Brich <radek.brich@devl.cz>
Sun, 06 Jan 2013 13:55:02 +0100
changeset 53 c4263588b716
parent 52 50a1857557da
child 54 86b84535726e
permissions -rw-r--r--
DriverSDL: Implement cursor, handle window resize.
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
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
     8
namespace Style
50
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
     9
{
52
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
    10
    const int BOLD      = 1 << 0;  // 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
    11
    const int UNDERLINE = 1 << 1;  // underline text
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
    12
    const int STANDOUT  = 1 << 2;  // inverse bg/fg
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
    13
    const int BLINK     = 1 << 3;  // blinking
50
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:
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    20
    Uint8 _map[16][3] = {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    21
        {0,0,0},        // 0 - black
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    22
        {23,23,178},    // 1 - blue
50
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
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    25
        {178,23,23},    // 4 - red
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    26
        {178,23,178},   // 5 - magenta
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    27
        {178,103,23},   // 6 - brown
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    28
        {178,178,178},  // 7 - light gray
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    29
        {104,104,104},  // 8 - gray
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    30
        {84,84,255},    // 9 - light blue
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    31
        {84,255,84},    // 10 - light green
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    32
        {84,255,255},   // 11 - light cyan
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    33
        {255,84,84},    // 12 - light red
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    34
        {255,84,255},   // 13 - light magenta
50
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
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    37
    };
50
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:
53
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
    40
    void index_to_rgb(int index, SDL_Color &color) const;
50
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    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:
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
    47
    // lookup glyph in cache, id is combined char and attr
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
    48
    SDL_Surface *lookup_glyph(Uint64 id);
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
    49
    void put_glyph(Uint64 id, SDL_Surface *srf);
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    50
    void flush();
48
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
    51
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
private:
52
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
    53
    std::map<Uint64, SDL_Surface*> _glyph_map;
48
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
    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
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
    56
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    57
class GlyphRenderer
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
public:
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    60
    GlyphRenderer();
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    61
    ~GlyphRenderer();
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
    void open_font(const char *fname_regular, const char *fname_bold, int ptsize);
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    64
    void close_font();
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    65
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    66
    // do not free surface returned!
52
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
    67
    SDL_Surface *render_cell(Uint32 ch, Uint32 attr);
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    68
53
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
    69
    int get_cell_width() const { return _cell_width; };
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
    70
    int get_cell_height() const { return _cell_height; };
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    71
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    72
private:
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    73
    TTF_Font *_font_regular;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    74
    TTF_Font *_font_bold;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    75
    int _cell_width;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    76
    int _cell_height;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    77
    GlyphCache _cache;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    78
    ColorMap _colormap;
52
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
    79
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
    80
    void _render_glyph(SDL_Surface *cell_surface, TTF_Font *font, Uint32 ch,
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
    81
            SDL_Color fgcolor, SDL_Color bgcolor);
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    82
};
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    83
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    84
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
    85
/* One cell of terminal window
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
    86
 *
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
    87
 * Each cell contains one character, its color and attributes.
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
    88
 * Character is encoded in 32bit unicode.
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
    89
 * Other 32 bits are attributes:
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
    90
 *   0-7   (8b) - foreground color index
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
    91
 *   8-15  (8b) - background color index
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
    92
 *   16-23 (8b) - RESERVED for alpha channel
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
    93
 *   24    (1b) - bold font
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
    94
 *   25    (1b) - underline
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
    95
 *   26    (1b) - standout (swap fg/bg color)
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
    96
 *   27    (1b) - blink
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
    97
 *   28-31 (4b) - RESERVED
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
    98
 */
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    99
struct TerminalCell
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   100
{
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
   101
    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
   102
    Uint32 attr;
53
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   103
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   104
    TerminalCell() : ch(0), attr(7) {};
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   105
    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
   106
};
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   107
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   108
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   109
class TerminalScreen
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   110
{
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   111
public:
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   112
    TerminalScreen():
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   113
        _screen_surface(NULL), _cells_front(0), _cells_back(0), _render(),
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   114
        _pixel_width(0), _pixel_height(0), _width(0), _height(0),
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   115
        _cell_width(0), _cell_height(0) {};
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   116
    ~TerminalScreen() {};
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   117
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   118
    void select_font(const char *fname_regular, const char *fname_bold, int ptsize);
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   119
    void resize(int pxwidth, int pxheight);
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   120
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   121
    void erase();
52
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   122
    void putch(int x, int y, Uint32 ch, Uint32 attr);
53
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   123
    void toggle_cursor(int x, int y);
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   124
    void commit();
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   125
53
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   126
    // force full redraw on next commit()
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   127
    void redraw();
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   128
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   129
    int get_width() const { return _width; };
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   130
    int get_height() const { return _height; };
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   131
    int get_cell_width() const { return _cell_width; };
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   132
    int get_cell_height() const { return _cell_height; };
48
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
   133
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   134
private:
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   135
    SDL_Surface *_screen_surface;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   136
    std::vector<TerminalCell> _cells_front;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   137
    std::vector<TerminalCell> _cells_back;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   138
    GlyphRenderer _render;
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   139
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   140
    int _pixel_width;  // terminal window width in pixels
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   141
    int _pixel_height;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   142
    int _width;  // width in characters
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   143
    int _height; // height in characters
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   144
    int _cell_width;  // character cell width in pixels
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   145
    int _cell_height;
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
    void _reset_cells();
47
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
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   150
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
   151
struct Event
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   152
{
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   153
    enum { QUIT, RESIZE, KEYPRESS, MOUSEDOWN, MOUSEUP, MOUSEMOVE, MOUSEWHEEL };
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   154
    int type;
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   155
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   156
    union
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   157
    {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   158
        struct
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   159
        {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   160
            char keyname[10];
52
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   161
            Uint32 unicode;
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   162
        } key;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   163
        struct
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   164
        {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   165
            int x, y;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   166
            int button;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   167
        } mouse;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   168
    };
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   169
};
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   170
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   171
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   172
class Terminal
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   173
{
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   174
public:
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   175
    Terminal();
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   176
    ~Terminal();
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   177
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   178
    void select_font(const char *fname_regular, const char *fname_bold, int ptsize)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   179
        { _screen.select_font(fname_regular, fname_bold, ptsize); };
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   180
    void resize(int pxwidth, int pxheight) { _screen.resize(pxwidth, pxheight); };
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   181
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   182
    void erase() { _screen.erase(); };
52
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   183
    void putch(int x, int y, Uint32 ch) { _screen.putch(x, y, ch, _attr); };
53
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   184
    void commit();
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   185
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
   186
    Uint32 prepare_attr(Uint8 fg, Uint8 bg, Uint8 style) { return (Uint32)fg | (Uint32)bg << 8 | (Uint32)style << 24; };
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   187
    void set_attr(Uint32 value) { _attr = value; };
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   188
53
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   189
    void show_cursor(int x, int y) { _cursor_x = x; _cursor_y = y; _cursor_visible = true; };
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   190
    void hide_cursor() { _cursor_visible = false; };
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   191
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   192
    void get_next_event(Event &event);
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   193
53
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   194
    int get_width() const { return _screen.get_width(); };
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   195
    int get_height() const { return _screen.get_height(); };
48
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
   196
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   197
private:
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   198
    TerminalScreen _screen;
52
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   199
    Uint32 _attr;
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   200
    int _cursor_x;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   201
    int _cursor_y;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   202
    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
   203
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   204
    int _mousemove_last_x;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   205
    int _mousemove_last_y;
49
1611c462c3e3 Update sdlterm: Optimize commit() - use two cell buffers, redraw only dirty cells, not everything. Fix keypress event, filter mousemove.
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   206
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   207
    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
   208
};
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   209