sdlterm/src/sdlterm.h
changeset 53 c4263588b716
parent 52 50a1857557da
child 54 86b84535726e
equal deleted inserted replaced
52:50a1857557da 53:c4263588b716
    35         {255,255,84},   // 14 - yellow
    35         {255,255,84},   // 14 - yellow
    36         {255,255,255},  // 15 - white
    36         {255,255,255},  // 15 - white
    37     };
    37     };
    38 
    38 
    39 public:
    39 public:
    40     void index_to_rgb(int index, SDL_Color &color);
    40     void index_to_rgb(int index, SDL_Color &color) const;
    41 };
    41 };
    42 
    42 
    43 
    43 
    44 class GlyphCache
    44 class GlyphCache
    45 {
    45 {
    64     void close_font();
    64     void close_font();
    65 
    65 
    66     // do not free surface returned!
    66     // do not free surface returned!
    67     SDL_Surface *render_cell(Uint32 ch, Uint32 attr);
    67     SDL_Surface *render_cell(Uint32 ch, Uint32 attr);
    68 
    68 
    69     int get_cell_width() { return _cell_width; };
    69     int get_cell_width() const { return _cell_width; };
    70     int get_cell_height() { return _cell_height; };
    70     int get_cell_height() const { return _cell_height; };
    71 
    71 
    72 private:
    72 private:
    73     TTF_Font *_font_regular;
    73     TTF_Font *_font_regular;
    74     TTF_Font *_font_bold;
    74     TTF_Font *_font_bold;
    75     int _cell_width;
    75     int _cell_width;
    98  */
    98  */
    99 struct TerminalCell
    99 struct TerminalCell
   100 {
   100 {
   101     Uint32 ch;
   101     Uint32 ch;
   102     Uint32 attr;
   102     Uint32 attr;
       
   103 
       
   104     TerminalCell() : ch(0), attr(7) {};
   103     bool operator !=(const TerminalCell &rhs) const { return ch != rhs.ch || attr != rhs.attr; };
   105     bool operator !=(const TerminalCell &rhs) const { return ch != rhs.ch || attr != rhs.attr; };
   104 };
   106 };
   105 
   107 
   106 
   108 
   107 class TerminalScreen
   109 class TerminalScreen
   116     void select_font(const char *fname_regular, const char *fname_bold, int ptsize);
   118     void select_font(const char *fname_regular, const char *fname_bold, int ptsize);
   117     void resize(int pxwidth, int pxheight);
   119     void resize(int pxwidth, int pxheight);
   118 
   120 
   119     void erase();
   121     void erase();
   120     void putch(int x, int y, Uint32 ch, Uint32 attr);
   122     void putch(int x, int y, Uint32 ch, Uint32 attr);
       
   123     void toggle_cursor(int x, int y);
   121     void commit();
   124     void commit();
   122 
   125 
   123     int get_width() { return _width; };
   126     // force full redraw on next commit()
   124     int get_height() { return _height; };
   127     void redraw();
   125     int get_cell_width() { return _cell_width; };
   128 
   126     int get_cell_height() { return _cell_height; };
   129     int get_width() const { return _width; };
       
   130     int get_height() const { return _height; };
       
   131     int get_cell_width() const { return _cell_width; };
       
   132     int get_cell_height() const { return _cell_height; };
   127 
   133 
   128 private:
   134 private:
   129     SDL_Surface *_screen_surface;
   135     SDL_Surface *_screen_surface;
   130     std::vector<TerminalCell> _cells_front;
   136     std::vector<TerminalCell> _cells_front;
   131     std::vector<TerminalCell> _cells_back;
   137     std::vector<TerminalCell> _cells_back;
   173         { _screen.select_font(fname_regular, fname_bold, ptsize); };
   179         { _screen.select_font(fname_regular, fname_bold, ptsize); };
   174     void resize(int pxwidth, int pxheight) { _screen.resize(pxwidth, pxheight); };
   180     void resize(int pxwidth, int pxheight) { _screen.resize(pxwidth, pxheight); };
   175 
   181 
   176     void erase() { _screen.erase(); };
   182     void erase() { _screen.erase(); };
   177     void putch(int x, int y, Uint32 ch) { _screen.putch(x, y, ch, _attr); };
   183     void putch(int x, int y, Uint32 ch) { _screen.putch(x, y, ch, _attr); };
   178     void commit() { _screen.commit(); };
   184     void commit();
   179 
   185 
   180     Uint32 prepare_attr(Uint8 fg, Uint8 bg, Uint8 style) { return (Uint32)fg | (Uint32)bg << 8 | (Uint32)style << 24; };
   186     Uint32 prepare_attr(Uint8 fg, Uint8 bg, Uint8 style) { return (Uint32)fg | (Uint32)bg << 8 | (Uint32)style << 24; };
   181     void set_attr(Uint32 value) { _attr = value; };
   187     void set_attr(Uint32 value) { _attr = value; };
   182 
   188 
   183     void set_cursor(int x, int y) { _cursor_x = x; _cursor_y = y; };
   189     void show_cursor(int x, int y) { _cursor_x = x; _cursor_y = y; _cursor_visible = true; };
   184     void show_cursor(bool visible) { _cursor_visible = visible; };
   190     void hide_cursor() { _cursor_visible = false; };
   185 
   191 
   186     void get_next_event(Event &event);
   192     void get_next_event(Event &event);
   187 
   193 
   188     int get_width() { return _screen.get_width(); };
   194     int get_width() const { return _screen.get_width(); };
   189     int get_height() { return _screen.get_height(); };
   195     int get_height() const { return _screen.get_height(); };
   190 
   196 
   191 private:
   197 private:
   192     TerminalScreen _screen;
   198     TerminalScreen _screen;
   193     Uint32 _attr;
   199     Uint32 _attr;
   194     int _cursor_x;
   200     int _cursor_x;