[Scummvm-cvs-logs] CVS: scummvm/gui EditTextWidget.cpp,1.1,1.2 EditTextWidget.h,1.1,1.2 ListWidget.cpp,1.14,1.15 dialog.cpp,1.24,1.25 dialog.h,1.15,1.16 launcher.cpp,1.20,1.21 launcher.h,1.7,1.8 widget.cpp,1.8,1.9 widget.h,1.9,1.10

Max Horn fingolfin at users.sourceforge.net
Thu Nov 21 07:21:05 CET 2002


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

Modified Files:
	EditTextWidget.cpp EditTextWidget.h ListWidget.cpp dialog.cpp 
	dialog.h launcher.cpp launcher.h widget.cpp widget.h 
Log Message:
Implemented EditTextWidget; fixed Add Game/Remove Game in launcher; make use of EditTextWidget in EditGameDialog; various other tweaks

Index: EditTextWidget.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/EditTextWidget.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- EditTextWidget.cpp	21 Nov 2002 12:48:50 -0000	1.1
+++ EditTextWidget.cpp	21 Nov 2002 15:20:51 -0000	1.2
@@ -22,3 +22,136 @@
 #include "EditTextWidget.h"
 #include "dialog.h"
 #include "newgui.h"
+
+EditTextWidget::EditTextWidget(Dialog *boss, int x, int y, int w, int h, const String &text)
+	: StaticTextWidget(boss, x, y-1, w, h+2, text, kTextAlignLeft), _backupString(text)
+{
+	_flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS | WIDGET_WANT_TICKLE;
+	_type = kEditTextWidget;
+
+	_currentKeyDown = 0;
+
+	_caretVisible = false;
+	_caretTime = 0;
+}
+
+void EditTextWidget::handleTickle()
+{
+	uint32 time = _boss->getGui()->get_time();
+	if (_caretTime < time) {
+		_caretTime = time + kCaretBlinkTime;
+		if (_caretVisible) {
+			drawCaret(true);
+		} else {
+			drawCaret(false);
+		}
+	}
+}
+
+void EditTextWidget::handleMouseDown(int x, int y, int button, int clickCount)
+{
+	// TODO - once we support "real editing" (i.e. caret can be at any spot),
+	// a mouse click should place the caret.
+}
+
+bool EditTextWidget::handleKeyDown(char key, int modifiers)
+{
+	bool handled = true;
+	bool dirty = false;
+
+	// First remove caret
+	if (_caretVisible)
+		drawCaret(true);
+
+	switch (key) {
+		case '\n':	// enter/return
+		case '\r':
+			_boss->releaseFocus();
+			dirty = true;
+			break;
+		case 27:	// escape
+			_label = _backupString;
+			_boss->releaseFocus();
+			dirty = true;
+			break;
+		case 8:		// backspace
+			_label.deleteLastChar();
+			dirty = true;
+			break;
+		case 20:	// left arrow
+			break;
+		case 19:	// right arrow
+			break;
+		case 22:	// home
+			break;
+		case 23:	// end
+			break;
+		default:
+			if (isalnum(key)  || key == ' ') {
+				_label += key;
+				dirty = true;
+			} else {
+				handled = false;
+			}
+	}
+
+	if (dirty)
+		draw();
+
+#ifndef _WIN32_WCE
+
+	// not done on WinCE because keyboard is emulated and
+	// keyup is not generated
+
+	_currentKeyDown = key;
+
+#endif
+	
+	return handled;
+}
+
+bool EditTextWidget::handleKeyUp(char key, int modifiers)
+{
+	if (key == _currentKeyDown)
+		_currentKeyDown = 0;
+	return true;
+}
+
+void EditTextWidget::drawWidget(bool hilite)
+{
+	NewGui			*gui = _boss->getGui();
+
+	// Draw a thin frame around us.
+	gui->hline(_x, _y, _x+_w-1, gui->_color);
+	gui->hline(_x, _y+_h-1, _x+_w-1, gui->_shadowcolor);
+	gui->vline(_x, _y, _y+_h-1, gui->_color);
+
+	// Draw the text
+	_align = (gui->getStringWidth(_label) > _w-6) ? kTextAlignRight : kTextAlignLeft;
+	gui->drawString(_label, _x+2, _y+3, _w-6, gui->_textcolor, _align);
+}
+
+void EditTextWidget::drawCaret(bool erase)
+{
+	// Only draw if item is visible
+	if (!isVisible() || !_boss->isVisible())
+		return;
+
+	NewGui *gui = _boss->getGui();
+	
+	int16 color = erase ? gui->_bgcolor : gui->_textcolorhi;
+	int x = _x + _boss->getX() + 3;
+	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);
+	if (width > _w-6)
+		width = _w-6;
+	x += width;
+
+	gui->vline(x, y, y+kLineHeight, color);
+	gui->addDirtyRect(x, y, 2, kLineHeight);
+	
+	_caretVisible = !erase;
+}

