[Scummvm-git-logs] scummvm master -> 217884d8738da705db7d23e7280086dbb6ae412e

sev- sev at scummvm.org
Sat May 2 22:45:35 UTC 2020


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

Summary:
e7045ee28b GRAPHICS: MACGUI: Implemented addNewLine() in editable text
d57b724999 GRAPHICS: MACGUI: Code cleanup
b8d2cdff02 GRAPHICS: MACGUI: Fix deleting characters at edge of chunks
2b1297c2f9 GRAPHICS: MACGUI: Fix text insertion
302cfb5459 GRAPHICS: MACGUI: Fixed edge cases for cursor navigation
8615f27a87 GRAPHICS: MACGUI: Implemented reshuffleParagraph() in editable text
217884d873 GRAPHICS: MACGUI: Collapse text formatting in getTextChunk()


Commit: e7045ee28b7c741f9d7d4b3bb0ee8efc0c7fcf1a
    https://github.com/scummvm/scummvm/commit/e7045ee28b7c741f9d7d4b3bb0ee8efc0c7fcf1a
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-05-02T21:53:56+02:00

Commit Message:
GRAPHICS: MACGUI: Implemented addNewLine() in editable text

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


diff --git a/graphics/macgui/maceditabletext.cpp b/graphics/macgui/maceditabletext.cpp
index 5e21f89caf..24b4b6e4bd 100644
--- a/graphics/macgui/maceditabletext.cpp
+++ b/graphics/macgui/maceditabletext.cpp
@@ -324,6 +324,7 @@ bool MacEditableText::processEvent(Common::Event &event) {
 
 		case Common::KEYCODE_RETURN:
 			addNewLine(&_cursorRow, &_cursorCol);
+			updateCursorPos();
 			_contentIsDirty = true;
 			return true;
 
diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 0ec5de4521..f9ba863d9c 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -929,6 +929,30 @@ void MacText::deletePreviousChar(int *row, int *col) {
 }
 
 void MacText::addNewLine(int *row, int *col) {
+	MacTextLine *line = &_textLines[*row];
+	int pos = *col;
+	uint ch = line->getChunkNum(&pos);
+	MacFontRun newchunk = line->chunks[ch];
+	MacTextLine newline;
+
+	newchunk.text = &line->chunks[ch].text.c_str()[pos];
+	line->chunks[ch].text = Common::U32String(line->chunks[ch].text.c_str(), pos);
+	newline.chunks.push_back(newchunk);
+
+	for (uint i = ch + 1; i < line->chunks.size(); i++) {
+		newline.chunks.push_back(MacFontRun(line->chunks[i]));
+		line->chunks[i].text.clear();
+	}
+	line->width = -1; // Drop cache
+
+	_textLines.insert_at(*row + 1, newline);
+
+	(*row)++;
+	*col = 0;
+
+	_fullRefresh = true;
+	recalcDims();
+	render();
 }
 
 void MacText::reshuffleParagraph(int *row, int *col) {


Commit: d57b724999a114c778b0fa3098ee1915ab4b9efa
    https://github.com/scummvm/scummvm/commit/d57b724999a114c778b0fa3098ee1915ab4b9efa
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-05-02T21:58:27+02:00

Commit Message:
GRAPHICS: MACGUI: Code cleanup

Changed paths:
    graphics/macgui/mactext.cpp


diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index f9ba863d9c..6ac2a128e7 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -857,28 +857,28 @@ Common::U32String MacText::getTextChunk(int startRow, int startCol, int endRow,
 void MacText::insertChar(byte c, int *row, int *col) {
 	MacTextLine *line = &_textLines[*row];
 	int pos = *col;
-	uint i = line->getChunkNum(&pos);
+	uint ch = line->getChunkNum(&pos);
 
-	for (i = 0; i < line->chunks.size(); i++) {
-		if (pos >= line->chunks[i].text.size()) {
-			pos -= line->chunks[i].text.size();
+	for (ch = 0; ch < line->chunks.size(); ch++) {
+		if (pos >= line->chunks[ch].text.size()) {
+			pos -= line->chunks[ch].text.size();
 		} else {
 			break;
 		}
 	}
 
-	if (i == line->chunks.size()) {
-		i--;	// touch the last chunk
-		pos = line->chunks[i].text.size();
+	if (ch == line->chunks.size()) {
+		ch--;	// touch the last chunk
+		pos = line->chunks[ch].text.size();
 	}
 
 	// We're in the needed chunk
-	Common::U32String newchunk(line->chunks[i].text);
+	Common::U32String newchunk(line->chunks[ch].text);
 	newchunk.insertChar(c, pos);
-	int chunkw = line->chunks[i].getFont()->getStringWidth(newchunk);
-	int oldw = line->chunks[i].getFont()->getStringWidth(line->chunks[i].text);
+	int chunkw = line->chunks[ch].getFont()->getStringWidth(newchunk);
+	int oldw = line->chunks[ch].getFont()->getStringWidth(line->chunks[ch].text);
 
-	line->chunks[i].text = newchunk;
+	line->chunks[ch].text = newchunk;
 	line->width = -1;	// Force recalc
 
 	(*col)++;
@@ -914,9 +914,9 @@ void MacText::deletePreviousChar(int *row, int *col) {
 		reshuffleParagraph(row, col);
 	} else {
 		int pos = *col - 1;
-		uint i = _textLines[*row].getChunkNum(&pos);
+		uint ch = _textLines[*row].getChunkNum(&pos);
 
-		_textLines[*row].chunks[i].text.deleteChar(pos);
+		_textLines[*row].chunks[ch].text.deleteChar(pos);
 
 		(*col)--;
 


Commit: b8d2cdff021717eef09346dcf90620fb5b7fd7e3
    https://github.com/scummvm/scummvm/commit/b8d2cdff021717eef09346dcf90620fb5b7fd7e3
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-05-02T22:01:11+02:00

Commit Message:
GRAPHICS: MACGUI: Fix deleting characters at edge of chunks

Changed paths:
    graphics/macgui/mactext.cpp


diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 6ac2a128e7..310b704ee4 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -69,7 +69,7 @@ uint MacTextLine::getChunkNum(int *col) {
 
 	if (i == chunks.size()) {
 		i--;	// touch the last chunk
-		pos = chunks[i].text.size();
+		pos = chunks[i].text.size() - 1;
 	}
 
 	*col = pos;


Commit: 2b1297c2f97f4f9db0d4aba6f4f381db67ff83bc
    https://github.com/scummvm/scummvm/commit/2b1297c2f97f4f9db0d4aba6f4f381db67ff83bc
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-05-02T22:02:12+02:00

Commit Message:
GRAPHICS: MACGUI: Fix text insertion

Changed paths:
    graphics/macgui/mactext.cpp


diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 310b704ee4..2237ae3b60 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -859,20 +859,6 @@ void MacText::insertChar(byte c, int *row, int *col) {
 	int pos = *col;
 	uint ch = line->getChunkNum(&pos);
 
-	for (ch = 0; ch < line->chunks.size(); ch++) {
-		if (pos >= line->chunks[ch].text.size()) {
-			pos -= line->chunks[ch].text.size();
-		} else {
-			break;
-		}
-	}
-
-	if (ch == line->chunks.size()) {
-		ch--;	// touch the last chunk
-		pos = line->chunks[ch].text.size();
-	}
-
-	// We're in the needed chunk
 	Common::U32String newchunk(line->chunks[ch].text);
 	newchunk.insertChar(c, pos);
 	int chunkw = line->chunks[ch].getFont()->getStringWidth(newchunk);


Commit: 302cfb54591078ad02d8a80a8cdb7bd1ee860840
    https://github.com/scummvm/scummvm/commit/302cfb54591078ad02d8a80a8cdb7bd1ee860840
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-05-02T23:43:05+02:00

Commit Message:
GRAPHICS: MACGUI: Fixed edge cases for cursor navigation

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


diff --git a/graphics/macgui/maceditabletext.cpp b/graphics/macgui/maceditabletext.cpp
index 24b4b6e4bd..2bce3ed627 100644
--- a/graphics/macgui/maceditabletext.cpp
+++ b/graphics/macgui/maceditabletext.cpp
@@ -334,7 +334,7 @@ bool MacEditableText::processEvent(Common::Event &event) {
 					return true;
 				}
 				_cursorRow--;
-				_cursorCol = getLineCharWidth(_cursorRow);
+				_cursorCol = getLineCharWidth(_cursorRow) - 1;
 			} else {
 				_cursorCol--;
 			}
@@ -343,7 +343,7 @@ bool MacEditableText::processEvent(Common::Event &event) {
 			return true;
 
 		case Common::KEYCODE_RIGHT:
-			if (_cursorCol == getLineCharWidth(_cursorRow)) {
+			if (_cursorCol >= getLineCharWidth(_cursorRow)) {
 				if (_cursorRow == getLineCount() - 1) { // Nowhere to go
 					return true;
 				}
@@ -361,8 +361,11 @@ bool MacEditableText::processEvent(Common::Event &event) {
 				return true;
 
 			_cursorRow--;
-			getRowCol(_cursorX, _textLines[_cursorRow].y, nullptr, nullptr, nullptr, &ncol);
-			_cursorCol = ncol + 1;
+
+			if (_cursorCol > 0) {
+				getRowCol(_cursorX, _textLines[_cursorRow].y, nullptr, nullptr, nullptr, &ncol);
+				_cursorCol = ncol + 1;
+			}
 
 			updateCursorPos();
 
@@ -373,8 +376,10 @@ bool MacEditableText::processEvent(Common::Event &event) {
 				return true;
 
 			_cursorRow++;
-			getRowCol(_cursorX, _textLines[_cursorRow].y, nullptr, nullptr, nullptr, &ncol);
-			_cursorCol = ncol + 1;
+			if (_cursorCol > 0) {
+				getRowCol(_cursorX, _textLines[_cursorRow].y, nullptr, nullptr, nullptr, &ncol);
+				_cursorCol = ncol + 1;
+			}
 
 			updateCursorPos();
 
diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 2237ae3b60..77c62d4747 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -897,7 +897,11 @@ void MacText::deletePreviousChar(int *row, int *col) {
 			_textLines[*row].chunks.push_back(MacFontRun(_textLines[*row + 1].firstChunk()));
 			_textLines[*row].firstChunk().text.clear();
 		}
-		reshuffleParagraph(row, col);
+
+		for (int i = 1; i < _textLines[*row + 1].chunks.size(); i++)
+			_textLines[*row].chunks.push_back(MacFontRun(_textLines[*row + 1].chunks[i]));
+
+		_textLines.remove_at(*row + 1);
 	} else {
 		int pos = *col - 1;
 		uint ch = _textLines[*row].getChunkNum(&pos);
@@ -905,10 +909,12 @@ void MacText::deletePreviousChar(int *row, int *col) {
 		_textLines[*row].chunks[ch].text.deleteChar(pos);
 
 		(*col)--;
-
-		reshuffleParagraph(row, col);
 	}
 
+	_textLines[*row].width = -1; // flush the cache
+
+	reshuffleParagraph(row, col);
+
 	_fullRefresh = true;
 	recalcDims();
 	render();
@@ -931,6 +937,8 @@ void MacText::addNewLine(int *row, int *col) {
 	}
 	line->width = -1; // Drop cache
 
+	_textLines[*row].width = -1; // flush the cache
+
 	_textLines.insert_at(*row + 1, newline);
 
 	(*row)++;


Commit: 8615f27a87c4e19a0504442b9832897a4c23db80
    https://github.com/scummvm/scummvm/commit/8615f27a87c4e19a0504442b9832897a4c23db80
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-05-03T00:23:34+02:00

Commit Message:
GRAPHICS: MACGUI: Implemented reshuffleParagraph() in editable text

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


diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 77c62d4747..a016f067a5 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -184,8 +184,8 @@ static const Common::U32String::value_type *readHex(uint16 *res, const Common::U
 // Adds the given string to the end of the last line/chunk
 // while observing the _maxWidth and keeping this chunk's
 // formatting
-void MacText::chopChunk(const Common::U32String &str) {
-	int curLine = _textLines.size() - 1;
+void MacText::chopChunk(const Common::U32String &str, int *curLinePtr) {
+	int curLine = *curLinePtr;
 	int curChunk = _textLines[curLine].chunks.size() - 1;
 	MacFontRun *chunk = &_textLines[curLine].chunks[curChunk];
 
@@ -232,14 +232,16 @@ void MacText::chopChunk(const Common::U32String &str) {
 		newchunk.text = text[i];
 
 		curLine++;
-		_textLines.resize(curLine + 1);
+		_textLines.insert_at(curLine, MacTextLine());
 		_textLines[curLine].chunks.push_back(newchunk);
 
 		D(9, "** chopChunk, added line: \"%s\"", toPrintable(text[i].encode()).c_str());
 	}
+
+	*curLinePtr = curLine;
 }
 
-void MacText::splitString(const Common::U32String &str) {
+void MacText::splitString(const Common::U32String &str, int curLine) {
 	const Common::U32String::value_type *l = str.c_str();
 
 	D(9, "** splitString(\"%s\")", toPrintable(str.encode()).c_str());
@@ -259,7 +261,9 @@ void MacText::splitString(const Common::U32String &str) {
 		D(9, "** splitString, continuing, %d lines", _textLines.size());
 	}
 
-	int curLine = _textLines.size() - 1;
+	if (curLine == -1)
+		curLine = _textLines.size() - 1;
+
 	int curChunk = _textLines[curLine].chunks.size() - 1;
 	MacFontRun chunk = _textLines[curLine].chunks[curChunk];
 
@@ -309,7 +313,7 @@ void MacText::splitString(const Common::U32String &str) {
 
 			// Okay, now we are either at the end of the line, or in the next
 			// chunk definition. That means, that we have to store the previous chunk
-			chopChunk(tmp);
+			chopChunk(tmp, &curLine);
 
 			tmp.clear();
 
@@ -368,7 +372,7 @@ void MacText::splitString(const Common::U32String &str) {
 		_textLines[curLine].paragraphEnd = true;
 
 		curLine++;
-		_textLines.resize(curLine + 1);
+		_textLines.insert_at(curLine, MacTextLine());
 		_textLines[curLine].chunks.push_back(chunk);
 	}
 
@@ -950,6 +954,25 @@ void MacText::addNewLine(int *row, int *col) {
 }
 
 void MacText::reshuffleParagraph(int *row, int *col) {
+	// First, we looking for the paragraph start and end
+	int start = *row, end = *row;
+
+	while (start && !_textLines[start - 1].paragraphEnd)
+		start--;
+
+	while (end < _textLines.size() - 1 && !_textLines[end].paragraphEnd) // stop at last line
+		end++;
+
+	// Get whole paragraph
+	Common::U32String paragraph = getTextChunk(start, 0, end, -1, true, false);
+
+	// Remove it from the text
+	for (int i = start; i <= end; i++) {
+		_textLines.remove_at(start);
+	}
+
+	// And now readd it
+	splitString(paragraph, start);
 }
 
 } // End of namespace Graphics
diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h
index 5ae093bba0..b6e1cd9679 100644
--- a/graphics/macgui/mactext.h
+++ b/graphics/macgui/mactext.h
@@ -151,8 +151,8 @@ public:
 	Common::U32String getTextChunk(int startRow, int startCol, int endRow, int endCol, bool formatted = false, bool newlines = true);
 
 private:
-	void chopChunk(const Common::U32String &str);
-	void splitString(const Common::U32String &s);
+	void chopChunk(const Common::U32String &str, int *curLine);
+	void splitString(const Common::U32String &s, int curLine = -1);
 	void render(int from, int to);
 	void recalcDims();
 	void reallocSurface();


Commit: 217884d8738da705db7d23e7280086dbb6ae412e
    https://github.com/scummvm/scummvm/commit/217884d8738da705db7d23e7280086dbb6ae412e
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-05-03T00:44:54+02:00

Commit Message:
GRAPHICS: MACGUI: Collapse text formatting in getTextChunk()

Changed paths:
    graphics/macgui/mactext.cpp


diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index a016f067a5..04cd0ad3c4 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -767,6 +767,15 @@ void MacText::getRowCol(int x, int y, int *sx, int *sy, int *row, int *col) {
 		*row = nrow;
 }
 
+#define ADDFORMATTING() \
+	if (formatted) { \
+		formatting = _textLines[i].chunks[chunk].toString(); \
+		if (formatting != prevformatting) { \
+			res += formatting; \
+			prevformatting = formatting; \
+		} \
+	}
+
 Common::U32String MacText::getTextChunk(int startRow, int startCol, int endRow, int endCol, bool formatted, bool newlines) {
 	Common::U32String res;
 
@@ -779,21 +788,23 @@ Common::U32String MacText::getTextChunk(int startRow, int startCol, int endRow,
 	startRow = CLIP(startRow, 0, (int)_textLines.size() - 1);
 	endRow = CLIP(endRow, 0, (int)_textLines.size() - 1);
 
+	Common::U32String formatting, prevformatting;
+
 	for (int i = startRow; i <= endRow; i++) {
 		if (i == startRow && i == endRow) {
 			for (uint chunk = 0; chunk < _textLines[i].chunks.size(); chunk++) {
+				if (_textLines[i].chunks[chunk].text.empty())
+					continue;
+
 				if (startCol <= 0) {
-					if (formatted)
-						res += _textLines[i].chunks[chunk].toString();
+					ADDFORMATTING();
 
 					if (endCol >= (int)_textLines[i].chunks[chunk].text.size())
 						res += _textLines[i].chunks[chunk].text;
 					else
 						res += Common::U32String(_textLines[i].chunks[chunk].text.c_str(), endCol);
 				} else if ((int)_textLines[i].chunks[chunk].text.size() > startCol) {
-					if (formatted)
-						res += _textLines[i].chunks[chunk].toString();
-
+					ADDFORMATTING();
 					res += Common::U32String(_textLines[i].chunks[chunk].text.c_str() + startCol, endCol - startCol);
 				}
 
@@ -805,15 +816,14 @@ Common::U32String MacText::getTextChunk(int startRow, int startCol, int endRow,
 			}
 		} else if (i == startRow && startCol != 0) {
 			for (uint chunk = 0; chunk < _textLines[i].chunks.size(); chunk++) {
-				if (startCol <= 0) {
-					if (formatted)
-						res += _textLines[i].chunks[chunk].toString();
+				if (_textLines[i].chunks[chunk].text.empty())
+					continue;
 
+				if (startCol <= 0) {
+					ADDFORMATTING();
 					res += _textLines[i].chunks[chunk].text;
 				} else if ((int)_textLines[i].chunks[chunk].text.size() > startCol) {
-					if (formatted)
-						res += _textLines[i].chunks[chunk].toString();
-
+					ADDFORMATTING();
 					res += Common::U32String(_textLines[i].chunks[chunk].text.c_str() + startCol);
 				}
 
@@ -825,8 +835,10 @@ Common::U32String MacText::getTextChunk(int startRow, int startCol, int endRow,
 				res += ' ';
 		} else if (i == endRow) {
 			for (uint chunk = 0; chunk < _textLines[i].chunks.size(); chunk++) {
-				if (formatted)
-					res += _textLines[i].chunks[chunk].toString();
+				if (_textLines[i].chunks[chunk].text.empty())
+					continue;
+
+				ADDFORMATTING();
 
 				if (endCol >= (int)_textLines[i].chunks[chunk].text.size())
 					res += _textLines[i].chunks[chunk].text;
@@ -840,9 +852,10 @@ Common::U32String MacText::getTextChunk(int startRow, int startCol, int endRow,
 			}
 		} else {
 			for (uint chunk = 0; chunk < _textLines[i].chunks.size(); chunk++) {
-				if (formatted)
-					res += _textLines[i].chunks[chunk].toString();
+				if (_textLines[i].chunks[chunk].text.empty())
+					continue;
 
+				ADDFORMATTING();
 				res += _textLines[i].chunks[chunk].text;
 			}
 




More information about the Scummvm-git-logs mailing list