[Scummvm-cvs-logs] CVS: scummvm/gui dialog.h,1.11,1.12 dialog.cpp,1.22,1.23 ScrollBarWidget.cpp,1.5,1.6 ListWidget.h,1.8,1.9 ListWidget.cpp,1.11,1.12

Max Horn fingolfin at users.sourceforge.net
Thu Jul 18 13:27:08 CEST 2002


Update of /cvsroot/scummvm/scummvm/gui
In directory usw-pr-cvs1:/tmp/cvs-serv30355/gui

Modified Files:
	dialog.h dialog.cpp ScrollBarWidget.cpp ListWidget.h 
	ListWidget.cpp 
Log Message:
put stuff in util.h into namespace ScummVM; fixed stupid bug in String class; took painelf's patch which implements save/load dialog in new GUI and fixed it slightly; various other minor changes

Index: dialog.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/dialog.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- dialog.h	13 Jul 2002 22:41:29 -0000	1.11
+++ dialog.h	18 Jul 2002 20:26:35 -0000	1.12
@@ -23,6 +23,7 @@
 
 #include "scummsys.h"
 #include "widget.h"
+#include "ListWidget.h"
 
 class NewGui;
 
@@ -83,7 +84,7 @@
 
 	virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
 protected:
-	Widget* _savegameList;
+	ListWidget* _savegameList;
 };
 
 

Index: dialog.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/dialog.cpp,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- dialog.cpp	16 Jul 2002 22:34:16 -0000	1.22
+++ dialog.cpp	18 Jul 2002 20:26:35 -0000	1.23
@@ -24,6 +24,7 @@
 #include "newgui.h"
 #include "dialog.h"
 #include "widget.h"
+#include "scumm.h"
 #include "ListWidget.h"
 
 Dialog::~Dialog()
@@ -248,6 +249,15 @@
 	kQuitCmd = 'QUIT'
 };
 
