aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThierry Crozat2018-04-29 21:45:32 +0100
committerThierry Crozat2018-04-29 21:47:10 +0100
commit8cb9eebd8a8f7cae2dbb68ad3398f444426929c1 (patch)
tree3a84d4589adaecc51a8022d894e27a7f2cb2b594
parentcf529f311f0be1332f6286b95741160e85651441 (diff)
downloadscummvm-rg350-8cb9eebd8a8f7cae2dbb68ad3398f444426929c1.tar.gz
scummvm-rg350-8cb9eebd8a8f7cae2dbb68ad3398f444426929c1.tar.bz2
scummvm-rg350-8cb9eebd8a8f7cae2dbb68ad3398f444426929c1.zip
ENGINES: Improve update of the Unknown Game Dialog when the overlay size changes
Previously the dialog was not resized and was just recentered on the screen. Now it is properly resized as well.
-rw-r--r--engines/advancedDetector.cpp1
-rw-r--r--engines/unknown-game-dialog.cpp126
-rw-r--r--engines/unknown-game-dialog.h9
3 files changed, 88 insertions, 48 deletions
diff --git a/engines/advancedDetector.cpp b/engines/advancedDetector.cpp
index dbe2cdfd68..0d01656cc8 100644
--- a/engines/advancedDetector.cpp
+++ b/engines/advancedDetector.cpp
@@ -357,7 +357,6 @@ void AdvancedMetaEngine::reportUnknown(const Common::FSNode &path, const ADFileP
report += "\n\n";
reportTranslated += "\n\n";
- reportTranslated.wordWrap(65);
Common::String reportLog = report;
reportLog.wordWrap(80);
diff --git a/engines/unknown-game-dialog.cpp b/engines/unknown-game-dialog.cpp
index 91a593c9b8..0314d2a8fd 100644
--- a/engines/unknown-game-dialog.cpp
+++ b/engines/unknown-game-dialog.cpp
@@ -58,13 +58,64 @@ UnknownGameDialog::UnknownGameDialog(const Common::String &reportData, const Com
}
#endif
- const int screenW = g_system->getOverlayWidth();
+ // For now place the buttons with a default place and size. They will be resized and moved when rebuild() is called.
+ _closeButton = new GUI::ButtonWidget(this, 0, 0, 0, 0, _("Close"), 0, kClose);
+
+ //Check if we have clipboard functionality
+ if (g_system->hasFeature(OSystem::kFeatureClipboardSupport)) {
+ _copyToClipboardButton = new GUI::ButtonWidget(this, 0, 0, 0, 0, _("Copy to clipboard"), 0, kCopyToClipboard);
+ } else
+ _copyToClipboardButton = nullptr;
+
+#if 0
+ // Do not create the button for reporting the game directly to the bugtracker
+ // for now until we find a proper solution for the problem that a change
+ // to our bugtracker system might break the URL generation. A possible approach
+ // for solving this would be to have a ULR under the .scummvm.org (of the type
+ // https://www.scummvm.org/unknowngame?engine=Foo&description=Bar) that would
+ // redirect to whatever our bugtracker system is.
+
+ //Check if we have support for opening URLs
+ if (g_system->hasFeature(OSystem::kFeatureOpenUrl)) {
+ buttonPos -= openBugtrackerURLButtonWidth + 5;
+ _openBugTrackerUrlButton = new GUI::ButtonWidget(this, 0, 0, 0, 0, _("Report game"), 0, kOpenBugtrackerURL);
+ //Formatting the reportData for bugtracker submission [replace line breaks]...
+ _bugtrackerGameData = _reportData;
+ while (_bugtrackerGameData.contains("\n")) {
+ Common::replace(_bugtrackerGameData, "\n", "%0A");
+ }
+ } else
+#endif
+ _openBugTrackerUrlButton = nullptr;
+
+ // Use a ScrollContainer for the report in case we have a lot of lines.
+ _textContainer = new GUI::ScrollContainerWidget(this, 0, 0, 0, 0, kScrollContainerReflow);
+ _textContainer->setTarget(this);
+
+ rebuild();
+}
+
+void UnknownGameDialog::reflowLayout() {
+ rebuild();
+ GUI::Dialog::reflowLayout();
+}
+
+void UnknownGameDialog::rebuild() {
+ // First remove the old text widgets
+ for (uint i = 0; i < _textWidgets.size() ; i++) {
+ _textContainer->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 buttonWidth = g_gui.xmlEval()->getVar("Globals.Button.Width", 0);
int buttonHeight = g_gui.xmlEval()->getVar("Globals.Button.Height", 0);
+ int buttonWidth = g_gui.xmlEval()->getVar("Globals.Button.Width", 0);
- //Calculate the size the dialog needs
// 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.
@@ -76,66 +127,47 @@ UnknownGameDialog::UnknownGameDialog(const Common::String &reportData, const Com
_h = MIN(screenH - 20, lineCount * kLineHeight + kLineHeight + buttonHeight + 24);
- // Buttons
- int closeButtonWidth = MAX(buttonWidth, g_gui.getFont().getStringWidth(_("Close")) + 10);
- int copyToClipboardButtonWidth = MAX(buttonWidth, g_gui.getFont().getStringWidth(_("Copy to clipboard")) + 10);
- int openBugtrackerURLButtonWidth = MAX(buttonWidth, g_gui.getFont().getStringWidth(_("Report game")) + 10);
- int totalButtonWidth = closeButtonWidth;
- if (g_system->hasFeature(OSystem::kFeatureClipboardSupport))
- totalButtonWidth += 10 + copyToClipboardButtonWidth;
- if (g_system->hasFeature(OSystem::kFeatureOpenUrl))
- totalButtonWidth += 10 + openBugtrackerURLButtonWidth;
+ int closeButtonWidth = MAX(buttonWidth, g_gui.getFont().getStringWidth(_closeButton->getLabel()) + 10);
+ int copyToClipboardButtonWidth = 0, openBugtrackerURLButtonWidth = 0, 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;
+ }
_w = MAX(MAX(maxlineWidth, 0) + 16 + scrollbarWidth, totalButtonWidth) + 20;
- int buttonPos = _w - closeButtonWidth - 10;
- new GUI::ButtonWidget(this, buttonPos, _h - buttonHeight - 8, buttonWidth, buttonHeight, _("Close"), 0, kClose);
+ // Center the dialog on the screen
+ _x = (g_system->getOverlayWidth() - _w) / 2;
+ _y = (g_system->getOverlayHeight() - _h) / 2;
- //Check if we have clipboard functionality
- if (g_system->hasFeature(OSystem::kFeatureClipboardSupport)) {
+ // Now move the buttons and text container to their proper place
+ int buttonPos = _w - closeButtonWidth - 10;
+ _closeButton->resize(buttonPos, _h - buttonHeight - 8, closeButtonWidth, buttonHeight);
+ if (_copyToClipboardButton) {
buttonPos -= copyToClipboardButtonWidth + 5;
- new GUI::ButtonWidget(this, buttonPos, _h - buttonHeight - 8, copyToClipboardButtonWidth, buttonHeight, _("Copy to clipboard"), 0, kCopyToClipboard);
+ _copyToClipboardButton->resize(buttonPos, _h - buttonHeight - 8, copyToClipboardButtonWidth, buttonHeight);
}
-
-#if 0
- // Do not create the button for reporting the game directly to the bugtracker
- // for now until we find a proper solution for the problem that a change
- // to our bugtracker system might break the URL generation. A possible approach
- // for solving this would be to have a ULR under the .scummvm.org (of the type
- // https://www.scummvm.org/unknowngame?engine=Foo&description=Bar) that would
- // redirect to whatever our bugtracker system is.
-
- //Check if we have support for opening URLs
- if (g_system->hasFeature(OSystem::kFeatureOpenUrl)) {
+ if (_openBugTrackerUrlButton) {
buttonPos -= openBugtrackerURLButtonWidth + 5;
- new GUI::ButtonWidget(this, buttonPos, _h - buttonHeight - 8, openBugtrackerURLButtonWidth, buttonHeight, _("Report game"), 0, kOpenBugtrackerURL);
- //Formatting the reportData for bugtracker submission [replace line breaks]...
- _bugtrackerGameData = _reportData;
- while (_bugtrackerGameData.contains("\n")) {
- Common::replace(_bugtrackerGameData, "\n", "%0A");
- }
+ _openBugTrackerUrlButton->resize(buttonPos, _h - buttonHeight - 8, openBugtrackerURLButtonWidth, buttonHeight);
}
-#endif
- // Each line is represented by one static text item.
- // Use a ScrollContainer for the report in case we have a lot of lines.
- int containerHeight = _h - kLineHeight - buttonHeight - 8;
- GUI::ScrollContainerWidget *container = new GUI::ScrollContainerWidget(this, 8, 8, _w - 16, containerHeight, kScrollContainerReflow);
- container->setTarget(this);
+ int containerHeight = _h - kLineHeight - buttonHeight - 16;
+ _textContainer->resize(8, 8, _w - 16, containerHeight);
+
+ // And create text widgets
uint y = 8;
for (uint i = 0; i < lines.size() ; i++) {
- GUI::StaticTextWidget *widget = new GUI::StaticTextWidget(container, 10, y, _w - 36 - scrollbarWidth, kLineHeight, lines[i], Graphics::kTextAlignLeft);
+ GUI::StaticTextWidget *widget = new GUI::StaticTextWidget(_textContainer, 10, y, _w - 36 - scrollbarWidth, kLineHeight, lines[i], Graphics::kTextAlignLeft);
_textWidgets.push_back(widget);
y += kLineHeight;
}
}
-void UnknownGameDialog::reflowLayout() {
- _x = (g_system->getOverlayWidth() - _w) / 2;
- _y = (g_system->getOverlayHeight() - _h) / 2;
- GUI::Dialog::reflowLayout();
-}
-
Common::String UnknownGameDialog::generateBugtrackerURL() {
return Common::String::format((
"https://bugs.scummvm.org/newticket?"
diff --git a/engines/unknown-game-dialog.h b/engines/unknown-game-dialog.h
index a527339211..4f0e9a495b 100644
--- a/engines/unknown-game-dialog.h
+++ b/engines/unknown-game-dialog.h
@@ -25,6 +25,8 @@
namespace GUI {
class StaticTextWidget;
+ class ScrollContainerWidget;
+ class ButtonWidget;
}
class UnknownGameDialog : public GUI::Dialog {
@@ -34,11 +36,18 @@ public:
virtual Common::String generateBugtrackerURL();
virtual void reflowLayout();
+protected:
+ void rebuild();
+
private:
Common::String _reportData;
Common::String _reportTranslated;
Common::String _bugtrackerGameData;
Common::String _bugtrackerAffectedEngine;
+ GUI::ScrollContainerWidget *_textContainer;
Common::Array<GUI::StaticTextWidget*> _textWidgets;
+ GUI::ButtonWidget* _openBugTrackerUrlButton;
+ GUI::ButtonWidget* _copyToClipboardButton;
+ GUI::ButtonWidget* _closeButton;
};