From d4479f4e43d1ce1a466255642e288df95ef685bf Mon Sep 17 00:00:00 2001 From: thrust26 Date: Wed, 1 May 2019 17:19:40 +0200 Subject: [PATCH] allow to position dialogs centered and in corners --- src/debugger/gui/DebuggerDialog.hxx | 1 + src/emucore/Settings.cxx | 3 ++ src/gui/Dialog.cxx | 45 +++++++++++++++++++++++++++-- src/gui/Dialog.hxx | 1 + src/gui/LauncherDialog.cxx | 8 +++-- src/gui/LauncherDialog.hxx | 1 + src/gui/StellaSettingsDialog.cxx | 34 +++++++++++++++++----- src/gui/StellaSettingsDialog.hxx | 1 + src/gui/UIDialog.cxx | 23 +++++++++++++-- src/gui/UIDialog.hxx | 1 + 10 files changed, 105 insertions(+), 13 deletions(-) diff --git a/src/debugger/gui/DebuggerDialog.hxx b/src/debugger/gui/DebuggerDialog.hxx index bfffba254..3199a7e23 100644 --- a/src/debugger/gui/DebuggerDialog.hxx +++ b/src/debugger/gui/DebuggerDialog.hxx @@ -74,6 +74,7 @@ class DebuggerDialog : public Dialog void showFatalMessage(const string& msg); private: + void center() { positionAt(0); } void loadConfig() override; void handleKeyDown(StellaKey key, StellaMod mod) override; void handleCommand(CommandSender* sender, int cmd, int data, int id) override; diff --git a/src/emucore/Settings.cxx b/src/emucore/Settings.cxx index 32e21b53a..dfa7f84e0 100644 --- a/src/emucore/Settings.cxx +++ b/src/emucore/Settings.cxx @@ -122,6 +122,7 @@ Settings::Settings() setPermanent("listdelay", "300"); setPermanent("mwheel", "4"); setPermanent("basic_settings", false); + setPermanent("dialogpos", 0); // Misc options setPermanent("autoslot", "false"); @@ -463,6 +464,8 @@ void Settings::usage() const << " (300-1000)\n" << " -mwheel Number of lines the mouse wheel will scroll in\n" << " UI\n" + << " -basic_settings <0|1> Display only a basic settings dialog\n" + << " -dialogpos <0..4> Display all dialogs at given positions\n" << " -romdir Directory in which to load ROM files\n" << " -avoxport The name of the serial port where an AtariVox is\n" << " connected\n" diff --git a/src/gui/Dialog.cxx b/src/gui/Dialog.cxx index c0556d883..50bdf952d 100644 --- a/src/gui/Dialog.cxx +++ b/src/gui/Dialog.cxx @@ -95,7 +95,7 @@ void Dialog::open() // Make sure we have a valid surface to draw into // Technically, this shouldn't be needed until drawDialog(), but some // dialogs cause drawing to occur within loadConfig() - if(_surface == nullptr) + if (_surface == nullptr) _surface = instance().frameBuffer().allocateSurface(_w, _h); parent().addDialog(this); @@ -108,6 +108,13 @@ void Dialog::open() else buildCurrentFocusList(); + /*if (!_surface->attributes().blending) + { + _surface->attributes().blending = true; + _surface->attributes().blendalpha = 90; + _surface->applyAttributes(); + }*/ + loadConfig(); // has to be done AFTER (re)building the focus list _visible = true; @@ -148,10 +155,44 @@ void Dialog::setTitle(const string& title) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Dialog::center() +{ + positionAt(instance().settings().getInt("dialogpos")); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Dialog::positionAt(uInt32 pos) { const GUI::Size& screen = instance().frameBuffer().screenSize(); const GUI::Rect& dst = _surface->dstRect(); - _surface->setDstPos((screen.w - dst.width()) >> 1, (screen.h - dst.height()) >> 1); + + int top = std::min(screen.h - dst.height(), screen.h >> 5); + int btm = std::min(screen.h - dst.height(), screen.h - dst.height() - (screen.h >> 5)); + int left = std::min(screen.w - dst.width(), screen.w >> 5); + int right = std::min(screen.w - dst.width(), screen.w - dst.width() - (screen.w >> 5)); + + switch (pos) + { + case 1: + _surface->setDstPos(left, top); + break; + + case 2: + _surface->setDstPos(right, top); + break; + + case 3: + _surface->setDstPos(right, btm); + break; + + case 4: + _surface->setDstPos(left, btm); + break; + + default: + // center + _surface->setDstPos((screen.w - dst.width()) >> 1, (screen.h - dst.height()) >> 1); + break; + } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/gui/Dialog.hxx b/src/gui/Dialog.hxx index 0fec2c7b8..c52fd207a 100644 --- a/src/gui/Dialog.hxx +++ b/src/gui/Dialog.hxx @@ -162,6 +162,7 @@ class Dialog : public GuiObject /** Define the size (allowed) for the dialog. */ void setSize(uInt32 w, uInt32 h, uInt32 max_w, uInt32 max_h); + void positionAt(uInt32 pos); private: void buildCurrentFocusList(int tabID = -1); diff --git a/src/gui/LauncherDialog.cxx b/src/gui/LauncherDialog.cxx index 2ce9ecc42..fc173a6c4 100644 --- a/src/gui/LauncherDialog.cxx +++ b/src/gui/LauncherDialog.cxx @@ -126,6 +126,8 @@ LauncherDialog::LauncherDialog(OSystem& osystem, DialogContainer& parent, // Show the checkbox for all files xpos -= lwidth2 + LBL_GAP * 3; myAllFiles = new CheckboxWidget(this, font, xpos, ypos, lblAllFiles, kAllfilesCmd); + wid.push_back(myAllFiles); + wid.push_back(myPattern); } // Add list with game titles @@ -143,7 +145,6 @@ LauncherDialog::LauncherDialog(OSystem& osystem, DialogContainer& parent, listWidth, _h - 43 - bheight - fontHeight - lineHeight); myList->setEditable(false); wid.push_back(myList); - if(myPattern) wid.push_back(myPattern); // Add after the list for tab order // Add ROM info area (if enabled) if(romWidth > 0) @@ -204,7 +205,10 @@ LauncherDialog::LauncherDialog(OSystem& osystem, DialogContainer& parent, wid.push_back(myStartButton); #endif } - mySelectedItem = 0; // Highlight 'Rom Listing' + if (myUseMinimalUI) // Highlight 'Rom Listing' + mySelectedItem = 0; + else + mySelectedItem = 2; // Create a game list, which contains all the information about a ROM that // the launcher needs diff --git a/src/gui/LauncherDialog.hxx b/src/gui/LauncherDialog.hxx index e6203b6b7..70b89d0a2 100644 --- a/src/gui/LauncherDialog.hxx +++ b/src/gui/LauncherDialog.hxx @@ -85,6 +85,7 @@ class LauncherDialog : public Dialog void reload() { updateListing(); } private: + void center() { positionAt(0); } void handleKeyDown(StellaKey key, StellaMod mod) override; void handleMouseDown(int x, int y, MouseButton b, int clickCount) override; void handleCommand(CommandSender* sender, int cmd, int data, int id) override; diff --git a/src/gui/StellaSettingsDialog.cxx b/src/gui/StellaSettingsDialog.cxx index 0bdff77aa..dcf16f0c2 100644 --- a/src/gui/StellaSettingsDialog.cxx +++ b/src/gui/StellaSettingsDialog.cxx @@ -45,13 +45,14 @@ StellaSettingsDialog::StellaSettingsDialog(OSystem& osystem, DialogContainer& pa VariantList items; // Set real dimensions - setSize(33 * fontWidth + HBORDER * 2, 14 * (lineHeight + VGAP) + VGAP * 9 + 6 + _th, max_w, max_h); + setSize(33 * fontWidth + HBORDER * 2 + 3, 15 * (lineHeight + VGAP) + VGAP * 9 + 6 + _th, max_w, max_h); xpos = HBORDER; ypos = VBORDER + _th; myAdvancedSettings = new ButtonWidget(this, font, xpos, ypos, _w - HBORDER * 2, buttonHeight, "Switch to Advanced Settings" + ELLIPSIS, kAdvancedSettings); + wid.push_back(myAdvancedSettings); ypos += lineHeight + VGAP*4; new StaticTextWidget(this, font, xpos, ypos + 1, "Global settings:"); @@ -83,15 +84,27 @@ void StellaSettingsDialog::addUIOptions(WidgetArray& wid, int& xpos, int& ypos, const int VGAP = 4; const int lineHeight = font.getLineHeight(); VariantList items; - int pwidth = font.getStringWidth("Bad adjust"); // align width with other popup + int pwidth = font.getStringWidth("Right bottom"); // align width with other popup ypos += 1; VarList::push_back(items, "Standard", "standard"); VarList::push_back(items, "Classic", "classic"); VarList::push_back(items, "Light", "light"); - myThemePopup = new PopUpWidget(this, font, xpos, ypos, pwidth, lineHeight, items, "UI theme "); + myThemePopup = new PopUpWidget(this, font, xpos, ypos, pwidth, lineHeight, items, "UI theme "); wid.push_back(myThemePopup); ypos += lineHeight + VGAP; + + // Dialog position + items.clear(); + VarList::push_back(items, "Centered", 0); + VarList::push_back(items, "Left top", 1); + VarList::push_back(items, "Right top", 2); + VarList::push_back(items, "Right bottom", 3); + VarList::push_back(items, "Left bottom", 4); + myPositionPopup = new PopUpWidget(this, font, xpos, ypos, pwidth, lineHeight, + items, "Dialogs position "); + wid.push_back(myPositionPopup); + ypos += lineHeight + VGAP; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -113,11 +126,11 @@ void StellaSettingsDialog::addVideoOptions(WidgetArray& wid, int& xpos, int& ypo VarList::push_back(items, "S-Video", static_cast(NTSCFilter::Preset::SVIDEO)); VarList::push_back(items, "Composite", static_cast(NTSCFilter::Preset::COMPOSITE)); VarList::push_back(items, "Bad adjust", static_cast(NTSCFilter::Preset::BAD)); - int lwidth = font.getStringWidth("TV mode "); + int lwidth = font.getStringWidth("TV mode "); int pwidth = font.getStringWidth("Bad adjust"); myTVMode = new PopUpWidget(this, font, xpos, ypos, pwidth, lineHeight, - items, "TV mode ", lwidth); + items, "TV mode "); wid.push_back(myTVMode); ypos += lineHeight + VGAP * 2; @@ -128,7 +141,7 @@ void StellaSettingsDialog::addVideoOptions(WidgetArray& wid, int& xpos, int& ypo myTVScanlines = new StaticTextWidget(this, font, xpos, ypos + 1, "Scanlines:"); ypos += lineHeight; myTVScanIntense = new SliderWidget(this, font, xpos + INDENT, ypos-1, swidth, lineHeight, - "Intensity ", lwidth, kScanlinesChanged, fontWidth * 3); + "Intensity ", lwidth, kScanlinesChanged, fontWidth * 2); myTVScanIntense->setMinValue(0); myTVScanIntense->setMaxValue(10); myTVScanIntense->setTickmarkInterval(2); wid.push_back(myTVScanIntense); @@ -139,7 +152,7 @@ void StellaSettingsDialog::addVideoOptions(WidgetArray& wid, int& xpos, int& ypo ypos += lineHeight; // TV Phosphor blend level myTVPhosLevel = new SliderWidget(this, font, xpos + INDENT, ypos-1, swidth, lineHeight, - "Blend ", lwidth, kPhosphorChanged, fontWidth * 3); + "Blend ", lwidth, kPhosphorChanged, fontWidth * 2); myTVPhosLevel->setMinValue(0); myTVPhosLevel->setMaxValue(10); myTVPhosLevel->setTickmarkInterval(2); wid.push_back(myTVPhosLevel); @@ -195,6 +208,8 @@ void StellaSettingsDialog::loadConfig() // UI palette const string& theme = settings.getString("uipalette"); myThemePopup->setSelected(theme, "standard"); + // Dialog position + myPositionPopup->setSelected(settings.getString("dialogpos"), "0"); // TV Mode myTVMode->setSelected( @@ -231,6 +246,9 @@ void StellaSettingsDialog::saveConfig() myThemePopup->getSelectedTag().toString()); instance().frameBuffer().setUIPalette(); + // Dialog position + settings.setValue("dialogpos", myPositionPopup->getSelectedTag().toString()); + // TV Mode instance().settings().setValue("tv.filter", myTVMode->getSelectedTag().toString()); @@ -269,6 +287,8 @@ void StellaSettingsDialog::setDefaults() { // UI Theme myThemePopup->setSelected("standard"); + // Dialog position + myPositionPopup->setSelected("0"); // TV effects myTVMode->setSelected("RGB", static_cast(NTSCFilter::Preset::RGB)); diff --git a/src/gui/StellaSettingsDialog.hxx b/src/gui/StellaSettingsDialog.hxx index 87c414d87..c794d8581 100644 --- a/src/gui/StellaSettingsDialog.hxx +++ b/src/gui/StellaSettingsDialog.hxx @@ -63,6 +63,7 @@ class StellaSettingsDialog : public Dialog // UI theme PopUpWidget* myThemePopup; + PopUpWidget* myPositionPopup; // TV effects PopUpWidget* myTVMode; diff --git a/src/gui/UIDialog.cxx b/src/gui/UIDialog.cxx index 2d80617b5..da81dc7d2 100644 --- a/src/gui/UIDialog.cxx +++ b/src/gui/UIDialog.cxx @@ -72,7 +72,7 @@ UIDialog::UIDialog(OSystem& osystem, DialogContainer& parent, wid.clear(); tabID = myTab->addTab(" Look & Feel "); lwidth = font.getStringWidth("Mouse wheel scroll "); - pwidth = font.getStringWidth("Standard"); + pwidth = font.getStringWidth("Right bottom"); xpos = HBORDER; ypos = VBORDER; // UI Palette @@ -82,8 +82,20 @@ UIDialog::UIDialog(OSystem& osystem, DialogContainer& parent, VarList::push_back(items, "Classic", "classic"); VarList::push_back(items, "Light", "light"); myPalettePopup = new PopUpWidget(myTab, font, xpos, ypos, pwidth, lineHeight, - items, "Theme ", lwidth); + items, "Theme ", lwidth); wid.push_back(myPalettePopup); + ypos += lineHeight + V_GAP; + + // Dialog position + items.clear(); + VarList::push_back(items, "Centered", 0); + VarList::push_back(items, "Left top", 1); + VarList::push_back(items, "Right top", 2); + VarList::push_back(items, "Right bottom", 3); + VarList::push_back(items, "Left bottom", 4); + myPositionPopup = new PopUpWidget(myTab, font, xpos, ypos, pwidth, lineHeight, + items, "Dialogs position ", lwidth); + wid.push_back(myPositionPopup); ypos += lineHeight + V_GAP * 4; // Delay between quick-selecting characters in ListWidget @@ -264,6 +276,9 @@ void UIDialog::loadConfig() const string& pal = settings.getString("uipalette"); myPalettePopup->setSelected(pal, "standard"); + // Dialog position + myPositionPopup->setSelected(settings.getString("dialogpos"), "0"); + // Listwidget quick delay int delay = settings.getInt("listdelay"); myListDelayPopup->setValue(delay); @@ -309,6 +324,9 @@ void UIDialog::saveConfig() myPalettePopup->getSelectedTag().toString()); instance().frameBuffer().setUIPalette(); + // Dialog position + settings.setValue("dialogpos", myPositionPopup->getSelectedTag().toString()); + // Listwidget quick delay settings.setValue("listdelay", myListDelayPopup->getValue()); ListWidget::setQuickSelectDelay(myListDelayPopup->getValue()); @@ -329,6 +347,7 @@ void UIDialog::setDefaults() { case 0: // Misc. options myPalettePopup->setSelected("standard"); + myPositionPopup->setSelected("0"); myListDelayPopup->setValue(300); myWheelLinesPopup->setValue(4); break; diff --git a/src/gui/UIDialog.hxx b/src/gui/UIDialog.hxx index 3cc52b8e2..5de735433 100644 --- a/src/gui/UIDialog.hxx +++ b/src/gui/UIDialog.hxx @@ -63,6 +63,7 @@ class UIDialog : public Dialog, public CommandSender // Misc options PopUpWidget* myPalettePopup; + PopUpWidget* myPositionPopup; SliderWidget* myListDelayPopup; SliderWidget* myWheelLinesPopup;