[Scummvm-git-logs] scummvm master -> c879bba4b4b7ab9f2d27c4c545eb50c3f3881b4d
sev-
sev at scummvm.org
Thu Apr 30 23:30:42 UTC 2020
This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
a5f2284421 COMMON: Added U32String::insertChar()
c879bba4b4 GRAPHICS: MACGUI: Implemented trivial case of character insertion in MacText
Commit: a5f2284421f2b652071bee93aa39a304d2bbe454
https://github.com/scummvm/scummvm/commit/a5f2284421f2b652071bee93aa39a304d2bbe454
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-05-01T01:30:20+02:00
Commit Message:
COMMON: Added U32String::insertChar()
Changed paths:
common/ustr.cpp
common/ustr.h
diff --git a/common/ustr.cpp b/common/ustr.cpp
index 8064383c6e..f85237a788 100644
--- a/common/ustr.cpp
+++ b/common/ustr.cpp
@@ -223,6 +223,16 @@ bool U32String::contains(value_type x) const {
return false;
}
+void U32String::insertChar(value_type c, uint32 p) {
+ assert(p <= _size);
+
+ ensureCapacity(_size + 1, true);
+ _size++;
+ for (uint32 i = _size; i > p; --i)
+ _str[i] = _str[i - 1];
+ _str[p] = c;
+}
+
void U32String::deleteChar(uint32 p) {
assert(p < _size);
diff --git a/common/ustr.h b/common/ustr.h
index 07d3136845..7fbc9bb040 100644
--- a/common/ustr.h
+++ b/common/ustr.h
@@ -161,6 +161,9 @@ public:
_str[p] = c;
}
+ /** Insert character c before position p. */
+ void insertChar(value_type c, uint32 p);
+
/**
* Removes the value at position p from the string.
* Using this on decomposed characters will not remove the whole
Commit: c879bba4b4b7ab9f2d27c4c545eb50c3f3881b4d
https://github.com/scummvm/scummvm/commit/c879bba4b4b7ab9f2d27c4c545eb50c3f3881b4d
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-05-01T01:30:20+02:00
Commit Message:
GRAPHICS: MACGUI: Implemented trivial case of character insertion in MacText
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 b9dc247550..10bd7f5de0 100644
--- a/graphics/macgui/maceditabletext.cpp
+++ b/graphics/macgui/maceditabletext.cpp
@@ -310,13 +310,13 @@ bool MacEditableText::processEvent(Common::Event &event) {
switch (event.kbd.keycode) {
case Common::KEYCODE_BACKSPACE:
if (_cursorRow > 0 || _cursorCol > 0) {
- deletePreviousChar();
+ deletePreviousChar(&_cursorRow, &_cursorCol);
_contentIsDirty = true;
}
return true;
case Common::KEYCODE_RETURN:
- addNewLine();
+ addNewLine(&_cursorRow, &_cursorCol);
_contentIsDirty = true;
return true;
@@ -371,7 +371,8 @@ bool MacEditableText::processEvent(Common::Event &event) {
return false;
if (event.kbd.ascii >= 0x20 && event.kbd.ascii <= 0x7f) {
- insertChar((byte)event.kbd.ascii);
+ insertChar((byte)event.kbd.ascii, &_cursorRow, &_cursorCol);
+ updateCursorPos();
_contentIsDirty = true;
return true;
@@ -476,17 +477,6 @@ void MacEditableText::updateTextSelection(int x, int y) {
_contentIsDirty = true;
}
-//////////////////
-// Text editing
-void MacEditableText::deletePreviousChar() {
-}
-
-void MacEditableText::addNewLine() {
-}
-
-void MacEditableText::insertChar(byte c) {
-}
-
//////////////////
// Cursor stuff
static void cursorTimerHandler(void *refCon) {
diff --git a/graphics/macgui/maceditabletext.h b/graphics/macgui/maceditabletext.h
index b68146b29d..6c98797e8e 100644
--- a/graphics/macgui/maceditabletext.h
+++ b/graphics/macgui/maceditabletext.h
@@ -96,10 +96,6 @@ private:
void startMarking(int x, int y);
void updateTextSelection(int x, int y);
- void deletePreviousChar();
- void addNewLine();
- void insertChar(byte c);
-
public:
int _cursorX, _cursorY;
bool _cursorState;
diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 6fd6dfd7f8..7c57902875 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -809,4 +809,50 @@ Common::U32String MacText::getTextChunk(int startRow, int startCol, int endRow,
return res;
}
+//////////////////
+// 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;
+
+ for (i = 0; i < line->chunks.size(); i++) {
+ if (pos >= line->chunks[i].text.size()) {
+ pos -= line->chunks[i].text.size();
+ } else {
+ break;
+ }
+ }
+
+ if (i == line->chunks.size()) {
+ i--; // touch the last chunk
+ pos = line->chunks[i].text.size();
+ }
+
+ // We're in the needed chunk
+ Common::U32String newchunk(line->chunks[i].text);
+ newchunk.insertChar(c, pos);
+ int chunkw = line->chunks[i].getFont()->getStringWidth(newchunk);
+ int oldw = line->chunks[i].getFont()->getStringWidth(line->chunks[i].text);
+
+ if (getLineWidth(*row) - oldw + chunkw > _maxWidth) { // Needs reshuffle
+ warning("insertChar(): Need reshuffle");
+ } else {
+ line->chunks[i].text = newchunk;
+ line->width = -1; // Force recalc
+
+ recalcDims();
+ render(*row, *row);
+
+ (*col)++;
+ }
+}
+
+
} // End of namespace Graphics
diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h
index 02e272d7ff..480946ee54 100644
--- a/graphics/macgui/mactext.h
+++ b/graphics/macgui/mactext.h
@@ -125,6 +125,10 @@ public:
int getTextHeight() { return _textMaxHeight; }
int getLineHeight(int line);
+ void deletePreviousChar(int *row, int *col);
+ void addNewLine(int *row, int *col);
+ void insertChar(byte c, int *row, int *col);
+
void render();
Graphics::ManagedSurface *getSurface() { return _surface; }
More information about the Scummvm-git-logs
mailing list