[Scummvm-git-logs] scummvm master -> 201b347ebdef47e7d4e29cff5937e02baf9bc052

criezy criezy at scummvm.org
Mon May 28 23:21:56 CEST 2018


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
42cd3e9596 GUI: Use ScrollContainerWidget in unknown game dialog
201b347ebd GUI: Improve layout update for UnknownGameDialog


Commit: 42cd3e9596e7004060518081b694a3e59efd6496
    https://github.com/scummvm/scummvm/commit/42cd3e9596e7004060518081b694a3e59efd6496
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2018-05-28T22:21:10+01:00

Commit Message:
GUI: Use ScrollContainerWidget in unknown game dialog

This should fix issues when the text to display in the dialog is
too big to fit on the screen.

Changed paths:
    gui/unknown-game-dialog.cpp
    gui/unknown-game-dialog.h


diff --git a/gui/unknown-game-dialog.cpp b/gui/unknown-game-dialog.cpp
index 01526d2..80446c5 100644
--- a/gui/unknown-game-dialog.cpp
+++ b/gui/unknown-game-dialog.cpp
@@ -30,13 +30,15 @@
 #include "gui/message.h"
 #include "gui/ThemeEval.h"
 #include "gui/widgets/popup.h"
+#include "gui/widgets/scrollcontainer.h"
 
 namespace GUI {
 
 enum {
 	kCopyToClipboard = 'cpcl',
 	kOpenBugtrackerURL = 'ourl',
-	kClose = 'clse'
+	kClose = 'clse',
+	kScrollContainerReflow = 'SCRf'
 };
 
 UnknownGameDialog::UnknownGameDialog(const DetectionResults &detectionResults) :
@@ -59,16 +61,22 @@ UnknownGameDialog::UnknownGameDialog(const DetectionResults &detectionResults) :
 #endif
 
 	const int screenW = g_system->getOverlayWidth();
+	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);
 
 	// 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.
+	int scrollbarWidth = g_gui.xmlEval()->getVar("Globals.Scrollbar.Width", 0);
 	Common::Array<Common::String> lines;
-	int maxlineWidth = g_gui.getFont().wordWrapText(reportTranslated, screenW - 2 * 20, lines);
+	int maxlineWidth = g_gui.getFont().wordWrapText(reportTranslated, screenW - 2 * 20 - 16 - scrollbarWidth, lines);
+
 	int lineCount = lines.size() + 1;
 
-	_h =  3 * kLineHeight + lineCount * kLineHeight;
+	_h = MIN(screenH - 20, lineCount * kLineHeight + kLineHeight + buttonHeight + 24);
 
 	// Buttons
 	int closeButtonWidth = MAX(buttonWidth, g_gui.getFont().getStringWidth(_("Close")) + 10);
@@ -80,7 +88,7 @@ UnknownGameDialog::UnknownGameDialog(const DetectionResults &detectionResults) :
 	if (g_system->hasFeature(OSystem::kFeatureOpenUrl))
 		totalButtonWidth += 10 + openBugtrackerURLButtonWidth;
 
-	_w = MAX(MAX(maxlineWidth, 0), totalButtonWidth) + 20;
+	_w = MAX(MAX(maxlineWidth, 0) + 16 + scrollbarWidth, totalButtonWidth) + 20;
 
 	int buttonPos = _w - closeButtonWidth - 10;
 	new ButtonWidget(this, buttonPos, _h - buttonHeight - 8, buttonWidth, buttonHeight, _("Close"), 0, kClose);
@@ -107,10 +115,14 @@ UnknownGameDialog::UnknownGameDialog(const DetectionResults &detectionResults) :
 #endif
 
 	// Each line is represented by one static text item.
-	// TODO: Use a ScrollContainer widget instead of truncated text.
-	uint y = 10;
-	for (uint i = 0; i < lines.size(); i++) {
-		new StaticTextWidget(this, 10, y, _w, kLineHeight, lines[i], Graphics::kTextAlignLeft);
+	// Use a ScrollContainer for the report in case we have a lot of lines.
+	int containerHeight = _h - kLineHeight - buttonHeight - 8;
+	ScrollContainerWidget *container = new ScrollContainerWidget(this, 8, 8, _w - 16, containerHeight, kScrollContainerReflow);
+	container->setTarget(this);
+	uint y = 8;
+	for (uint i = 0; i < lines.size() ; i++) {
+		StaticTextWidget *widget = new StaticTextWidget(container, 10, y, _w - 36 - scrollbarWidth, kLineHeight, lines[i], Graphics::kTextAlignLeft);
+		_textWidgets.push_back(widget);
 		y += kLineHeight;
 	}
 }
@@ -160,6 +172,10 @@ 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;
 	}
 }
 
