mirror of https://github.com/stella-emu/stella.git
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
This commit is contained in:
parent
86b6191570
commit
b9fece9cde
|
@ -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.
|
||||
|
||||
|
|
|
@ -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:
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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 = "");
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
|
|
@ -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<Entry> myArray;
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue