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
|
- Fixed labelling in ROW directives; it wasn't accurately setting
|
||||||
a label in the case where it occurred in the middle of the data.
|
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
|
* Fixed redundant "New console created" message when entering the same
|
||||||
ROM multiple times from the ROM launcher.
|
ROM multiple times from the ROM launcher.
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include "GameList.hxx"
|
#include "GameList.hxx"
|
||||||
#include "GuiObject.hxx"
|
#include "GuiObject.hxx"
|
||||||
#include "OSystem.hxx"
|
#include "OSystem.hxx"
|
||||||
|
#include "EditTextWidget.hxx"
|
||||||
#include "StringListWidget.hxx"
|
#include "StringListWidget.hxx"
|
||||||
#include "Widget.hxx"
|
#include "Widget.hxx"
|
||||||
|
|
||||||
|
@ -55,7 +56,8 @@ BrowserDialog::BrowserDialog(GuiObject* boss, const GUI::Font& font,
|
||||||
|
|
||||||
const int lineHeight = font.getLineHeight(),
|
const int lineHeight = font.getLineHeight(),
|
||||||
buttonWidth = font.getStringWidth("Defaults") + 20,
|
buttonWidth = font.getStringWidth("Defaults") + 20,
|
||||||
buttonHeight = font.getLineHeight() + 4;
|
buttonHeight = font.getLineHeight() + 4,
|
||||||
|
selectHeight = lineHeight + 8;
|
||||||
int xpos, ypos;
|
int xpos, ypos;
|
||||||
ButtonWidget* b;
|
ButtonWidget* b;
|
||||||
|
|
||||||
|
@ -71,11 +73,21 @@ BrowserDialog::BrowserDialog(GuiObject* boss, const GUI::Font& font,
|
||||||
"", kTextAlignLeft);
|
"", kTextAlignLeft);
|
||||||
|
|
||||||
// Add file list
|
// Add file list
|
||||||
ypos += lineHeight;
|
ypos += lineHeight + 4;
|
||||||
_fileList = new StringListWidget(this, font, xpos, ypos,
|
_fileList = new StringListWidget(this, font, xpos, ypos, _w - 2 * xpos,
|
||||||
_w - 2 * xpos, _h - buttonHeight - ypos - 20);
|
_h - selectHeight - buttonHeight - ypos - 20);
|
||||||
_fileList->setEditable(false);
|
_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
|
// Buttons
|
||||||
_goUpButton = new ButtonWidget(this, font, 10, _h - buttonHeight - 10,
|
_goUpButton = new ButtonWidget(this, font, 10, _h - buttonHeight - 10,
|
||||||
buttonWidth, buttonHeight, "Go up", kGoUpCmd);
|
buttonWidth, buttonHeight, "Go up", kGoUpCmd);
|
||||||
|
@ -213,6 +225,16 @@ void BrowserDialog::handleCommand(CommandSender* sender, int cmd,
|
||||||
updateListing();
|
updateListing();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case ListWidget::kSelectionChangedCmd:
|
||||||
|
{
|
||||||
|
int item = _fileList->getSelected();
|
||||||
|
if(item >= 0)
|
||||||
|
{
|
||||||
|
_selected->setEditString(_fileList->getSelectedString());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case ListWidget::kActivatedCmd:
|
case ListWidget::kActivatedCmd:
|
||||||
case ListWidget::kDoubleClickedCmd:
|
case ListWidget::kDoubleClickedCmd:
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
class GuiObject;
|
class GuiObject;
|
||||||
class ButtonWidget;
|
class ButtonWidget;
|
||||||
|
class EditTextWidget;
|
||||||
class StaticTextWidget;
|
class StaticTextWidget;
|
||||||
class StringListWidget;
|
class StringListWidget;
|
||||||
class GameList;
|
class GameList;
|
||||||
|
@ -38,9 +39,9 @@ class BrowserDialog : public Dialog, public CommandSender
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum ListMode {
|
enum ListMode {
|
||||||
kFileLoad, // File selector, no input from user
|
FileLoad, // File selector, no input from user
|
||||||
kFileSave, // File selector, filename changable by user
|
FileSave, // File selector, filename changable by user
|
||||||
kDirectoryOpen // Directories only, no input from user
|
DirectoryOpen // Directories only, no input from user
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -69,6 +70,8 @@ class BrowserDialog : public Dialog, public CommandSender
|
||||||
StringListWidget* _fileList;
|
StringListWidget* _fileList;
|
||||||
StaticTextWidget* _currentPath;
|
StaticTextWidget* _currentPath;
|
||||||
StaticTextWidget* _title;
|
StaticTextWidget* _title;
|
||||||
|
StaticTextWidget* _type;
|
||||||
|
EditTextWidget* _selected;
|
||||||
ButtonWidget* _goUpButton;
|
ButtonWidget* _goUpButton;
|
||||||
ButtonWidget* _basedirButton;
|
ButtonWidget* _basedirButton;
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ class EditTextWidget : public EditableWidget
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
EditTextWidget(GuiObject* boss, const GUI::Font& font,
|
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);
|
void setEditString(const string& str, bool changed = false);
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
#include "Dialog.hxx"
|
#include "Dialog.hxx"
|
||||||
#include "EditableWidget.hxx"
|
#include "EditableWidget.hxx"
|
||||||
|
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
EditableWidget::EditableWidget(GuiObject* boss, const GUI::Font& font,
|
EditableWidget::EditableWidget(GuiObject* boss, const GUI::Font& font,
|
||||||
int x, int y, int w, int h, const string& str)
|
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:
|
case KBDK_RETURN:
|
||||||
// confirm edit and exit editmode
|
// confirm edit and exit editmode
|
||||||
endEditMode();
|
endEditMode();
|
||||||
sendCommand(kEditAcceptCmd, 0, _id);
|
sendCommand(EditableWidget::kAcceptCmd, 0, _id);
|
||||||
dirty = true;
|
dirty = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KBDK_ESCAPE:
|
case KBDK_ESCAPE:
|
||||||
abortEditMode();
|
abortEditMode();
|
||||||
sendCommand(kEditCancelCmd, 0, _id);
|
sendCommand(EditableWidget::kCancelCmd, 0, _id);
|
||||||
dirty = true;
|
dirty = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KBDK_BACKSPACE:
|
case KBDK_BACKSPACE:
|
||||||
dirty = killChar(-1);
|
dirty = killChar(-1);
|
||||||
if(dirty) sendCommand(kEditChangedCmd, ascii, _id);
|
if(dirty) sendCommand(EditableWidget::kChangedCmd, ascii, _id);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KBDK_DELETE:
|
case KBDK_DELETE:
|
||||||
dirty = killChar(+1);
|
dirty = killChar(+1);
|
||||||
if(dirty) sendCommand(kEditChangedCmd, ascii, _id);
|
if(dirty) sendCommand(EditableWidget::kChangedCmd, ascii, _id);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KBDK_LEFT:
|
case KBDK_LEFT:
|
||||||
|
@ -158,7 +157,7 @@ bool EditableWidget::handleKeyDown(StellaKey key, StellaMod mod, char ascii)
|
||||||
else if (tryInsertChar(ascii, _caretPos))
|
else if (tryInsertChar(ascii, _caretPos))
|
||||||
{
|
{
|
||||||
_caretPos++;
|
_caretPos++;
|
||||||
sendCommand(kEditChangedCmd, ascii, _id);
|
sendCommand(EditableWidget::kChangedCmd, ascii, _id);
|
||||||
dirty = true;
|
dirty = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -265,7 +264,7 @@ bool EditableWidget::specialKeys(StellaKey key, char ascii)
|
||||||
|
|
||||||
case KBDK_c:
|
case KBDK_c:
|
||||||
copySelectedText();
|
copySelectedText();
|
||||||
if(handled) sendCommand(kEditChangedCmd, ascii, _id);
|
if(handled) sendCommand(EditableWidget::kChangedCmd, ascii, _id);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KBDK_e:
|
case KBDK_e:
|
||||||
|
@ -274,27 +273,27 @@ bool EditableWidget::specialKeys(StellaKey key, char ascii)
|
||||||
|
|
||||||
case KBDK_d:
|
case KBDK_d:
|
||||||
handled = killChar(+1);
|
handled = killChar(+1);
|
||||||
if(handled) sendCommand(kEditChangedCmd, ascii, _id);
|
if(handled) sendCommand(EditableWidget::kChangedCmd, ascii, _id);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KBDK_k:
|
case KBDK_k:
|
||||||
handled = killLine(+1);
|
handled = killLine(+1);
|
||||||
if(handled) sendCommand(kEditChangedCmd, ascii, _id);
|
if(handled) sendCommand(EditableWidget::kChangedCmd, ascii, _id);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KBDK_u:
|
case KBDK_u:
|
||||||
handled = killLine(-1);
|
handled = killLine(-1);
|
||||||
if(handled) sendCommand(kEditChangedCmd, ascii, _id);
|
if(handled) sendCommand(EditableWidget::kChangedCmd, ascii, _id);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KBDK_v:
|
case KBDK_v:
|
||||||
pasteSelectedText();
|
pasteSelectedText();
|
||||||
if(handled) sendCommand(kEditChangedCmd, ascii, _id);
|
if(handled) sendCommand(EditableWidget::kChangedCmd, ascii, _id);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KBDK_w:
|
case KBDK_w:
|
||||||
handled = killLastWord();
|
handled = killLastWord();
|
||||||
if(handled) sendCommand(kEditChangedCmd, ascii, _id);
|
if(handled) sendCommand(EditableWidget::kChangedCmd, ascii, _id);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KBDK_LEFT:
|
case KBDK_LEFT:
|
||||||
|
|
|
@ -26,18 +26,19 @@
|
||||||
#include "Widget.hxx"
|
#include "Widget.hxx"
|
||||||
#include "Rect.hxx"
|
#include "Rect.hxx"
|
||||||
|
|
||||||
enum {
|
|
||||||
kEditAcceptCmd = 'EDac',
|
|
||||||
kEditCancelCmd = 'EDcl',
|
|
||||||
kEditChangedCmd = 'EDch'
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for widgets which need to edit text, like ListWidget and
|
* Base class for widgets which need to edit text, like ListWidget and
|
||||||
* EditTextWidget.
|
* EditTextWidget.
|
||||||
*/
|
*/
|
||||||
class EditableWidget : public Widget, public CommandSender
|
class EditableWidget : public Widget, public CommandSender
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
enum {
|
||||||
|
kAcceptCmd = 'EDac',
|
||||||
|
kCancelCmd = 'EDcl',
|
||||||
|
kChangedCmd = 'EDch'
|
||||||
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
EditableWidget(GuiObject *boss, const GUI::Font& font,
|
EditableWidget(GuiObject *boss, const GUI::Font& font,
|
||||||
int x, int y, int w, int h, const string& str = "");
|
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,
|
void GameList::appendGame(const string& name, const string& path,
|
||||||
const string& md5, bool isDir)
|
const string& md5, bool isDir)
|
||||||
{
|
{
|
||||||
Entry g;
|
myArray.push_back(Entry(name, path, md5, isDir));
|
||||||
g._name = name;
|
|
||||||
g._path = path;
|
|
||||||
g._md5 = md5;
|
|
||||||
g._isdir = isDir;
|
|
||||||
|
|
||||||
myArray.push_back(g);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
|
@ -35,16 +35,16 @@ class GameList
|
||||||
GameList();
|
GameList();
|
||||||
~GameList();
|
~GameList();
|
||||||
|
|
||||||
const string& name(int i) const
|
const string& name(uInt32 i) const
|
||||||
{ return i < (int)myArray.size() ? myArray[i]._name : EmptyString; }
|
{ return i < myArray.size() ? myArray[i]._name : EmptyString; }
|
||||||
const string& path(int i) const
|
const string& path(uInt32 i) const
|
||||||
{ return i < (int)myArray.size() ? myArray[i]._path : EmptyString; }
|
{ return i < myArray.size() ? myArray[i]._path : EmptyString; }
|
||||||
const string& md5(int i) const
|
const string& md5(uInt32 i) const
|
||||||
{ return i < (int)myArray.size() ? myArray[i]._md5 : EmptyString; }
|
{ return i < myArray.size() ? myArray[i]._md5 : EmptyString; }
|
||||||
const bool isDir(int i) const
|
const bool isDir(uInt32 i) const
|
||||||
{ return i < (int)myArray.size() ? myArray[i]._isdir: false; }
|
{ 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; }
|
{ myArray[i]._md5 = md5; }
|
||||||
|
|
||||||
int size() const { return myArray.size(); }
|
int size() const { return myArray.size(); }
|
||||||
|
@ -55,14 +55,18 @@ class GameList
|
||||||
void sortByName();
|
void sortByName();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class Entry {
|
struct Entry {
|
||||||
public:
|
string _name;
|
||||||
string _name;
|
string _path;
|
||||||
string _path;
|
string _md5;
|
||||||
string _md5;
|
bool _isdir;
|
||||||
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;
|
vector<Entry> myArray;
|
||||||
};
|
};
|
||||||
|
|
|
@ -173,7 +173,7 @@ void InputTextDialog::handleCommand(CommandSender* sender, int cmd,
|
||||||
switch(cmd)
|
switch(cmd)
|
||||||
{
|
{
|
||||||
case kOKCmd:
|
case kOKCmd:
|
||||||
case kEditAcceptCmd:
|
case EditableWidget::kAcceptCmd:
|
||||||
{
|
{
|
||||||
// Send a signal to the calling class that a selection has been made
|
// 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'
|
// 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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case kEditChangedCmd:
|
case EditableWidget::kChangedCmd:
|
||||||
// Erase the invalid message once editing is restarted
|
// Erase the invalid message once editing is restarted
|
||||||
if(myErrorFlag)
|
if(myErrorFlag)
|
||||||
{
|
{
|
||||||
|
@ -194,7 +194,7 @@ void InputTextDialog::handleCommand(CommandSender* sender, int cmd,
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kEditCancelCmd:
|
case EditableWidget::kCancelCmd:
|
||||||
Dialog::handleCommand(sender, kCloseCmd, data, id);
|
Dialog::handleCommand(sender, kCloseCmd, data, id);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -623,8 +623,8 @@ void LauncherDialog::handleCommand(CommandSender* sender, int cmd,
|
||||||
handleContextMenu();
|
handleContextMenu();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kEditAcceptCmd:
|
case EditableWidget::kAcceptCmd:
|
||||||
case kEditChangedCmd:
|
case EditableWidget::kChangedCmd:
|
||||||
// The updateListing() method knows what to do when the text changes
|
// The updateListing() method knows what to do when the text changes
|
||||||
updateListing();
|
updateListing();
|
||||||
break;
|
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)
|
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
|
// First check whether the selection changed
|
||||||
int newSelectedItem;
|
int newSelectedItem;
|
||||||
newSelectedItem = findItem(x, y);
|
newSelectedItem = findItem(x, y);
|
||||||
if (newSelectedItem > (int)_list.size() - 1)
|
if (newSelectedItem >= (int)_list.size())
|
||||||
newSelectedItem = -1;
|
return;
|
||||||
|
|
||||||
if (_selectedItem != newSelectedItem)
|
if (_selectedItem != newSelectedItem)
|
||||||
{
|
{
|
||||||
|
|
|
@ -60,8 +60,8 @@ class ListWidget : public EditableWidget
|
||||||
int getHighlighted() const { return _highlightedItem; }
|
int getHighlighted() const { return _highlightedItem; }
|
||||||
void setHighlighted(int item);
|
void setHighlighted(int item);
|
||||||
|
|
||||||
const StringList& getList() const { return _list; }
|
const StringList& getList() const { return _list; }
|
||||||
const string& getSelectedString() const { return _list[_selectedItem]; }
|
const string& getSelectedString() const;
|
||||||
|
|
||||||
void scrollTo(int item);
|
void scrollTo(int item);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue