[Scummvm-git-logs] scummvm master -> 520e2b107b1726cc95e049784d1943935fd8621b

sev- sev at scummvm.org
Sat May 2 19:28:31 UTC 2020


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

Summary:
520e2b107b GRAPHICS: MACGUI: Fixed vertical cursor movement in editable text


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

Commit Message:
GRAPHICS: MACGUI: Fixed vertical cursor movement 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 b1d6c69da9..5e21f89caf 100644
--- a/graphics/macgui/maceditabletext.cpp
+++ b/graphics/macgui/maceditabletext.cpp
@@ -311,6 +311,8 @@ bool MacEditableText::processEvent(Common::Event &event) {
 			return false;
 		}
 
+		int ncol;
+
 		switch (event.kbd.keycode) {
 		case Common::KEYCODE_BACKSPACE:
 			if (_cursorRow > 0 || _cursorCol > 0) {
@@ -358,6 +360,9 @@ bool MacEditableText::processEvent(Common::Event &event) {
 				return true;
 
 			_cursorRow--;
+			getRowCol(_cursorX, _textLines[_cursorRow].y, nullptr, nullptr, nullptr, &ncol);
+			_cursorCol = ncol + 1;
+
 			updateCursorPos();
 
 			return true;
@@ -367,6 +372,9 @@ bool MacEditableText::processEvent(Common::Event &event) {
 				return true;
 
 			_cursorRow++;
+			getRowCol(_cursorX, _textLines[_cursorRow].y, nullptr, nullptr, nullptr, &ncol);
+			_cursorCol = ncol + 1;
+
 			updateCursorPos();
 
 			return true;
diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index bab072f559..0ec5de4521 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -702,6 +702,8 @@ void MacText::removeLastLine() {
 }
 
 void MacText::getRowCol(int x, int y, int *sx, int *sy, int *row, int *col) {
+	int nsx, nsy, nrow, ncol;
+
 	if (y > _textMaxHeight) {
 		x = _surface->w;
 	}
@@ -709,47 +711,56 @@ void MacText::getRowCol(int x, int y, int *sx, int *sy, int *row, int *col) {
 	y = CLIP(y, 0, _textMaxHeight);
 
 	// FIXME: We should use bsearch() here
-	*row = _textLines.size() - 1;
+	nrow = _textLines.size() - 1;
 
-	while (*row && _textLines[*row].y > y)
-		(*row)--;
+	while (nrow && _textLines[nrow].y > y)
+		(nrow)--;
 
-	*sy = _textLines[*row].y;
+	nsy = _textLines[nrow].y;
 
-	*col = 0;
+	ncol = 0;
 
 	int width = 0, pwidth = 0;
 	int mcol = 0, pmcol = 0;
 	uint chunk;
-	for (chunk = 0; chunk < _textLines[*row].chunks.size(); chunk++) {
+	for (chunk = 0; chunk < _textLines[nrow].chunks.size(); chunk++) {
 		pwidth = width;
 		pmcol = mcol;
-		if (!_textLines[*row].chunks[chunk].text.empty()) {
-			width += _textLines[*row].chunks[chunk].getFont()->getStringWidth(_textLines[*row].chunks[chunk].text);
-			mcol += _textLines[*row].chunks[chunk].text.size();
+		if (!_textLines[nrow].chunks[chunk].text.empty()) {
+			width += _textLines[nrow].chunks[chunk].getFont()->getStringWidth(_textLines[nrow].chunks[chunk].text);
+			mcol += _textLines[nrow].chunks[chunk].text.size();
 		}
 
 		if (width > x)
 			break;
 	}
 
-	if (chunk == _textLines[*row].chunks.size())
+	if (chunk == _textLines[nrow].chunks.size())
 		chunk--;
 
-	Common::U32String str = _textLines[*row].chunks[chunk].text;
+	Common::U32String str = _textLines[nrow].chunks[chunk].text;
 
-	*col = mcol;
+	ncol = mcol;
 
 	for (int i = str.size(); i >= 0; i--) {
-		int strw = _textLines[*row].chunks[chunk].getFont()->getStringWidth(str);
+		int strw = _textLines[nrow].chunks[chunk].getFont()->getStringWidth(str);
 		if (strw + pwidth < x) {
-			*col = pmcol + i;
-			*sx = strw + pwidth;
+			ncol = pmcol + i;
+			nsx = strw + pwidth;
 			break;
 		}
 
 		str.deleteLastChar();
 	}
+
+	if (sx)
+		*sx = nsx;
+	if (sy)
+		*sy = nsy;
+	if (col)
+		*col = ncol;
+	if (row)
+		*row = nrow;
 }
 
 Common::U32String MacText::getTextChunk(int startRow, int startCol, int endRow, int endCol, bool formatted, bool newlines) {




More information about the Scummvm-git-logs mailing list