[Scummvm-cvs-logs] CVS: scummvm/gui EditTextWidget.cpp,1.6,1.7 EditTextWidget.h,1.3,1.4

Oliver Kiehl olki at users.sourceforge.net
Fri Jan 10 13:34:06 CET 2003


Update of /cvsroot/scummvm/scummvm/gui
In directory sc8-pr-cvs1:/tmp/cvs-serv6498/gui

Modified Files:
	EditTextWidget.cpp EditTextWidget.h 
Log Message:
Added some basic line editing to the EditText widget


Index: EditTextWidget.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/EditTextWidget.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- EditTextWidget.cpp	22 Nov 2002 18:46:18 -0000	1.6
+++ EditTextWidget.cpp	10 Jan 2003 21:33:42 -0000	1.7
@@ -31,6 +31,8 @@
 
 	_caretVisible = false;
 	_caretTime = 0;
+
+	_pos = _label.size();
 }
 
 void EditTextWidget::handleTickle()
@@ -74,19 +76,33 @@
 			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 @@
 	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;

Index: EditTextWidget.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/EditTextWidget.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- EditTextWidget.h	22 Nov 2002 14:02:29 -0000	1.3
+++ EditTextWidget.h	10 Jan 2003 21:33:42 -0000	1.4
@@ -33,6 +33,7 @@
 	String			_backupString;
 	bool			_caretVisible;
 	uint32			_caretTime;
+	int			_pos;
 public:
 	EditTextWidget(Dialog *boss, int x, int y, int w, int h, const String &text);
 





More information about the Scummvm-git-logs mailing list