diff --git a/src/gui/CommandDialog.cxx b/src/gui/CommandDialog.cxx index ad6735cc1..6269cecb3 100644 --- a/src/gui/CommandDialog.cxx +++ b/src/gui/CommandDialog.cxx @@ -27,13 +27,10 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CommandDialog::CommandDialog(OSystem& osystem, DialogContainer& parent) - : Dialog(osystem, parent) + : Dialog(osystem, parent, osystem.frameBuffer().font(), "Commands") { - const GUI::Font& font = instance().frameBuffer().font(); - initTitle(font, "Commands"); - - const int buttonWidth = font.getStringWidth("Right Diff B") + 20, - buttonHeight = font.getLineHeight() + 6, + const int buttonWidth = _font.getStringWidth("Right Diff B") + 20, + buttonHeight = _font.getLineHeight() + 6, rowHeight = buttonHeight + 8; // Set real dimensions @@ -46,7 +43,7 @@ CommandDialog::CommandDialog(OSystem& osystem, DialogContainer& parent) auto ADD_CD_BUTTON = [&](const string& label, int cmd) { - ButtonWidget* bw = new ButtonWidget(this, font, xoffset, yoffset, + ButtonWidget* bw = new ButtonWidget(this, _font, xoffset, yoffset, buttonWidth, buttonHeight, label, cmd); xoffset += buttonWidth + 8; return bw; diff --git a/src/gui/ContextMenu.cxx b/src/gui/ContextMenu.cxx index ba1ff7761..1085d0c32 100644 --- a/src/gui/ContextMenu.cxx +++ b/src/gui/ContextMenu.cxx @@ -28,7 +28,7 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ContextMenu::ContextMenu(GuiObject* boss, const GUI::Font& font, const VariantList& items, int cmd, int width) - : Dialog(boss->instance(), boss->parent()), + : Dialog(boss->instance(), boss->parent(), font), CommandSender(boss), _rowHeight(font.getLineHeight()), _firstEntry(0), @@ -39,7 +39,6 @@ ContextMenu::ContextMenu(GuiObject* boss, const GUI::Font& font, _isScrolling(false), _scrollUpColor(kColor), _scrollDnColor(kColor), - _font(font), _cmd(cmd), _xorig(0), _yorig(0), diff --git a/src/gui/ContextMenu.hxx b/src/gui/ContextMenu.hxx index 4ce617a34..9118f56e0 100644 --- a/src/gui/ContextMenu.hxx +++ b/src/gui/ContextMenu.hxx @@ -120,7 +120,6 @@ class ContextMenu : public Dialog, public CommandSender bool _isScrolling; uInt32 _scrollUpColor, _scrollDnColor; - const GUI::Font& _font; int _cmd; uInt32 _xorig, _yorig; diff --git a/src/gui/Dialog.cxx b/src/gui/Dialog.cxx index 4cc1a36e0..8bba62a5f 100644 --- a/src/gui/Dialog.cxx +++ b/src/gui/Dialog.cxx @@ -44,10 +44,10 @@ * ... */ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Dialog::Dialog(OSystem& instance, DialogContainer& parent, const GUI::Font& font, const string& title, - int x, int y, int w, int h) +Dialog::Dialog(OSystem& instance, DialogContainer& parent, const GUI::Font& font, + const string& title, int x, int y, int w, int h) : GuiObject(instance, parent, *this, x, y, w, h), + _font(font), _mouseWidget(nullptr), _focusedWidget(nullptr), _dragWidget(nullptr), @@ -57,31 +57,17 @@ Dialog::Dialog(OSystem& instance, DialogContainer& parent, const GUI::Font& font _processCancel(false), _title(title), _th(0), - _font(&font), _surface(nullptr), _tabID(0), _flags(WIDGET_ENABLED | WIDGET_BORDER | WIDGET_CLEARBG) { - initTitle(font, title); + setTitle(title); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Dialog::Dialog(OSystem& instance, DialogContainer& parent, int x, int y, int w, int h) - : GuiObject(instance, parent, *this, x, y, w, h), - _mouseWidget(nullptr), - _focusedWidget(nullptr), - _dragWidget(nullptr), - _okWidget(nullptr), - _cancelWidget(nullptr), - _visible(false), - _processCancel(false), - _title(""), - _th(0), - _font(nullptr), - _fh(0), - _surface(nullptr), - _tabID(0), - _flags(WIDGET_ENABLED | WIDGET_BORDER | WIDGET_CLEARBG) + : Dialog(instance, parent, instance.frameBuffer().font(), "", x, y, w, h) { } @@ -133,27 +119,16 @@ void Dialog::close(bool refresh) parent().removeDialog(); } -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Dialog::initTitle(const GUI::Font& font, const string& title) -{ - _font = &font; - _fh = font.getLineHeight(); - setTitle(title); -} - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Dialog::setTitle(const string& title) { - if(_font != nullptr) - { - _title = title; - _h -= _th; - if(title.empty()) - _th = 0; - else - _th = _fh + 4; - _h += _th; - } + _title = title; + _h -= _th; + if(title.empty()) + _th = 0; + else + _th = _font.getLineHeight() + 4; + _h += _th; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -336,7 +311,7 @@ void Dialog::drawDialog() if(_th) { s.fillRect(_x, _y, _w, _th, onTop ? kColorTitleBar : kColorTitleBarLo); - s.drawString(*_font, _title, _x + 10, _y + 2 + 1, _font->getStringWidth(_title), + s.drawString(_font, _title, _x + 10, _y + 2 + 1, _font.getStringWidth(_title), onTop ? kColorTitleText : kColorTitleTextLo); } } diff --git a/src/gui/Dialog.hxx b/src/gui/Dialog.hxx index bfa275caf..1701bc66e 100644 --- a/src/gui/Dialog.hxx +++ b/src/gui/Dialog.hxx @@ -46,8 +46,8 @@ class Dialog : public GuiObject public: Dialog(OSystem& instance, DialogContainer& parent, int x = 0, int y = 0, int w = 0, int h = 0); - Dialog(OSystem& instance, DialogContainer& parent, const GUI::Font& font, const string& title, - int x = 0, int y = 0, int w = 0, int h = 0); + Dialog(OSystem& instance, DialogContainer& parent, const GUI::Font& font, + const string& title = "", int x = 0, int y = 0, int w = 0, int h = 0); virtual ~Dialog(); @@ -129,8 +129,6 @@ class Dialog : public GuiObject void processCancelWithoutWidget(bool state) { _processCancel = state; } - void initTitle(const GUI::Font& font, const string& title); - private: void buildCurrentFocusList(int tabID = -1); bool handleNavEvent(Event::Type e); @@ -138,18 +136,19 @@ class Dialog : public GuiObject bool cycleTab(int direction); protected: + const GUI::Font& _font; + Widget* _mouseWidget; Widget* _focusedWidget; Widget* _dragWidget; Widget* _defaultWidget; Widget* _okWidget; Widget* _cancelWidget; + bool _visible; bool _processCancel; string _title; int _th; - const GUI::Font* _font; - int _fh; Common::FixedStack> mySurfaceStack; diff --git a/src/gui/OptionsDialog.cxx b/src/gui/OptionsDialog.cxx index 77d9bba6d..584e414b0 100644 --- a/src/gui/OptionsDialog.cxx +++ b/src/gui/OptionsDialog.cxx @@ -48,16 +48,13 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - OptionsDialog::OptionsDialog(OSystem& osystem, DialogContainer& parent, GuiObject* boss, int max_w, int max_h, stellaMode mode) - : Dialog(osystem, parent), + : Dialog(osystem, parent, osystem.frameBuffer().font(), "Options"), myMode(mode), _boss(boss) { - const GUI::Font& font = instance().frameBuffer().font(); - initTitle(font, "Options"); - - const int buttonWidth = font.getStringWidth("Game Properties" + ELLIPSIS) + 20, - buttonHeight = font.getLineHeight() + 6, - rowHeight = font.getLineHeight() + 10; + const int buttonWidth = _font.getStringWidth("Game Properties" + ELLIPSIS) + 20, + buttonHeight = _font.getLineHeight() + 6, + rowHeight = _font.getLineHeight() + 10; const int VBORDER = 10 + _th; _w = 2 * buttonWidth + 30; @@ -69,7 +66,7 @@ OptionsDialog::OptionsDialog(OSystem& osystem, DialogContainer& parent, auto ADD_OD_BUTTON = [&](const string& label, int cmd) { - ButtonWidget* bw = new ButtonWidget(this, font, xoffset, yoffset, + ButtonWidget* bw = new ButtonWidget(this, _font, xoffset, yoffset, buttonWidth, buttonHeight, label, cmd); yoffset += rowHeight; return bw; @@ -128,21 +125,21 @@ OptionsDialog::OptionsDialog(OSystem& osystem, DialogContainer& parent, addCancelWidget(b); // Now create all the dialogs attached to each menu button - myVideoDialog = make_unique(osystem, parent, font, max_w, max_h); - myAudioDialog = make_unique(osystem, parent, font); - myInputDialog = make_unique(osystem, parent, font, max_w, max_h); - myUIDialog = make_unique(osystem, parent, font); - mySnapshotDialog = make_unique(osystem, parent, font, max_w, max_h); - myConfigPathDialog = make_unique(osystem, parent, font, boss, max_w, max_h); - myRomAuditDialog = make_unique(osystem, parent, font, max_w, max_h); - myGameInfoDialog = make_unique(osystem, parent, font, this); + myVideoDialog = make_unique(osystem, parent, _font, max_w, max_h); + myAudioDialog = make_unique(osystem, parent, _font); + myInputDialog = make_unique(osystem, parent, _font, max_w, max_h); + myUIDialog = make_unique(osystem, parent, _font); + mySnapshotDialog = make_unique(osystem, parent, _font, max_w, max_h); + myConfigPathDialog = make_unique(osystem, parent, _font, boss, max_w, max_h); + myRomAuditDialog = make_unique(osystem, parent, _font, max_w, max_h); + myGameInfoDialog = make_unique(osystem, parent, _font, this); #ifdef CHEATCODE_SUPPORT - myCheatCodeDialog = make_unique(osystem, parent, font); + myCheatCodeDialog = make_unique(osystem, parent, _font); #endif - myLoggerDialog = make_unique(osystem, parent, font, max_w, max_h); - myDeveloperDialog = make_unique(osystem, parent, font, max_w, max_h); - myHelpDialog = make_unique(osystem, parent, font); - myAboutDialog = make_unique(osystem, parent, font); + myLoggerDialog = make_unique(osystem, parent, _font, max_w, max_h); + myDeveloperDialog = make_unique(osystem, parent, _font, max_w, max_h); + myHelpDialog = make_unique(osystem, parent, _font); + myAboutDialog = make_unique(osystem, parent, _font); addToFocusList(wid);