sdlterm/src/sdlterm.cc
author Radek Brich <radek.brich@devl.cz>
Fri, 18 Jan 2013 22:36:50 +0100
changeset 62 2f61931520c9
parent 61 15088f62c4ac
child 67 71f60bf6ebb7
permissions -rw-r--r--
Rework layouts: Layout is now normal Container which places its children upon resize event. Drop TopWindow, top is now any subclass of Container. Add floater concept: floaters are widgets drawn over normal widgets, not clipped by parent. Add HScrollbar and Scrollbar abstract base class.
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 <algorithm>
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
54
86b84535726e DriverSDL: system font lookup.
Radek Brich <radek.brich@devl.cz>
parents: 53
diff changeset
     6
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
     7
{
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
     8
    color.r = _map[index][0];
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
     9
    color.g = _map[index][1];
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    10
    color.b = _map[index][2];
50
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    11
}
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
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
    14
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
    15
{
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
    16
    auto iter = _glyph_map.find(id);
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    17
    if (iter == _glyph_map.end())
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    18
    {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    19
        return NULL;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    20
    }
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    21
    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
    22
}
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
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
    25
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
    26
{
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
    27
    _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
    28
}
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
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
    32
{
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    33
    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
    34
    {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    35
        SDL_FreeSurface(iter->second);
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    36
    }
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    37
    _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
    38
}
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
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    41
GlyphRenderer::GlyphRenderer()
50
c5b8b9d2da95 DriverSDL: Implement colors.
Radek Brich <radek.brich@devl.cz>
parents: 49
diff changeset
    42
 : _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
    43
{
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    44
    if (TTF_Init() == -1)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    45
    {
58
50308ed5e4f9 sdlterm: Cleanup exceptions.
Radek Brich <radek.brich@devl.cz>
parents: 57
diff changeset
    46
        throw SDLTermError(std::string("TTF_Init: ") + TTF_GetError());
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    47
    }
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    48
}
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    49
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
GlyphRenderer::~GlyphRenderer()
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    52
{
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    53
    _cache.flush();
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    54
    close_font();
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    55
    TTF_Quit();
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    56
}
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    57
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    58
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    59
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
    60
{
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    61
    close_font();
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
    // open regular font
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    64
    _font_regular = TTF_OpenFont(fname_regular, ptsize);
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    65
    if (!_font_regular)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    66
    {
58
50308ed5e4f9 sdlterm: Cleanup exceptions.
Radek Brich <radek.brich@devl.cz>
parents: 57
diff changeset
    67
        throw SDLTermError(std::string("TTF_OpenFont: ") + TTF_GetError());
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    68
    }
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    69
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    70
    // open bold font
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    71
    _font_bold = TTF_OpenFont(fname_bold, ptsize);
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    72
    if (!_font_bold)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    73
    {
58
50308ed5e4f9 sdlterm: Cleanup exceptions.
Radek Brich <radek.brich@devl.cz>
parents: 57
diff changeset
    74
        throw SDLTermError(std::string("TTF_OpenFont: ") + TTF_GetError());
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    75
    }
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    76
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    77
    // update metrics for regular font
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    78
    int advance;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    79
    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
    80
    {
58
50308ed5e4f9 sdlterm: Cleanup exceptions.
Radek Brich <radek.brich@devl.cz>
parents: 57
diff changeset
    81
        throw SDLTermError(std::string("TTF_GlyphMetrics: ") + TTF_GetError());
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    82
    }
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    83
    _cell_width = advance;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    84
    _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
    85
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    86
    // read metrics for bold font
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    87
    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
    88
    {
58
50308ed5e4f9 sdlterm: Cleanup exceptions.
Radek Brich <radek.brich@devl.cz>
parents: 57
diff changeset
    89
        throw SDLTermError(std::string("TTF_GlyphMetrics: ") + TTF_GetError());
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    90
    }
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    91
    if (advance > _cell_width)
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
        _cell_width = advance;
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
    int height = TTF_FontHeight(_font_bold);
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    96
    if (height > _cell_height)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    97
    {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    98
        _cell_height = height;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
    99
    }
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   100
}
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   101
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   102
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   103
void GlyphRenderer::close_font()
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   104
{
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   105
    if (_font_regular)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   106
    {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   107
        TTF_CloseFont(_font_regular);
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   108
        _font_regular = NULL;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   109
    }
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   110
    if (_font_bold)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   111
    {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   112
        TTF_CloseFont(_font_bold);
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   113
        _font_bold = NULL;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   114
    }
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   115
}
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   116
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   117
60
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   118
SDL_Surface *GlyphRenderer::render_cell(Uint32 ch, Uint32 attr, bool blink_state)
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   119
{
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   120
    SDL_Surface *cell_surface;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   121
    TTF_Font *font;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   122
    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
   123
60
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   124
    // blink affects cache lookup, must be processed first
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   125
    if ((attr & Style::BLINK) && !blink_state)
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   126
    {
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   127
        ch = ' ';
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   128
    }
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   129
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   130
    // 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
   131
    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
   132
    cell_surface = _cache.lookup_glyph(id);
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   133
    if (cell_surface)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   134
    {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   135
        return cell_surface;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   136
    }
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
   137
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   138
    // 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
   139
    _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
   140
    _colormap.index_to_rgb((attr & 0x0000FF00) >> 8, bgcolor);
60
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   141
    font = (attr & Style::BOLD) ? _font_bold : _font_regular;
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   142
    if (attr & Style::STANDOUT)
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
   143
    {
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
        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
   145
    }
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
    // 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
   148
    cell_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   149
            _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
   150
    SDL_Rect dst_rect;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   151
    dst_rect.x = 0;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   152
    dst_rect.y = 0;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   153
    dst_rect.w = _cell_width;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   154
    dst_rect.h = _cell_height;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   155
    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
   156
    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
   157
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   158
    // render glyph, blit it onto cell surface
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   159
    if (ch)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   160
    {
52
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   161
        // when glyph is not provided by BOLD font but is provided by REGULAR font, use that (better than nothing)
60
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   162
        if ((attr & Style::BOLD) && !TTF_GlyphIsProvided(font, ch) && TTF_GlyphIsProvided(_font_regular, ch))
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
   163
        {
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
            // 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
   165
            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
   166
            _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
   167
            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
   168
        }
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
        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
   170
        {
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
            // 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
   172
            _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
   173
        }
60
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   174
        if (attr & Style::UNDERLINE)
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
   175
        {
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
            // 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
   177
            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
   178
            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
   179
            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
   180
            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
   181
            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
   182
                *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
   183
            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
   184
        }
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   185
    }
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   186
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   187
    // convert to display format
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   188
    SDL_Surface *tmp_surface = cell_surface;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   189
    cell_surface = SDL_DisplayFormat(tmp_surface);
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   190
    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
   191
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   192
    // 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
   193
    _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
   194
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   195
    return cell_surface;
47
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
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   198
52
50a1857557da Update SDL driver: Enlarge char, attr to 32 bits, 64 bits per terminal cell. Colors and attributes are complete, only blink does not work.
Radek Brich <radek.brich@devl.cz>
parents: 51
diff changeset
   199
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
   200
        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
   201
{
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
    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
   203
    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
   204
    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
   205
    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
   206
    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
   207
    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
   208
    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
   209
    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
   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
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
   212
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   213
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
   214
{
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   215
    _render.open_font(fname_regular, fname_bold, ptsize);
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   216
    _reset_cells();
47
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
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   219
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
   220
{
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
   221
    _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
   222
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   223
    if (_screen_surface == NULL)
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   224
    {
58
50308ed5e4f9 sdlterm: Cleanup exceptions.
Radek Brich <radek.brich@devl.cz>
parents: 57
diff changeset
   225
        throw SDLTermError(std::string("SDL_SetVideoMode: ") + SDL_GetError());
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];
60
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   252
    cell.attr ^= Style::STANDOUT;
53
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;
60
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   270
                cell_surface = _render.render_cell(front_iter->ch, front_iter->attr, _blink_state);
51
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
60
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   309
void TerminalScreen::_draw_blink()
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   310
{
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   311
    // Use back buffer which contains commited changes.
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   312
    // This is called from timer while application may draw into front_buffer.
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   313
    auto back_iter = _cells_back.begin();
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   314
    SDL_Surface *cell_surface;
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   315
    SDL_Rect dst_rect;
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   316
    for (int y = 0; y < _height; y++)
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   317
    {
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   318
        for (int x = 0; x < _width; x++)
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   319
        {
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   320
            // draw only blinking characters
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   321
            if (back_iter->attr & Style::BLINK)
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   322
            {
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   323
                dst_rect.x = x * _cell_width;
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   324
                dst_rect.y = y * _cell_height;
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   325
                cell_surface = _render.render_cell(back_iter->ch, back_iter->attr, _blink_state);
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   326
                SDL_BlitSurface(cell_surface, NULL, _screen_surface, &dst_rect);
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   327
            }
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   328
            back_iter++;
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   329
        }
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   330
    }
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   331
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   332
    SDL_UpdateRect(_screen_surface, 0, 0, 0, 0);
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   333
}
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   334
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   335
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   336
Terminal::Terminal()
55
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 54
diff changeset
   337
 : _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
   338
   _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
   339
{
57
911927edbdde DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents: 55
diff changeset
   340
    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1)
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   341
    {
58
50308ed5e4f9 sdlterm: Cleanup exceptions.
Radek Brich <radek.brich@devl.cz>
parents: 57
diff changeset
   342
        throw SDLTermError(std::string("SDL_Init: ") + SDL_GetError());
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   343
    }
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
   344
    SDL_EnableUNICODE(1);
55
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 54
diff changeset
   345
    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
   346
    SDL_WM_SetCaption("terminal", NULL);
60
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   347
    SDL_AddTimer(500, _blink_toggle_callback, NULL);
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   348
}
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   349
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   350
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   351
Terminal::~Terminal()
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   352
{
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   353
    SDL_Quit();
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   354
}
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   355
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   356
53
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   357
void Terminal::commit()
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   358
{
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   359
    if (_cursor_visible)
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
        _screen.toggle_cursor(_cursor_x, _cursor_y);
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   362
        _screen.commit();
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   363
        _screen.toggle_cursor(_cursor_x, _cursor_y);
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   364
    }
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   365
    else
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   366
    {
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   367
        _screen.commit();
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   368
    }
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   369
}
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   370
57
911927edbdde DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents: 55
diff changeset
   371
911927edbdde DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents: 55
diff changeset
   372
bool Terminal::wait_event(Event &event, Uint32 timeout)
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   373
{
57
911927edbdde DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents: 55
diff changeset
   374
    // use timer to simulate SDL_WaitEventTimeout, which is not available in SDL 1.2
911927edbdde DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents: 55
diff changeset
   375
    SDL_TimerID timer_id = NULL;
911927edbdde DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents: 55
diff changeset
   376
    if (timeout)
911927edbdde DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents: 55
diff changeset
   377
    {
911927edbdde DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents: 55
diff changeset
   378
        timer_id = SDL_AddTimer(timeout, _wait_event_callback, NULL);
911927edbdde DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents: 55
diff changeset
   379
    }
911927edbdde DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents: 55
diff changeset
   380
62
2f61931520c9 Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents: 61
diff changeset
   381
    // loop until we have something to return
2f61931520c9 Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents: 61
diff changeset
   382
    SDL_Event sdl_event;
2f61931520c9 Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents: 61
diff changeset
   383
    bool event_ready = false;
61
15088f62c4ac DriverSDL: Fix.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   384
    while (SDL_WaitEvent(&sdl_event) && !event_ready)
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   385
    {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   386
        switch (sdl_event.type)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   387
        {
60
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   388
            case SDL_USEREVENT:
61
15088f62c4ac DriverSDL: Fix.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   389
                // timeout
15088f62c4ac DriverSDL: Fix.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   390
                if (sdl_event.user.code == 1)
15088f62c4ac DriverSDL: Fix.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   391
                {
15088f62c4ac DriverSDL: Fix.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   392
                    SDL_RemoveTimer(timer_id);
15088f62c4ac DriverSDL: Fix.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   393
                    return false;
15088f62c4ac DriverSDL: Fix.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   394
                }
60
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   395
                // toggle blink
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   396
                if (sdl_event.user.code == 2)
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   397
                {
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   398
                    _screen.toggle_blink();
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   399
                }
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   400
                break; // continue loop
61
15088f62c4ac DriverSDL: Fix.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   401
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   402
            case SDL_QUIT:
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   403
                event.type = Event::QUIT;
61
15088f62c4ac DriverSDL: Fix.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   404
                event_ready = true;
15088f62c4ac DriverSDL: Fix.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   405
                break;
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   406
53
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   407
            case SDL_VIDEORESIZE:
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   408
                event.type = Event::RESIZE;
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   409
                _screen.resize(sdl_event.resize.w, sdl_event.resize.h);
61
15088f62c4ac DriverSDL: Fix.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   410
                event_ready = true;
15088f62c4ac DriverSDL: Fix.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   411
                break;
53
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   412
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   413
            case SDL_VIDEOEXPOSE:
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   414
                _screen.redraw();
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   415
                break;
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   416
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   417
            case SDL_KEYDOWN:
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
                //switch(event.key.keysym.sym)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   420
                event.type = Event::KEYPRESS;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   421
                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
   422
                // return only keyname or unicode, never both
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   423
                if (keyname)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   424
                {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   425
                    strncpy(event.key.keyname, keyname, 10);
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   426
                    event.key.unicode = 0;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   427
                }
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   428
                else
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   429
                {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   430
                    event.key.keyname[0] = 0;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   431
                    event.key.unicode = sdl_event.key.keysym.unicode;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   432
                    if (!event.key.unicode)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   433
                        break; // continue loop (unknown key)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   434
                }
61
15088f62c4ac DriverSDL: Fix.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   435
                event_ready = true;
15088f62c4ac DriverSDL: Fix.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   436
                break;
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   437
            }
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
   438
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   439
            case SDL_MOUSEBUTTONDOWN:
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   440
            case SDL_MOUSEBUTTONUP:
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   441
                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
   442
                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
   443
                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
   444
                event.mouse.button = sdl_event.button.button;
55
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 54
diff changeset
   445
                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
   446
                {
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 54
diff changeset
   447
                    if (sdl_event.type == SDL_MOUSEBUTTONUP)
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 54
diff changeset
   448
                        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
   449
                    event.type = Event::MOUSEWHEEL;
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 54
diff changeset
   450
                }
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   451
                _mousemove_last_x = -1;
61
15088f62c4ac DriverSDL: Fix.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   452
                event_ready = true;
15088f62c4ac DriverSDL: Fix.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   453
                break;
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
   454
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   455
            case SDL_MOUSEMOTION:
53
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   456
                if (sdl_event.motion.state == 0)
c4263588b716 DriverSDL: Implement cursor, handle window resize.
Radek Brich <radek.brich@devl.cz>
parents: 52
diff changeset
   457
                    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
   458
                event.type = Event::MOUSEMOVE;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   459
                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
   460
                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
   461
                if (_mousemove_last_x != event.mouse.x ||
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   462
                    _mousemove_last_y != event.mouse.y)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   463
                {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   464
                    _mousemove_last_x = event.mouse.x;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   465
                    _mousemove_last_y = event.mouse.y;
61
15088f62c4ac DriverSDL: Fix.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   466
                    event_ready = true;
15088f62c4ac DriverSDL: Fix.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   467
                    break;
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   468
                }
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   469
                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
   470
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   471
            default:
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   472
                break; // continue loop
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   473
        }
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   474
    }
61
15088f62c4ac DriverSDL: Fix.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   475
15088f62c4ac DriverSDL: Fix.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   476
    // remove timer when other event came before timeout
15088f62c4ac DriverSDL: Fix.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   477
    if (timeout)
15088f62c4ac DriverSDL: Fix.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   478
    {
15088f62c4ac DriverSDL: Fix.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   479
        SDL_RemoveTimer(timer_id);
15088f62c4ac DriverSDL: Fix.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   480
    }
15088f62c4ac DriverSDL: Fix.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   481
15088f62c4ac DriverSDL: Fix.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   482
    // ok or error?
15088f62c4ac DriverSDL: Fix.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   483
    if (event_ready)
15088f62c4ac DriverSDL: Fix.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   484
    {
15088f62c4ac DriverSDL: Fix.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   485
        return true;
15088f62c4ac DriverSDL: Fix.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   486
    }
15088f62c4ac DriverSDL: Fix.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   487
    else
15088f62c4ac DriverSDL: Fix.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   488
    {
15088f62c4ac DriverSDL: Fix.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   489
        throw SDLTermError(std::string("SDL_WaitEvent: ") + SDL_GetError());
15088f62c4ac DriverSDL: Fix.
Radek Brich <radek.brich@devl.cz>
parents: 60
diff changeset
   490
    }
47
537d7c6b48a2 Add sdlterm prototype: extension module for SDL driver.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   491
}
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
   492
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
   493
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
   494
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
   495
{
51
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   496
    switch (sym)
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   497
    {
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   498
        case SDLK_BACKSPACE:    return "backspace";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   499
        case SDLK_TAB:          return "tab";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   500
        case SDLK_RETURN:       return "enter";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   501
        case SDLK_KP_ENTER:     return "enter";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   502
        case SDLK_ESCAPE:       return "escape";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   503
        case SDLK_DELETE:       return "delete";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   504
        case SDLK_INSERT:       return "insert";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   505
        case SDLK_UP:           return "up";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   506
        case SDLK_DOWN:         return "down";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   507
        case SDLK_LEFT:         return "left";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   508
        case SDLK_RIGHT:        return "right";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   509
        case SDLK_HOME:         return "home";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   510
        case SDLK_END:          return "end";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   511
        case SDLK_PAGEUP:       return "pageup";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   512
        case SDLK_PAGEDOWN:     return "pagedown";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   513
        case SDLK_F1:           return "f1";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   514
        case SDLK_F2:           return "f2";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   515
        case SDLK_F3:           return "f3";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   516
        case SDLK_F4:           return "f4";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   517
        case SDLK_F5:           return "f5";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   518
        case SDLK_F6:           return "f6";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   519
        case SDLK_F7:           return "f7";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   520
        case SDLK_F8:           return "f8";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   521
        case SDLK_F9:           return "f9";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   522
        case SDLK_F10:          return "f10";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   523
        case SDLK_F11:          return "f11";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   524
        case SDLK_F12:          return "f12";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   525
        case SDLK_PRINT:        return "print";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   526
        case SDLK_SCROLLOCK:    return "scrllock";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   527
        case SDLK_PAUSE:        return "pause";
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   528
        default: return NULL;
dce7325109c1 Clean up: expand unwanted tabs.
Radek Brich <radek.brich@devl.cz>
parents: 50
diff changeset
   529
    }
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
   530
}
1f00e90fd72a Add SDL driver prototype. Update sdlterm: Handle keyboard, mouse events. Add glyph cache.
Radek Brich <radek.brich@devl.cz>
parents: 47
diff changeset
   531
57
911927edbdde DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents: 55
diff changeset
   532
911927edbdde DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents: 55
diff changeset
   533
Uint32 Terminal::_wait_event_callback(Uint32 interval, void *param)
911927edbdde DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents: 55
diff changeset
   534
{
911927edbdde DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents: 55
diff changeset
   535
    SDL_Event event;
911927edbdde DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents: 55
diff changeset
   536
    event.type = SDL_USEREVENT;
911927edbdde DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents: 55
diff changeset
   537
    event.user.code = 1;
911927edbdde DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents: 55
diff changeset
   538
    SDL_PushEvent(&event);
911927edbdde DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents: 55
diff changeset
   539
    return 0;
911927edbdde DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents: 55
diff changeset
   540
}
911927edbdde DriverSDL: Add support for timeouts.
Radek Brich <radek.brich@devl.cz>
parents: 55
diff changeset
   541
60
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   542
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   543
Uint32 Terminal::_blink_toggle_callback(Uint32 interval, void *param)
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   544
{
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   545
    SDL_Event event;
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   546
    event.type = SDL_USEREVENT;
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   547
    event.user.code = 2;
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   548
    SDL_PushEvent(&event);
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   549
    return interval;
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   550
}
fccca2a60492 DriverSDL: Implement blink attribute.
Radek Brich <radek.brich@devl.cz>
parents: 58
diff changeset
   551