sdlterm/src/sdlterm.h
author Radek Brich <radek.brich@devl.cz>
Sat, 05 Jan 2013 23:00:41 +0100
changeset 52 50a1857557da
parent 51 dce7325109c1
child 53 c4263588b716
permissions -rw-r--r--
Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
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:
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:
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
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    69
    int get_cell_width() { return _cell_width; };
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    70
    int get_cell_height() { 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;
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   103
    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
   104
};
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   105
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
class TerminalScreen
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
public:
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   110
    TerminalScreen():
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   111
        _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
   112
        _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
   113
        _cell_width(0), _cell_height(0) {};
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   114
    ~TerminalScreen() {};
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   115
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   116
    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
   117
    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
   118
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   119
    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
   120
    void putch(int x, int y, Uint32 ch, Uint32 attr);
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   121
    void commit();
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   122
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   123
    int get_width() { return _width; };
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   124
    int get_height() { return _height; };
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   125
    int get_cell_width() { return _cell_width; };
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   126
    int get_cell_height() { 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
   127
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   128
private:
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   129
    SDL_Surface *_screen_surface;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   130
    std::vector<TerminalCell> _cells_front;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   131
    std::vector<TerminalCell> _cells_back;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   132
    GlyphRenderer _render;
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   133
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   134
    int _pixel_width;  // terminal window width in pixels
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   135
    int _pixel_height;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   136
    int _width;  // width in characters
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   137
    int _height; // height in characters
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   138
    int _cell_width;  // character cell width in pixels
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   139
    int _cell_height;
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   140
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   141
    void _reset_cells();
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   142
};
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   143
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   144
48
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
   145
struct Event
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
    enum { QUIT, RESIZE, KEYPRESS, MOUSEDOWN, MOUSEUP, MOUSEMOVE, MOUSEWHEEL };
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   148
    int type;
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   149
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   150
    union
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   151
    {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   152
        struct
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   153
        {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   154
            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
   155
            Uint32 unicode;
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   156
        } key;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   157
        struct
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   158
        {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   159
            int x, y;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   160
            int button;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   161
        } mouse;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   162
    };
47
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
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   165
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   166
class Terminal
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   167
{
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   168
public:
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   169
    Terminal();
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   170
    ~Terminal();
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   171
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   172
    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
   173
        { _screen.select_font(fname_regular, fname_bold, ptsize); };
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   174
    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
   175
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   176
    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
   177
    void putch(int x, int y, Uint32 ch) { _screen.putch(x, y, ch, _attr); };
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   178
    void commit() { _screen.commit(); };
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   179
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
   180
    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
   181
    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
   182
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   183
    void set_cursor(int x, int y) { _cursor_x = x; _cursor_y = y; };
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   184
    void show_cursor(bool visible) { _cursor_visible = visible; };
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   185
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   186
    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
   187
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   188
    int get_width() { return _screen.get_width(); };
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   189
    int get_height() { 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
   190
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   191
private:
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   192
    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
   193
    Uint32 _attr;
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   194
    int _cursor_x;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   195
    int _cursor_y;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   196
    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
   197
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   198
    int _mousemove_last_x;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   199
    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
   200
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   201
    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
   202
};
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   203