Index: EditTextWidget.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/EditTextWidget.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- EditTextWidget.h	21 Nov 2002 12:48:50 -0000	1.1
+++ EditTextWidget.h	21 Nov 2002 15:20:51 -0000	1.2
@@ -35,22 +35,20 @@
 	bool			_caretVisible;
 	uint32			_caretTime;
 public:
-	EditTextWidget(Dialog *boss, int x, int y, int w, int h);
-	virtual ~EditTextWidget();
+	EditTextWidget(Dialog *boss, int x, int y, int w, int h, const String &text);
 
 	virtual void handleTickle();
 	virtual void handleMouseDown(int x, int y, int button, int clickCount);
-	virtual void handleMouseUp(int x, int y, int button, int clickCount);
 	virtual bool handleKeyDown(char key, int modifiers);
 	virtual bool handleKeyUp(char key, int modifiers);
-	virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
+	//virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
 
 	virtual bool wantsFocus() { return true; };
 
 protected:
 	void drawWidget(bool hilite);
 	void drawCaret(bool erase);
-	void lostFocusWidget();
+	void lostFocusWidget() { _backupString = _label; drawCaret(true); }
 };
 
 #endif

Index: ListWidget.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/ListWidget.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- ListWidget.cpp	21 Nov 2002 12:48:50 -0000	1.14
+++ ListWidget.cpp	21 Nov 2002 15:20:51 -0000	1.15
@@ -92,7 +92,7 @@
 {
 	uint32 time = _boss->getGui()->get_time();
 	if (_editMode && _caretTime < time) {
-		_caretTime = time + 300;
+		_caretTime = time + kCaretBlinkTime;
 		if (_caretVisible) {
 			drawCaret(true);
 		} else {
@@ -101,40 +101,6 @@
 	}
 }
 
-void ListWidget::drawCaret(bool erase)
-{
-	// Only draw if item is visible
-	if (_selectedItem < _currentPos || _selectedItem >= _currentPos + _entriesPerPage)
-		return;
-	if (!isVisible() || !_boss->isVisible())
-		return;
-
-	NewGui *gui = _boss->getGui();
-	
-	// The item is selected, thus _bgcolor is used to draw the caret and _textcolorhi to erase it
-	int16 color = erase ? gui->_textcolorhi : gui->_bgcolor;
-	int x = _x + _boss->getX() + 3;
-	int y = _y + _boss->getY() + 1;
-	ScummVM::String	buffer;
-
-	y += (_selectedItem - _currentPos) * kLineHeight;
-
-	if (_numberingMode == kListNumberingZero || _numberingMode == kListNumberingOne) {
-		char temp[10];
-		sprintf(temp, "%2d. ", (_selectedItem + _numberingMode));
-		buffer = temp;
-		buffer += _list[_selectedItem];
-	} else
-		buffer = _list[_selectedItem];
-
-	x += gui->getStringWidth(buffer);
-
-	gui->vline(x, y, y+kLineHeight, color);
-	gui->addDirtyRect(x, y, 2, kLineHeight);
-	
-	_caretVisible = !erase;
-}
-
 void ListWidget::handleMouseDown(int x, int y, int button, int clickCount)
 {
 	if (isEnabled()) {
@@ -330,6 +296,40 @@
 		gui->drawString(buffer, _x+2, _y+3 + kLineHeight * i, _w - 4,
 							(_selectedItem == pos && _hasFocus) ? gui->_bgcolor : gui->_textcolor);
 	}
+}
+
+void ListWidget::drawCaret(bool erase)
+{
+	// Only draw if item is visible
+	if (_selectedItem < _currentPos || _selectedItem >= _currentPos + _entriesPerPage)
+		return;
+	if (!isVisible() || !_boss->isVisible())
+		return;
+
+	NewGui *gui = _boss->getGui();
+	
+	// The item is selected, thus _bgcolor is used to draw the caret and _textcolorhi to erase it
+	int16 color = erase ? gui->_textcolorhi : gui->_bgcolor;
+	int x = _x + _boss->getX() + 3;
+	int y = _y + _boss->getY() + 1;
+	ScummVM::String	buffer;
+
+	y += (_selectedItem - _currentPos) * kLineHeight;
+
+	if (_numberingMode == kListNumberingZero || _numberingMode == kListNumberingOne) {
+		char temp[10];
+		sprintf(temp, "%2d. ", (_selectedItem + _numberingMode));
+		buffer = temp;
+		buffer += _list[_selectedItem];
+	} else
+		buffer = _list[_selectedItem];
+
+	x += gui->getStringWidth(buffer);
+
+	gui->vline(x, y, y+kLineHeight, color);
+	gui->addDirtyRect(x, y, 2, kLineHeight);
+	
+	_caretVisible = !erase;
 }
 
 void ListWidget::scrollToCurrent() {

Index: dialog.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/dialog.cpp,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- dialog.cpp	19 Nov 2002 01:36:47 -0000	1.24
+++ dialog.cpp	21 Nov 2002 15:20:51 -0000	1.25
@@ -90,12 +90,18 @@
 		_mouseWidget->handleMouseLeft(0);
 		_mouseWidget = 0;
 	}
+	releaseFocus();
+}
+
+void Dialog::releaseFocus()
+{
 	if (_focusedWidget) {
 		_focusedWidget->lostFocus();
 		_focusedWidget = 0;
 	}
 }
 
