[Scummvm-git-logs] scummvm master -> 877320d509305cd2dda98e0c532a46ef17f69031

sev- sev at scummvm.org
Thu Apr 30 22:50:56 UTC 2020


This automated email contains information about 10 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
bfdc650d95 GRAPHICS: MACGUI: Unset previous active widget when setting the new one
8b7abdb15d GRAPHICS: MACGUI: Fix crash in editable text selection
5aa4fbd20a GRAPHICS: MACGUI: Fix selection and cursor drawing in editable text
d6ab653e57 GRAPHICS: MACGUI: Initial code for cursor management in editable text
5a6ff99821 GRAPHICS: MACGUI: Simplified editable text code
e88a9016ea GRAPHICS: MACGUI: Added notion of paragraphs to MacText
cc58bbb05a DIRECTOR: The created window should receive keyboard events
5ff383d042 GRAPHICS: MACGUI: Pass keyboard event to active widget in editable window
cd1ef8e879 GRAPHICS: MACGUI: Implemented horizontal cursor navigation in editable text
877320d509 GRAPHICS: MACGUI: Implemented vertical cursor navigation in editable text


Commit: bfdc650d9531fd995f7cc58bb2faf520a218b065
    https://github.com/scummvm/scummvm/commit/bfdc650d9531fd995f7cc58bb2faf520a218b065
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-05-01T00:49:58+02:00

Commit Message:
GRAPHICS: MACGUI: Unset previous active widget when setting the new one

Changed paths:
    graphics/macgui/maceditabletext.cpp
    graphics/macgui/macwindowmanager.cpp
    graphics/macgui/macwindowmanager.h


