[Scummvm-git-logs] scummvm master -> 6aacdb1938c8e141a6fb0d3ad653cdb57358220e

sev- sev at scummvm.org
Sat May 9 19:59:31 UTC 2020


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:
77c51088ee DIRECTOR: Improved makePathRelative
6aacdb1938 GUI: Normalize width/height parameters


Commit: 77c51088eebbcfa19fe2bc46751ca74ce4a4652d
    https://github.com/scummvm/scummvm/commit/77c51088eebbcfa19fe2bc46751ca74ce4a4652d
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-05-09T21:59:07+02:00

Commit Message:
DIRECTOR: Improved makePathRelative

Now it is able to process "MediaBand\main\title" for opening
MAIN/TITLE.DXR

Changed paths:
    engines/director/util.cpp
    engines/director/util.h


diff --git a/engines/director/util.cpp b/engines/director/util.cpp
index 44c2be83df..599f64abd3 100644
--- a/engines/director/util.cpp
+++ b/engines/director/util.cpp
@@ -149,11 +149,25 @@ Common::String getPath(Common::String path, Common::String cwd) {
 	return cwd; // The path is not altered
 }
 
-Common::String pathMakeRelative(Common::String path, bool recursive) {
-	Common::String initialPath = Common::normalizePath(g_director->getCurrentPath() + convertPath(path), '/');
+Common::String pathMakeRelative(Common::String path, bool recursive, bool addexts) {
+	Common::String initialPath(path);
+
+	// First, convert Windows-style separators
+	if (g_director->getPlatform() == Common::kPlatformWindows) {
+		if (initialPath.contains('\\'))
+			for (uint i = 0; i < initialPath.size(); i++)
+				if (initialPath[i] == '\\')
+					initialPath.setChar('/', i);
+	}
+
+	debug(2, "pathMakeRelative(): s1 %s -> %s", path.c_str(), initialPath.c_str());
+
+	initialPath = Common::normalizePath(g_director->getCurrentPath() + convertPath(initialPath), '/');
 	Common::File f;
 	Common::String convPath = initialPath;
 
+	debug(2, "pathMakeRelative(): s2 %s", convPath.c_str());
+
 	if (f.open(initialPath))
 		return initialPath;
 
@@ -163,10 +177,12 @@ Common::String pathMakeRelative(Common::String path, bool recursive) {
 		int pos = convPath.find('/');
 		convPath = Common::String(&convPath.c_str()[pos + 1]);
 
+		debug(2, "pathMakeRelative(): s3 try %s", convPath.c_str());
+
 		if (!f.open(convPath))
 			continue;
 
-		debug(2, "pathMakeRelative(): Path converted %s -> %s", path.c_str(), convPath.c_str());
+		debug(2, "pathMakeRelative(): s3 converted %s -> %s", path.c_str(), convPath.c_str());
 
 		opened = true;
 
@@ -176,7 +192,7 @@ Common::String pathMakeRelative(Common::String path, bool recursive) {
 	if (!opened && recursive) {
 		// Hmmm. We couldn't find the path as is.
 		// Let's try to translate file path into 8.3 format
-		if (g_director->getPlatform() == Common::kPlatformWindows && g_director->getVersion() < 4) {
+		if (g_director->getPlatform() == Common::kPlatformWindows && g_director->getVersion() < 5) {
 			convPath.clear();
 			const char *ptr = initialPath.c_str();
 			Common::String component;
@@ -198,11 +214,20 @@ Common::String pathMakeRelative(Common::String path, bool recursive) {
 				ptr++;
 			}
 
-			convPath += convertMacFilename(component.c_str()) + ".MMM";
+			Common::String convname = convertMacFilename(component.c_str());
+			debug(2, "pathMakeRelative(): s5 %s -> %s%s", initialPath.c_str(), convPath.c_str(), convname.c_str());
 
-			debug(2, "pathMakeRelative(): Trying %s -> %s", path.c_str(), convPath.c_str());
+			const char *exts[] = { ".MMM", ".DIR", ".DXR", 0 };
+			for (int i = 0; exts[i] && addexts; ++i) {
+				Common::String newpath = convPath + convname + exts[i];
 
-			return pathMakeRelative(convPath, false);
+				debug(2, "pathMakeRelative(): s5 try %s", newpath.c_str());
+
+				Common::String res = pathMakeRelative(newpath, false, false);
+
+				if (!res.equals(newpath))
+					return res;
+			}
 		}
 
 
@@ -211,7 +236,10 @@ Common::String pathMakeRelative(Common::String path, bool recursive) {
 
 	f.close();
 
-	return convPath;
+	if (opened)
+		return convPath;
+	else
+		return initialPath;
 }
 
 //////////////////
diff --git a/engines/director/util.h b/engines/director/util.h
index 30a6f2d95f..f9401f3f6b 100644
--- a/engines/director/util.h
+++ b/engines/director/util.h
@@ -38,7 +38,7 @@ Common::String convertPath(Common::String &path);
 
 Common::String getPath(Common::String path, Common::String cwd);
 
-Common::String pathMakeRelative(Common::String path, bool recursive = true);
+Common::String pathMakeRelative(Common::String path, bool recursive = true, bool addexts = true);
 
 Common::String convertMacFilename(const char *name);
 


Commit: 6aacdb1938c8e141a6fb0d3ad653cdb57358220e
    https://github.com/scummvm/scummvm/commit/6aacdb1938c8e141a6fb0d3ad653cdb57358220e
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-05-09T21:59:07+02:00

Commit Message:
GUI: Normalize width/height parameters

The fact that ThemeLayout had them int, and GuiObject as uint, was
leading to number of unexpected overflows.

Changed paths:
    engines/scumm/dialogs.cpp
    gui/ThemeEval.cpp
    gui/ThemeEval.h
    gui/ThemeLayout.cpp
    gui/ThemeLayout.h
    gui/object.cpp
    gui/options.cpp
    gui/saveload-dialog.cpp


diff --git a/engines/scumm/dialogs.cpp b/engines/scumm/dialogs.cpp
index a65792245d..14bf29e1f2 100644
--- a/engines/scumm/dialogs.cpp
+++ b/engines/scumm/dialogs.cpp
@@ -305,7 +305,7 @@ void HelpDialog::reflowLayout() {
 
 	int lineHeight = g_gui.getFontHeight();
 	int16 x, y;
-	uint16 w, h;
+	int16 w, h;
 
 	assert(lineHeight);
 
diff --git a/gui/ThemeEval.cpp b/gui/ThemeEval.cpp
index 76264e5d10..338e8d315e 100644
--- a/gui/ThemeEval.cpp
+++ b/gui/ThemeEval.cpp
@@ -50,7 +50,7 @@ void ThemeEval::reset() {
 	_layouts.clear();
 }
 
-bool ThemeEval::getWidgetData(const Common::String &widget, int16 &x, int16 &y, uint16 &w, uint16 &h) {
+bool ThemeEval::getWidgetData(const Common::String &widget, int16 &x, int16 &y, int16 &w, int16 &h) {
 	Common::StringTokenizer tokenizer(widget, ".");
 
 	if (widget.hasPrefix("Dialog."))
diff --git a/gui/ThemeEval.h b/gui/ThemeEval.h
index cb36c139aa..053539ef48 100644
--- a/gui/ThemeEval.h
+++ b/gui/ThemeEval.h
@@ -88,7 +88,7 @@ public:
 	bool hasDialog(const Common::String &name);
 
 	void reflowDialogLayout(const Common::String &name, Widget *widgetChain);
-	bool getWidgetData(const Common::String &widget, int16 &x, int16 &y, uint16 &w, uint16 &h);
+	bool getWidgetData(const Common::String &widget, int16 &x, int16 &y, int16 &w, int16 &h);
 
 	Graphics::TextAlign getWidgetTextHAlign(const Common::String &widget);
 
diff --git a/gui/ThemeLayout.cpp b/gui/ThemeLayout.cpp
index 86118d0a12..edac50aa1a 100644
--- a/gui/ThemeLayout.cpp
+++ b/gui/ThemeLayout.cpp
@@ -71,7 +71,7 @@ void ThemeLayout::resetLayout() {
 		_children[i]->resetLayout();
 }
 
-bool ThemeLayout::getWidgetData(const Common::String &name, int16 &x, int16 &y, uint16 &w, uint16 &h) {
+bool ThemeLayout::getWidgetData(const Common::String &name, int16 &x, int16 &y, int16 &w, int16 &h) {
 	if (name.empty()) {
 		assert(getLayoutType() == kLayoutMain);
 		x = _x; y = _y;
@@ -158,7 +158,7 @@ void ThemeLayout::debugDraw(Graphics::Surface *screen, const Graphics::Font *fon
 #endif
 
 
-bool ThemeLayoutWidget::getWidgetData(const Common::String &name, int16 &x, int16 &y, uint16 &w, uint16 &h) {
+bool ThemeLayoutWidget::getWidgetData(const Common::String &name, int16 &x, int16 &y, int16 &w, int16 &h) {
 	if (name == _name) {
 		x = _x; y = _y;
 		w = _w; h = _h;
@@ -229,7 +229,7 @@ void ThemeLayoutMain::reflowLayout(Widget *widgetChain) {
 		_w = _defaultW > 0 ? MIN(_defaultW, g_system->getOverlayWidth()) : -1;
 		_h = _defaultH > 0 ? MIN(_defaultH, g_system->getOverlayHeight()) : -1;
 	} else {
-		if (!g_gui.xmlEval()->getWidgetData(_overlays, _x, _y, (uint16 &) _w, (uint16 &) _h)) {
+		if (!g_gui.xmlEval()->getWidgetData(_overlays, _x, _y, _w, _h)) {
 			warning("Unable to retrieve overlayed dialog position %s", _overlays.c_str());
 		}
 
diff --git a/gui/ThemeLayout.h b/gui/ThemeLayout.h
index ccf44d1f1a..482413c1ed 100644
--- a/gui/ThemeLayout.h
+++ b/gui/ThemeLayout.h
@@ -114,7 +114,7 @@ protected:
 	virtual ThemeLayout *makeClone(ThemeLayout *newParent) = 0;
 
 public:
-	virtual bool getWidgetData(const Common::String &name, int16 &x, int16 &y, uint16 &w, uint16 &h);
+	virtual bool getWidgetData(const Common::String &name, int16 &x, int16 &y, int16 &w, int16 &h);
 
 	virtual Graphics::TextAlign getWidgetTextHAlign(const Common::String &name);
 
@@ -226,7 +226,7 @@ public:
 		setTextHAlign(align);
 	}
 
-	bool getWidgetData(const Common::String &name, int16 &x, int16 &y, uint16 &w, uint16 &h) override;
+	bool getWidgetData(const Common::String &name, int16 &x, int16 &y, int16 &w, int16 &h) override;
 	Graphics::TextAlign getWidgetTextHAlign(const Common::String &name) override;
 
 	void reflowLayout(Widget *widgetChain) override;
@@ -263,7 +263,7 @@ public:
 		}
 	}
 
-	bool getWidgetData(const Common::String &name, int16 &x, int16 &y, uint16 &w, uint16 &h) override {
+	bool getWidgetData(const Common::String &name, int16 &x, int16 &y, int16 &w, int16 &h) override {
 		if (ThemeLayoutWidget::getWidgetData(name, x, y, w, h)) {
 			h -= _tabHeight;
 			return true;
@@ -294,7 +294,7 @@ public:
 		}
 	}
 
-	bool getWidgetData(const Common::String &name, int16 &x, int16 &y, uint16 &w, uint16 &h) override { return false; }
+	bool getWidgetData(const Common::String &name, int16 &x, int16 &y, int16 &w, int16 &h) override { return false; }
 	void reflowLayout(Widget *widgetChain) override {}
 #ifdef LAYOUT_DEBUG_DIALOG
 	const char *getName() const { return "SPACE"; }
diff --git a/gui/object.cpp b/gui/object.cpp
index 84dd1035ad..e9d2c4b19a 100644
--- a/gui/object.cpp
+++ b/gui/object.cpp
@@ -40,9 +40,13 @@ GuiObject::~GuiObject() {
 
 void GuiObject::reflowLayout() {
 	if (!_name.empty()) {
-		if (!g_gui.xmlEval()->getWidgetData(_name, _x, _y, _w, _h)) {
+		int16 w, h;
+
+		if (!g_gui.xmlEval()->getWidgetData(_name, _x, _y, w, h) || w == -1 || h == -1) {
 			error("Could not load widget position for '%s'", _name.c_str());
 		}
+		_w = w;
+		_h = h;
 	}
 }
 
diff --git a/gui/options.cpp b/gui/options.cpp
index ad3905a25c..1b3e610e28 100644
--- a/gui/options.cpp
+++ b/gui/options.cpp
@@ -1133,7 +1133,7 @@ void OptionsDialog::addAchievementsControls(GuiObject *boss, const Common::Strin
 
 	for (int16 viewAchieved = 1; viewAchieved >= 0; viewAchieved--) {
 		// run this twice, first view all achieved, then view all non-hidden & non-achieved
-	
+
 		for (uint16 idx = 0; idx < nMax ; idx++) {
 			bool isAchieved = AchMan.isAchieved(info.descriptions[idx].id);
 
@@ -1144,7 +1144,7 @@ void OptionsDialog::addAchievementsControls(GuiObject *boss, const Common::Strin
 			if (isAchieved) {
 				nAchieved++;
 			}
-			
+
 			if (!isAchieved && info.descriptions[idx].isHidden) {
 				nHidden++;
 				continue;
@@ -2773,7 +2773,7 @@ void GlobalOptionsDialog::setupCloudTab() {
 
 	// calculate shift
 	int16 x, y;
-	uint16 w, h;
+	int16 w, h;
 	int16 shiftUp = 0;
 	if (!showingCurrentStorage || enabled) {
 		// "storage is disabled" hint is not shown, shift everything up
@@ -2902,7 +2902,7 @@ void GlobalOptionsDialog::shiftWidget(Widget *widget, const char *widgetName, in
 	if (!widget) return;
 
 	int16 x, y;
-	uint16 w, h;
+	int16 w, h;
 	if (!g_gui.xmlEval()->getWidgetData(widgetName, x, y, w, h))
 		warning("%s's position is undefined", widgetName);
 
diff --git a/gui/saveload-dialog.cpp b/gui/saveload-dialog.cpp
index 56a4d4c708..d63d2479a6 100644
--- a/gui/saveload-dialog.cpp
+++ b/gui/saveload-dialog.cpp
@@ -489,7 +489,7 @@ void SaveLoadChooserSimple::reflowLayout() {
 
 	if (g_gui.xmlEval()->getVar("Globals.SaveLoadChooser.ExtInfo.Visible") == 1 && (_thumbnailSupport || _saveDateSupport || _playTimeSupport)) {
 		int16 x, y;
-		uint16 w, h;
+		int16 w, h;
 
 		if (!g_gui.xmlEval()->getWidgetData("SaveLoadChooser.Thumbnail", x, y, w, h))
 			error("Error when loading position data for Save/Load Thumbnails");
@@ -919,10 +919,10 @@ void SaveLoadChooserGrid::reflowLayout() {
 	// HACK: The whole code below really works around the fact, that we have
 	// no easy way to dynamically layout widgets.
 	const uint16 availableWidth = getWidth() - 20;
-	uint16 availableHeight;
+	int16 availableHeight;
 
 	int16 x, y;
-	uint16 w;
+	int16 w;
 	if (!g_gui.xmlEval()->getWidgetData("SaveLoadChooser.List", x, y, w, availableHeight))
 		error("Could not load widget position for 'SaveLoadChooser.List'");
 




More information about the Scummvm-git-logs mailing list