aboutsummaryrefslogtreecommitdiff
path: root/graphics/macgui
diff options
context:
space:
mode:
authorEugene Sandulenko2017-07-30 22:46:58 +0200
committerEugene Sandulenko2017-08-01 10:42:22 +0200
commita2427fddd72f6c18c1609e50393950c8f2cb20ba (patch)
tree01bffdf8590224b1c219b818046d4602c12a01da /graphics/macgui
parent62a2ac8c2bf2113e6cd96c232f6d68bcb6d42929 (diff)
downloadscummvm-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')
-rw-r--r--graphics/macgui/mactextwindow.cpp81
-rw-r--r--graphics/macgui/mactextwindow.h24
-rw-r--r--graphics/macgui/macwindow.h15
3 files changed, 114 insertions, 6 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
diff --git a/graphics/macgui/mactextwindow.h b/graphics/macgui/mactextwindow.h
index 802d02b717..0e48122e36 100644
--- a/graphics/macgui/mactextwindow.h
+++ b/graphics/macgui/mactextwindow.h
@@ -28,6 +28,10 @@
namespace Graphics {
+enum {
+ kCursorHeight = 12
+};
+
struct SelectedText {
int startX, startY;
int endX, endY;
@@ -49,6 +53,13 @@ public:
virtual bool processEvent(Common::Event &event);
+ /**
+ * Similar to that described in BaseMacWindow.
+ * @param g See BaseMacWindow.
+ * @param forceRedraw If true, the borders are guarranteed to redraw.
+ */
+ virtual bool draw(ManagedSurface *g, bool forceRedraw = false);
+
void setTextWindowFont(const MacFont *macFont);
const MacFont *getTextWindowFont();
@@ -59,9 +70,21 @@ public:
void setSelection(int selStartX, int selStartY, int selEndX, int selEndY);
+ void undrawCursor();
+
private:
void drawInput();
+public:
+ int _cursorX, _cursorY;
+ bool _cursorState;
+
+ bool _cursorDirty;
+ Common::Rect _cursorRect;
+ bool _cursorOff;
+
+ int _scrollPos;
+
private:
MacText *_mactext;
const MacFont *_font;
@@ -72,6 +95,7 @@ private:
int _maxWidth;
Common::String _inputText;
uint _inputTextHeight;
+
};
} // End of namespace Graphics
diff --git a/graphics/macgui/macwindow.h b/graphics/macgui/macwindow.h
index 3db9096b9c..77be0aee19 100644
--- a/graphics/macgui/macwindow.h
+++ b/graphics/macgui/macwindow.h
@@ -228,7 +228,7 @@ public:
* @param g See BaseMacWindow.
* @param forceRedraw If true, the borders are guarranteed to redraw.
*/
- bool draw(ManagedSurface *g, bool forceRedraw = false);
+ virtual bool draw(ManagedSurface *g, bool forceRedraw = false);
/**
* Mutator to change the active state of the window.
@@ -285,10 +285,7 @@ public:
*/
void setCloseable(bool closeable);
- WindowClick isInBorder(int x, int y);
-
private:
- void drawBorder();
void prepareBorderSurface(ManagedSurface *g);
void drawSimpleBorder(ManagedSurface *g);
void drawBorderFromSurface(ManagedSurface *g);
@@ -302,10 +299,17 @@ private:
bool isInResizeButton(int x, int y);
WindowClick isInScroll(int x, int y);
-private:
+protected:
+ void drawBorder();
+ WindowClick isInBorder(int x, int y);
+
+protected:
ManagedSurface _borderSurface;
ManagedSurface _composeSurface;
+ bool _borderIsDirty;
+
+private:
MacWindowBorder _macBorder;
int _pattern;
@@ -314,7 +318,6 @@ private:
bool _scrollable;
bool _resizable;
bool _active;
- bool _borderIsDirty;
bool _closeable;