From eb28c5a09288e563011b11eafea1c772a7127e7f Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Sat, 28 Dec 2019 10:43:58 +0100 Subject: GUI: Use a dialog theme layout for the unknown game dialog --- gui/ThemeEngine.cpp | 4 +- gui/ThemeEngine.h | 2 +- gui/editgamedialog.cpp | 2 +- gui/options.cpp | 4 +- gui/themes/default.inc | 46 +++++++++- gui/themes/scummclassic.zip | Bin 157827 -> 158832 bytes gui/themes/scummclassic/classic_layout.stx | 26 +++++- gui/themes/scummclassic/classic_layout_lowres.stx | 23 +++++ gui/themes/scummmodern.zip | Bin 287886 -> 288886 bytes gui/themes/scummmodern/scummmodern_layout.stx | 27 +++++- .../scummmodern/scummmodern_layout_lowres.stx | 31 ++++++- gui/themes/scummremastered.zip | Bin 285930 -> 286934 bytes gui/themes/scummremastered/remastered_layout.stx | 28 +++++- .../scummremastered/remastered_layout_lowres.stx | 25 +++++- gui/unknown-game-dialog.cpp | 95 ++++----------------- gui/widget.cpp | 4 +- gui/widgets/edittext.cpp | 2 +- gui/widgets/list.cpp | 2 +- gui/widgets/popup.cpp | 2 +- gui/widgets/scrollcontainer.cpp | 18 +--- gui/widgets/scrollcontainer.h | 6 +- 21 files changed, 227 insertions(+), 120 deletions(-) (limited to 'gui') diff --git a/gui/ThemeEngine.cpp b/gui/ThemeEngine.cpp index 946864bf47..9f28547e4d 100644 --- a/gui/ThemeEngine.cpp +++ b/gui/ThemeEngine.cpp @@ -1047,7 +1047,7 @@ void ThemeEngine::drawSlider(const Common::Rect &r, int width, WidgetStateInfo s r2.setWidth(MIN((int16)width, r.width())); // r2.top++; r2.bottom--; r2.left++; r2.right--; - drawWidgetBackground(r, 0, kWidgetBackgroundSlider); + drawWidgetBackground(r, kWidgetBackgroundSlider); drawDD(dd, r2); } @@ -1160,7 +1160,7 @@ void ThemeEngine::drawSurface(const Common::Point &p, const Graphics::Surface &s addDirtyRect(dirtyRect); } -void ThemeEngine::drawWidgetBackground(const Common::Rect &r, uint16 hints, WidgetBackground background) { +void ThemeEngine::drawWidgetBackground(const Common::Rect &r, WidgetBackground background) { if (!ready()) return; diff --git a/gui/ThemeEngine.h b/gui/ThemeEngine.h index db2794cd91..46c8c1ff91 100644 --- a/gui/ThemeEngine.h +++ b/gui/ThemeEngine.h @@ -402,7 +402,7 @@ public: /** @name WIDGET DRAWING METHODS */ //@{ - void drawWidgetBackground(const Common::Rect &r, uint16 hints, WidgetBackground background = kWidgetBackgroundPlain); + void drawWidgetBackground(const Common::Rect &r, WidgetBackground background); void drawButton(const Common::Rect &r, const Common::String &str, WidgetStateInfo state = kStateEnabled, uint16 hints = 0); diff --git a/gui/editgamedialog.cpp b/gui/editgamedialog.cpp index a1e368580f..60feac15d6 100644 --- a/gui/editgamedialog.cpp +++ b/gui/editgamedialog.cpp @@ -185,7 +185,7 @@ EditGameDialog::EditGameDialog(const String &domain) // _graphicsTabId = tab->addTab(g_system->getOverlayWidth() > 320 ? _("Graphics") : _("GFX"), "GameOptions_Graphics"); ScrollContainerWidget *graphicsContainer = new ScrollContainerWidget(tab, "GameOptions_Graphics.Container", "GameOptions_Graphics_Container", kGraphicsTabContainerReflowCmd); - graphicsContainer->setBackgroundType(ThemeEngine::kDialogBackgroundNone); + graphicsContainer->setBackgroundType(ThemeEngine::kWidgetBackgroundNo); graphicsContainer->setTarget(this); if (g_system->getOverlayWidth() > 320) diff --git a/gui/options.cpp b/gui/options.cpp index 599d865ffb..137494f211 100644 --- a/gui/options.cpp +++ b/gui/options.cpp @@ -1551,7 +1551,7 @@ void GlobalOptionsDialog::build() { _graphicsTabId = tab->addTab(g_system->getOverlayWidth() > 320 ? _("Graphics") : _("GFX"), "GlobalOptions_Graphics"); ScrollContainerWidget *graphicsContainer = new ScrollContainerWidget(tab, "GlobalOptions_Graphics.Container", "GlobalOptions_Graphics_Container", kGraphicsTabContainerReflowCmd); graphicsContainer->setTarget(this); - graphicsContainer->setBackgroundType(ThemeEngine::kDialogBackgroundNone); + graphicsContainer->setBackgroundType(ThemeEngine::kWidgetBackgroundNo); addGraphicControls(graphicsContainer, "GlobalOptions_Graphics_Container."); // @@ -1768,7 +1768,7 @@ void GlobalOptionsDialog::build() { ScrollContainerWidget *container = new ScrollContainerWidget(tab, "GlobalOptions_Cloud.Container", "GlobalOptions_Cloud_Container", kCloudTabContainerReflowCmd); container->setTarget(this); - container->setBackgroundType(ThemeEngine::kDialogBackgroundNone); + container->setBackgroundType(ThemeEngine::kWidgetBackgroundNo); setTarget(container); addCloudControls(container, "GlobalOptions_Cloud_Container.", g_system->getOverlayWidth() <= 320); diff --git a/gui/themes/default.inc b/gui/themes/default.inc index 8a56822ba9..affbcb9b4d 100644 --- a/gui/themes/default.inc +++ b/gui/themes/default.inc @@ -1812,9 +1812,9 @@ const char *defaultXML1 = "" "" "" "" -"" +"" "" -"" +"" "" "" "" "" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" "" ; const char *defaultXML4 = "" @@ -4339,6 +4360,27 @@ const char *defaultXML1 = "" "" "" "" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" +"" "" ; const char *defaultXML[] = { defaultXML1, defaultXML2, defaultXML3, defaultXML4 }; diff --git a/gui/themes/scummclassic.zip b/gui/themes/scummclassic.zip index 0414fd0b39..f7c4ddbb1f 100644 Binary files a/gui/themes/scummclassic.zip and b/gui/themes/scummclassic.zip differ diff --git a/gui/themes/scummclassic/classic_layout.stx b/gui/themes/scummclassic/classic_layout.stx index 9ec0350f47..0cbe043da9 100644 --- a/gui/themes/scummclassic/classic_layout.stx +++ b/gui/themes/scummclassic/classic_layout.stx @@ -955,9 +955,9 @@ - + - + + + + + + + + + + + + + + diff --git a/gui/themes/scummclassic/classic_layout_lowres.stx b/gui/themes/scummclassic/classic_layout_lowres.stx index 473c336a00..f735acb93c 100644 --- a/gui/themes/scummclassic/classic_layout_lowres.stx +++ b/gui/themes/scummclassic/classic_layout_lowres.stx @@ -1777,6 +1777,29 @@ + + + + + + + + + + + + + + diff --git a/gui/themes/scummmodern.zip b/gui/themes/scummmodern.zip index 1c8f107df7..bf3bcc1e57 100644 Binary files a/gui/themes/scummmodern.zip and b/gui/themes/scummmodern.zip differ diff --git a/gui/themes/scummmodern/scummmodern_layout.stx b/gui/themes/scummmodern/scummmodern_layout.stx index 71f3d78ff6..537368f6db 100644 --- a/gui/themes/scummmodern/scummmodern_layout.stx +++ b/gui/themes/scummmodern/scummmodern_layout.stx @@ -968,9 +968,9 @@ - + - + + + + + + + + + + + + + + + diff --git a/gui/themes/scummmodern/scummmodern_layout_lowres.stx b/gui/themes/scummmodern/scummmodern_layout_lowres.stx index c5e0155011..6d26505e56 100644 --- a/gui/themes/scummmodern/scummmodern_layout_lowres.stx +++ b/gui/themes/scummmodern/scummmodern_layout_lowres.stx @@ -922,12 +922,12 @@ + /> - - + /> + + @@ -1795,6 +1795,29 @@ + + + + + + + + + + + + + + diff --git a/gui/themes/scummremastered.zip b/gui/themes/scummremastered.zip index 5ed31519a3..bf23c0ac8a 100644 Binary files a/gui/themes/scummremastered.zip and b/gui/themes/scummremastered.zip differ diff --git a/gui/themes/scummremastered/remastered_layout.stx b/gui/themes/scummremastered/remastered_layout.stx index c5d8eef5c2..895b0b9e4c 100644 --- a/gui/themes/scummremastered/remastered_layout.stx +++ b/gui/themes/scummremastered/remastered_layout.stx @@ -968,9 +968,9 @@ - + - + + + + + + + + + + + + + + + + diff --git a/gui/themes/scummremastered/remastered_layout_lowres.stx b/gui/themes/scummremastered/remastered_layout_lowres.stx index fa81408d82..6d26505e56 100644 --- a/gui/themes/scummremastered/remastered_layout_lowres.stx +++ b/gui/themes/scummremastered/remastered_layout_lowres.stx @@ -611,7 +611,7 @@ - + @@ -1795,6 +1795,29 @@ + + + + + + + + + + + + + + diff --git a/gui/unknown-game-dialog.cpp b/gui/unknown-game-dialog.cpp index cdbfcd4e97..b443334347 100644 --- a/gui/unknown-game-dialog.cpp +++ b/gui/unknown-game-dialog.cpp @@ -38,36 +38,35 @@ enum { kCopyToClipboard = 'cpcl', kOpenBugtrackerURL = 'ourl', kClose = 'clse', - kAddAnyway = 'adda', - kScrollContainerReflow = 'SCRf' + kAddAnyway = 'adda' }; UnknownGameDialog::UnknownGameDialog(const DetectedGame &detectedGame) : - Dialog(30, 20, 260, 124), + Dialog("UnknownGameDialog"), _detectedGame(detectedGame) { - // For now place the buttons with a default place and size. They will be resized and moved when rebuild() is called. - _closeButton = new ButtonWidget(this, 0, 0, 0, 0, detectedGame.canBeAdded ? _("Cancel") : _("Close"), 0, kClose); if (detectedGame.canBeAdded) { - _addAnywayButton = new ButtonWidget(this, 0, 0, 0, 0, _("Add anyway"), 0, kAddAnyway); + _addAnywayButton = new ButtonWidget(this, "UnknownGameDialog.Add", _("Add anyway"), 0, kAddAnyway); } else { _addAnywayButton = nullptr; } + _closeButton = new ButtonWidget(this, "UnknownGameDialog.Close", detectedGame.canBeAdded ? _("Cancel") : _("Close"), 0, kClose); + //Check if we have clipboard functionality if (g_system->hasFeature(OSystem::kFeatureClipboardSupport)) { - _copyToClipboardButton = new ButtonWidget(this, 0, 0, 0, 0, _("Copy to clipboard"), 0, kCopyToClipboard); + _copyToClipboardButton = new ButtonWidget(this, "UnknownGameDialog.Copy", _("Copy to clipboard"), 0, kCopyToClipboard); } else _copyToClipboardButton = nullptr; //Check if we have support for opening URLs if (g_system->hasFeature(OSystem::kFeatureOpenUrl)) { - _openBugTrackerUrlButton = new ButtonWidget(this, 0, 0, 0, 0, _("Report game"), 0, kOpenBugtrackerURL); + _openBugTrackerUrlButton = new ButtonWidget(this, "UnknownGameDialog.Report", _("Report game"), 0, kOpenBugtrackerURL); } else _openBugTrackerUrlButton = nullptr; // Use a ScrollContainer for the report in case we have a lot of lines. - _textContainer = new ScrollContainerWidget(this, 0, 0, 0, 0, kScrollContainerReflow); + _textContainer = new ScrollContainerWidget(this, "UnknownGameDialog.TextContainer", ""); _textContainer->setTarget(this); rebuild(); @@ -78,28 +77,22 @@ void UnknownGameDialog::handleMouseWheel(int x, int y, int direction) { } void UnknownGameDialog::reflowLayout() { - rebuild(); Dialog::reflowLayout(); + rebuild(); } void UnknownGameDialog::rebuild() { - // TODO: Use a theme layout dialog definition - // First remove the old text widgets for (uint i = 0; i < _textWidgets.size() ; i++) { _textContainer->removeWidget(_textWidgets[i]); + + // Also remove the widget from the dialog for the case it was + // the active widget. + removeWidget(_textWidgets[i]); delete _textWidgets[i]; } _textWidgets.clear(); - // Work out dialog size and position of the various elements in the dialog. - // Limit the width of the dialog to 600 - 2 * 10 pixels. - const int screenW = MIN((int)g_system->getOverlayWidth(), 600); - const int screenH = g_system->getOverlayHeight(); - - int buttonHeight = g_gui.xmlEval()->getVar("Globals.Button.Height", 0); - int buttonWidth = g_gui.xmlEval()->getVar("Globals.Button.Width", 0); - Common::String reportTranslated = generateUnknownGameReport(_detectedGame, true, true); // Check if we have clipboard functionality and expand the reportTranslated message if needed... @@ -113,64 +106,14 @@ void UnknownGameDialog::rebuild() { reportTranslated += _("You can also directly report your game to the Bug Tracker."); } - // We use a ScrollContainer to display the text, with a 2 * 8 pixels margin to the dialog border, - // the scrollbar, and 2 * 10 margin for the text in the container. - // We also keep 2 * 10 pixels between the screen border and the dialog. - int scrollbarWidth = g_gui.xmlEval()->getVar("Globals.Scrollbar.Width", 0); + // We use a ScrollContainer to display the text, with a 2 * 10 margin for the text in the container. Common::Array lines; - int maxlineWidth = g_gui.getFont().wordWrapText(reportTranslated, screenW - 2 * 20 - 16 - scrollbarWidth, lines); - - int lineCount = lines.size() + 1; - - _h = MIN(screenH - 20, lineCount * kLineHeight + kLineHeight + buttonHeight + 24); - - int closeButtonWidth = MAX(buttonWidth, g_gui.getFont().getStringWidth(_closeButton->getLabel()) + 10); - int copyToClipboardButtonWidth = 0, openBugtrackerURLButtonWidth = 0, addAnywayButtonWidth = 0; - int totalButtonWidth = closeButtonWidth; - - if (_copyToClipboardButton) { - copyToClipboardButtonWidth = MAX(buttonWidth, g_gui.getFont().getStringWidth(_copyToClipboardButton->getLabel()) + 10); - totalButtonWidth += copyToClipboardButtonWidth + 10; - } - if (_openBugTrackerUrlButton) { - openBugtrackerURLButtonWidth = MAX(buttonWidth, g_gui.getFont().getStringWidth(_openBugTrackerUrlButton->getLabel()) + 10); - totalButtonWidth += openBugtrackerURLButtonWidth + 10; - } - if (_addAnywayButton) { - addAnywayButtonWidth = MAX(buttonWidth, g_gui.getFont().getStringWidth(_addAnywayButton->getLabel()) + 10); - totalButtonWidth += addAnywayButtonWidth + 10; - } + g_gui.getFont().wordWrapText(reportTranslated, _textContainer->getWidth() - 20, lines); - _w = MAX(MAX(maxlineWidth, 0) + 16 + scrollbarWidth, totalButtonWidth) + 20; - - // Center the dialog on the screen - _x = (g_system->getOverlayWidth() - _w) / 2; - _y = (g_system->getOverlayHeight() - _h) / 2; - - // Now move the buttons and text container to their proper place - int buttonPos = _w - 10; - if (_addAnywayButton) { - buttonPos -= addAnywayButtonWidth + 5; - _addAnywayButton->resize(buttonPos, _h - buttonHeight - 8, addAnywayButtonWidth, buttonHeight); - } - buttonPos -= closeButtonWidth + 5; - _closeButton->resize(buttonPos, _h - buttonHeight - 8, closeButtonWidth, buttonHeight); - if (_copyToClipboardButton) { - buttonPos -= copyToClipboardButtonWidth + 5; - _copyToClipboardButton->resize(buttonPos, _h - buttonHeight - 8, copyToClipboardButtonWidth, buttonHeight); - } - if (_openBugTrackerUrlButton) { - buttonPos -= openBugtrackerURLButtonWidth + 5; - _openBugTrackerUrlButton->resize(buttonPos, _h - buttonHeight - 8, openBugtrackerURLButtonWidth, buttonHeight); - } - - int containerHeight = _h - kLineHeight - buttonHeight - 16; - _textContainer->resize(8, 8, _w - 16, containerHeight); - - // And create text widgets + // Create text widgets uint y = 8; for (uint i = 0; i < lines.size() ; i++) { - StaticTextWidget *widget = new StaticTextWidget(_textContainer, 10, y, _w - 36 - scrollbarWidth, kLineHeight, lines[i], Graphics::kTextAlignLeft); + StaticTextWidget *widget = new StaticTextWidget(_textContainer, 10, y, _textContainer->getWidth() - 20, kLineHeight, lines[i], Graphics::kTextAlignLeft); _textWidgets.push_back(widget); y += kLineHeight; } @@ -228,10 +171,6 @@ void UnknownGameDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 case kOpenBugtrackerURL: g_system->openUrl(generateBugtrackerURL()); break; - case kScrollContainerReflow: - for (uint i = 0; i < _textWidgets.size() ; i++) - _textWidgets[i]->setVisible(true); - break; default: break; } diff --git a/gui/widget.cpp b/gui/widget.cpp index 17098df6ea..1a81d8fba1 100644 --- a/gui/widget.cpp +++ b/gui/widget.cpp @@ -115,7 +115,7 @@ void Widget::draw() { // Draw border if (_flags & WIDGET_BORDER) { - g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y, _x + _w, _y + _h), 0, + g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y, _x + _w, _y + _h), ThemeEngine::kWidgetBackgroundBorder); _x += 4; _y += 4; @@ -900,7 +900,7 @@ void ContainerWidget::setBackgroundType(ThemeEngine::WidgetBackground background } void ContainerWidget::drawWidget() { - g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y, _x + _w, _y + _h), 0, _backgroundType); + g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y, _x + _w, _y + _h), _backgroundType); } } // End of namespace GUI diff --git a/gui/widgets/edittext.cpp b/gui/widgets/edittext.cpp index e2dcd2be3e..ff21b3d3a9 100644 --- a/gui/widgets/edittext.cpp +++ b/gui/widgets/edittext.cpp @@ -90,7 +90,7 @@ void EditTextWidget::handleMouseDown(int x, int y, int button, int clickCount) { } void EditTextWidget::drawWidget() { - g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y, _x + _w, _y + _h), 0, + g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y, _x + _w, _y + _h), ThemeEngine::kWidgetBackgroundEditText); // Draw the text diff --git a/gui/widgets/list.cpp b/gui/widgets/list.cpp index 9144282e65..8bdc002a8e 100644 --- a/gui/widgets/list.cpp +++ b/gui/widgets/list.cpp @@ -520,7 +520,7 @@ void ListWidget::drawWidget() { Common::String buffer; // Draw a thin frame around the list. - g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y, _x + _w, _y + _h), 0, + g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y, _x + _w, _y + _h), ThemeEngine::kWidgetBackgroundBorder); // Draw the list items diff --git a/gui/widgets/popup.cpp b/gui/widgets/popup.cpp index ebb69f1e4d..aa87e1e835 100644 --- a/gui/widgets/popup.cpp +++ b/gui/widgets/popup.cpp @@ -130,7 +130,7 @@ void PopUpDialog::drawDialog(DrawLayer layerToDraw) { Dialog::drawDialog(layerToDraw); // Draw the menu border - g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y, _x + _w, _y + _h), 0); + g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y, _x + _w, _y + _h), ThemeEngine::kWidgetBackgroundPlain); /*if (_twoColumns) g_gui.vLine(_x + _w / 2, _y, _y + _h - 2, g_gui._color);*/ diff --git a/gui/widgets/scrollcontainer.cpp b/gui/widgets/scrollcontainer.cpp index e0680e123b..ac79f844f9 100644 --- a/gui/widgets/scrollcontainer.cpp +++ b/gui/widgets/scrollcontainer.cpp @@ -41,7 +41,7 @@ ScrollContainerWidget::ScrollContainerWidget(GuiObject *boss, const Common::Stri void ScrollContainerWidget::init() { setFlags(WIDGET_ENABLED); _type = kScrollContainerWidget; - _backgroundType = ThemeEngine::kDialogBackgroundDefault; + _backgroundType = ThemeEngine::kWidgetBackgroundPlain; _verticalScroll = new ScrollBarWidget(this, _w-16, 0, 16, _h); _verticalScroll->setTarget(this); _scrolledX = 0; @@ -136,24 +136,12 @@ void ScrollContainerWidget::reflowLayout() { //recalculate height recalc(); - //hide those widgets which are out of visible area - ptr = _firstWidget; - while (ptr) { - int y = ptr->getAbsY() - getChildY(); - int h = ptr->getHeight(); - bool visible = ptr->isVisible(); - if (y + h - _scrolledY < 0) visible = false; - if (y - _scrolledY > _limitH) visible = false; - ptr->setVisible(visible); - ptr = ptr->next(); - } - _verticalScroll->setVisible(_verticalScroll->_numEntries > _limitH); //show when there is something to scroll _verticalScroll->recalc(); } void ScrollContainerWidget::drawWidget() { - g_gui.theme()->drawDialogBackground(Common::Rect(_x, _y, _x + _w, _y + getHeight()), _backgroundType); + g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y, _x + _w, _y + getHeight()), _backgroundType); } bool ScrollContainerWidget::containsWidget(Widget *w) const { @@ -176,7 +164,7 @@ Common::Rect ScrollContainerWidget::getClipRect() const { return Common::Rect(getAbsX(), getAbsY(), getAbsX() + _w, getAbsY() + getHeight() - 1); // this -1 is because of container border, which might not be present actually } -void ScrollContainerWidget::setBackgroundType(ThemeEngine::DialogBackground backgroundType) { +void ScrollContainerWidget::setBackgroundType(ThemeEngine::WidgetBackground backgroundType) { _backgroundType = backgroundType; } diff --git a/gui/widgets/scrollcontainer.h b/gui/widgets/scrollcontainer.h index fd8db765a3..d534a6352b 100644 --- a/gui/widgets/scrollcontainer.h +++ b/gui/widgets/scrollcontainer.h @@ -34,7 +34,7 @@ class ScrollContainerWidget: public Widget, public CommandSender { int16 _scrolledX, _scrolledY; uint16 _limitH; uint32 _reflowCmd; - ThemeEngine::DialogBackground _backgroundType; + ThemeEngine::WidgetBackground _backgroundType; Common::String _dialogName; void recalc(); @@ -52,11 +52,10 @@ public: Common::Rect getClipRect() const override; - void setBackgroundType(ThemeEngine::DialogBackground backgroundType); + void setBackgroundType(ThemeEngine::WidgetBackground backgroundType); void handleMouseWheel(int x, int y, int direction) override; -protected: // We overload getChildY to make sure child widgets are positioned correctly. // Essentially this compensates for the space taken up by the tab title header. int16 getChildX() const override; @@ -64,6 +63,7 @@ protected: uint16 getWidth() const override; uint16 getHeight() const override; +protected: void drawWidget() override; Widget *findWidget(int x, int y) override; -- cgit v1.2.3