diff --git a/gui/unknown-game-dialog.h b/gui/unknown-game-dialog.h
index f7f9d5c..79a1acf 100644
--- a/gui/unknown-game-dialog.h
+++ b/gui/unknown-game-dialog.h
@@ -24,11 +24,13 @@
 #define GUI_UNKNOWN_GAME_DIALOG_H
 
 #include "gui/dialog.h"
-
+#include "common/array.h"
 #include "engines/game.h"
 
 namespace GUI {
 
+class StaticTextWidget;
+
 class UnknownGameDialog : public Dialog {
 public:
 	UnknownGameDialog(const DetectionResults &detectionResults);
@@ -41,6 +43,7 @@ private:
 	Common::String generateBugtrackerURL();
 
 	const DetectionResults &_detectionResults;
+	Common::Array<GUI::StaticTextWidget *> _textWidgets;
 };
 
 } // End of namespace GUI


Commit: 201b347ebdef47e7d4e29cff5937e02baf9bc052
    https://github.com/scummvm/scummvm/commit/201b347ebdef47e7d4e29cff5937e02baf9bc052
Author: Thierry Crozat (criezy at scummvm.org)
Date: 2018-05-28T22:21:10+01:00

Commit Message:
GUI: Improve layout update for UnknownGameDialog

Previously the dialog was not resized and was just recentered on
the screen when the overlay size changed. Now it is properly
resized as well.

Changed paths:
    gui/unknown-game-dialog.cpp
    gui/unknown-game-dialog.h


diff --git a/gui/unknown-game-dialog.cpp b/gui/unknown-game-dialog.cpp
index 80446c5..561d394 100644
--- a/gui/unknown-game-dialog.cpp
+++ b/gui/unknown-game-dialog.cpp
@@ -44,6 +44,64 @@ enum {
 UnknownGameDialog::UnknownGameDialog(const DetectionResults &detectionResults) :
 		Dialog(30, 20, 260, 124),
 		_detectionResults(detectionResults) {
+	// 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, _("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);
+	} 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 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 ScrollContainerWidget(this, 0, 0, 0, 0, kScrollContainerReflow);
+	_textContainer->setTarget(this);
+
+	rebuild();
+}
+
+void UnknownGameDialog::reflowLayout() {
+	rebuild();
+	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 buttonHeight = g_gui.xmlEval()->getVar("Globals.Button.Height", 0);
+	int buttonWidth = g_gui.xmlEval()->getVar("Globals.Button.Width", 0);
+
 	Common::String reportTranslated = _detectionResults.generateUnknownGameReport(true);
 
 	// Check if we have clipboard functionality and expand the reportTranslated message if needed...
@@ -60,13 +118,6 @@ UnknownGameDialog::UnknownGameDialog(const DetectionResults &detectionResults) :
 	}
 #endif
 
-	const int screenW = g_system->getOverlayWidth();
-	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);
-
-	// 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.
@@ -78,60 +129,47 @@ UnknownGameDialog::UnknownGameDialog(const DetectionResults &detectionResults) :
 
 	_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 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 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 ButtonWidget(this, buttonPos, _h - buttonHeight - 8, openBugtrackerURLButtonWidth, buttonHeight, _("Report game"), 0, kOpenBugtrackerURL);
+		_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;
-	ScrollContainerWidget *container = new 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++) {
-		StaticTextWidget *widget = new StaticTextWidget(container, 10, y, _w - 36 - scrollbarWidth, kLineHeight, lines[i], Graphics::kTextAlignLeft);
+		StaticTextWidget *widget = new 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;
-	Dialog::reflowLayout();
-}
 
 Common::String UnknownGameDialog::generateBugtrackerURL() {
 	// TODO: Remove the filesystem path from the bugtracker report
diff --git a/gui/unknown-game-dialog.h b/gui/unknown-game-dialog.h
index 79a1acf..bad61d7 100644
--- a/gui/unknown-game-dialog.h
+++ b/gui/unknown-game-dialog.h
@@ -30,12 +30,16 @@
 namespace GUI {
 
 class StaticTextWidget;
+class ScrollContainerWidget;
+class ButtonWidget;
 
 class UnknownGameDialog : public Dialog {
 public:
 	UnknownGameDialog(const DetectionResults &detectionResults);
 
 private:
+	void rebuild();
+
 	// Dialog API
 	void handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data) override;
 	void reflowLayout() override;
@@ -43,7 +47,11 @@ private:
 	Common::String generateBugtrackerURL();
 
 	const DetectionResults &_detectionResults;
-	Common::Array<GUI::StaticTextWidget *> _textWidgets;
+	ScrollContainerWidget *_textContainer;
+	Common::Array<StaticTextWidget *> _textWidgets;
+	ButtonWidget* _openBugTrackerUrlButton;
+	ButtonWidget* _copyToClipboardButton;
+	ButtonWidget* _closeButton;
 };
 
 } // End of namespace GUI





More information about the Scummvm-git-logs mailing list