diff options
author | Eugene Sandulenko | 2017-07-30 22:46:58 +0200 |
---|---|---|
committer | Eugene Sandulenko | 2017-08-01 10:42:22 +0200 |
commit | a2427fddd72f6c18c1609e50393950c8f2cb20ba (patch) | |
tree | 01bffdf8590224b1c219b818046d4602c12a01da /graphics/macgui/mactextwindow.cpp | |
parent | 62a2ac8c2bf2113e6cd96c232f6d68bcb6d42929 (diff) | |
download | scummvm-rg350-a2427fddd72f6c18c1609e50393950c8f2cb20ba.tar.gz scummvm-rg350-a2427fddd72f6c18c1609e50393950c8f2cb20ba.tar.bz2 scummvm-rg350-a2427fddd72f6c18c1609e50393950c8f2cb20ba.zip |
GRAPHICS: MACGUI: Initial code for cursor drawing in MacTextWindow
Diffstat (limited to 'graphics/macgui/mactextwindow.cpp')
-rw-r--r-- | graphics/macgui/mactextwindow.cpp | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/graphics/macgui/mactextwindow.cpp b/graphics/macgui/mactextwindow.cpp index 9373751734..c4395cdf19 100644 --- a/graphics/macgui/mactextwindow.cpp +++ b/graphics/macgui/mactextwindow.cpp @@ -20,6 +20,8 @@ * */ +#include "common/timer.h" +#include "common/system.h" #include "graphics/macgui/macwindowmanager.h" #include "graphics/macgui/macfontmanager.h" @@ -27,6 +29,8 @@ namespace Graphics { +static void cursorTimerHandler(void *refCon); + MacTextWindow::MacTextWindow(MacWindowManager *wm, const MacFont *font, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment) : MacWindow(wm->getLastId(), true, true, true, wm) { @@ -37,6 +41,15 @@ MacTextWindow::MacTextWindow(MacWindowManager *wm, const MacFont *font, int fgco _inputTextHeight = 0; _maxWidth = maxWidth; + + _scrollPos = 0; + + _cursorX = 0; + _cursorY = 0; + _cursorState = false; + _cursorOff = false; + + g_system->getTimerManager()->installTimerProc(&cursorTimerHandler, 200000, this, "textWindowCursor"); } void MacTextWindow::drawText(ManagedSurface *g, int x, int y, int w, int h, int xoff, int yoff) { @@ -63,6 +76,7 @@ void MacTextWindow::setSelection(int selStartX, int selStartY, int selEndX, int } MacTextWindow::~MacTextWindow() { + g_system->getTimerManager()->removeTimerProc(&cursorTimerHandler); } void MacTextWindow::setTextWindowFont(const MacFont *font) { @@ -75,6 +89,24 @@ const MacFont *MacTextWindow::getTextWindowFont() { return _font; } +bool MacTextWindow::draw(ManagedSurface *g, bool forceRedraw) { + if (!_borderIsDirty && !_contentIsDirty && !_cursorDirty && !forceRedraw) + return false; + + if (_borderIsDirty || forceRedraw) + drawBorder(); + + _contentIsDirty = false; + + // Compose + _composeSurface.blitFrom(_surface, Common::Rect(0, 0, _surface.w - 2, _surface.h - 2), Common::Point(2, 2)); + _composeSurface.transBlitFrom(_borderSurface, kColorGreen); + + g->transBlitFrom(_composeSurface, _composeSurface.getBounds(), Common::Point(_dims.left - 2, _dims.top - 2), kColorGreen2); + + return true; +} + bool MacTextWindow::processEvent(Common::Event &event) { WindowClick click = isInBorder(event.mouse.x, event.mouse.y); @@ -119,6 +151,55 @@ void MacTextWindow::drawInput() { // And add new input line to the text appendText(_inputText, _font); + + _cursorX = _fontRef->getStringWidth(text[_inputTextHeight - 1]); + + if (_scrollPos) + _cursorY = _mactext->getTextHeight() - kCursorHeight * 2; + else + _cursorY = _mactext->getTextHeight() - kCursorHeight; + } +////////////////// +// Cursor stuff +static void cursorTimerHandler(void *refCon) { + MacTextWindow *w = (MacTextWindow *)refCon; + + int x = w->_cursorX; + int y = w->_cursorY; + + if (x == 0 && y == 0) + return; + + x += w->getInnerDimensions().left; + y += w->getInnerDimensions().top; + int h = kCursorHeight; + + if (y + h > w->getInnerDimensions().bottom) { + h = w->getInnerDimensions().bottom - y; + } + + if (h > 0) + w->getSurface()->vLine(x, y, y + h, w->_cursorState ? kColorBlack : kColorWhite); + + if (!w->_cursorOff) + w->_cursorState = !w->_cursorState; + + w->_cursorRect.left = x; + w->_cursorRect.right = MIN<uint16>(x + 1, w->getInnerDimensions().right); + w->_cursorRect.top = MIN<uint16>(y - 1, w->getInnerDimensions().top); + w->_cursorRect.bottom = MIN<uint16>(y + h, w->getInnerDimensions().bottom); + + w->_cursorDirty = true; +} + +void MacTextWindow::undrawCursor() { + _cursorOff = true; + _cursorState = false; + cursorTimerHandler(this); + _cursorOff = false; +} + + } // End of namespace Graphics |