diff --git a/graphics/macgui/maceditabletext.cpp b/graphics/macgui/maceditabletext.cpp
index ec3e3e5fe7..657d830a2f 100644
--- a/graphics/macgui/maceditabletext.cpp
+++ b/graphics/macgui/maceditabletext.cpp
@@ -96,7 +96,7 @@ void MacEditableText::init() {
 }
 
 MacEditableText::~MacEditableText() {
-	setActive(false);
+	_wm->setActiveWidget(nullptr);
 
 	delete _cursorRect;
 	delete _cursorSurface;
@@ -361,7 +361,7 @@ bool MacEditableText::processEvent(Common::Event &event) {
 		return false;
 
 	if (event.type == Common::EVENT_LBUTTONDOWN) {
-		setActive(true);
+		_wm->setActiveWidget(this);
 
 		startMarking(event.mouse.x, event.mouse.y);
 
diff --git a/graphics/macgui/macwindowmanager.cpp b/graphics/macgui/macwindowmanager.cpp
index 5820539c11..1e7a79f4f8 100644
--- a/graphics/macgui/macwindowmanager.cpp
+++ b/graphics/macgui/macwindowmanager.cpp
@@ -158,6 +158,8 @@ MacWindowManager::MacWindowManager(uint32 mode) {
 	_activeWindow = -1;
 	_needsRemoval = false;
 
+	_activeWidget = nullptr;
+
 	_mode = mode;
 
 	_menu = 0;
@@ -210,6 +212,15 @@ void MacWindowManager::setMode(uint32 mode) {
 		_fontMan->forceBuiltinFonts();
 }
 
+void MacWindowManager::setActiveWidget(MacWidget *widget) {
+	if (_activeWidget)
+		_activeWidget->setActive(false);
+
+	_activeWidget = widget;
+
+	if (_activeWidget)
+		_activeWidget->setActive(true);
+}
 
 MacWindow *MacWindowManager::addWindow(bool scrollable, bool resizable, bool editable) {
 	MacWindow *w = new MacWindow(_lastId, scrollable, resizable, editable, this);
diff --git a/graphics/macgui/macwindowmanager.h b/graphics/macgui/macwindowmanager.h
index 204007e109..83289f76d8 100644
--- a/graphics/macgui/macwindowmanager.h
+++ b/graphics/macgui/macwindowmanager.h
@@ -73,6 +73,7 @@ class ManagedSurface;
 
 class MacMenu;
 class MacTextWindow;
+class MacWidget;
 
 class MacFont;
 
@@ -160,11 +161,13 @@ public:
 	 * Set delay in milliseconds when menu appears (works only with autohide menu)
 	 */
 	void setMenuDelay(int delay) { _menuDelay = delay; }
+
 	/**
 	 * Set the desired window state to active.
 	 * @param id ID of the window that has to be set to active.
 	 */
 	void setActiveWindow(int id);
+
 	/**
 	 * Mark a window for removal.
 	 * Note that the window data will be destroyed.
@@ -208,6 +211,13 @@ public:
 	 */
 	MacPatterns &getPatterns() { return _patterns; }
 
+	/**
+	 * Sets an active widget, typically the one which steals the input
+	 * It also sends deactivation message to the previous one
+	 * @param widget Pointer to the widget to activate, nullptr for no widget
+	 */
+	void setActiveWidget(MacWidget *widget);
+
 	void pushArrowCursor();
 	void pushBeamCursor();
 	void pushCrossHairCursor();
@@ -273,6 +283,8 @@ private:
 	void (*_redrawEngineCallback)(void *engine);
 
 	bool _cursorIsArrow;
+
+	MacWidget *_activeWidget;
 };
 
 } // End of namespace Graphics


Commit: 8b7abdb15db0f9db4195d44ef3bf2b6b4fa9d57f
    https://github.com/scummvm/scummvm/commit/8b7abdb15db0f9db4195d44ef3bf2b6b4fa9d57f
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-05-01T00:49:58+02:00

Commit Message:
GRAPHICS: MACGUI: Fix crash in editable text selection

Changed paths:
    graphics/macgui/maceditabletext.cpp


diff --git a/graphics/macgui/maceditabletext.cpp b/graphics/macgui/maceditabletext.cpp
index 657d830a2f..3cd2846c2c 100644
--- a/graphics/macgui/maceditabletext.cpp
+++ b/graphics/macgui/maceditabletext.cpp
@@ -33,11 +33,6 @@
 namespace Graphics {
 
 enum {
-	kConWOverlap = 20,
-	kConHOverlap = 20,
-	kConWPadding = 3,
-	kConHPadding = 4,
-	kConOverscan = 3,
 	kConScrollStep = 12,
 
 	kCursorHeight = 12
@@ -243,7 +238,7 @@ void MacEditableText::drawSelection() {
 			numLines--;
 		}
 
-		byte *ptr = (byte *)_composeSurface->getBasePtr(x1 + kConWOverlap - 2, y + kConWOverlap - 2);
+		byte *ptr = (byte *)_composeSurface->getBasePtr(x1, y);
 
 		for (int x = x1; x < x2; x++, ptr++)
 			if (*ptr == _wm->_colorBlack)


Commit: 5aa4fbd20a70861ed4ab281aa2f8baae513ce407
    https://github.com/scummvm/scummvm/commit/5aa4fbd20a70861ed4ab281aa2f8baae513ce407
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-05-01T00:49:58+02:00

Commit Message:
GRAPHICS: MACGUI: Fix selection and cursor drawing in editable text

Changed paths:
    graphics/macgui/maceditabletext.cpp


diff --git a/graphics/macgui/maceditabletext.cpp b/graphics/macgui/maceditabletext.cpp
index 3cd2846c2c..470164472d 100644
--- a/graphics/macgui/maceditabletext.cpp
+++ b/graphics/macgui/maceditabletext.cpp
@@ -109,6 +109,11 @@ void MacEditableText::setActive(bool active) {
 	} else {
 		g_system->getTimerManager()->removeTimerProc(&cursorTimerHandler);
 	}
+
+	if (!_cursorOff && _cursorState == true) {
+		_cursorState = false;
+		_cursorDirty = true;
+	}
 }
 
 void MacEditableText::resize(int w, int h) {
@@ -361,10 +366,13 @@ bool MacEditableText::processEvent(Common::Event &event) {
 		startMarking(event.mouse.x, event.mouse.y);
 
 		return true;
-	} else if (event.type == Common::EVENT_LBUTTONUP && _menu) {
+	} else if (event.type == Common::EVENT_LBUTTONUP) {
 		if (_inTextSelection) {
 			_inTextSelection = false;
 
+			if (!_menu)
+				return true;
+
 			if (_selectedText.endY == -1 ||
 					(_selectedText.endX == _selectedText.startX && _selectedText.endY == _selectedText.startY)) {
 				_selectedText.startY = _selectedText.endY = -1;


Commit: d6ab653e57c0de2a195c697495dcbe8280d06705
    https://github.com/scummvm/scummvm/commit/d6ab653e57c0de2a195c697495dcbe8280d06705
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-05-01T00:49:58+02:00

Commit Message:
GRAPHICS: MACGUI: Initial code for cursor management in editable text

Changed paths:
    graphics/macgui/maceditabletext.cpp
    graphics/macgui/maceditabletext.h
    graphics/macgui/mactext.cpp
    graphics/macgui/mactext.h


diff --git a/graphics/macgui/maceditabletext.cpp b/graphics/macgui/maceditabletext.cpp
index 470164472d..0f1a8c5a31 100644
--- a/graphics/macgui/maceditabletext.cpp
+++ b/graphics/macgui/maceditabletext.cpp
@@ -77,6 +77,9 @@ void MacEditableText::init() {
 	_cursorState = false;
 	_cursorOff = false;
 
+	_cursorRow = getLineCount();
+	_cursorCol = getLineCharWidth(_cursorRow) + 1;
+
 	_cursorDirty = true;
 
 	_scrollbarIsDirty = false;
@@ -332,6 +335,8 @@ bool MacEditableText::processEvent(Common::Event &event) {
 			undrawInput();
 			return false; // Pass it to the higher level for processing
 
+		case Common::KEYCODE_LEFT:
+
 		default:
 			if (event.kbd.ascii == '~')
 				return false;
diff --git a/graphics/macgui/maceditabletext.h b/graphics/macgui/maceditabletext.h
index 29682c5b78..11c8d148ae 100644
--- a/graphics/macgui/maceditabletext.h
+++ b/graphics/macgui/maceditabletext.h
@@ -109,6 +109,7 @@ private:
 public:
 	int _cursorX, _cursorY;
 	bool _cursorState;
+	int _cursorRow, _cursorCol;
 
 	bool _cursorDirty;
 	Common::Rect *_cursorRect;
diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 3b517f7eb6..a452b5d4b2 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -181,12 +181,17 @@ void MacText::chopChunk(const Common::U32String &str) {
 	if (text.size() == 0) {
 		warning("chopChunk: too narrow width, >%d", _maxWidth);
 		chunk->text += str;
+		getLineCharWidth(curLine, true);
 
 		return;
 	}
 
 	chunk->text += text[0];
 
+	// Recalc dims
+	getLineWidth(curLine, true);
+	getLineCharWidth(curLine, true);
+
 	D(9, "** splitString, subchunk: \"%s\" (%d lines, maxW: %d)", toPrintable(text[0].encode()).c_str(), text.size(), _maxWidth);
 
 	// We do not overlap, so we're done
@@ -472,6 +477,28 @@ int MacText::getLineWidth(int line, bool enforce) {
 	return width;
 }
 
+int MacText::getLineCharWidth(int line, bool enforce) {
+	if ((uint)line >= _textLines.size())
+		return 0;
+
+	if (_textLines[line].charwidth != -1 && !enforce)
+		return _textLines[line].charwidth;
+
+	int width = 0;
+	bool hastext = false;
+
+	for (uint i = 0; i < _textLines[line].chunks.size(); i++) {
+		if (!_textLines[line].chunks[i].text.empty()) {
+			width += _textLines[line].chunks[i].text.size();
+			hastext = true;
+		}
+	}
+
+	_textLines[line].charwidth = width;
+
+	return width;
+}
+
 int MacText::getLineHeight(int line) {
 	if ((uint)line >= _textLines.size())
 		return 0;
@@ -499,6 +526,7 @@ void MacText::recalcDims() {
 		// We must calculate width first, because it enforces
 		// the computation. Calling Height() will return cached value!
 		_textMaxWidth = MAX(_textMaxWidth, getLineWidth(i, true));
+		getLineCharWidth(i, true);
 		y += getLineHeight(i) + _interLinear;
 	}
 
diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h
index 101334aaed..b9cc96e2e7 100644
--- a/graphics/macgui/mactext.h
+++ b/graphics/macgui/mactext.h
@@ -78,11 +78,12 @@ struct MacTextLine {
 	int width;
 	int height;
 	int y;
+	int charwidth;
 
 	Common::Array<MacFontRun> chunks;
 
 	MacTextLine() {
-		width = height = -1;
+		width = height = charwidth = -1;
 		y = 0;
 	}
 };
@@ -118,6 +119,7 @@ public:
 	void replaceLastLine(const Common::String &str);
 	void removeLastLine();
 	int getLineCount() { return _textLines.size(); }
+	int getLineCharWidth(int line, bool enforce = false);
 	int getTextHeight() { return _textMaxHeight; }
 	int getLineHeight(int line);
 


Commit: 5a6ff99821aa7745788f9cda5ac759f99e4c1132
    https://github.com/scummvm/scummvm/commit/5a6ff99821aa7745788f9cda5ac759f99e4c1132
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-05-01T00:49:58+02:00

Commit Message:
GRAPHICS: MACGUI: Simplified editable text code

Changed paths:
    graphics/macgui/maceditabletext.cpp
    graphics/macgui/maceditabletext.h
    graphics/macgui/mactext.cpp
    graphics/macgui/mactext.h


diff --git a/graphics/macgui/maceditabletext.cpp b/graphics/macgui/maceditabletext.cpp
index 0f1a8c5a31..fc3b1ccfff 100644
--- a/graphics/macgui/maceditabletext.cpp
+++ b/graphics/macgui/maceditabletext.cpp
@@ -48,6 +48,8 @@ MacEditableText::MacEditableText(MacWidget *parent, int x, int y, int w, int h,
 	init();
 
 	setDefaultFormatting(macFont->getId(), macFont->getSlant(), macFont->getSize(), 0, 0, 0);
+
+	MacText::render();
 }
 
 MacEditableText::MacEditableText(MacWidget *parent, int x, int y, int w, int h, MacWindowManager *wm, const Common::String &s, const MacFont *macFont, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment, int interlinear) :
@@ -58,18 +60,19 @@ MacEditableText::MacEditableText(MacWidget *parent, int x, int y, int w, int h,
 	init();
 
 	setDefaultFormatting(macFont->getId(), macFont->getSlant(), macFont->getSize(), 0, 0, 0);
+
+	MacText::render();
 }
 
 void MacEditableText::init() {
-	_inputTextHeight = 0;
-
-	_inputIsDirty = true;
 	_inTextSelection = false;
 
 	_scrollPos = 0;
 	_editable = true;
 	_selectable = true;
 
+	_editableRow = 0;
+
 	_menu = nullptr;
 
 	_cursorX = 0;
@@ -82,8 +85,6 @@ void MacEditableText::init() {
 
 	_cursorDirty = true;
 
-	_scrollbarIsDirty = false;
-
 	_cursorRect = new Common::Rect(0, 0, 1, kCursorHeight);
 
 	_cursorSurface = new ManagedSurface(1, kCursorHeight);
@@ -123,8 +124,6 @@ void MacEditableText::resize(int w, int h) {
 	if (_surface->w == w && _surface->h == h)
 		return;
 
-	undrawInput();
-
 	_maxWidth = w;
 	MacText::setMaxWidth(_maxWidth);
 }
@@ -137,6 +136,9 @@ void MacEditableText::appendText(const Common::U32String &str, const MacFont *ma
 	if (_editable) {
 		_scrollPos = MAX(0, MacText::getTextHeight() - getDimensions().height());
 
+		_cursorRow = getLineCount();
+		_cursorCol = getLineCharWidth(_cursorRow) + 1;
+
 		updateCursorPos();
 	}
 }
@@ -149,25 +151,18 @@ void MacEditableText::clearText() {
 	MacText::clearText();
 
 	_contentIsDirty = true;
-	_scrollbarIsDirty = true;
+
+	_cursorRow = _cursorCol = 0;
 
 	updateCursorPos();
 }
 
 bool MacEditableText::draw(bool forceRedraw) {
-	if (!_scrollbarIsDirty && !_contentIsDirty && !_cursorDirty && !_inputIsDirty && !forceRedraw)
+	if (!_contentIsDirty && !_cursorDirty && !forceRedraw)
 		return false;
 
-	if (_scrollbarIsDirty || forceRedraw) {
-		drawScrollbar();
-
+	if (forceRedraw)
 		_composeSurface->clear(_wm->_colorWhite);
-	}
-
-	if (_inputIsDirty || forceRedraw) {
-		drawInput();
-		_inputIsDirty = false;
-	}
 
 	_contentIsDirty = false;
 	_cursorDirty = false;
@@ -275,8 +270,8 @@ void MacEditableText::clearSelection() {
 }
 
 bool MacEditableText::isCutAllowed() {
-	if (_selectedText.startRow >= (int)(MacText::getLineCount() - _inputTextHeight) &&
-			_selectedText.endRow  >= (int)(MacText::getLineCount() - _inputTextHeight))
+	if (_selectedText.startRow >= _editableRow &&
+			_selectedText.endRow  >= _editableRow)
 		return true;
 
 	return false;
@@ -295,19 +290,9 @@ Common::U32String MacEditableText::cutSelection() {
 
 	Common::U32String selection = MacText::getTextChunk(s.startRow, s.startCol, s.endRow, s.endCol, false, false);
 
-	uint32 selPos = _inputText.find(selection);
-
-	if (selPos == Common::U32String::npos) {
-		//warning("Cannot find substring '%s' in '%s'", selection.c_str(), _inputText.c_str()); // Needed encode method
-
-		return Common::U32String("");
-	}
-
-	Common::U32String newInput = Common::U32String(_inputText.c_str(), selPos) + Common::U32String(_inputText.c_str() + selPos + selection.size());
+	// TODO: Remove the actual text
 
 	clearSelection();
-	clearInput();
-	appendInput(newInput);
 
 	return selection;
 }
@@ -325,25 +310,24 @@ bool MacEditableText::processEvent(Common::Event &event) {
 
 		switch (event.kbd.keycode) {
 		case Common::KEYCODE_BACKSPACE:
-			if (!_inputText.empty()) {
-				_inputText.deleteLastChar();
-				_inputIsDirty = true;
+			if (_cursorRow > 0 || _cursorCol > 0) {
+				deletePreviousChar();
+				_contentIsDirty = true;
 			}
 			return true;
 
 		case Common::KEYCODE_RETURN:
-			undrawInput();
-			return false; // Pass it to the higher level for processing
-
-		case Common::KEYCODE_LEFT:
+			addNewLine();
+			_contentIsDirty = true;
+			return true;
 
 		default:
 			if (event.kbd.ascii == '~')
 				return false;
 
 			if (event.kbd.ascii >= 0x20 && event.kbd.ascii <= 0x7f) {
-				_inputText += (char)event.kbd.ascii;
-				_inputIsDirty = true;
+				insertChar((byte)event.kbd.ascii);
+				_contentIsDirty = true;
 
 				return true;
 			}
@@ -417,7 +401,6 @@ void MacEditableText::scroll(int delta) {
 	undrawCursor();
 	_cursorY -= (_scrollPos - oldScrollPos);
 	_contentIsDirty = true;
-	_scrollbarIsDirty = true;
 }
 
 void MacEditableText::startMarking(int x, int y) {
@@ -448,53 +431,15 @@ void MacEditableText::updateTextSelection(int x, int y) {
 	_contentIsDirty = true;
 }
 
-void MacEditableText::undrawInput() {
-	for (uint i = 0; i < _inputTextHeight; i++)
-		MacText::removeLastLine();
-
-	_inputTextHeight = 0;
-}
-
-void MacEditableText::drawInput() {
-	undrawInput();
-
-	Common::Array<Common::U32String> text;
-
-	const Font *fontRef = getDefaultFormatting().font;
-
-	if (fontRef == nullptr) {
-		error("MacEditableText::drawInput(): default font is not set");
-	}
-
-	// Now recalc new text height
-	fontRef->wordWrapText(_inputText, _maxWidth, text);
-	_inputTextHeight = MAX((uint)1, text.size()); // We always have line to clean
-
-	// And add new input line to the text
-	appendTextDefault(_inputText, true);
-
-	_cursorX = _inputText.empty() ? 0 : fontRef->getStringWidth(text[_inputTextHeight - 1]);
-
-	updateCursorPos();
-
-	_contentIsDirty = true;
-}
-
-void MacEditableText::clearInput() {
-	undrawCursor();
-
-	_cursorX = 0;
-	_inputText.clear();
+//////////////////
+// Text editing
+void MacEditableText::deletePreviousChar() {
 }
 
-void MacEditableText::appendInput(const Common::U32String &str) {
-	_inputText += str;
-
-	drawInput();
+void MacEditableText::addNewLine() {
 }
 
-void MacEditableText::appendInput(const Common::String &str) {
-	appendInput(Common::U32String(str));
+void MacEditableText::insertChar(byte c) {
 }
 
 //////////////////
@@ -519,10 +464,4 @@ void MacEditableText::undrawCursor() {
 	_cursorDirty = true;
 }
 
-void MacEditableText::setScroll(float scrollPos, float scrollSize) {
-}
-
-void MacEditableText::drawScrollbar() {
-}
-
 } // End of namespace Graphics
diff --git a/graphics/macgui/maceditabletext.h b/graphics/macgui/maceditabletext.h
index 11c8d148ae..b68146b29d 100644
--- a/graphics/macgui/maceditabletext.h
+++ b/graphics/macgui/maceditabletext.h
@@ -79,11 +79,6 @@ public:
 
 	void undrawCursor();
 
-	const Common::U32String &getInput() { return _inputText; }
-	void clearInput();
-	void appendInput(const Common::U32String &str);
-	void appendInput(const Common::String &str);
-
 	Common::U32String getSelection(bool formatted = false, bool newlines = true);
 	void clearSelection();
 	Common::U32String cutSelection();
@@ -95,16 +90,15 @@ private:
 
 	void scroll(int delta);
 
-	void undrawInput();
-	void drawInput();
 	void drawSelection();
 	void updateCursorPos();
 
 	void startMarking(int x, int y);
 	void updateTextSelection(int x, int y);
 
-	void drawScrollbar();
-	void setScroll(float scrollPos, float scrollSize);
+	void deletePreviousChar();
+	void addNewLine();
+	void insertChar(byte c);
 
 public:
 	int _cursorX, _cursorY;
@@ -122,15 +116,12 @@ public:
 private:
 	ManagedSurface *_cursorSurface;
 
+	int _editableRow;
+
 	bool _inTextSelection;
 	SelectedText _selectedText;
 
 	int _maxWidth;
-	Common::U32String _inputText;
-	uint _inputTextHeight;
-	bool _inputIsDirty;
-
-	bool _scrollbarIsDirty;
 
 	MacMenu *_menu;
 };
diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index a452b5d4b2..286aa1f31b 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -444,11 +444,11 @@ void MacText::render(int from, int to) {
 	}
 }
 
-int MacText::getLineWidth(int line, bool enforce) {
+int MacText::getLineWidth(int line, bool enforce, int col) {
 	if ((uint)line >= _textLines.size())
 		return 0;
 
-	if (_textLines[line].width != -1 && !enforce)
+	if (_textLines[line].width != -1 && !enforce && col == -1)
 		return _textLines[line].width;
 
 	int width = 0;
@@ -460,6 +460,18 @@ int MacText::getLineWidth(int line, bool enforce) {
 		if (enforce)
 			_textLines[line].chunks[i].font = nullptr;
 
+		if (col >= 0) {
+			if (col >= _textLines[line].chunks[i].text.size()) {
+				col -= _textLines[line].chunks[i].text.size();
+			} else {
+				Common::U32String tmp(_textLines[line].chunks[i].text.c_str(), col);
+
+				width += _textLines[line].chunks[i].getFont()->getStringWidth(tmp);
+
+				return width;
+			}
+		}
+
 		if (!_textLines[line].chunks[i].text.empty()) {
 			width += _textLines[line].chunks[i].getFont()->getStringWidth(_textLines[line].chunks[i].text);
 			hastext = true;
diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h
index b9cc96e2e7..57d7a5265d 100644
--- a/graphics/macgui/mactext.h
+++ b/graphics/macgui/mactext.h
@@ -136,7 +136,17 @@ private:
 	void render(int from, int to);
 	void recalcDims();
 	void reallocSurface();
-	int getLineWidth(int line, bool enforce = false);
+	/**
+	 * Returns line width in pixels. This takes into account chunks.
+	 * The result is cached for faster subsequent calls.
+	 *
+	 * @param line Line number
+	 * @param enforce Flag for indicating skipping the cache and computing the width,
+	 *                must be called when text gets changed
+	 * @param col Compute line width up to specified column, including this column
+	 * @return line width in pixels, or 0 for non-existent lines
+	 */
+	int getLineWidth(int line, bool enforce = false, int col = -1);
 
 protected:
 	MacWindowManager *_wm;


Commit: e88a9016ea54085e190cea748e75505ae0d7e968
    https://github.com/scummvm/scummvm/commit/e88a9016ea54085e190cea748e75505ae0d7e968
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-05-01T00:49:58+02:00

Commit Message:
GRAPHICS: MACGUI: Added notion of paragraphs to MacText

Changed paths:
    graphics/macgui/mactext.cpp
    graphics/macgui/mactext.h


diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 286aa1f31b..6fd6dfd7f8 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -165,7 +165,7 @@ void MacText::chopChunk(const Common::U32String &str) {
 	// This happens when the previous run is finished only with
 	// empty formatting, or when we were adding text for the first time
 	if (chunk->text.empty() && str.empty()) {
-		D(9, "** splitString, replaced formatting, line %d", curLine);
+		D(9, "** chopChunk, replaced formatting, line %d", curLine);
 
 		_textLines[curLine].chunks.pop_back();
 
@@ -192,7 +192,7 @@ void MacText::chopChunk(const Common::U32String &str) {
 	getLineWidth(curLine, true);
 	getLineCharWidth(curLine, true);
 
-	D(9, "** splitString, subchunk: \"%s\" (%d lines, maxW: %d)", toPrintable(text[0].encode()).c_str(), text.size(), _maxWidth);
+	D(9, "** chopChunk, subchunk: \"%s\" (%d lines, maxW: %d)", toPrintable(text[0].encode()).c_str(), text.size(), _maxWidth);
 
 	// We do not overlap, so we're done
 	if (text.size() == 1)
@@ -208,7 +208,7 @@ void MacText::chopChunk(const Common::U32String &str) {
 		_textLines.resize(curLine + 1);
 		_textLines[curLine].chunks.push_back(newchunk);
 
-		D(9, "** splitString, added line: \"%s\"", toPrintable(text[i].encode()).c_str());
+		D(9, "** chopChunk, added line: \"%s\"", toPrintable(text[i].encode()).c_str());
 	}
 }
 
@@ -222,7 +222,7 @@ void MacText::splitString(const Common::U32String &str) {
 		return;
 	}
 
-	Common::U32String line, tmp;
+	Common::U32String paragraph, tmp;
 
 	if (_textLines.empty()) {
 		_textLines.resize(1);
@@ -237,9 +237,9 @@ void MacText::splitString(const Common::U32String &str) {
 	MacFontRun chunk = _textLines[curLine].chunks[curChunk];
 
 	while (*l) {
-		line.clear();
+		paragraph.clear();
 
-		// First, get the whole line
+		// First, get the whole paragraph
 		while (*l) {
 			if (*l == '\r') {
 				l++;
@@ -250,13 +250,13 @@ void MacText::splitString(const Common::U32String &str) {
 				break;
 			}
 
-			line += *l++;
+			paragraph += *l++;
 		}
 
-		D(9, "** splitString, line: \"%s\"", Common::toPrintable(line.encode()).c_str());
+		D(9, "** splitString, paragraph: \"%s\"", Common::toPrintable(line.encode()).c_str());
 
-		// Now process whole line
-		const Common::U32String::value_type *s = line.c_str();
+		// Now process whole paragraph
+		const Common::U32String::value_type *s = paragraph.c_str();
 
 		tmp.clear();
 
@@ -338,6 +338,8 @@ void MacText::splitString(const Common::U32String &str) {
 		// Add new line
 		D(9, "** splitString: new line");
 
+		_textLines[curLine].paragraphEnd = true;
+
 		curLine++;
 		_textLines.resize(curLine + 1);
 		_textLines[curLine].chunks.push_back(chunk);
diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h
index 57d7a5265d..02e272d7ff 100644
--- a/graphics/macgui/mactext.h
+++ b/graphics/macgui/mactext.h
@@ -79,12 +79,14 @@ struct MacTextLine {
 	int height;
 	int y;
 	int charwidth;
+	bool paragraphEnd;
 
 	Common::Array<MacFontRun> chunks;
 
 	MacTextLine() {
 		width = height = charwidth = -1;
 		y = 0;
+		paragraphEnd = false;
 	}
 };
 


Commit: cc58bbb05a030111475b2d7d9bb8390fd3fcc4fd
    https://github.com/scummvm/scummvm/commit/cc58bbb05a030111475b2d7d9bb8390fd3fcc4fd
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-05-01T00:49:58+02:00

Commit Message:
DIRECTOR: The created window should receive keyboard events

Changed paths:
    engines/director/score.cpp


diff --git a/engines/director/score.cpp b/engines/director/score.cpp
index 50c8d9ccd7..c18c9f1124 100644
--- a/engines/director/score.cpp
+++ b/engines/director/score.cpp
@@ -1519,7 +1519,7 @@ void Score::startLoop() {
 
 	initGraphics(_movieRect.width(), _movieRect.height());
 
-	_window = _vm->_wm->addWindow(false, false, false);
+	_window = _vm->_wm->addWindow(false, false, true);
 	_window->disableBorder();
 	_window->resize(_movieRect.width(), _movieRect.height());
 


Commit: 5ff383d042cdb38b6965d41012dbb4699b3aa801
    https://github.com/scummvm/scummvm/commit/5ff383d042cdb38b6965d41012dbb4699b3aa801
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-05-01T00:49:58+02:00

Commit Message:
GRAPHICS: MACGUI: Pass keyboard event to active widget in editable window

Changed paths:
    graphics/macgui/macwindow.cpp
    graphics/macgui/macwindowmanager.h


diff --git a/graphics/macgui/macwindow.cpp b/graphics/macgui/macwindow.cpp
index e5ba409a37..823159b2e9 100644
--- a/graphics/macgui/macwindow.cpp
+++ b/graphics/macgui/macwindow.cpp
@@ -545,6 +545,16 @@ bool MacWindow::processEvent(Common::Event &event) {
 
 		setHighlight(kBorderNone);
 		break;
+
+	case Common::EVENT_KEYDOWN:
+		if (!_editable)
+			return false;
+
+		if (_wm->getActiveWidget())
+			return _wm->getActiveWidget()->processEvent(event);
+
+		return false;
+
 	default:
 		return false;
 	}
diff --git a/graphics/macgui/macwindowmanager.h b/graphics/macgui/macwindowmanager.h
index 83289f76d8..8c4749aa2a 100644
--- a/graphics/macgui/macwindowmanager.h
+++ b/graphics/macgui/macwindowmanager.h
@@ -218,6 +218,8 @@ public:
 	 */
 	void setActiveWidget(MacWidget *widget);
 
+	MacWidget *getActiveWidget() { return _activeWidget; }
+
 	void pushArrowCursor();
 	void pushBeamCursor();
 	void pushCrossHairCursor();


Commit: cd1ef8e879b1413f44ef13bafad5898cb90d25d4
    https://github.com/scummvm/scummvm/commit/cd1ef8e879b1413f44ef13bafad5898cb90d25d4
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-05-01T00:49:58+02:00

Commit Message:
GRAPHICS: MACGUI: Implemented horizontal cursor navigation in editable text

Changed paths:
    graphics/macgui/maceditabletext.cpp


diff --git a/graphics/macgui/maceditabletext.cpp b/graphics/macgui/maceditabletext.cpp
index fc3b1ccfff..fb4604277c 100644
--- a/graphics/macgui/maceditabletext.cpp
+++ b/graphics/macgui/maceditabletext.cpp
@@ -80,10 +80,10 @@ void MacEditableText::init() {
 	_cursorState = false;
 	_cursorOff = false;
 
-	_cursorRow = getLineCount();
+	_cursorRow = getLineCount() - 1;
 	_cursorCol = getLineCharWidth(_cursorRow) + 1;
 
-	_cursorDirty = true;
+	updateCursorPos();
 
 	_cursorRect = new Common::Rect(0, 0, 1, kCursorHeight);
 
@@ -161,8 +161,7 @@ bool MacEditableText::draw(bool forceRedraw) {
 	if (!_contentIsDirty && !_cursorDirty && !forceRedraw)
 		return false;
 
-	if (forceRedraw)
-		_composeSurface->clear(_wm->_colorWhite);
+	_composeSurface->clear(_wm->_colorWhite);
 
 	_contentIsDirty = false;
 	_cursorDirty = false;
@@ -321,6 +320,34 @@ bool MacEditableText::processEvent(Common::Event &event) {
 			_contentIsDirty = true;
 			return true;
 
+		case Common::KEYCODE_LEFT:
+			if (_cursorCol == 0) {
+				if (_cursorRow == 0) { // Nowhere to go
+					return true;
+				}
+				_cursorRow--;
+				_cursorCol = getLineCharWidth(_cursorRow) + 1;
+			} else {
+				_cursorCol--;
+			}
+			updateCursorPos();
+
+			return true;
+
+		case Common::KEYCODE_RIGHT:
+			if (_cursorCol == getLineCharWidth(_cursorRow) + 1) {
+				if (_cursorRow == getLineCount()) { // Nowhere to go
+					return true;
+				}
+				_cursorRow++;
+				_cursorCol = 0;
+			} else {
+				_cursorCol++;
+			}
+			updateCursorPos();
+
+			return true;
+
 		default:
 			if (event.kbd.ascii == '~')
 				return false;
@@ -454,7 +481,8 @@ static void cursorTimerHandler(void *refCon) {
 }
 
 void MacEditableText::updateCursorPos() {
-	_cursorY = MacText::getTextHeight() - _scrollPos - kCursorHeight;
+	_cursorY = _textLines[_cursorRow].y;
+	_cursorX = getLineWidth(_cursorRow, false, _cursorCol);
 
 	_cursorDirty = true;
 }


Commit: 877320d509305cd2dda98e0c532a46ef17f69031
    https://github.com/scummvm/scummvm/commit/877320d509305cd2dda98e0c532a46ef17f69031
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-05-01T00:49:58+02:00

Commit Message:
GRAPHICS: MACGUI: Implemented vertical cursor navigation in editable text

Changed paths:
    graphics/macgui/maceditabletext.cpp


diff --git a/graphics/macgui/maceditabletext.cpp b/graphics/macgui/maceditabletext.cpp
index fb4604277c..b9dc247550 100644
--- a/graphics/macgui/maceditabletext.cpp
+++ b/graphics/macgui/maceditabletext.cpp
@@ -81,7 +81,7 @@ void MacEditableText::init() {
 	_cursorOff = false;
 
 	_cursorRow = getLineCount() - 1;
-	_cursorCol = getLineCharWidth(_cursorRow) + 1;
+	_cursorCol = getLineCharWidth(_cursorRow);
 
 	updateCursorPos();
 
@@ -137,7 +137,7 @@ void MacEditableText::appendText(const Common::U32String &str, const MacFont *ma
 		_scrollPos = MAX(0, MacText::getTextHeight() - getDimensions().height());
 
 		_cursorRow = getLineCount();
-		_cursorCol = getLineCharWidth(_cursorRow) + 1;
+		_cursorCol = getLineCharWidth(_cursorRow);
 
 		updateCursorPos();
 	}
@@ -326,7 +326,7 @@ bool MacEditableText::processEvent(Common::Event &event) {
 					return true;
 				}
 				_cursorRow--;
-				_cursorCol = getLineCharWidth(_cursorRow) + 1;
+				_cursorCol = getLineCharWidth(_cursorRow);
 			} else {
 				_cursorCol--;
 			}
@@ -335,8 +335,8 @@ bool MacEditableText::processEvent(Common::Event &event) {
 			return true;
 
 		case Common::KEYCODE_RIGHT:
-			if (_cursorCol == getLineCharWidth(_cursorRow) + 1) {
-				if (_cursorRow == getLineCount()) { // Nowhere to go
+			if (_cursorCol == getLineCharWidth(_cursorRow)) {
+				if (_cursorRow == getLineCount() - 1) { // Nowhere to go
 					return true;
 				}
 				_cursorRow++;
@@ -348,6 +348,24 @@ bool MacEditableText::processEvent(Common::Event &event) {
 
 			return true;
 
+		case Common::KEYCODE_UP:
+			if (_cursorRow == 0)
+				return true;
+
+			_cursorRow--;
+			updateCursorPos();
+
+			return true;
+
+		case Common::KEYCODE_DOWN:
+			if (_cursorRow == getLineCount() - 1)
+				return true;
+
+			_cursorRow++;
+			updateCursorPos();
+
+			return true;
+
 		default:
 			if (event.kbd.ascii == '~')
 				return false;




More information about the Scummvm-git-logs mailing list