From 13c616c4c8ef22d135141424a7d4f10827026029 Mon Sep 17 00:00:00 2001 From: thrust26 Date: Fri, 17 Aug 2018 20:44:50 +0200 Subject: [PATCH] moved ROM viewer image path settings into UIDialog --- src/gui/EditTextWidget.cxx | 6 +-- src/gui/SnapshotDialog.cxx | 31 ++------------- src/gui/SnapshotDialog.hxx | 3 -- src/gui/UIDialog.cxx | 81 +++++++++++++++++++++++++++++++++++--- src/gui/UIDialog.hxx | 17 ++++++-- 5 files changed, 95 insertions(+), 43 deletions(-) diff --git a/src/gui/EditTextWidget.cxx b/src/gui/EditTextWidget.cxx index 42d64cd9f..58261304d 100644 --- a/src/gui/EditTextWidget.cxx +++ b/src/gui/EditTextWidget.cxx @@ -85,7 +85,7 @@ void EditTextWidget::drawWidget(bool hilite) // Highlight changes if(_changed && onTop) s.fillRect(_x, _y, _w, _h, kDbgChangedColor); - else if(!isEditable()) + else if(!isEditable() || !isEnabled()) s.fillRect(_x, _y, _w, _h, onTop ? kDlgColor : kBGColorLo); // Draw a thin frame around us. @@ -94,9 +94,9 @@ void EditTextWidget::drawWidget(bool hilite) // Draw the text adjustOffset(); s.drawString(_font, editString(), _x + 2, _y + 2, getEditRect().width(), - _changed && onTop + _changed && onTop && isEnabled() ? kDbgChangedTextColor - : onTop ? _textcolor : kColor, + : onTop && isEnabled() ? _textcolor : kColor, TextAlign::Left, -_editScrollOffset, false); // Draw the caret diff --git a/src/gui/SnapshotDialog.cxx b/src/gui/SnapshotDialog.cxx index c3590b04f..e02ba7c14 100644 --- a/src/gui/SnapshotDialog.cxx +++ b/src/gui/SnapshotDialog.cxx @@ -57,16 +57,6 @@ SnapshotDialog::SnapshotDialog(OSystem& osystem, DialogContainer& parent, _w - xpos - HBORDER, lineHeight, ""); wid.push_back(mySnapSavePath); - // Snapshot path (load files) - xpos = HBORDER; ypos += buttonHeight + V_GAP; - b = new ButtonWidget(this, font, xpos, ypos, buttonWidth, buttonHeight, - "Load path" + ELLIPSIS, kChooseSnapLoadDirCmd); - wid.push_back(b); - xpos += buttonWidth + 8; - mySnapLoadPath = new EditTextWidget(this, font, xpos, ypos + 1, - _w - xpos - HBORDER, lineHeight, ""); - wid.push_back(mySnapLoadPath); - // Snapshot naming xpos = HBORDER; ypos += buttonHeight + V_GAP * 4; fwidth = font.getStringWidth("10 seconds"); @@ -116,8 +106,7 @@ SnapshotDialog::~SnapshotDialog() void SnapshotDialog::loadConfig() { const Settings& settings = instance().settings(); - mySnapSavePath->setText(settings.getString("snapsavedir")); - mySnapLoadPath->setText(settings.getString("snaploaddir")); + mySnapSavePath->setText(settings.getString("snapsavedir")); mySnapInterval->setValue(instance().settings().getInt("ssinterval")); mySnapName->setState(instance().settings().getString("snapname") == "rom"); mySnapSingle->setState(settings.getBool("sssingle")); @@ -127,8 +116,7 @@ void SnapshotDialog::loadConfig() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void SnapshotDialog::saveConfig() { - instance().settings().setValue("snapsavedir", mySnapSavePath->getText()); - instance().settings().setValue("snaploaddir", mySnapLoadPath->getText()); + instance().settings().setValue("snapsavedir", mySnapSavePath->getText()); instance().settings().setValue("ssinterval", mySnapInterval->getValue()); instance().settings().setValue("snapname", mySnapName->getState() ? "rom" : "int"); instance().settings().setValue("sssingle", mySnapSingle->getState()); @@ -142,8 +130,7 @@ void SnapshotDialog::saveConfig() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void SnapshotDialog::setDefaults() { - mySnapSavePath->setText(instance().defaultSaveDir()); - mySnapLoadPath->setText(instance().defaultLoadDir()); + mySnapSavePath->setText(instance().defaultSaveDir()); mySnapInterval->setValue(2); mySnapName->setState(false); mySnapSingle->setState(false); @@ -173,22 +160,10 @@ void SnapshotDialog::handleCommand(CommandSender* sender, int cmd, BrowserDialog::Directories, kSnapSaveDirChosenCmd); break; - case kChooseSnapLoadDirCmd: - // This dialog is resizable under certain conditions, so we need - // to re-create it as necessary - createBrowser("Select snapshot load directory"); - myBrowser->show(mySnapLoadPath->getText(), - BrowserDialog::Directories, kSnapLoadDirChosenCmd); - break; - case kSnapSaveDirChosenCmd: mySnapSavePath->setText(myBrowser->getResult().getShortPath()); break; - case kSnapLoadDirChosenCmd: - mySnapLoadPath->setText(myBrowser->getResult().getShortPath()); - break; - case kSnapshotInterval: if(mySnapInterval->getValue() == 1) mySnapInterval->setValueUnit(" second"); diff --git a/src/gui/SnapshotDialog.hxx b/src/gui/SnapshotDialog.hxx index 4412deffc..861d3ec29 100644 --- a/src/gui/SnapshotDialog.hxx +++ b/src/gui/SnapshotDialog.hxx @@ -48,9 +48,7 @@ class SnapshotDialog : public Dialog private: enum { kChooseSnapSaveDirCmd = 'LOss', // snapshot dir (save files) - kChooseSnapLoadDirCmd = 'LOsl', // snapshot dir (load files) kSnapSaveDirChosenCmd = 'snsc', // snap chosen (save files) - kSnapLoadDirChosenCmd = 'snlc', // snap chosen (load files) kSnapshotInterval = 'SnIn' // snap chosen (load files) }; @@ -58,7 +56,6 @@ class SnapshotDialog : public Dialog // Config paths EditTextWidget* mySnapSavePath; - EditTextWidget* mySnapLoadPath; CheckboxWidget* mySnapName; SliderWidget* mySnapInterval; diff --git a/src/gui/UIDialog.cxx b/src/gui/UIDialog.cxx index c78cdfc52..a848f0ed0 100644 --- a/src/gui/UIDialog.cxx +++ b/src/gui/UIDialog.cxx @@ -16,6 +16,7 @@ //============================================================================ #include "bspf.hxx" +#include "BrowserDialog.hxx" #include "Dialog.hxx" #include "OSystem.hxx" #include "FrameBuffer.hxx" @@ -23,6 +24,7 @@ #include "ListWidget.hxx" #include "PopUpWidget.hxx" #include "ScrollBarWidget.hxx" +#include "EditTextWidget.hxx" #include "Settings.hxx" #include "TabWidget.hxx" #include "Widget.hxx" @@ -35,15 +37,19 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - UIDialog::UIDialog(OSystem& osystem, DialogContainer& parent, const GUI::Font& font) - : Dialog(osystem, parent, font, "User interface settings") + : Dialog(osystem, parent, font, "User interface settings"), + myFont(font) { const GUI::Font& ifont = instance().frameBuffer().infoFont(); const int lineHeight = font.getLineHeight(), fontWidth = font.getMaxCharWidth(), fontHeight = font.getFontHeight(), + buttonWidth = font.getStringWidth("Image path" + ELLIPSIS) + 20 + 1, buttonHeight = font.getLineHeight() + 4; + const int VBORDER = 8; const int HBORDER = 10; + const int INDENT = 16; int xpos, ypos, tabID; int lwidth, pwidth = font.getStringWidth("Standard"); WidgetArray wid; @@ -51,8 +57,8 @@ UIDialog::UIDialog(OSystem& osystem, DialogContainer& parent, const GUI::Size& ds = instance().frameBuffer().desktopSize(); // Set real dimensions - _w = 39 * fontWidth + 10 * 2; - _h = 10 * (lineHeight + 4) + VBORDER + _th; + _w = (39+15) * fontWidth + 10 * 2; + _h = (10+1) * (lineHeight + 4) + VBORDER + _th; // The tab widget xpos = HBORDER; ypos = VBORDER; @@ -138,7 +144,7 @@ UIDialog::UIDialog(OSystem& osystem, DialogContainer& parent, new PopUpWidget(myTab, font, xpos, ypos + 1, pwidth, lineHeight, items, "Launcher Font ", lwidth); wid.push_back(myLauncherFontPopup); - ypos += lineHeight + 4; + ypos += lineHeight + 4 * 4; // ROM launcher info/snapshot viewer items.clear(); @@ -147,11 +153,25 @@ UIDialog::UIDialog(OSystem& osystem, DialogContainer& parent, VarList::push_back(items, "2x (1000x760)", "2"); myRomViewerPopup = new PopUpWidget(myTab, font, xpos, ypos + 1, pwidth, lineHeight, items, - "ROM Info viewer ", lwidth); + "ROM Info viewer ", lwidth, kRomViewer); wid.push_back(myRomViewerPopup); - ypos += lineHeight + 4*4; + ypos += lineHeight + 4; + + // Snapshot path (load files) + xpos = HBORDER + INDENT; + myOpenBrowserButton = new ButtonWidget(myTab, font, xpos, ypos, buttonWidth, buttonHeight, + "Image path" + ELLIPSIS, kChooseSnapLoadDirCmd); + wid.push_back(myOpenBrowserButton); + //ypos += lineHeight + 4; + xpos = myOpenBrowserButton->getRight() + 8; + + mySnapLoadPath = new EditTextWidget(myTab, font, xpos, ypos + 1, + _w - xpos - HBORDER, lineHeight, ""); + wid.push_back(mySnapLoadPath); + ypos += lineHeight + 4 * 5; // Exit to Launcher + xpos = HBORDER; myLauncherExitWidget = new CheckboxWidget(myTab, font, xpos + 1, ypos, "Always exit to Launcher"); wid.push_back(myLauncherExitWidget); @@ -198,6 +218,9 @@ void UIDialog::loadConfig() const string& viewer = instance().settings().getString("romviewer"); myRomViewerPopup->setSelected(viewer, "0"); + // ROM launcher info viewer image path + mySnapLoadPath->setText(instance().settings().getString("snaploaddir")); + // Exit to launcher bool exitlauncher = instance().settings().getBool("exitlauncher"); myLauncherExitWidget->setState(exitlauncher); @@ -214,6 +237,8 @@ void UIDialog::loadConfig() int mw = instance().settings().getInt("mwheel"); myWheelLinesPopup->setValue(mw); + handleRomViewer(); + myTab->loadConfig(); } @@ -233,6 +258,9 @@ void UIDialog::saveConfig() instance().settings().setValue("romviewer", myRomViewerPopup->getSelectedTag().toString()); + // ROM launcher info viewer image path + instance().settings().setValue("snaploaddir", mySnapLoadPath->getText()); + // Exit to Launcher instance().settings().setValue("exitlauncher", myLauncherExitWidget->getState()); @@ -268,6 +296,7 @@ void UIDialog::setDefaults() myLauncherHeightSlider->setValue(h); myLauncherFontPopup->setSelected("medium", ""); myRomViewerPopup->setSelected("1", ""); + mySnapLoadPath->setText(instance().defaultLoadDir()); myLauncherExitWidget->setState(false); break; } @@ -313,8 +342,48 @@ void UIDialog::handleCommand(CommandSender* sender, int cmd, int data, int id) myWheelLinesPopup->setValueUnit(" lines"); break; + case kRomViewer: + handleRomViewer(); + break; + + case kChooseSnapLoadDirCmd: + // This dialog is resizable under certain conditions, so we need + // to re-create it as necessary + createBrowser("Select snapshot load directory"); + myBrowser->show(mySnapLoadPath->getText(), + BrowserDialog::Directories, kSnapLoadDirChosenCmd); + break; + + case kSnapLoadDirChosenCmd: + mySnapLoadPath->setText(myBrowser->getResult().getShortPath()); + break; + default: Dialog::handleCommand(sender, cmd, data, 0); break; } } + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void UIDialog::handleRomViewer() +{ + bool enable = myRomViewerPopup->getSelectedName() != "Off"; + + myOpenBrowserButton->setEnabled(enable); + mySnapLoadPath->setEnabled(enable); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void UIDialog::createBrowser(const string& title) +{ + uInt32 w = 0, h = 0; + getResizableBounds(w, h); + + // Create file browser dialog + if(!myBrowser || uInt32(myBrowser->getWidth()) != w || + uInt32(myBrowser->getHeight()) != h) + myBrowser = make_unique(this, myFont, w, h, title); + else + myBrowser->setTitle(title); +} + diff --git a/src/gui/UIDialog.hxx b/src/gui/UIDialog.hxx index e0811b23e..389bece1b 100644 --- a/src/gui/UIDialog.hxx +++ b/src/gui/UIDialog.hxx @@ -26,6 +26,7 @@ class PopUpWidget; class SliderWidget; class StaticTextWidget; class TabWidget; +class BrowserDialog; class OSystem; #include "bspf.hxx" @@ -42,27 +43,37 @@ class UIDialog : public Dialog void setDefaults() override; void handleCommand(CommandSender* sender, int cmd, int data, int id) override; + void handleRomViewer(); + void createBrowser(const string& title); private: enum { kListDelay = 'UILd', kMouseWheel = 'UIMw', + kRomViewer = 'UIRv', + kChooseSnapLoadDirCmd = 'UIsl', // snapshot dir (load files) + kSnapLoadDirChosenCmd = 'UIsc' // snap chosen (load files) }; + const GUI::Font& myFont; TabWidget* myTab; // Launcher options SliderWidget* myLauncherWidthSlider; SliderWidget* myLauncherHeightSlider; - CheckboxWidget* myLauncherExitWidget; PopUpWidget* myLauncherFontPopup; PopUpWidget* myRomViewerPopup; + ButtonWidget* myOpenBrowserButton; + EditTextWidget* mySnapLoadPath; + CheckboxWidget* myLauncherExitWidget; // Misc options PopUpWidget* myPalettePopup; - SliderWidget* myListDelayPopup; - SliderWidget* myWheelLinesPopup; + SliderWidget* myListDelayPopup; + SliderWidget* myWheelLinesPopup; + + unique_ptr myBrowser; private: // Following constructors and assignment operators not supported