[Scummvm-git-logs] scummvm master -> 37485b96703b063edb532af31efeb976a038b01f

sev- sev at scummvm.org
Mon Apr 6 19:10:39 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:
8f44cb6acf DIRECTOR: Fix code analysis issues. Some are embarrassing.
37485b9670 GRAPHICS: MACGUI: Implemented event dispatcher for MacWidget


Commit: 8f44cb6acfc606a084cbbedd7a20aa6770649508
    https://github.com/scummvm/scummvm/commit/8f44cb6acfc606a084cbbedd7a20aa6770649508
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-04-06T21:09:13+02:00

Commit Message:
DIRECTOR: Fix code analysis issues. Some are embarrassing.

Changed paths:
    engines/director/resource.cpp
    engines/director/transitions.cpp


diff --git a/engines/director/resource.cpp b/engines/director/resource.cpp
index ed6fc05611..80ef246900 100644
--- a/engines/director/resource.cpp
+++ b/engines/director/resource.cpp
@@ -343,9 +343,10 @@ void DirectorEngine::loadSharedCastsFrom(Common::String filename) {
 	if (vwci.size() > 0) {
 		debug(0, "****** Loading %d CastInfo resources", vwci.size());
 
-		for (Common::Array<uint16>::iterator iterator = vwci.begin(); iterator != vwci.end(); ++iterator)
+		for (Common::Array<uint16>::iterator iterator = vwci.begin(); iterator != vwci.end(); ++iterator) {
 			_sharedScore->loadCastInfo(*(r = sharedCast->getResource(MKTAG('V', 'W', 'C', 'I'), *iterator)), *iterator);
 			delete r;
+		}
 	}
 
 	Common::Array<uint16> cast = sharedCast->getResourceIDList(MKTAG('C','A','S','t'));
diff --git a/engines/director/transitions.cpp b/engines/director/transitions.cpp
index 5abcdf303c..c109bbb204 100644
--- a/engines/director/transitions.cpp
+++ b/engines/director/transitions.cpp
@@ -496,6 +496,8 @@ static void dissolveTrans(TransParams &t, Score *score, Common::Rect &clipRect)
 	uint realw = w, realh = h;
 	byte pixmask[8];
 
+	memset(pixmask, 0, 8);
+
 	t.xStepSize = 1;
 	t.yStepSize = 1;
 
@@ -933,8 +935,6 @@ static void transZoom(TransParams &t, Score *score, Common::Rect &clipRect) {
 	Graphics::MacPlotData pd(score->_backSurface, &g_director->_wm->getPatterns(), Graphics::kPatternCheckers, 0, 0, 1, 0);
 
 	for (uint16 i = 1; i < t.steps; i++) {
-		bool stop = false;
-
 		score->_backSurface->copyFrom(*score->_backSurface2);
 
 		for (int s = 2; s >= 0; s--) {
@@ -961,9 +961,6 @@ static void transZoom(TransParams &t, Score *score, Common::Rect &clipRect) {
 		r.setWidth(t.xStepSize * i * 2);
 		r.moveTo(w / 2 - t.xStepSize * i, h / 2 - t.yStepSize * i);
 
-		if (stop)
-			break;
-
 		g_system->copyRectToScreen(score->_backSurface->getPixels(), score->_backSurface->pitch, 0, 0, w, h);
 		g_system->updateScreen();
 


Commit: 37485b96703b063edb532af31efeb976a038b01f
    https://github.com/scummvm/scummvm/commit/37485b96703b063edb532af31efeb976a038b01f
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2020-04-06T21:09:13+02:00

Commit Message:
GRAPHICS: MACGUI: Implemented event dispatcher for MacWidget

Changed paths:
    graphics/macgui/maceditabletext.cpp
    graphics/macgui/maceditabletext.h
    graphics/macgui/macwidget.cpp
    graphics/macgui/macwidget.h
    graphics/macgui/macwindow.cpp
    graphics/macgui/macwindow.h
    graphics/macgui/macwindowmanager.cpp


diff --git a/graphics/macgui/maceditabletext.cpp b/graphics/macgui/maceditabletext.cpp
index 02579a55b3..a141c60f67 100644
--- a/graphics/macgui/maceditabletext.cpp
+++ b/graphics/macgui/maceditabletext.cpp
@@ -45,16 +45,16 @@ enum {
 
 static void cursorTimerHandler(void *refCon);
 
-MacEditableText::MacEditableText(int w, int h, MacWindowManager *wm, Common::U32String s, const MacFont *macFont, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment, int interlinear) :
-		MacWidget(w, h, true), MacText(s, wm, macFont, fgcolor, bgcolor, maxWidth, textAlignment, interlinear) {
+MacEditableText::MacEditableText( MacWidget *parent,int x, int y, int w, int h, MacWindowManager *wm, Common::U32String s, const MacFont *macFont, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment, int interlinear) :
+		MacWidget(parent, x, y, w, h, true), MacText(s, wm, macFont, fgcolor, bgcolor, maxWidth, textAlignment, interlinear) {
 
 	_maxWidth = maxWidth;
 
 	init();
 }
 
-MacEditableText::MacEditableText(int w, int h, MacWindowManager *wm, const Common::String &s, const MacFont *macFont, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment, int interlinear) :
-		MacWidget(w, h, true), MacText(s, wm, macFont, fgcolor, bgcolor, maxWidth, textAlignment, interlinear) {
+MacEditableText::MacEditableText(MacWidget *parent, int x, int y, int w, int h, MacWindowManager *wm, const Common::String &s, const MacFont *macFont, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment, int interlinear) :
+		MacWidget(parent, x, y, w, h, true), MacText(s, wm, macFont, fgcolor, bgcolor, maxWidth, textAlignment, interlinear) {
 
 	_maxWidth = maxWidth;
 
@@ -297,9 +297,6 @@ bool MacEditableText::processEvent(Common::Event &event) {
 		if (!_editable)
 			return false;
 
-		// Make the parent window active
-		_wm->setActive(_parent->getId());
-
 		if (event.kbd.flags & (Common::KBD_ALT | Common::KBD_CTRL | Common::KBD_META)) {
 			return false;
 		}
diff --git a/graphics/macgui/maceditabletext.h b/graphics/macgui/maceditabletext.h
index 39747775b8..d625e6e9c4 100644
--- a/graphics/macgui/maceditabletext.h
+++ b/graphics/macgui/maceditabletext.h
@@ -52,9 +52,9 @@ struct SelectedText {
 
 class MacEditableText : public MacText, public MacWidget {
 public:
-	MacEditableText(int w, int h, MacWindowManager *wm, Common::U32String s, const MacFont *font, int fgcolor, int bgcolor,
+	MacEditableText(MacWidget *parent, int x, int y, int w, int h, MacWindowManager *wm, Common::U32String s, const MacFont *font, int fgcolor, int bgcolor,
 			int maxWidth = -1, TextAlign textAlignment = kTextAlignLeft, int interlinear = 0);
-	MacEditableText(int w, int h, MacWindowManager *wm, const Common::String &s, const MacFont *font, int fgcolor, int bgcolor,
+	MacEditableText(MacWidget *parent, int x, int y, int w, int h, MacWindowManager *wm, const Common::String &s, const MacFont *font, int fgcolor, int bgcolor,
 			int maxWidth = -1, TextAlign textAlignment = kTextAlignLeft, int interlinear = 0);
 			// 0 pixels between the lines by default
 	virtual ~MacEditableText();
diff --git a/graphics/macgui/macwidget.cpp b/graphics/macgui/macwidget.cpp
index 66901e8f39..b17e1e3abd 100644
--- a/graphics/macgui/macwidget.cpp
+++ b/graphics/macgui/macwidget.cpp
@@ -20,18 +20,79 @@
  *
  */
 
+#include "common/system.h"
+
 #include "graphics/macgui/macwidget.h"
 
 namespace Graphics {
 
-MacWidget::MacWidget(int w, int h, bool focusable) :
-		_focusable(focusable) {
+MacWidget::MacWidget(MacWidget *parent, int x, int y, int w, int h, bool focusable) :
+		_focusable(focusable), _parent(parent) {
 	_contentIsDirty = true;
 
-	_dims.left = 0;
-	_dims.right = w;
-	_dims.top = 0;
-	_dims.bottom = h;
+	_dims.left = x;
+	_dims.right = x + w;
+	_dims.top = y;
+	_dims.bottom = y + h;
+
+	if (parent)
+		parent->_children.push_back(this);
+}
+
+MacWidget::~MacWidget() {
+	if (_parent)
+		_parent->removeWidget(this, false);
+}
+
+void MacWidget::removeWidget(MacWidget *child, bool del) {
+	for (uint i = 0; i < _children.size(); i++) {
+		if (_children[i] == child) {
+			if (del)
+				delete _children[i];
+
+			_children.remove_at(i);
+		}
+	}
+}
+
+MacWidget *MacWidget::findEventHandler(Common::Event &event, int dx, int dy) {
+	switch (event.type) {
+	case Common::EVENT_LBUTTONDOWN:
+	case Common::EVENT_LBUTTONUP:
+	case Common::EVENT_RBUTTONDOWN:
+	case Common::EVENT_RBUTTONUP:
+	case Common::EVENT_MOUSEMOVE:
+		{
+			Common::Point pos;
+
+			pos = g_system->getEventManager()->getMousePos();
+
+			if (_dims.contains(pos.x - dx, pos.y - dy)) {
+				for (uint i = 0; i < _children.size(); i++) {
+					MacWidget *res = _children[i]->findEventHandler(event, dx + _dims.left, dy + _dims.top);
+					if (res)
+						return res;
+				}
+				return this;
+			}
+			break;
+		}
+
+	case Common::EVENT_KEYDOWN:
+		break;
+
+	default:
+		return nullptr;
+	}
+
+	return nullptr;
+}
+
+Common::Point MacWidget::getAbsolutePos() {
+	if (!_parent)
+		return Common::Point(0, 0);
+
+	return Common::Point(_parent->_dims.left, _parent->_dims.top) + _parent->getAbsolutePos();
 }
 
 } // End of namespace Graphics
diff --git a/graphics/macgui/macwidget.h b/graphics/macgui/macwidget.h
index 3b2d70017e..fe1df7e753 100644
--- a/graphics/macgui/macwidget.h
+++ b/graphics/macgui/macwidget.h
@@ -23,6 +23,8 @@
 #ifndef GRAPHICS_MACGUI_MACWIDGET_H
 #define GRAPHICS_MACGUI_MACWIDGET_H
 
+#include "common/array.h"
+#include "common/events.h"
 #include "common/rect.h"
 
 namespace Common {
@@ -31,15 +33,14 @@ namespace Common {
 
 namespace Graphics {
 
-class BaseMacWindow;
 class ManagedSurface;
 
 class MacWidget {
 	friend class MacEditableText;
 
 public:
-	MacWidget(int w, int h, bool focusable);
-	virtual ~MacWidget() {}
+	MacWidget(MacWidget *parent, int x, int y, int w, int h, bool focusable);
+	virtual ~MacWidget();
 
 	const Common::Rect &getDimensions() { return _dims; }
 	bool isFocusable() { return _focusable; }
@@ -48,7 +49,11 @@ public:
 	virtual bool draw(ManagedSurface *g, bool forceRedraw = false) = 0;
 	virtual bool processEvent(Common::Event &event) = 0;
 	virtual bool hasAllFocus() = 0;
-	void setParent(BaseMacWindow *parent) { _parent = parent; }
+
+	Common::Point getAbsolutePos();
+	MacWidget *findEventHandler(Common::Event &event, int dx, int dy);
+
+	void removeWidget(MacWidget *child, bool del = true);
 
 protected:
 	bool _focusable;
@@ -57,7 +62,8 @@ protected:
 	Common::Rect _dims;
 
 public:
-	BaseMacWindow *_parent;
+	MacWidget *_parent;
+	Common::Array<MacWidget *> _children;
 };
 
 } // End of namespace Graphics
diff --git a/graphics/macgui/macwindow.cpp b/graphics/macgui/macwindow.cpp
index c9a276857a..e33d9dbe1e 100644
--- a/graphics/macgui/macwindow.cpp
+++ b/graphics/macgui/macwindow.cpp
@@ -41,22 +41,6 @@ BaseMacWindow::BaseMacWindow(int id, bool editable, MacWindowManager *wm) :
 	_type = kWindowUnknown;
 }
 
-WidgetInfo::WidgetInfo(MacWidget *widget_, int x, int y) {
-	widget = widget_;
-	bbox = widget->getDimensions();
-	bbox.moveTo(x, y);
-}
-
-WidgetInfo::~WidgetInfo() {
-	delete widget;
-}
-
-void BaseMacWindow::addWidget(MacWidget *widget, int x, int y) {
-	_widgets.push_back(new WidgetInfo(widget, x, y));
-
-	widget->setParent(this);
-}
-
 MacWindow::MacWindow(int id, bool scrollable, bool resizable, bool editable, MacWindowManager *wm) :
 		BaseMacWindow(id, editable, wm), _scrollable(scrollable), _resizable(resizable) {
 	_active = false;
diff --git a/graphics/macgui/macwindow.h b/graphics/macgui/macwindow.h
index c6ebdd20f5..672cdda6e1 100644
--- a/graphics/macgui/macwindow.h
+++ b/graphics/macgui/macwindow.h
@@ -63,14 +63,6 @@ enum WindowClick {
 }
 using namespace MacWindowConstants;
 
-struct WidgetInfo {
-	Common::Rect bbox;
-	MacWidget *widget;
-
-	WidgetInfo(MacWidget *widget_, int x, int y);
-	~WidgetInfo();
-};
-
 /**
  * Abstract class that defines common functionality for all window classes.
  * It supports event callbacks and drawing.
@@ -159,8 +151,6 @@ public:
 	 */
 	void setCallback(bool (*callback)(WindowClick, Common::Event &, void *), void *data) { _callback = callback; _dataPtr = data; }
 
-	void addWidget(MacWidget *widget, int x, int y);
-
 protected:
 	int _id;
 	WindowType _type;
@@ -175,8 +165,6 @@ protected:
 	bool (*_callback)(WindowClick, Common::Event &, void *);
 	void *_dataPtr;
 
-	Common::List<WidgetInfo *> _widgets;
-
 public:
 	MacWindowManager *_wm;
 };
diff --git a/graphics/macgui/macwindowmanager.cpp b/graphics/macgui/macwindowmanager.cpp
index 64d4a3779d..d753d6430a 100644
--- a/graphics/macgui/macwindowmanager.cpp
+++ b/graphics/macgui/macwindowmanager.cpp
@@ -20,7 +20,6 @@
  */
 
 #include "common/array.h"
-#include "common/events.h"
 #include "common/list.h"
 #include "common/system.h"
 #include "common/timer.h"




More information about the Scummvm-git-logs mailing list