revamped LauncherDialog

added option to disable bottom buttons
This commit is contained in:
Thomas Jentzsch 2021-12-05 18:08:38 +01:00
parent 7485ee594d
commit 4462492be8
10 changed files with 977 additions and 490 deletions

View File

@ -155,6 +155,7 @@ Settings::Settings()
setPermanent("launcherroms", "true");
setPermanent("launchersubdirs", "false");
setPermanent("launcherextensions", "false");
setPermanent("launcherbuttons", "false");
setPermanent("romviewer", "1");
setPermanent("lastrom", "");
setPermanent("favorites", "true");
@ -601,6 +602,7 @@ void Settings::usage() const
<< " -launcherroms <1|0> Show only ROMs in the launcher (vs. all files)\n"
<< " -launchersubdirs <0|1> Show files from subdirectories too\n"
<< " -launcherextensions <0|1> Display file extensions in launcher\n"
<< " -launcherbuttons <0|1> Display bottom buttons in launcher\n"
<< " -favorites <0|1> Enable virtual favorite directories in launcher\n"
<< " -altsorting <0|1> Alternative sorting in virtual folders\n"
<< " -maxrecentroms <number> Number of ROMs tracked in 'Recently played'\n"

View File

@ -39,13 +39,20 @@ void FavoritesManager::load()
const string& serializedUser = mySettings.getString("_favoriteroms");
if(!serializedUser.empty())
{
const json& jUser = json::parse(serializedUser);
for(const auto& u : jUser)
try
{
const string& path = u.get<string>();
FilesystemNode node(path);
if(node.exists())
addUser(path);
const json& jUser = json::parse(serializedUser);
for (const auto& u : jUser)
{
const string& path = u.get<string>();
FilesystemNode node(path);
if (node.exists())
addUser(path);
}
}
catch (...)
{
cerr << "ERROR: FavoritesManager::load() '_favoriteroms' exception\n";
}
}
@ -56,13 +63,20 @@ void FavoritesManager::load()
const string& serializedRecent = mySettings.getString("_recentroms");
if(!serializedRecent.empty())
{
const json& jRecent = json::parse(serializedRecent);
for(const auto& r : jRecent)
try
{
const string& path = r.get<string>();
FilesystemNode node(path);
if(node.exists())
addRecent(path);
const json& jRecent = json::parse(serializedRecent);
for (const auto& r : jRecent)
{
const string& path = r.get<string>();
FilesystemNode node(path);
if (node.exists())
addRecent(path);
}
}
catch (...)
{
cerr << "ERROR: FavoritesManager::load() '_recentroms' exception\n";
}
}
}
@ -70,16 +84,23 @@ void FavoritesManager::load()
// Most Popular
myPopularMap.clear();
const string& serializedPopular = mySettings.getString("_popularroms");
if(!serializedPopular.empty())
if (!serializedPopular.empty())
{
const json& jPopular = json::parse(serializedPopular);
for(const auto& p : jPopular)
try
{
const string& path = p[0].get<string>();
const uInt32 count = p[1].get<uInt32>();
FilesystemNode node(path);
if(node.exists())
myPopularMap.emplace(path, count);
const json& jPopular = json::parse(serializedPopular);
for (const auto& p : jPopular)
{
const string& path = p[0].get<string>();
const uInt32 count = p[1].get<uInt32>();
FilesystemNode node(path);
if (node.exists())
myPopularMap.emplace(path, count);
}
}
catch (...)
{
cerr << "ERROR: FavoritesManager::load() '_popularroms' exception\n";
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -121,6 +121,10 @@ class LauncherDialog : public Dialog
void loadConfig() override;
void saveConfig() override;
void updateUI();
void addOptionWidgets(int& ypos, WidgetArray& wid);
void addPathWidgets(int& ypos, WidgetArray& wid);
void addRomWidgets(int& ypos, WidgetArray& wid);
void addButtonWidgets(int& ypos, WidgetArray& wid);
string getRomDir();
/**
@ -162,21 +166,23 @@ class LauncherDialog : public Dialog
void loadRom();
void loadRomInfo();
void handleFavoritesChanged();
void handleContextMenu();
void openSettings();
void openContextMenu(int x = -1, int y = -1);
void openGlobalProps();
void openHighScores();
void openWhatsNew();
void showOnlyROMs(bool state);
void toggleShowAll();
void toggleSubDirs();
void toggleShowAll(bool toggle = true);
void toggleSubDirs(bool toggle = true);
void gotoHomeDir();
void handleContextMenu();
void handleQuit();
void toggleExtensions();
void toggleSorting();
void handleFavoritesChanged();
void removeAllFavorites();
void removeAllPopular();
void removeAllRecent();
void openContextMenu(int x = -1, int y = -1);
void openGlobalProps();
void openSettings();
void openHighScores();
void openWhatsNew();
ContextMenu& contextMenu();
@ -187,17 +193,19 @@ class LauncherDialog : public Dialog
// automatically sized font for ROM info viewer
unique_ptr<GUI::Font> myROMInfoFont;
CheckboxWidget* myAllFiles{nullptr};
ButtonWidget* mySettingsButton{nullptr};
EditTextWidget* myPattern{nullptr};
CheckboxWidget* mySubDirs{nullptr};
ButtonWidget* myOnlyRomsButton{nullptr};
ButtonWidget* mySubDirsButton{nullptr};
StaticTextWidget* myRomCount{nullptr};
ButtonWidget* myHomeButton{nullptr};
ButtonWidget* myUpButton{nullptr};
EditTextWidget* myDir{nullptr};
ButtonWidget* myReloadButton{nullptr};
LauncherFileListWidget* myList{nullptr};
StaticTextWidget* myDirLabel{nullptr};
EditTextWidget* myDir{nullptr};
ButtonWidget* myHomeButton{nullptr};
ButtonWidget* myStartButton{nullptr};
ButtonWidget* myPrevDirButton{nullptr};
ButtonWidget* myOptionsButton{nullptr};
@ -213,6 +221,7 @@ class LauncherDialog : public Dialog
int mySelectedItem{0};
bool myShowOnlyROMs{false};
bool myIncludeSubDirs{false};
bool myUseMinimalUI{false};
bool myEventHandled{false};
bool myShortCount{false};
@ -226,6 +235,7 @@ class LauncherDialog : public Dialog
kOptionsCmd = 'OPTI',
kQuitCmd = 'QUIT',
kHomeDirCmd = 'homc', // goto Home directory
kReloadCmd = 'relc',
kRmAllFav = 'rmaf',
kRmAllPop = 'rmap',
kRmAllRec = 'rmar'

View File

@ -58,6 +58,9 @@ class LauncherFileListWidget : public FileListWidget
bool inUserDir() const { return myVirtualDir == user_name; }
bool inRecentDir() const { return myVirtualDir == recent_name; }
bool inPopularDir() const { return myVirtualDir == popular_name; }
bool isUserDir(const string& name) const { return name == user_name; }
bool isRecentDir(const string& name) const { return name == recent_name; }
bool isPopularDir(const string& name) const { return name == popular_name; }
private:
static const string user_name;

View File

@ -213,7 +213,7 @@ bool RomInfoWidget::loadPng(const string& filename)
// Scale surface to available image area
const Common::Rect& src = mySurface->srcRect();
float scale = std::min(float(myAvail.w) / src.w(), float(myAvail.h) / src.h()) *
const float scale = std::min(float(myAvail.w) / src.w(), float(myAvail.h) / src.h()) *
instance().frameBuffer().hidpiScaleFactor();
mySurface->setDstSize(uInt32(src.w() * scale), uInt32(src.h() * scale));
@ -241,10 +241,9 @@ void RomInfoWidget::handleMouseUp(int x, int y, MouseButton b, int clickCount)
void RomInfoWidget::drawWidget(bool hilite)
{
FBSurface& s = dialog().surface();
const int yoff = myAvail.h + 10;
const int yoff = myAvail.h + _font.getFontHeight() / 2;
s.fillRect(_x+2, _y+2, _w-4, _h-4, _bgcolor);
s.frameRect(_x, _y, _w, _h, kColor);
s.frameRect(_x, _y+yoff, _w, _h-yoff, kColor);
if(!myHaveProperties)
@ -257,8 +256,8 @@ void RomInfoWidget::drawWidget(bool hilite)
{
const Common::Rect& dst = mySurface->dstRect();
const uInt32 scale = instance().frameBuffer().hidpiScaleFactor();
uInt32 x = _x*scale + ((_w*scale - dst.w()) >> 1);
uInt32 y = _y*scale + ((yoff*scale - dst.h()) >> 1);
const uInt32 x = _x * scale + ((_w * scale - dst.w()) >> 1);
const uInt32 y = _y * scale + ((myAvail.h * scale - dst.h()) >> 1);
// Make sure when positioning the snapshot surface that we take
// the dialog surface position into account
@ -267,12 +266,13 @@ void RomInfoWidget::drawWidget(bool hilite)
}
else if(mySurfaceErrorMsg != "")
{
uInt32 x = _x + ((_w - _font.getStringWidth(mySurfaceErrorMsg)) >> 1);
uInt32 y = _y + ((yoff - _font.getLineHeight()) >> 1);
const uInt32 x = _x + ((_w - _font.getStringWidth(mySurfaceErrorMsg)) >> 1);
const uInt32 y = _y + ((yoff - _font.getLineHeight()) >> 1);
s.drawString(_font, mySurfaceErrorMsg, x, y, _w - 10, _textcolor);
}
int xpos = _x + 8, ypos = _y + yoff + 5;
const int xpos = _x + 8;
int ypos = _y + yoff + 5;
for(const auto& info : myRomInfo)
{
if(info.length() * _font.getMaxCharWidth() <= uInt64(_w - 16))

View File

@ -224,7 +224,7 @@ UIDialog::UIDialog(OSystem& osystem, DialogContainer& parent,
wid.push_back(myFollowLauncherWidget);
xpos = HBORDER;
ypos += VGAP * 4;
ypos += lineHeight + VGAP;
// Launcher font
pwidth = font.getStringWidth("2x (1000x760)");
@ -255,20 +255,27 @@ UIDialog::UIDialog(OSystem& osystem, DialogContainer& parent,
myLauncherHeightSlider->setMaxValue(ds.h);
myLauncherHeightSlider->setStepValue(10);
wid.push_back(myLauncherHeightSlider);
ypos += lineHeight + VGAP;
ypos = myLauncherFontPopup->getTop();
// Track favorites
ypos = myLauncherWidthSlider->getTop();
myFavoritesWidget = new CheckboxWidget(myTab, _font, xpos2, ypos + 2,
myFavoritesWidget = new CheckboxWidget(myTab, _font, xpos2, ypos + 1,
"Track favorites");
myFavoritesWidget->setToolTip("Check to enable favorites tracking and display.");
wid.push_back(myFavoritesWidget);
ypos += lineHeight + VGAP;
// Display launcher extensions
myLauncherExtensionsWidget = new CheckboxWidget(myTab, _font, xpos2, ypos + 2,
myLauncherExtensionsWidget = new CheckboxWidget(myTab, _font, xpos2, ypos + 1,
"Display file extensions");
wid.push_back(myLauncherExtensionsWidget);
ypos += lineHeight + VGAP;
// Display bottom buttons
myLauncherButtonsWidget = new CheckboxWidget(myTab, _font, xpos2, ypos + 1,
"Display bottom buttons");
myLauncherButtonsWidget->setToolTip("Check to enable bottom command buttons.");
wid.push_back(myLauncherButtonsWidget);
// ROM launcher info/snapshot viewer
ypos = myLauncherHeightSlider->getTop() + lineHeight + VGAP * 4;
@ -369,6 +376,7 @@ void UIDialog::loadConfig()
myFavoritesWidget->setState(settings.getBool("favorites"));
myLauncherExtensionsWidget->setState(settings.getBool("launcherextensions"));
myLauncherButtonsWidget->setState(settings.getBool("launcherbuttons"));
// ROM launcher info viewer
float zoom = instance().settings().getFloat("romviewer");
@ -457,6 +465,8 @@ void UIDialog::saveConfig()
settings.setValue("favorites", myFavoritesWidget->getState());
// Display launcher extensions
settings.setValue("launcherextensions", myLauncherExtensionsWidget->getState());
// Display bottom buttons
settings.setValue("launcherbuttons", myLauncherButtonsWidget->getState());
// ROM launcher info viewer
int w = myLauncherWidthSlider->getValue();
@ -543,6 +553,7 @@ void UIDialog::setDefaults()
myLauncherFontPopup->setSelected("medium", "");
myFavoritesWidget->setState(true);
myLauncherExtensionsWidget->setState(false);
myLauncherButtonsWidget->setState(false);
myRomViewerSize->setValue(35);
mySnapLoadPath->setText(instance().userDir().getShortPath());
myLauncherExitWidget->setState(false);

View File

@ -57,8 +57,9 @@ class UIDialog : public Dialog, public CommandSender
SliderWidget* myLauncherWidthSlider{nullptr};
SliderWidget* myLauncherHeightSlider{nullptr};
PopUpWidget* myLauncherFontPopup{nullptr};
CheckboxWidget* myLauncherExtensionsWidget{nullptr};
CheckboxWidget* myFavoritesWidget{nullptr};
CheckboxWidget* myLauncherExtensionsWidget{nullptr};
CheckboxWidget* myLauncherButtonsWidget{nullptr};
SliderWidget* myRomViewerSize{nullptr};
ButtonWidget* myOpenBrowserButton{nullptr};
EditTextWidget* mySnapLoadPath{nullptr};

View File

@ -662,11 +662,29 @@ ButtonWidget::ButtonWidget(GuiObject* boss, const GUI::Font& font,
: ButtonWidget(boss, font, x, y, w, h, "", cmd, repeat)
{
_useBitmap = true;
_useText = false;
_bitmap = bitmap;
_bmw = bmw;
_bmh = bmh;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ButtonWidget::ButtonWidget(GuiObject* boss, const GUI::Font& font,
int x, int y, int w, int h,
const uInt32* bitmap, int bmw, int bmh, int bmx,
const string& label,
int cmd, bool repeat)
: ButtonWidget(boss, font, x, y, w + bmx * 1.5 + font.getStringWidth(label), h,
label, cmd, repeat)
{
_useBitmap = true;
_bitmap = bitmap;
_bmw = bmw;
_bmh = bmh;
_bmx = bmx;
_align = TextAlign::Left;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void ButtonWidget::handleMouseEntered()
{
@ -736,15 +754,20 @@ void ButtonWidget::drawWidget(bool hilite)
s.frameRect(_x, _y, _w, _h, hilite && isEnabled() ? kBtnBorderColorHi : kBtnBorderColor);
if (!_useBitmap)
s.drawString(_font, _label, _x, _y + (_h - _lineHeight)/2 + 1, _w,
!isEnabled() ? _textcolorlo :
hilite ? _textcolorhi : _textcolor, _align);
else
s.drawBitmap(_bitmap, _x + (_w - _bmw) / 2, _y + (_h - _bmh) / 2,
int x = _x;
if(_useBitmap)
{
int xb = _useText ? _x + _bmx / 2 : _x + (_w - _bmw) / 2;
s.drawBitmap(_bitmap, xb, _y + (_h - _bmh) / 2,
!isEnabled() ? _textcolorlo :
hilite ? _textcolorhi : _textcolor,
_bmw, _bmh);
x = _x + _bmw + _bmx;
}
if(_useText)
s.drawString(_font, _label, x, _y + (_h - _lineHeight)/2 + 1, _w,
!isEnabled() ? _textcolorlo :
hilite ? _textcolorhi : _textcolor, _align);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -266,12 +266,15 @@ class ButtonWidget : public StaticTextWidget
int x, int y, int dw, int dh,
const uInt32* bitmap, int bmw, int bmh,
int cmd = 0, bool repeat = false);
ButtonWidget(GuiObject* boss, const GUI::Font& font,
int x, int y, int w, int h,
const uInt32* bitmap, int bmw, int bmh, int bmx,
const string& label,
int cmd = 0, bool repeat= false);
~ButtonWidget() override = default;
bool handleEvent(Event::Type event) override;
void setCmd(int cmd) { _cmd = cmd; }
int getCmd() const { return _cmd; }
/* Sets/changes the button's bitmap **/
void setBitmap(const uInt32* bitmap, int bmw, int bmh);
@ -286,9 +289,10 @@ class ButtonWidget : public StaticTextWidget
protected:
bool _repeat{false}; // button repeats
bool _useText{true};
bool _useBitmap{false};
const uInt32* _bitmap{nullptr};
int _bmw{0}, _bmh{0};
int _bmw{0}, _bmh{0}, _bmx{0};
private:
// Following constructors and assignment operators not supported