# HG changeset patch # User Radek Brich # Date 1357408605 -3600 # Node ID dce7325109c1e4fc2055b88845d1790261cd0e97 # Parent c5b8b9d2da959060aa51c5723124a626a08aee0f Clean up: expand unwanted tabs. diff -r c5b8b9d2da95 -r dce7325109c1 sdlterm/demo.cc --- a/sdlterm/demo.cc Sat Jan 05 18:44:56 2013 +0100 +++ b/sdlterm/demo.cc Sat Jan 05 18:56:45 2013 +0100 @@ -4,57 +4,57 @@ class Application { public: - Terminal term; - bool done; + Terminal term; + bool done; - Application() : term(), done(false) {}; + Application() : term(), done(false) {}; - void init(); - void wait_and_process_event(); + void init(); + void wait_and_process_event(); }; void Application::init() { - term.resize(800, 600); - term.select_font("font/DejaVuSansMono.ttf", "font/DejaVuSansMono-Bold.ttf", 12); - term.erase(); - term.set_attr( term.prepare_attr(14, 1, 1) ); + term.resize(800, 600); + term.select_font("font/DejaVuSansMono.ttf", "font/DejaVuSansMono-Bold.ttf", 12); + term.erase(); + term.set_attr( term.prepare_attr(14, 1, 1) ); - char hello[] = "Hello World!"; - for (char *c = hello; *c; c++) - { - term.putch(5 + (c - hello), 5, *c); - } - term.commit(); + char hello[] = "Hello World!"; + for (char *c = hello; *c; c++) + { + term.putch(5 + (c - hello), 5, *c); + } + term.commit(); } void Application::wait_and_process_event() { - Event event; - term.get_next_event(event); + Event event; + term.get_next_event(event); - switch (event.type) - { - case Event::QUIT: - done = true; - break; + switch (event.type) + { + case Event::QUIT: + done = true; + break; - default: - break; - } + default: + break; + } } int main(int argc, char *argv[]) { - Application app; - app.init(); + Application app; + app.init(); while (!app.done) { - app.wait_and_process_event(); + app.wait_and_process_event(); } return 0; diff -r c5b8b9d2da95 -r dce7325109c1 sdlterm/src/sdlterm.cc --- a/sdlterm/src/sdlterm.cc Sat Jan 05 18:44:56 2013 +0100 +++ b/sdlterm/src/sdlterm.cc Sat Jan 05 18:56:45 2013 +0100 @@ -6,177 +6,177 @@ void ColorMap::index_to_rgb(int index, SDL_Color &color) { - color.r = _map[index][0]; - color.g = _map[index][1]; - color.b = _map[index][2]; + color.r = _map[index][0]; + color.g = _map[index][1]; + color.b = _map[index][2]; } SDL_Surface *GlyphCache::lookup_glyph(Uint16 ch) { - auto iter = _glyph_map.find(ch); - if (iter == _glyph_map.end()) - { - return NULL; - } - return iter->second; + auto iter = _glyph_map.find(ch); + if (iter == _glyph_map.end()) + { + return NULL; + } + return iter->second; } void GlyphCache::put_glyph(Uint16 ch, SDL_Surface *srf) { - _glyph_map[ch] = srf; + _glyph_map[ch] = srf; } void GlyphCache::flush() { - for (auto iter = _glyph_map.begin(); iter != _glyph_map.end(); iter++) - { - SDL_FreeSurface(iter->second); - } - _glyph_map.clear(); + for (auto iter = _glyph_map.begin(); iter != _glyph_map.end(); iter++) + { + SDL_FreeSurface(iter->second); + } + _glyph_map.clear(); } GlyphRenderer::GlyphRenderer() : _font_regular(NULL), _font_bold(NULL), _cell_width(0), _cell_height(0), _cache(), _colormap() { - if (TTF_Init() == -1) - { - printf("TTF_Init: %s\n", TTF_GetError()); - throw std::exception(); - } + if (TTF_Init() == -1) + { + printf("TTF_Init: %s\n", TTF_GetError()); + throw std::exception(); + } } GlyphRenderer::~GlyphRenderer() { - _cache.flush(); - close_font(); - TTF_Quit(); + _cache.flush(); + close_font(); + TTF_Quit(); } void GlyphRenderer::open_font(const char *fname_regular, const char *fname_bold, int ptsize) { - close_font(); + close_font(); - // open regular font - _font_regular = TTF_OpenFont(fname_regular, ptsize); - if (!_font_regular) - { - printf("TTF_OpenFont: %s\n", TTF_GetError()); - throw std::exception(); - } + // open regular font + _font_regular = TTF_OpenFont(fname_regular, ptsize); + if (!_font_regular) + { + printf("TTF_OpenFont: %s\n", TTF_GetError()); + throw std::exception(); + } - // open bold font - _font_bold = TTF_OpenFont(fname_bold, ptsize); - if (!_font_bold) - { - printf("TTF_OpenFont: %s\n", TTF_GetError()); - throw std::exception(); - } + // open bold font + _font_bold = TTF_OpenFont(fname_bold, ptsize); + if (!_font_bold) + { + printf("TTF_OpenFont: %s\n", TTF_GetError()); + throw std::exception(); + } - // update metrics for regular font - int advance; - if (TTF_GlyphMetrics(_font_regular, 'M', NULL, NULL, NULL, NULL, &advance) == -1) - { - printf("TTF_GlyphMetrics: %s\n", TTF_GetError()); - } - _cell_width = advance; - _cell_height = TTF_FontHeight(_font_regular); + // update metrics for regular font + int advance; + if (TTF_GlyphMetrics(_font_regular, 'M', NULL, NULL, NULL, NULL, &advance) == -1) + { + printf("TTF_GlyphMetrics: %s\n", TTF_GetError()); + } + _cell_width = advance; + _cell_height = TTF_FontHeight(_font_regular); - // read metrics for bold font - if (TTF_GlyphMetrics(_font_bold, 'M', NULL, NULL, NULL, NULL, &advance) == -1) - { - printf("TTF_GlyphMetrics: %s\n", TTF_GetError()); - } - if (advance > _cell_width) - { - _cell_width = advance; - } - int height = TTF_FontHeight(_font_bold); - if (height > _cell_height) - { - _cell_height = height; - } + // read metrics for bold font + if (TTF_GlyphMetrics(_font_bold, 'M', NULL, NULL, NULL, NULL, &advance) == -1) + { + printf("TTF_GlyphMetrics: %s\n", TTF_GetError()); + } + if (advance > _cell_width) + { + _cell_width = advance; + } + int height = TTF_FontHeight(_font_bold); + if (height > _cell_height) + { + _cell_height = height; + } } void GlyphRenderer::close_font() { - if (_font_regular) - { - TTF_CloseFont(_font_regular); - _font_regular = NULL; - } - if (_font_bold) - { - TTF_CloseFont(_font_bold); - _font_bold = NULL; - } + if (_font_regular) + { + TTF_CloseFont(_font_regular); + _font_regular = NULL; + } + if (_font_bold) + { + TTF_CloseFont(_font_bold); + _font_bold = NULL; + } } SDL_Surface *GlyphRenderer::render_cell(Uint16 ch, Uint16 attr) { - SDL_Surface *cell_surface; - TTF_Font *font; - SDL_Color fgcolor, bgcolor; + SDL_Surface *cell_surface; + TTF_Font *font; + SDL_Color fgcolor, bgcolor; - // try cache - cell_surface = _cache.lookup_glyph(ch); - if (cell_surface) - { - return cell_surface; - } + // try cache + cell_surface = _cache.lookup_glyph(ch); + if (cell_surface) + { + return cell_surface; + } - // load attributes - _colormap.index_to_rgb(attr & 0x000F, fgcolor); - _colormap.index_to_rgb((attr & 0x00F0) >> 4, bgcolor); - Style style = (Style) ((attr & 0xFF00) >> 8); - font = (style == Style::BOLD) ? _font_bold : _font_regular; + // load attributes + _colormap.index_to_rgb(attr & 0x000F, fgcolor); + _colormap.index_to_rgb((attr & 0x00F0) >> 4, bgcolor); + Style style = (Style) ((attr & 0xFF00) >> 8); + font = (style == Style::BOLD) ? _font_bold : _font_regular; - // create surface for whole cell and fill it with bg color - cell_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, - _cell_width, _cell_height, 32, 0, 0, 0, 0); - SDL_Rect dst_rect; - dst_rect.x = 0; - dst_rect.y = 0; - dst_rect.w = _cell_width; - dst_rect.h = _cell_height; - Uint32 bgcolor_mapped = SDL_MapRGB(cell_surface->format, bgcolor.r, bgcolor.g, bgcolor.b); - SDL_FillRect(cell_surface, &dst_rect, bgcolor_mapped); + // create surface for whole cell and fill it with bg color + cell_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, + _cell_width, _cell_height, 32, 0, 0, 0, 0); + SDL_Rect dst_rect; + dst_rect.x = 0; + dst_rect.y = 0; + dst_rect.w = _cell_width; + dst_rect.h = _cell_height; + Uint32 bgcolor_mapped = SDL_MapRGB(cell_surface->format, bgcolor.r, bgcolor.g, bgcolor.b); + SDL_FillRect(cell_surface, &dst_rect, bgcolor_mapped); - // render glyph, blit it onto cell surface - if (ch) - { - SDL_Surface *glyph_surface = TTF_RenderGlyph_Shaded(font, ch, fgcolor, bgcolor); - int minx, maxy; - TTF_GlyphMetrics(font, ch, &minx, NULL, NULL, &maxy, NULL); - dst_rect.x = minx; - dst_rect.y = TTF_FontAscent(font) - maxy; - SDL_BlitSurface(glyph_surface, NULL, cell_surface, &dst_rect); - SDL_FreeSurface(glyph_surface); - } + // render glyph, blit it onto cell surface + if (ch) + { + SDL_Surface *glyph_surface = TTF_RenderGlyph_Shaded(font, ch, fgcolor, bgcolor); + int minx, maxy; + TTF_GlyphMetrics(font, ch, &minx, NULL, NULL, &maxy, NULL); + dst_rect.x = minx; + dst_rect.y = TTF_FontAscent(font) - maxy; + SDL_BlitSurface(glyph_surface, NULL, cell_surface, &dst_rect); + SDL_FreeSurface(glyph_surface); + } - // convert to display format - SDL_Surface *tmp_surface = cell_surface; - cell_surface = SDL_DisplayFormat(tmp_surface); - SDL_FreeSurface(tmp_surface); + // convert to display format + SDL_Surface *tmp_surface = cell_surface; + cell_surface = SDL_DisplayFormat(tmp_surface); + SDL_FreeSurface(tmp_surface); - // put to cache - _cache.put_glyph(ch, cell_surface); + // put to cache + _cache.put_glyph(ch, cell_surface); - return cell_surface; + return cell_surface; } void TerminalScreen::select_font(const char *fname_regular, const char *fname_bold, int ptsize) { - _render.open_font(fname_regular, fname_bold, ptsize); - _reset_cells(); + _render.open_font(fname_regular, fname_bold, ptsize); + _reset_cells(); } void TerminalScreen::resize(int pxwidth, int pxheight) @@ -185,8 +185,8 @@ if (_screen_surface == NULL) { - fprintf(stderr, "Unable to set video: %s\n", SDL_GetError()); - throw std::exception(); + fprintf(stderr, "Unable to set video: %s\n", SDL_GetError()); + throw std::exception(); } SDL_WM_SetCaption("terminal", NULL); @@ -200,60 +200,60 @@ void TerminalScreen::erase() { - std::fill(_cells_front.begin(), _cells_front.end(), TerminalCell()); + std::fill(_cells_front.begin(), _cells_front.end(), TerminalCell()); } void TerminalScreen::putch(int x, int y, Uint16 ch, Uint16 attr) { - TerminalCell &cell = _cells_front[y * _width + x]; - cell.ch = ch; - cell.attr = attr; + TerminalCell &cell = _cells_front[y * _width + x]; + cell.ch = ch; + cell.attr = attr; } void TerminalScreen::commit() { - auto front_iter = _cells_front.begin(); - auto back_iter = _cells_back.begin(); - SDL_Surface *cell_surface; - SDL_Rect dst_rect; - for (int y = 0; y < _height; y++) - { - for (int x = 0; x < _width; x++) - { - if (*front_iter != *back_iter) - { - dst_rect.x = x * _cell_width; - dst_rect.y = y * _cell_height; - cell_surface = _render.render_cell(front_iter->ch, front_iter->attr); - SDL_BlitSurface(cell_surface, NULL, _screen_surface, &dst_rect); - *back_iter = *front_iter; - } - front_iter++; - back_iter++; - } - } + auto front_iter = _cells_front.begin(); + auto back_iter = _cells_back.begin(); + SDL_Surface *cell_surface; + SDL_Rect dst_rect; + for (int y = 0; y < _height; y++) + { + for (int x = 0; x < _width; x++) + { + if (*front_iter != *back_iter) + { + dst_rect.x = x * _cell_width; + dst_rect.y = y * _cell_height; + cell_surface = _render.render_cell(front_iter->ch, front_iter->attr); + SDL_BlitSurface(cell_surface, NULL, _screen_surface, &dst_rect); + *back_iter = *front_iter; + } + front_iter++; + back_iter++; + } + } - SDL_UpdateRect(_screen_surface, 0, 0, 0, 0); + SDL_UpdateRect(_screen_surface, 0, 0, 0, 0); } void TerminalScreen::_reset_cells() { - _cell_width = _render.get_cell_width(); - _cell_height = _render.get_cell_height(); - if (!_cell_width || !_cell_height) - return; + _cell_width = _render.get_cell_width(); + _cell_height = _render.get_cell_height(); + if (!_cell_width || !_cell_height) + return; - _width = _pixel_width / _cell_width; - _height = _pixel_height / _cell_height; - if (!_width || !_height) - return; + _width = _pixel_width / _cell_width; + _height = _pixel_height / _cell_height; + if (!_width || !_height) + return; - int num_cells = _width * _height; - _cells_front.resize(num_cells, TerminalCell()); - _cells_back.resize(num_cells, TerminalCell()); + int num_cells = _width * _height; + _cells_front.resize(num_cells, TerminalCell()); + _cells_back.resize(num_cells, TerminalCell()); } @@ -262,8 +262,8 @@ { if (SDL_Init(SDL_INIT_VIDEO) == -1) { - fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError()); - throw std::exception(); + fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError()); + throw std::exception(); } SDL_EnableUNICODE(1); } @@ -271,107 +271,107 @@ Terminal::~Terminal() { - SDL_Quit(); + SDL_Quit(); } void Terminal::get_next_event(Event &event) { - static SDL_Event sdl_event; + static SDL_Event sdl_event; - while (SDL_WaitEvent(&sdl_event)) - { - switch (sdl_event.type) - { - case SDL_QUIT: - event.type = Event::QUIT; - return; + while (SDL_WaitEvent(&sdl_event)) + { + switch (sdl_event.type) + { + case SDL_QUIT: + event.type = Event::QUIT; + return; - case SDL_KEYDOWN: - { - //switch(event.key.keysym.sym) - event.type = Event::KEYPRESS; - const char *keyname = _translate_keyname(sdl_event.key.keysym.sym); - // return only keyname or unicode, never both - if (keyname) - { - strncpy(event.key.keyname, keyname, 10); - event.key.unicode = 0; - } - else - { - event.key.keyname[0] = 0; - event.key.unicode = sdl_event.key.keysym.unicode; - if (!event.key.unicode) - break; // continue loop (unknown key) - } - return; - } + case SDL_KEYDOWN: + { + //switch(event.key.keysym.sym) + event.type = Event::KEYPRESS; + const char *keyname = _translate_keyname(sdl_event.key.keysym.sym); + // return only keyname or unicode, never both + if (keyname) + { + strncpy(event.key.keyname, keyname, 10); + event.key.unicode = 0; + } + else + { + event.key.keyname[0] = 0; + event.key.unicode = sdl_event.key.keysym.unicode; + if (!event.key.unicode) + break; // continue loop (unknown key) + } + return; + } - case SDL_MOUSEBUTTONDOWN: - case SDL_MOUSEBUTTONUP: - event.type = (sdl_event.type == SDL_MOUSEBUTTONDOWN) ? Event::MOUSEDOWN : Event::MOUSEUP; - event.mouse.x = sdl_event.button.x / _screen.get_cell_width(); - event.mouse.y = sdl_event.button.y / _screen.get_cell_height(); - event.mouse.button = sdl_event.button.button; - _mousemove_last_x = -1; - return; + case SDL_MOUSEBUTTONDOWN: + case SDL_MOUSEBUTTONUP: + event.type = (sdl_event.type == SDL_MOUSEBUTTONDOWN) ? Event::MOUSEDOWN : Event::MOUSEUP; + event.mouse.x = sdl_event.button.x / _screen.get_cell_width(); + event.mouse.y = sdl_event.button.y / _screen.get_cell_height(); + event.mouse.button = sdl_event.button.button; + _mousemove_last_x = -1; + return; - case SDL_MOUSEMOTION: - event.type = Event::MOUSEMOVE; - event.mouse.x = sdl_event.motion.x / _screen.get_cell_width(); - event.mouse.y = sdl_event.motion.y / _screen.get_cell_height(); - if (_mousemove_last_x != event.mouse.x || - _mousemove_last_y != event.mouse.y) - { - _mousemove_last_x = event.mouse.x; - _mousemove_last_y = event.mouse.y; - return; - } - break; // continue loop when mouse position did not change + case SDL_MOUSEMOTION: + event.type = Event::MOUSEMOVE; + event.mouse.x = sdl_event.motion.x / _screen.get_cell_width(); + event.mouse.y = sdl_event.motion.y / _screen.get_cell_height(); + if (_mousemove_last_x != event.mouse.x || + _mousemove_last_y != event.mouse.y) + { + _mousemove_last_x = event.mouse.x; + _mousemove_last_y = event.mouse.y; + return; + } + break; // continue loop when mouse position did not change - default: - break; // continue loop - } - } + default: + break; // continue loop + } + } } const char *Terminal::_translate_keyname(SDLKey sym) { - switch (sym) - { - case SDLK_BACKSPACE: return "backspace"; - case SDLK_TAB: return "tab"; - case SDLK_RETURN: return "enter"; - case SDLK_KP_ENTER: return "enter"; - case SDLK_ESCAPE: return "escape"; - case SDLK_DELETE: return "delete"; - case SDLK_INSERT: return "insert"; - case SDLK_UP: return "up"; - case SDLK_DOWN: return "down"; - case SDLK_LEFT: return "left"; - case SDLK_RIGHT: return "right"; - case SDLK_HOME: return "home"; - case SDLK_END: return "end"; - case SDLK_PAGEUP: return "pageup"; - case SDLK_PAGEDOWN: return "pagedown"; - case SDLK_F1: return "f1"; - case SDLK_F2: return "f2"; - case SDLK_F3: return "f3"; - case SDLK_F4: return "f4"; - case SDLK_F5: return "f5"; - case SDLK_F6: return "f6"; - case SDLK_F7: return "f7"; - case SDLK_F8: return "f8"; - case SDLK_F9: return "f9"; - case SDLK_F10: return "f10"; - case SDLK_F11: return "f11"; - case SDLK_F12: return "f12"; - case SDLK_PRINT: return "print"; - case SDLK_SCROLLOCK: return "scrllock"; - case SDLK_PAUSE: return "pause"; - default: return NULL; - } + switch (sym) + { + case SDLK_BACKSPACE: return "backspace"; + case SDLK_TAB: return "tab"; + case SDLK_RETURN: return "enter"; + case SDLK_KP_ENTER: return "enter"; + case SDLK_ESCAPE: return "escape"; + case SDLK_DELETE: return "delete"; + case SDLK_INSERT: return "insert"; + case SDLK_UP: return "up"; + case SDLK_DOWN: return "down"; + case SDLK_LEFT: return "left"; + case SDLK_RIGHT: return "right"; + case SDLK_HOME: return "home"; + case SDLK_END: return "end"; + case SDLK_PAGEUP: return "pageup"; + case SDLK_PAGEDOWN: return "pagedown"; + case SDLK_F1: return "f1"; + case SDLK_F2: return "f2"; + case SDLK_F3: return "f3"; + case SDLK_F4: return "f4"; + case SDLK_F5: return "f5"; + case SDLK_F6: return "f6"; + case SDLK_F7: return "f7"; + case SDLK_F8: return "f8"; + case SDLK_F9: return "f9"; + case SDLK_F10: return "f10"; + case SDLK_F11: return "f11"; + case SDLK_F12: return "f12"; + case SDLK_PRINT: return "print"; + case SDLK_SCROLLOCK: return "scrllock"; + case SDLK_PAUSE: return "pause"; + default: return NULL; + } } diff -r c5b8b9d2da95 -r dce7325109c1 sdlterm/src/sdlterm.h --- a/sdlterm/src/sdlterm.h Sat Jan 05 18:44:56 2013 +0100 +++ b/sdlterm/src/sdlterm.h Sat Jan 05 18:56:45 2013 +0100 @@ -7,34 +7,34 @@ enum class Style: Uint16 { - BOLD = 1 << 0, // bold font - UNDERLINE = 1 << 1, // underline text - STANDOUT = 1 << 2, // inverse bg/fg - BLINK = 1 << 3, // blinking + BOLD = 1 << 0, // bold font + UNDERLINE = 1 << 1, // underline text + STANDOUT = 1 << 2, // inverse bg/fg + BLINK = 1 << 3, // blinking }; class ColorMap { private: - Uint8 _map[16][3] = { - {0,0,0}, // 0 - black - {23,23,178}, // 1 - blue + Uint8 _map[16][3] = { + {0,0,0}, // 0 - black + {23,23,178}, // 1 - blue {23,178,23}, // 2 - green {23,178,178}, // 3 - cyan - {178,23,23}, // 4 - red - {178,23,178}, // 5 - magenta - {178,103,23}, // 6 - brown - {178,178,178}, // 7 - light gray - {104,104,104}, // 8 - gray - {84,84,255}, // 9 - light blue - {84,255,84}, // 10 - light green - {84,255,255}, // 11 - light cyan - {255,84,84}, // 12 - light red - {255,84,255}, // 13 - light magenta + {178,23,23}, // 4 - red + {178,23,178}, // 5 - magenta + {178,103,23}, // 6 - brown + {178,178,178}, // 7 - light gray + {104,104,104}, // 8 - gray + {84,84,255}, // 9 - light blue + {84,255,84}, // 10 - light green + {84,255,255}, // 11 - light cyan + {255,84,84}, // 12 - light red + {255,84,255}, // 13 - light magenta {255,255,84}, // 14 - yellow {255,255,255}, // 15 - white - }; + }; public: void index_to_rgb(int index, SDL_Color &color); @@ -44,141 +44,142 @@ class GlyphCache { public: - SDL_Surface *lookup_glyph(Uint16 ch); - void put_glyph(Uint16 ch, SDL_Surface *srf); - void flush(); + SDL_Surface *lookup_glyph(Uint16 ch); + void put_glyph(Uint16 ch, SDL_Surface *srf); + void flush(); private: - std::map _glyph_map; + std::map _glyph_map; }; class GlyphRenderer { public: - GlyphRenderer(); - ~GlyphRenderer(); + GlyphRenderer(); + ~GlyphRenderer(); - void open_font(const char *fname_regular, const char *fname_bold, int ptsize); - void close_font(); + void open_font(const char *fname_regular, const char *fname_bold, int ptsize); + void close_font(); - // do not free surface returned! - SDL_Surface *render_cell(Uint16 ch, Uint16 attr); + // do not free surface returned! + SDL_Surface *render_cell(Uint16 ch, Uint16 attr); - int get_cell_width() { return _cell_width; }; - int get_cell_height() { return _cell_height; }; + int get_cell_width() { return _cell_width; }; + int get_cell_height() { return _cell_height; }; private: - TTF_Font *_font_regular; - TTF_Font *_font_bold; - int _cell_width; - int _cell_height; - GlyphCache _cache; - ColorMap _colormap; + TTF_Font *_font_regular; + TTF_Font *_font_bold; + int _cell_width; + int _cell_height; + GlyphCache _cache; + ColorMap _colormap; }; struct TerminalCell { - Uint16 ch; - Uint16 attr; - bool operator !=(const TerminalCell &rhs) const { return ch != rhs.ch || attr != rhs.attr; }; + Uint16 ch; + Uint16 attr; + bool operator !=(const TerminalCell &rhs) const { return ch != rhs.ch || attr != rhs.attr; }; }; class TerminalScreen { public: - TerminalScreen(): - _screen_surface(NULL), _cells_front(0), _cells_back(0), _render(), - _pixel_width(0), _pixel_height(0) {}; - ~TerminalScreen() {}; + TerminalScreen(): + _screen_surface(NULL), _cells_front(0), _cells_back(0), _render(), + _pixel_width(0), _pixel_height(0), _width(0), _height(0), + _cell_width(0), _cell_height(0) {}; + ~TerminalScreen() {}; - void select_font(const char *fname_regular, const char *fname_bold, int ptsize); - void resize(int pxwidth, int pxheight); + void select_font(const char *fname_regular, const char *fname_bold, int ptsize); + void resize(int pxwidth, int pxheight); - void erase(); - void putch(int x, int y, Uint16 ch, Uint16 attr); - void commit(); + void erase(); + void putch(int x, int y, Uint16 ch, Uint16 attr); + void commit(); - int get_width() { return _width; }; - int get_height() { return _height; }; - int get_cell_width() { return _cell_width; }; - int get_cell_height() { return _cell_height; }; + int get_width() { return _width; }; + int get_height() { return _height; }; + int get_cell_width() { return _cell_width; }; + int get_cell_height() { return _cell_height; }; private: - SDL_Surface *_screen_surface; - std::vector _cells_front; - std::vector _cells_back; - GlyphRenderer _render; + SDL_Surface *_screen_surface; + std::vector _cells_front; + std::vector _cells_back; + GlyphRenderer _render; - int _pixel_width; // terminal window width in pixels - int _pixel_height; - int _width; // width in characters - int _height; // height in characters - int _cell_width; // character cell width in pixels - int _cell_height; + int _pixel_width; // terminal window width in pixels + int _pixel_height; + int _width; // width in characters + int _height; // height in characters + int _cell_width; // character cell width in pixels + int _cell_height; - void _reset_cells(); + void _reset_cells(); }; struct Event { - enum { QUIT, RESIZE, KEYPRESS, MOUSEDOWN, MOUSEUP, MOUSEMOVE, MOUSEWHEEL }; - int type; + enum { QUIT, RESIZE, KEYPRESS, MOUSEDOWN, MOUSEUP, MOUSEMOVE, MOUSEWHEEL }; + int type; - union - { - struct - { - char keyname[10]; - Uint16 unicode; - } key; - struct - { - int x, y; - int button; - } mouse; - }; + union + { + struct + { + char keyname[10]; + Uint16 unicode; + } key; + struct + { + int x, y; + int button; + } mouse; + }; }; class Terminal { public: - Terminal(); - ~Terminal(); + Terminal(); + ~Terminal(); - void select_font(const char *fname_regular, const char *fname_bold, int ptsize) - { _screen.select_font(fname_regular, fname_bold, ptsize); }; - void resize(int pxwidth, int pxheight) { _screen.resize(pxwidth, pxheight); }; + void select_font(const char *fname_regular, const char *fname_bold, int ptsize) + { _screen.select_font(fname_regular, fname_bold, ptsize); }; + void resize(int pxwidth, int pxheight) { _screen.resize(pxwidth, pxheight); }; - void erase() { _screen.erase(); }; - void putch(int x, int y, Uint16 ch) { _screen.putch(x, y, ch, _attr); }; - void commit() { _screen.commit(); }; + void erase() { _screen.erase(); }; + void putch(int x, int y, Uint16 ch) { _screen.putch(x, y, ch, _attr); }; + void commit() { _screen.commit(); }; - Uint16 prepare_attr(Uint8 fg, Uint8 bg, Uint8 style) { return fg | bg << 4 | style << 8; }; - void set_attr(Uint16 value) { _attr = value; }; + Uint16 prepare_attr(Uint8 fg, Uint8 bg, Uint8 style) { return fg | bg << 4 | style << 8; }; + void set_attr(Uint16 value) { _attr = value; }; - void set_cursor(int x, int y) { _cursor_x = x; _cursor_y = y; }; - void show_cursor(bool visible) { _cursor_visible = visible; }; + void set_cursor(int x, int y) { _cursor_x = x; _cursor_y = y; }; + void show_cursor(bool visible) { _cursor_visible = visible; }; - void get_next_event(Event &event); + void get_next_event(Event &event); - int get_width() { return _screen.get_width(); }; - int get_height() { return _screen.get_height(); }; + int get_width() { return _screen.get_width(); }; + int get_height() { return _screen.get_height(); }; private: - TerminalScreen _screen; - Uint16 _attr; - int _cursor_x; - int _cursor_y; - bool _cursor_visible; + TerminalScreen _screen; + Uint16 _attr; + int _cursor_x; + int _cursor_y; + bool _cursor_visible; - int _mousemove_last_x; - int _mousemove_last_y; + int _mousemove_last_x; + int _mousemove_last_y; - const char *_translate_keyname(SDLKey sym); + const char *_translate_keyname(SDLKey sym); };