+
 void Dialog::draw()
 {
 	_gui->_needRedraw = true;
@@ -134,8 +140,7 @@
 	if (w && w != _focusedWidget) {
 		// The focus will change. Tell the old focused widget (if any)
 		// that it lost the focus.
-		if (_focusedWidget)
-			_focusedWidget->lostFocus();
+		releaseFocus();
 	
 		// Tell the new focused widget (if any) that it just gained the focus.
 		if (w)
@@ -157,8 +162,7 @@
 		
 		// Lose focus on mouseup unless the widget requested to retain the focus
 		if (! (_focusedWidget->getFlags() & WIDGET_RETAIN_FOCUS )) {
-			_focusedWidget->lostFocus();
-			_focusedWidget = 0;
+			releaseFocus();
 		}
 
 	} else {
@@ -208,6 +212,8 @@
 	// ESC closes all dialogs by default
 	if (key == 27)
 		close();
+	
+	// TODO: tab/shift-tab should focus the next/previous focusable widget
 }
 
 void Dialog::handleKeyUp(char key, int modifiers)

Index: dialog.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/dialog.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- dialog.h	19 Nov 2002 01:36:47 -0000	1.15
+++ dialog.h	21 Nov 2002 15:20:51 -0000	1.16
@@ -62,6 +62,8 @@
 	int16	getX() const		{ return _x; }
 	int16	getY() const		{ return _y; }
 
+	void releaseFocus();
+
 protected:
 	virtual void open();
 	virtual void close();

Index: launcher.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/launcher.cpp,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- launcher.cpp	21 Nov 2002 14:12:55 -0000	1.20
+++ launcher.cpp	21 Nov 2002 15:20:52 -0000	1.21
@@ -50,6 +50,7 @@
  * - the description (used for user feedback only)
  * - amiga/subtitles flag? Although those make only sense for Scumm games
  * - the music driver for that game (<Default> or custom)
+ *   Of course this means we need an API to query the available music drivers.
  * - maybe scaler. But there are two problems:
  *   1) different backends can have different scalers with different names,
  *      so we first have to add a way to query those... no Ender, I don't
@@ -97,19 +98,18 @@
 	}
 	
 	// Label & edit widget for the description
-	new StaticTextWidget(this, 10, 8, 40, kLineHeight, "Name: ", kTextAlignRight);
-	new StaticTextWidget(this, 50, 8, _w-50-10, kLineHeight, description, kTextAlignLeft);	// TODO - should be an EditTextWidget
-	
-	
+	new StaticTextWidget(this, 10, 10, 40, kLineHeight, "Name: ", kTextAlignRight);
+	new EditTextWidget(this, 50, 10, _w-50-10, kLineHeight, description);
+
 	// Path to game data (view only)
 	String path(_config.get("path", domain));
-	new StaticTextWidget(this, 10, 20, 40, kLineHeight, "Path: ", kTextAlignRight);
-	new StaticTextWidget(this, 50, 20, _w-50-10, kLineHeight, path, kTextAlignLeft);
+	new StaticTextWidget(this, 10, 24, 40, kLineHeight, "Path: ", kTextAlignRight);
+	new StaticTextWidget(this, 50, 24, _w-50-10, kLineHeight, path, kTextAlignLeft);
 	
 
 	// Add OK & Cancel buttons
 	addButton(_w-2*(kButtonWidth+10), _h-24, "Cancel", kCloseCmd, 0);
-	addButton(_w-(kButtonWidth+10), _h-24, "OK", kCloseCmd, 0);
+	addButton(_w-(kButtonWidth+10), _h-24, "OK", kOKCmd, 0);
 }
 
 void EditGameDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data)
