From b9fece9cde889cd405d33f9fa51e50a291b9d057 Mon Sep 17 00:00:00 2001 From: stephena Date: Thu, 2 May 2013 17:06:36 +0000 Subject: [PATCH] More work on BrowserWidget, and further cleanup of the enum's in various GUI code. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2714 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- Changes.txt | 4 ++++ src/gui/BrowserDialog.cxx | 30 ++++++++++++++++++++++++++---- src/gui/BrowserDialog.hxx | 9 ++++++--- src/gui/EditTextWidget.hxx | 2 +- src/gui/EditableWidget.cxx | 23 +++++++++++------------ src/gui/EditableWidget.hxx | 13 +++++++------ src/gui/GameList.cxx | 8 +------- src/gui/GameList.hxx | 36 ++++++++++++++++++++---------------- src/gui/InputTextDialog.cxx | 6 +++--- src/gui/LauncherDialog.cxx | 4 ++-- src/gui/ListWidget.cxx | 11 +++++++++-- src/gui/ListWidget.hxx | 4 ++-- 12 files changed, 92 insertions(+), 58 deletions(-) diff --git a/Changes.txt b/Changes.txt index adbd56b85..b5ee55cbb 100644 --- a/Changes.txt +++ b/Changes.txt @@ -40,6 +40,10 @@ - Fixed labelling in ROW directives; it wasn't accurately setting a label in the case where it occurred in the middle of the data. + * Fixed bug in Linux/OSX versions when starting Stella for the first + time; it was previously creating mislabeled directories to store + settings, snapshots, etc. + * Fixed redundant "New console created" message when entering the same ROM multiple times from the ROM launcher. diff --git a/src/gui/BrowserDialog.cxx b/src/gui/BrowserDialog.cxx index aac3178f1..24933d859 100644 --- a/src/gui/BrowserDialog.cxx +++ b/src/gui/BrowserDialog.cxx @@ -28,6 +28,7 @@ #include "GameList.hxx" #include "GuiObject.hxx" #include "OSystem.hxx" +#include "EditTextWidget.hxx" #include "StringListWidget.hxx" #include "Widget.hxx" @@ -55,7 +56,8 @@ BrowserDialog::BrowserDialog(GuiObject* boss, const GUI::Font& font, const int lineHeight = font.getLineHeight(), buttonWidth = font.getStringWidth("Defaults") + 20, - buttonHeight = font.getLineHeight() + 4; + buttonHeight = font.getLineHeight() + 4, + selectHeight = lineHeight + 8; int xpos, ypos; ButtonWidget* b; @@ -71,11 +73,21 @@ BrowserDialog::BrowserDialog(GuiObject* boss, const GUI::Font& font, "", kTextAlignLeft); // Add file list - ypos += lineHeight; - _fileList = new StringListWidget(this, font, xpos, ypos, - _w - 2 * xpos, _h - buttonHeight - ypos - 20); + ypos += lineHeight + 4; + _fileList = new StringListWidget(this, font, xpos, ypos, _w - 2 * xpos, + _h - selectHeight - buttonHeight - ypos - 20); _fileList->setEditable(false); + // Add currently selected item + ypos += _fileList->getHeight() + 4; + + _type = new StaticTextWidget(this, font, xpos, ypos, + font.getStringWidth("File: "), lineHeight, + "", kTextAlignCenter); + _selected = new EditTextWidget(this, font, xpos + _type->getWidth(), ypos, + _w - _type->getWidth() - 2 * xpos, lineHeight, ""); + _selected->setEditable(false); + // Buttons _goUpButton = new ButtonWidget(this, font, 10, _h - buttonHeight - 10, buttonWidth, buttonHeight, "Go up", kGoUpCmd); @@ -213,6 +225,16 @@ void BrowserDialog::handleCommand(CommandSender* sender, int cmd, updateListing(); break; + case ListWidget::kSelectionChangedCmd: + { + int item = _fileList->getSelected(); + if(item >= 0) + { + _selected->setEditString(_fileList->getSelectedString()); + } + break; + } + case ListWidget::kActivatedCmd: case ListWidget::kDoubleClickedCmd: { diff --git a/src/gui/BrowserDialog.hxx b/src/gui/BrowserDialog.hxx index 568a77983..e7800ec21 100644 --- a/src/gui/BrowserDialog.hxx +++ b/src/gui/BrowserDialog.hxx @@ -25,6 +25,7 @@ class GuiObject; class ButtonWidget; +class EditTextWidget; class StaticTextWidget; class StringListWidget; class GameList; @@ -38,9 +39,9 @@ class BrowserDialog : public Dialog, public CommandSender { public: enum ListMode { - kFileLoad, // File selector, no input from user - kFileSave, // File selector, filename changable by user - kDirectoryOpen // Directories only, no input from user + FileLoad, // File selector, no input from user + FileSave, // File selector, filename changable by user + DirectoryOpen // Directories only, no input from user }; public: @@ -69,6 +70,8 @@ class BrowserDialog : public Dialog, public CommandSender StringListWidget* _fileList; StaticTextWidget* _currentPath; StaticTextWidget* _title; + StaticTextWidget* _type; + EditTextWidget* _selected; ButtonWidget* _goUpButton; ButtonWidget* _basedirButton; diff --git a/src/gui/EditTextWidget.hxx b/src/gui/EditTextWidget.hxx index 5c78cdda3..1eecd7f9a 100644 --- a/src/gui/EditTextWidget.hxx +++ b/src/gui/EditTextWidget.hxx @@ -32,7 +32,7 @@ class EditTextWidget : public EditableWidget { public: EditTextWidget(GuiObject* boss, const GUI::Font& font, - int x, int y, int w, int h, const string& text); + int x, int y, int w, int h, const string& text = ""); void setEditString(const string& str, bool changed = false); diff --git a/src/gui/EditableWidget.cxx b/src/gui/EditableWidget.cxx index c0d87a3bc..0e02b7e0c 100644 --- a/src/gui/EditableWidget.cxx +++ b/src/gui/EditableWidget.cxx @@ -23,7 +23,6 @@ #include "Dialog.hxx" #include "EditableWidget.hxx" - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - EditableWidget::EditableWidget(GuiObject* boss, const GUI::Font& font, int x, int y, int w, int h, const string& str) @@ -108,24 +107,24 @@ bool EditableWidget::handleKeyDown(StellaKey key, StellaMod mod, char ascii) case KBDK_RETURN: // confirm edit and exit editmode endEditMode(); - sendCommand(kEditAcceptCmd, 0, _id); + sendCommand(EditableWidget::kAcceptCmd, 0, _id); dirty = true; break; case KBDK_ESCAPE: abortEditMode(); - sendCommand(kEditCancelCmd, 0, _id); + sendCommand(EditableWidget::kCancelCmd, 0, _id); dirty = true; break; case KBDK_BACKSPACE: dirty = killChar(-1); - if(dirty) sendCommand(kEditChangedCmd, ascii, _id); + if(dirty) sendCommand(EditableWidget::kChangedCmd, ascii, _id); break; case KBDK_DELETE: dirty = killChar(+1); - if(dirty) sendCommand(kEditChangedCmd, ascii, _id); + if(dirty) sendCommand(EditableWidget::kChangedCmd, ascii, _id); break; case KBDK_LEFT: @@ -158,7 +157,7 @@ bool EditableWidget::handleKeyDown(StellaKey key, StellaMod mod, char ascii) else if (tryInsertChar(ascii, _caretPos)) { _caretPos++; - sendCommand(kEditChangedCmd, ascii, _id); + sendCommand(EditableWidget::kChangedCmd, ascii, _id); dirty = true; } else @@ -265,7 +264,7 @@ bool EditableWidget::specialKeys(StellaKey key, char ascii) case KBDK_c: copySelectedText(); - if(handled) sendCommand(kEditChangedCmd, ascii, _id); + if(handled) sendCommand(EditableWidget::kChangedCmd, ascii, _id); break; case KBDK_e: @@ -274,27 +273,27 @@ bool EditableWidget::specialKeys(StellaKey key, char ascii) case KBDK_d: handled = killChar(+1); - if(handled) sendCommand(kEditChangedCmd, ascii, _id); + if(handled) sendCommand(EditableWidget::kChangedCmd, ascii, _id); break; case KBDK_k: handled = killLine(+1); - if(handled) sendCommand(kEditChangedCmd, ascii, _id); + if(handled) sendCommand(EditableWidget::kChangedCmd, ascii, _id); break; case KBDK_u: handled = killLine(-1); - if(handled) sendCommand(kEditChangedCmd, ascii, _id); + if(handled) sendCommand(EditableWidget::kChangedCmd, ascii, _id); break; case KBDK_v: pasteSelectedText(); - if(handled) sendCommand(kEditChangedCmd, ascii, _id); + if(handled) sendCommand(EditableWidget::kChangedCmd, ascii, _id); break; case KBDK_w: handled = killLastWord(); - if(handled) sendCommand(kEditChangedCmd, ascii, _id); + if(handled) sendCommand(EditableWidget::kChangedCmd, ascii, _id); break; case KBDK_LEFT: diff --git a/src/gui/EditableWidget.hxx b/src/gui/EditableWidget.hxx index c29873998..74b19c034 100644 --- a/src/gui/EditableWidget.hxx +++ b/src/gui/EditableWidget.hxx @@ -26,18 +26,19 @@ #include "Widget.hxx" #include "Rect.hxx" -enum { - kEditAcceptCmd = 'EDac', - kEditCancelCmd = 'EDcl', - kEditChangedCmd = 'EDch' -}; - /** * Base class for widgets which need to edit text, like ListWidget and * EditTextWidget. */ class EditableWidget : public Widget, public CommandSender { + public: + enum { + kAcceptCmd = 'EDac', + kCancelCmd = 'EDcl', + kChangedCmd = 'EDch' + }; + public: EditableWidget(GuiObject *boss, const GUI::Font& font, int x, int y, int w, int h, const string& str = ""); diff --git a/src/gui/GameList.cxx b/src/gui/GameList.cxx index 73be2f4cc..9af23c5d2 100644 --- a/src/gui/GameList.cxx +++ b/src/gui/GameList.cxx @@ -40,13 +40,7 @@ GameList::~GameList() void GameList::appendGame(const string& name, const string& path, const string& md5, bool isDir) { - Entry g; - g._name = name; - g._path = path; - g._md5 = md5; - g._isdir = isDir; - - myArray.push_back(g); + myArray.push_back(Entry(name, path, md5, isDir)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/gui/GameList.hxx b/src/gui/GameList.hxx index c3f62722b..b01e1a872 100644 --- a/src/gui/GameList.hxx +++ b/src/gui/GameList.hxx @@ -35,16 +35,16 @@ class GameList GameList(); ~GameList(); - const string& name(int i) const - { return i < (int)myArray.size() ? myArray[i]._name : EmptyString; } - const string& path(int i) const - { return i < (int)myArray.size() ? myArray[i]._path : EmptyString; } - const string& md5(int i) const - { return i < (int)myArray.size() ? myArray[i]._md5 : EmptyString; } - const bool isDir(int i) const - { return i < (int)myArray.size() ? myArray[i]._isdir: false; } + const string& name(uInt32 i) const + { return i < myArray.size() ? myArray[i]._name : EmptyString; } + const string& path(uInt32 i) const + { return i < myArray.size() ? myArray[i]._path : EmptyString; } + const string& md5(uInt32 i) const + { return i < myArray.size() ? myArray[i]._md5 : EmptyString; } + const bool isDir(uInt32 i) const + { return i < myArray.size() ? myArray[i]._isdir: false; } - void setMd5(int i, const string& md5) + void setMd5(uInt32 i, const string& md5) { myArray[i]._md5 = md5; } int size() const { return myArray.size(); } @@ -55,14 +55,18 @@ class GameList void sortByName(); private: - class Entry { - public: - string _name; - string _path; - string _md5; - bool _isdir; + struct Entry { + string _name; + string _path; + string _md5; + bool _isdir; - bool operator < (const Entry& a) const; + Entry(string name, string path, string md5, bool isdir) + { + _name = name; _path = path; _md5 = md5; _isdir = isdir; + } + + bool operator < (const Entry& a) const; }; vector myArray; }; diff --git a/src/gui/InputTextDialog.cxx b/src/gui/InputTextDialog.cxx index 16cd747f7..cdd8e5d44 100644 --- a/src/gui/InputTextDialog.cxx +++ b/src/gui/InputTextDialog.cxx @@ -173,7 +173,7 @@ void InputTextDialog::handleCommand(CommandSender* sender, int cmd, switch(cmd) { case kOKCmd: - case kEditAcceptCmd: + case EditableWidget::kAcceptCmd: { // Send a signal to the calling class that a selection has been made // Since we aren't derived from a widget, we don't have a 'data' or 'id' @@ -185,7 +185,7 @@ void InputTextDialog::handleCommand(CommandSender* sender, int cmd, break; } - case kEditChangedCmd: + case EditableWidget::kChangedCmd: // Erase the invalid message once editing is restarted if(myErrorFlag) { @@ -194,7 +194,7 @@ void InputTextDialog::handleCommand(CommandSender* sender, int cmd, } break; - case kEditCancelCmd: + case EditableWidget::kCancelCmd: Dialog::handleCommand(sender, kCloseCmd, data, id); break; diff --git a/src/gui/LauncherDialog.cxx b/src/gui/LauncherDialog.cxx index 8ee2991a7..8613e995c 100644 --- a/src/gui/LauncherDialog.cxx +++ b/src/gui/LauncherDialog.cxx @@ -623,8 +623,8 @@ void LauncherDialog::handleCommand(CommandSender* sender, int cmd, handleContextMenu(); break; - case kEditAcceptCmd: - case kEditChangedCmd: + case EditableWidget::kAcceptCmd: + case EditableWidget::kChangedCmd: // The updateListing() method knows what to do when the text changes updateListing(); break; diff --git a/src/gui/ListWidget.cxx b/src/gui/ListWidget.cxx index 46c8c8e90..6105cb36f 100644 --- a/src/gui/ListWidget.cxx +++ b/src/gui/ListWidget.cxx @@ -111,6 +111,13 @@ void ListWidget::setHighlighted(int item) } } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +const string& ListWidget::getSelectedString() const +{ + return (_selectedItem >= 0 && _selectedItem < (int)_list.size()) + ? _list[_selectedItem] : EmptyString; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void ListWidget::scrollTo(int item) { @@ -166,8 +173,8 @@ void ListWidget::handleMouseDown(int x, int y, int button, int clickCount) // First check whether the selection changed int newSelectedItem; newSelectedItem = findItem(x, y); - if (newSelectedItem > (int)_list.size() - 1) - newSelectedItem = -1; + if (newSelectedItem >= (int)_list.size()) + return; if (_selectedItem != newSelectedItem) { diff --git a/src/gui/ListWidget.hxx b/src/gui/ListWidget.hxx index db306f0cc..eb41e1020 100644 --- a/src/gui/ListWidget.hxx +++ b/src/gui/ListWidget.hxx @@ -60,8 +60,8 @@ class ListWidget : public EditableWidget int getHighlighted() const { return _highlightedItem; } void setHighlighted(int item); - const StringList& getList() const { return _list; } - const string& getSelectedString() const { return _list[_selectedItem]; } + const StringList& getList() const { return _list; } + const string& getSelectedString() const; void scrollTo(int item);