[Scummvm-cvs-logs] CVS: scummvm/gui ListWidget.cpp,1.11,1.12 ListWidget.h,1.9,1.10 browser.cpp,1.1,1.2 browser.h,1.1,1.2
Max Horn
fingolfin at users.sourceforge.net
Thu Nov 14 06:43:05 CET 2002
Update of /cvsroot/scummvm/scummvm/gui
In directory usw-pr-cvs1:/tmp/cvs-serv13099
Modified Files:
ListWidget.cpp ListWidget.h browser.cpp browser.h
Log Message:
Browser already can display files and navigate down; TOOD: go up, choose
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 23 Oct 2002 14:00:47 -0000 1.11
+++ ListWidget.cpp 14 Nov 2002 14:42:39 -0000 1.12
@@ -65,6 +65,20 @@
scrollBarRecalc();
}
+void ListWidget::scrollTo(int item)
+{
+ int size = _list.size();
+ if (item >= size)
+ item = size - 1;
+ else if (item < 0)
+ item = 0;
+
+ if (_currentPos != item) {
+ _currentPos = item;
+ scrollBarRecalc();
+ }
+}
+
void ListWidget::scrollBarRecalc()
{
_scrollBar->_numEntries = _list.size();
Index: ListWidget.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/ListWidget.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- ListWidget.h 23 Oct 2002 14:00:47 -0000 1.9
+++ ListWidget.h 14 Nov 2002 14:42:39 -0000 1.10
@@ -67,6 +67,7 @@
void setNumberingMode(int numberingMode) { _numberingMode = numberingMode; }
bool isEditable() const { return _editable; }
void setEditable(bool editable) { _editable = editable; }
+ void scrollTo(int item);
virtual void handleTickle();
virtual void handleMouseDown(int x, int y, int button, int clickCount);
Index: browser.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/browser.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- browser.cpp 14 Nov 2002 13:46:35 -0000 1.1
+++ browser.cpp 14 Nov 2002 14:42:39 -0000 1.2
@@ -30,22 +30,102 @@
* - others???
*/
+enum {
+ kChooseCmd = 'Chos',
+ kGoUpCmd = 'GoUp'
+};
+
BrowserDialog::BrowserDialog(NewGui *gui)
- : Dialog(gui, 50, 20, 320-2*50, 200-2*20)
+ : Dialog(gui, 40, 10, 320-2*40, 200-2*10)
{
// Headline - TODO: should be customizable during creation time
- new StaticTextWidget(this, 10, 10, _w-2*10, kLineHeight,
+ new StaticTextWidget(this, 10, 8, _w-2*10, kLineHeight,
"Select directory with game data", kTextAlignCenter);
+
+ // Current path - TODO: handle long paths ?
+ _currentPath =
+ new StaticTextWidget(this, 10, 20, _w-2*10, kLineHeight,
+ "DUMMY", kTextAlignLeft);
// Add file list
- _fileList = new ListWidget(this, 10, 20, _w-2*10, _h-20-24-10);
+ _fileList = new ListWidget(this, 10, 34, _w-2*10, _h-34-24-10);
+ _fileList->setNumberingMode(kListNumberingOff);
// Buttons
- addButton(10, _h-24, "Go up", kCloseCmd, 0);
+ addButton(10, _h-24, "Go up", kGoUpCmd, 0);
addButton(_w-2*(kButtonWidth+10), _h-24, "Cancel", kCloseCmd, 0);
- addButton(_w-(kButtonWidth+10), _h-24, "Choose", kCloseCmd, 0);
+ addButton(_w-(kButtonWidth+10), _h-24, "Choose", kChooseCmd, 0);
+}
- // TODO - populate list item, implement buttons, etc. etc.
- // TODO - will the choose button select the directory we are currrently in?!?
- // TODO - double clicking an item should traverse into that directory
+void BrowserDialog::open()
+{
+ // If no node has been set, or the last used one is now invalid,
+ // go back to the root/default dir.
+ if (_node == NULL || !_node->isValid()) {
+ delete _node;
+ _node = FilesystemNode::getRoot();
+ assert(_node != NULL);
+ }
+
+ // Alway refresh file list
+ updateListing();
+
+ // Call super implementation
+ Dialog::open();
+}
+
+void BrowserDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data)
+{
+ FilesystemNode *tmp;
+
+ switch (cmd) {
+ case kChooseCmd:
+ // If nothing is selected in the list widget, choose the current dir.
+ // Else, choose the dir that is selected.
+ // TODO
+ close();
+ break;
+ case kGoUpCmd:
+/*
+ tmp = _node->parent();
+ delete _node;
+ _node = tmp;
+ updateListing();
+*/
+ break;
+ case kListItemDoubleClickedCmd:
+ tmp = (*_nodeContent)[data].clone();
+ delete _node;
+ _node = tmp;
+ updateListing();
+ break;
+ default:
+ Dialog::handleCommand(sender, cmd, data);
+ }
+}
+
+void BrowserDialog::updateListing()
+{
+ assert(_node != NULL);
+
+ // Update the path display
+ _currentPath->setLabel(_node->path());
+
+ // Read in the data from the file system
+ delete _nodeContent;
+ _nodeContent = _node->listDir();
+ assert(_nodeContent != NULL);
+
+ // Populate the ListWidget
+ ScummVM::StringList list;
+ int size = _nodeContent->size();
+ for (int i = 0; i < size; i++) {
+ list.push_back((*_nodeContent)[i].displayName());
+ }
+ _fileList->setList(list);
+ _fileList->scrollTo(0);
+
+ // Finally, redraw
+ draw();
}
+
Index: browser.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/browser.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- browser.h 14 Nov 2002 13:46:35 -0000 1.1
+++ browser.h 14 Nov 2002 14:42:39 -0000 1.2
@@ -26,6 +26,8 @@
#include "common/list.h"
class ListWidget;
+class StaticTextWidget;
+
class FilesystemNode;
class FSList;
@@ -35,11 +37,16 @@
public:
BrowserDialog(NewGui *gui);
+ virtual void open();
+ virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
+
protected:
ListWidget *_fileList;
+ StaticTextWidget*_currentPath;
FilesystemNode *_node;
- FSList *_content;
+ FSList *_nodeContent;
+ void updateListing();
};
#endif
More information about the Scummvm-git-logs
mailing list