sdlterm/src/sdlterm.cc
author Radek Brich <radek.brich@devl.cz>
Mon, 07 Jan 2013 00:23:45 +0100
changeset 55 1ab0edd5d784
parent 54 86b84535726e
child 57 911927edbdde
permissions -rw-r--r--
DriverSDL: mousewheel, key repeation.
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 "sdlterm.h"
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     2
49
1611c462c3e3 Update sdlterm: Optimize commit() - use two cell buffers, redraw only dirty cells, not everything. Fix keypress event, filter mousemove.
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
     3
#include <exception>
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
     4
#include <algorithm>
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     6
54
86b84535726e DriverSDL: system font lookup.
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
     7
void ColorMap::index_to_rgb(int index, SDL_Color &color) const
50
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
     8
{
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
     9
    color.r = _map[index][0];
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    10
    color.g = _map[index][1];
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    11
    color.b = _map[index][2];
50
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    12
}
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    13
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    14
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
    15
SDL_Surface *GlyphCache::lookup_glyph(Uint64 id)
48
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
    16
{
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
    17
    auto iter = _glyph_map.find(id);
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    18
    if (iter == _glyph_map.end())
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    19
    {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    20
        return NULL;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    21
    }
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    22
    return iter->second;
48
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
    23
}
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
    24
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
    25
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
    26
void GlyphCache::put_glyph(Uint64 id, SDL_Surface *srf)
48
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
    27
{
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
    28
    _glyph_map[id] = srf;
48
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
    29
}
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
    30
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
    31
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
    32
