mirror of https://github.com/stella-emu/stella.git
Refactor Dialog class containing fonts:
- the previous code has a _font pointer in derived classes, and a _font reference in the base class; this causes name collisions - the Dialog class now takes a font reference, which is used throughout the hierarchy - this simplifies certain code (setTitle vs. initTitle) and also eliminates clang warnings
This commit is contained in:
parent
3837921073
commit
e01321fbea
|
@ -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;
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -120,7 +120,6 @@ class ContextMenu : public Dialog, public CommandSender
|
|||
bool _isScrolling;
|
||||
uInt32 _scrollUpColor, _scrollDnColor;
|
||||
|
||||
const GUI::Font& _font;
|
||||
int _cmd;
|
||||
|
||||
uInt32 _xorig, _yorig;
|
||||
|
|
|
@ -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,28 +119,17 @@ 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;
|
||||
_th = _font.getLineHeight() + 4;
|
||||
_h += _th;
|
||||
}
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void Dialog::center()
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<shared_ptr<FBSurface>> mySurfaceStack;
|
||||
|
||||
|
|
|
@ -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<VideoDialog>(osystem, parent, font, max_w, max_h);
|
||||
myAudioDialog = make_unique<AudioDialog>(osystem, parent, font);
|
||||
myInputDialog = make_unique<InputDialog>(osystem, parent, font, max_w, max_h);
|
||||
myUIDialog = make_unique<UIDialog>(osystem, parent, font);
|
||||
mySnapshotDialog = make_unique<SnapshotDialog>(osystem, parent, font, max_w, max_h);
|
||||
myConfigPathDialog = make_unique<ConfigPathDialog>(osystem, parent, font, boss, max_w, max_h);
|
||||
myRomAuditDialog = make_unique<RomAuditDialog>(osystem, parent, font, max_w, max_h);
|
||||
myGameInfoDialog = make_unique<GameInfoDialog>(osystem, parent, font, this);
|
||||
myVideoDialog = make_unique<VideoDialog>(osystem, parent, _font, max_w, max_h);
|
||||
myAudioDialog = make_unique<AudioDialog>(osystem, parent, _font);
|
||||
myInputDialog = make_unique<InputDialog>(osystem, parent, _font, max_w, max_h);
|
||||
myUIDialog = make_unique<UIDialog>(osystem, parent, _font);
|
||||
mySnapshotDialog = make_unique<SnapshotDialog>(osystem, parent, _font, max_w, max_h);
|
||||
myConfigPathDialog = make_unique<ConfigPathDialog>(osystem, parent, _font, boss, max_w, max_h);
|
||||
myRomAuditDialog = make_unique<RomAuditDialog>(osystem, parent, _font, max_w, max_h);
|
||||
myGameInfoDialog = make_unique<GameInfoDialog>(osystem, parent, _font, this);
|
||||
#ifdef CHEATCODE_SUPPORT
|
||||
myCheatCodeDialog = make_unique<CheatCodeDialog>(osystem, parent, font);
|
||||
myCheatCodeDialog = make_unique<CheatCodeDialog>(osystem, parent, _font);
|
||||
#endif
|
||||
myLoggerDialog = make_unique<LoggerDialog>(osystem, parent, font, max_w, max_h);
|
||||
myDeveloperDialog = make_unique<DeveloperDialog>(osystem, parent, font, max_w, max_h);
|
||||
myHelpDialog = make_unique<HelpDialog>(osystem, parent, font);
|
||||
myAboutDialog = make_unique<AboutDialog>(osystem, parent, font);
|
||||
myLoggerDialog = make_unique<LoggerDialog>(osystem, parent, _font, max_w, max_h);
|
||||
myDeveloperDialog = make_unique<DeveloperDialog>(osystem, parent, _font, max_w, max_h);
|
||||
myHelpDialog = make_unique<HelpDialog>(osystem, parent, _font);
|
||||
myAboutDialog = make_unique<AboutDialog>(osystem, parent, _font);
|
||||
|
||||
addToFocusList(wid);
|
||||
|
||||
|
|
Loading…
Reference in New Issue