--- a/sdlterm/src/sdlterm.h Sat Jan 05 00:40:27 2013 +0100
+++ b/sdlterm/src/sdlterm.h Sat Jan 05 12:40:32 2013 +0100
@@ -5,6 +5,18 @@
#include <vector>
+class GlyphCache
+{
+public:
+ SDL_Surface *lookup_glyph(Uint16 ch);
+ void put_glyph(Uint16 ch, SDL_Surface *srf);
+ void flush();
+
+private:
+ std::map<Uint16, SDL_Surface*> _glyph_map;
+};
+
+
class GlyphRenderer
{
public:
@@ -14,6 +26,7 @@
void open_font(const char *fname_regular, const char *fname_bold, int ptsize);
void close_font();
+ // do not free surface returned!
SDL_Surface *render_glyph(Uint16 ch);
int get_cell_width() { return _cell_width; };
@@ -24,7 +37,7 @@
TTF_Font *_font_bold;
int _cell_width;
int _cell_height;
- std::map<Uint16, SDL_Surface*> _cache;
+ GlyphCache _cache;
};
@@ -48,6 +61,11 @@
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; };
+
private:
SDL_Surface *_screen_surface;
TerminalCell *_cells;
@@ -64,42 +82,24 @@
};
-enum class EventType : Uint8
+struct Event
{
- quit,
- resize,
- keypress,
- mousedown,
- mouseup,
- mousemove,
- mousewheel
-};
-
-
-struct WindowEvent
-{
- EventType type;
-};
-
+ enum { QUIT, RESIZE, KEYPRESS, MOUSEDOWN, MOUSEUP, MOUSEMOVE, MOUSEWHEEL };
+ int type;
-struct KeyboardEvent
-{
- EventType type;
-};
-
-
-struct MouseEvent
-{
- EventType type;
-};
-
-
-union Event
-{
- EventType type;
- WindowEvent window;
- KeyboardEvent key;
- MouseEvent mouse;
+ union
+ {
+ struct
+ {
+ char keyname[10];
+ Uint16 unicode;
+ } key;
+ struct
+ {
+ int x, y;
+ int button;
+ } mouse;
+ };
};
@@ -125,11 +125,16 @@
void get_next_event(Event &event);
+ 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;
+
+ const char *_translate_keyname(SDLKey sym);
};