void GlyphCache::flush()
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
    33
{
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    34
    for (auto iter = _glyph_map.begin(); iter != _glyph_map.end(); iter++)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    35
    {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    36
        SDL_FreeSurface(iter->second);
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    37
    }
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    38
    _glyph_map.clear();
48
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
    39
}
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
    40
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
    41
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    42
GlyphRenderer::GlyphRenderer()
50
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    43
 : _font_regular(NULL), _font_bold(NULL), _cell_width(0), _cell_height(0), _cache(), _colormap()
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    44
{
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    45
    if (TTF_Init() == -1)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    46
    {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    47
        printf("TTF_Init: %s\n", TTF_GetError());
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    48
        throw std::exception();
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    49
    }
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    50
}
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    51
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    52
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    53
GlyphRenderer::~GlyphRenderer()
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    54
{
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    55
    _cache.flush();
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    56
    close_font();
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    57
    TTF_Quit();
47
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
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    60
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    61
void GlyphRenderer::open_font(const char *fname_regular, const char *fname_bold, int ptsize)
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    62
{
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    63
    close_font();
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    64
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    65
    // open regular font
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    66
    _font_regular = TTF_OpenFont(fname_regular, ptsize);
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    67
    if (!_font_regular)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    68
    {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    69
        printf("TTF_OpenFont: %s\n", TTF_GetError());
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    70
        throw std::exception();
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    71
    }
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    72
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    73
    // open bold font
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    74
    _font_bold = TTF_OpenFont(fname_bold, ptsize);
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    75
    if (!_font_bold)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    76
    {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    77
        printf("TTF_OpenFont: %s\n", TTF_GetError());
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    78
        throw std::exception();
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    79
    }
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    80
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    81
    // update metrics for regular font
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    82
    int advance;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    83
    if (TTF_GlyphMetrics(_font_regular, 'M', NULL, NULL, NULL, NULL, &advance) == -1)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    84
    {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    85
        printf("TTF_GlyphMetrics: %s\n", TTF_GetError());
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    86
    }
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    87
    _cell_width = advance;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    88
    _cell_height = TTF_FontHeight(_font_regular);
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    89
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    90
    // read metrics for bold font
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    91
    if (TTF_GlyphMetrics(_font_bold, 'M', NULL, NULL, NULL, NULL, &advance) == -1)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    92
    {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    93
        printf("TTF_GlyphMetrics: %s\n", TTF_GetError());
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    94
    }
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    95
    if (advance > _cell_width)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    96
    {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    97
        _cell_width = advance;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    98
    }
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    99
    int height = TTF_FontHeight(_font_bold);
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   100
    if (height > _cell_height)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   101
    {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   102
        _cell_height = height;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   103
    }
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
void GlyphRenderer::close_font()
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   108
{
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   109
    if (_font_regular)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   110
    {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   111
        TTF_CloseFont(_font_regular);
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   112
        _font_regular = NULL;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   113
    }
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   114
    if (_font_bold)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   115
    {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   116
        TTF_CloseFont(_font_bold);
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   117
        _font_bold = NULL;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   118
    }
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   119
}
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   120
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   121
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
SDL_Surface *GlyphRenderer::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
   123
{
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   124
    SDL_Surface *cell_surface;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   125
    TTF_Font *font;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   126
    SDL_Color fgcolor, bgcolor;
48
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
   127
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   128
    // try cache
52
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   129
    Uint64 id = (Uint64)ch | (Uint64)attr << 32;
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   130
    cell_surface = _cache.lookup_glyph(id);
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   131
    if (cell_surface)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   132
    {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   133
        return cell_surface;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   134
    }
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
   135
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   136
    // load attributes
52
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   137
    _colormap.index_to_rgb((attr & 0x000000FF), fgcolor);
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   138
    _colormap.index_to_rgb((attr & 0x0000FF00) >> 8, bgcolor);
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   139
    int style = (attr & 0xFF000000) >> 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
   140
    font = (style & Style::BOLD) ? _font_bold : _font_regular;
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
   141
    if (style & Style::STANDOUT)
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
   142
    {
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   143
        std::swap(fgcolor, bgcolor);
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   144
    }
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   145
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   146
    // create surface for whole cell and fill it with bg color
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   147
    cell_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   148
            _cell_width, _cell_height, 32, 0, 0, 0, 0);
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   149
    SDL_Rect dst_rect;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   150
    dst_rect.x = 0;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   151
    dst_rect.y = 0;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   152
    dst_rect.w = _cell_width;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   153
    dst_rect.h = _cell_height;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   154
    Uint32 bgcolor_mapped = SDL_MapRGB(cell_surface->format, bgcolor.r, bgcolor.g, bgcolor.b);
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   155
    SDL_FillRect(cell_surface, &dst_rect, bgcolor_mapped);
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   156
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   157
    // render glyph, blit it onto cell surface
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   158
    if (ch)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   159
    {
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
   160
        // when glyph is not provided by BOLD font but is provided by REGULAR font, use that (better than nothing)
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
        if ((style & Style::BOLD) && !TTF_GlyphIsProvided(font, ch) && TTF_GlyphIsProvided(_font_regular, 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
   162
        {
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   163
            // use bold style of regular font instead of bold font
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   164
            TTF_SetFontStyle(_font_regular, TTF_STYLE_BOLD);
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   165
            _render_glyph(cell_surface, _font_regular, ch, fgcolor, bgcolor);
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   166
            TTF_SetFontStyle(_font_regular, TTF_STYLE_NORMAL);
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   167
        }
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   168
        else
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   169
        {
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   170
            // normal case
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   171
            _render_glyph(cell_surface, font, ch, fgcolor, bgcolor);
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   172
        }
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   173
        if (style & Style::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
   174
        {
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   175
            // draw underline
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   176
            SDL_LockSurface(cell_surface);
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   177
            int y = 1 + TTF_FontAscent(font);
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   178
            Uint32 fgcolor_mapped = SDL_MapRGB(cell_surface->format, fgcolor.r, fgcolor.g, fgcolor.b);
53
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   179
            Uint32 *p = (Uint32 *)((Uint8 *)cell_surface->pixels + y * cell_surface->pitch);
52
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   180
            for (int x = 0; x < _cell_width; x++)
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   181
                *p++ = fgcolor_mapped;
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   182
            SDL_UnlockSurface(cell_surface);
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   183
        }
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   184
    }
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
    // convert to display format
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   187
    SDL_Surface *tmp_surface = cell_surface;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   188
    cell_surface = SDL_DisplayFormat(tmp_surface);
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   189
    SDL_FreeSurface(tmp_surface);
49
1611c462c3e3 Update sdlterm: Optimize commit() - use two cell buffers, redraw only dirty cells, not everything. Fix keypress event, filter mousemove.
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   190
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   191
    // put to cache
52
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   192
    _cache.put_glyph(id, cell_surface);
49
1611c462c3e3 Update sdlterm: Optimize commit() - use two cell buffers, redraw only dirty cells, not everything. Fix keypress event, filter mousemove.
Radek Brich <radek.brich@devl.cz>
parents: 48
diff changeset
   193
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   194
    return cell_surface;
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   195
}
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   196
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   197
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
   198
void GlyphRenderer::_render_glyph(SDL_Surface *cell_surface, TTF_Font *font, Uint32 ch,
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   199
        SDL_Color fgcolor, SDL_Color bgcolor)
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   200
{
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   201
    int minx, maxy;
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   202
    SDL_Rect dst_rect;
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   203
    SDL_Surface *glyph_surface = TTF_RenderGlyph_Shaded(font, ch, fgcolor, bgcolor);
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   204
    TTF_GlyphMetrics(font, ch, &minx, NULL, NULL, &maxy, NULL);
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   205
    dst_rect.x = minx;
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   206
    dst_rect.y = TTF_FontAscent(font) - maxy;
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   207
    SDL_BlitSurface(glyph_surface, NULL, cell_surface, &dst_rect);
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   208
    SDL_FreeSurface(glyph_surface);
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   209
}
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   210
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   211
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   212
void TerminalScreen::select_font(const char *fname_regular, const char *fname_bold, int ptsize)
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   213
{
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   214
    _render.open_font(fname_regular, fname_bold, ptsize);
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   215
    _reset_cells();
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   216
}
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   217
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   218
void TerminalScreen::resize(int pxwidth, int pxheight)
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   219
{
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
   220
    _screen_surface = SDL_SetVideoMode(pxwidth, pxheight, 0, SDL_SWSURFACE|SDL_ANYFORMAT|SDL_RESIZABLE);
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   221
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   222
    if (_screen_surface == NULL)
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   223
    {
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   224
        fprintf(stderr, "Unable to set video: %s\n", SDL_GetError());
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   225
        throw std::exception();
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   226
    }
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   227
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   228
    _pixel_width = pxwidth;
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   229
    _pixel_height = pxheight;
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   230
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   231
    _reset_cells();
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   232
}
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   233
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   234
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   235
void TerminalScreen::erase()
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   236
{
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   237
    std::fill(_cells_front.begin(), _cells_front.end(), TerminalCell());
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   238
}
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   239
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   240
52
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   241
void TerminalScreen::putch(int x, int y, Uint32 ch, Uint32 attr)
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   242
{
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   243
    TerminalCell &cell = _cells_front[y * _width + x];
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   244
    cell.ch = ch;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   245
    cell.attr = attr;
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   246
}
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   247
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   248
53
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   249
void TerminalScreen::toggle_cursor(int x, int y)
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   250
{
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   251
    TerminalCell &cell = _cells_front[y * _width + x];
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   252
    cell.attr ^= (Style::STANDOUT << 24);
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   253
}
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   254
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   255
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   256
void TerminalScreen::commit()
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   257
{
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   258
    auto front_iter = _cells_front.begin();
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   259
    auto back_iter = _cells_back.begin();
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   260
    SDL_Surface *cell_surface;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   261
    SDL_Rect dst_rect;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   262
    for (int y = 0; y < _height; y++)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   263
    {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   264
        for (int x = 0; x < _width; x++)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   265
        {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   266
            if (*front_iter != *back_iter)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   267
            {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   268
                dst_rect.x = x * _cell_width;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   269
                dst_rect.y = y * _cell_height;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   270
                cell_surface = _render.render_cell(front_iter->ch, front_iter->attr);
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   271
                SDL_BlitSurface(cell_surface, NULL, _screen_surface, &dst_rect);
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   272
                *back_iter = *front_iter;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   273
            }
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   274
            front_iter++;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   275
            back_iter++;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   276
        }
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   277
    }
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   278
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   279
    SDL_UpdateRect(_screen_surface, 0, 0, 0, 0);
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   280
}
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   281
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   282
53
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   283
void TerminalScreen::redraw()
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   284
{
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   285
    // clear back buffer, current screen is considered blank
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   286
    std::fill(_cells_back.begin(), _cells_back.end(), TerminalCell());
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   287
}
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   288
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   289
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   290
void TerminalScreen::_reset_cells()
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   291
{
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   292
    _cell_width = _render.get_cell_width();
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   293
    _cell_height = _render.get_cell_height();
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   294
    if (!_cell_width || !_cell_height)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   295
        return;
50
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
   296
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   297
    _width = _pixel_width / _cell_width;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   298
    _height = _pixel_height / _cell_height;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   299
    if (!_width || !_height)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   300
        return;
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   301
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   302
    int num_cells = _width * _height;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   303
    _cells_front.resize(num_cells, TerminalCell());
53
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   304
    _cells_back.resize(num_cells);
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   305
    redraw();
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   306
}
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   307
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   308
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   309
Terminal::Terminal()
55
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 54
diff changeset
   310
 : _screen(), _attr(7), _cursor_x(0), _cursor_y(0), _cursor_visible(false),
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 54
diff changeset
   311
   _mousemove_last_x(-1), _mousemove_last_y(-1)
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   312
{
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   313
    if (SDL_Init(SDL_INIT_VIDEO) == -1)
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   314
    {
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   315
        fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError());
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   316
        throw std::exception();
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   317
    }
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
   318
    SDL_EnableUNICODE(1);
55
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 54
diff changeset
   319
    SDL_EnableKeyRepeat(250, SDL_DEFAULT_REPEAT_INTERVAL);
53
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   320
    SDL_WM_SetCaption("terminal", NULL);
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   321
}
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   322
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   323
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   324
Terminal::~Terminal()
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   325
{
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   326
    SDL_Quit();
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   327
}
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   328
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   329
53
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   330
void Terminal::commit()
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   331
{
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   332
    if (_cursor_visible)
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   333
    {
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   334
        _screen.toggle_cursor(_cursor_x, _cursor_y);
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   335
        _screen.commit();
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   336
        _screen.toggle_cursor(_cursor_x, _cursor_y);
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   337
    }
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   338
    else
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   339
    {
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   340
        _screen.commit();
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   341
    }
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   342
}
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   343
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   344
void Terminal::get_next_event(Event &event)
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   345
{
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   346
    static SDL_Event sdl_event;
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   347
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   348
    while (SDL_WaitEvent(&sdl_event))
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   349
    {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   350
        switch (sdl_event.type)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   351
        {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   352
            case SDL_QUIT:
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   353
                event.type = Event::QUIT;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   354
                return;
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   355
53
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   356
            case SDL_VIDEORESIZE:
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   357
                event.type = Event::RESIZE;
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   358
                _screen.resize(sdl_event.resize.w, sdl_event.resize.h);
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   359
                return;
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   360
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   361
            case SDL_VIDEOEXPOSE:
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   362
                _screen.redraw();
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   363
                break;
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   364
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   365
            case SDL_KEYDOWN:
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   366
            {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   367
                //switch(event.key.keysym.sym)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   368
                event.type = Event::KEYPRESS;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   369
                const char *keyname = _translate_keyname(sdl_event.key.keysym.sym);
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   370
                // return only keyname or unicode, never both
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   371
                if (keyname)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   372
                {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   373
                    strncpy(event.key.keyname, keyname, 10);
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   374
                    event.key.unicode = 0;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   375
                }
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   376
                else
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   377
                {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   378
                    event.key.keyname[0] = 0;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   379
                    event.key.unicode = sdl_event.key.keysym.unicode;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   380
                    if (!event.key.unicode)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   381
                        break; // continue loop (unknown key)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   382
                }
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   383
                return;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   384
            }
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
   385
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   386
            case SDL_MOUSEBUTTONDOWN:
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   387
            case SDL_MOUSEBUTTONUP:
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   388
                event.type = (sdl_event.type == SDL_MOUSEBUTTONDOWN) ? Event::MOUSEDOWN : Event::MOUSEUP;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   389
                event.mouse.x = sdl_event.button.x / _screen.get_cell_width();
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   390
                event.mouse.y = sdl_event.button.y / _screen.get_cell_height();
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   391
                event.mouse.button = sdl_event.button.button;
55
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 54
diff changeset
   392
                if (sdl_event.button.button == SDL_BUTTON_WHEELUP || sdl_event.button.button == SDL_BUTTON_WHEELDOWN)
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 54
diff changeset
   393
                {
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 54
diff changeset
   394
                    if (sdl_event.type == SDL_MOUSEBUTTONUP)
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 54
diff changeset
   395
                        break; // do not report button-up events for mouse wheel
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 54
diff changeset
   396
                    event.type = Event::MOUSEWHEEL;
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 54
diff changeset
   397
                }
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   398
                _mousemove_last_x = -1;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   399
                return;
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
   400
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   401
            case SDL_MOUSEMOTION:
53
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   402
                if (sdl_event.motion.state == 0)
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   403
                    break; // continue loop, do not report move events when no button is pressed
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   404
                event.type = Event::MOUSEMOVE;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   405
                event.mouse.x = sdl_event.motion.x / _screen.get_cell_width();
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   406
                event.mouse.y = sdl_event.motion.y / _screen.get_cell_height();
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   407
                if (_mousemove_last_x != event.mouse.x ||
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   408
                    _mousemove_last_y != event.mouse.y)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   409
                {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   410
                    _mousemove_last_x = event.mouse.x;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   411
                    _mousemove_last_y = event.mouse.y;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   412
                    return;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   413
                }
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   414
                break; // continue loop when mouse position did not change
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   415
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   416
            default:
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   417
                break; // continue loop
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   418
        }
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   419
    }
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   420
}
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
   421
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
   422
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
   423
const char *Terminal::_translate_keyname(SDLKey sym)
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
   424
{
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   425
    switch (sym)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   426
    {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   427
        case SDLK_BACKSPACE:    return "backspace";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   428
        case SDLK_TAB:          return "tab";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   429
        case SDLK_RETURN:       return "enter";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   430
        case SDLK_KP_ENTER:     return "enter";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   431
        case SDLK_ESCAPE:       return "escape";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   432
        case SDLK_DELETE:       return "delete";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   433
        case SDLK_INSERT:       return "insert";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   434
        case SDLK_UP:           return "up";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   435
        case SDLK_DOWN:         return "down";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   436
        case SDLK_LEFT:         return "left";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   437
        case SDLK_RIGHT:        return "right";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   438
        case SDLK_HOME:         return "home";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   439
        case SDLK_END:          return "end";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   440
        case SDLK_PAGEUP:       return "pageup";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   441
        case SDLK_PAGEDOWN:     return "pagedown";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   442
        case SDLK_F1:           return "f1";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   443
        case SDLK_F2:           return "f2";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   444
        case SDLK_F3:           return "f3";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   445
        case SDLK_F4:           return "f4";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   446
        case SDLK_F5:           return "f5";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   447
        case SDLK_F6:           return "f6";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   448
        case SDLK_F7:           return "f7";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   449
        case SDLK_F8:           return "f8";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   450
        case SDLK_F9:           return "f9";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   451
        case SDLK_F10:          return "f10";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   452
        case SDLK_F11:          return "f11";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   453
        case SDLK_F12:          return "f12";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   454
        case SDLK_PRINT:        return "print";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   455
        case SDLK_SCROLLOCK:    return "scrllock";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   456
        case SDLK_PAUSE:        return "pause";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   457
        default: return NULL;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   458
    }
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
   459
}
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
   460