--- a/sdlterm/src/sdlterm.cc Sat Jan 05 23:00:41 2013 +0100
+++ b/sdlterm/src/sdlterm.cc Sun Jan 06 13:55:02 2013 +0100
@@ -176,7 +176,7 @@
SDL_LockSurface(cell_surface);
int y = 1 + TTF_FontAscent(font);
Uint32 fgcolor_mapped = SDL_MapRGB(cell_surface->format, fgcolor.r, fgcolor.g, fgcolor.b);
- Uint32 *p = (Uint32 *)(cell_surface->pixels + y * cell_surface->pitch);
+ Uint32 *p = (Uint32 *)((Uint8 *)cell_surface->pixels + y * cell_surface->pitch);
for (int x = 0; x < _cell_width; x++)
*p++ = fgcolor_mapped;
SDL_UnlockSurface(cell_surface);
@@ -225,8 +225,6 @@
throw std::exception();
}
- SDL_WM_SetCaption("terminal", NULL);
-
_pixel_width = pxwidth;
_pixel_height = pxheight;
@@ -248,6 +246,13 @@
}
+void TerminalScreen::toggle_cursor(int x, int y)
+{
+ TerminalCell &cell = _cells_front[y * _width + x];
+ cell.attr ^= (Style::STANDOUT << 24);
+}
+
+
void TerminalScreen::commit()
{
auto front_iter = _cells_front.begin();
@@ -275,6 +280,13 @@
}
+void TerminalScreen::redraw()
+{
+ // clear back buffer, current screen is considered blank
+ std::fill(_cells_back.begin(), _cells_back.end(), TerminalCell());
+}
+
+
void TerminalScreen::_reset_cells()
{
_cell_width = _render.get_cell_width();
@@ -289,12 +301,13 @@
int num_cells = _width * _height;
_cells_front.resize(num_cells, TerminalCell());
- _cells_back.resize(num_cells, TerminalCell());
+ _cells_back.resize(num_cells);
+ redraw();
}
Terminal::Terminal()
- : _screen(), _attr(7), _mousemove_last_x(-1)
+ : _screen(), _attr(7), _cursor_visible(false), _mousemove_last_x(-1)
{
if (SDL_Init(SDL_INIT_VIDEO) == -1)
{
@@ -302,6 +315,7 @@
throw std::exception();
}
SDL_EnableUNICODE(1);
+ SDL_WM_SetCaption("terminal", NULL);
}
@@ -311,6 +325,20 @@
}
+void Terminal::commit()
+{
+ if (_cursor_visible)
+ {
+ _screen.toggle_cursor(_cursor_x, _cursor_y);
+ _screen.commit();
+ _screen.toggle_cursor(_cursor_x, _cursor_y);
+ }
+ else
+ {
+ _screen.commit();
+ }
+}
+
void Terminal::get_next_event(Event &event)
{
static SDL_Event sdl_event;
@@ -323,6 +351,15 @@
event.type = Event::QUIT;
return;
+ case SDL_VIDEORESIZE:
+ event.type = Event::RESIZE;
+ _screen.resize(sdl_event.resize.w, sdl_event.resize.h);
+ return;
+
+ case SDL_VIDEOEXPOSE:
+ _screen.redraw();
+ break;
+
case SDL_KEYDOWN:
{
//switch(event.key.keysym.sym)
@@ -354,6 +391,8 @@
return;
case SDL_MOUSEMOTION:
+ if (sdl_event.motion.state == 0)
+ break; // continue loop, do not report move events when no button is pressed
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();