[Scummvm-git-logs] scummvm master -> 619ead749b272b71809d5b3e401b72584c1798e6
sev-
sev at scummvm.org
Fri May 1 13:07:38 UTC 2020
This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
b1a8835adc GRAPHICS: MACGUI: Implemented trivial case for backspace in editable text
abe45f2895 GRAPHICS: MACGUI: Implemented method for obtaining edited string
619ead749b DIRECTOR: Plug editable text
Commit: b1a8835adc9aa3988eca1df278bd1d49c8f07363
https://github.com/scummvm/scummvm/commit/b1a8835adc9aa3988eca1df278bd1d49c8f07363
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-05-01T15:07:22+02:00
Commit Message:
GRAPHICS: MACGUI: Implemented trivial case for backspace in editable text
Changed paths:
graphics/macgui/maceditabletext.cpp
graphics/macgui/mactext.cpp
graphics/macgui/mactext.h
diff --git a/graphics/macgui/maceditabletext.cpp b/graphics/macgui/maceditabletext.cpp
index 10bd7f5de0..7bb6165db6 100644
--- a/graphics/macgui/maceditabletext.cpp
+++ b/graphics/macgui/maceditabletext.cpp
@@ -311,6 +311,7 @@ bool MacEditableText::processEvent(Common::Event &event) {
case Common::KEYCODE_BACKSPACE:
if (_cursorRow > 0 || _cursorCol > 0) {
deletePreviousChar(&_cursorRow, &_cursorCol);
+ updateCursorPos();
_contentIsDirty = true;
}
return true;
diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 7c57902875..377ab97120 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -49,6 +49,34 @@ const Common::String MacFontRun::toString() {
return Common::String::format("\001\016%04x%02x%04x%04x%04x%04x", fontId, textSlant, fontSize, palinfo1, palinfo2, palinfo3);
}
+bool MacFontRun::equals(MacFontRun &to) {
+ return (fontId == to.fontId && textSlant == to.textSlant
+ && fontSize == to.fontSize && palinfo1 == to.palinfo1
+ && palinfo2 == to.palinfo2 && palinfo3 == to.palinfo3);
+}
+
+uint MacTextLine::getChunkNum(int *col) {
+ int pos = *col;
+ uint i;
+
+ for (i = 0; i < chunks.size(); i++) {
+ if (pos >= chunks[i].text.size()) {
+ pos -= chunks[i].text.size();
+ } else {
+ break;
+ }
+ }
+
+ if (i == chunks.size()) {
+ i--; // touch the last chunk
+ pos = chunks[i].text.size();
+ }
+
+ *col = pos;
+
+ return i;
+}
+
MacText::~MacText() {
delete _surface;
}
@@ -190,7 +218,6 @@ void MacText::chopChunk(const Common::U32String &str) {
// Recalc dims
getLineWidth(curLine, true);
- getLineCharWidth(curLine, true);
D(9, "** chopChunk, subchunk: \"%s\" (%d lines, maxW: %d)", toPrintable(text[0].encode()).c_str(), text.size(), _maxWidth);
@@ -455,6 +482,7 @@ int MacText::getLineWidth(int line, bool enforce, int col) {
int width = 0;
int height = 0;
+ int charwidth = 0;
bool hastext = false;
@@ -476,6 +504,7 @@ int MacText::getLineWidth(int line, bool enforce, int col) {
if (!_textLines[line].chunks[i].text.empty()) {
width += _textLines[line].chunks[i].getFont()->getStringWidth(_textLines[line].chunks[i].text);
+ charwidth += _textLines[line].chunks[i].text.size();
hastext = true;
}
@@ -487,6 +516,7 @@ int MacText::getLineWidth(int line, bool enforce, int col) {
_textLines[line].width = width;
_textLines[line].height = height;
+ _textLines[line].charwidth = charwidth;
return width;
}
@@ -499,13 +529,10 @@ int MacText::getLineCharWidth(int line, bool 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()) {
+ if (!_textLines[line].chunks[i].text.empty())
width += _textLines[line].chunks[i].text.size();
- hastext = true;
- }
}
_textLines[line].charwidth = width;
@@ -540,7 +567,6 @@ 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;
}
@@ -811,16 +837,10 @@ Common::U32String MacText::getTextChunk(int startRow, int startCol, int endRow,
//////////////////
// Text editing
-void MacText::deletePreviousChar(int *row, int *col) {
-}
-
-void MacText::addNewLine(int *row, int *col) {
-}
-
void MacText::insertChar(byte c, int *row, int *col) {
MacTextLine *line = &_textLines[*row];
int pos = *col;
- uint i;
+ uint i = line->getChunkNum(&pos);
for (i = 0; i < line->chunks.size(); i++) {
if (pos >= line->chunks[i].text.size()) {
@@ -841,18 +861,60 @@ void MacText::insertChar(byte c, int *row, int *col) {
int chunkw = line->chunks[i].getFont()->getStringWidth(newchunk);
int oldw = line->chunks[i].getFont()->getStringWidth(line->chunks[i].text);
+ line->chunks[i].text = newchunk;
+ line->width = -1; // Force recalc
+
+ (*col)++;
+
if (getLineWidth(*row) - oldw + chunkw > _maxWidth) { // Needs reshuffle
- warning("insertChar(): Need reshuffle");
+ reshuffleParagraph(row, col);
+ _fullRefresh = true;
+ recalcDims();
+ render();
} else {
- line->chunks[i].text = newchunk;
- line->width = -1; // Force recalc
-
recalcDims();
render(*row, *row);
+ }
+}
+
+void MacText::deletePreviousChar(int *row, int *col) {
+ if (*col == 0 && *row == 0) // nothing to do
+ return;
+
+ if (*col == 0) { // Need to glue the lines
+ *col = getLineCharWidth(*row - 1);
+ (*row)--;
+
+ // formatting matches, glue texts as normal
+ if (_textLines[*row].lastChunk().equals(_textLines[*row + 1].firstChunk())) {
+ _textLines[*row].lastChunk().text += _textLines[*row + 1].firstChunk().text;
+ _textLines[*row + 1].firstChunk().text.clear();
+ } else {
+ // formatting doesn't match, move whole chunk
+ _textLines[*row].chunks.push_back(MacFontRun(_textLines[*row + 1].firstChunk()));
+ _textLines[*row].firstChunk().text.clear();
+ }
+ reshuffleParagraph(row, col);
+ } else {
+ int pos = *col - 1;
+ uint i = _textLines[*row].getChunkNum(&pos);
+
+ _textLines[*row].chunks[i].text.deleteChar(pos);
- (*col)++;
+ (*col)--;
+
+ reshuffleParagraph(row, col);
}
+
+ _fullRefresh = true;
+ recalcDims();
+ render();
+}
+
+void MacText::addNewLine(int *row, int *col) {
}
+void MacText::reshuffleParagraph(int *row, int *col) {
+}
} // End of namespace Graphics
diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h
index 480946ee54..5ae093bba0 100644
--- a/graphics/macgui/mactext.h
+++ b/graphics/macgui/mactext.h
@@ -72,6 +72,7 @@ struct MacFontRun {
const Font *getFont();
const Common::String toString();
+ bool equals(MacFontRun &to);
};
struct MacTextLine {
@@ -88,6 +89,19 @@ struct MacTextLine {
y = 0;
paragraphEnd = false;
}
+
+ MacFontRun &firstChunk() { return chunks[0]; }
+ MacFontRun &lastChunk() { return chunks[chunks.size() - 1]; }
+
+ /**
+ * Search for a chunk at given char column.
+ *
+ * @param col Requested column, gets modified with in-chunk column
+ * @returns Chunk number
+ *
+ * @note If requested column is too big, returns last character in the line
+ */
+ uint getChunkNum(int *col);
};
class MacText {
@@ -154,6 +168,13 @@ private:
*/
int getLineWidth(int line, bool enforce = false, int col = -1);
+ /**
+ * Rewraps paragraph containing given text row.
+ * When text is modified, we redo whole thing again without touching
+ * other paragraphs. Also, cursor position is returned in the arguments
+ */
+ void reshuffleParagraph(int *row, int *col);
+
protected:
MacWindowManager *_wm;
Commit: abe45f28958b57f94c5d9278e743352692413fa0
https://github.com/scummvm/scummvm/commit/abe45f28958b57f94c5d9278e743352692413fa0
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-05-01T15:07:22+02:00
Commit Message:
GRAPHICS: MACGUI: Implemented method for obtaining edited string
Changed paths:
graphics/macgui/maceditabletext.cpp
graphics/macgui/maceditabletext.h
graphics/macgui/mactext.cpp
diff --git a/graphics/macgui/maceditabletext.cpp b/graphics/macgui/maceditabletext.cpp
index 7bb6165db6..58d3653ddf 100644
--- a/graphics/macgui/maceditabletext.cpp
+++ b/graphics/macgui/maceditabletext.cpp
@@ -276,6 +276,10 @@ bool MacEditableText::isCutAllowed() {
return false;
}
+Common::U32String MacEditableText::getEditedString() {
+ return getTextChunk(_editableRow, 0, -1, -1);
+}
+
Common::U32String MacEditableText::cutSelection() {
if (!isCutAllowed())
return Common::U32String("");
diff --git a/graphics/macgui/maceditabletext.h b/graphics/macgui/maceditabletext.h
index 6c98797e8e..f39e7d6768 100644
--- a/graphics/macgui/maceditabletext.h
+++ b/graphics/macgui/maceditabletext.h
@@ -84,6 +84,8 @@ public:
Common::U32String cutSelection();
const SelectedText *getSelectedText() { return &_selectedText; }
+ Common::U32String getEditedString();
+
private:
void init();
bool isCutAllowed();
diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 377ab97120..bab072f559 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -755,6 +755,12 @@ void MacText::getRowCol(int x, int y, int *sx, int *sy, int *row, int *col) {
Common::U32String MacText::getTextChunk(int startRow, int startCol, int endRow, int endCol, bool formatted, bool newlines) {
Common::U32String res;
+ if (endRow == -1)
+ endRow = _textLines.size() - 1;
+
+ if (endCol == -1)
+ endCol = getLineCharWidth(endRow);
+
startRow = CLIP(startRow, 0, (int)_textLines.size() - 1);
endRow = CLIP(endRow, 0, (int)_textLines.size() - 1);
Commit: 619ead749b272b71809d5b3e401b72584c1798e6
https://github.com/scummvm/scummvm/commit/619ead749b272b71809d5b3e401b72584c1798e6
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-05-01T15:07:22+02:00
Commit Message:
DIRECTOR: Plug editable text
Changed paths:
engines/director/cast.cpp
engines/director/cast.h
engines/director/lingo/lingo-codegen.cpp
engines/director/lingo/lingo.cpp
diff --git a/engines/director/cast.cpp b/engines/director/cast.cpp
index 1c09c49b91..c2a9ade8d0 100644
--- a/engines/director/cast.cpp
+++ b/engines/director/cast.cpp
@@ -300,6 +300,13 @@ void TextCast::setText(const char *text) {
}
}
+Common::String TextCast::getText() {
+ if (_widget)
+ _ptext = ((Graphics::MacEditableText *)_widget)->getEditedString().encode();
+
+ return _ptext;
+}
+
ShapeCast::ShapeCast(Common::ReadStreamEndian &stream, uint16 version) {
_type = kCastShape;
diff --git a/engines/director/cast.h b/engines/director/cast.h
index ab10af0336..c3bac04fc7 100644
--- a/engines/director/cast.h
+++ b/engines/director/cast.h
@@ -129,6 +129,8 @@ public:
void importStxt(const Stxt *stxt);
void importRTE(byte* text);
CachedMacText *_cachedMacText;
+
+ Common::String getText();
};
class ButtonCast : public TextCast {
diff --git a/engines/director/lingo/lingo-codegen.cpp b/engines/director/lingo/lingo-codegen.cpp
index 10e23bac72..d60fa60594 100644
--- a/engines/director/lingo/lingo-codegen.cpp
+++ b/engines/director/lingo/lingo-codegen.cpp
@@ -652,7 +652,7 @@ Datum Lingo::varFetch(Datum &var) {
switch (cast->_type) {
case kCastText:
result.type = STRING;
- result.u.s = new Common::String(((TextCast *)cast)->_ptext);
+ result.u.s = new Common::String(((TextCast *)cast)->getText());
break;
default:
warning("varFetch: Unhandled cast type %s", tag2str(cast->_type));
diff --git a/engines/director/lingo/lingo.cpp b/engines/director/lingo/lingo.cpp
index d57c093c94..0ae5051924 100644
--- a/engines/director/lingo/lingo.cpp
+++ b/engines/director/lingo/lingo.cpp
@@ -532,9 +532,9 @@ Common::String *Datum::makeString(bool printonly) {
}
if (!printonly) {
- *s = ((TextCast *)score->_loadedCast->getVal(idx))->_ptext;
+ *s = Common::String(((TextCast *)score->_loadedCast->getVal(idx))->getText());
} else {
- *s = Common::String::format("reference: \"%s\"", ((TextCast *)score->_loadedCast->getVal(idx))->_ptext.c_str());
+ *s = Common::String::format("reference: \"%s\"", ((TextCast *)score->_loadedCast->getVal(idx))->getText().c_str());
}
}
break;
More information about the Scummvm-git-logs
mailing list