aboutsummaryrefslogtreecommitdiff
path: root/gui/EditTextWidget.cpp
diff options
context:
space:
mode:
authorOliver Kiehl2003-01-10 21:33:42 +0000
committerOliver Kiehl2003-01-10 21:33:42 +0000
commitebdf89e4184240a752061c7c8d5450dbca809f39 (patch)
tree6fe9fe552feb98eccfe2c2b7a4d7945e560daf26 /gui/EditTextWidget.cpp
parent23a02b712a83ddd4759dd9158dc470f7f3742dfc (diff)
downloadscummvm-rg350-ebdf89e4184240a752061c7c8d5450dbca809f39.tar.gz
scummvm-rg350-ebdf89e4184240a752061c7c8d5450dbca809f39.tar.bz2
scummvm-rg350-ebdf89e4184240a752061c7c8d5450dbca809f39.zip
Added some basic line editing to the EditText widget
svn-id: r6393
Diffstat (limited to 'gui/EditTextWidget.cpp')
-rw-r--r--gui/EditTextWidget.cpp27
1 files changed, 22 insertions, 5 deletions
diff --git a/gui/EditTextWidget.cpp b/gui/EditTextWidget.cpp
index 10caf64cd7..25326eb868 100644
--- a/gui/EditTextWidget.cpp
+++ b/gui/EditTextWidget.cpp
@@ -31,6 +31,8 @@ EditTextWidget::EditTextWidget(Dialog *boss, int x, int y, int w, int h, const S
_caretVisible = false;
_caretTime = 0;
+
+ _pos = _label.size();
}
void EditTextWidget::handleTickle()
@@ -74,19 +76,33 @@ bool EditTextWidget::handleKeyDown(uint16 ascii, int keycode, int modifiers)
break;
case 8: // backspace
_label.deleteLastChar();
+ if (_pos > 0)
+ _pos--;
+ dirty = true;
+ break;
+ case 127: // delete
+ _label.deleteChar(_pos);
dirty = true;
break;
case 256+20: // left arrow
+ if (_pos > 0)
+ _pos--;
break;
case 256+19: // right arrow
+ if (_pos < _label.size())
+ _pos++;
+ break;
break;
case 256+22: // home
+ _pos = 0;
break;
case 256+23: // end
+ _pos = _label.size();
break;
default:
if (isprint((char)ascii)) {
- _label += (char)ascii;
+ _label.insertChar((char)ascii, _pos++);
+ //_label += (char)ascii;
dirty = true;
} else {
handled = false;
@@ -123,12 +139,13 @@ void EditTextWidget::drawCaret(bool erase)
NewGui *gui = _boss->getGui();
int16 color = erase ? gui->_bgcolor : gui->_textcolorhi;
- int x = _x + _boss->getX() + 3;
+ int x = _x + _boss->getX() + 2;
int y = _y + _boss->getY() + 1;
- // TODO - once we support "real editing" (i.e. caret can be at any spot),
- // x should be calculated based on the current caret position.
- int width = gui->getStringWidth(_label);
+ int width = 0;
+ for (int i = 0; i < _pos; i++)
+ width += gui->getCharWidth(_label[i]);
+
if (width > _w-6)
width = _w-6;
x += width;