[Scummvm-git-logs] scummvm master -> cd09742f409f8f4019812e69672e8ec9b13448a9

sev- noreply at scummvm.org
Wed Sep 27 09:57:12 UTC 2023


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

Summary:
cd09742f40 GUI: Make MacWindowManager global to GUI


Commit: cd09742f409f8f4019812e69672e8ec9b13448a9
    https://github.com/scummvm/scummvm/commit/cd09742f409f8f4019812e69672e8ec9b13448a9
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-09-27T11:56:06+02:00

Commit Message:
GUI: Make MacWindowManager global to GUI

The current hack with the local variable led to unstable behaviour
on Android when the app is suspended. Also, it was leaking memory.

Changed paths:
    gui/gui-manager.cpp
    gui/gui-manager.h
    gui/widgets/richtext.cpp


diff --git a/gui/gui-manager.cpp b/gui/gui-manager.cpp
index d901e480b5b..ae946f62d19 100644
--- a/gui/gui-manager.cpp
+++ b/gui/gui-manager.cpp
@@ -37,6 +37,7 @@
 #include "gui/widget.h"
 
 #include "graphics/cursorman.h"
+#include "graphics/macgui/macwindowmanager.h"
 
 namespace Common {
 DECLARE_SINGLETON(GUI::GuiManager);
@@ -104,6 +105,7 @@ GuiManager::GuiManager() : CommandSender(nullptr), _redrawStatus(kRedrawDisabled
 
 GuiManager::~GuiManager() {
 	delete _theme;
+	delete _wm;
 }
 
 void GuiManager::initIconsSet() {
@@ -885,4 +887,20 @@ void GuiManager::initTextToSpeech() {
 	ttsMan->setVoice(voice);
 }
 
+Graphics::MacWindowManager *GuiManager::getWM() {
+	if (_wm)
+		return _wm;
+
+	if (ConfMan.hasKey("extrapath")) {
+		Common::FSNode dir(ConfMan.get("extrapath"));
+		SearchMan.addDirectory(dir.getPath(), dir);
+	}
+
+	uint32 wmMode = Graphics::kWMModeNoDesktop | Graphics::kWMMode32bpp | Graphics::kWMModeNoCursorOverride;
+
+	_wm = new Graphics::MacWindowManager(wmMode);
+
+	return _wm;
+}
+
 } // End of namespace GUI
diff --git a/gui/gui-manager.h b/gui/gui-manager.h
index 92538379d38..5b79345673c 100644
--- a/gui/gui-manager.h
+++ b/gui/gui-manager.h
@@ -36,6 +36,7 @@ class OSystem;
 
 namespace Graphics {
 class Font;
+class MacWindowManager;
 }
 
 namespace Common {
@@ -143,6 +144,8 @@ public:
 
 	void displayTopDialogOnly(bool mode);
 
+	Graphics::MacWindowManager *getWM();
+
 protected:
 	enum RedrawStatus {
 		kRedrawDisabled = 0,
@@ -178,6 +181,8 @@ protected:
 	Common::SearchSet _iconsSet;
 	bool _iconsSetChanged;
 
+	Graphics::MacWindowManager *_wm = nullptr;
+
 	// position and time of last mouse click (used to detect double clicks)
 	struct MousePos {
 		MousePos() : x(-1), y(-1), count(0) { time = 0; }
diff --git a/gui/widgets/richtext.cpp b/gui/widgets/richtext.cpp
index ec87754a236..c5c910c0c5f 100644
--- a/gui/widgets/richtext.cpp
+++ b/gui/widgets/richtext.cpp
@@ -34,22 +34,6 @@
 
 namespace GUI {
 
-Graphics::MacWindowManager *_wm = nullptr;
-
-void ensureWM() {
-	if (_wm)
-		return;
-
-	if (ConfMan.hasKey("extrapath")) {
-		Common::FSNode dir(ConfMan.get("extrapath"));
-		SearchMan.addDirectory(dir.getPath(), dir);
-	}
-
-	uint32 wmMode = Graphics::kWMModeNoDesktop | Graphics::kWMMode32bpp | Graphics::kWMModeNoCursorOverride;
-
-	_wm = new Graphics::MacWindowManager(wmMode);
-}
-
 RichTextWidget::RichTextWidget(GuiObject *boss, int x, int y, int w, int h, bool scale, const Common::U32String &text, const Common::U32String &tooltip)
 	: Widget(boss, x, y, w, h, scale, tooltip), CommandSender(nullptr)  {
 
@@ -84,8 +68,6 @@ void RichTextWidget::init() {
 
 	_textWidth = _w - _scrollbarWidth - _x;
 
-	ensureWM();
-
 	_limitH = 140;
 }
 
@@ -148,22 +130,24 @@ void RichTextWidget::recalc() {
 }
 
 void RichTextWidget::createWidget() {
-	uint32 bg = _wm->_pixelformat.ARGBToColor(0, 0xff, 0xff, 0xff); // transparent
+	Graphics::MacWindowManager *wm = g_gui.getWM();
+
+	uint32 bg = wm->_pixelformat.ARGBToColor(0, 0xff, 0xff, 0xff); // transparent
 	TextColorData *normal = g_gui.theme()->getTextColorData(kTextColorNormal);
-	uint32 fg = _wm->_pixelformat.RGBToColor(normal->r, normal->g, normal->b);
+	uint32 fg = wm->_pixelformat.RGBToColor(normal->r, normal->g, normal->b);
 
 	const int fontHeight = g_gui.xmlEval()->getVar("Globals.Font.Height", 25);
 
 	Graphics::MacFont macFont(Graphics::kMacFontNewYork, fontHeight, Graphics::kMacFontRegular);
 
-	_txtWnd = new Graphics::MacText(Common::U32String(), _wm, &macFont, fg, bg, _textWidth, Graphics::kTextAlignLeft);
+	_txtWnd = new Graphics::MacText(Common::U32String(), wm, &macFont, fg, bg, _textWidth, Graphics::kTextAlignLeft);
 
 	if (!_imageArchive.empty())
 		_txtWnd->setImageArchive(_imageArchive);
 
 	_txtWnd->setMarkdownText(_text);
 
-	_surface = new Graphics::ManagedSurface(_w, _h, _wm->_pixelformat);
+	_surface = new Graphics::ManagedSurface(_w, _h, wm->_pixelformat);
 
 	recalc();
 }
@@ -186,7 +170,7 @@ void RichTextWidget::drawWidget() {
 
 	g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y, _x + _w, _y + _h), ThemeEngine::kWidgetBackgroundPlain);
 
-	_surface->clear(_wm->_pixelformat.ARGBToColor(0, 0xff, 0xff, 0xff)); // transparent
+	_surface->clear(g_gui.getWM()->_pixelformat.ARGBToColor(0, 0xff, 0xff, 0xff)); // transparent
 
 	_txtWnd->draw(_surface, 0, _scrolledY, _w - _scrollbarWidth, _h, 0, 0);
 




More information about the Scummvm-git-logs mailing list