+/*
+ * TODO
+ * - Maybe go back to the old way of differentiating between the save and the load mode?
+ *   This would include that in the load mode the list is not editable.
+ * - Currently the savegame list is only loaded once when the dialog is created. Instead,
+ *   it should be loaded whenever the dialog is opened. Might want to add an open()
+ *   method to Dialog for that.
+ */
+
 SaveLoadDialog::SaveLoadDialog(NewGui *gui)
 	: Dialog (gui, 30, 20, 260, 124)
 {
@@ -269,16 +279,41 @@
 	
 	// FIXME - test
 	_savegameList = new ListWidget(this, 10, 40, 180, 74);
+
+	// Get savegame names
+	ScummVM::StringList l;
+	char name[32];
+	Scumm *s = _gui->getScumm();
+
+	for (int i = 0; i <= 80; i++) {		// 80 I got from old gui
+		s->getSavegameName(i, name);
+		l.push_back(name);
+	}
+
+	((ListWidget *)_savegameList)->setList(l);
 }
 
 void SaveLoadDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data)
 {
 	switch (cmd) {
 	case kSaveCmd:
-		//printf("Saving game in slot %d\n", _savegameList->getSelected());
+		if (_savegameList->getSelectedString()[0] != 0) {
+			Scumm *s = _gui->getScumm();
+			s->_saveLoadSlot = _savegameList->getSelected();
+			s->_saveLoadCompatible = false;
+			s->_saveLoadFlag = 1;		// 1 for save, I assume (Painelf)
+			strcpy(s->_saveLoadName, _savegameList->getSelectedString());
+			close();
+		}
 		break;
 	case kLoadCmd:
-		//printf("Loading game in slot %d\n", _savegameList->getSelected());
+		if (_savegameList->getSelectedString()[0] != 0) {
+			Scumm *s = _gui->getScumm();
+			s->_saveLoadSlot = _savegameList->getSelected();
+			s->_saveLoadCompatible = false;
+			s->_saveLoadFlag = 2;		// 2 for load. Magic number anyone?
+			close();
+		}
 		break;
 	case kPlayCmd:
 		close();

Index: ScrollBarWidget.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/ScrollBarWidget.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- ScrollBarWidget.cpp	13 Jul 2002 22:41:29 -0000	1.5
+++ ScrollBarWidget.cpp	18 Jul 2002 20:26:35 -0000	1.6
@@ -29,6 +29,8 @@
  * - Auto-repeat: if one clicks & holds on one of the arrows, then after a
  *   brief delay, it should start to contiously scroll
  * - Allow for a horizontal scrollbar, too?
+ * - If there are less items than fit on one pages, no scrolling can be done
+ *   and we thus should not highlight the arrows/slider.
  */
 
 #define UP_DOWN_BOX_HEIGHT	10
@@ -172,8 +174,8 @@
 void ScrollBarWidget::recalc()
 {
 	_sliderHeight = (_h - 2 * UP_DOWN_BOX_HEIGHT) * _entriesPerPage / _numEntries;
-	if (_sliderHeight < 4)
-		_sliderHeight = 4;
+	if (_sliderHeight < UP_DOWN_BOX_HEIGHT)
+		_sliderHeight = UP_DOWN_BOX_HEIGHT;
 
 	_sliderPos =
 		UP_DOWN_BOX_HEIGHT + (_h - 2 * UP_DOWN_BOX_HEIGHT - _sliderHeight + 1) * _currentPos / (_numEntries -

Index: ListWidget.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/ListWidget.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- ListWidget.h	18 Jul 2002 14:47:24 -0000	1.8
+++ ListWidget.h	18 Jul 2002 20:26:35 -0000	1.9
@@ -33,7 +33,8 @@
 };
 
 /* ListWidget */
-class ListWidget : public Widget, public CommandReceiver {
+class ListWidget : public Widget, public CommandReceiver, public CommandSender {
+	typedef ScummVM::StringList StringList;
 protected:
 	StringList		_list;
 	bool			_editable;
@@ -48,15 +49,18 @@
 	ListWidget(Dialog *boss, int x, int y, int w, int h);
 	virtual ~ListWidget();
 	
-	void setList(const StringList& list)		{ _list = list; }
+	void setList(const StringList& list)		{ _list = list; scrollBarRecalc(); }
 	const StringList& getList()	const			{ return _list; }
 	int getSelected() const						{ return _selectedItem; }
+	const ScummVM::String& getSelectedString() const	{ return _list[_selectedItem]; }
 	void setNumberingMode(int numberingMode)	{ _numberingMode = numberingMode; }
 	
 	virtual void handleMouseDown(int x, int y, int button);
 	virtual void handleKeyDown(char key, int modifiers);
 	virtual void handleKeyUp(char key, int modifiers);
 	virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
+
+	void scrollBarRecalc();
 
 protected:
 	void drawWidget(bool hilite);

Index: ListWidget.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/ListWidget.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- ListWidget.cpp	18 Jul 2002 14:47:24 -0000	1.11
+++ ListWidget.cpp	18 Jul 2002 20:26:35 -0000	1.12
@@ -27,8 +27,13 @@
 
 /*
  * TODO:
- * - Allow escape to abort changes
- * - Add key repeat (for backspace, etc)
+ * - Abort changes when ESC is pressed or the selection changes
+ * - When the editing of a string is ended by return, we might consider sending
+ *   a message. Return means that the edit was confirmed. Hence the SaveDialog
+ *   could immediatly do the save in a trivial fashion.
+ * - Handle double clicks: either start editing of the selected item, or
+ *   send a cmd to our target (i.e. as specified via setCmd or setDoubleCmd)
+ *   This will allow a double click in the load dialog to immediatly load the game
  */
 
 
@@ -37,13 +42,13 @@
 
 
 ListWidget::ListWidget(Dialog *boss, int x, int y, int w, int h)
-	: Widget(boss, x, y, w - kScrollBarWidth, h)
+	: Widget(boss, x, y, w - kScrollBarWidth, h), CommandSender(boss)
 {
 	_flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS | WIDGET_WANT_TICKLE;
 	_type = kListWidget;
 	_numberingMode = kListNumberingOne;
 	_entriesPerPage = (_h - 4) / LINE_HEIGHT;
-	_currentPos = 3;
+	_currentPos = 0;
 	_selectedItem = -1;
 	_scrollBar = new ScrollBarWidget(boss, _x + _w, _y, kScrollBarWidth, _h);
 	_scrollBar->setTarget(this);
@@ -53,38 +58,20 @@
 	_editable = true;
 
 	_editMode = false;
+}
 
-	// FIXME - fill in dummy data for now
-	_list.push_back("A simple game?");
-	_list.push_back("This space for rent!");
-	_list.push_back("To be or not to be...");
-	_list.push_back("It's not easy come up with dummy text :-)");
-	_list.push_back("Foo bar baz");
-	_list.push_back("Empty slots follow:");
-	_list.push_back("");
-	_list.push_back("");
-	_list.push_back("Now again a filled slot");
-	_list.push_back("We need some more text!");
-	_list.push_back("Because only this way...");
-	_list.push_back("...can you see the scrollbar...");
-	_list.push_back("...and verify that it works!");
-	_list.push_back("One");
-	_list.push_back("Two");
-	_list.push_back("Three");
-	_list.push_back("Four");
-	_list.push_back("The End");
-
+ListWidget::~ListWidget()
+{
+}
 
+void ListWidget::scrollBarRecalc()
+{
 	_scrollBar->_numEntries = _list.size();
 	_scrollBar->_entriesPerPage = _entriesPerPage;
 	_scrollBar->_currentPos = _currentPos;
 	_scrollBar->recalc();
 }
 
-ListWidget::~ListWidget()
-{
-}
-
 void ListWidget::handleMouseDown(int x, int y, int button)
 {
 	int oldSelectedItem = _selectedItem;
@@ -220,19 +207,19 @@
 
 void ListWidget::drawWidget(bool hilite)
 {
-	NewGui	*gui = _boss->getGui();
-	int		i, pos;
-	String	buffer;
+	NewGui			*gui = _boss->getGui();
+	int				i, pos, len = _list.size();
+	ScummVM::String	buffer;
 
 	// Draw the list items
-	// FIXME - this is just a temporary demo hack
-	for (i = 0, pos = _currentPos; i < _entriesPerPage; i++, pos++) {
+	for (i = 0, pos = _currentPos; i < _entriesPerPage && pos < len; i++, pos++) {
 		if (_numberingMode == kListNumberingZero || _numberingMode == kListNumberingOne) {
 			char temp[10];
 			sprintf(temp, "%2d. ", (pos + _numberingMode));
 			buffer = temp;
 		} else
 			buffer = "";
+
 		buffer += _list[pos];
 	
 		gui->drawString(buffer, _x+5, _y+2 + LINE_HEIGHT * i, _w - 10,





More information about the Scummvm-git-logs mailing list