@@ -172,6 +172,7 @@
 	
 	// Create file browser dialog
 	_browser = new BrowserDialog(_gui);
+
 }
 
 LauncherDialog::~LauncherDialog()
@@ -179,18 +180,29 @@
 	delete _browser;
 }
 
+void LauncherDialog::open()
+{
+	Dialog::open();
+	g_config->set_writing(true);
+}
+
+void LauncherDialog::close()
+{
+	g_config->flush();
+	g_config->set_writing(false);
+	Dialog::close();
+}
+
 void LauncherDialog::updateListing()
 {
 	int i;
 	const VersionSettings *v = version_settings;
 	ScummVM::StringList l;
-	// TODO - maybe only display those games for which settings are known
-	// (i.e. a path to the game data was set and is accesible) ?
-
 
 	// Retrieve a list of all games defined in the config file
+	_domains.clear();
 	StringList domains = g_config->get_domains();
-	for (i = 0; i < domains.size();i++) {
+	for (i = 0; i < domains.size(); i++) {
 		String name(g_config->get("gameid", domains[i]));
 		String description(g_config->get("description", domains[i]));
 		
@@ -217,8 +229,7 @@
 		}
 	}
 
-	if (l.size() > 0) 
-		_list->setList(l);
+	_list->setList(l);
 }
 
 /*
@@ -340,9 +351,7 @@
 					// User pressed OK, so make changes permanent
 
 					// Write config to disk
-					g_config->set_writing(true);
 					g_config->flush();
-					g_config->set_writing(false);
 					
 					// Update the ListWidget and force a redraw
 					updateListing();
@@ -358,6 +367,11 @@
 		// Remove the currently selected game from the list
 		assert(item >= 0);
 		g_config->delete_domain(_domains[item]);
+
+		// Write config to disk
+		g_config->flush();
+		
+		// Update the ListWidget and force a redraw
 		updateListing();
 		draw();
 		break;
@@ -374,9 +388,7 @@
 			// User pressed OK, so make changes permanent
 
 			// Write config to disk
-			g_config->set_writing(true);
 			g_config->flush();
-			g_config->set_writing(false);
 			
 			// Update the ListWidget and force a redraw
 			updateListing();

Index: launcher.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/launcher.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- launcher.h	21 Nov 2002 14:12:55 -0000	1.7
+++ launcher.h	21 Nov 2002 15:20:52 -0000	1.8
@@ -36,7 +36,9 @@
 	LauncherDialog(NewGui *gui, GameDetector &detector);
 	~LauncherDialog();
 
-	void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
+	virtual void open();
+	virtual void close();
+	virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
 
 protected:
 	ListWidget		*_list;

Index: widget.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/widget.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- widget.cpp	19 Oct 2002 01:22:41 -0000	1.8
+++ widget.cpp	21 Nov 2002 15:20:52 -0000	1.9
@@ -101,7 +101,7 @@
 void StaticTextWidget::drawWidget(bool hilite)
 {
 	NewGui *gui = _boss->getGui();
-	gui->drawString(_label.c_str(), _x, _y, _w, gui->_textcolor, _align);
+	gui->drawString(_label, _x, _y, _w, gui->_textcolor, _align);
 }
 
 
@@ -125,7 +125,7 @@
 void ButtonWidget::drawWidget(bool hilite)
 {
 	NewGui *gui = _boss->getGui();
-	gui->drawString(_label.c_str(), _x, _y, _w,
+	gui->drawString(_label, _x, _y, _w,
 	                !isEnabled() ? gui->_color :
 	                hilite ? gui->_textcolorhi : gui->_textcolor, _align);
 }
@@ -195,7 +195,7 @@
 		gui->fillRect(_x + 2, _y + 2, 10, 10, gui->_bgcolor);
 	
 	// Finally draw the label
-	gui->drawString(_label.c_str(), _x + 20, _y + 3, _w, gui->_textcolor);
+	gui->drawString(_label, _x + 20, _y + 3, _w, gui->_textcolor);
 }
 
 #pragma mark -

Index: widget.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/widget.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- widget.h	5 Nov 2002 22:34:50 -0000	1.9
+++ widget.h	21 Nov 2002 15:20:52 -0000	1.10
@@ -41,11 +41,16 @@
 
 enum {
 	kStaticTextWidget	= 'TEXT',
+	kEditTextWidget		= 'EDIT',
 	kButtonWidget		= 'BTTN',
 	kCheckboxWidget		= 'CHKB',
 	kSliderWidget		= 'SLDE',
 	kListWidget			= 'LIST',
 	kScrollBarWidget	= 'SCRB'
+};
+
+enum {
+	kCaretBlinkTime = 300
 };
 
 enum {





More information about the Scummvm-git-logs mailing list