GUI: Move the lowres string handling logic inside the button widgets

This commit is contained in:
Die4Ever 2022-05-15 05:16:29 -05:00 committed by GitHub
parent 4034ab2335
commit 2296af6b1e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 38 deletions

View file

@ -238,29 +238,20 @@ void LauncherDialog::build() {
#endif #endif
if (!g_system->hasFeature(OSystem::kFeatureNoQuit)) if (!g_system->hasFeature(OSystem::kFeatureNoQuit))
new ButtonWidget(this, _title + ".QuitButton", _("~Q~uit"), _("Quit ScummVM"), kQuitCmd); new ButtonWidget(this, _title + ".QuitButton", _("~Q~uit"), _("Quit ScummVM"), kQuitCmd);
new ButtonWidget(this, _title + ".AboutButton", _("A~b~out"), _("About ScummVM"), kAboutCmd); new ButtonWidget(this, _title + ".AboutButton", _("A~b~out"), _("About ScummVM"), kAboutCmd);
if (g_system->getOverlayWidth() > 320) new ButtonWidget(this, _title + ".OptionsButton", _("Global ~O~ptions..."), _("Change global ScummVM options"), kOptionsCmd, 0, _c("Global Opts...", "lowres"));
new ButtonWidget(this, _title + ".OptionsButton", _("Global ~O~ptions..."), _("Change global ScummVM options"), kOptionsCmd);
else
new ButtonWidget(this, _title + ".OptionsButton", _c("Global ~O~pts...", "lowres"), _("Change global ScummVM options"), kOptionsCmd);
// Above the lowest button rows: two more buttons (directly below the list box) // Above the lowest button rows: two more buttons (directly below the list box)
DropdownButtonWidget *addButton =
new DropdownButtonWidget(this, _title + ".AddGameButton", _("~A~dd Game..."), _("Add games to the list"), kAddGameCmd, 0, _c("~A~dd Game...", "lowres"));
_addButton = addButton;
_removeButton =
new ButtonWidget(this, _title + ".RemoveGameButton", _("~R~emove Game"), _("Remove game from the list. The game data files stay intact"), kRemoveGameCmd, 0, _c("~R~emove Game", "lowres"));
if (g_system->getOverlayWidth() > 320) { if (g_system->getOverlayWidth() > 320) {
DropdownButtonWidget *addButton =
new DropdownButtonWidget(this, _title + ".AddGameButton", _("~A~dd Game..."), _("Add games to the list"), kAddGameCmd);
addButton->appendEntry(_("Mass Add..."), kMassAddGameCmd); addButton->appendEntry(_("Mass Add..."), kMassAddGameCmd);
_addButton = addButton;
_removeButton =
new ButtonWidget(this, _title + ".RemoveGameButton", _("~R~emove Game"), _("Remove game from the list. The game data files stay intact"), kRemoveGameCmd);
} else { } else {
DropdownButtonWidget *addButton =
new DropdownButtonWidget(this, _title + ".AddGameButton", _c("~A~dd Game...", "lowres"), _("Add games to the list"), kAddGameCmd);
addButton->appendEntry(_c("Mass Add...", "lowres"), kMassAddGameCmd); addButton->appendEntry(_c("Mass Add...", "lowres"), kMassAddGameCmd);
_addButton = addButton;
_removeButton =
new ButtonWidget(this, _title + ".RemoveGameButton", _c("~R~emove Game", "lowres"), _("Remove game from the list. The game data files stay intact"), kRemoveGameCmd);
} }
// Search box // Search box
@ -994,13 +985,8 @@ void LauncherSimple::build() {
_loadButton = loadButton; _loadButton = loadButton;
// Add edit button // Add edit button
if (g_system->getOverlayWidth() > 320) {
_editButton = _editButton =
new ButtonWidget(this, "Launcher.EditGameButton", _("~G~ame Options..."), _("Change game options"), kEditGameCmd); new ButtonWidget(this, "Launcher.EditGameButton", _("~G~ame Options..."), _("Change game options"), kEditGameCmd, 0, _c("Game Opts...", "lowres"));
} else {
_editButton =
new ButtonWidget(this, "Launcher.EditGameButton", _c("~G~ame Opts...", "lowres"), _("Change game options"), kEditGameCmd);
}
// Add list with game titles // Add list with game titles
_list = new GroupedListWidget(this, "Launcher.GameList", Common::U32String(), kListSearchCmd); _list = new GroupedListWidget(this, "Launcher.GameList", Common::U32String(), kListSearchCmd);

View file

@ -346,9 +346,10 @@ void StaticTextWidget::setFont(ThemeEngine::FontStyle font, Common::Language lan
#pragma mark - #pragma mark -
ButtonWidget::ButtonWidget(GuiObject *boss, int x, int y, int w, int h, const Common::U32String &label, const Common::U32String &tooltip, uint32 cmd, uint8 hotkey) ButtonWidget::ButtonWidget(GuiObject *boss, int x, int y, int w, int h, const Common::U32String &label, const Common::U32String &tooltip, uint32 cmd, uint8 hotkey, const Common::U32String &lowresLabel)
: StaticTextWidget(boss, x, y, w, h, cleanupHotkey(label), Graphics::kTextAlignCenter, tooltip), CommandSender(boss), : StaticTextWidget(boss, x, y, w, h, cleanupHotkey(label), Graphics::kTextAlignCenter, tooltip), CommandSender(boss),
_cmd(cmd), _hotkey(hotkey), _duringPress(false) { _cmd(cmd), _hotkey(hotkey), _duringPress(false) {
_lowresLabel = lowresLabel;
if (hotkey == 0) if (hotkey == 0)
_hotkey = parseHotkey(label); _hotkey = parseHotkey(label);
@ -357,11 +358,14 @@ ButtonWidget::ButtonWidget(GuiObject *boss, int x, int y, int w, int h, const Co
_type = kButtonWidget; _type = kButtonWidget;
} }
ButtonWidget::ButtonWidget(GuiObject *boss, const Common::String &name, const Common::U32String &label, const Common::U32String &tooltip, uint32 cmd, uint8 hotkey) ButtonWidget::ButtonWidget(GuiObject *boss, const Common::String &name, const Common::U32String &label, const Common::U32String &tooltip, uint32 cmd, uint8 hotkey, const Common::U32String &lowresLabel)
: StaticTextWidget(boss, name, cleanupHotkey(label), tooltip), CommandSender(boss), : StaticTextWidget(boss, name, cleanupHotkey(label), tooltip), CommandSender(boss),
_cmd(cmd), _hotkey(hotkey), _duringPress(false) { _cmd(cmd), _hotkey(hotkey), _duringPress(false) {
_lowresLabel = lowresLabel;
if (hotkey == 0) if (hotkey == 0)
_hotkey = parseHotkey(label); _hotkey = parseHotkey(label);
setFlags(WIDGET_ENABLED/* | WIDGET_BORDER*/ | WIDGET_CLEARBG); setFlags(WIDGET_ENABLED/* | WIDGET_BORDER*/ | WIDGET_CLEARBG);
_type = kButtonWidget; _type = kButtonWidget;
} }
@ -387,7 +391,7 @@ void ButtonWidget::handleMouseDown(int x, int y, int button, int clickCount) {
} }
void ButtonWidget::drawWidget() { void ButtonWidget::drawWidget() {
g_gui.theme()->drawButton(Common::Rect(_x, _y, _x + _w, _y + _h), _label, _state, getFlags()); g_gui.theme()->drawButton(Common::Rect(_x, _y, _x + _w, _y + _h), getLabel(), _state, getFlags());
} }
void ButtonWidget::setLabel(const Common::U32String &label) { void ButtonWidget::setLabel(const Common::U32String &label) {
@ -398,6 +402,17 @@ void ButtonWidget::setLabel(const Common::String &label) {
ButtonWidget::setLabel(Common::U32String(label)); ButtonWidget::setLabel(Common::U32String(label));
} }
void ButtonWidget::setLowresLabel(const Common::U32String &label) {
_lowresLabel = label;
}
const Common::U32String &ButtonWidget::getLabel() {
bool useLowres = false;
if (!_lowresLabel.empty())
useLowres = g_gui.theme()->getStringWidth(_label) > _w;
return useLowres ? _lowresLabel : _label;
}
ButtonWidget *addClearButton(GuiObject *boss, const Common::String &name, uint32 cmd, int x, int y, int w, int h) { ButtonWidget *addClearButton(GuiObject *boss, const Common::String &name, uint32 cmd, int x, int y, int w, int h) {
ButtonWidget *button; ButtonWidget *button;
@ -437,15 +452,15 @@ void ButtonWidget::setUnpressedState() {
#pragma mark - #pragma mark -
DropdownButtonWidget::DropdownButtonWidget(GuiObject *boss, int x, int y, int w, int h, const Common::U32String &label, const Common::U32String &tooltip, uint32 cmd, uint8 hotkey) : DropdownButtonWidget::DropdownButtonWidget(GuiObject *boss, int x, int y, int w, int h, const Common::U32String &label, const Common::U32String &tooltip, uint32 cmd, uint8 hotkey, const Common::U32String &lowresLabel) :
ButtonWidget(boss, x, y, w, h, label, tooltip, cmd, hotkey) { ButtonWidget(boss, x, y, w, h, label, tooltip, cmd, hotkey, lowresLabel) {
setFlags(getFlags() | WIDGET_TRACK_MOUSE); setFlags(getFlags() | WIDGET_TRACK_MOUSE);
reset(); reset();
} }
DropdownButtonWidget::DropdownButtonWidget(GuiObject *boss, const Common::String &name, const Common::U32String &label, const Common::U32String &tooltip, uint32 cmd, uint8 hotkey) : DropdownButtonWidget::DropdownButtonWidget(GuiObject *boss, const Common::String &name, const Common::U32String &label, const Common::U32String &tooltip, uint32 cmd, uint8 hotkey, const Common::U32String &lowresLabel) :
ButtonWidget(boss, name, label, tooltip, cmd, hotkey) { ButtonWidget(boss, name, label, tooltip, cmd, hotkey, lowresLabel) {
setFlags(getFlags() | WIDGET_TRACK_MOUSE); setFlags(getFlags() | WIDGET_TRACK_MOUSE);
reset(); reset();
@ -534,9 +549,9 @@ void DropdownButtonWidget::clearEntries() {
void DropdownButtonWidget::drawWidget() { void DropdownButtonWidget::drawWidget() {
if (_entries.empty()) { if (_entries.empty()) {
// Degrade to a regular button // Degrade to a regular button
g_gui.theme()->drawButton(Common::Rect(_x, _y, _x + _w, _y + _h), _label, _state); g_gui.theme()->drawButton(Common::Rect(_x, _y, _x + _w, _y + _h), getLabel(), _state);
} else { } else {
g_gui.theme()->drawDropDownButton(Common::Rect(_x, _y, _x + _w, _y + _h), _dropdownWidth, _label, g_gui.theme()->drawDropDownButton(Common::Rect(_x, _y, _x + _w, _y + _h), _dropdownWidth, getLabel(),
_state, _inButton, _inDropdown, (g_gui.useRTL() && _useRTL)); _state, _inButton, _inDropdown, (g_gui.useRTL() && _useRTL));
} }
} }
@ -705,7 +720,7 @@ void CheckboxWidget::setState(bool state) {
} }
void CheckboxWidget::drawWidget() { void CheckboxWidget::drawWidget() {
g_gui.theme()->drawCheckbox(Common::Rect(_x, _y, _x + _w, _y + _h), _spacing, _label, _state, Widget::_state, (g_gui.useRTL() && _useRTL)); g_gui.theme()->drawCheckbox(Common::Rect(_x, _y, _x + _w, _y + _h), _spacing, getLabel(), _state, Widget::_state, (g_gui.useRTL() && _useRTL));
} }
#pragma mark - #pragma mark -
@ -777,7 +792,7 @@ void RadiobuttonWidget::setState(bool state, bool setGroup) {
} }
void RadiobuttonWidget::drawWidget() { void RadiobuttonWidget::drawWidget() {
g_gui.theme()->drawRadiobutton(Common::Rect(_x, _y, _x + _w, _y + _h), _spacing, _label, _state, Widget::_state, (g_gui.useRTL() && _useRTL)); g_gui.theme()->drawRadiobutton(Common::Rect(_x, _y, _x + _w, _y + _h), _spacing, getLabel(), _state, Widget::_state, (g_gui.useRTL() && _useRTL));
} }
#pragma mark - #pragma mark -

View file

@ -225,9 +225,10 @@ class ButtonWidget : public StaticTextWidget, public CommandSender {
protected: protected:
uint32 _cmd; uint32 _cmd;
uint8 _hotkey; uint8 _hotkey;
Common::U32String _lowresLabel;
public: public:
ButtonWidget(GuiObject *boss, int x, int y, int w, int h, const Common::U32String &label, const Common::U32String &tooltip = Common::U32String(), uint32 cmd = 0, uint8 hotkey = 0); ButtonWidget(GuiObject *boss, int x, int y, int w, int h, const Common::U32String &label, const Common::U32String &tooltip = Common::U32String(), uint32 cmd = 0, uint8 hotkey = 0, const Common::U32String &lowresLabel = Common::U32String());
ButtonWidget(GuiObject *boss, const Common::String &name, const Common::U32String &label, const Common::U32String &tooltip = Common::U32String(), uint32 cmd = 0, uint8 hotkey = 0); ButtonWidget(GuiObject *boss, const Common::String &name, const Common::U32String &label, const Common::U32String &tooltip = Common::U32String(), uint32 cmd = 0, uint8 hotkey = 0, const Common::U32String &lowresLabel = Common::U32String());
void getMinSize(int &minWidth, int &minHeight) override; void getMinSize(int &minWidth, int &minHeight) override;
@ -236,6 +237,8 @@ public:
void setLabel(const Common::U32String &label); void setLabel(const Common::U32String &label);
void setLabel(const Common::String &label); void setLabel(const Common::String &label);
void setLowresLabel(const Common::U32String &label);
const Common::U32String &getLabel();
void handleMouseUp(int x, int y, int button, int clickCount) override; void handleMouseUp(int x, int y, int button, int clickCount) override;
void handleMouseDown(int x, int y, int button, int clickCount) override; void handleMouseDown(int x, int y, int button, int clickCount) override;
@ -253,8 +256,8 @@ protected:
/* DropdownButtonWidget */ /* DropdownButtonWidget */
class DropdownButtonWidget : public ButtonWidget { class DropdownButtonWidget : public ButtonWidget {
public: public:
DropdownButtonWidget(GuiObject *boss, int x, int y, int w, int h, const Common::U32String &label, const Common::U32String &tooltip = Common::U32String(), uint32 cmd = 0, uint8 hotkey = 0); DropdownButtonWidget(GuiObject *boss, int x, int y, int w, int h, const Common::U32String &label, const Common::U32String &tooltip = Common::U32String(), uint32 cmd = 0, uint8 hotkey = 0, const Common::U32String &lowresLabel = Common::U32String());
DropdownButtonWidget(GuiObject *boss, const Common::String &name, const Common::U32String &label, const Common::U32String &tooltip = Common::U32String(), uint32 cmd = 0, uint8 hotkey = 0); DropdownButtonWidget(GuiObject *boss, const Common::String &name, const Common::U32String &label, const Common::U32String &tooltip = Common::U32String(), uint32 cmd = 0, uint8 hotkey = 0, const Common::U32String &lowresLabel = Common::U32String());
void handleMouseMoved(int x, int y, int button) override; void handleMouseMoved(int x, int y, int button) override;
void handleMouseUp(int x, int y, int button, int clickCount) override; void handleMouseUp(int x, int y, int button, int clickCount) override;