GRAPHICS: MACGUI: Implemented trivial case of character insertion in MacText

This commit is contained in:
Eugene Sandulenko 2020-05-01 01:29:45 +02:00
parent a5f2284421
commit c879bba4b4
4 changed files with 54 additions and 18 deletions

View File

@ -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) {

View File

@ -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;

View File

@ -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

View File

@ -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; }