[Scummvm-cvs-logs] scummvm master -> a00272c62c012ed4f6ee98ada7415064e8faac5a

sev- sev at scummvm.org
Wed Aug 3 14:38:16 CEST 2016


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

Summary:
3d4087b9d0 WAGE: Extract MacWindowManager
592a6defb7 WAGE: Change namespace of MacWindow
744034bd98 WAGE: Extract MacWindow
d8652af84e GRAPHICS: Change namespace of MacMenu
8a2aeeecc9 WAGE: Adapt to MacMenu namespace change
68b2d44a0f WAGE: Extract MacMenu
ffbc6b0c78 GRAPHICS: Create wrapper namespace for MacMenu constants
941617fc38 GRAPHICS: Create wrapper namespace for MacWindow constants
1080f19995 GRAPHICS: Create wrapper namespace for MacWindowManager constants
9ce6fbd0d7 GRAPHICS: Move MacMenu constants
80604fb3f5 GRAPHICS: Clean up namespaces
b9ca6836bd WAGE: Adapt to namespace change
c071eb0e18 GRAPHICS: Fix style issues
5bb5bb64f0 WAGE: Fix style issues
1f00d2a099 GRAPHICS: Introduce NinePatchBitmap to MacWindow
b8d36443f3 WAGE: Remove unnecessary border code
98d0838df3 WAGE: Add basic border loading code
6c89eaa1b8 GRAPHICS: Include border loading code
3d950ad125 WAGE: Remove superfluous comment
4a16f5fc39 WAGE: Begin adding borders to the windows
b6722a1477 GRAPHICS: Fix segfault in macwindow
d49d573edc WAGE: Fix border loading
26238ee6f9 GRAPHICS: Fix border loading
4ab02530ae GRAPHICS: Add MacWindowBorder to abstract borders
a2955b1025 GRAPHICS: Add active/inactive borders to MacWindowBorders
1bfb1a561c WAGE: Implement active/inactive borders
f642ad1cae GRAPHICS: Refactor MacWindow to accept MacWindowBorder
638e8e99c8 WAGE: Change GUI Scene to load BMP borders
fafd209d04 WAGE: Remove custom borders
3b1ba50c88 GRAPHICS: First approximation to custom border offsets
2b586e7c59 WAGE: Fallback to built-in borders
bc798d9ff4 GRAPHICS: Add custom border measures
38f80f10f8 WAGE: Remove leftover files
7bc8d472ab GRAPHICS: Fix style and spelling
f92873ae37 GRAPHICS: Add missing file header
95beba7b63 GRAPHICS: Fix spacing issues in MacWindowManager
da33e52539 GRAPHICS: Reorder modules to preserve alphabetical order
f7ba1cb812 GRAPHICS: Rename header guards in macgui
6d8b6ad4f8 GRAPHICS: Fix include path in macwindowborder
a0bea8567b WAGE: Revert indentation
e809320f58 GRAPHICS: Fix indentation
03f2d9b01e GRAPHICS: Remove unused variables
02a18134c3 GRAPHICS: Add basic caching to 9patch colors
d7010637af GRAPHICS: Add documentation to MacWindowBorder
c4f6c4c2fd GRAPHICS: Add documentation to BaseMacWindow
5ce231a527 GRAPHICS: Add macwindow documentation
ff9b1ccb57 GRAPHICS: Add most of the documentation to MacWindowManager
a00272c62c Merge pull request #796 from blorente/move-macgui


Commit: 3d4087b9d0c199ba48a6f69d7d20a2850215f72f
    https://github.com/scummvm/scummvm/commit/3d4087b9d0c199ba48a6f69d7d20a2850215f72f
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-07-30T09:41:54+02:00

Commit Message:
WAGE: Extract MacWindowManager

Changed paths:
  A graphics/macgui/macwindowmanager.cpp
  A graphics/macgui/macwindowmanager.h
  R engines/wage/macwindowmanager.h
    engines/wage/design.cpp
    engines/wage/design.h
    engines/wage/dialog.cpp
    engines/wage/gui.cpp
    engines/wage/gui.h
    engines/wage/macmenu.cpp
    engines/wage/macmenu.h
    engines/wage/macwindow.cpp
    engines/wage/macwindow.h
    engines/wage/module.mk
    engines/wage/world.h
    graphics/module.mk



diff --git a/engines/wage/design.cpp b/engines/wage/design.cpp
index 2bfea9d..a578a84 100644
--- a/engines/wage/design.cpp
+++ b/engines/wage/design.cpp
@@ -47,15 +47,15 @@
 
 #include "graphics/managed_surface.h"
 #include "graphics/primitives.h"
+#include "graphics/macgui/macwindowmanager.h"
 
-#include "wage/macwindowmanager.h"
 #include "wage/design.h"
 
 namespace Wage {
 
 struct PlotData {
 	Graphics::ManagedSurface *surface;
-	Patterns *patterns;
+	Graphics::Patterns *patterns;
 	uint fillType;
 	int thickness;
 	Design *design;
diff --git a/engines/wage/design.h b/engines/wage/design.h
index 86225c9..c64ae6d 100644
--- a/engines/wage/design.h
+++ b/engines/wage/design.h
@@ -51,7 +51,7 @@
 #include "common/memstream.h"
 #include "common/rect.h"
 
-#include "wage/macwindowmanager.h"
+#include "graphics/macgui/macwindowmanager.h"
 
 namespace Wage {
 
@@ -68,14 +68,14 @@ public:
 		return _bounds;
 	}
 
-    void paint(Graphics::ManagedSurface *canvas, Patterns &patterns, int x, int y);
+    void paint(Graphics::ManagedSurface *canvas, Graphics::Patterns &patterns, int x, int y);
 	bool isPointOpaque(int x, int y);
-	static void drawRect(Graphics::ManagedSurface *surface, Common::Rect &rect, int thickness, int color, Patterns &patterns, byte fillType);
-	static void drawRect(Graphics::ManagedSurface *surface, int x1, int y1, int x2, int y2, int thickness, int color, Patterns &patterns, byte fillType);
-	static void drawFilledRect(Graphics::ManagedSurface *surface, Common::Rect &rect, int color, Patterns &patterns, byte fillType);
-	static void drawFilledRoundRect(Graphics::ManagedSurface *surface, Common::Rect &rect, int arc, int color, Patterns &patterns, byte fillType);
-	static void drawHLine(Graphics::ManagedSurface *surface, int x1, int x2, int y, int thickness, int color, Patterns &patterns, byte fillType);
-	static void drawVLine(Graphics::ManagedSurface *surface, int x, int y1, int y2, int thickness, int color, Patterns &patterns, byte fillType);
+	static void drawRect(Graphics::ManagedSurface *surface, Common::Rect &rect, int thickness, int color, Graphics::Patterns &patterns, byte fillType);
+	static void drawRect(Graphics::ManagedSurface *surface, int x1, int y1, int x2, int y2, int thickness, int color, Graphics::Patterns &patterns, byte fillType);
+	static void drawFilledRect(Graphics::ManagedSurface *surface, Common::Rect &rect, int color, Graphics::Patterns &patterns, byte fillType);
+	static void drawFilledRoundRect(Graphics::ManagedSurface *surface, Common::Rect &rect, int arc, int color, Graphics::Patterns &patterns, byte fillType);
+	static void drawHLine(Graphics::ManagedSurface *surface, int x1, int x2, int y, int thickness, int color, Graphics::Patterns &patterns, byte fillType);
+	static void drawVLine(Graphics::ManagedSurface *surface, int x, int y1, int y2, int thickness, int color, Graphics::Patterns &patterns, byte fillType);
 
 	bool isBoundsCalculation() { return _boundsCalculationMode; }
 	void adjustBounds(int16 x, int16 y);
@@ -88,15 +88,15 @@ private:
 	bool _boundsCalculationMode;
 
 private:
-	void render(Patterns &patterns);
+	void render(Graphics::Patterns &patterns);
 	void drawRect(Graphics::ManagedSurface *surface, Common::ReadStream &in,
-		Patterns &patterns, byte fillType, byte borderThickness, byte borderFillType);
+		Graphics::Patterns &patterns, byte fillType, byte borderThickness, byte borderFillType);
 	void drawRoundRect(Graphics::ManagedSurface *surface, Common::ReadStream &in,
-		Patterns &patterns, byte fillType, byte borderThickness, byte borderFillType);
+		Graphics::Patterns &patterns, byte fillType, byte borderThickness, byte borderFillType);
 	void drawPolygon(Graphics::ManagedSurface *surface, Common::ReadStream &in,
-		Patterns &patterns, byte fillType, byte borderThickness, byte borderFillType);
+		Graphics::Patterns &patterns, byte fillType, byte borderThickness, byte borderFillType);
 	void drawOval(Graphics::ManagedSurface *surface, Common::ReadStream &in,
-		Patterns &patterns, byte fillType, byte borderThickness, byte borderFillType);
+		Graphics::Patterns &patterns, byte fillType, byte borderThickness, byte borderFillType);
 	void drawBitmap(Graphics::ManagedSurface *surface, Common::SeekableReadStream &in);
 };
 
diff --git a/engines/wage/dialog.cpp b/engines/wage/dialog.cpp
index 86080c9..a2013db 100644
--- a/engines/wage/dialog.cpp
+++ b/engines/wage/dialog.cpp
@@ -48,8 +48,9 @@
 #include "common/system.h"
 #include "common/events.h"
 
+#include "graphics/macgui/macwindowmanager.h"
+
 #include "wage/wage.h"
-#include "wage/macwindowmanager.h"
 #include "wage/design.h"
 #include "wage/gui.h"
 #include "wage/dialog.h"
diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp
index cdc646f..b87a28c 100644
--- a/engines/wage/gui.cpp
+++ b/engines/wage/gui.cpp
@@ -49,13 +49,13 @@
 #include "common/system.h"
 #include "graphics/cursorman.h"
 #include "graphics/primitives.h"
+#include "graphics/macgui/macwindowmanager.h"
 
 #include "wage/wage.h"
 #include "wage/design.h"
 #include "wage/entities.h"
 #include "wage/gui.h"
 #include "wage/macwindow.h"
-#include "wage/macwindowmanager.h"
 #include "wage/macmenu.h"
 #include "wage/world.h"
 
diff --git a/engines/wage/gui.h b/engines/wage/gui.h
index ba1bb5e..ef93f6e 100644
--- a/engines/wage/gui.h
+++ b/engines/wage/gui.h
@@ -51,11 +51,12 @@
 #include "common/str-array.h"
 #include "graphics/font.h"
 #include "graphics/managed_surface.h"
+#include "graphics/macgui/macwindowmanager.h"
+
 #include "common/events.h"
 #include "common/rect.h"
 
 #include "wage/macwindow.h"
-#include "wage/macwindowmanager.h"
 
 namespace Wage {
 
@@ -121,7 +122,7 @@ public:
 
 	Scene *_scene;
 
-	MacWindowManager _wm;
+	Graphics::MacWindowManager _wm;
 	MacWindow *_sceneWindow;
 	MacWindow *_consoleWindow;
 
diff --git a/engines/wage/macmenu.cpp b/engines/wage/macmenu.cpp
index b29903c..5d79906 100644
--- a/engines/wage/macmenu.cpp
+++ b/engines/wage/macmenu.cpp
@@ -50,8 +50,8 @@
 
 #include "graphics/primitives.h"
 #include "graphics/font.h"
+#include "graphics/macgui/macwindowmanager.h"
 
-#include "wage/macwindowmanager.h"
 #include "wage/macwindow.h"
 #include "wage/macmenu.h"
 
@@ -89,7 +89,7 @@ struct MenuItem {
 	MenuItem(const char *n) : name(n) {}
 };
 
-Menu::Menu(int id, const Common::Rect &bounds, MacWindowManager *wm)
+Menu::Menu(int id, const Common::Rect &bounds, Graphics::MacWindowManager *wm)
 		: BaseMacWindow(id, false, wm) {
 	_font = getMenuFont();
 
diff --git a/engines/wage/macmenu.h b/engines/wage/macmenu.h
index e73e4c4..239c4fc 100644
--- a/engines/wage/macmenu.h
+++ b/engines/wage/macmenu.h
@@ -48,6 +48,10 @@
 #ifndef WAGE_MACMENU_H
 #define WAGE_MACMENU_H
 
+namespace Graphics {
+	class MacWindowManager;
+}
+
 namespace Wage {
 
 struct MenuItem;
@@ -101,7 +105,7 @@ struct MenuData {
 
 class Menu : public BaseMacWindow {
 public:
-	Menu(int id, const Common::Rect &bounds, MacWindowManager *wm);
+	Menu(int id, const Common::Rect &bounds, Graphics::MacWindowManager *wm);
 	~Menu();
 
 	void setCommandsCallback(void (*callback)(int, Common::String &, void *), void *data) { _ccallback = callback; _cdata = data; }
diff --git a/engines/wage/macwindow.cpp b/engines/wage/macwindow.cpp
index db8ef38..1100c0b 100644
--- a/engines/wage/macwindow.cpp
+++ b/engines/wage/macwindow.cpp
@@ -48,13 +48,13 @@
 #include "graphics/font.h"
 #include "graphics/primitives.h"
 #include "common/events.h"
+#include "graphics/macgui/macwindowmanager.h"
 
 #include "wage/macwindow.h"
-#include "wage/macwindowmanager.h"
 
 namespace Wage {
 
-BaseMacWindow::BaseMacWindow(int id, bool editable, MacWindowManager *wm) :
+BaseMacWindow::BaseMacWindow(int id, bool editable, Graphics::MacWindowManager *wm) :
 		_id(id), _editable(editable), _wm(wm) {
 	_callback = 0;
 	_dataPtr = 0;
@@ -64,7 +64,7 @@ BaseMacWindow::BaseMacWindow(int id, bool editable, MacWindowManager *wm) :
 	_type = kWindowUnknown;
 }
 
-MacWindow::MacWindow(int id, bool scrollable, bool resizable, bool editable, MacWindowManager *wm) :
+MacWindow::MacWindow(int id, bool scrollable, bool resizable, bool editable, Graphics::MacWindowManager *wm) :
 		BaseMacWindow(id, editable, wm), _scrollable(scrollable), _resizable(resizable) {
 	_active = false;
 	_borderIsDirty = true;
diff --git a/engines/wage/macwindow.h b/engines/wage/macwindow.h
index 4c6e9ef..4d824bd 100644
--- a/engines/wage/macwindow.h
+++ b/engines/wage/macwindow.h
@@ -50,9 +50,11 @@
 
 #include "graphics/managed_surface.h"
 
-namespace Wage {
+namespace Graphics {
+	class MacWindowManager;
+}
 
-class MacWindowManager;
+namespace Wage {
 
 enum WindowType {
 	kWindowUnknown,
@@ -76,7 +78,7 @@ enum WindowClick {
 
 class BaseMacWindow {
 public:
-	BaseMacWindow(int id, bool editable, MacWindowManager *wm);
+	BaseMacWindow(int id, bool editable, Graphics::MacWindowManager *wm);
 	virtual ~BaseMacWindow() {}
 
 	const Common::Rect &getDimensions() { return _dims; }
@@ -108,12 +110,12 @@ protected:
 	bool (*_callback)(WindowClick, Common::Event &, void *);
 	void *_dataPtr;
 
-	MacWindowManager *_wm;
+	Graphics::MacWindowManager *_wm;
 };
 
 class MacWindow : public BaseMacWindow {
 public:
-	MacWindow(int id, bool scrollable, bool resizable, bool editable, MacWindowManager *wm);
+	MacWindow(int id, bool scrollable, bool resizable, bool editable, Graphics::MacWindowManager *wm);
 	virtual ~MacWindow();
 	void move(int x, int y);
 	void resize(int w, int h);
diff --git a/engines/wage/macwindowmanager.h b/engines/wage/macwindowmanager.h
deleted file mode 100644
index 13f85cd..0000000
--- a/engines/wage/macwindowmanager.h
+++ /dev/null
@@ -1,141 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * MIT License:
- *
- * Copyright (c) 2009 Alexei Svitkine, Eugene Sandulenko
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following
- * conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- */
-
-#ifndef WAGE_MACWINDOWMANAGER_H
-#define WAGE_MACWINDOWMANAGER_H
-
-#include "common/array.h"
-#include "common/list.h"
-#include "common/events.h"
-#include "common/archive.h"
-
-#include "graphics/fontman.h"
-
-namespace Graphics {
-class ManagedSurface;
-}
-
-namespace Wage {
-
-enum {
-	kDesktopArc = 7
-};
-
-enum {
-	kColorBlack  = 0,
-	kColorGray   = 1,
-	kColorWhite  = 2,
-	kColorGreen  = 3,
-	kColorGreen2 = 4
-};
-
-enum {
-	kPatternSolid = 1,
-	kPatternStripes = 2,
-	kPatternCheckers = 3,
-	kPatternCheckers2 = 4
-};
-
-class BaseMacWindow;
-class MacWindow;
-class Menu;
-
-typedef Common::Array<byte *> Patterns;
-
-class MacWindowManager {
-public:
-	MacWindowManager();
-	~MacWindowManager();
-
-	void setScreen(Graphics::ManagedSurface *screen) { _screen = screen; }
-	bool hasBuiltInFonts() { return _builtInFonts; }
-	const Graphics::Font *getFont(const char *name, Graphics::FontManager::FontUsage fallback);
-
-	MacWindow *addWindow(bool scrollable, bool resizable, bool editable);
-	Menu *addMenu();
-	void setActive(int id);
-
-	void setFullRefresh(bool redraw) { _fullRefresh = true; }
-
-	void draw();
-
-	bool processEvent(Common::Event &event);
-
-	BaseMacWindow *getWindow(int id) { return _windows[id]; }
-
-	Patterns &getPatterns() { return _patterns; }
-	void drawFilledRoundRect(Graphics::ManagedSurface *surface, Common::Rect &rect, int arc, int color);
-
-	void pushArrowCursor();
-	void popCursor();
-
-private:
-	void drawDesktop();
-	void loadFonts();
-
-private:
-	Graphics::ManagedSurface *_screen;
-
-	Common::List<BaseMacWindow *> _windowStack;
-	Common::Array<BaseMacWindow *> _windows;
-
-	int _lastId;
-	int _activeWindow;
-
-	bool _fullRefresh;
-
-	Patterns _patterns;
-
-	Menu *_menu;
-
-	bool _builtInFonts;
-	bool _cursorIsArrow;
-};
-
-} // End of namespace Wage
-
-#endif
diff --git a/engines/wage/module.mk b/engines/wage/module.mk
index 1f397b5..43f0f0f 100644
--- a/engines/wage/module.mk
+++ b/engines/wage/module.mk
@@ -11,7 +11,6 @@ MODULE_OBJS := \
 	gui-console.o \
 	macmenu.o \
 	macwindow.o \
-	macwindowmanager.o \
 	randomhat.o \
 	saveload.o \
 	script.o \
diff --git a/engines/wage/world.h b/engines/wage/world.h
index 918616c..b3908be 100644
--- a/engines/wage/world.h
+++ b/engines/wage/world.h
@@ -49,7 +49,7 @@
 #define WAGE_WORLD_H
 
 #include "wage/entities.h"
-#include "wage/macwindowmanager.h"
+#include "graphics/macgui/macwindowmanager.h"
 
 namespace Wage {
 
@@ -89,7 +89,7 @@ public:
 	ObjArray _orderedObjs;
 	ChrArray _orderedChrs;
 	Common::Array<Sound *> _orderedSounds;
-	Patterns *_patterns;
+	Graphics::Patterns *_patterns;
 	Scene *_storageScene;
 	Chr *_player;
 	int _signature;
diff --git a/graphics/macgui/macwindowmanager.cpp b/graphics/macgui/macwindowmanager.cpp
new file mode 100644
index 0000000..7df635a
--- /dev/null
+++ b/graphics/macgui/macwindowmanager.cpp
@@ -0,0 +1,380 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * MIT License:
+ *
+ * Copyright (c) 2009 Alexei Svitkine, Eugene Sandulenko
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#include "common/array.h"
+#include "common/events.h"
+#include "common/list.h"
+#include "common/unzip.h"
+#include "common/system.h"
+#include "common/stream.h"
+
+#include "graphics/cursorman.h"
+#include "graphics/fonts/bdf.h"
+#include "graphics/managed_surface.h"
+#include "graphics/palette.h"
+#include "graphics/primitives.h"
+#include "graphics/macgui/macwindowmanager.h"
+
+#include "wage/macwindow.h"
+#include "wage/macmenu.h"
+
+namespace Graphics {
+
+static const byte palette[] = {
+	0, 0, 0,           // Black
+	0x80, 0x80, 0x80,  // Gray
+	0xff, 0xff, 0xff,  // White
+	0x00, 0xff, 0x00,  // Green
+	0x00, 0xcf, 0x00   // Green2
+};
+
+static byte fillPatterns[][8] = { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, // kPatternSolid
+								  { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 }, // kPatternStripes
+								  { 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55 }, // kPatternCheckers
+								  { 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa }  // kPatternCheckers2
+};
+
+static const byte macCursorArrow[] = {
+	2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+	2, 0, 2, 3, 3, 3, 3, 3, 3, 3, 3,
+	2, 0, 0, 2, 3, 3, 3, 3, 3, 3, 3,
+	2, 0, 0, 0, 2, 3, 3, 3, 3, 3, 3,
+	2, 0, 0, 0, 0, 2, 3, 3, 3, 3, 3,
+	2, 0, 0, 0, 0, 0, 2, 3, 3, 3, 3,
+	2, 0, 0, 0, 0, 0, 0, 2, 3, 3, 3,
+	2, 0, 0, 0, 0, 0, 0, 0, 2, 3, 3,
+	2, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3,
+	2, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2,
+	2, 0, 0, 2, 0, 0, 2, 3, 3, 3, 3,
+	2, 0, 2, 3, 2, 0, 0, 2, 3, 3, 3,
+	2, 2, 3, 3, 2, 0, 0, 2, 3, 3, 3,
+	2, 3, 3, 3, 3, 2, 0, 0, 2, 3, 3,
+	3, 3, 3, 3, 3, 2, 0, 0, 2, 3, 3,
+	3, 3, 3, 3, 3, 3, 2, 2, 2, 3, 3
+};
+
+static const byte macCursorBeam[] = {
+	0, 0, 3, 3, 3, 0, 0, 3, 3, 3, 3,
+	3, 3, 0, 3, 0, 3, 3, 3, 3, 3, 3,
+	3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3,
+	3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3,
+	3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3,
+	3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3,
+	3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3,
+	3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3,
+	3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3,
+	3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3,
+	3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3,
+	3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3,
+	3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3,
+	3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3,
+	3, 3, 0, 3, 0, 3, 3, 3, 3, 3, 3,
+	0, 0, 3, 3, 3, 0, 0, 3, 3, 3, 3,
+};
+
+MacWindowManager::MacWindowManager() {
+    _screen = 0;
+    _lastId = 0;
+    _activeWindow = -1;
+
+	_menu = 0;
+
+	_fullRefresh = true;
+
+	_builtInFonts = true;
+
+	for (int i = 0; i < ARRAYSIZE(fillPatterns); i++)
+		_patterns.push_back(fillPatterns[i]);
+
+	loadFonts();
+
+	g_system->getPaletteManager()->setPalette(palette, 0, ARRAYSIZE(palette) / 3);
+
+	CursorMan.replaceCursorPalette(palette, 0, ARRAYSIZE(palette) / 3);
+	CursorMan.replaceCursor(macCursorArrow, 11, 16, 1, 1, 3);
+	_cursorIsArrow = true;
+	CursorMan.showMouse(true);
+}
+
+MacWindowManager::~MacWindowManager() {
+    for (int i = 0; i < _lastId; i++)
+        delete _windows[i];
+}
+
+Wage::MacWindow *MacWindowManager::addWindow(bool scrollable, bool resizable, bool editable) {
+	Wage::MacWindow *w = new Wage::MacWindow(_lastId, scrollable, resizable, editable, this);
+
+    _windows.push_back(w);
+    _windowStack.push_back(w);
+
+    setActive(_lastId);
+
+    _lastId++;
+
+    return w;
+}
+
+Wage::Menu *MacWindowManager::addMenu() {
+	_menu = new Wage::Menu(_lastId, _screen->getBounds(), this);
+
+	_windows.push_back(_menu);
+
+	_lastId++;
+
+	return _menu;
+}
+
+void MacWindowManager::setActive(int id) {
+    if (_activeWindow == id)
+        return;
+
+    if (_activeWindow != -1)
+        _windows[_activeWindow]->setActive(false);
+
+    _activeWindow = id;
+
+    _windows[id]->setActive(true);
+
+    _windowStack.remove(_windows[id]);
+    _windowStack.push_back(_windows[id]);
+
+    _fullRefresh = true;
+}
+
+struct PlotData {
+	Graphics::ManagedSurface *surface;
+	Patterns *patterns;
+	uint fillType;
+	int thickness;
+
+	PlotData(Graphics::ManagedSurface *s, Patterns *p, int f, int t) :
+		surface(s), patterns(p), fillType(f), thickness(t) {}
+};
+
+static void drawPixel(int x, int y, int color, void *data) {
+	PlotData *p = (PlotData *)data;
+
+	if (p->fillType > p->patterns->size())
+		return;
+
+	byte *pat = p->patterns->operator[](p->fillType - 1);
+
+	if (p->thickness == 1) {
+		if (x >= 0 && x < p->surface->w && y >= 0 && y < p->surface->h) {
+			uint xu = (uint)x; // for letting compiler optimize it
+			uint yu = (uint)y;
+
+			*((byte *)p->surface->getBasePtr(xu, yu)) =
+				(pat[yu % 8] & (1 << (7 - xu % 8))) ?
+					color : kColorWhite;
+		}
+	} else {
+		int x1 = x;
+		int x2 = x1 + p->thickness;
+		int y1 = y;
+		int y2 = y1 + p->thickness;
+
+		for (y = y1; y < y2; y++)
+			for (x = x1; x < x2; x++)
+				if (x >= 0 && x < p->surface->w && y >= 0 && y < p->surface->h) {
+					uint xu = (uint)x; // for letting compiler optimize it
+					uint yu = (uint)y;
+					*((byte *)p->surface->getBasePtr(xu, yu)) =
+						(pat[yu % 8] & (1 << (7 - xu % 8))) ?
+							color : kColorWhite;
+				}
+	}
+}
+
+void MacWindowManager::drawDesktop() {
+	Common::Rect r(_screen->getBounds());
+
+	PlotData pd(_screen, &_patterns, kPatternCheckers, 1);
+
+	Graphics::drawRoundRect(r, kDesktopArc, kColorBlack, true, drawPixel, &pd);
+
+	g_system->copyRectToScreen(_screen->getPixels(), _screen->pitch, 0, 0, _screen->w, _screen->h);
+}
+
+void MacWindowManager::draw() {
+    assert(_screen);
+
+	if (_fullRefresh)
+		drawDesktop();
+
+    for (Common::List<Wage::BaseMacWindow *>::const_iterator it = _windowStack.begin(); it != _windowStack.end(); it++) {
+		Wage::BaseMacWindow *w = *it;
+        if (w->draw(_screen, _fullRefresh)) {
+            w->setDirty(false);
+
+			Common::Rect clip(w->getDimensions().left - 2, w->getDimensions().top - 2, w->getDimensions().right - 2, w->getDimensions().bottom - 2);
+			clip.clip(_screen->getBounds());
+
+            g_system->copyRectToScreen(_screen->getBasePtr(clip.left, clip.top), _screen->pitch, clip.left, clip.top, clip.width(), clip.height());
+        }
+    }
+
+	// Menu is drawn on top of everything and always
+	if (_menu)
+		_menu->draw(_screen, _fullRefresh);
+
+    _fullRefresh = false;
+}
+
+bool MacWindowManager::processEvent(Common::Event &event) {
+	// Menu gets events first fir shortcuts and menu bar
+	if (_menu && _menu->processEvent(event))
+		return true;
+
+    if (event.type != Common::EVENT_MOUSEMOVE && event.type != Common::EVENT_LBUTTONDOWN &&
+            event.type != Common::EVENT_LBUTTONUP)
+        return false;
+
+	if (_windows[_activeWindow]->isEditable() && _windows[_activeWindow]->getType() == Wage::kWindowWindow &&
+			((Wage::MacWindow *)_windows[_activeWindow])->getInnerDimensions().contains(event.mouse.x, event.mouse.y)) {
+		if (_cursorIsArrow) {
+			CursorMan.replaceCursor(macCursorBeam, 11, 16, 3, 8, 3);
+			_cursorIsArrow = false;
+		}
+	} else {
+		if (_cursorIsArrow == false) {
+			CursorMan.replaceCursor(macCursorArrow, 11, 16, 1, 1, 3);
+			_cursorIsArrow = true;
+		}
+	}
+
+    for (Common::List<Wage::BaseMacWindow *>::const_iterator it = _windowStack.end(); it != _windowStack.begin();) {
+        it--;
+		Wage::BaseMacWindow *w = *it;
+
+        if (w->hasAllFocus() || w->getDimensions().contains(event.mouse.x, event.mouse.y)) {
+            if (event.type == Common::EVENT_LBUTTONDOWN || event.type == Common::EVENT_LBUTTONUP)
+                setActive(w->getId());
+
+            return w->processEvent(event);
+        }
+    }
+
+    return false;
+}
+
+//////////////////////
+// Font stuff
+//////////////////////
+void MacWindowManager::loadFonts() {
+	Common::Archive *dat;
+
+	dat = Common::makeZipArchive("classicmacfonts.dat");
+
+	if (!dat) {
+		warning("Could not find classicmacfonts.dat. Falling back to built-in fonts");
+		_builtInFonts = true;
+
+		return;
+	}
+
+	Common::ArchiveMemberList list;
+	dat->listMembers(list);
+
+	for (Common::ArchiveMemberList::iterator it = list.begin(); it != list.end(); ++it) {
+		Common::SeekableReadStream *stream = dat->createReadStreamForMember((*it)->getName());
+
+		Graphics::BdfFont *font = Graphics::BdfFont::loadFont(*stream);
+
+		delete stream;
+
+		Common::String fontName = (*it)->getName();
+
+		// Trim the .bdf extension
+		for (int i = fontName.size() - 1; i >= 0; --i) {
+			if (fontName[i] == '.') {
+				while ((uint)i < fontName.size()) {
+					fontName.deleteLastChar();
+				}
+				break;
+			}
+		}
+
+		FontMan.assignFontToName(fontName, font);
+
+		debug(2, " %s", fontName.c_str());
+	}
+
+	_builtInFonts = false;
+
+	delete dat;
+}
+
+const Graphics::Font *MacWindowManager::getFont(const char *name, Graphics::FontManager::FontUsage fallback) {
+	const Graphics::Font *font = 0;
+
+	if (!_builtInFonts) {
+		font = FontMan.getFontByName(name);
+
+		if (!font)
+			warning("Cannot load font %s", name);
+	}
+
+	if (_builtInFonts || !font)
+		font = FontMan.getFontByUsage(fallback);
+
+	return font;
+}
+
+/////////////////
+// Cursor stuff
+/////////////////
+void MacWindowManager::pushArrowCursor() {
+	CursorMan.pushCursor(macCursorArrow, 11, 16, 1, 1, 3);
+}
+
+void MacWindowManager::popCursor() {
+	CursorMan.popCursor();
+}
+
+
+} // End of namespace Graphics
diff --git a/graphics/macgui/macwindowmanager.h b/graphics/macgui/macwindowmanager.h
new file mode 100644
index 0000000..ccc9234
--- /dev/null
+++ b/graphics/macgui/macwindowmanager.h
@@ -0,0 +1,167 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * MIT License:
+ *
+ * Copyright (c) 2009 Alexei Svitkine, Eugene Sandulenko
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#ifndef GRAPHICS_MACWINDOWMANAGER_H
+#define GRAPHICS_MACWINDOWMANAGER_H
+
+#include "common/array.h"
+#include "common/list.h"
+#include "common/events.h"
+#include "common/archive.h"
+
+#include "graphics/fontman.h"
+
+#include "engines\wage\macwindow.h"
+
+namespace Wage {
+	class MacWindow;
+	class BaseMacWindow;
+	class Menu;
+}
+
+namespace Graphics {	
+
+enum {
+	kDesktopArc = 7
+};
+
+enum {
+	kColorBlack  = 0,
+	kColorGray   = 1,
+	kColorWhite  = 2,
+	kColorGreen  = 3,
+	kColorGreen2 = 4
+};
+
+enum {
+	kPatternSolid = 1,
+	kPatternStripes = 2,
+	kPatternCheckers = 3,
+	kPatternCheckers2 = 4
+};
+
+class ManagedSurface;
+
+typedef Common::Array<byte *> Patterns;
+
+class MacWindowManager {
+public:
+	MacWindowManager();
+	~MacWindowManager();
+
+	void setScreen(ManagedSurface *screen) { _screen = screen; }
+	bool hasBuiltInFonts() { return _builtInFonts; }
+	const Font *getFont(const char *name, FontManager::FontUsage fallback);
+
+	Wage::MacWindow *addWindow(bool scrollable, bool resizable, bool editable);
+	Wage::Menu *addMenu();
+	void setActive(int id);
+
+	void setFullRefresh(bool redraw) { _fullRefresh = true; }
+
+	void draw();
+
+	bool processEvent(Common::Event &event);
+
+	Wage::BaseMacWindow *getWindow(int id) { return _windows[id]; }
+
+	Patterns &getPatterns() { return _patterns; }
+	void drawFilledRoundRect(ManagedSurface *surface, Common::Rect &rect, int arc, int color);
+
+	void pushArrowCursor();
+	void popCursor();
+
+private:
+	void drawDesktop();
+	void loadFonts();
+
+private:
+	ManagedSurface *_screen;
+
+	Common::List<Wage::BaseMacWindow *> _windowStack;
+	Common::Array<Wage::BaseMacWindow *> _windows;
+
+	int _lastId;
+	int _activeWindow;
+
+	bool _fullRefresh;
+
+	Patterns _patterns;
+
+	Wage::Menu *_menu;
+
+	bool _builtInFonts;
+	bool _cursorIsArrow;
+};
+
+} // End of namespace Graphics
+
+namespace Wage {
+	typedef Graphics::Patterns Patterns;
+	
+	enum {
+		kDesktopArc = 7
+	};
+
+	enum {
+		kColorBlack = 0,
+		kColorGray = 1,
+		kColorWhite = 2,
+		kColorGreen = 3,
+		kColorGreen2 = 4
+	};
+
+	enum {
+		kPatternSolid = 1,
+		kPatternStripes = 2,
+		kPatternCheckers = 3,
+		kPatternCheckers2 = 4
+	};
+}
+
+
+#endif
diff --git a/graphics/module.mk b/graphics/module.mk
index 7331a56..4d6c11b 100644
--- a/graphics/module.mk
+++ b/graphics/module.mk
@@ -28,7 +28,8 @@ MODULE_OBJS := \
 	VectorRenderer.o \
 	VectorRendererSpec.o \
 	wincursor.o \
-	yuv_to_rgb.o
+	yuv_to_rgb.o \
+	macgui/macwindowmanager.o
 
 ifdef USE_SCALERS
 MODULE_OBJS += \


Commit: 592a6defb7841a11aac2d6f6843e052d56504566
    https://github.com/scummvm/scummvm/commit/592a6defb7841a11aac2d6f6843e052d56504566
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-07-30T09:42:49+02:00

Commit Message:
WAGE: Change namespace of MacWindow

Changed paths:
    engines/wage/gui-console.cpp
    engines/wage/gui.cpp
    engines/wage/gui.h
    engines/wage/macmenu.h
    engines/wage/macwindow.cpp
    engines/wage/macwindow.h
    graphics/macgui/macwindowmanager.cpp
    graphics/macgui/macwindowmanager.h



diff --git a/engines/wage/gui-console.cpp b/engines/wage/gui-console.cpp
index 8b6fe43..a856a0d 100644
--- a/engines/wage/gui-console.cpp
+++ b/engines/wage/gui-console.cpp
@@ -424,8 +424,8 @@ void Gui::enableNewGameMenus() {
 	_menu->enableCommand(kMenuFile, kMenuActionQuit, true);
 }
 
-bool Gui::processConsoleEvents(WindowClick click, Common::Event &event) {
-	if (click == kBorderScrollUp || click == kBorderScrollDown) {
+bool Gui::processConsoleEvents(Graphics::WindowClick click, Common::Event &event) {
+	if (click == Graphics::kBorderScrollUp || click == Graphics::kBorderScrollDown) {
 		if (event.type == Common::EVENT_LBUTTONDOWN) {
 			int consoleHeight = _consoleWindow->getInnerDimensions().height();
 			int textFullSize = _lines.size() * _consoleLineHeight + consoleHeight;
@@ -439,14 +439,14 @@ bool Gui::processConsoleEvents(WindowClick click, Common::Event &event) {
 			int oldScrollPos = _scrollPos;
 
 			switch (click) {
-			case kBorderScrollUp:
+			case Graphics::kBorderScrollUp:
 				_scrollPos = MAX<int>(0, _scrollPos - _consoleLineHeight);
 				undrawCursor();
 				_cursorY -= (_scrollPos - oldScrollPos);
 				_consoleDirty = true;
 				_consoleFullRedraw = true;
 				break;
-			case kBorderScrollDown:
+			case Graphics::kBorderScrollDown:
 				_scrollPos = MIN<int>((_lines.size() - 2) * _consoleLineHeight, _scrollPos + _consoleLineHeight);
 				undrawCursor();
 				_cursorY -= (_scrollPos - oldScrollPos);
@@ -463,14 +463,14 @@ bool Gui::processConsoleEvents(WindowClick click, Common::Event &event) {
 		return false;
 	}
 
-	if (click == kBorderResizeButton) {
+	if (click == Graphics::kBorderResizeButton) {
 		_consoleDirty = true;
 		_consoleFullRedraw = true;
 
 		return true;
 	}
 
-	if (click == kBorderInner) {
+	if (click == Graphics::kBorderInner) {
 		if (event.type == Common::EVENT_LBUTTONDOWN) {
 			startMarking(event.mouse.x, event.mouse.y);
 
diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp
index b87a28c..5a28835 100644
--- a/engines/wage/gui.cpp
+++ b/engines/wage/gui.cpp
@@ -110,8 +110,8 @@ static void cursorTimerHandler(void *refCon) {
 	gui->_cursorDirty = true;
 }
 
-static bool sceneWindowCallback(WindowClick click, Common::Event &event, void *gui);
-static bool consoleWindowCallback(WindowClick click, Common::Event &event, void *gui);
+static bool sceneWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui);
+static bool consoleWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui);
 static void menuCommandsCallback(int action, Common::String &text, void *data);
 
 
@@ -235,14 +235,14 @@ void Gui::drawScene() {
 	_consoleFullRedraw = true;
 }
 
-static bool sceneWindowCallback(WindowClick click, Common::Event &event, void *g) {
+static bool sceneWindowCallback(Graphics::WindowClick click, Common::Event &event, void *g) {
 	Gui *gui = (Gui *)g;
 
 	return gui->processSceneEvents(click, event);
 }
 
-bool Gui::processSceneEvents(WindowClick click, Common::Event &event) {
-	if (click == kBorderInner && event.type == Common::EVENT_LBUTTONUP) {
+bool Gui::processSceneEvents(Graphics::WindowClick click, Common::Event &event) {
+	if (click == Graphics::kBorderInner && event.type == Common::EVENT_LBUTTONUP) {
 		Designed *obj = _scene->lookUpEntity(event.mouse.x - _sceneWindow->getDimensions().left,
 												  event.mouse.y - _sceneWindow->getDimensions().top);
 
@@ -260,12 +260,12 @@ void Gui::drawConsole() {
 	if (!_consoleDirty && !_consoleFullRedraw && !_sceneDirty)
 		return;
 
-	renderConsole(_consoleWindow->getSurface(), Common::Rect(kBorderWidth - 2, kBorderWidth - 2,
+	renderConsole(_consoleWindow->getSurface(), Common::Rect(Graphics::kBorderWidth - 2, Graphics::kBorderWidth - 2,
 				_consoleWindow->getDimensions().width(), _consoleWindow->getDimensions().height()));
 	_consoleWindow->setDirty(true);
 }
 
-static bool consoleWindowCallback(WindowClick click, Common::Event &event, void *g) {
+static bool consoleWindowCallback(Graphics::WindowClick click, Common::Event &event, void *g) {
 	Gui *gui = (Gui *)g;
 
 	return gui->processConsoleEvents(click, event);
diff --git a/engines/wage/gui.h b/engines/wage/gui.h
index ef93f6e..fd0447a 100644
--- a/engines/wage/gui.h
+++ b/engines/wage/gui.h
@@ -92,8 +92,8 @@ public:
 	void disableAllMenus();
 	void enableNewGameMenus();
 
-	bool processSceneEvents(WindowClick click, Common::Event &event);
-	bool processConsoleEvents(WindowClick click, Common::Event &event);
+	bool processSceneEvents(Graphics::WindowClick click, Common::Event &event);
+	bool processConsoleEvents(Graphics::WindowClick click, Common::Event &event);
 	void executeMenuCommand(int action, Common::String &text);
 
 private:
@@ -123,8 +123,8 @@ public:
 	Scene *_scene;
 
 	Graphics::MacWindowManager _wm;
-	MacWindow *_sceneWindow;
-	MacWindow *_consoleWindow;
+	Graphics::MacWindow *_sceneWindow;
+	Graphics::MacWindow *_consoleWindow;
 
 private:
 	Graphics::ManagedSurface _console;
diff --git a/engines/wage/macmenu.h b/engines/wage/macmenu.h
index 239c4fc..793cb27 100644
--- a/engines/wage/macmenu.h
+++ b/engines/wage/macmenu.h
@@ -50,6 +50,7 @@
 
 namespace Graphics {
 	class MacWindowManager;
+	class BaseMacWindow;
 }
 
 namespace Wage {
@@ -103,7 +104,7 @@ struct MenuData {
 	bool enabled;
 };
 
-class Menu : public BaseMacWindow {
+class Menu : public Graphics::BaseMacWindow {
 public:
 	Menu(int id, const Common::Rect &bounds, Graphics::MacWindowManager *wm);
 	~Menu();
diff --git a/engines/wage/macwindow.cpp b/engines/wage/macwindow.cpp
index 1100c0b..39ad739 100644
--- a/engines/wage/macwindow.cpp
+++ b/engines/wage/macwindow.cpp
@@ -52,9 +52,9 @@
 
 #include "wage/macwindow.h"
 
-namespace Wage {
+namespace Graphics {
 
-BaseMacWindow::BaseMacWindow(int id, bool editable, Graphics::MacWindowManager *wm) :
+BaseMacWindow::BaseMacWindow(int id, bool editable, MacWindowManager *wm) :
 		_id(id), _editable(editable), _wm(wm) {
 	_callback = 0;
 	_dataPtr = 0;
@@ -64,7 +64,7 @@ BaseMacWindow::BaseMacWindow(int id, bool editable, Graphics::MacWindowManager *
 	_type = kWindowUnknown;
 }
 
-MacWindow::MacWindow(int id, bool scrollable, bool resizable, bool editable, Graphics::MacWindowManager *wm) :
+MacWindow::MacWindow(int id, bool scrollable, bool resizable, bool editable, MacWindowManager *wm) :
 		BaseMacWindow(id, editable, wm), _scrollable(scrollable), _resizable(resizable) {
 	_active = false;
 	_borderIsDirty = true;
@@ -84,8 +84,8 @@ MacWindow::MacWindow(int id, bool scrollable, bool resizable, bool editable, Gra
 MacWindow::~MacWindow() {
 }
 
-const Graphics::Font *MacWindow::getTitleFont() {
-	return _wm->getFont("Chicago-12", Graphics::FontManager::kBigGUIFont);
+const Font *MacWindow::getTitleFont() {
+	return _wm->getFont("Chicago-12", FontManager::kBigGUIFont);
 }
 
 void MacWindow::setActive(bool active) {
@@ -101,11 +101,11 @@ void MacWindow::resize(int w, int h) {
 		return;
 
 	_surface.free();
-	_surface.create(w, h, Graphics::PixelFormat::createFormatCLUT8());
+	_surface.create(w, h, PixelFormat::createFormatCLUT8());
 	_borderSurface.free();
-	_borderSurface.create(w, h, Graphics::PixelFormat::createFormatCLUT8());
+	_borderSurface.create(w, h, PixelFormat::createFormatCLUT8());
 	_composeSurface.free();
-	_composeSurface.create(w, h, Graphics::PixelFormat::createFormatCLUT8());
+	_composeSurface.create(w, h, PixelFormat::createFormatCLUT8());
 
 	_dims.setWidth(w);
 	_dims.setHeight(h);
@@ -134,7 +134,7 @@ void MacWindow::setDimensions(const Common::Rect &r) {
 	_contentIsDirty = true;
 }
 
-bool MacWindow::draw(Graphics::ManagedSurface *g, bool forceRedraw) {
+bool MacWindow::draw(ManagedSurface *g, bool forceRedraw) {
 	if (!_borderIsDirty && !_contentIsDirty && !forceRedraw)
 		return false;
 
@@ -163,7 +163,7 @@ const int arrowPixels[ARROW_H][ARROW_W] = {
 		{1,1,1,1,1,1,1,1,1,1,1,1}};
 
 static void drawPixelInverted(int x, int y, int color, void *data) {
-	Graphics::ManagedSurface *surface = (Graphics::ManagedSurface *)data;
+	ManagedSurface *surface = (ManagedSurface *)data;
 
 	if (x >= 0 && x < surface->w && y >= 0 && y < surface->h) {
 		byte *p = (byte *)surface->getBasePtr(x, y);
@@ -186,7 +186,7 @@ void MacWindow::drawBorder() {
 	int y = 0;
 	int width = _borderSurface.w;
 	int height = _borderSurface.h;
-	Graphics::ManagedSurface *g = &_borderSurface;
+	ManagedSurface *g = &_borderSurface;
 
 	// We draw rect with outer kColorGreen2 and inner kColorGreen, so on 2 passes we cut out
 	// scene by external shape of the border
@@ -233,7 +233,7 @@ void MacWindow::drawBorder() {
 				int ry2 = ry1 + _dims.height() * _scrollSize;
 				Common::Rect rr(rx1, ry1, rx2, ry2);
 
-				Graphics::drawFilledRect(rr, kColorBlack, drawPixelInverted, g);
+				drawFilledRect(rr, kColorBlack, drawPixelInverted, g);
 			}
 		}
 		if (closeable) {
@@ -246,7 +246,7 @@ void MacWindow::drawBorder() {
 	}
 
 	if (drawTitle) {
-		const Graphics::Font *font = getTitleFont();
+		const Font *font = getTitleFont();
 		int yOff = _wm->hasBuiltInFonts() ? 3 : 1;
 
 		int w = font->getStringWidth(_title) + 10;
@@ -276,14 +276,14 @@ void MacWindow::setScroll(float scrollPos, float scrollSize) {
 }
 
 
-void MacWindow::drawBox(Graphics::ManagedSurface *g, int x, int y, int w, int h) {
+void MacWindow::drawBox(ManagedSurface *g, int x, int y, int w, int h) {
 	Common::Rect r(x, y, x + w + 1, y + h + 1);
 
 	g->fillRect(r, kColorWhite);
 	g->frameRect(r, kColorBlack);
 }
 
-void MacWindow::fillRect(Graphics::ManagedSurface *g, int x, int y, int w, int h, int color) {
+void MacWindow::fillRect(ManagedSurface *g, int x, int y, int w, int h, int color) {
 	Common::Rect r(x, y, x + w, y + h);
 
 	g->fillRect(r, color);
diff --git a/engines/wage/macwindow.h b/engines/wage/macwindow.h
index 4d824bd..55f9d5c 100644
--- a/engines/wage/macwindow.h
+++ b/engines/wage/macwindow.h
@@ -45,16 +45,14 @@
  *
  */
 
-#ifndef WAGE_MACWINDOW_H
-#define WAGE_MACWINDOW_H
+#ifndef GRAPHICS_MACWINDOW_H
+#define GRAPHICS_MACWINDOW_H
 
 #include "graphics/managed_surface.h"
 
 namespace Graphics {
-	class MacWindowManager;
-}
 
-namespace Wage {
+class MacWindowManager;
 
 enum WindowType {
 	kWindowUnknown,
@@ -78,18 +76,18 @@ enum WindowClick {
 
 class BaseMacWindow {
 public:
-	BaseMacWindow(int id, bool editable, Graphics::MacWindowManager *wm);
+	BaseMacWindow(int id, bool editable, MacWindowManager *wm);
 	virtual ~BaseMacWindow() {}
 
 	const Common::Rect &getDimensions() { return _dims; }
 	int getId() { return _id; }
 	WindowType getType() { return _type; }
 	bool isEditable() { return _editable; }
-	Graphics::ManagedSurface *getSurface() { return &_surface; }
+	ManagedSurface *getSurface() { return &_surface; }
 	virtual void setActive(bool active) = 0;
 	void setDirty(bool dirty) { _contentIsDirty = dirty; }
 
-	virtual bool draw(Graphics::ManagedSurface *g, bool forceRedraw = false) = 0;
+	virtual bool draw(ManagedSurface *g, bool forceRedraw = false) = 0;
 	virtual bool processEvent(Common::Event &event) = 0;
 
 	virtual bool hasAllFocus() = 0;
@@ -102,7 +100,7 @@ protected:
 
 	bool _editable;
 
-	Graphics::ManagedSurface _surface;
+	ManagedSurface _surface;
 	bool _contentIsDirty;
 
 	Common::Rect _dims;
@@ -110,19 +108,19 @@ protected:
 	bool (*_callback)(WindowClick, Common::Event &, void *);
 	void *_dataPtr;
 
-	Graphics::MacWindowManager *_wm;
+	MacWindowManager *_wm;
 };
 
 class MacWindow : public BaseMacWindow {
 public:
-	MacWindow(int id, bool scrollable, bool resizable, bool editable, Graphics::MacWindowManager *wm);
+	MacWindow(int id, bool scrollable, bool resizable, bool editable, MacWindowManager *wm);
 	virtual ~MacWindow();
 	void move(int x, int y);
 	void resize(int w, int h);
 	void setDimensions(const Common::Rect &r);
 	const Common::Rect &getInnerDimensions() { return _innerDims; }
 
-	bool draw(Graphics::ManagedSurface *g, bool forceRedraw = false);
+	bool draw(ManagedSurface *g, bool forceRedraw = false);
 
 	void setActive(bool active);
 	void setTitle(Common::String &title) { _title = title; }
@@ -133,15 +131,15 @@ public:
 
 private:
 	void drawBorder();
-	void drawBox(Graphics::ManagedSurface *g, int x, int y, int w, int h);
-	void fillRect(Graphics::ManagedSurface *g, int x, int y, int w, int h, int color);
-	const Graphics::Font *getTitleFont();
+	void drawBox(ManagedSurface *g, int x, int y, int w, int h);
+	void fillRect(ManagedSurface *g, int x, int y, int w, int h, int color);
+	const Font *getTitleFont();
 	void updateInnerDims();
 	WindowClick isInBorder(int x, int y);
 
 private:
-	Graphics::ManagedSurface _borderSurface;
-	Graphics::ManagedSurface _composeSurface;
+	ManagedSurface _borderSurface;
+	ManagedSurface _composeSurface;
 	bool _scrollable;
 	bool _resizable;
 	bool _active;
@@ -158,6 +156,7 @@ private:
 	Common::String _title;
 };
 
-} // End of namespace Wage
+} // End of namespace Graphics
+
 
 #endif
diff --git a/graphics/macgui/macwindowmanager.cpp b/graphics/macgui/macwindowmanager.cpp
index 7df635a..6ec1831 100644
--- a/graphics/macgui/macwindowmanager.cpp
+++ b/graphics/macgui/macwindowmanager.cpp
@@ -145,8 +145,8 @@ MacWindowManager::~MacWindowManager() {
         delete _windows[i];
 }
 
-Wage::MacWindow *MacWindowManager::addWindow(bool scrollable, bool resizable, bool editable) {
-	Wage::MacWindow *w = new Wage::MacWindow(_lastId, scrollable, resizable, editable, this);
+MacWindow *MacWindowManager::addWindow(bool scrollable, bool resizable, bool editable) {
+	MacWindow *w = new MacWindow(_lastId, scrollable, resizable, editable, this);
 
     _windows.push_back(w);
     _windowStack.push_back(w);
@@ -246,8 +246,8 @@ void MacWindowManager::draw() {
 	if (_fullRefresh)
 		drawDesktop();
 
-    for (Common::List<Wage::BaseMacWindow *>::const_iterator it = _windowStack.begin(); it != _windowStack.end(); it++) {
-		Wage::BaseMacWindow *w = *it;
+    for (Common::List<BaseMacWindow *>::const_iterator it = _windowStack.begin(); it != _windowStack.end(); it++) {
+		BaseMacWindow *w = *it;
         if (w->draw(_screen, _fullRefresh)) {
             w->setDirty(false);
 
@@ -274,8 +274,8 @@ bool MacWindowManager::processEvent(Common::Event &event) {
             event.type != Common::EVENT_LBUTTONUP)
         return false;
 
-	if (_windows[_activeWindow]->isEditable() && _windows[_activeWindow]->getType() == Wage::kWindowWindow &&
-			((Wage::MacWindow *)_windows[_activeWindow])->getInnerDimensions().contains(event.mouse.x, event.mouse.y)) {
+	if (_windows[_activeWindow]->isEditable() && _windows[_activeWindow]->getType() == kWindowWindow &&
+			((MacWindow *)_windows[_activeWindow])->getInnerDimensions().contains(event.mouse.x, event.mouse.y)) {
 		if (_cursorIsArrow) {
 			CursorMan.replaceCursor(macCursorBeam, 11, 16, 3, 8, 3);
 			_cursorIsArrow = false;
@@ -287,9 +287,9 @@ bool MacWindowManager::processEvent(Common::Event &event) {
 		}
 	}
 
-    for (Common::List<Wage::BaseMacWindow *>::const_iterator it = _windowStack.end(); it != _windowStack.begin();) {
+    for (Common::List<BaseMacWindow *>::const_iterator it = _windowStack.end(); it != _windowStack.begin();) {
         it--;
-		Wage::BaseMacWindow *w = *it;
+		BaseMacWindow *w = *it;
 
         if (w->hasAllFocus() || w->getDimensions().contains(event.mouse.x, event.mouse.y)) {
             if (event.type == Common::EVENT_LBUTTONDOWN || event.type == Common::EVENT_LBUTTONUP)
diff --git a/graphics/macgui/macwindowmanager.h b/graphics/macgui/macwindowmanager.h
index ccc9234..45532ed 100644
--- a/graphics/macgui/macwindowmanager.h
+++ b/graphics/macgui/macwindowmanager.h
@@ -55,7 +55,7 @@
 
 #include "graphics/fontman.h"
 
-#include "engines\wage\macwindow.h"
+#include "engines/wage/macwindow.h"
 
 namespace Wage {
 	class MacWindow;
@@ -97,7 +97,7 @@ public:
 	bool hasBuiltInFonts() { return _builtInFonts; }
 	const Font *getFont(const char *name, FontManager::FontUsage fallback);
 
-	Wage::MacWindow *addWindow(bool scrollable, bool resizable, bool editable);
+	MacWindow *addWindow(bool scrollable, bool resizable, bool editable);
 	Wage::Menu *addMenu();
 	void setActive(int id);
 
@@ -107,7 +107,7 @@ public:
 
 	bool processEvent(Common::Event &event);
 
-	Wage::BaseMacWindow *getWindow(int id) { return _windows[id]; }
+	BaseMacWindow *getWindow(int id) { return _windows[id]; }
 
 	Patterns &getPatterns() { return _patterns; }
 	void drawFilledRoundRect(ManagedSurface *surface, Common::Rect &rect, int arc, int color);
@@ -122,8 +122,8 @@ private:
 private:
 	ManagedSurface *_screen;
 
-	Common::List<Wage::BaseMacWindow *> _windowStack;
-	Common::Array<Wage::BaseMacWindow *> _windows;
+	Common::List<BaseMacWindow *> _windowStack;
+	Common::Array<BaseMacWindow *> _windows;
 
 	int _lastId;
 	int _activeWindow;


Commit: 744034bd986b5a42b9dea8b9acadfd0c62ce536d
    https://github.com/scummvm/scummvm/commit/744034bd986b5a42b9dea8b9acadfd0c62ce536d
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-07-30T10:06:09+02:00

Commit Message:
WAGE: Extract MacWindow

Changed paths:
  A graphics/macgui/macwindow.cpp
  A graphics/macgui/macwindow.h
  R engines/wage/macwindow.cpp
  R engines/wage/macwindow.h
    engines/wage/gui-console.cpp
    engines/wage/gui.cpp
    engines/wage/gui.h
    engines/wage/macmenu.cpp
    engines/wage/module.mk
    graphics/macgui/macwindowmanager.cpp
    graphics/macgui/macwindowmanager.h
    graphics/module.mk



diff --git a/engines/wage/gui-console.cpp b/engines/wage/gui-console.cpp
index a856a0d..1ae0384 100644
--- a/engines/wage/gui-console.cpp
+++ b/engines/wage/gui-console.cpp
@@ -51,11 +51,11 @@
 #include "graphics/cursorman.h"
 #include "graphics/fonts/bdf.h"
 #include "graphics/palette.h"
+#include "graphics/macgui/macwindow.h"
 
 #include "wage/wage.h"
 #include "wage/design.h"
 #include "wage/entities.h"
-#include "wage/macwindow.h"
 #include "wage/macmenu.h"
 #include "wage/gui.h"
 #include "wage/world.h"
diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp
index 5a28835..532aa5f 100644
--- a/engines/wage/gui.cpp
+++ b/engines/wage/gui.cpp
@@ -50,12 +50,12 @@
 #include "graphics/cursorman.h"
 #include "graphics/primitives.h"
 #include "graphics/macgui/macwindowmanager.h"
+#include "graphics/macgui/macwindow.h"
 
 #include "wage/wage.h"
 #include "wage/design.h"
 #include "wage/entities.h"
 #include "wage/gui.h"
-#include "wage/macwindow.h"
 #include "wage/macmenu.h"
 #include "wage/world.h"
 
diff --git a/engines/wage/gui.h b/engines/wage/gui.h
index fd0447a..7355797 100644
--- a/engines/wage/gui.h
+++ b/engines/wage/gui.h
@@ -52,12 +52,11 @@
 #include "graphics/font.h"
 #include "graphics/managed_surface.h"
 #include "graphics/macgui/macwindowmanager.h"
+#include "graphics/macgui/macwindow.h"
 
 #include "common/events.h"
 #include "common/rect.h"
 
-#include "wage/macwindow.h"
-
 namespace Wage {
 
 class Menu;
diff --git a/engines/wage/macmenu.cpp b/engines/wage/macmenu.cpp
index 5d79906..d6dec32 100644
--- a/engines/wage/macmenu.cpp
+++ b/engines/wage/macmenu.cpp
@@ -51,8 +51,8 @@
 #include "graphics/primitives.h"
 #include "graphics/font.h"
 #include "graphics/macgui/macwindowmanager.h"
+#include "graphics/macgui/macwindow.h"
 
-#include "wage/macwindow.h"
 #include "wage/macmenu.h"
 
 namespace Wage {
diff --git a/engines/wage/macwindow.cpp b/engines/wage/macwindow.cpp
deleted file mode 100644
index 39ad739..0000000
--- a/engines/wage/macwindow.cpp
+++ /dev/null
@@ -1,376 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * MIT License:
- *
- * Copyright (c) 2009 Alexei Svitkine, Eugene Sandulenko
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following
- * conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- */
-
-#include "graphics/font.h"
-#include "graphics/primitives.h"
-#include "common/events.h"
-#include "graphics/macgui/macwindowmanager.h"
-
-#include "wage/macwindow.h"
-
-namespace Graphics {
-
-BaseMacWindow::BaseMacWindow(int id, bool editable, MacWindowManager *wm) :
-		_id(id), _editable(editable), _wm(wm) {
-	_callback = 0;
-	_dataPtr = 0;
-
-	_contentIsDirty = true;
-
-	_type = kWindowUnknown;
-}
-
-MacWindow::MacWindow(int id, bool scrollable, bool resizable, bool editable, MacWindowManager *wm) :
-		BaseMacWindow(id, editable, wm), _scrollable(scrollable), _resizable(resizable) {
-	_active = false;
-	_borderIsDirty = true;
-
-	_highlightedPart = kBorderNone;
-
-	_scrollPos = _scrollSize = 0.0;
-
-	_beingDragged = false;
-	_beingResized = false;
-
-	_draggedX = _draggedY = 0;
-
-	_type = kWindowWindow;
-}
-
-MacWindow::~MacWindow() {
-}
-
-const Font *MacWindow::getTitleFont() {
-	return _wm->getFont("Chicago-12", FontManager::kBigGUIFont);
-}
-
-void MacWindow::setActive(bool active) {
-	if (active == _active)
-		return;
-
-	_active = active;
-	_borderIsDirty = true;
-}
-
-void MacWindow::resize(int w, int h) {
-	if (_surface.w == w && _surface.h == h)
-		return;
-
-	_surface.free();
-	_surface.create(w, h, PixelFormat::createFormatCLUT8());
-	_borderSurface.free();
-	_borderSurface.create(w, h, PixelFormat::createFormatCLUT8());
-	_composeSurface.free();
-	_composeSurface.create(w, h, PixelFormat::createFormatCLUT8());
-
-	_dims.setWidth(w);
-	_dims.setHeight(h);
-
-	updateInnerDims();
-
-	_contentIsDirty = true;
-	_borderIsDirty = true;
-}
-
-void MacWindow::move(int x, int y) {
-	if (_dims.left == x && _dims.top == y)
-		return;
-
-	_dims.moveTo(x, y);
-	updateInnerDims();
-
-	_contentIsDirty = true;
-}
-
-void MacWindow::setDimensions(const Common::Rect &r) {
-	resize(r.width(), r.height());
-	_dims.moveTo(r.left, r.top);
-	updateInnerDims();
-
-	_contentIsDirty = true;
-}
-
-bool MacWindow::draw(ManagedSurface *g, bool forceRedraw) {
-	if (!_borderIsDirty && !_contentIsDirty && !forceRedraw)
-		return false;
-
-	if (_borderIsDirty || forceRedraw)
-		drawBorder();
-
-	_contentIsDirty = false;
-
-	// Compose
-	_composeSurface.blitFrom(_surface, Common::Rect(0, 0, _surface.w - 2, _surface.h - 2), Common::Point(2, 2));
-	_composeSurface.transBlitFrom(_borderSurface, kColorGreen);
-
-	g->transBlitFrom(_composeSurface, _composeSurface.getBounds(), Common::Point(_dims.left - 2, _dims.top - 2), kColorGreen2);
-
-	return true;
-}
-
-#define ARROW_W 12
-#define ARROW_H 6
-const int arrowPixels[ARROW_H][ARROW_W] = {
-		{0,0,0,0,0,1,1,0,0,0,0,0},
-		{0,0,0,0,1,1,1,1,0,0,0,0},
-		{0,0,0,1,1,1,1,1,1,0,0,0},
-		{0,0,1,1,1,1,1,1,1,1,0,0},
-		{0,1,1,1,1,1,1,1,1,1,1,0},
-		{1,1,1,1,1,1,1,1,1,1,1,1}};
-
-static void drawPixelInverted(int x, int y, int color, void *data) {
-	ManagedSurface *surface = (ManagedSurface *)data;
-
-	if (x >= 0 && x < surface->w && y >= 0 && y < surface->h) {
-		byte *p = (byte *)surface->getBasePtr(x, y);
-
-		*p = *p == kColorWhite ? kColorBlack : kColorWhite;
-	}
-}
-
-void MacWindow::updateInnerDims() {
-	_innerDims = _dims;
-	_innerDims.grow(-kBorderWidth);
-}
-
-void MacWindow::drawBorder() {
-	_borderIsDirty = false;
-
-	bool active = _active, scrollable = _scrollable, closeable = _active, drawTitle = !_title.empty();
-	const int size = kBorderWidth;
-	int x = 0;
-	int y = 0;
-	int width = _borderSurface.w;
-	int height = _borderSurface.h;
-	ManagedSurface *g = &_borderSurface;
-
-	// We draw rect with outer kColorGreen2 and inner kColorGreen, so on 2 passes we cut out
-	// scene by external shape of the border
-	int sz = kBorderWidth / 2;
-	g->clear(kColorGreen2);
-	g->fillRect(Common::Rect(sz, sz, width - sz, height - sz), kColorGreen);
-
-	drawBox(g, x,                    y,                     size,                 size);
-	drawBox(g, x + width - size - 1, y,                     size,                 size);
-	drawBox(g, x + width - size - 1, y + height - size - 1, size,                 size);
-	drawBox(g, x,                    y + height - size - 1, size,                 size);
-	drawBox(g, x + size,             y + 2,                 width - 2 * size - 1, size - 4);
-	drawBox(g, x + size,             y + height - size + 1, width - 2 * size - 1, size - 4);
-	drawBox(g, x + 2,                y + size,              size - 4,             height - 2 * size - 1);
-	drawBox(g, x + width - size + 1, y + size,              size - 4,             height - 2 * size - 1);
-
-	if (active) {
-		fillRect(g, x + size, y + 5,           width - 2 * size - 1, 8, kColorBlack);
-		fillRect(g, x + size, y + height - 13, width - 2 * size - 1, 8, kColorBlack);
-		fillRect(g, x + 5,    y + size,        8,                    height - 2 * size - 1, kColorBlack);
-		if (!scrollable) {
-			fillRect(g, x + width - 13, y + size, 8, height - 2 * size - 1, kColorBlack);
-		} else {
-			int x1 = x + width - 15;
-			int y1 = y + size + 1;
-
-			for (int yy = 0; yy < ARROW_H; yy++) {
-				for (int xx = 0; xx < ARROW_W; xx++)
-					g->hLine(x1 + xx, y1 + yy, x1 + xx, (arrowPixels[yy][xx] != 0 ? kColorBlack : kColorWhite));
-			}
-
-			fillRect(g, x + width - 13, y + size + ARROW_H, 8, height - 2 * size - 1 - ARROW_H * 2, kColorBlack);
-
-			y1 += height - 2 * size - ARROW_H - 2;
-			for (int yy = 0; yy < ARROW_H; yy++) {
-				for (int xx = 0; xx < ARROW_W; xx++)
-					g->hLine(x1 + xx, y1 + yy, x1 + xx, (arrowPixels[ARROW_H - yy - 1][xx] != 0 ? kColorBlack : kColorWhite));
-			}
-
-			if (_highlightedPart == kBorderScrollUp || _highlightedPart == kBorderScrollDown) {
-				int rx1 = x + width - kBorderWidth + 2;
-				int ry1 = y + size + _dims.height() * _scrollPos;
-				int rx2 = rx1 + size - 4;
-				int ry2 = ry1 + _dims.height() * _scrollSize;
-				Common::Rect rr(rx1, ry1, rx2, ry2);
-
-				drawFilledRect(rr, kColorBlack, drawPixelInverted, g);
-			}
-		}
-		if (closeable) {
-			if (_highlightedPart == kBorderCloseButton) {
-				fillRect(g, x + 6, y + 6, 6, 6, kColorBlack);
-			} else {
-				drawBox(g, x + 5, y + 5, 7, 7);
-			}
-		}
-	}
-
-	if (drawTitle) {
-		const Font *font = getTitleFont();
-		int yOff = _wm->hasBuiltInFonts() ? 3 : 1;
-
-		int w = font->getStringWidth(_title) + 10;
-		int maxWidth = width - size * 2 - 7;
-		if (w > maxWidth)
-			w = maxWidth;
-		drawBox(g, x + (width - w) / 2, y, w, size);
-		font->drawString(g, _title, x + (width - w) / 2 + 5, y + yOff, w, kColorBlack);
-	}
-}
-
-void MacWindow::setHighlight(WindowClick highlightedPart) {
-	if (_highlightedPart == highlightedPart)
-		return;
-
-	_highlightedPart = highlightedPart;
-	_borderIsDirty = true;
-}
-
-void MacWindow::setScroll(float scrollPos, float scrollSize) {
-	if (_scrollPos == scrollPos && _scrollSize == scrollSize)
-		return;
-
-	_scrollPos = scrollPos;
-	_scrollSize = scrollSize;
-	_borderIsDirty = true;
-}
-
-
-void MacWindow::drawBox(ManagedSurface *g, int x, int y, int w, int h) {
-	Common::Rect r(x, y, x + w + 1, y + h + 1);
-
-	g->fillRect(r, kColorWhite);
-	g->frameRect(r, kColorBlack);
-}
-
-void MacWindow::fillRect(ManagedSurface *g, int x, int y, int w, int h, int color) {
-	Common::Rect r(x, y, x + w, y + h);
-
-	g->fillRect(r, color);
-}
-
-WindowClick MacWindow::isInBorder(int x, int y) {
-	if (_innerDims.contains(x, y))
-		return kBorderInner;
-
-	if (x >= _innerDims.left - kBorderWidth && x < _innerDims.left && y >= _innerDims.top - kBorderWidth && y < _innerDims.top)
-		return kBorderCloseButton;
-
-	if (_resizable)
-		if (x >= _innerDims.right && x < _innerDims.right + kBorderWidth && y >= _innerDims.bottom && y < _innerDims.bottom + kBorderWidth)
-			return kBorderResizeButton;
-
-	if (_scrollable && x >= _innerDims.right && x < _innerDims.right + kBorderWidth) {
-		if (y < _innerDims.top - kBorderWidth)
-			return kBorderBorder;
-
-		if (y >= _innerDims.bottom + kBorderWidth)
-			return kBorderBorder;
-
-		if (y >= _innerDims.top + _innerDims.height() / 2)
-			return kBorderScrollDown;
-
-		return kBorderScrollUp;
-	}
-
-	return kBorderBorder;
-}
-
-bool MacWindow::processEvent(Common::Event &event) {
-	WindowClick click = isInBorder(event.mouse.x, event.mouse.y);
-
-	switch (event.type) {
-	case Common::EVENT_MOUSEMOVE:
-		if (_beingDragged) {
-			_dims.translate(event.mouse.x - _draggedX, event.mouse.y - _draggedY);
-			updateInnerDims();
-
-			_draggedX = event.mouse.x;
-			_draggedY = event.mouse.y;
-
-			_wm->setFullRefresh(true);
-		}
-
-		if (_beingResized) {
-			resize(MAX(kBorderWidth * 4, _dims.width()  + event.mouse.x - _draggedX),
-				   MAX(kBorderWidth * 4, _dims.height() + event.mouse.y - _draggedY));
-
-			_draggedX = event.mouse.x;
-			_draggedY = event.mouse.y;
-
-			_wm->setFullRefresh(true);
-			(*_callback)(click, event, _dataPtr);
-		}
-		break;
-	case Common::EVENT_LBUTTONDOWN:
-		setHighlight(click);
-
-		if (click == kBorderBorder) {
-			_beingDragged = true;
-
-			_draggedX = event.mouse.x;
-			_draggedY = event.mouse.y;
-		}
-
-		if (click == kBorderResizeButton) {
-			_beingResized = true;
-
-			_draggedX = event.mouse.x;
-			_draggedY = event.mouse.y;
-		}
-
-		break;
-	case Common::EVENT_LBUTTONUP:
-		_beingDragged = false;
-		_beingResized = false;
-
-		setHighlight(kBorderNone);
-		break;
-	default:
-		return false;
-	}
-
-	return (*_callback)(click, event, _dataPtr);
-}
-
-} // End of namespace Wage
diff --git a/engines/wage/macwindow.h b/engines/wage/macwindow.h
deleted file mode 100644
index 55f9d5c..0000000
--- a/engines/wage/macwindow.h
+++ /dev/null
@@ -1,162 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * MIT License:
- *
- * Copyright (c) 2009 Alexei Svitkine, Eugene Sandulenko
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following
- * conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- */
-
-#ifndef GRAPHICS_MACWINDOW_H
-#define GRAPHICS_MACWINDOW_H
-
-#include "graphics/managed_surface.h"
-
-namespace Graphics {
-
-class MacWindowManager;
-
-enum WindowType {
-	kWindowUnknown,
-	kWindowWindow,
-	kWindowMenu
-};
-
-enum {
-	kBorderWidth = 17
-};
-
-enum WindowClick {
-	kBorderNone = 0,
-	kBorderScrollUp,
-	kBorderScrollDown,
-	kBorderCloseButton,
-	kBorderInner,
-	kBorderBorder,
-	kBorderResizeButton
-};
-
-class BaseMacWindow {
-public:
-	BaseMacWindow(int id, bool editable, MacWindowManager *wm);
-	virtual ~BaseMacWindow() {}
-
-	const Common::Rect &getDimensions() { return _dims; }
-	int getId() { return _id; }
-	WindowType getType() { return _type; }
-	bool isEditable() { return _editable; }
-	ManagedSurface *getSurface() { return &_surface; }
-	virtual void setActive(bool active) = 0;
-	void setDirty(bool dirty) { _contentIsDirty = dirty; }
-
-	virtual bool draw(ManagedSurface *g, bool forceRedraw = false) = 0;
-	virtual bool processEvent(Common::Event &event) = 0;
-
-	virtual bool hasAllFocus() = 0;
-
-	void setCallback(bool (*callback)(WindowClick, Common::Event &, void *), void *data) { _callback = callback; _dataPtr = data; }
-
-protected:
-	int _id;
-	WindowType _type;
-
-	bool _editable;
-
-	ManagedSurface _surface;
-	bool _contentIsDirty;
-
-	Common::Rect _dims;
-
-	bool (*_callback)(WindowClick, Common::Event &, void *);
-	void *_dataPtr;
-
-	MacWindowManager *_wm;
-};
-
-class MacWindow : public BaseMacWindow {
-public:
-	MacWindow(int id, bool scrollable, bool resizable, bool editable, MacWindowManager *wm);
-	virtual ~MacWindow();
-	void move(int x, int y);
-	void resize(int w, int h);
-	void setDimensions(const Common::Rect &r);
-	const Common::Rect &getInnerDimensions() { return _innerDims; }
-
-	bool draw(ManagedSurface *g, bool forceRedraw = false);
-
-	void setActive(bool active);
-	void setTitle(Common::String &title) { _title = title; }
-	void setHighlight(WindowClick highlightedPart);
-	void setScroll(float scrollPos, float scrollSize);
-	bool processEvent(Common::Event &event);
-	bool hasAllFocus() { return _beingDragged || _beingResized; }
-
-private:
-	void drawBorder();
-	void drawBox(ManagedSurface *g, int x, int y, int w, int h);
-	void fillRect(ManagedSurface *g, int x, int y, int w, int h, int color);
-	const Font *getTitleFont();
-	void updateInnerDims();
-	WindowClick isInBorder(int x, int y);
-
-private:
-	ManagedSurface _borderSurface;
-	ManagedSurface _composeSurface;
-	bool _scrollable;
-	bool _resizable;
-	bool _active;
-	bool _borderIsDirty;
-
-	bool _beingDragged, _beingResized;
-	int _draggedX, _draggedY;
-
-	WindowClick _highlightedPart;
-	float _scrollPos, _scrollSize;
-
-	Common::Rect _innerDims;
-
-	Common::String _title;
-};
-
-} // End of namespace Graphics
-
-
-#endif
diff --git a/engines/wage/module.mk b/engines/wage/module.mk
index 43f0f0f..46d3980 100644
--- a/engines/wage/module.mk
+++ b/engines/wage/module.mk
@@ -10,7 +10,6 @@ MODULE_OBJS := \
 	gui.o \
 	gui-console.o \
 	macmenu.o \
-	macwindow.o \
 	randomhat.o \
 	saveload.o \
 	script.o \
diff --git a/graphics/macgui/macwindow.cpp b/graphics/macgui/macwindow.cpp
new file mode 100644
index 0000000..0d43b6d
--- /dev/null
+++ b/graphics/macgui/macwindow.cpp
@@ -0,0 +1,375 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * MIT License:
+ *
+ * Copyright (c) 2009 Alexei Svitkine, Eugene Sandulenko
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#include "graphics/font.h"
+#include "graphics/primitives.h"
+#include "common/events.h"
+#include "graphics/macgui/macwindowmanager.h"
+#include "graphics/macgui/macwindow.h"
+
+namespace Graphics {
+
+BaseMacWindow::BaseMacWindow(int id, bool editable, MacWindowManager *wm) :
+		_id(id), _editable(editable), _wm(wm) {
+	_callback = 0;
+	_dataPtr = 0;
+
+	_contentIsDirty = true;
+
+	_type = kWindowUnknown;
+}
+
+MacWindow::MacWindow(int id, bool scrollable, bool resizable, bool editable, MacWindowManager *wm) :
+		BaseMacWindow(id, editable, wm), _scrollable(scrollable), _resizable(resizable) {
+	_active = false;
+	_borderIsDirty = true;
+
+	_highlightedPart = kBorderNone;
+
+	_scrollPos = _scrollSize = 0.0;
+
+	_beingDragged = false;
+	_beingResized = false;
+
+	_draggedX = _draggedY = 0;
+
+	_type = kWindowWindow;
+}
+
+MacWindow::~MacWindow() {
+}
+
+const Font *MacWindow::getTitleFont() {
+	return _wm->getFont("Chicago-12", FontManager::kBigGUIFont);
+}
+
+void MacWindow::setActive(bool active) {
+	if (active == _active)
+		return;
+
+	_active = active;
+	_borderIsDirty = true;
+}
+
+void MacWindow::resize(int w, int h) {
+	if (_surface.w == w && _surface.h == h)
+		return;
+
+	_surface.free();
+	_surface.create(w, h, PixelFormat::createFormatCLUT8());
+	_borderSurface.free();
+	_borderSurface.create(w, h, PixelFormat::createFormatCLUT8());
+	_composeSurface.free();
+	_composeSurface.create(w, h, PixelFormat::createFormatCLUT8());
+
+	_dims.setWidth(w);
+	_dims.setHeight(h);
+
+	updateInnerDims();
+
+	_contentIsDirty = true;
+	_borderIsDirty = true;
+}
+
+void MacWindow::move(int x, int y) {
+	if (_dims.left == x && _dims.top == y)
+		return;
+
+	_dims.moveTo(x, y);
+	updateInnerDims();
+
+	_contentIsDirty = true;
+}
+
+void MacWindow::setDimensions(const Common::Rect &r) {
+	resize(r.width(), r.height());
+	_dims.moveTo(r.left, r.top);
+	updateInnerDims();
+
+	_contentIsDirty = true;
+}
+
+bool MacWindow::draw(ManagedSurface *g, bool forceRedraw) {
+	if (!_borderIsDirty && !_contentIsDirty && !forceRedraw)
+		return false;
+
+	if (_borderIsDirty || forceRedraw)
+		drawBorder();
+
+	_contentIsDirty = false;
+
+	// Compose
+	_composeSurface.blitFrom(_surface, Common::Rect(0, 0, _surface.w - 2, _surface.h - 2), Common::Point(2, 2));
+	_composeSurface.transBlitFrom(_borderSurface, kColorGreen);
+
+	g->transBlitFrom(_composeSurface, _composeSurface.getBounds(), Common::Point(_dims.left - 2, _dims.top - 2), kColorGreen2);
+
+	return true;
+}
+
+#define ARROW_W 12
+#define ARROW_H 6
+const int arrowPixels[ARROW_H][ARROW_W] = {
+		{0,0,0,0,0,1,1,0,0,0,0,0},
+		{0,0,0,0,1,1,1,1,0,0,0,0},
+		{0,0,0,1,1,1,1,1,1,0,0,0},
+		{0,0,1,1,1,1,1,1,1,1,0,0},
+		{0,1,1,1,1,1,1,1,1,1,1,0},
+		{1,1,1,1,1,1,1,1,1,1,1,1}};
+
+static void drawPixelInverted(int x, int y, int color, void *data) {
+	ManagedSurface *surface = (ManagedSurface *)data;
+
+	if (x >= 0 && x < surface->w && y >= 0 && y < surface->h) {
+		byte *p = (byte *)surface->getBasePtr(x, y);
+
+		*p = *p == kColorWhite ? kColorBlack : kColorWhite;
+	}
+}
+
+void MacWindow::updateInnerDims() {
+	_innerDims = _dims;
+	_innerDims.grow(-kBorderWidth);
+}
+
+void MacWindow::drawBorder() {
+	_borderIsDirty = false;
+
+	bool active = _active, scrollable = _scrollable, closeable = _active, drawTitle = !_title.empty();
+	const int size = kBorderWidth;
+	int x = 0;
+	int y = 0;
+	int width = _borderSurface.w;
+	int height = _borderSurface.h;
+	ManagedSurface *g = &_borderSurface;
+
+	// We draw rect with outer kColorGreen2 and inner kColorGreen, so on 2 passes we cut out
+	// scene by external shape of the border
+	int sz = kBorderWidth / 2;
+	g->clear(kColorGreen2);
+	g->fillRect(Common::Rect(sz, sz, width - sz, height - sz), kColorGreen);
+
+	drawBox(g, x,                    y,                     size,                 size);
+	drawBox(g, x + width - size - 1, y,                     size,                 size);
+	drawBox(g, x + width - size - 1, y + height - size - 1, size,                 size);
+	drawBox(g, x,                    y + height - size - 1, size,                 size);
+	drawBox(g, x + size,             y + 2,                 width - 2 * size - 1, size - 4);
+	drawBox(g, x + size,             y + height - size + 1, width - 2 * size - 1, size - 4);
+	drawBox(g, x + 2,                y + size,              size - 4,             height - 2 * size - 1);
+	drawBox(g, x + width - size + 1, y + size,              size - 4,             height - 2 * size - 1);
+
+	if (active) {
+		fillRect(g, x + size, y + 5,           width - 2 * size - 1, 8, kColorBlack);
+		fillRect(g, x + size, y + height - 13, width - 2 * size - 1, 8, kColorBlack);
+		fillRect(g, x + 5,    y + size,        8,                    height - 2 * size - 1, kColorBlack);
+		if (!scrollable) {
+			fillRect(g, x + width - 13, y + size, 8, height - 2 * size - 1, kColorBlack);
+		} else {
+			int x1 = x + width - 15;
+			int y1 = y + size + 1;
+
+			for (int yy = 0; yy < ARROW_H; yy++) {
+				for (int xx = 0; xx < ARROW_W; xx++)
+					g->hLine(x1 + xx, y1 + yy, x1 + xx, (arrowPixels[yy][xx] != 0 ? kColorBlack : kColorWhite));
+			}
+
+			fillRect(g, x + width - 13, y + size + ARROW_H, 8, height - 2 * size - 1 - ARROW_H * 2, kColorBlack);
+
+			y1 += height - 2 * size - ARROW_H - 2;
+			for (int yy = 0; yy < ARROW_H; yy++) {
+				for (int xx = 0; xx < ARROW_W; xx++)
+					g->hLine(x1 + xx, y1 + yy, x1 + xx, (arrowPixels[ARROW_H - yy - 1][xx] != 0 ? kColorBlack : kColorWhite));
+			}
+
+			if (_highlightedPart == kBorderScrollUp || _highlightedPart == kBorderScrollDown) {
+				int rx1 = x + width - kBorderWidth + 2;
+				int ry1 = y + size + _dims.height() * _scrollPos;
+				int rx2 = rx1 + size - 4;
+				int ry2 = ry1 + _dims.height() * _scrollSize;
+				Common::Rect rr(rx1, ry1, rx2, ry2);
+
+				drawFilledRect(rr, kColorBlack, drawPixelInverted, g);
+			}
+		}
+		if (closeable) {
+			if (_highlightedPart == kBorderCloseButton) {
+				fillRect(g, x + 6, y + 6, 6, 6, kColorBlack);
+			} else {
+				drawBox(g, x + 5, y + 5, 7, 7);
+			}
+		}
+	}
+
+	if (drawTitle) {
+		const Font *font = getTitleFont();
+		int yOff = _wm->hasBuiltInFonts() ? 3 : 1;
+
+		int w = font->getStringWidth(_title) + 10;
+		int maxWidth = width - size * 2 - 7;
+		if (w > maxWidth)
+			w = maxWidth;
+		drawBox(g, x + (width - w) / 2, y, w, size);
+		font->drawString(g, _title, x + (width - w) / 2 + 5, y + yOff, w, kColorBlack);
+	}
+}
+
+void MacWindow::setHighlight(WindowClick highlightedPart) {
+	if (_highlightedPart == highlightedPart)
+		return;
+
+	_highlightedPart = highlightedPart;
+	_borderIsDirty = true;
+ }
+
+ void MacWindow::setScroll(float scrollPos, float scrollSize) {
+	if (_scrollPos == scrollPos && _scrollSize == scrollSize)
+		return;
+
+	_scrollPos = scrollPos;
+	_scrollSize = scrollSize;
+	_borderIsDirty = true;
+ }
+
+
+void MacWindow::drawBox(ManagedSurface *g, int x, int y, int w, int h) {
+	Common::Rect r(x, y, x + w + 1, y + h + 1);
+
+	g->fillRect(r, kColorWhite);
+	g->frameRect(r, kColorBlack);
+}
+
+void MacWindow::fillRect(ManagedSurface *g, int x, int y, int w, int h, int color) {
+	Common::Rect r(x, y, x + w, y + h);
+
+	g->fillRect(r, color);
+}
+
+WindowClick MacWindow::isInBorder(int x, int y) {
+	if (_innerDims.contains(x, y))
+		return kBorderInner;
+
+	if (x >= _innerDims.left - kBorderWidth && x < _innerDims.left && y >= _innerDims.top - kBorderWidth && y < _innerDims.top)
+		return kBorderCloseButton;
+
+	if (_resizable)
+		if (x >= _innerDims.right && x < _innerDims.right + kBorderWidth && y >= _innerDims.bottom && y < _innerDims.bottom + kBorderWidth)
+			return kBorderResizeButton;
+
+	if (_scrollable && x >= _innerDims.right && x < _innerDims.right + kBorderWidth) {
+		if (y < _innerDims.top - kBorderWidth)
+			return kBorderBorder;
+
+		if (y >= _innerDims.bottom + kBorderWidth)
+			return kBorderBorder;
+
+		if (y >= _innerDims.top + _innerDims.height() / 2)
+			return kBorderScrollDown;
+
+		return kBorderScrollUp;
+	}
+
+	return kBorderBorder;
+}
+
+bool MacWindow::processEvent(Common::Event &event) {
+	WindowClick click = isInBorder(event.mouse.x, event.mouse.y);
+
+	switch (event.type) {
+	case Common::EVENT_MOUSEMOVE:
+		if (_beingDragged) {
+			_dims.translate(event.mouse.x - _draggedX, event.mouse.y - _draggedY);
+			updateInnerDims();
+
+			_draggedX = event.mouse.x;
+			_draggedY = event.mouse.y;
+
+			_wm->setFullRefresh(true);
+		}
+
+		if (_beingResized) {
+			resize(MAX(kBorderWidth * 4, _dims.width()  + event.mouse.x - _draggedX),
+				   MAX(kBorderWidth * 4, _dims.height() + event.mouse.y - _draggedY));
+
+			_draggedX = event.mouse.x;
+			_draggedY = event.mouse.y;
+
+			_wm->setFullRefresh(true);
+			(*_callback)(click, event, _dataPtr);
+		}
+		break;
+	case Common::EVENT_LBUTTONDOWN:
+		setHighlight(click);
+
+		if (click == kBorderBorder) {
+			_beingDragged = true;
+
+			_draggedX = event.mouse.x;
+			_draggedY = event.mouse.y;
+		}
+
+		if (click == kBorderResizeButton) {
+			_beingResized = true;
+
+			_draggedX = event.mouse.x;
+			_draggedY = event.mouse.y;
+		}
+
+		break;
+	case Common::EVENT_LBUTTONUP:
+		_beingDragged = false;
+		_beingResized = false;
+
+		setHighlight(kBorderNone);
+		break;
+	default:
+		return false;
+	}
+
+	return (*_callback)(click, event, _dataPtr);
+}
+
+} // End of namespace Wage
diff --git a/graphics/macgui/macwindow.h b/graphics/macgui/macwindow.h
new file mode 100644
index 0000000..55f9d5c
--- /dev/null
+++ b/graphics/macgui/macwindow.h
@@ -0,0 +1,162 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * MIT License:
+ *
+ * Copyright (c) 2009 Alexei Svitkine, Eugene Sandulenko
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#ifndef GRAPHICS_MACWINDOW_H
+#define GRAPHICS_MACWINDOW_H
+
+#include "graphics/managed_surface.h"
+
+namespace Graphics {
+
+class MacWindowManager;
+
+enum WindowType {
+	kWindowUnknown,
+	kWindowWindow,
+	kWindowMenu
+};
+
+enum {
+	kBorderWidth = 17
+};
+
+enum WindowClick {
+	kBorderNone = 0,
+	kBorderScrollUp,
+	kBorderScrollDown,
+	kBorderCloseButton,
+	kBorderInner,
+	kBorderBorder,
+	kBorderResizeButton
+};
+
+class BaseMacWindow {
+public:
+	BaseMacWindow(int id, bool editable, MacWindowManager *wm);
+	virtual ~BaseMacWindow() {}
+
+	const Common::Rect &getDimensions() { return _dims; }
+	int getId() { return _id; }
+	WindowType getType() { return _type; }
+	bool isEditable() { return _editable; }
+	ManagedSurface *getSurface() { return &_surface; }
+	virtual void setActive(bool active) = 0;
+	void setDirty(bool dirty) { _contentIsDirty = dirty; }
+
+	virtual bool draw(ManagedSurface *g, bool forceRedraw = false) = 0;
+	virtual bool processEvent(Common::Event &event) = 0;
+
+	virtual bool hasAllFocus() = 0;
+
+	void setCallback(bool (*callback)(WindowClick, Common::Event &, void *), void *data) { _callback = callback; _dataPtr = data; }
+
+protected:
+	int _id;
+	WindowType _type;
+
+	bool _editable;
+
+	ManagedSurface _surface;
+	bool _contentIsDirty;
+
+	Common::Rect _dims;
+
+	bool (*_callback)(WindowClick, Common::Event &, void *);
+	void *_dataPtr;
+
+	MacWindowManager *_wm;
+};
+
+class MacWindow : public BaseMacWindow {
+public:
+	MacWindow(int id, bool scrollable, bool resizable, bool editable, MacWindowManager *wm);
+	virtual ~MacWindow();
+	void move(int x, int y);
+	void resize(int w, int h);
+	void setDimensions(const Common::Rect &r);
+	const Common::Rect &getInnerDimensions() { return _innerDims; }
+
+	bool draw(ManagedSurface *g, bool forceRedraw = false);
+
+	void setActive(bool active);
+	void setTitle(Common::String &title) { _title = title; }
+	void setHighlight(WindowClick highlightedPart);
+	void setScroll(float scrollPos, float scrollSize);
+	bool processEvent(Common::Event &event);
+	bool hasAllFocus() { return _beingDragged || _beingResized; }
+
+private:
+	void drawBorder();
+	void drawBox(ManagedSurface *g, int x, int y, int w, int h);
+	void fillRect(ManagedSurface *g, int x, int y, int w, int h, int color);
+	const Font *getTitleFont();
+	void updateInnerDims();
+	WindowClick isInBorder(int x, int y);
+
+private:
+	ManagedSurface _borderSurface;
+	ManagedSurface _composeSurface;
+	bool _scrollable;
+	bool _resizable;
+	bool _active;
+	bool _borderIsDirty;
+
+	bool _beingDragged, _beingResized;
+	int _draggedX, _draggedY;
+
+	WindowClick _highlightedPart;
+	float _scrollPos, _scrollSize;
+
+	Common::Rect _innerDims;
+
+	Common::String _title;
+};
+
+} // End of namespace Graphics
+
+
+#endif
diff --git a/graphics/macgui/macwindowmanager.cpp b/graphics/macgui/macwindowmanager.cpp
index 6ec1831..dc2c46c 100644
--- a/graphics/macgui/macwindowmanager.cpp
+++ b/graphics/macgui/macwindowmanager.cpp
@@ -58,8 +58,8 @@
 #include "graphics/palette.h"
 #include "graphics/primitives.h"
 #include "graphics/macgui/macwindowmanager.h"
+#include "graphics/macgui/macwindow.h"
 
-#include "wage/macwindow.h"
 #include "wage/macmenu.h"
 
 namespace Graphics {
diff --git a/graphics/macgui/macwindowmanager.h b/graphics/macgui/macwindowmanager.h
index 45532ed..9a8be93 100644
--- a/graphics/macgui/macwindowmanager.h
+++ b/graphics/macgui/macwindowmanager.h
@@ -54,8 +54,7 @@
 #include "common/archive.h"
 
 #include "graphics/fontman.h"
-
-#include "engines/wage/macwindow.h"
+#include "graphics/macgui/macwindow.h"
 
 namespace Wage {
 	class MacWindow;
diff --git a/graphics/module.mk b/graphics/module.mk
index 4d6c11b..2e033d9 100644
--- a/graphics/module.mk
+++ b/graphics/module.mk
@@ -29,7 +29,8 @@ MODULE_OBJS := \
 	VectorRendererSpec.o \
 	wincursor.o \
 	yuv_to_rgb.o \
-	macgui/macwindowmanager.o
+	macgui/macwindowmanager.o\
+	macgui/macwindow.o
 
 ifdef USE_SCALERS
 MODULE_OBJS += \


Commit: d8652af84e4f909854d753f0ed6aa1dcc4b0a269
    https://github.com/scummvm/scummvm/commit/d8652af84e4f909854d753f0ed6aa1dcc4b0a269
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-07-30T10:06:14+02:00

Commit Message:
GRAPHICS: Change namespace of MacMenu

Changed paths:
    graphics/macgui/macwindowmanager.cpp
    graphics/macgui/macwindowmanager.h



diff --git a/graphics/macgui/macwindowmanager.cpp b/graphics/macgui/macwindowmanager.cpp
index dc2c46c..7d919a4 100644
--- a/graphics/macgui/macwindowmanager.cpp
+++ b/graphics/macgui/macwindowmanager.cpp
@@ -158,8 +158,8 @@ MacWindow *MacWindowManager::addWindow(bool scrollable, bool resizable, bool edi
     return w;
 }
 
-Wage::Menu *MacWindowManager::addMenu() {
-	_menu = new Wage::Menu(_lastId, _screen->getBounds(), this);
+Menu *MacWindowManager::addMenu() {
+	_menu = new Menu(_lastId, _screen->getBounds(), this);
 
 	_windows.push_back(_menu);
 
diff --git a/graphics/macgui/macwindowmanager.h b/graphics/macgui/macwindowmanager.h
index 9a8be93..e30d2d8 100644
--- a/graphics/macgui/macwindowmanager.h
+++ b/graphics/macgui/macwindowmanager.h
@@ -56,12 +56,6 @@
 #include "graphics/fontman.h"
 #include "graphics/macgui/macwindow.h"
 
-namespace Wage {
-	class MacWindow;
-	class BaseMacWindow;
-	class Menu;
-}
-
 namespace Graphics {	
 
 enum {
@@ -85,6 +79,8 @@ enum {
 
 class ManagedSurface;
 
+class Menu;
+
 typedef Common::Array<byte *> Patterns;
 
 class MacWindowManager {
@@ -97,7 +93,7 @@ public:
 	const Font *getFont(const char *name, FontManager::FontUsage fallback);
 
 	MacWindow *addWindow(bool scrollable, bool resizable, bool editable);
-	Wage::Menu *addMenu();
+	Menu *addMenu();
 	void setActive(int id);
 
 	void setFullRefresh(bool redraw) { _fullRefresh = true; }
@@ -131,7 +127,7 @@ private:
 
 	Patterns _patterns;
 
-	Wage::Menu *_menu;
+	Menu *_menu;
 
 	bool _builtInFonts;
 	bool _cursorIsArrow;


Commit: 8a2aeeecc942b6f8991cbdc6577313a6e8f74d9d
    https://github.com/scummvm/scummvm/commit/8a2aeeecc942b6f8991cbdc6577313a6e8f74d9d
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-07-30T10:06:14+02:00

Commit Message:
WAGE: Adapt to MacMenu namespace change

Changed paths:
    engines/wage/gui-console.cpp
    engines/wage/gui.cpp
    engines/wage/gui.h
    engines/wage/macmenu.cpp
    engines/wage/macmenu.h



diff --git a/engines/wage/gui-console.cpp b/engines/wage/gui-console.cpp
index 1ae0384..d06b8da 100644
--- a/engines/wage/gui-console.cpp
+++ b/engines/wage/gui-console.cpp
@@ -348,7 +348,7 @@ void Gui::actionCopy() {
 		}
 	}
 
-	_menu->enableCommand(kMenuEdit, kMenuActionPaste, true);
+	_menu->enableCommand(Graphics::kMenuEdit, Graphics::kMenuActionPaste, true);
 }
 
 void Gui::actionPaste() {
@@ -357,14 +357,14 @@ void Gui::actionPaste() {
 	drawInput();
 	_engine->_inputText = _out.back();	// Set last part of the multiline text
 
-	_menu->enableCommand(kMenuEdit, kMenuActionUndo, true);
+	_menu->enableCommand(Graphics::kMenuEdit, Graphics::kMenuActionUndo, true);
 }
 
 void Gui::actionUndo() {
 	_engine->_inputText = _undobuffer;
 	drawInput();
 
-	_menu->enableCommand(kMenuEdit, kMenuActionUndo, false);
+	_menu->enableCommand(Graphics::kMenuEdit, Graphics::kMenuActionUndo, false);
 }
 
 void Gui::actionClear() {
@@ -381,7 +381,7 @@ void Gui::actionClear() {
 	_engine->_inputText = beg + end;
 	drawInput();
 
-	_menu->enableCommand(kMenuEdit, kMenuActionUndo, true);
+	_menu->enableCommand(Graphics::kMenuEdit, Graphics::kMenuActionUndo, true);
 
 	_selectionStartY = -1;
 	_selectionEndY = -1;
@@ -403,15 +403,15 @@ void Gui::actionCut() {
 	_clipboard = mid;
 	drawInput();
 
-	_menu->enableCommand(kMenuEdit, kMenuActionUndo, true);
-	_menu->enableCommand(kMenuEdit, kMenuActionPaste, true);
+	_menu->enableCommand(Graphics::kMenuEdit, Graphics::kMenuActionUndo, true);
+	_menu->enableCommand(Graphics::kMenuEdit, Graphics::kMenuActionPaste, true);
 
 	_selectionStartY = -1;
 	_selectionEndY = -1;
 }
 
 void Gui::disableUndo() {
-	_menu->enableCommand(kMenuEdit, kMenuActionUndo, false);
+	_menu->enableCommand(Graphics::kMenuEdit, Graphics::kMenuActionUndo, false);
 }
 
 void Gui::disableAllMenus() {
@@ -419,9 +419,9 @@ void Gui::disableAllMenus() {
 }
 
 void Gui::enableNewGameMenus() {
-	_menu->enableCommand(kMenuFile, kMenuActionNew, true);
-	_menu->enableCommand(kMenuFile, kMenuActionOpen, true);
-	_menu->enableCommand(kMenuFile, kMenuActionQuit, true);
+	_menu->enableCommand(Graphics::kMenuFile, Graphics::kMenuActionNew, true);
+	_menu->enableCommand(Graphics::kMenuFile, Graphics::kMenuActionOpen, true);
+	_menu->enableCommand(Graphics::kMenuFile, Graphics::kMenuActionQuit, true);
 }
 
 bool Gui::processConsoleEvents(Graphics::WindowClick click, Common::Event &event) {
@@ -483,17 +483,17 @@ bool Gui::processConsoleEvents(Graphics::WindowClick click, Common::Event &event
 						(_selectionEndX == _selectionStartX && _selectionEndY == _selectionStartY)) {
 					_selectionStartY = _selectionEndY = -1;
 					_consoleFullRedraw = true;
-					_menu->enableCommand(kMenuEdit, kMenuActionCopy, false);
+					_menu->enableCommand(Graphics::kMenuEdit, Graphics::kMenuActionCopy, false);
 				} else {
-					_menu->enableCommand(kMenuEdit, kMenuActionCopy, true);
+					_menu->enableCommand(Graphics::kMenuEdit, Graphics::kMenuActionCopy, true);
 
 					bool cutAllowed = false;
 
 					if (_selectionStartY == _selectionEndY && _selectionStartY == (int)_lines.size() - 1)
 						cutAllowed = true;
 
-					_menu->enableCommand(kMenuEdit, kMenuActionCut, cutAllowed);
-					_menu->enableCommand(kMenuEdit, kMenuActionClear, cutAllowed);
+					_menu->enableCommand(Graphics::kMenuEdit, Graphics::kMenuActionCut, cutAllowed);
+					_menu->enableCommand(Graphics::kMenuEdit, Graphics::kMenuActionClear, cutAllowed);
 				}
 			}
 
diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp
index 532aa5f..7d329d2 100644
--- a/engines/wage/gui.cpp
+++ b/engines/wage/gui.cpp
@@ -61,23 +61,23 @@
 
 namespace Wage {
 
-static const MenuData menuSubItems[] = {
-	{ kMenuHighLevel, "File",	0, 0, false },
-	{ kMenuHighLevel, "Edit",	0, 0, false },
-	{ kMenuFile, "New",			kMenuActionNew, 0, false },
-	{ kMenuFile, "Open...",		kMenuActionOpen, 0, true },
-	{ kMenuFile, "Close",		kMenuActionClose, 0, true },
-	{ kMenuFile, "Save",		kMenuActionSave, 0, true },
-	{ kMenuFile, "Save as...",	kMenuActionSaveAs, 0, true },
-	{ kMenuFile, "Revert",		kMenuActionRevert, 0, false },
-	{ kMenuFile, "Quit",		kMenuActionQuit, 0, true },
-
-	{ kMenuEdit, "Undo",		kMenuActionUndo, 'Z', false },
-	{ kMenuEdit, NULL,			0, 0, false },
-	{ kMenuEdit, "Cut",			kMenuActionCut, 'K', false },
-	{ kMenuEdit, "Copy",		kMenuActionCopy, 'C', false },
-	{ kMenuEdit, "Paste",		kMenuActionPaste, 'V', false },
-	{ kMenuEdit, "Clear",		kMenuActionClear, 'B', false },
+static const Graphics::MenuData menuSubItems[] = {
+	{ Graphics::kMenuHighLevel, "File",	0, 0, false },
+	{ Graphics::kMenuHighLevel, "Edit",	0, 0, false },
+	{ Graphics::kMenuFile, "New",			Graphics::kMenuActionNew, 0, false },
+	{ Graphics::kMenuFile, "Open...",		Graphics::kMenuActionOpen, 0, true },
+	{ Graphics::kMenuFile, "Close",			Graphics::kMenuActionClose, 0, true },
+	{ Graphics::kMenuFile, "Save",			Graphics::kMenuActionSave, 0, true },
+	{ Graphics::kMenuFile, "Save as...",	Graphics::kMenuActionSaveAs, 0, true },
+	{ Graphics::kMenuFile, "Revert",		Graphics::kMenuActionRevert, 0, false },
+	{ Graphics::kMenuFile, "Quit",			Graphics::kMenuActionQuit, 0, true },
+
+	{ Graphics::kMenuEdit, "Undo",			Graphics::kMenuActionUndo, 'Z', false },
+	{ Graphics::kMenuEdit, NULL,			0, 0, false },
+	{ Graphics::kMenuEdit, "Cut",			Graphics::kMenuActionCut, 'K', false },
+	{ Graphics::kMenuEdit, "Copy",			Graphics::kMenuActionCopy, 'C', false },
+	{ Graphics::kMenuEdit, "Paste",			Graphics::kMenuActionPaste, 'V', false },
+	{ Graphics::kMenuEdit, "Clear",			Graphics::kMenuActionClear, 'B', false },
 
 	{ 0, NULL,			0, 0, false }
 };
@@ -148,7 +148,7 @@ Gui::Gui(WageEngine *engine) {
 	_menu->setCommandsCallback(menuCommandsCallback, this);
 
 	_menu->addStaticMenus(menuSubItems);
-	_menu->addMenuSubItem(kMenuAbout, _engine->_world->getAboutMenuItemName(), kMenuActionAbout);
+	_menu->addMenuSubItem(Graphics::kMenuAbout, _engine->_world->getAboutMenuItemName(), Graphics::kMenuActionAbout);
 
 	_commandsMenuId = _menu->addMenuItem(_engine->_world->_commandsMenuName.c_str());
 	regenCommandsMenu();
@@ -298,7 +298,7 @@ void Gui::regenWeaponsMenu() {
 			command += " ";
 			command += obj->_name;
 
-			_menu->addMenuSubItem(_weaponsMenuId, command.c_str(), kMenuActionCommand, 0, 0, true);
+			_menu->addMenuSubItem(_weaponsMenuId, command.c_str(), Graphics::kMenuActionCommand, 0, 0, true);
 
 			empty = false;
 		}
@@ -321,39 +321,39 @@ void menuCommandsCallback(int action, Common::String &text, void *data) {
 
 void Gui::executeMenuCommand(int action, Common::String &text) {
 	switch(action) {
-	case kMenuActionAbout:
-	case kMenuActionNew:
-	case kMenuActionClose:
-	case kMenuActionRevert:
-	case kMenuActionQuit:
+	case Graphics::kMenuActionAbout:
+	case Graphics::kMenuActionNew:
+	case Graphics::kMenuActionClose:
+	case Graphics::kMenuActionRevert:
+	case Graphics::kMenuActionQuit:
 		break;
 
-	case kMenuActionOpen:
+	case Graphics::kMenuActionOpen:
 		_engine->scummVMSaveLoadDialog(false);
 		break;
 
-	case kMenuActionSave:
-	case kMenuActionSaveAs:
+	case Graphics::kMenuActionSave:
+	case Graphics::kMenuActionSaveAs:
 		_engine->scummVMSaveLoadDialog(true);
 		break;
 
-	case kMenuActionUndo:
+	case Graphics::kMenuActionUndo:
 		actionUndo();
 		break;
-	case kMenuActionCut:
+	case Graphics::kMenuActionCut:
 		actionCut();
 		break;
-	case kMenuActionCopy:
+	case Graphics::kMenuActionCopy:
 		actionCopy();
 		break;
-	case kMenuActionPaste:
+	case Graphics::kMenuActionPaste:
 		actionPaste();
 		break;
-	case kMenuActionClear:
+	case Graphics::kMenuActionClear:
 		actionClear();
 		break;
 
-	case kMenuActionCommand:
+	case Graphics::kMenuActionCommand:
 		_engine->processTurn(&text, NULL);
 		break;
 
diff --git a/engines/wage/gui.h b/engines/wage/gui.h
index 7355797..ed841b0 100644
--- a/engines/wage/gui.h
+++ b/engines/wage/gui.h
@@ -59,7 +59,6 @@
 
 namespace Wage {
 
-class Menu;
 class Scene;
 class WageEngine;
 
@@ -127,7 +126,7 @@ public:
 
 private:
 	Graphics::ManagedSurface _console;
-	Menu *_menu;
+	Graphics::Menu *_menu;
 	bool _sceneDirty;
 	bool _consoleDirty;
 
diff --git a/engines/wage/macmenu.cpp b/engines/wage/macmenu.cpp
index d6dec32..b776223 100644
--- a/engines/wage/macmenu.cpp
+++ b/engines/wage/macmenu.cpp
@@ -55,7 +55,7 @@
 
 #include "wage/macmenu.h"
 
-namespace Wage {
+namespace Graphics {
 
 enum {
 	kMenuHeight = 20,
@@ -89,11 +89,11 @@ struct MenuItem {
 	MenuItem(const char *n) : name(n) {}
 };
 
-Menu::Menu(int id, const Common::Rect &bounds, Graphics::MacWindowManager *wm)
+Menu::Menu(int id, const Common::Rect &bounds, MacWindowManager *wm)
 		: BaseMacWindow(id, false, wm) {
 	_font = getMenuFont();
 
-	_screen.create(bounds.width(), bounds.height(), Graphics::PixelFormat::createFormatCLUT8());
+	_screen.create(bounds.width(), bounds.height(), PixelFormat::createFormatCLUT8());
 
 	_bbox.left = 0;
 	_bbox.top = 0;
@@ -107,7 +107,7 @@ Menu::Menu(int id, const Common::Rect &bounds, Graphics::MacWindowManager *wm)
 	_ccallback = NULL;
 	_cdata = NULL;
 
-	_tempSurface.create(_screen.w, _font->getFontHeight(), Graphics::PixelFormat::createFormatCLUT8());
+	_tempSurface.create(_screen.w, _font->getFontHeight(), PixelFormat::createFormatCLUT8());
 }
 
 Menu::~Menu() {
@@ -250,8 +250,8 @@ void Menu::createSubMenuFromString(int id, const char *str) {
 	calcMenuBounds(menu);
 }
 
-const Graphics::Font *Menu::getMenuFont() {
-	return _wm->getFont("Chicago-12", Graphics::FontManager::kBigGUIFont);
+const Font *Menu::getMenuFont() {
+	return _wm->getFont("Chicago-12", FontManager::kBigGUIFont);
 }
 
 const char *Menu::getAcceleratorString(MenuSubItem *item, const char *prefix) {
@@ -299,17 +299,17 @@ void Menu::calcMenuBounds(MenuItem *menu) {
 }
 
 static void drawPixelPlain(int x, int y, int color, void *data) {
-	Graphics::ManagedSurface *surface = (Graphics::ManagedSurface *)data;
+	ManagedSurface *surface = (ManagedSurface *)data;
 
 	if (x >= 0 && x < surface->w && y >= 0 && y < surface->h)
 		*((byte *)surface->getBasePtr(x, y)) = (byte)color;
 }
 
-static void drawFilledRoundRect(Graphics::ManagedSurface *surface, Common::Rect &rect, int arc, int color) {
-	Graphics::drawRoundRect(rect, arc, color, true, drawPixelPlain, surface);
+static void drawFilledRoundRect(ManagedSurface *surface, Common::Rect &rect, int arc, int color) {
+	drawRoundRect(rect, arc, color, true, drawPixelPlain, surface);
 }
 
-bool Menu::draw(Graphics::ManagedSurface *g, bool forceRedraw) {
+bool Menu::draw(ManagedSurface *g, bool forceRedraw) {
 	Common::Rect r(_bbox);
 
 	if (!_contentIsDirty && !forceRedraw)
@@ -385,7 +385,7 @@ void Menu::renderSubmenu(MenuItem *menu) {
 		}
 
 		if (!text.empty()) {
-			Graphics::ManagedSurface *s = &_screen;
+			ManagedSurface *s = &_screen;
 			int tx = x, ty = y;
 
 			if (!menu->subitems[i]->enabled) {
diff --git a/engines/wage/macmenu.h b/engines/wage/macmenu.h
index 793cb27..e0309b2 100644
--- a/engines/wage/macmenu.h
+++ b/engines/wage/macmenu.h
@@ -45,15 +45,10 @@
  *
  */
 
-#ifndef WAGE_MACMENU_H
-#define WAGE_MACMENU_H
+#ifndef GRAPHICS_MACMENU_H
+#define GRAPHICS_MACMENU_H
 
 namespace Graphics {
-	class MacWindowManager;
-	class BaseMacWindow;
-}
-
-namespace Wage {
 
 struct MenuItem;
 struct MenuSubItem;
@@ -104,9 +99,9 @@ struct MenuData {
 	bool enabled;
 };
 
-class Menu : public Graphics::BaseMacWindow {
+class Menu : public BaseMacWindow {
 public:
-	Menu(int id, const Common::Rect &bounds, Graphics::MacWindowManager *wm);
+	Menu(int id, const Common::Rect &bounds, MacWindowManager *wm);
 	~Menu();
 
 	void setCommandsCallback(void (*callback)(int, Common::String &, void *), void *data) { _ccallback = callback; _cdata = data; }
@@ -119,7 +114,7 @@ public:
 	void createSubMenuFromString(int id, const char *string);
 	void clearSubMenu(int id);
 
-	bool draw(Graphics::ManagedSurface *g, bool forceRedraw = false);
+	bool draw(ManagedSurface *g, bool forceRedraw = false);
 	bool processEvent(Common::Event &event);
 
 	void enableCommand(int menunum, int action, bool state);
@@ -131,11 +126,11 @@ public:
 	Common::Rect _bbox;
 
 private:
-	Graphics::ManagedSurface _screen;
-	Graphics::ManagedSurface _tempSurface;
+	ManagedSurface _screen;
+	ManagedSurface _tempSurface;
 
 private:
-	const Graphics::Font *getMenuFont();
+	const Font *getMenuFont();
 	const char *getAcceleratorString(MenuSubItem *item, const char *prefix);
 	int calculateMenuWidth(MenuItem *menu);
 	void calcMenuBounds(MenuItem *menu);
@@ -150,7 +145,7 @@ private:
 
 	Common::Array<MenuItem *> _items;
 
-	const Graphics::Font *_font;
+	const Font *_font;
 
 	bool _menuActivated;
 
@@ -161,6 +156,6 @@ private:
 	void *_cdata;
 };
 
-} // End of namespace Wage
+} // End of namespace Graphics
 
 #endif


Commit: 68b2d44a0f732aed23afaa96e18b0786fca1d77d
    https://github.com/scummvm/scummvm/commit/68b2d44a0f732aed23afaa96e18b0786fca1d77d
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-07-31T14:04:48+02:00

Commit Message:
WAGE: Extract MacMenu

Changed paths:
  A graphics/macgui/macmenu.cpp
  A graphics/macgui/macmenu.h
  R engines/wage/macmenu.h
    engines/wage/gui-console.cpp
    engines/wage/gui.cpp
    engines/wage/module.mk
    graphics/macgui/macwindowmanager.cpp
    graphics/module.mk



diff --git a/engines/wage/gui-console.cpp b/engines/wage/gui-console.cpp
index d06b8da..87c84ad 100644
--- a/engines/wage/gui-console.cpp
+++ b/engines/wage/gui-console.cpp
@@ -52,11 +52,11 @@
 #include "graphics/fonts/bdf.h"
 #include "graphics/palette.h"
 #include "graphics/macgui/macwindow.h"
+#include "graphics/macgui/macmenu.h"
 
 #include "wage/wage.h"
 #include "wage/design.h"
 #include "wage/entities.h"
-#include "wage/macmenu.h"
 #include "wage/gui.h"
 #include "wage/world.h"
 
diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp
index 7d329d2..f8971e1 100644
--- a/engines/wage/gui.cpp
+++ b/engines/wage/gui.cpp
@@ -51,12 +51,12 @@
 #include "graphics/primitives.h"
 #include "graphics/macgui/macwindowmanager.h"
 #include "graphics/macgui/macwindow.h"
+#include "graphics/macgui/macmenu.h"
 
 #include "wage/wage.h"
 #include "wage/design.h"
 #include "wage/entities.h"
 #include "wage/gui.h"
-#include "wage/macmenu.h"
 #include "wage/world.h"
 
 namespace Wage {
diff --git a/engines/wage/macmenu.h b/engines/wage/macmenu.h
deleted file mode 100644
index e0309b2..0000000
--- a/engines/wage/macmenu.h
+++ /dev/null
@@ -1,161 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * MIT License:
- *
- * Copyright (c) 2009 Alexei Svitkine, Eugene Sandulenko
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following
- * conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- */
-
-#ifndef GRAPHICS_MACMENU_H
-#define GRAPHICS_MACMENU_H
-
-namespace Graphics {
-
-struct MenuItem;
-struct MenuSubItem;
-
-enum {
-	kFontStyleBold = 1,
-	kFontStyleItalic = 2,
-	kFontStyleUnderline = 4,
-	kFontStyleOutline = 8,
-	kFontStyleShadow = 16,
-	kFontStyleCondensed = 32,
-	kFontStyleExtended = 64
-};
-
-enum {
-	kMenuHighLevel = -1,
-	kMenuAbout = 0,
-	kMenuFile = 1,
-	kMenuEdit = 2,
-	kMenuCommands = 3,
-	kMenuWeapons = 4
-};
-
-enum {
-	kMenuActionAbout,
-	kMenuActionNew,
-	kMenuActionOpen,
-	kMenuActionClose,
-	kMenuActionSave,
-	kMenuActionSaveAs,
-	kMenuActionRevert,
-	kMenuActionQuit,
-
-	kMenuActionUndo,
-	kMenuActionCut,
-	kMenuActionCopy,
-	kMenuActionPaste,
-	kMenuActionClear,
-
-	kMenuActionCommand
-};
-
-struct MenuData {
-	int menunum;
-	const char *title;
-	int action;
-	byte shortcut;
-	bool enabled;
-};
-
-class Menu : public BaseMacWindow {
-public:
-	Menu(int id, const Common::Rect &bounds, MacWindowManager *wm);
-	~Menu();
-
-	void setCommandsCallback(void (*callback)(int, Common::String &, void *), void *data) { _ccallback = callback; _cdata = data; }
-
-	void addStaticMenus(const MenuData *data);
-	void calcDimensions();
-
-	int addMenuItem(const char *name);
-	void addMenuSubItem(int id, const char *text, int action, int style = 0, char shortcut = 0, bool enabled = true);
-	void createSubMenuFromString(int id, const char *string);
-	void clearSubMenu(int id);
-
-	bool draw(ManagedSurface *g, bool forceRedraw = false);
-	bool processEvent(Common::Event &event);
-
-	void enableCommand(int menunum, int action, bool state);
-	void disableAllMenus();
-
-	void setActive(bool active) { _menuActivated = active; }
-	bool hasAllFocus() { return _menuActivated; }
-
-	Common::Rect _bbox;
-
-private:
-	ManagedSurface _screen;
-	ManagedSurface _tempSurface;
-
-private:
-	const Font *getMenuFont();
-	const char *getAcceleratorString(MenuSubItem *item, const char *prefix);
-	int calculateMenuWidth(MenuItem *menu);
-	void calcMenuBounds(MenuItem *menu);
-	void renderSubmenu(MenuItem *menu);
-
-	bool keyEvent(Common::Event &event);
-	bool mouseClick(int x, int y);
-	bool mouseRelease(int x, int y);
-	bool mouseMove(int x, int y);
-
-	bool processMenuShortCut(byte flags, uint16 ascii);
-
-	Common::Array<MenuItem *> _items;
-
-	const Font *_font;
-
-	bool _menuActivated;
-
-	int _activeItem;
-	int _activeSubItem;
-
-	void (*_ccallback)(int action, Common::String &text, void *data);
-	void *_cdata;
-};
-
-} // End of namespace Graphics
-
-#endif
diff --git a/engines/wage/module.mk b/engines/wage/module.mk
index 46d3980..be148dd 100644
--- a/engines/wage/module.mk
+++ b/engines/wage/module.mk
@@ -9,7 +9,6 @@ MODULE_OBJS := \
 	entities.o \
 	gui.o \
 	gui-console.o \
-	macmenu.o \
 	randomhat.o \
 	saveload.o \
 	script.o \
diff --git a/graphics/macgui/macmenu.cpp b/graphics/macgui/macmenu.cpp
new file mode 100644
index 0000000..3a4d624
--- /dev/null
+++ b/graphics/macgui/macmenu.cpp
@@ -0,0 +1,564 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * MIT License:
+ *
+ * Copyright (c) 2009 Alexei Svitkine, Eugene Sandulenko
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#include "common/system.h"
+#include "common/keyboard.h"
+
+#include "graphics/primitives.h"
+#include "graphics/font.h"
+#include "graphics/macgui/macwindowmanager.h"
+#include "graphics/macgui/macwindow.h"
+#include "graphics/macgui/macmenu.h"
+
+namespace Graphics {
+
+enum {
+	kMenuHeight = 20,
+	kMenuLeftMargin = 7,
+	kMenuSpacing = 13,
+	kMenuPadding = 16,
+	kMenuDropdownPadding = 14,
+	kMenuDropdownItemHeight = 16,
+	kMenuItemHeight = 20
+};
+
+struct MenuSubItem {
+	Common::String text;
+	int action;
+	int style;
+	char shortcut;
+	bool enabled;
+	Common::Rect bbox;
+
+	MenuSubItem(const char *t, int a, int s = 0, char sh = 0, bool e = true) : text(t), action(a), style(s), shortcut(sh), enabled(e) {}
+};
+
+typedef Common::Array<MenuSubItem *> SubItemArray;
+
+struct MenuItem {
+	Common::String name;
+	SubItemArray subitems;
+	Common::Rect bbox;
+	Common::Rect subbbox;
+
+	MenuItem(const char *n) : name(n) {}
+};
+
+Menu::Menu(int id, const Common::Rect &bounds, MacWindowManager *wm)
+		: BaseMacWindow(id, false, wm) {
+	_font = getMenuFont();
+
+	_screen.create(bounds.width(), bounds.height(), PixelFormat::createFormatCLUT8());
+
+	_bbox.left = 0;
+	_bbox.top = 0;
+	_bbox.right = _screen.w;
+	_bbox.bottom = kMenuHeight;
+
+	_menuActivated = false;
+	_activeItem = -1;
+	_activeSubItem = -1;
+
+	_ccallback = NULL;
+	_cdata = NULL;
+
+	_tempSurface.create(_screen.w, _font->getFontHeight(), PixelFormat::createFormatCLUT8());
+}
+
+Menu::~Menu() {
+	for (uint i = 0; i < _items.size(); i++) {
+		for (uint j = 0; j < _items[i]->subitems.size(); j++)
+			delete _items[i]->subitems[j];
+		delete _items[i];
+	}
+}
+
+void Menu::addStaticMenus(const MenuData *data) {
+	MenuItem *about = new MenuItem(_wm->hasBuiltInFonts() ? "\xa9" : "\xf0"); // (c) Symbol as the most resembling apple
+	_items.push_back(about);
+
+	for (int i = 0; data[i].menunum; i++) {
+		const MenuData *m = &data[i];
+
+		if (m->menunum == kMenuHighLevel) {
+			MenuItem *item = new MenuItem(m->title);
+			_items.push_back(item);
+
+			continue;
+		}
+
+		_items[m->menunum]->subitems.push_back(new MenuSubItem(m->title, m->action, 0, m->shortcut, m->enabled));
+	}
+}
+
+int Menu::addMenuItem(const char *name) {
+	MenuItem *i = new MenuItem(name);
+	_items.push_back(i);
+
+	return _items.size() - 1;
+}
+
+void Menu::addMenuSubItem(int id, const char *text, int action, int style, char shortcut, bool enabled) {
+	_items[id]->subitems.push_back(new MenuSubItem(text, action, style, shortcut, enabled));
+
+	calcMenuBounds(_items[id]);
+}
+
+void Menu::calcDimensions() {
+	// Calculate menu dimensions
+	int y = 1;
+	int x = 18;
+
+	for (uint i = 0; i < _items.size(); i++) {
+		int w = _font->getStringWidth(_items[i]->name);
+
+		if (_items[i]->bbox.bottom == 0) {
+			_items[i]->bbox.left = x - kMenuLeftMargin;
+			_items[i]->bbox.top = y;
+			_items[i]->bbox.right = x + w + kMenuSpacing - kMenuLeftMargin;
+			_items[i]->bbox.bottom = y + _font->getFontHeight() + (_wm->hasBuiltInFonts() ? 3 : 2);
+		}
+
+		calcMenuBounds(_items[i]);
+
+		x += w + kMenuSpacing;
+	}
+}
+
+void Menu::clearSubMenu(int id) {
+	MenuItem *menu = _items[id];
+
+	for (uint j = 0; j < menu->subitems.size(); j++)
+		delete menu->subitems[j];
+
+	menu->subitems.clear();
+}
+
+void Menu::createSubMenuFromString(int id, const char *str) {
+	clearSubMenu(id);
+
+	MenuItem *menu = _items[id];
+	Common::String string(str);
+
+	Common::String item;
+
+	for (uint i = 0; i < string.size(); i++) {
+		while(i < string.size() && string[i] != ';') // Read token
+			item += string[i++];
+
+		if (item == "(-") {
+			menu->subitems.push_back(new MenuSubItem(NULL, 0));
+		} else {
+			bool enabled = true;
+			int style = 0;
+			char shortcut = 0;
+			const char *shortPtr = strrchr(item.c_str(), '/');
+			if (shortPtr != NULL) {
+				if (strlen(shortPtr) >= 2) {
+					shortcut = shortPtr[1];
+					item.deleteChar(shortPtr - item.c_str());
+					item.deleteChar(shortPtr - item.c_str());
+				} else {
+					error("Unexpected shortcut: '%s', item '%s' in menu '%s'", shortPtr, item.c_str(), string.c_str());
+				}
+			}
+
+			while (item.size() >= 2 && item[item.size() - 2] == '<') {
+				char c = item.lastChar();
+				if (c == 'B') {
+					style |= kFontStyleBold;
+				} else if (c == 'I') {
+					style |= kFontStyleItalic;
+				} else if (c == 'U') {
+					style |= kFontStyleUnderline;
+				} else if (c == 'O') {
+					style |= kFontStyleOutline;
+				} else if (c == 'S') {
+					style |= kFontStyleShadow;
+				} else if (c == 'C') {
+					style |= kFontStyleCondensed;
+				} else if (c == 'E') {
+					style |= kFontStyleExtended;
+				}
+				item.deleteLastChar();
+				item.deleteLastChar();
+			}
+
+			Common::String tmpitem(item);
+			tmpitem.trim();
+			if (tmpitem[0] == '(') {
+				enabled = false;
+
+				for (uint j = 0; j < item.size(); j++)
+					if (item[j] == '(') {
+						item.deleteChar(j);
+						break;
+					}
+			}
+
+			menu->subitems.push_back(new MenuSubItem(item.c_str(), kMenuActionCommand, style, shortcut, enabled));
+		}
+
+		item.clear();
+	}
+
+	calcMenuBounds(menu);
+}
+
+const Font *Menu::getMenuFont() {
+	return _wm->getFont("Chicago-12", FontManager::kBigGUIFont);
+}
+
+const char *Menu::getAcceleratorString(MenuSubItem *item, const char *prefix) {
+	static char res[20];
+	*res = 0;
+
+	if (item->shortcut != 0)
+		sprintf(res, "%s%c%c", prefix, (_wm->hasBuiltInFonts() ? '^' : '\x11'), item->shortcut);
+
+	return res;
+}
+
+int Menu::calculateMenuWidth(MenuItem *menu) {
+	int maxWidth = 0;
+	for (uint i = 0; i < menu->subitems.size(); i++) {
+		MenuSubItem *item = menu->subitems[i];
+		if (!item->text.empty()) {
+			Common::String text(item->text);
+			Common::String acceleratorText(getAcceleratorString(item, "  "));
+			if (!acceleratorText.empty()) {
+				text += acceleratorText;
+			}
+
+			int width = _font->getStringWidth(text);
+			if (width > maxWidth) {
+				maxWidth = width;
+			}
+		}
+	}
+	return maxWidth;
+}
+
+void Menu::calcMenuBounds(MenuItem *menu) {
+	// TODO: cache maxWidth
+	int maxWidth = calculateMenuWidth(menu);
+	int x1 = menu->bbox.left - 1;
+	int y1 = menu->bbox.bottom + 1;
+	int x2 = x1 + maxWidth + kMenuDropdownPadding * 2 - 4;
+	int y2 = y1 + menu->subitems.size() * kMenuDropdownItemHeight + 2;
+
+	menu->subbbox.left = x1;
+	menu->subbbox.top = y1;
+	menu->subbbox.right = x2;
+	menu->subbbox.bottom = y2;
+}
+
+static void drawPixelPlain(int x, int y, int color, void *data) {
+	ManagedSurface *surface = (ManagedSurface *)data;
+
+	if (x >= 0 && x < surface->w && y >= 0 && y < surface->h)
+		*((byte *)surface->getBasePtr(x, y)) = (byte)color;
+}
+
+static void drawFilledRoundRect(ManagedSurface *surface, Common::Rect &rect, int arc, int color) {
+	drawRoundRect(rect, arc, color, true, drawPixelPlain, surface);
+}
+
+bool Menu::draw(ManagedSurface *g, bool forceRedraw) {
+	Common::Rect r(_bbox);
+
+	if (!_contentIsDirty && !forceRedraw)
+		return false;
+
+	_contentIsDirty = false;
+
+	_screen.clear(kColorGreen);
+
+	drawFilledRoundRect(&_screen, r, kDesktopArc, kColorWhite);
+	r.top = 7;
+	_screen.fillRect(r, kColorWhite);
+	r.top = kMenuHeight - 1;
+	r.bottom++;
+	_screen.fillRect(r, kColorGreen);
+	r.bottom--;
+	_screen.fillRect(r, kColorBlack);
+
+	for (uint i = 0; i < _items.size(); i++) {
+		int color = kColorBlack;
+		MenuItem *it = _items[i];
+
+		if ((uint)_activeItem == i) {
+			Common::Rect hbox = it->bbox;
+
+			hbox.left -= 1;
+			hbox.right += 3;
+			hbox.bottom += 1;
+
+			_screen.fillRect(hbox, kColorBlack);
+			color = kColorWhite;
+
+			if (!it->subitems.empty())
+				renderSubmenu(it);
+		}
+
+		_font->drawString(&_screen, it->name, it->bbox.left + kMenuLeftMargin, it->bbox.top + (_wm->hasBuiltInFonts() ? 2 : 1), it->bbox.width(), color);
+	}
+
+	g->transBlitFrom(_screen, kColorGreen);
+
+	g_system->copyRectToScreen(g->getPixels(), g->pitch, 0, 0, g->w, g->h);
+
+	return true;
+}
+
+void Menu::renderSubmenu(MenuItem *menu) {
+	Common::Rect *r = &menu->subbbox;
+
+	if (r->width() == 0 || r->height() == 0)
+		return;
+
+	_screen.fillRect(*r, kColorWhite);
+	_screen.frameRect(*r, kColorBlack);
+	_screen.vLine(r->right, r->top + 3, r->bottom + 1, kColorBlack);
+	_screen.vLine(r->right + 1, r->top + 3, r->bottom + 1, kColorBlack);
+	_screen.hLine(r->left + 3, r->bottom, r->right + 1, kColorBlack);
+	_screen.hLine(r->left + 3, r->bottom + 1, r->right + 1, kColorBlack);
+
+	int x = r->left + kMenuDropdownPadding;
+	int y = r->top + 1;
+	for (uint i = 0; i < menu->subitems.size(); i++) {
+		Common::String text(menu->subitems[i]->text);
+		Common::String acceleratorText(getAcceleratorString(menu->subitems[i], ""));
+		int accelX = r->right - 25;
+
+		int color = kColorBlack;
+		if (i == (uint)_activeSubItem && !text.empty() && menu->subitems[i]->enabled) {
+			color = kColorWhite;
+			Common::Rect trect(r->left, y - (_wm->hasBuiltInFonts() ? 1 : 0), r->right, y + _font->getFontHeight());
+
+			_screen.fillRect(trect, kColorBlack);
+		}
+
+		if (!text.empty()) {
+			ManagedSurface *s = &_screen;
+			int tx = x, ty = y;
+
+			if (!menu->subitems[i]->enabled) {
+				s = &_tempSurface;
+				tx = 0;
+				ty = 0;
+				accelX -= x;
+
+				_tempSurface.clear(kColorGreen);
+			}
+
+			_font->drawString(s, text, tx, ty, r->width(), color);
+
+			if (!acceleratorText.empty())
+				_font->drawString(s, acceleratorText, accelX, ty, r->width(), color);
+
+			if (!menu->subitems[i]->enabled) {
+				// I am lazy to extend drawString() with plotProc as a parameter, so
+				// fake it here
+				for (int ii = 0; ii < _tempSurface.h; ii++) {
+					const byte *src = (const byte *)_tempSurface.getBasePtr(0, ii);
+					byte *dst = (byte *)_screen.getBasePtr(x, y+ii);
+					byte pat = _wm->getPatterns()[kPatternCheckers2 - 1][ii % 8];
+					for (int j = 0; j < r->width(); j++) {
+						if (*src != kColorGreen && (pat & (1 << (7 - (x + j) % 8))))
+							*dst = *src;
+						src++;
+						dst++;
+					}
+				}
+			}
+		} else { // Delimiter
+			bool flip = r->left & 2;
+			byte *ptr = (byte *)_screen.getBasePtr(r->left + 1, y + kMenuDropdownItemHeight / 2);
+			for (int xx = r->left + 1; xx <= r->right - 1; xx++, ptr++) {
+				*ptr = flip ? kColorBlack : kColorWhite;
+				flip = !flip;
+			}
+		}
+
+		y += kMenuDropdownItemHeight;
+	}
+
+	_contentIsDirty = true;
+	//g_system->copyRectToScreen(_screen.getBasePtr(r->left, r->top), _screen.pitch, r->left, r->top, r->width() + 2, r->height() + 2);
+}
+
+bool Menu::processEvent(Common::Event &event) {
+	switch (event.type) {
+	case Common::EVENT_KEYDOWN:
+		return keyEvent(event);
+	case Common::EVENT_LBUTTONDOWN:
+		return mouseClick(event.mouse.x, event.mouse.y);
+	case Common::EVENT_LBUTTONUP:
+		return mouseRelease(event.mouse.x, event.mouse.y);
+	case Common::EVENT_MOUSEMOVE:
+		return mouseMove(event.mouse.x, event.mouse.y);
+	default:
+		return false;
+	}
+}
+
+bool Menu::keyEvent(Common::Event &event) {
+	if (event.type != Common::EVENT_KEYDOWN)
+		return false;
+
+	if (event.kbd.flags & (Common::KBD_ALT | Common::KBD_CTRL | Common::KBD_META)) {
+		if (event.kbd.ascii >= 0x20 && event.kbd.ascii <= 0x7f) {
+			return processMenuShortCut(event.kbd.flags, event.kbd.ascii);
+		}
+	}
+
+	return false;
+}
+
+bool Menu::mouseClick(int x, int y) {
+	if (_bbox.contains(x, y)) {
+		for (uint i = 0; i < _items.size(); i++)
+			if (_items[i]->bbox.contains(x, y)) {
+			  if ((uint)_activeItem == i)
+					return false;
+
+				if (_activeItem != -1) { // Restore background
+					Common::Rect r(_items[_activeItem]->subbbox);
+					r.right += 3;
+					r.bottom += 3;
+
+					_wm->setFullRefresh(true);
+				}
+
+				_activeItem = i;
+				_activeSubItem = -1;
+				_menuActivated = true;
+
+				_contentIsDirty = true;
+
+				return true;
+			}
+	} else if (_menuActivated && _items[_activeItem]->subbbox.contains(x, y)) {
+		MenuItem *it = _items[_activeItem];
+		int numSubItem = (y - it->subbbox.top) / kMenuDropdownItemHeight;
+
+		if (numSubItem != _activeSubItem) {
+			_activeSubItem = numSubItem;
+
+			renderSubmenu(_items[_activeItem]);
+			_contentIsDirty = true;
+		}
+	} else if (_menuActivated && _activeItem != -1) {
+		_activeSubItem = -1;
+
+		renderSubmenu(_items[_activeItem]);
+		_contentIsDirty = true;
+	}
+
+	return false;
+}
+
+bool Menu::mouseMove(int x, int y) {
+	if (_menuActivated)
+		if (mouseClick(x, y))
+			return true;
+
+	return false;
+}
+
+bool Menu::mouseRelease(int x, int y) {
+	if (_menuActivated) {
+		_menuActivated = false;
+
+		if (_activeItem != -1 && _activeSubItem != -1 && _items[_activeItem]->subitems[_activeSubItem]->enabled)
+			(*_ccallback)(_items[_activeItem]->subitems[_activeSubItem]->action,
+					_items[_activeItem]->subitems[_activeSubItem]->text, _cdata);
+
+		_activeItem = -1;
+		_activeSubItem = -1;
+
+		_wm->setFullRefresh(true);
+
+		return true;
+	}
+
+	return false;
+}
+
+bool Menu::processMenuShortCut(byte flags, uint16 ascii) {
+	ascii = tolower(ascii);
+
+	if (flags & (Common::KBD_CTRL | Common::KBD_META)) {
+		for (uint i = 0; i < _items.size(); i++)
+			for (uint j = 0; j < _items[i]->subitems.size(); j++)
+				if (_items[i]->subitems[j]->enabled && tolower(_items[i]->subitems[j]->shortcut) == ascii) {
+					(*_ccallback)(_items[i]->subitems[j]->action, _items[i]->subitems[j]->text, _cdata);
+					return true;
+				}
+	}
+
+	return false;
+}
+
+void Menu::enableCommand(int menunum, int action, bool state) {
+	for (uint i = 0; i < _items[menunum]->subitems.size(); i++)
+		if (_items[menunum]->subitems[i]->action == action)
+			_items[menunum]->subitems[i]->enabled = state;
+
+	_contentIsDirty = true;
+}
+
+void Menu::disableAllMenus() {
+	for (uint i = 1; i < _items.size(); i++) // Leave About menu on
+		for (uint j = 0; j < _items[i]->subitems.size(); j++)
+			_items[i]->subitems[j]->enabled = false;
+
+	_contentIsDirty = true;
+}
+
+} // End of namespace Wage
diff --git a/graphics/macgui/macmenu.h b/graphics/macgui/macmenu.h
new file mode 100644
index 0000000..e0309b2
--- /dev/null
+++ b/graphics/macgui/macmenu.h
@@ -0,0 +1,161 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * MIT License:
+ *
+ * Copyright (c) 2009 Alexei Svitkine, Eugene Sandulenko
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#ifndef GRAPHICS_MACMENU_H
+#define GRAPHICS_MACMENU_H
+
+namespace Graphics {
+
+struct MenuItem;
+struct MenuSubItem;
+
+enum {
+	kFontStyleBold = 1,
+	kFontStyleItalic = 2,
+	kFontStyleUnderline = 4,
+	kFontStyleOutline = 8,
+	kFontStyleShadow = 16,
+	kFontStyleCondensed = 32,
+	kFontStyleExtended = 64
+};
+
+enum {
+	kMenuHighLevel = -1,
+	kMenuAbout = 0,
+	kMenuFile = 1,
+	kMenuEdit = 2,
+	kMenuCommands = 3,
+	kMenuWeapons = 4
+};
+
+enum {
+	kMenuActionAbout,
+	kMenuActionNew,
+	kMenuActionOpen,
+	kMenuActionClose,
+	kMenuActionSave,
+	kMenuActionSaveAs,
+	kMenuActionRevert,
+	kMenuActionQuit,
+
+	kMenuActionUndo,
+	kMenuActionCut,
+	kMenuActionCopy,
+	kMenuActionPaste,
+	kMenuActionClear,
+
+	kMenuActionCommand
+};
+
+struct MenuData {
+	int menunum;
+	const char *title;
+	int action;
+	byte shortcut;
+	bool enabled;
+};
+
+class Menu : public BaseMacWindow {
+public:
+	Menu(int id, const Common::Rect &bounds, MacWindowManager *wm);
+	~Menu();
+
+	void setCommandsCallback(void (*callback)(int, Common::String &, void *), void *data) { _ccallback = callback; _cdata = data; }
+
+	void addStaticMenus(const MenuData *data);
+	void calcDimensions();
+
+	int addMenuItem(const char *name);
+	void addMenuSubItem(int id, const char *text, int action, int style = 0, char shortcut = 0, bool enabled = true);
+	void createSubMenuFromString(int id, const char *string);
+	void clearSubMenu(int id);
+
+	bool draw(ManagedSurface *g, bool forceRedraw = false);
+	bool processEvent(Common::Event &event);
+
+	void enableCommand(int menunum, int action, bool state);
+	void disableAllMenus();
+
+	void setActive(bool active) { _menuActivated = active; }
+	bool hasAllFocus() { return _menuActivated; }
+
+	Common::Rect _bbox;
+
+private:
+	ManagedSurface _screen;
+	ManagedSurface _tempSurface;
+
+private:
+	const Font *getMenuFont();
+	const char *getAcceleratorString(MenuSubItem *item, const char *prefix);
+	int calculateMenuWidth(MenuItem *menu);
+	void calcMenuBounds(MenuItem *menu);
+	void renderSubmenu(MenuItem *menu);
+
+	bool keyEvent(Common::Event &event);
+	bool mouseClick(int x, int y);
+	bool mouseRelease(int x, int y);
+	bool mouseMove(int x, int y);
+
+	bool processMenuShortCut(byte flags, uint16 ascii);
+
+	Common::Array<MenuItem *> _items;
+
+	const Font *_font;
+
+	bool _menuActivated;
+
+	int _activeItem;
+	int _activeSubItem;
+
+	void (*_ccallback)(int action, Common::String &text, void *data);
+	void *_cdata;
+};
+
+} // End of namespace Graphics
+
+#endif
diff --git a/graphics/macgui/macwindowmanager.cpp b/graphics/macgui/macwindowmanager.cpp
index 7d919a4..6c6e428 100644
--- a/graphics/macgui/macwindowmanager.cpp
+++ b/graphics/macgui/macwindowmanager.cpp
@@ -59,8 +59,7 @@
 #include "graphics/primitives.h"
 #include "graphics/macgui/macwindowmanager.h"
 #include "graphics/macgui/macwindow.h"
-
-#include "wage/macmenu.h"
+#include "graphics/macgui/macmenu.h"
 
 namespace Graphics {
 
diff --git a/graphics/module.mk b/graphics/module.mk
index 2e033d9..941ae1d 100644
--- a/graphics/module.mk
+++ b/graphics/module.mk
@@ -30,7 +30,8 @@ MODULE_OBJS := \
 	wincursor.o \
 	yuv_to_rgb.o \
 	macgui/macwindowmanager.o\
-	macgui/macwindow.o
+	macgui/macwindow.o \
+	macgui/macmenu.o
 
 ifdef USE_SCALERS
 MODULE_OBJS += \


Commit: ffbc6b0c783b5d86a91ef15a4974cde7f606c585
    https://github.com/scummvm/scummvm/commit/ffbc6b0c783b5d86a91ef15a4974cde7f606c585
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-07-31T14:05:14+02:00

Commit Message:
GRAPHICS: Create wrapper namespace for MacMenu constants

Changed paths:
    engines/wage/gui.cpp
    engines/wage/gui.h
    graphics/macgui/macmenu.h



diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp
index f8971e1..d74b77b 100644
--- a/engines/wage/gui.cpp
+++ b/engines/wage/gui.cpp
@@ -62,22 +62,22 @@
 namespace Wage {
 
 static const Graphics::MenuData menuSubItems[] = {
-	{ Graphics::kMenuHighLevel, "File",	0, 0, false },
-	{ Graphics::kMenuHighLevel, "Edit",	0, 0, false },
-	{ Graphics::kMenuFile, "New",			Graphics::kMenuActionNew, 0, false },
-	{ Graphics::kMenuFile, "Open...",		Graphics::kMenuActionOpen, 0, true },
-	{ Graphics::kMenuFile, "Close",			Graphics::kMenuActionClose, 0, true },
-	{ Graphics::kMenuFile, "Save",			Graphics::kMenuActionSave, 0, true },
-	{ Graphics::kMenuFile, "Save as...",	Graphics::kMenuActionSaveAs, 0, true },
-	{ Graphics::kMenuFile, "Revert",		Graphics::kMenuActionRevert, 0, false },
-	{ Graphics::kMenuFile, "Quit",			Graphics::kMenuActionQuit, 0, true },
-
-	{ Graphics::kMenuEdit, "Undo",			Graphics::kMenuActionUndo, 'Z', false },
-	{ Graphics::kMenuEdit, NULL,			0, 0, false },
-	{ Graphics::kMenuEdit, "Cut",			Graphics::kMenuActionCut, 'K', false },
-	{ Graphics::kMenuEdit, "Copy",			Graphics::kMenuActionCopy, 'C', false },
-	{ Graphics::kMenuEdit, "Paste",			Graphics::kMenuActionPaste, 'V', false },
-	{ Graphics::kMenuEdit, "Clear",			Graphics::kMenuActionClear, 'B', false },
+	{ kMenuHighLevel, "File",	0, 0, false },
+	{ kMenuHighLevel, "Edit",	0, 0, false },
+	{ kMenuFile, "New",			kMenuActionNew, 0, false },
+	{ kMenuFile, "Open...",		kMenuActionOpen, 0, true },
+	{ kMenuFile, "Close",			kMenuActionClose, 0, true },
+	{ kMenuFile, "Save",			kMenuActionSave, 0, true },
+	{ kMenuFile, "Save as...",	kMenuActionSaveAs, 0, true },
+	{ kMenuFile, "Revert",		kMenuActionRevert, 0, false },
+	{ kMenuFile, "Quit",			kMenuActionQuit, 0, true },
+
+	{ kMenuEdit, "Undo",			kMenuActionUndo, 'Z', false },
+	{ kMenuEdit, NULL,			0, 0, false },
+	{ kMenuEdit, "Cut",			kMenuActionCut, 'K', false },
+	{ kMenuEdit, "Copy",			kMenuActionCopy, 'C', false },
+	{ kMenuEdit, "Paste",			kMenuActionPaste, 'V', false },
+	{ kMenuEdit, "Clear",			kMenuActionClear, 'B', false },
 
 	{ 0, NULL,			0, 0, false }
 };
@@ -148,7 +148,7 @@ Gui::Gui(WageEngine *engine) {
 	_menu->setCommandsCallback(menuCommandsCallback, this);
 
 	_menu->addStaticMenus(menuSubItems);
-	_menu->addMenuSubItem(Graphics::kMenuAbout, _engine->_world->getAboutMenuItemName(), Graphics::kMenuActionAbout);
+	_menu->addMenuSubItem(kMenuAbout, _engine->_world->getAboutMenuItemName(), kMenuActionAbout);
 
 	_commandsMenuId = _menu->addMenuItem(_engine->_world->_commandsMenuName.c_str());
 	regenCommandsMenu();
@@ -298,7 +298,7 @@ void Gui::regenWeaponsMenu() {
 			command += " ";
 			command += obj->_name;
 
-			_menu->addMenuSubItem(_weaponsMenuId, command.c_str(), Graphics::kMenuActionCommand, 0, 0, true);
+			_menu->addMenuSubItem(_weaponsMenuId, command.c_str(), kMenuActionCommand, 0, 0, true);
 
 			empty = false;
 		}
@@ -321,39 +321,39 @@ void menuCommandsCallback(int action, Common::String &text, void *data) {
 
 void Gui::executeMenuCommand(int action, Common::String &text) {
 	switch(action) {
-	case Graphics::kMenuActionAbout:
-	case Graphics::kMenuActionNew:
-	case Graphics::kMenuActionClose:
-	case Graphics::kMenuActionRevert:
-	case Graphics::kMenuActionQuit:
+	case kMenuActionAbout:
+	case kMenuActionNew:
+	case kMenuActionClose:
+	case kMenuActionRevert:
+	case kMenuActionQuit:
 		break;
 
-	case Graphics::kMenuActionOpen:
+	case kMenuActionOpen:
 		_engine->scummVMSaveLoadDialog(false);
 		break;
 
-	case Graphics::kMenuActionSave:
-	case Graphics::kMenuActionSaveAs:
+	case kMenuActionSave:
+	case kMenuActionSaveAs:
 		_engine->scummVMSaveLoadDialog(true);
 		break;
 
-	case Graphics::kMenuActionUndo:
+	case kMenuActionUndo:
 		actionUndo();
 		break;
-	case Graphics::kMenuActionCut:
+	case kMenuActionCut:
 		actionCut();
 		break;
-	case Graphics::kMenuActionCopy:
+	case kMenuActionCopy:
 		actionCopy();
 		break;
-	case Graphics::kMenuActionPaste:
+	case kMenuActionPaste:
 		actionPaste();
 		break;
-	case Graphics::kMenuActionClear:
+	case kMenuActionClear:
 		actionClear();
 		break;
 
-	case Graphics::kMenuActionCommand:
+	case kMenuActionCommand:
 		_engine->processTurn(&text, NULL);
 		break;
 
diff --git a/engines/wage/gui.h b/engines/wage/gui.h
index ed841b0..4c9580d 100644
--- a/engines/wage/gui.h
+++ b/engines/wage/gui.h
@@ -53,11 +53,14 @@
 #include "graphics/managed_surface.h"
 #include "graphics/macgui/macwindowmanager.h"
 #include "graphics/macgui/macwindow.h"
+#include "graphics/macgui/macmenu.h"
 
 #include "common/events.h"
 #include "common/rect.h"
 
 namespace Wage {
+	
+using namespace Graphics::MacMenuConstants;
 
 class Scene;
 class WageEngine;
diff --git a/graphics/macgui/macmenu.h b/graphics/macgui/macmenu.h
index e0309b2..ce0b0ed 100644
--- a/graphics/macgui/macmenu.h
+++ b/graphics/macgui/macmenu.h
@@ -53,43 +53,46 @@ namespace Graphics {
 struct MenuItem;
 struct MenuSubItem;
 
-enum {
-	kFontStyleBold = 1,
-	kFontStyleItalic = 2,
-	kFontStyleUnderline = 4,
-	kFontStyleOutline = 8,
-	kFontStyleShadow = 16,
-	kFontStyleCondensed = 32,
-	kFontStyleExtended = 64
-};
-
-enum {
-	kMenuHighLevel = -1,
-	kMenuAbout = 0,
-	kMenuFile = 1,
-	kMenuEdit = 2,
-	kMenuCommands = 3,
-	kMenuWeapons = 4
-};
-
-enum {
-	kMenuActionAbout,
-	kMenuActionNew,
-	kMenuActionOpen,
-	kMenuActionClose,
-	kMenuActionSave,
-	kMenuActionSaveAs,
-	kMenuActionRevert,
-	kMenuActionQuit,
-
-	kMenuActionUndo,
-	kMenuActionCut,
-	kMenuActionCopy,
-	kMenuActionPaste,
-	kMenuActionClear,
-
-	kMenuActionCommand
-};
+namespace MacMenuConstants {
+	enum MacMenuFontStyle {
+		kFontStyleBold = 1,
+		kFontStyleItalic = 2,
+		kFontStyleUnderline = 4,
+		kFontStyleOutline = 8,
+		kFontStyleShadow = 16,
+		kFontStyleCondensed = 32,
+		kFontStyleExtended = 64
+	};
+
+	enum MacMenuTab {
+		kMenuHighLevel = -1,
+		kMenuAbout = 0,
+		kMenuFile = 1,
+		kMenuEdit = 2,
+		kMenuCommands = 3,
+		kMenuWeapons = 4
+	};
+
+	enum MacMenuAction {
+		kMenuActionAbout,
+		kMenuActionNew,
+		kMenuActionOpen,
+		kMenuActionClose,
+		kMenuActionSave,
+		kMenuActionSaveAs,
+		kMenuActionRevert,
+		kMenuActionQuit,
+
+		kMenuActionUndo,
+		kMenuActionCut,
+		kMenuActionCopy,
+		kMenuActionPaste,
+		kMenuActionClear,
+
+		kMenuActionCommand
+	};
+}
+using namespace MacMenuConstants;
 
 struct MenuData {
 	int menunum;


Commit: 941617fc3829d545cd35ada87f770655004e9914
    https://github.com/scummvm/scummvm/commit/941617fc3829d545cd35ada87f770655004e9914
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-07-31T14:05:14+02:00

Commit Message:
GRAPHICS: Create wrapper namespace for MacWindow constants

Changed paths:
    engines/wage/gui-console.cpp
    engines/wage/gui.cpp
    engines/wage/gui.h
    graphics/macgui/macwindow.h



diff --git a/engines/wage/gui-console.cpp b/engines/wage/gui-console.cpp
index 87c84ad..1cf98ab 100644
--- a/engines/wage/gui-console.cpp
+++ b/engines/wage/gui-console.cpp
@@ -348,7 +348,7 @@ void Gui::actionCopy() {
 		}
 	}
 
-	_menu->enableCommand(Graphics::kMenuEdit, Graphics::kMenuActionPaste, true);
+	_menu->enableCommand(kMenuEdit, kMenuActionPaste, true);
 }
 
 void Gui::actionPaste() {
@@ -357,14 +357,14 @@ void Gui::actionPaste() {
 	drawInput();
 	_engine->_inputText = _out.back();	// Set last part of the multiline text
 
-	_menu->enableCommand(Graphics::kMenuEdit, Graphics::kMenuActionUndo, true);
+	_menu->enableCommand(kMenuEdit, kMenuActionUndo, true);
 }
 
 void Gui::actionUndo() {
 	_engine->_inputText = _undobuffer;
 	drawInput();
 
-	_menu->enableCommand(Graphics::kMenuEdit, Graphics::kMenuActionUndo, false);
+	_menu->enableCommand(kMenuEdit, kMenuActionUndo, false);
 }
 
 void Gui::actionClear() {
@@ -381,7 +381,7 @@ void Gui::actionClear() {
 	_engine->_inputText = beg + end;
 	drawInput();
 
-	_menu->enableCommand(Graphics::kMenuEdit, Graphics::kMenuActionUndo, true);
+	_menu->enableCommand(kMenuEdit, kMenuActionUndo, true);
 
 	_selectionStartY = -1;
 	_selectionEndY = -1;
@@ -403,15 +403,15 @@ void Gui::actionCut() {
 	_clipboard = mid;
 	drawInput();
 
-	_menu->enableCommand(Graphics::kMenuEdit, Graphics::kMenuActionUndo, true);
-	_menu->enableCommand(Graphics::kMenuEdit, Graphics::kMenuActionPaste, true);
+	_menu->enableCommand(kMenuEdit, kMenuActionUndo, true);
+	_menu->enableCommand(kMenuEdit, kMenuActionPaste, true);
 
 	_selectionStartY = -1;
 	_selectionEndY = -1;
 }
 
 void Gui::disableUndo() {
-	_menu->enableCommand(Graphics::kMenuEdit, Graphics::kMenuActionUndo, false);
+	_menu->enableCommand(kMenuEdit, kMenuActionUndo, false);
 }
 
 void Gui::disableAllMenus() {
@@ -419,13 +419,13 @@ void Gui::disableAllMenus() {
 }
 
 void Gui::enableNewGameMenus() {
-	_menu->enableCommand(Graphics::kMenuFile, Graphics::kMenuActionNew, true);
-	_menu->enableCommand(Graphics::kMenuFile, Graphics::kMenuActionOpen, true);
-	_menu->enableCommand(Graphics::kMenuFile, Graphics::kMenuActionQuit, true);
+	_menu->enableCommand(kMenuFile, kMenuActionNew, true);
+	_menu->enableCommand(kMenuFile, kMenuActionOpen, true);
+	_menu->enableCommand(kMenuFile, kMenuActionQuit, true);
 }
 
-bool Gui::processConsoleEvents(Graphics::WindowClick click, Common::Event &event) {
-	if (click == Graphics::kBorderScrollUp || click == Graphics::kBorderScrollDown) {
+bool Gui::processConsoleEvents(WindowClick click, Common::Event &event) {
+	if (click == kBorderScrollUp || click == kBorderScrollDown) {
 		if (event.type == Common::EVENT_LBUTTONDOWN) {
 			int consoleHeight = _consoleWindow->getInnerDimensions().height();
 			int textFullSize = _lines.size() * _consoleLineHeight + consoleHeight;
@@ -439,14 +439,14 @@ bool Gui::processConsoleEvents(Graphics::WindowClick click, Common::Event &event
 			int oldScrollPos = _scrollPos;
 
 			switch (click) {
-			case Graphics::kBorderScrollUp:
+			case kBorderScrollUp:
 				_scrollPos = MAX<int>(0, _scrollPos - _consoleLineHeight);
 				undrawCursor();
 				_cursorY -= (_scrollPos - oldScrollPos);
 				_consoleDirty = true;
 				_consoleFullRedraw = true;
 				break;
-			case Graphics::kBorderScrollDown:
+			case kBorderScrollDown:
 				_scrollPos = MIN<int>((_lines.size() - 2) * _consoleLineHeight, _scrollPos + _consoleLineHeight);
 				undrawCursor();
 				_cursorY -= (_scrollPos - oldScrollPos);
@@ -463,14 +463,14 @@ bool Gui::processConsoleEvents(Graphics::WindowClick click, Common::Event &event
 		return false;
 	}
 
-	if (click == Graphics::kBorderResizeButton) {
+	if (click == kBorderResizeButton) {
 		_consoleDirty = true;
 		_consoleFullRedraw = true;
 
 		return true;
 	}
 
-	if (click == Graphics::kBorderInner) {
+	if (click == kBorderInner) {
 		if (event.type == Common::EVENT_LBUTTONDOWN) {
 			startMarking(event.mouse.x, event.mouse.y);
 
@@ -483,17 +483,17 @@ bool Gui::processConsoleEvents(Graphics::WindowClick click, Common::Event &event
 						(_selectionEndX == _selectionStartX && _selectionEndY == _selectionStartY)) {
 					_selectionStartY = _selectionEndY = -1;
 					_consoleFullRedraw = true;
-					_menu->enableCommand(Graphics::kMenuEdit, Graphics::kMenuActionCopy, false);
+					_menu->enableCommand(kMenuEdit, kMenuActionCopy, false);
 				} else {
-					_menu->enableCommand(Graphics::kMenuEdit, Graphics::kMenuActionCopy, true);
+					_menu->enableCommand(kMenuEdit, kMenuActionCopy, true);
 
 					bool cutAllowed = false;
 
 					if (_selectionStartY == _selectionEndY && _selectionStartY == (int)_lines.size() - 1)
 						cutAllowed = true;
 
-					_menu->enableCommand(Graphics::kMenuEdit, Graphics::kMenuActionCut, cutAllowed);
-					_menu->enableCommand(Graphics::kMenuEdit, Graphics::kMenuActionClear, cutAllowed);
+					_menu->enableCommand(kMenuEdit, kMenuActionCut, cutAllowed);
+					_menu->enableCommand(kMenuEdit, kMenuActionClear, cutAllowed);
 				}
 			}
 
diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp
index d74b77b..49f56f3 100644
--- a/engines/wage/gui.cpp
+++ b/engines/wage/gui.cpp
@@ -110,8 +110,8 @@ static void cursorTimerHandler(void *refCon) {
 	gui->_cursorDirty = true;
 }
 
-static bool sceneWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui);
-static bool consoleWindowCallback(Graphics::WindowClick click, Common::Event &event, void *gui);
+static bool sceneWindowCallback(WindowClick click, Common::Event &event, void *gui);
+static bool consoleWindowCallback(WindowClick click, Common::Event &event, void *gui);
 static void menuCommandsCallback(int action, Common::String &text, void *data);
 
 
@@ -235,13 +235,13 @@ void Gui::drawScene() {
 	_consoleFullRedraw = true;
 }
 
-static bool sceneWindowCallback(Graphics::WindowClick click, Common::Event &event, void *g) {
+static bool sceneWindowCallback(WindowClick click, Common::Event &event, void *g) {
 	Gui *gui = (Gui *)g;
 
 	return gui->processSceneEvents(click, event);
 }
 
-bool Gui::processSceneEvents(Graphics::WindowClick click, Common::Event &event) {
+bool Gui::processSceneEvents(WindowClick click, Common::Event &event) {
 	if (click == Graphics::kBorderInner && event.type == Common::EVENT_LBUTTONUP) {
 		Designed *obj = _scene->lookUpEntity(event.mouse.x - _sceneWindow->getDimensions().left,
 												  event.mouse.y - _sceneWindow->getDimensions().top);
@@ -265,7 +265,7 @@ void Gui::drawConsole() {
 	_consoleWindow->setDirty(true);
 }
 
-static bool consoleWindowCallback(Graphics::WindowClick click, Common::Event &event, void *g) {
+static bool consoleWindowCallback(WindowClick click, Common::Event &event, void *g) {
 	Gui *gui = (Gui *)g;
 
 	return gui->processConsoleEvents(click, event);
diff --git a/engines/wage/gui.h b/engines/wage/gui.h
index 4c9580d..7a2edb5 100644
--- a/engines/wage/gui.h
+++ b/engines/wage/gui.h
@@ -60,7 +60,9 @@
 
 namespace Wage {
 	
+// Import the enum definitions
 using namespace Graphics::MacMenuConstants;
+using namespace Graphics::MacWindowConstants;
 
 class Scene;
 class WageEngine;
@@ -93,8 +95,8 @@ public:
 	void disableAllMenus();
 	void enableNewGameMenus();
 
-	bool processSceneEvents(Graphics::WindowClick click, Common::Event &event);
-	bool processConsoleEvents(Graphics::WindowClick click, Common::Event &event);
+	bool processSceneEvents(WindowClick click, Common::Event &event);
+	bool processConsoleEvents(WindowClick click, Common::Event &event);
 	void executeMenuCommand(int action, Common::String &text);
 
 private:
diff --git a/graphics/macgui/macwindow.h b/graphics/macgui/macwindow.h
index 55f9d5c..e614e61 100644
--- a/graphics/macgui/macwindow.h
+++ b/graphics/macgui/macwindow.h
@@ -54,25 +54,28 @@ namespace Graphics {
 
 class MacWindowManager;
 
-enum WindowType {
-	kWindowUnknown,
-	kWindowWindow,
-	kWindowMenu
-};
-
-enum {
-	kBorderWidth = 17
-};
-
-enum WindowClick {
-	kBorderNone = 0,
-	kBorderScrollUp,
-	kBorderScrollDown,
-	kBorderCloseButton,
-	kBorderInner,
-	kBorderBorder,
-	kBorderResizeButton
-};
+namespace MacWindowConstants {
+	enum WindowType {
+		kWindowUnknown,
+		kWindowWindow,
+		kWindowMenu
+	};
+
+	enum {
+		kBorderWidth = 17
+	};
+
+	enum WindowClick {
+		kBorderNone = 0,
+		kBorderScrollUp,
+		kBorderScrollDown,
+		kBorderCloseButton,
+		kBorderInner,
+		kBorderBorder,
+		kBorderResizeButton
+	};
+}
+using namespace MacWindowConstants;
 
 class BaseMacWindow {
 public:


Commit: 1080f199957326261245da49bf0efe5059b17a18
    https://github.com/scummvm/scummvm/commit/1080f199957326261245da49bf0efe5059b17a18
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-07-31T14:05:14+02:00

Commit Message:
GRAPHICS: Create wrapper namespace for MacWindowManager constants

Changed paths:
    engines/wage/design.h
    engines/wage/gui.h
    engines/wage/world.h
    graphics/macgui/macwindowmanager.h



diff --git a/engines/wage/design.h b/engines/wage/design.h
index c64ae6d..7a422a4 100644
--- a/engines/wage/design.h
+++ b/engines/wage/design.h
@@ -55,6 +55,9 @@
 
 namespace Wage {
 
+using namespace Graphics::MacGUIConstants;
+using Graphics::Patterns;
+
 class Design {
 public:
 	Design(Common::SeekableReadStream *data);
@@ -88,15 +91,15 @@ private:
 	bool _boundsCalculationMode;
 
 private:
-	void render(Graphics::Patterns &patterns);
+	void render(Patterns &patterns);
 	void drawRect(Graphics::ManagedSurface *surface, Common::ReadStream &in,
-		Graphics::Patterns &patterns, byte fillType, byte borderThickness, byte borderFillType);
+		Patterns &patterns, byte fillType, byte borderThickness, byte borderFillType);
 	void drawRoundRect(Graphics::ManagedSurface *surface, Common::ReadStream &in,
-		Graphics::Patterns &patterns, byte fillType, byte borderThickness, byte borderFillType);
+		Patterns &patterns, byte fillType, byte borderThickness, byte borderFillType);
 	void drawPolygon(Graphics::ManagedSurface *surface, Common::ReadStream &in,
-		Graphics::Patterns &patterns, byte fillType, byte borderThickness, byte borderFillType);
+		Patterns &patterns, byte fillType, byte borderThickness, byte borderFillType);
 	void drawOval(Graphics::ManagedSurface *surface, Common::ReadStream &in,
-		Graphics::Patterns &patterns, byte fillType, byte borderThickness, byte borderFillType);
+		Patterns &patterns, byte fillType, byte borderThickness, byte borderFillType);
 	void drawBitmap(Graphics::ManagedSurface *surface, Common::SeekableReadStream &in);
 };
 
diff --git a/engines/wage/gui.h b/engines/wage/gui.h
index 7a2edb5..8536a76 100644
--- a/engines/wage/gui.h
+++ b/engines/wage/gui.h
@@ -63,6 +63,7 @@ namespace Wage {
 // Import the enum definitions
 using namespace Graphics::MacMenuConstants;
 using namespace Graphics::MacWindowConstants;
+using namespace Graphics::MacGUIConstants;
 
 class Scene;
 class WageEngine;
diff --git a/engines/wage/world.h b/engines/wage/world.h
index b3908be..e0e0448 100644
--- a/engines/wage/world.h
+++ b/engines/wage/world.h
@@ -53,6 +53,9 @@
 
 namespace Wage {
 
+// Import the enum definitions
+using Graphics::Patterns;
+
 class Script;
 class Sound;
 
diff --git a/graphics/macgui/macwindowmanager.h b/graphics/macgui/macwindowmanager.h
index e30d2d8..d5b817b 100644
--- a/graphics/macgui/macwindowmanager.h
+++ b/graphics/macgui/macwindowmanager.h
@@ -58,24 +58,27 @@
 
 namespace Graphics {	
 
-enum {
-	kDesktopArc = 7
-};
+namespace MacGUIConstants {
+	enum {
+		kDesktopArc = 7
+	};
 
-enum {
-	kColorBlack  = 0,
-	kColorGray   = 1,
-	kColorWhite  = 2,
-	kColorGreen  = 3,
-	kColorGreen2 = 4
-};
+	enum MacGUIColor {
+		kColorBlack = 0,
+		kColorGray = 1,
+		kColorWhite = 2,
+		kColorGreen = 3,
+		kColorGreen2 = 4
+	};
 
-enum {
-	kPatternSolid = 1,
-	kPatternStripes = 2,
-	kPatternCheckers = 3,
-	kPatternCheckers2 = 4
-};
+	enum MacGUIPattern {
+		kPatternSolid = 1,
+		kPatternStripes = 2,
+		kPatternCheckers = 3,
+		kPatternCheckers2 = 4
+	};
+}
+using namespace MacGUIConstants;
 
 class ManagedSurface;
 
@@ -135,28 +138,5 @@ private:
 
 } // End of namespace Graphics
 
-namespace Wage {
-	typedef Graphics::Patterns Patterns;
-	
-	enum {
-		kDesktopArc = 7
-	};
-
-	enum {
-		kColorBlack = 0,
-		kColorGray = 1,
-		kColorWhite = 2,
-		kColorGreen = 3,
-		kColorGreen2 = 4
-	};
-
-	enum {
-		kPatternSolid = 1,
-		kPatternStripes = 2,
-		kPatternCheckers = 3,
-		kPatternCheckers2 = 4
-	};
-}
-
 
 #endif


Commit: 9ce6fbd0d7faf05fcd62cd9a6ee953cdc63d53cf
    https://github.com/scummvm/scummvm/commit/9ce6fbd0d7faf05fcd62cd9a6ee953cdc63d53cf
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-07-31T14:05:14+02:00

Commit Message:
GRAPHICS: Move MacMenu constants

Changed paths:
    engines/wage/design.cpp
    engines/wage/design.h
    engines/wage/gui.cpp
    engines/wage/gui.h
    engines/wage/world.cpp
    engines/wage/world.h
    graphics/macgui/macmenu.cpp
    graphics/macgui/macmenu.h
    graphics/macgui/macwindowmanager.cpp
    graphics/macgui/macwindowmanager.h



diff --git a/engines/wage/design.cpp b/engines/wage/design.cpp
index a578a84..6255932 100644
--- a/engines/wage/design.cpp
+++ b/engines/wage/design.cpp
@@ -55,12 +55,12 @@ namespace Wage {
 
 struct PlotData {
 	Graphics::ManagedSurface *surface;
-	Graphics::Patterns *patterns;
+	Graphics::MacPatterns *patterns;
 	uint fillType;
 	int thickness;
 	Design *design;
 
-	PlotData(Graphics::ManagedSurface *s, Patterns *p, int f, int t, Design *d) :
+	PlotData(Graphics::ManagedSurface *s, Graphics::MacPatterns *p, int f, int t, Design *d) :
 		surface(s), patterns(p), fillType(f), thickness(t), design(d) {}
 };
 
@@ -85,7 +85,7 @@ Design::~Design() {
 	delete _surface;
 }
 
-void Design::paint(Graphics::ManagedSurface *surface, Patterns &patterns, int x, int y) {
+void Design::paint(Graphics::ManagedSurface *surface, Graphics::MacPatterns &patterns, int x, int y) {
 	bool needRender = false;
 
 	if (_surface == NULL) {
@@ -141,7 +141,7 @@ void Design::paint(Graphics::ManagedSurface *surface, Patterns &patterns, int x,
 	}
 }
 
-void Design::render(Patterns &patterns) {
+void Design::render(Graphics::MacPatterns &patterns) {
 	Common::MemoryReadStream in(_data, _len);
 	bool needRender = true;
 
@@ -265,7 +265,7 @@ void drawPixelPlain(int x, int y, int color, void *data) {
 }
 
 void Design::drawRect(Graphics::ManagedSurface *surface, Common::ReadStream &in,
-				Patterns &patterns, byte fillType, byte borderThickness, byte borderFillType) {
+	Graphics::MacPatterns &patterns, byte fillType, byte borderThickness, byte borderFillType) {
 	int16 y1 = in.readSint16BE();
 	int16 x1 = in.readSint16BE();
 	int16 y2 = in.readSint16BE();
@@ -294,7 +294,7 @@ void Design::drawRect(Graphics::ManagedSurface *surface, Common::ReadStream &in,
 }
 
 void Design::drawRoundRect(Graphics::ManagedSurface *surface, Common::ReadStream &in,
-				Patterns &patterns, byte fillType, byte borderThickness, byte borderFillType) {
+	Graphics::MacPatterns &patterns, byte fillType, byte borderThickness, byte borderFillType) {
 	int16 y1 = in.readSint16BE();
 	int16 x1 = in.readSint16BE();
 	int16 y2 = in.readSint16BE();
@@ -320,7 +320,7 @@ void Design::drawRoundRect(Graphics::ManagedSurface *surface, Common::ReadStream
 }
 
 void Design::drawPolygon(Graphics::ManagedSurface *surface, Common::ReadStream &in,
-	Patterns &patterns, byte fillType, byte borderThickness, byte borderFillType) {
+	Graphics::MacPatterns &patterns, byte fillType, byte borderThickness, byte borderFillType) {
 
 	byte ignored = in.readSint16BE(); // ignored
 
@@ -397,7 +397,7 @@ void Design::drawPolygon(Graphics::ManagedSurface *surface, Common::ReadStream &
 }
 
 void Design::drawOval(Graphics::ManagedSurface *surface, Common::ReadStream &in,
-			Patterns &patterns, byte fillType, byte borderThickness, byte borderFillType) {
+	Graphics::MacPatterns &patterns, byte fillType, byte borderThickness, byte borderFillType) {
 	int16 y1 = in.readSint16BE();
 	int16 x1 = in.readSint16BE();
 	int16 y2 = in.readSint16BE();
@@ -501,11 +501,11 @@ void Design::drawBitmap(Graphics::ManagedSurface *surface, Common::SeekableReadS
 	tmp.free();
 }
 
-void Design::drawRect(Graphics::ManagedSurface *surface, Common::Rect &rect, int thickness, int color, Patterns &patterns, byte fillType) {
+void Design::drawRect(Graphics::ManagedSurface *surface, Common::Rect &rect, int thickness, int color, Graphics::MacPatterns &patterns, byte fillType) {
 	drawRect(surface, rect.left, rect.top, rect.right, rect.bottom, thickness, color, patterns, fillType);
 }
 
-void Design::drawRect(Graphics::ManagedSurface *surface, int x1, int y1, int x2, int y2, int thickness, int color, Patterns &patterns, byte fillType) {
+void Design::drawRect(Graphics::ManagedSurface *surface, int x1, int y1, int x2, int y2, int thickness, int color, Graphics::MacPatterns &patterns, byte fillType) {
 	PlotData pd(surface, &patterns, fillType, thickness, nullptr);
 
 	Graphics::drawLine(x1, y1, x2, y1, kColorBlack, drawPixel, &pd);
@@ -515,26 +515,26 @@ void Design::drawRect(Graphics::ManagedSurface *surface, int x1, int y1, int x2,
 }
 
 
-void Design::drawFilledRect(Graphics::ManagedSurface *surface, Common::Rect &rect, int color, Patterns &patterns, byte fillType) {
+void Design::drawFilledRect(Graphics::ManagedSurface *surface, Common::Rect &rect, int color, Graphics::MacPatterns &patterns, byte fillType) {
 	PlotData pd(surface, &patterns, fillType, 1, nullptr);
 
 	for (int y = rect.top; y <= rect.bottom; y++)
 		Graphics::drawHLine(rect.left, rect.right, y, color, drawPixel, &pd);
 }
 
-void Design::drawFilledRoundRect(Graphics::ManagedSurface *surface, Common::Rect &rect, int arc, int color, Patterns &patterns, byte fillType) {
+void Design::drawFilledRoundRect(Graphics::ManagedSurface *surface, Common::Rect &rect, int arc, int color, Graphics::MacPatterns &patterns, byte fillType) {
 	PlotData pd(surface, &patterns, fillType, 1, nullptr);
 
 	Graphics::drawRoundRect(rect, arc, color, true, drawPixel, &pd);
 }
 
-void Design::drawHLine(Graphics::ManagedSurface *surface, int x1, int x2, int y, int thickness, int color, Patterns &patterns, byte fillType) {
+void Design::drawHLine(Graphics::ManagedSurface *surface, int x1, int x2, int y, int thickness, int color, Graphics::MacPatterns &patterns, byte fillType) {
 	PlotData pd(surface, &patterns, fillType, thickness, nullptr);
 
 	Graphics::drawHLine(x1, x2, y, color, drawPixel, &pd);
 }
 
-void Design::drawVLine(Graphics::ManagedSurface *surface, int x, int y1, int y2, int thickness, int color, Patterns &patterns, byte fillType) {
+void Design::drawVLine(Graphics::ManagedSurface *surface, int x, int y1, int y2, int thickness, int color, Graphics::MacPatterns &patterns, byte fillType) {
 	PlotData pd(surface, &patterns, fillType, thickness, nullptr);
 
 	Graphics::drawVLine(x, y1, y2, color, drawPixel, &pd);
diff --git a/engines/wage/design.h b/engines/wage/design.h
index 7a422a4..948476b 100644
--- a/engines/wage/design.h
+++ b/engines/wage/design.h
@@ -56,7 +56,6 @@
 namespace Wage {
 
 using namespace Graphics::MacGUIConstants;
-using Graphics::Patterns;
 
 class Design {
 public:
@@ -71,14 +70,14 @@ public:
 		return _bounds;
 	}
 
-    void paint(Graphics::ManagedSurface *canvas, Graphics::Patterns &patterns, int x, int y);
+    void paint(Graphics::ManagedSurface *canvas, Graphics::MacPatterns &patterns, int x, int y);
 	bool isPointOpaque(int x, int y);
-	static void drawRect(Graphics::ManagedSurface *surface, Common::Rect &rect, int thickness, int color, Graphics::Patterns &patterns, byte fillType);
-	static void drawRect(Graphics::ManagedSurface *surface, int x1, int y1, int x2, int y2, int thickness, int color, Graphics::Patterns &patterns, byte fillType);
-	static void drawFilledRect(Graphics::ManagedSurface *surface, Common::Rect &rect, int color, Graphics::Patterns &patterns, byte fillType);
-	static void drawFilledRoundRect(Graphics::ManagedSurface *surface, Common::Rect &rect, int arc, int color, Graphics::Patterns &patterns, byte fillType);
-	static void drawHLine(Graphics::ManagedSurface *surface, int x1, int x2, int y, int thickness, int color, Graphics::Patterns &patterns, byte fillType);
-	static void drawVLine(Graphics::ManagedSurface *surface, int x, int y1, int y2, int thickness, int color, Graphics::Patterns &patterns, byte fillType);
+	static void drawRect(Graphics::ManagedSurface *surface, Common::Rect &rect, int thickness, int color, Graphics::MacPatterns &patterns, byte fillType);
+	static void drawRect(Graphics::ManagedSurface *surface, int x1, int y1, int x2, int y2, int thickness, int color, Graphics::MacPatterns &patterns, byte fillType);
+	static void drawFilledRect(Graphics::ManagedSurface *surface, Common::Rect &rect, int color, Graphics::MacPatterns &patterns, byte fillType);
+	static void drawFilledRoundRect(Graphics::ManagedSurface *surface, Common::Rect &rect, int arc, int color, Graphics::MacPatterns &patterns, byte fillType);
+	static void drawHLine(Graphics::ManagedSurface *surface, int x1, int x2, int y, int thickness, int color, Graphics::MacPatterns &patterns, byte fillType);
+	static void drawVLine(Graphics::ManagedSurface *surface, int x, int y1, int y2, int thickness, int color, Graphics::MacPatterns &patterns, byte fillType);
 
 	bool isBoundsCalculation() { return _boundsCalculationMode; }
 	void adjustBounds(int16 x, int16 y);
@@ -91,15 +90,15 @@ private:
 	bool _boundsCalculationMode;
 
 private:
-	void render(Patterns &patterns);
+	void render(Graphics::MacPatterns &patterns);
 	void drawRect(Graphics::ManagedSurface *surface, Common::ReadStream &in,
-		Patterns &patterns, byte fillType, byte borderThickness, byte borderFillType);
+		Graphics::MacPatterns &patterns, byte fillType, byte borderThickness, byte borderFillType);
 	void drawRoundRect(Graphics::ManagedSurface *surface, Common::ReadStream &in,
-		Patterns &patterns, byte fillType, byte borderThickness, byte borderFillType);
+		Graphics::MacPatterns &patterns, byte fillType, byte borderThickness, byte borderFillType);
 	void drawPolygon(Graphics::ManagedSurface *surface, Common::ReadStream &in,
-		Patterns &patterns, byte fillType, byte borderThickness, byte borderFillType);
+		Graphics::MacPatterns &patterns, byte fillType, byte borderThickness, byte borderFillType);
 	void drawOval(Graphics::ManagedSurface *surface, Common::ReadStream &in,
-		Patterns &patterns, byte fillType, byte borderThickness, byte borderFillType);
+		Graphics::MacPatterns &patterns, byte fillType, byte borderThickness, byte borderFillType);
 	void drawBitmap(Graphics::ManagedSurface *surface, Common::SeekableReadStream &in);
 };
 
diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp
index 49f56f3..a8d2284 100644
--- a/engines/wage/gui.cpp
+++ b/engines/wage/gui.cpp
@@ -73,8 +73,8 @@ static const Graphics::MenuData menuSubItems[] = {
 	{ kMenuFile, "Quit",			kMenuActionQuit, 0, true },
 
 	{ kMenuEdit, "Undo",			kMenuActionUndo, 'Z', false },
-	{ kMenuEdit, NULL,			0, 0, false },
-	{ kMenuEdit, "Cut",			kMenuActionCut, 'K', false },
+	{ kMenuEdit, NULL,				0, 0, false },
+	{ kMenuEdit, "Cut",				kMenuActionCut, 'K', false },
 	{ kMenuEdit, "Copy",			kMenuActionCopy, 'C', false },
 	{ kMenuEdit, "Paste",			kMenuActionPaste, 'V', false },
 	{ kMenuEdit, "Clear",			kMenuActionClear, 'B', false },
diff --git a/engines/wage/gui.h b/engines/wage/gui.h
index 8536a76..cf30c57 100644
--- a/engines/wage/gui.h
+++ b/engines/wage/gui.h
@@ -59,12 +59,9 @@
 #include "common/rect.h"
 
 namespace Wage {
-	
-// Import the enum definitions
-using namespace Graphics::MacMenuConstants;
-using namespace Graphics::MacWindowConstants;
-using namespace Graphics::MacGUIConstants;
 
+using namespace Graphics::MacWindowConstants;
+	
 class Scene;
 class WageEngine;
 
@@ -72,6 +69,44 @@ enum {
 	kCursorHeight = 12
 };
 
+enum {
+	kFontStyleBold = 1,
+	kFontStyleItalic = 2,
+	kFontStyleUnderline = 4,
+	kFontStyleOutline = 8,
+	kFontStyleShadow = 16,
+	kFontStyleCondensed = 32,
+	kFontStyleExtended = 64
+};
+
+enum {
+	kMenuHighLevel = -1,
+	kMenuAbout = 0,
+	kMenuFile = 1,
+	kMenuEdit = 2,
+	kMenuCommands = 3,
+	kMenuWeapons = 4
+};
+
+enum {
+	kMenuActionAbout,
+	kMenuActionNew,
+	kMenuActionOpen,
+	kMenuActionClose,
+	kMenuActionSave,
+	kMenuActionSaveAs,
+	kMenuActionRevert,
+	kMenuActionQuit,
+
+	kMenuActionUndo,
+	kMenuActionCut,
+	kMenuActionCopy,
+	kMenuActionPaste,
+	kMenuActionClear,
+
+	kMenuActionCommand
+};
+
 class Gui {
 public:
 	Gui(WageEngine *engine);
diff --git a/engines/wage/world.cpp b/engines/wage/world.cpp
index 286ecdd..acc2a83 100644
--- a/engines/wage/world.cpp
+++ b/engines/wage/world.cpp
@@ -75,7 +75,7 @@ World::World(WageEngine *engine) {
 
 	_engine = engine;
 
-	_patterns = new Patterns;
+	_patterns = new Graphics::MacPatterns;
 }
 
 World::~World() {
diff --git a/engines/wage/world.h b/engines/wage/world.h
index e0e0448..5c1aaf3 100644
--- a/engines/wage/world.h
+++ b/engines/wage/world.h
@@ -54,7 +54,7 @@
 namespace Wage {
 
 // Import the enum definitions
-using Graphics::Patterns;
+using Graphics::MacPatterns;
 
 class Script;
 class Sound;
@@ -92,7 +92,7 @@ public:
 	ObjArray _orderedObjs;
 	ChrArray _orderedChrs;
 	Common::Array<Sound *> _orderedSounds;
-	Graphics::Patterns *_patterns;
+	Graphics::MacPatterns *_patterns;
 	Scene *_storageScene;
 	Chr *_player;
 	int _signature;
diff --git a/graphics/macgui/macmenu.cpp b/graphics/macgui/macmenu.cpp
index 3a4d624..6169b3e 100644
--- a/graphics/macgui/macmenu.cpp
+++ b/graphics/macgui/macmenu.cpp
@@ -66,6 +66,25 @@ enum {
 	kMenuItemHeight = 20
 };
 
+enum {
+	kMenuHighLevel = -1
+};
+
+enum {
+	kFontStyleBold = 1,
+	kFontStyleItalic = 2,
+	kFontStyleUnderline = 4,
+	kFontStyleOutline = 8,
+	kFontStyleShadow = 16,
+	kFontStyleCondensed = 32,
+	kFontStyleExtended = 64
+};
+
+enum {
+	kMenuActionCommand
+};
+
+
 struct MenuSubItem {
 	Common::String text;
 	int action;
diff --git a/graphics/macgui/macmenu.h b/graphics/macgui/macmenu.h
index ce0b0ed..5c08f4f 100644
--- a/graphics/macgui/macmenu.h
+++ b/graphics/macgui/macmenu.h
@@ -53,47 +53,6 @@ namespace Graphics {
 struct MenuItem;
 struct MenuSubItem;
 
-namespace MacMenuConstants {
-	enum MacMenuFontStyle {
-		kFontStyleBold = 1,
-		kFontStyleItalic = 2,
-		kFontStyleUnderline = 4,
-		kFontStyleOutline = 8,
-		kFontStyleShadow = 16,
-		kFontStyleCondensed = 32,
-		kFontStyleExtended = 64
-	};
-
-	enum MacMenuTab {
-		kMenuHighLevel = -1,
-		kMenuAbout = 0,
-		kMenuFile = 1,
-		kMenuEdit = 2,
-		kMenuCommands = 3,
-		kMenuWeapons = 4
-	};
-
-	enum MacMenuAction {
-		kMenuActionAbout,
-		kMenuActionNew,
-		kMenuActionOpen,
-		kMenuActionClose,
-		kMenuActionSave,
-		kMenuActionSaveAs,
-		kMenuActionRevert,
-		kMenuActionQuit,
-
-		kMenuActionUndo,
-		kMenuActionCut,
-		kMenuActionCopy,
-		kMenuActionPaste,
-		kMenuActionClear,
-
-		kMenuActionCommand
-	};
-}
-using namespace MacMenuConstants;
-
 struct MenuData {
 	int menunum;
 	const char *title;
diff --git a/graphics/macgui/macwindowmanager.cpp b/graphics/macgui/macwindowmanager.cpp
index 6c6e428..3d4ef3b 100644
--- a/graphics/macgui/macwindowmanager.cpp
+++ b/graphics/macgui/macwindowmanager.cpp
@@ -186,11 +186,11 @@ void MacWindowManager::setActive(int id) {
 
 struct PlotData {
 	Graphics::ManagedSurface *surface;
-	Patterns *patterns;
+	MacPatterns *patterns;
 	uint fillType;
 	int thickness;
 
-	PlotData(Graphics::ManagedSurface *s, Patterns *p, int f, int t) :
+	PlotData(Graphics::ManagedSurface *s, MacPatterns *p, int f, int t) :
 		surface(s), patterns(p), fillType(f), thickness(t) {}
 };
 
diff --git a/graphics/macgui/macwindowmanager.h b/graphics/macgui/macwindowmanager.h
index d5b817b..5be82e3 100644
--- a/graphics/macgui/macwindowmanager.h
+++ b/graphics/macgui/macwindowmanager.h
@@ -63,7 +63,7 @@ namespace MacGUIConstants {
 		kDesktopArc = 7
 	};
 
-	enum MacGUIColor {
+	enum {
 		kColorBlack = 0,
 		kColorGray = 1,
 		kColorWhite = 2,
@@ -71,7 +71,7 @@ namespace MacGUIConstants {
 		kColorGreen2 = 4
 	};
 
-	enum MacGUIPattern {
+	enum {
 		kPatternSolid = 1,
 		kPatternStripes = 2,
 		kPatternCheckers = 3,
@@ -84,7 +84,7 @@ class ManagedSurface;
 
 class Menu;
 
-typedef Common::Array<byte *> Patterns;
+typedef Common::Array<byte *> MacPatterns;
 
 class MacWindowManager {
 public:
@@ -107,7 +107,7 @@ public:
 
 	BaseMacWindow *getWindow(int id) { return _windows[id]; }
 
-	Patterns &getPatterns() { return _patterns; }
+	MacPatterns &getPatterns() { return _patterns; }
 	void drawFilledRoundRect(ManagedSurface *surface, Common::Rect &rect, int arc, int color);
 
 	void pushArrowCursor();
@@ -128,7 +128,7 @@ private:
 
 	bool _fullRefresh;
 
-	Patterns _patterns;
+	MacPatterns _patterns;
 
 	Menu *_menu;
 


Commit: 80604fb3f5f09a7f50f83f3c9a84f0fe317c05b0
    https://github.com/scummvm/scummvm/commit/80604fb3f5f09a7f50f83f3c9a84f0fe317c05b0
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-07-31T14:05:14+02:00

Commit Message:
GRAPHICS: Clean up namespaces

Changed paths:
    graphics/macgui/macwindow.h
    graphics/macgui/macwindowmanager.h



diff --git a/graphics/macgui/macwindow.h b/graphics/macgui/macwindow.h
index e614e61..d4d2c07 100644
--- a/graphics/macgui/macwindow.h
+++ b/graphics/macgui/macwindow.h
@@ -161,5 +161,4 @@ private:
 
 } // End of namespace Graphics
 
-
 #endif
diff --git a/graphics/macgui/macwindowmanager.h b/graphics/macgui/macwindowmanager.h
index 5be82e3..21bc381 100644
--- a/graphics/macgui/macwindowmanager.h
+++ b/graphics/macgui/macwindowmanager.h
@@ -138,5 +138,4 @@ private:
 
 } // End of namespace Graphics
 
-
 #endif


Commit: b9ca6836bdbb16bd9ee637cbb3e1dcb43ecb3ab0
    https://github.com/scummvm/scummvm/commit/b9ca6836bdbb16bd9ee637cbb3e1dcb43ecb3ab0
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-07-31T14:05:14+02:00

Commit Message:
WAGE: Adapt to namespace change

Changed paths:
    engines/wage/gui.cpp



diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp
index a8d2284..235a249 100644
--- a/engines/wage/gui.cpp
+++ b/engines/wage/gui.cpp
@@ -242,7 +242,7 @@ static bool sceneWindowCallback(WindowClick click, Common::Event &event, void *g
 }
 
 bool Gui::processSceneEvents(WindowClick click, Common::Event &event) {
-	if (click == Graphics::kBorderInner && event.type == Common::EVENT_LBUTTONUP) {
+	if (click == kBorderInner && event.type == Common::EVENT_LBUTTONUP) {
 		Designed *obj = _scene->lookUpEntity(event.mouse.x - _sceneWindow->getDimensions().left,
 												  event.mouse.y - _sceneWindow->getDimensions().top);
 
@@ -260,7 +260,7 @@ void Gui::drawConsole() {
 	if (!_consoleDirty && !_consoleFullRedraw && !_sceneDirty)
 		return;
 
-	renderConsole(_consoleWindow->getSurface(), Common::Rect(Graphics::kBorderWidth - 2, Graphics::kBorderWidth - 2,
+	renderConsole(_consoleWindow->getSurface(), Common::Rect(kBorderWidth - 2, kBorderWidth - 2,
 				_consoleWindow->getDimensions().width(), _consoleWindow->getDimensions().height()));
 	_consoleWindow->setDirty(true);
 }


Commit: c071eb0e188a458e90afae3c01bacf78f0b91c92
    https://github.com/scummvm/scummvm/commit/c071eb0e188a458e90afae3c01bacf78f0b91c92
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-07-31T14:05:14+02:00

Commit Message:
GRAPHICS: Fix style issues

Changed paths:
    graphics/macgui/macwindowmanager.cpp
    graphics/nine_patch.h



diff --git a/graphics/macgui/macwindowmanager.cpp b/graphics/macgui/macwindowmanager.cpp
index 3d4ef3b..da573e6 100644
--- a/graphics/macgui/macwindowmanager.cpp
+++ b/graphics/macgui/macwindowmanager.cpp
@@ -290,6 +290,7 @@ bool MacWindowManager::processEvent(Common::Event &event) {
         it--;
 		BaseMacWindow *w = *it;
 
+
         if (w->hasAllFocus() || w->getDimensions().contains(event.mouse.x, event.mouse.y)) {
             if (event.type == Common::EVENT_LBUTTONDOWN || event.type == Common::EVENT_LBUTTONUP)
                 setActive(w->getId());
diff --git a/graphics/nine_patch.h b/graphics/nine_patch.h
index 45e4e09..ebd6e1e 100644
--- a/graphics/nine_patch.h
+++ b/graphics/nine_patch.h
@@ -50,6 +50,9 @@
 
 namespace Graphics {
 
+	class TransparentSurface;
+	class Surface;
+
 struct NinePatchMark {
 	int offset;
 	int length;


Commit: 5bb5bb64f0bd3acdd8235a8c3c294053db27fb4c
    https://github.com/scummvm/scummvm/commit/5bb5bb64f0bd3acdd8235a8c3c294053db27fb4c
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-07-31T14:05:14+02:00

Commit Message:
WAGE: Fix style issues

Changed paths:
    engines/wage/design.cpp
    engines/wage/design.h
    engines/wage/entities.cpp
    engines/wage/gui.cpp



diff --git a/engines/wage/design.cpp b/engines/wage/design.cpp
index 6255932..f28d583 100644
--- a/engines/wage/design.cpp
+++ b/engines/wage/design.cpp
@@ -263,7 +263,7 @@ void drawPixelPlain(int x, int y, int color, void *data) {
 	if (x >= 0 && x < p->surface->w && y >= 0 && y < p->surface->h)
 		*((byte *)p->surface->getBasePtr(x, y)) = (byte)color;
 }
-
+/*
 void Design::drawRect(Graphics::ManagedSurface *surface, Common::ReadStream &in,
 	Graphics::MacPatterns &patterns, byte fillType, byte borderThickness, byte borderFillType) {
 	int16 y1 = in.readSint16BE();
@@ -292,6 +292,41 @@ void Design::drawRect(Graphics::ManagedSurface *surface, Common::ReadStream &in,
 		Graphics::drawLine(x1, y2, x1, y1, kColorBlack, drawPixel, &pd);
 	}
 }
+*/
+
+void Design::drawRect(Graphics::ManagedSurface *surface, Common::ReadStream &in,
+	Graphics::MacPatterns &patterns, byte fillType, byte borderThickness, byte borderFillType) {
+	int16 y1 = in.readSint16BE();
+	int16 x1 = in.readSint16BE();
+	int16 y2 = in.readSint16BE();
+	int16 x2 = in.readSint16BE();
+
+	if (x1 > x2)
+		SWAP(x1, x2);
+	if (y1 > y2)
+		SWAP(y1, y2);
+
+	Common::Rect r(x1, y1, x2, y2);
+	PlotData pd(surface, &patterns, fillType, 1, this);
+
+	const Graphics::Surface s(*surface);
+	Graphics::TransparentSurface *ts = new Graphics::TransparentSurface(*surface);
+	Graphics::NinePatchBitmap bmp(ts, true);
+	//bmp.blit(s, x1, y1, (x2 - x1), (y2 - y1));
+
+	if (fillType <= patterns.size())		
+		Graphics::drawFilledRect(r, kColorBlack, drawPixel, &pd);
+
+	pd.fillType = borderFillType;
+	pd.thickness = borderThickness;
+
+	if (borderThickness > 0 && borderFillType <= patterns.size()) {
+		Graphics::drawLine(x1, y1, x2, y1, kColorBlack, drawPixel, &pd);
+		Graphics::drawLine(x2, y1, x2, y2, kColorBlack, drawPixel, &pd);
+		Graphics::drawLine(x2, y2, x1, y2, kColorBlack, drawPixel, &pd);
+		Graphics::drawLine(x1, y2, x1, y1, kColorBlack, drawPixel, &pd);
+	}
+}
 
 void Design::drawRoundRect(Graphics::ManagedSurface *surface, Common::ReadStream &in,
 	Graphics::MacPatterns &patterns, byte fillType, byte borderThickness, byte borderFillType) {
diff --git a/engines/wage/design.h b/engines/wage/design.h
index 948476b..017fdfc 100644
--- a/engines/wage/design.h
+++ b/engines/wage/design.h
@@ -51,6 +51,9 @@
 #include "common/memstream.h"
 #include "common/rect.h"
 
+#include "graphics/nine_patch.h"
+#include "graphics/transparent_surface.h"
+
 #include "graphics/macgui/macwindowmanager.h"
 
 namespace Wage {
diff --git a/engines/wage/entities.cpp b/engines/wage/entities.cpp
index b2babba..28a708b 100644
--- a/engines/wage/entities.cpp
+++ b/engines/wage/entities.cpp
@@ -146,12 +146,12 @@ void Scene::paint(Graphics::ManagedSurface *surface, int x, int y) {
 	_design->paint(surface, *((WageEngine *)g_engine)->_world->_patterns, x, y);
 
 	for (ObjList::const_iterator it = _objs.begin(); it != _objs.end(); ++it) {
-		debug(2, "paining Obj: %s, index: %d, type: %d", (*it)->_name.c_str(), (*it)->_index, (*it)->_type);
+		debug(2, "painting Obj: %s, index: %d, type: %d", (*it)->_name.c_str(), (*it)->_index, (*it)->_type);
 		(*it)->_design->paint(surface, *((WageEngine *)g_engine)->_world->_patterns, x, y);
 	}
 
 	for (ChrList::const_iterator it = _chrs.begin(); it != _chrs.end(); ++it) {
-		debug(2, "paining Chr: %s", (*it)->_name.c_str());
+		debug(2, "painting Chr: %s", (*it)->_name.c_str());
 		(*it)->_design->paint(surface, *((WageEngine *)g_engine)->_world->_patterns, x, y);
 	}
 }
diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp
index 235a249..2626f3b 100644
--- a/engines/wage/gui.cpp
+++ b/engines/wage/gui.cpp
@@ -13,7 +13,7 @@
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
-
+ 
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


Commit: 1f00d2a09995436551ac42df49df5ab0f710357e
    https://github.com/scummvm/scummvm/commit/1f00d2a09995436551ac42df49df5ab0f710357e
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-07-31T14:05:15+02:00

Commit Message:
GRAPHICS: Introduce NinePatchBitmap to MacWindow

Changed paths:
    graphics/macgui/macwindow.cpp
    graphics/macgui/macwindow.h



diff --git a/graphics/macgui/macwindow.cpp b/graphics/macgui/macwindow.cpp
index 0d43b6d..5531956 100644
--- a/graphics/macgui/macwindow.cpp
+++ b/graphics/macgui/macwindow.cpp
@@ -142,9 +142,12 @@ bool MacWindow::draw(ManagedSurface *g, bool forceRedraw) {
 
 	_contentIsDirty = false;
 
+	TransparentSurface tr;
+	_bmp->blit(tr, 0, 0, _borderSurface.w, _borderSurface.h);
+
 	// Compose
 	_composeSurface.blitFrom(_surface, Common::Rect(0, 0, _surface.w - 2, _surface.h - 2), Common::Point(2, 2));
-	_composeSurface.transBlitFrom(_borderSurface, kColorGreen);
+	_composeSurface.transBlitFrom(tr, kColorGreen);
 
 	g->transBlitFrom(_composeSurface, _composeSurface.getBounds(), Common::Point(_dims.left - 2, _dims.top - 2), kColorGreen2);
 
@@ -202,6 +205,8 @@ void MacWindow::drawBorder() {
 	drawBox(g, x + 2,                y + size,              size - 4,             height - 2 * size - 1);
 	drawBox(g, x + width - size + 1, y + size,              size - 4,             height - 2 * size - 1);
 
+	
+
 	if (active) {
 		fillRect(g, x + size, y + 5,           width - 2 * size - 1, 8, kColorBlack);
 		fillRect(g, x + size, y + height - 13, width - 2 * size - 1, 8, kColorBlack);
@@ -255,6 +260,20 @@ void MacWindow::drawBorder() {
 		drawBox(g, x + (width - w) / 2, y, w, size);
 		font->drawString(g, _title, x + (width - w) / 2 + 5, y + yOff, w, kColorBlack);
 	}
+	
+	initBorders(g);
+}
+
+void MacWindow::initBorders(ManagedSurface *source) {
+	TransparentSurface *tr = new TransparentSurface();
+	tr->create(source->w, source->h, PixelFormat::createFormatCLUT8());	
+	
+	// Fill with alpha so that _check_pixel will go through
+	tr->drawThickLine(0, tr->h / 2, tr->w, tr->h/2, 1, tr->h/2, Graphics::ALPHA_FULL);
+	// Show that something can be drawn
+	tr->drawLine(1, 1, tr->w - 2, tr->h - 2, kColorBlack);
+
+	_bmp = new NinePatchBitmap(tr, false);
 }
 
 void MacWindow::setHighlight(WindowClick highlightedPart) {
diff --git a/graphics/macgui/macwindow.h b/graphics/macgui/macwindow.h
index d4d2c07..908eab8 100644
--- a/graphics/macgui/macwindow.h
+++ b/graphics/macgui/macwindow.h
@@ -49,6 +49,8 @@
 #define GRAPHICS_MACWINDOW_H
 
 #include "graphics/managed_surface.h"
+#include "graphics/transparent_surface.h"
+#include "graphics/nine_patch.h"
 
 namespace Graphics {
 
@@ -110,7 +112,7 @@ protected:
 
 	bool (*_callback)(WindowClick, Common::Event &, void *);
 	void *_dataPtr;
-
+	
 	MacWindowManager *_wm;
 };
 
@@ -140,9 +142,14 @@ private:
 	void updateInnerDims();
 	WindowClick isInBorder(int x, int y);
 
+	void initBorders(ManagedSurface *tr);
+
 private:
 	ManagedSurface _borderSurface;
 	ManagedSurface _composeSurface;
+
+	NinePatchBitmap *_bmp;
+
 	bool _scrollable;
 	bool _resizable;
 	bool _active;


Commit: b8d36443f36a6302f95ee7cc28f063b378810dcc
    https://github.com/scummvm/scummvm/commit/b8d36443f36a6302f95ee7cc28f063b378810dcc
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-07-31T14:05:15+02:00

Commit Message:
WAGE: Remove unnecessary border code

Changed paths:
    engines/wage/design.cpp



diff --git a/engines/wage/design.cpp b/engines/wage/design.cpp
index f28d583..ef50a28 100644
--- a/engines/wage/design.cpp
+++ b/engines/wage/design.cpp
@@ -102,7 +102,7 @@ void Design::paint(Graphics::ManagedSurface *surface, Graphics::MacPatterns &pat
 		_surface->create(_bounds->width(), _bounds->height(), Graphics::PixelFormat::createFormatCLUT8());
 
 		_surface->clear(kColorGreen);
-
+		
 		needRender = true;
 	}
 
@@ -263,36 +263,6 @@ void drawPixelPlain(int x, int y, int color, void *data) {
 	if (x >= 0 && x < p->surface->w && y >= 0 && y < p->surface->h)
 		*((byte *)p->surface->getBasePtr(x, y)) = (byte)color;
 }
-/*
-void Design::drawRect(Graphics::ManagedSurface *surface, Common::ReadStream &in,
-	Graphics::MacPatterns &patterns, byte fillType, byte borderThickness, byte borderFillType) {
-	int16 y1 = in.readSint16BE();
-	int16 x1 = in.readSint16BE();
-	int16 y2 = in.readSint16BE();
-	int16 x2 = in.readSint16BE();
-
-	if (x1 > x2)
-		SWAP(x1, x2);
-	if (y1 > y2)
-		SWAP(y1, y2);
-
-	Common::Rect r(x1, y1, x2, y2);
-	PlotData pd(surface, &patterns, fillType, 1, this);
-
-	if (fillType <= patterns.size())
-		Graphics::drawFilledRect(r, kColorBlack, drawPixel, &pd);
-
-	pd.fillType = borderFillType;
-	pd.thickness = borderThickness;
-
-	if (borderThickness > 0 && borderFillType <= patterns.size()) {
-		Graphics::drawLine(x1, y1, x2, y1, kColorBlack, drawPixel, &pd);
-		Graphics::drawLine(x2, y1, x2, y2, kColorBlack, drawPixel, &pd);
-		Graphics::drawLine(x2, y2, x1, y2, kColorBlack, drawPixel, &pd);
-		Graphics::drawLine(x1, y2, x1, y1, kColorBlack, drawPixel, &pd);
-	}
-}
-*/
 
 void Design::drawRect(Graphics::ManagedSurface *surface, Common::ReadStream &in,
 	Graphics::MacPatterns &patterns, byte fillType, byte borderThickness, byte borderFillType) {
@@ -309,12 +279,7 @@ void Design::drawRect(Graphics::ManagedSurface *surface, Common::ReadStream &in,
 	Common::Rect r(x1, y1, x2, y2);
 	PlotData pd(surface, &patterns, fillType, 1, this);
 
-	const Graphics::Surface s(*surface);
-	Graphics::TransparentSurface *ts = new Graphics::TransparentSurface(*surface);
-	Graphics::NinePatchBitmap bmp(ts, true);
-	//bmp.blit(s, x1, y1, (x2 - x1), (y2 - y1));
-
-	if (fillType <= patterns.size())		
+	if (fillType <= patterns.size())
 		Graphics::drawFilledRect(r, kColorBlack, drawPixel, &pd);
 
 	pd.fillType = borderFillType;


Commit: 98d0838df3ee3697268b846d9d114e2a9788cb40
    https://github.com/scummvm/scummvm/commit/98d0838df3ee3697268b846d9d114e2a9788cb40
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-07-31T14:05:15+02:00

Commit Message:
WAGE: Add basic border loading code

Changed paths:
    engines/wage/gui.cpp
    engines/wage/gui.h



diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp
index 2626f3b..09e2e1a 100644
--- a/engines/wage/gui.cpp
+++ b/engines/wage/gui.cpp
@@ -168,6 +168,9 @@ Gui::Gui(WageEngine *engine) {
 
 	_consoleWindow = _wm.addWindow(true, true, true);
 	_consoleWindow->setCallback(consoleWindowCallback, this);
+
+	loadBorders();
+	//_sceneWindow->setBorders(&_borders);
 }
 
 Gui::~Gui() {
@@ -220,6 +223,8 @@ void Gui::draw() {
 	_sceneDirty = false;
 	_consoleDirty = false;
 	_consoleFullRedraw = false;
+
+	loadBorders();
 }
 
 void Gui::drawScene() {
@@ -228,7 +233,7 @@ void Gui::drawScene() {
 
 	_scene->paint(_sceneWindow->getSurface(), 0, 0);
 	_sceneWindow->setDirty(true);
-
+	
 	_sceneDirty = true;
 	_consoleDirty = true;
 	_menu->setDirty(true);
@@ -363,4 +368,33 @@ void Gui::executeMenuCommand(int action, Common::String &text) {
 	}
 }
 
+void Gui::loadBorders() {
+	Common::File borderfile;
+	if (!borderfile.open("borders.bmp")) {
+		debug(1, "Cannot open border file");
+		return;
+	}
+
+	Image::BitmapDecoder bmpDecoder;
+	Common::SeekableReadStream *stream = borderfile.readStream(borderfile.size());
+	const Graphics::Surface * source;
+
+	if (stream) {
+		bmpDecoder.loadStream(*stream);		
+		source = bmpDecoder.getSurface();		
+
+		_borders.create(source->w, source->h, source->format);
+		_borders.copyRectToSurface(*source, 0, 0, Common::Rect(0, 0, source->w, source->h));
+		//source = source->convertTo(Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 0, 0, 0));
+
+		delete stream;
+
+		g_system->copyRectToScreen(source->getPixels(), source->pitch, 40, 0, source->w, source->h);
+		g_system->copyRectToScreen(_borders.getPixels(), _borders.pitch, 40, 100, _borders.w, _borders.h);
+		g_system->updateScreen();
+	}
+
+	debug(1, "Hello");
+}
+
 } // End of namespace Wage
diff --git a/engines/wage/gui.h b/engines/wage/gui.h
index cf30c57..23ee9f0 100644
--- a/engines/wage/gui.h
+++ b/engines/wage/gui.h
@@ -58,6 +58,14 @@
 #include "common/events.h"
 #include "common/rect.h"
 
+#include "common/file.h"
+#include "graphics/pixelformat.h"
+#include "image/bmp.h"
+#include "image/png.h"
+
+#include "graphics/primitives.h"
+
+
 namespace Wage {
 
 using namespace Graphics::MacWindowConstants;
@@ -147,6 +155,7 @@ private:
 	int calcTextX(int x, int textLine);
 	int calcTextY(int y);
 	void updateTextSelection(int x, int y);
+	void loadBorders();
 
 public:
 	Graphics::ManagedSurface _screen;
@@ -165,6 +174,8 @@ public:
 	Graphics::MacWindow *_sceneWindow;
 	Graphics::MacWindow *_consoleWindow;
 
+	Graphics::TransparentSurface _borders;
+
 private:
 	Graphics::ManagedSurface _console;
 	Graphics::Menu *_menu;


Commit: 6c89eaa1b8b3c674e5f507bd3bf5d29db959e244
    https://github.com/scummvm/scummvm/commit/6c89eaa1b8b3c674e5f507bd3bf5d29db959e244
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-07-31T14:05:15+02:00

Commit Message:
GRAPHICS: Include border loading code

Changed paths:
    graphics/macgui/macwindow.cpp
    graphics/macgui/macwindow.h



diff --git a/graphics/macgui/macwindow.cpp b/graphics/macgui/macwindow.cpp
index 5531956..4dacf23 100644
--- a/graphics/macgui/macwindow.cpp
+++ b/graphics/macgui/macwindow.cpp
@@ -64,7 +64,7 @@ BaseMacWindow::BaseMacWindow(int id, bool editable, MacWindowManager *wm) :
 }
 
 MacWindow::MacWindow(int id, bool scrollable, bool resizable, bool editable, MacWindowManager *wm) :
-		BaseMacWindow(id, editable, wm), _scrollable(scrollable), _resizable(resizable) {
+		BaseMacWindow(id, editable, wm), _scrollable(scrollable), _resizable(resizable), _bmp(new TransparentSurface(), false) {
 	_active = false;
 	_borderIsDirty = true;
 
@@ -78,6 +78,9 @@ MacWindow::MacWindow(int id, bool scrollable, bool resizable, bool editable, Mac
 	_draggedX = _draggedY = 0;
 
 	_type = kWindowWindow;
+
+	TransparentSurface *srf = new TransparentSurface;
+	_bmp = NinePatchBitmap(srf, false);
 }
 
 MacWindow::~MacWindow() {
@@ -142,18 +145,23 @@ bool MacWindow::draw(ManagedSurface *g, bool forceRedraw) {
 
 	_contentIsDirty = false;
 
-	TransparentSurface tr;
-	_bmp->blit(tr, 0, 0, _borderSurface.w, _borderSurface.h);
-
+	
 	// Compose
 	_composeSurface.blitFrom(_surface, Common::Rect(0, 0, _surface.w - 2, _surface.h - 2), Common::Point(2, 2));
-	_composeSurface.transBlitFrom(tr, kColorGreen);
+	_composeSurface.transBlitFrom(_borderSurface, kColorGreen);
 
 	g->transBlitFrom(_composeSurface, _composeSurface.getBounds(), Common::Point(_dims.left - 2, _dims.top - 2), kColorGreen2);
 
 	return true;
 }
 
+bool MacWindow::drawTR(Surface &g, int x, int y, int w, int h, bool forceRedraw) {
+
+	_bmp.blit(g, x, y, w, h);
+
+	return false;
+}
+
 #define ARROW_W 12
 #define ARROW_H 6
 const int arrowPixels[ARROW_H][ARROW_W] = {
@@ -259,21 +267,7 @@ void MacWindow::drawBorder() {
 			w = maxWidth;
 		drawBox(g, x + (width - w) / 2, y, w, size);
 		font->drawString(g, _title, x + (width - w) / 2 + 5, y + yOff, w, kColorBlack);
-	}
-	
-	initBorders(g);
-}
-
-void MacWindow::initBorders(ManagedSurface *source) {
-	TransparentSurface *tr = new TransparentSurface();
-	tr->create(source->w, source->h, PixelFormat::createFormatCLUT8());	
-	
-	// Fill with alpha so that _check_pixel will go through
-	tr->drawThickLine(0, tr->h / 2, tr->w, tr->h/2, 1, tr->h/2, Graphics::ALPHA_FULL);
-	// Show that something can be drawn
-	tr->drawLine(1, 1, tr->w - 2, tr->h - 2, kColorBlack);
-
-	_bmp = new NinePatchBitmap(tr, false);
+	}	
 }
 
 void MacWindow::setHighlight(WindowClick highlightedPart) {
@@ -293,6 +287,10 @@ void MacWindow::setHighlight(WindowClick highlightedPart) {
 	_borderIsDirty = true;
  }
 
+ void MacWindow::setBorders(TransparentSurface *source) {
+	 _bmp = NinePatchBitmap(source, true);
+ }
+
 
 void MacWindow::drawBox(ManagedSurface *g, int x, int y, int w, int h) {
 	Common::Rect r(x, y, x + w + 1, y + h + 1);
diff --git a/graphics/macgui/macwindow.h b/graphics/macgui/macwindow.h
index 908eab8..dbbaff2 100644
--- a/graphics/macgui/macwindow.h
+++ b/graphics/macgui/macwindow.h
@@ -51,6 +51,7 @@
 #include "graphics/managed_surface.h"
 #include "graphics/transparent_surface.h"
 #include "graphics/nine_patch.h"
+#include "graphics/palette.h"
 
 namespace Graphics {
 
@@ -126,6 +127,7 @@ public:
 	const Common::Rect &getInnerDimensions() { return _innerDims; }
 
 	bool draw(ManagedSurface *g, bool forceRedraw = false);
+	bool drawTR(Surface &g, int x, int y, int w, int h, bool forceRedraw);
 
 	void setActive(bool active);
 	void setTitle(Common::String &title) { _title = title; }
@@ -134,21 +136,21 @@ public:
 	bool processEvent(Common::Event &event);
 	bool hasAllFocus() { return _beingDragged || _beingResized; }
 
+	void setBorders(TransparentSurface *source);
+
 private:
 	void drawBorder();
 	void drawBox(ManagedSurface *g, int x, int y, int w, int h);
 	void fillRect(ManagedSurface *g, int x, int y, int w, int h, int color);
 	const Font *getTitleFont();
 	void updateInnerDims();
-	WindowClick isInBorder(int x, int y);
-
-	void initBorders(ManagedSurface *tr);
+	WindowClick isInBorder(int x, int y);	
 
 private:
 	ManagedSurface _borderSurface;
 	ManagedSurface _composeSurface;
 
-	NinePatchBitmap *_bmp;
+	NinePatchBitmap _bmp;
 
 	bool _scrollable;
 	bool _resizable;


Commit: 3d950ad125dee02b45931c2a7943e4ee4d6a93d9
    https://github.com/scummvm/scummvm/commit/3d950ad125dee02b45931c2a7943e4ee4d6a93d9
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-07-31T14:05:15+02:00

Commit Message:
WAGE: Remove superfluous comment

Changed paths:
    engines/wage/gui.cpp



diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp
index 09e2e1a..49a457d 100644
--- a/engines/wage/gui.cpp
+++ b/engines/wage/gui.cpp
@@ -385,7 +385,6 @@ void Gui::loadBorders() {
 
 		_borders.create(source->w, source->h, source->format);
 		_borders.copyRectToSurface(*source, 0, 0, Common::Rect(0, 0, source->w, source->h));
-		//source = source->convertTo(Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 0, 0, 0));
 
 		delete stream;
 


Commit: 4a16f5fc3987be23dd67d6ed42c9f8f0453eba6d
    https://github.com/scummvm/scummvm/commit/4a16f5fc3987be23dd67d6ed42c9f8f0453eba6d
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-07-31T14:05:15+02:00

Commit Message:
WAGE: Begin adding borders to the windows

Changed paths:
    engines/wage/gui.cpp
    engines/wage/gui.h
    graphics/macgui/macwindow.cpp
    graphics/macgui/macwindow.h



diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp
index 49a457d..0e0c034 100644
--- a/engines/wage/gui.cpp
+++ b/engines/wage/gui.cpp
@@ -170,7 +170,7 @@ Gui::Gui(WageEngine *engine) {
 	_consoleWindow->setCallback(consoleWindowCallback, this);
 
 	loadBorders();
-	//_sceneWindow->setBorders(&_borders);
+	_sceneWindow->setBorders(&_borders);
 }
 
 Gui::~Gui() {
@@ -223,8 +223,6 @@ void Gui::draw() {
 	_sceneDirty = false;
 	_consoleDirty = false;
 	_consoleFullRedraw = false;
-
-	loadBorders();
 }
 
 void Gui::drawScene() {
@@ -370,27 +368,29 @@ void Gui::executeMenuCommand(int action, Common::String &text) {
 
 void Gui::loadBorders() {
 	Common::File borderfile;
-	if (!borderfile.open("borders.bmp")) {
+	if (!borderfile.open("logo.bmp")) {
 		debug(1, "Cannot open border file");
 		return;
 	}
 
 	Image::BitmapDecoder bmpDecoder;
 	Common::SeekableReadStream *stream = borderfile.readStream(borderfile.size());
-	const Graphics::Surface * source;
+	Graphics::Surface source;
 
 	if (stream) {
-		bmpDecoder.loadStream(*stream);		
-		source = bmpDecoder.getSurface();		
+		bmpDecoder.loadStream(*stream);	
+		source = *bmpDecoder.getSurface();
+		source.convertToInPlace(_borders.getSupportedPixelFormat(), bmpDecoder.getPalette());
 
-		_borders.create(source->w, source->h, source->format);
-		_borders.copyRectToSurface(*source, 0, 0, Common::Rect(0, 0, source->w, source->h));
+		_borders.create(source.w, source.h, source.format);
+		_borders.copyFrom(source);
+		_borders.applyColorKey(255, 0, 255, false);
 
 		delete stream;
 
-		g_system->copyRectToScreen(source->getPixels(), source->pitch, 40, 0, source->w, source->h);
-		g_system->copyRectToScreen(_borders.getPixels(), _borders.pitch, 40, 100, _borders.w, _borders.h);
-		g_system->updateScreen();
+		//g_system->copyRectToScreen(source.getPixels(), source.pitch, 40, 0, source.w, source.h);
+		//g_system->copyRectToScreen(_borders.getPixels(), _borders.pitch, 40, 100, _borders.w, _borders.h);
+		//g_system->updateScreen();
 	}
 
 	debug(1, "Hello");
diff --git a/engines/wage/gui.h b/engines/wage/gui.h
index 23ee9f0..a72f469 100644
--- a/engines/wage/gui.h
+++ b/engines/wage/gui.h
@@ -61,9 +61,8 @@
 #include "common/file.h"
 #include "graphics/pixelformat.h"
 #include "image/bmp.h"
-#include "image/png.h"
 
-#include "graphics/primitives.h"
+#include "graphics/palette.h"
 
 
 namespace Wage {
diff --git a/graphics/macgui/macwindow.cpp b/graphics/macgui/macwindow.cpp
index 4dacf23..0ca0a89 100644
--- a/graphics/macgui/macwindow.cpp
+++ b/graphics/macgui/macwindow.cpp
@@ -64,7 +64,7 @@ BaseMacWindow::BaseMacWindow(int id, bool editable, MacWindowManager *wm) :
 }
 
 MacWindow::MacWindow(int id, bool scrollable, bool resizable, bool editable, MacWindowManager *wm) :
-		BaseMacWindow(id, editable, wm), _scrollable(scrollable), _resizable(resizable), _bmp(new TransparentSurface(), false) {
+		BaseMacWindow(id, editable, wm), _scrollable(scrollable), _resizable(resizable) {
 	_active = false;
 	_borderIsDirty = true;
 
@@ -79,8 +79,6 @@ MacWindow::MacWindow(int id, bool scrollable, bool resizable, bool editable, Mac
 
 	_type = kWindowWindow;
 
-	TransparentSurface *srf = new TransparentSurface;
-	_bmp = NinePatchBitmap(srf, false);
 }
 
 MacWindow::~MacWindow() {
@@ -150,17 +148,17 @@ bool MacWindow::draw(ManagedSurface *g, bool forceRedraw) {
 	_composeSurface.blitFrom(_surface, Common::Rect(0, 0, _surface.w - 2, _surface.h - 2), Common::Point(2, 2));
 	_composeSurface.transBlitFrom(_borderSurface, kColorGreen);
 
+	TransparentSurface tr(_borders);
+	//tr.create(_composeSurface.w, _composeSurface.h, tr.getSupportedPixelFormat());
+	
+	//_bmp->blit(tr, 0, 0, tr.w, tr.h)
+	_composeSurface.transBlitFrom(tr);
+
 	g->transBlitFrom(_composeSurface, _composeSurface.getBounds(), Common::Point(_dims.left - 2, _dims.top - 2), kColorGreen2);
 
 	return true;
 }
 
-bool MacWindow::drawTR(Surface &g, int x, int y, int w, int h, bool forceRedraw) {
-
-	_bmp.blit(g, x, y, w, h);
-
-	return false;
-}
 
 #define ARROW_W 12
 #define ARROW_H 6
@@ -289,6 +287,7 @@ void MacWindow::setHighlight(WindowClick highlightedPart) {
 
  void MacWindow::setBorders(TransparentSurface *source) {
 	 _bmp = NinePatchBitmap(source, true);
+	 _borders = TransparentSurface(*source);
  }
 
 
diff --git a/graphics/macgui/macwindow.h b/graphics/macgui/macwindow.h
index dbbaff2..335722b 100644
--- a/graphics/macgui/macwindow.h
+++ b/graphics/macgui/macwindow.h
@@ -127,8 +127,7 @@ public:
 	const Common::Rect &getInnerDimensions() { return _innerDims; }
 
 	bool draw(ManagedSurface *g, bool forceRedraw = false);
-	bool drawTR(Surface &g, int x, int y, int w, int h, bool forceRedraw);
-
+	
 	void setActive(bool active);
 	void setTitle(Common::String &title) { _title = title; }
 	void setHighlight(WindowClick highlightedPart);
@@ -151,6 +150,7 @@ private:
 	ManagedSurface _composeSurface;
 
 	NinePatchBitmap _bmp;
+	TransparentSurface _borders;
 
 	bool _scrollable;
 	bool _resizable;


Commit: b6722a1477e0ae30c8429dc77f9e1381651f2603
    https://github.com/scummvm/scummvm/commit/b6722a1477e0ae30c8429dc77f9e1381651f2603
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-07-31T14:05:15+02:00

Commit Message:
GRAPHICS: Fix segfault in macwindow

Changed paths:
    graphics/macgui/macwindow.cpp
    graphics/macgui/macwindow.h



diff --git a/graphics/macgui/macwindow.cpp b/graphics/macgui/macwindow.cpp
index 0ca0a89..dfb1c07 100644
--- a/graphics/macgui/macwindow.cpp
+++ b/graphics/macgui/macwindow.cpp
@@ -79,6 +79,8 @@ MacWindow::MacWindow(int id, bool scrollable, bool resizable, bool editable, Mac
 
 	_type = kWindowWindow;
 
+	_borders = nullptr;
+
 }
 
 MacWindow::~MacWindow() {
@@ -148,11 +150,13 @@ bool MacWindow::draw(ManagedSurface *g, bool forceRedraw) {
 	_composeSurface.blitFrom(_surface, Common::Rect(0, 0, _surface.w - 2, _surface.h - 2), Common::Point(2, 2));
 	_composeSurface.transBlitFrom(_borderSurface, kColorGreen);
 
-	TransparentSurface tr(_borders);
-	//tr.create(_composeSurface.w, _composeSurface.h, tr.getSupportedPixelFormat());
-	
-	//_bmp->blit(tr, 0, 0, tr.w, tr.h)
-	_composeSurface.transBlitFrom(tr);
+	if (_borders) {
+		TransparentSurface tr(*_borders);
+		//tr.create(_composeSurface.w, _composeSurface.h, tr.getSupportedPixelFormat());
+
+		//_bmp->blit(tr, 0, 0, tr.w, tr.h)
+		_composeSurface.transBlitFrom(tr);
+	}
 
 	g->transBlitFrom(_composeSurface, _composeSurface.getBounds(), Common::Point(_dims.left - 2, _dims.top - 2), kColorGreen2);
 
@@ -286,8 +290,8 @@ void MacWindow::setHighlight(WindowClick highlightedPart) {
  }
 
  void MacWindow::setBorders(TransparentSurface *source) {
-	 _bmp = NinePatchBitmap(source, true);
-	 _borders = TransparentSurface(*source);
+	 _bmp = new NinePatchBitmap(source, true);
+	 _borders = new TransparentSurface(*source);
  }
 
 
diff --git a/graphics/macgui/macwindow.h b/graphics/macgui/macwindow.h
index 335722b..9c908f3 100644
--- a/graphics/macgui/macwindow.h
+++ b/graphics/macgui/macwindow.h
@@ -149,8 +149,8 @@ private:
 	ManagedSurface _borderSurface;
 	ManagedSurface _composeSurface;
 
-	NinePatchBitmap _bmp;
-	TransparentSurface _borders;
+	NinePatchBitmap *_bmp;
+	TransparentSurface *_borders = nullptr;
 
 	bool _scrollable;
 	bool _resizable;


Commit: d49d573edc7e7c4698dac2d7748365a6e9dcef0c
    https://github.com/scummvm/scummvm/commit/d49d573edc7e7c4698dac2d7748365a6e9dcef0c
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-07-31T14:05:15+02:00

Commit Message:
WAGE: Fix border loading

Changed paths:
    engines/wage/gui.cpp



diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp
index 0e0c034..4ef2cf8 100644
--- a/engines/wage/gui.cpp
+++ b/engines/wage/gui.cpp
@@ -368,7 +368,7 @@ void Gui::executeMenuCommand(int action, Common::String &text) {
 
 void Gui::loadBorders() {
 	Common::File borderfile;
-	if (!borderfile.open("logo.bmp")) {
+	if (!borderfile.open("border.bmp")) {
 		debug(1, "Cannot open border file");
 		return;
 	}
@@ -379,9 +379,8 @@ void Gui::loadBorders() {
 
 	if (stream) {
 		bmpDecoder.loadStream(*stream);	
-		source = *bmpDecoder.getSurface();
+		source = *(bmpDecoder.getSurface());
 		source.convertToInPlace(_borders.getSupportedPixelFormat(), bmpDecoder.getPalette());
-
 		_borders.create(source.w, source.h, source.format);
 		_borders.copyFrom(source);
 		_borders.applyColorKey(255, 0, 255, false);


Commit: 26238ee6f987a1ffe5836145f3b937cfd38d28cf
    https://github.com/scummvm/scummvm/commit/26238ee6f987a1ffe5836145f3b937cfd38d28cf
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-07-31T14:44:48+02:00

Commit Message:
GRAPHICS: Fix border loading

Changed paths:
    graphics/macgui/macwindow.cpp
    graphics/macgui/macwindow.h



diff --git a/graphics/macgui/macwindow.cpp b/graphics/macgui/macwindow.cpp
index dfb1c07..226037e 100644
--- a/graphics/macgui/macwindow.cpp
+++ b/graphics/macgui/macwindow.cpp
@@ -145,19 +145,10 @@ bool MacWindow::draw(ManagedSurface *g, bool forceRedraw) {
 
 	_contentIsDirty = false;
 
-	
 	// Compose
 	_composeSurface.blitFrom(_surface, Common::Rect(0, 0, _surface.w - 2, _surface.h - 2), Common::Point(2, 2));
 	_composeSurface.transBlitFrom(_borderSurface, kColorGreen);
 
-	if (_borders) {
-		TransparentSurface tr(*_borders);
-		//tr.create(_composeSurface.w, _composeSurface.h, tr.getSupportedPixelFormat());
-
-		//_bmp->blit(tr, 0, 0, tr.w, tr.h)
-		_composeSurface.transBlitFrom(tr);
-	}
-
 	g->transBlitFrom(_composeSurface, _composeSurface.getBounds(), Common::Point(_dims.left - 2, _dims.top - 2), kColorGreen2);
 
 	return true;
@@ -192,19 +183,43 @@ void MacWindow::updateInnerDims() {
 void MacWindow::drawBorder() {
 	_borderIsDirty = false;
 
-	bool active = _active, scrollable = _scrollable, closeable = _active, drawTitle = !_title.empty();
-	const int size = kBorderWidth;
-	int x = 0;
-	int y = 0;
-	int width = _borderSurface.w;
-	int height = _borderSurface.h;
 	ManagedSurface *g = &_borderSurface;
+	prepareBorderSurface(g);
+
+	if (_borders)
+		drawBorderFromSurface(g);
+	else
+		drawSimpleBorder(g);
+}
 
+void MacWindow::prepareBorderSurface(ManagedSurface *g) {
 	// We draw rect with outer kColorGreen2 and inner kColorGreen, so on 2 passes we cut out
 	// scene by external shape of the border
 	int sz = kBorderWidth / 2;
+	int width = g->w;
+	int height = g->h;
 	g->clear(kColorGreen2);
 	g->fillRect(Common::Rect(sz, sz, width - sz, height - sz), kColorGreen);
+}
+
+void MacWindow::drawBorderFromSurface(ManagedSurface *g) {
+	TransparentSurface srf;
+	srf.create(_composeSurface.w, _composeSurface.h, _borders->format);
+
+	_bmp = new NinePatchBitmap(_borders, false);
+
+	_bmp->blit(srf, 0, 0, srf.w, srf.h);
+	_borderSurface.transBlitFrom(srf, _borderSurface.format.ARGBToColor(0, 255, 255, 255));
+}
+
+void MacWindow::drawSimpleBorder(ManagedSurface *g) {
+
+	bool active = _active, scrollable = _scrollable, closeable = _active, drawTitle = !_title.empty();
+	const int size = kBorderWidth;
+	int x = 0;
+	int y = 0;
+	int width = _borderSurface.w;
+	int height = _borderSurface.h;
 
 	drawBox(g, x,                    y,                     size,                 size);
 	drawBox(g, x + width - size - 1, y,                     size,                 size);
@@ -215,8 +230,6 @@ void MacWindow::drawBorder() {
 	drawBox(g, x + 2,                y + size,              size - 4,             height - 2 * size - 1);
 	drawBox(g, x + width - size + 1, y + size,              size - 4,             height - 2 * size - 1);
 
-	
-
 	if (active) {
 		fillRect(g, x + size, y + 5,           width - 2 * size - 1, 8, kColorBlack);
 		fillRect(g, x + size, y + height - 13, width - 2 * size - 1, 8, kColorBlack);
@@ -247,7 +260,7 @@ void MacWindow::drawBorder() {
 				int ry2 = ry1 + _dims.height() * _scrollSize;
 				Common::Rect rr(rx1, ry1, rx2, ry2);
 
-				drawFilledRect(rr, kColorBlack, drawPixelInverted, g);
+				Graphics::drawFilledRect(rr, kColorBlack, drawPixelInverted, g);
 			}
 		}
 		if (closeable) {
@@ -260,7 +273,7 @@ void MacWindow::drawBorder() {
 	}
 
 	if (drawTitle) {
-		const Font *font = getTitleFont();
+		const Graphics::Font *font = getTitleFont();
 		int yOff = _wm->hasBuiltInFonts() ? 3 : 1;
 
 		int w = font->getStringWidth(_title) + 10;
@@ -269,7 +282,7 @@ void MacWindow::drawBorder() {
 			w = maxWidth;
 		drawBox(g, x + (width - w) / 2, y, w, size);
 		font->drawString(g, _title, x + (width - w) / 2 + 5, y + yOff, w, kColorBlack);
-	}	
+	}
 }
 
 void MacWindow::setHighlight(WindowClick highlightedPart) {
@@ -290,7 +303,6 @@ void MacWindow::setHighlight(WindowClick highlightedPart) {
  }
 
  void MacWindow::setBorders(TransparentSurface *source) {
-	 _bmp = new NinePatchBitmap(source, true);
 	 _borders = new TransparentSurface(*source);
  }
 
diff --git a/graphics/macgui/macwindow.h b/graphics/macgui/macwindow.h
index 9c908f3..6526e05 100644
--- a/graphics/macgui/macwindow.h
+++ b/graphics/macgui/macwindow.h
@@ -139,6 +139,9 @@ public:
 
 private:
 	void drawBorder();
+	void prepareBorderSurface(ManagedSurface *g);
+	void drawSimpleBorder(ManagedSurface *g);
+	void drawBorderFromSurface(ManagedSurface *g);
 	void drawBox(ManagedSurface *g, int x, int y, int w, int h);
 	void fillRect(ManagedSurface *g, int x, int y, int w, int h, int color);
 	const Font *getTitleFont();
@@ -150,7 +153,7 @@ private:
 	ManagedSurface _composeSurface;
 
 	NinePatchBitmap *_bmp;
-	TransparentSurface *_borders = nullptr;
+	TransparentSurface *_borders;
 
 	bool _scrollable;
 	bool _resizable;


Commit: 4ab02530ae8e6d32bf970973669b306a859b2805
    https://github.com/scummvm/scummvm/commit/4ab02530ae8e6d32bf970973669b306a859b2805
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-07-31T14:45:36+02:00

Commit Message:
GRAPHICS: Add MacWindowBorder to abstract borders

Changed paths:
  A graphics/macgui/macwindowborder.cpp
  A graphics/macgui/macwindowborder.h
    graphics/macgui/macwindow.cpp
    graphics/macgui/macwindow.h
    graphics/module.mk
    graphics/nine_patch.h



diff --git a/graphics/macgui/macwindow.cpp b/graphics/macgui/macwindow.cpp
index 226037e..7ad5666 100644
--- a/graphics/macgui/macwindow.cpp
+++ b/graphics/macgui/macwindow.cpp
@@ -203,12 +203,12 @@ void MacWindow::prepareBorderSurface(ManagedSurface *g) {
 }
 
 void MacWindow::drawBorderFromSurface(ManagedSurface *g) {
-	TransparentSurface srf;
-	srf.create(_composeSurface.w, _composeSurface.h, _borders->format);
+	assert(_borders);
 
-	_bmp = new NinePatchBitmap(_borders, false);
+	TransparentSurface srf;
+	srf.create(_borderSurface.w, _borderSurface.h, _borders->format);
 
-	_bmp->blit(srf, 0, 0, srf.w, srf.h);
+	_macBorder.blitBorderInto(_borderSurface, false);
 	_borderSurface.transBlitFrom(srf, _borderSurface.format.ARGBToColor(0, 255, 255, 255));
 }
 
@@ -304,6 +304,8 @@ void MacWindow::setHighlight(WindowClick highlightedPart) {
 
  void MacWindow::setBorders(TransparentSurface *source) {
 	 _borders = new TransparentSurface(*source);
+	 if (_borders)
+		 _macBorder.addInactiveBorder(_borders);
  }
 
 
diff --git a/graphics/macgui/macwindow.h b/graphics/macgui/macwindow.h
index 6526e05..1181190 100644
--- a/graphics/macgui/macwindow.h
+++ b/graphics/macgui/macwindow.h
@@ -53,9 +53,12 @@
 #include "graphics/nine_patch.h"
 #include "graphics/palette.h"
 
+#include "graphics/macgui/macwindowborder.h"
+
 namespace Graphics {
 
 class MacWindowManager;
+class MacWindowBorder;
 
 namespace MacWindowConstants {
 	enum WindowType {
@@ -155,6 +158,8 @@ private:
 	NinePatchBitmap *_bmp;
 	TransparentSurface *_borders;
 
+	MacWindowBorder _macBorder;
+
 	bool _scrollable;
 	bool _resizable;
 	bool _active;
diff --git a/graphics/macgui/macwindowborder.cpp b/graphics/macgui/macwindowborder.cpp
new file mode 100644
index 0000000..7e64f1d
--- /dev/null
+++ b/graphics/macgui/macwindowborder.cpp
@@ -0,0 +1,38 @@
+#include "macwindowborder.h"
+
+namespace Graphics {
+
+MacWindowBorder::MacWindowBorder() {
+	_activeBorder = nullptr;
+	_inactiveBorder = nullptr;
+}
+
+
+MacWindowBorder::~MacWindowBorder() {
+	if (_activeBorder)
+		delete _activeBorder;
+	if (_inactiveBorder)
+		delete _inactiveBorder;
+}
+
+void MacWindowBorder::addActiveBorder(TransparentSurface *source) {
+	// Assumes NinePatchBitmap invariants hold
+	_activeBorder = new NinePatchBitmap(source, false);	
+}
+
+void MacWindowBorder::addInactiveBorder(TransparentSurface *source) {
+	_inactiveBorder = new NinePatchBitmap(source, false);
+}
+
+void MacWindowBorder::blitBorderInto(ManagedSurface &destination, bool active) {
+
+	TransparentSurface srf;
+	NinePatchBitmap *src = active ? _activeBorder : _inactiveBorder;
+
+	srf.create(destination.w, destination.h, src->getSource()->format);
+
+	src->blit(srf, 0, 0, srf.w, srf.h);
+	destination.transBlitFrom(srf, destination.format.ARGBToColor(0, 255, 255, 255));
+}
+
+} // End of namespace Graphics
diff --git a/graphics/macgui/macwindowborder.h b/graphics/macgui/macwindowborder.h
new file mode 100644
index 0000000..c956add
--- /dev/null
+++ b/graphics/macgui/macwindowborder.h
@@ -0,0 +1,78 @@
+/* ScummVM - Graphic Adventure Engine
+*
+* ScummVM is the legal property of its developers, whose names
+* are too numerous to list here. Please refer to the COPYRIGHT
+* file distributed with this source distribution.
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*
+* MIT License:
+*
+* Copyright (c) 2016 Borja Lorente
+*
+* Permission is hereby granted, free of charge, to any person
+* obtaining a copy of this software and associated documentation
+* files (the "Software"), to deal in the Software without
+* restriction, including without limitation the rights to use,
+* copy, modify, merge, publish, distribute, sublicense, and/or sell
+* copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following
+* conditions:
+*
+* The above copyright notice and this permission notice shall be
+* included in all copies or substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+* OTHER DEALINGS IN THE SOFTWARE.
+*
+*/
+
+#ifndef GRAPHICS_MACWINDOWBORDER_H
+#define GRAPHICS_MACWINDOWBORDER_H
+
+#include "common/str.h"
+#include "common/list.h"
+
+#include "graphics/nine_patch.h"
+#include "graphics/managed_surface.h"
+#include "graphics/transparent_surface.h"
+
+namespace Graphics {
+
+class MacWindowBorder {
+public:
+	MacWindowBorder();
+	~MacWindowBorder();
+
+	void addActiveBorder(TransparentSurface *source);
+	void addInactiveBorder(TransparentSurface *source);
+	void blitBorderInto(ManagedSurface &destination, bool active);
+
+private:
+
+	NinePatchBitmap *_activeBorder;
+	NinePatchBitmap *_inactiveBorder;
+
+};
+
+} // End of namespace Graphics
+#endif
+
diff --git a/graphics/module.mk b/graphics/module.mk
index 941ae1d..1af6d28 100644
--- a/graphics/module.mk
+++ b/graphics/module.mk
@@ -31,7 +31,8 @@ MODULE_OBJS := \
 	yuv_to_rgb.o \
 	macgui/macwindowmanager.o\
 	macgui/macwindow.o \
-	macgui/macmenu.o
+	macgui/macmenu.o \
+	macgui/macwindowborder.o
 
 ifdef USE_SCALERS
 MODULE_OBJS += \
diff --git a/graphics/nine_patch.h b/graphics/nine_patch.h
index ebd6e1e..eaebac3 100644
--- a/graphics/nine_patch.h
+++ b/graphics/nine_patch.h
@@ -47,6 +47,7 @@
 #define GRAPHICS_NINE_PATCH_H
 
 #include "common/array.h"
+#include "common/rect.h"
 
 namespace Graphics {
 


Commit: a2955b102547ab37a7cf9b42ca0addeed82bb942
    https://github.com/scummvm/scummvm/commit/a2955b102547ab37a7cf9b42ca0addeed82bb942
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-07-31T14:45:36+02:00

Commit Message:
GRAPHICS: Add active/inactive borders to MacWindowBorders

Changed paths:
    graphics/macgui/macwindow.cpp
    graphics/macgui/macwindow.h
    graphics/macgui/macwindowborder.cpp
    graphics/macgui/macwindowborder.h



diff --git a/graphics/macgui/macwindow.cpp b/graphics/macgui/macwindow.cpp
index 7ad5666..3c9372a 100644
--- a/graphics/macgui/macwindow.cpp
+++ b/graphics/macgui/macwindow.cpp
@@ -186,7 +186,7 @@ void MacWindow::drawBorder() {
 	ManagedSurface *g = &_borderSurface;
 	prepareBorderSurface(g);
 
-	if (_borders)
+	if (!_macBorder.empty())
 		drawBorderFromSurface(g);
 	else
 		drawSimpleBorder(g);
@@ -203,12 +203,11 @@ void MacWindow::prepareBorderSurface(ManagedSurface *g) {
 }
 
 void MacWindow::drawBorderFromSurface(ManagedSurface *g) {
-	assert(_borders);
 
 	TransparentSurface srf;
 	srf.create(_borderSurface.w, _borderSurface.h, _borders->format);
 
-	_macBorder.blitBorderInto(_borderSurface, false);
+	_macBorder.blitBorderInto(_borderSurface, _active);
 	_borderSurface.transBlitFrom(srf, _borderSurface.format.ARGBToColor(0, 255, 255, 255));
 }
 
@@ -302,10 +301,12 @@ void MacWindow::setHighlight(WindowClick highlightedPart) {
 	_borderIsDirty = true;
  }
 
- void MacWindow::setBorders(TransparentSurface *source) {
+ void MacWindow::setBorder(TransparentSurface *source, bool active) {
 	 _borders = new TransparentSurface(*source);
-	 if (_borders)
-		 _macBorder.addInactiveBorder(_borders);
+	 if (active)
+		 _macBorder.addActiveBorder(_borders);
+	 else	
+		_macBorder.addInactiveBorder(_borders);
  }
 
 
diff --git a/graphics/macgui/macwindow.h b/graphics/macgui/macwindow.h
index 1181190..bffeaf7 100644
--- a/graphics/macgui/macwindow.h
+++ b/graphics/macgui/macwindow.h
@@ -138,7 +138,7 @@ public:
 	bool processEvent(Common::Event &event);
 	bool hasAllFocus() { return _beingDragged || _beingResized; }
 
-	void setBorders(TransparentSurface *source);
+	void setBorder(TransparentSurface *source, bool active);
 
 private:
 	void drawBorder();
@@ -155,7 +155,6 @@ private:
 	ManagedSurface _borderSurface;
 	ManagedSurface _composeSurface;
 
-	NinePatchBitmap *_bmp;
 	TransparentSurface *_borders;
 
 	MacWindowBorder _macBorder;
diff --git a/graphics/macgui/macwindowborder.cpp b/graphics/macgui/macwindowborder.cpp
index 7e64f1d..cbb2ef0 100644
--- a/graphics/macgui/macwindowborder.cpp
+++ b/graphics/macgui/macwindowborder.cpp
@@ -15,6 +15,8 @@ MacWindowBorder::~MacWindowBorder() {
 		delete _inactiveBorder;
 }
 
+bool MacWindowBorder::empty() { return !(_activeBorder || _inactiveBorder); }
+
 void MacWindowBorder::addActiveBorder(TransparentSurface *source) {
 	// Assumes NinePatchBitmap invariants hold
 	_activeBorder = new NinePatchBitmap(source, false);	
diff --git a/graphics/macgui/macwindowborder.h b/graphics/macgui/macwindowborder.h
index c956add..0c98e23 100644
--- a/graphics/macgui/macwindowborder.h
+++ b/graphics/macgui/macwindowborder.h
@@ -62,6 +62,7 @@ public:
 	MacWindowBorder();
 	~MacWindowBorder();
 
+	bool empty();
 	void addActiveBorder(TransparentSurface *source);
 	void addInactiveBorder(TransparentSurface *source);
 	void blitBorderInto(ManagedSurface &destination, bool active);


Commit: 1bfb1a561c61a30865ba5fadeb3cdb76831ad522
    https://github.com/scummvm/scummvm/commit/1bfb1a561c61a30865ba5fadeb3cdb76831ad522
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-07-31T14:45:36+02:00

Commit Message:
WAGE: Implement active/inactive borders

Changed paths:
    engines/wage/gui.cpp
    engines/wage/gui.h



diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp
index 4ef2cf8..35a8f28 100644
--- a/engines/wage/gui.cpp
+++ b/engines/wage/gui.cpp
@@ -170,7 +170,8 @@ Gui::Gui(WageEngine *engine) {
 	_consoleWindow->setCallback(consoleWindowCallback, this);
 
 	loadBorders();
-	_sceneWindow->setBorders(&_borders);
+	_sceneWindow->setBorder(_activeBorder, true);
+	_sceneWindow->setBorder(_inactiveBorder, false);
 }
 
 Gui::~Gui() {
@@ -368,7 +369,7 @@ void Gui::executeMenuCommand(int action, Common::String &text) {
 
 void Gui::loadBorders() {
 	Common::File borderfile;
-	if (!borderfile.open("border.bmp")) {
+	if (!borderfile.open("border_act.bmp")) {
 		debug(1, "Cannot open border file");
 		return;
 	}
@@ -380,19 +381,35 @@ void Gui::loadBorders() {
 	if (stream) {
 		bmpDecoder.loadStream(*stream);	
 		source = *(bmpDecoder.getSurface());
-		source.convertToInPlace(_borders.getSupportedPixelFormat(), bmpDecoder.getPalette());
-		_borders.create(source.w, source.h, source.format);
-		_borders.copyFrom(source);
-		_borders.applyColorKey(255, 0, 255, false);
+
+		_activeBorder = new Graphics::TransparentSurface();
+		source.convertToInPlace(_activeBorder->getSupportedPixelFormat(), bmpDecoder.getPalette());		
+		_activeBorder->create(source.w, source.h, source.format);
+		_activeBorder->copyFrom(source);
+		_activeBorder->applyColorKey(255, 0, 255, false);
 
 		delete stream;
+	}
 
-		//g_system->copyRectToScreen(source.getPixels(), source.pitch, 40, 0, source.w, source.h);
-		//g_system->copyRectToScreen(_borders.getPixels(), _borders.pitch, 40, 100, _borders.w, _borders.h);
-		//g_system->updateScreen();
+	if (!borderfile.open("border_inac.bmp")) {
+		debug(1, "Cannot open border file");
+		return;
 	}
+	
+	stream = borderfile.readStream(borderfile.size());
 
-	debug(1, "Hello");
+	if (stream) {
+		bmpDecoder.loadStream(*stream);
+		source = *(bmpDecoder.getSurface());
+
+		_inactiveBorder = new Graphics::TransparentSurface();
+		source.convertToInPlace(_inactiveBorder->getSupportedPixelFormat(), bmpDecoder.getPalette());
+		_inactiveBorder->create(source.w, source.h, source.format);
+		_inactiveBorder->copyFrom(source);
+		_inactiveBorder->applyColorKey(255, 0, 255, false);
+
+		delete stream;
+	}
 }
 
 } // End of namespace Wage
diff --git a/engines/wage/gui.h b/engines/wage/gui.h
index a72f469..a6a2526 100644
--- a/engines/wage/gui.h
+++ b/engines/wage/gui.h
@@ -154,6 +154,7 @@ private:
 	int calcTextX(int x, int textLine);
 	int calcTextY(int y);
 	void updateTextSelection(int x, int y);
+	
 	void loadBorders();
 
 public:
@@ -173,9 +174,10 @@ public:
 	Graphics::MacWindow *_sceneWindow;
 	Graphics::MacWindow *_consoleWindow;
 
-	Graphics::TransparentSurface _borders;
-
 private:
+	Graphics::TransparentSurface *_activeBorder;
+	Graphics::TransparentSurface *_inactiveBorder;
+
 	Graphics::ManagedSurface _console;
 	Graphics::Menu *_menu;
 	bool _sceneDirty;


Commit: f642ad1caec00295094fe89ded56a3302bafad2d
    https://github.com/scummvm/scummvm/commit/f642ad1caec00295094fe89ded56a3302bafad2d
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-07-31T14:45:37+02:00

Commit Message:
GRAPHICS: Refactor MacWindow to accept MacWindowBorder

Changed paths:
    graphics/macgui/macwindow.cpp
    graphics/macgui/macwindow.h
    graphics/macgui/macwindowborder.cpp
    graphics/macgui/macwindowborder.h



diff --git a/graphics/macgui/macwindow.cpp b/graphics/macgui/macwindow.cpp
index 3c9372a..96139b2 100644
--- a/graphics/macgui/macwindow.cpp
+++ b/graphics/macgui/macwindow.cpp
@@ -78,9 +78,6 @@ MacWindow::MacWindow(int id, bool scrollable, bool resizable, bool editable, Mac
 	_draggedX = _draggedY = 0;
 
 	_type = kWindowWindow;
-
-	_borders = nullptr;
-
 }
 
 MacWindow::~MacWindow() {
@@ -186,7 +183,7 @@ void MacWindow::drawBorder() {
 	ManagedSurface *g = &_borderSurface;
 	prepareBorderSurface(g);
 
-	if (!_macBorder.empty())
+	if (_macBorder.hasBorder(_active))
 		drawBorderFromSurface(g);
 	else
 		drawSimpleBorder(g);
@@ -203,12 +200,7 @@ void MacWindow::prepareBorderSurface(ManagedSurface *g) {
 }
 
 void MacWindow::drawBorderFromSurface(ManagedSurface *g) {
-
-	TransparentSurface srf;
-	srf.create(_borderSurface.w, _borderSurface.h, _borders->format);
-
 	_macBorder.blitBorderInto(_borderSurface, _active);
-	_borderSurface.transBlitFrom(srf, _borderSurface.format.ARGBToColor(0, 255, 255, 255));
 }
 
 void MacWindow::drawSimpleBorder(ManagedSurface *g) {
@@ -301,15 +293,13 @@ void MacWindow::setHighlight(WindowClick highlightedPart) {
 	_borderIsDirty = true;
  }
 
- void MacWindow::setBorder(TransparentSurface *source, bool active) {
-	 _borders = new TransparentSurface(*source);
+ void MacWindow::setBorder(TransparentSurface &border, bool active) {
 	 if (active)
-		 _macBorder.addActiveBorder(_borders);
-	 else	
-		_macBorder.addInactiveBorder(_borders);
+		 _macBorder.addActiveBorder(border);
+	 else
+		 _macBorder.addInactiveBorder(border);
  }
 
-
 void MacWindow::drawBox(ManagedSurface *g, int x, int y, int w, int h) {
 	Common::Rect r(x, y, x + w + 1, y + h + 1);
 
diff --git a/graphics/macgui/macwindow.h b/graphics/macgui/macwindow.h
index bffeaf7..e9e2ffd 100644
--- a/graphics/macgui/macwindow.h
+++ b/graphics/macgui/macwindow.h
@@ -138,7 +138,7 @@ public:
 	bool processEvent(Common::Event &event);
 	bool hasAllFocus() { return _beingDragged || _beingResized; }
 
-	void setBorder(TransparentSurface *source, bool active);
+	void setBorder(TransparentSurface &border, bool active);
 
 private:
 	void drawBorder();
@@ -155,8 +155,6 @@ private:
 	ManagedSurface _borderSurface;
 	ManagedSurface _composeSurface;
 
-	TransparentSurface *_borders;
-
 	MacWindowBorder _macBorder;
 
 	bool _scrollable;
diff --git a/graphics/macgui/macwindowborder.cpp b/graphics/macgui/macwindowborder.cpp
index cbb2ef0..761e1b6 100644
--- a/graphics/macgui/macwindowborder.cpp
+++ b/graphics/macgui/macwindowborder.cpp
@@ -2,9 +2,9 @@
 
 namespace Graphics {
 
-MacWindowBorder::MacWindowBorder() {
+MacWindowBorder::MacWindowBorder() : _activeInitialized(false), _inactiveInitialized(false) {
 	_activeBorder = nullptr;
-	_inactiveBorder = nullptr;
+	_inactiveBorder = nullptr;	
 }
 
 
@@ -15,15 +15,20 @@ MacWindowBorder::~MacWindowBorder() {
 		delete _inactiveBorder;
 }
 
-bool MacWindowBorder::empty() { return !(_activeBorder || _inactiveBorder); }
+bool MacWindowBorder::hasBorder(bool active) { 
+	return active ? _activeInitialized : _inactiveInitialized; 
+}
 
-void MacWindowBorder::addActiveBorder(TransparentSurface *source) {
-	// Assumes NinePatchBitmap invariants hold
-	_activeBorder = new NinePatchBitmap(source, false);	
+void MacWindowBorder::addActiveBorder(TransparentSurface &source) {
+	assert(!_activeBorder);
+	_activeBorder = new NinePatchBitmap(&source, false);	
+	_activeInitialized = true;
 }
 
-void MacWindowBorder::addInactiveBorder(TransparentSurface *source) {
-	_inactiveBorder = new NinePatchBitmap(source, false);
+void MacWindowBorder::addInactiveBorder(TransparentSurface &source) {
+	assert(!_inactiveBorder);
+	_inactiveBorder = new NinePatchBitmap(&source, false);
+	_inactiveInitialized = true;
 }
 
 void MacWindowBorder::blitBorderInto(ManagedSurface &destination, bool active) {
diff --git a/graphics/macgui/macwindowborder.h b/graphics/macgui/macwindowborder.h
index 0c98e23..1e46e1a 100644
--- a/graphics/macgui/macwindowborder.h
+++ b/graphics/macgui/macwindowborder.h
@@ -62,9 +62,9 @@ public:
 	MacWindowBorder();
 	~MacWindowBorder();
 
-	bool empty();
-	void addActiveBorder(TransparentSurface *source);
-	void addInactiveBorder(TransparentSurface *source);
+	bool hasBorder(bool active);
+	void addActiveBorder(TransparentSurface &source);
+	void addInactiveBorder(TransparentSurface &source);
 	void blitBorderInto(ManagedSurface &destination, bool active);
 
 private:
@@ -72,6 +72,9 @@ private:
 	NinePatchBitmap *_activeBorder;
 	NinePatchBitmap *_inactiveBorder;
 
+	bool _activeInitialized;
+	bool _inactiveInitialized;
+
 };
 
 } // End of namespace Graphics


Commit: 638e8e99c885722b0ab2d7ee62a7f840ddea1c1a
    https://github.com/scummvm/scummvm/commit/638e8e99c885722b0ab2d7ee62a7f840ddea1c1a
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-07-31T14:45:37+02:00

Commit Message:
WAGE: Change GUI Scene to load BMP borders

Changed paths:
    engines/wage/gui.cpp
    engines/wage/gui.h



diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp
index 35a8f28..0f47333 100644
--- a/engines/wage/gui.cpp
+++ b/engines/wage/gui.cpp
@@ -170,8 +170,7 @@ Gui::Gui(WageEngine *engine) {
 	_consoleWindow->setCallback(consoleWindowCallback, this);
 
 	loadBorders();
-	_sceneWindow->setBorder(_activeBorder, true);
-	_sceneWindow->setBorder(_inactiveBorder, false);
+	
 }
 
 Gui::~Gui() {
@@ -367,9 +366,15 @@ void Gui::executeMenuCommand(int action, Common::String &text) {
 	}
 }
 
-void Gui::loadBorders() {
+void Gui::loadBorders() {	
+	loadBorder(_sceneWindow, "border_inac.bmp", false);
+	loadBorder(_sceneWindow, "border_act.bmp", true);
+}
+
+void Gui::loadBorder(Graphics::MacWindow *target, Common::String filename, bool active) {
 	Common::File borderfile;
-	if (!borderfile.open("border_act.bmp")) {
+
+	if (!borderfile.open(filename)) {
 		debug(1, "Cannot open border file");
 		return;
 	}
@@ -377,36 +382,21 @@ void Gui::loadBorders() {
 	Image::BitmapDecoder bmpDecoder;
 	Common::SeekableReadStream *stream = borderfile.readStream(borderfile.size());
 	Graphics::Surface source;
+	Graphics::TransparentSurface *surface  = new Graphics::TransparentSurface();
 
 	if (stream) {
-		bmpDecoder.loadStream(*stream);	
+		debug(4, "Loading %s border from %s", (active ? "active" : "inactive"), filename);
+		bmpDecoder.loadStream(*stream);
 		source = *(bmpDecoder.getSurface());
 
-		_activeBorder = new Graphics::TransparentSurface();
-		source.convertToInPlace(_activeBorder->getSupportedPixelFormat(), bmpDecoder.getPalette());		
-		_activeBorder->create(source.w, source.h, source.format);
-		_activeBorder->copyFrom(source);
-		_activeBorder->applyColorKey(255, 0, 255, false);
-
-		delete stream;
-	}
-
-	if (!borderfile.open("border_inac.bmp")) {
-		debug(1, "Cannot open border file");
-		return;
-	}
-	
-	stream = borderfile.readStream(borderfile.size());
+		source.convertToInPlace(surface->getSupportedPixelFormat(), bmpDecoder.getPalette());
+		surface->create(source.w, source.h, source.format);
+		surface->copyFrom(source);
+		surface->applyColorKey(255, 0, 255, false);
 
-	if (stream) {
-		bmpDecoder.loadStream(*stream);
-		source = *(bmpDecoder.getSurface());
+		target->setBorder(*surface, active);
 
-		_inactiveBorder = new Graphics::TransparentSurface();
-		source.convertToInPlace(_inactiveBorder->getSupportedPixelFormat(), bmpDecoder.getPalette());
-		_inactiveBorder->create(source.w, source.h, source.format);
-		_inactiveBorder->copyFrom(source);
-		_inactiveBorder->applyColorKey(255, 0, 255, false);
+		borderfile.close();
 
 		delete stream;
 	}
diff --git a/engines/wage/gui.h b/engines/wage/gui.h
index a6a2526..898c7c3 100644
--- a/engines/wage/gui.h
+++ b/engines/wage/gui.h
@@ -54,6 +54,7 @@
 #include "graphics/macgui/macwindowmanager.h"
 #include "graphics/macgui/macwindow.h"
 #include "graphics/macgui/macmenu.h"
+#include "graphics/macgui/macwindowborder.h"
 
 #include "common/events.h"
 #include "common/rect.h"
@@ -156,6 +157,7 @@ private:
 	void updateTextSelection(int x, int y);
 	
 	void loadBorders();
+	void loadBorder(Graphics::MacWindow *target, Common::String filename, bool active);
 
 public:
 	Graphics::ManagedSurface _screen;
@@ -175,8 +177,6 @@ public:
 	Graphics::MacWindow *_consoleWindow;
 
 private:
-	Graphics::TransparentSurface *_activeBorder;
-	Graphics::TransparentSurface *_inactiveBorder;
 
 	Graphics::ManagedSurface _console;
 	Graphics::Menu *_menu;


Commit: fafd209d04f57680c141ea34f37f3a0f59080939
    https://github.com/scummvm/scummvm/commit/fafd209d04f57680c141ea34f37f3a0f59080939
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-07-31T14:45:37+02:00

Commit Message:
WAGE: Remove custom borders

Changed paths:
    engines/wage/gui.cpp



diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp
index 0f47333..6907679 100644
--- a/engines/wage/gui.cpp
+++ b/engines/wage/gui.cpp
@@ -13,7 +13,7 @@
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- 
+
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
@@ -170,7 +170,7 @@ Gui::Gui(WageEngine *engine) {
 	_consoleWindow->setCallback(consoleWindowCallback, this);
 
 	loadBorders();
-	
+
 }
 
 Gui::~Gui() {
@@ -231,7 +231,7 @@ void Gui::drawScene() {
 
 	_scene->paint(_sceneWindow->getSurface(), 0, 0);
 	_sceneWindow->setDirty(true);
-	
+
 	_sceneDirty = true;
 	_consoleDirty = true;
 	_menu->setDirty(true);
@@ -366,9 +366,10 @@ void Gui::executeMenuCommand(int action, Common::String &text) {
 	}
 }
 
-void Gui::loadBorders() {	
-	loadBorder(_sceneWindow, "border_inac.bmp", false);
-	loadBorder(_sceneWindow, "border_act.bmp", true);
+void Gui::loadBorders() {
+	// Do not load borders for now
+	//loadBorder(_sceneWindow, "border_inac.bmp", false);
+	//loadBorder(_sceneWindow, "border_act.bmp", true);
 }
 
 void Gui::loadBorder(Graphics::MacWindow *target, Common::String filename, bool active) {
@@ -394,7 +395,7 @@ void Gui::loadBorder(Graphics::MacWindow *target, Common::String filename, bool
 		surface->copyFrom(source);
 		surface->applyColorKey(255, 0, 255, false);
 
-		target->setBorder(*surface, active);
+		target->setBorder(*surface, active, 10, 10, 1, 1);
 
 		borderfile.close();
 


Commit: 3b1ba50c88931074184b63bc919cdaa47a749283
    https://github.com/scummvm/scummvm/commit/3b1ba50c88931074184b63bc919cdaa47a749283
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-07-31T14:47:19+02:00

Commit Message:
GRAPHICS: First approximation to custom border offsets

Changed paths:
    graphics/macgui/macwindow.cpp
    graphics/macgui/macwindow.h
    graphics/macgui/macwindowborder.cpp
    graphics/macgui/macwindowborder.h



diff --git a/graphics/macgui/macwindow.cpp b/graphics/macgui/macwindow.cpp
index 96139b2..3508784 100644
--- a/graphics/macgui/macwindow.cpp
+++ b/graphics/macgui/macwindow.cpp
@@ -78,6 +78,10 @@ MacWindow::MacWindow(int id, bool scrollable, bool resizable, bool editable, Mac
 	_draggedX = _draggedY = 0;
 
 	_type = kWindowWindow;
+
+	_closeable = false;
+
+	_borderWidth = kBorderWidth;
 }
 
 MacWindow::~MacWindow() {
@@ -174,7 +178,14 @@ static void drawPixelInverted(int x, int y, int color, void *data) {
 
 void MacWindow::updateInnerDims() {
 	_innerDims = _dims;
-	_innerDims.grow(-kBorderWidth);
+	if (_macBorder.hasBorder(_active) && _macBorder.hasOffsets()) {
+		int maxW = _innerDims.width() - _macBorder.getBorderOffset(kBorderOffsetLeft) - _macBorder.getBorderOffset(kBorderOffsetRight);
+		int maxH = _innerDims.width() - _macBorder.getBorderOffset(kBorderOffsetTop) - _macBorder.getBorderOffset(kBorderOffsetBottom);
+		_innerDims.clip(maxW, maxH);
+		_innerDims.translate(_macBorder.getBorderOffset(kBorderOffsetLeft), _macBorder.getBorderOffset(kBorderOffsetTop));
+	} else {
+		_innerDims.grow(-kBorderWidth);
+	}
 }
 
 void MacWindow::drawBorder() {
@@ -293,11 +304,14 @@ void MacWindow::setHighlight(WindowClick highlightedPart) {
 	_borderIsDirty = true;
  }
 
- void MacWindow::setBorder(TransparentSurface &border, bool active) {
+ void MacWindow::setBorder(TransparentSurface &border, bool active, int lo, int ro, int to, int bo) {
 	 if (active)
 		 _macBorder.addActiveBorder(border);
 	 else
 		 _macBorder.addInactiveBorder(border);
+
+		if (!_macBorder.hasOffsets())
+			_macBorder.setBorderOffsets(lo, ro, to, bo);
  }
 
 void MacWindow::drawBox(ManagedSurface *g, int x, int y, int w, int h) {
@@ -317,18 +331,18 @@ WindowClick MacWindow::isInBorder(int x, int y) {
 	if (_innerDims.contains(x, y))
 		return kBorderInner;
 
-	if (x >= _innerDims.left - kBorderWidth && x < _innerDims.left && y >= _innerDims.top - kBorderWidth && y < _innerDims.top)
+	if (x >= _innerDims.left - _borderWidth && x < _innerDims.left && y >= _innerDims.top - _borderWidth && y < _innerDims.top)
 		return kBorderCloseButton;
 
 	if (_resizable)
-		if (x >= _innerDims.right && x < _innerDims.right + kBorderWidth && y >= _innerDims.bottom && y < _innerDims.bottom + kBorderWidth)
+		if (x >= _innerDims.right && x < _innerDims.right + _borderWidth && y >= _innerDims.bottom && y < _innerDims.bottom + _borderWidth)
 			return kBorderResizeButton;
 
-	if (_scrollable && x >= _innerDims.right && x < _innerDims.right + kBorderWidth) {
-		if (y < _innerDims.top - kBorderWidth)
+	if (_scrollable && x >= _innerDims.right && x < _innerDims.right + _borderWidth) {
+		if (y < _innerDims.top - _borderWidth)
 			return kBorderBorder;
 
-		if (y >= _innerDims.bottom + kBorderWidth)
+		if (y >= _innerDims.bottom + _borderWidth)
 			return kBorderBorder;
 
 		if (y >= _innerDims.top + _innerDims.height() / 2)
@@ -356,8 +370,8 @@ bool MacWindow::processEvent(Common::Event &event) {
 		}
 
 		if (_beingResized) {
-			resize(MAX(kBorderWidth * 4, _dims.width()  + event.mouse.x - _draggedX),
-				   MAX(kBorderWidth * 4, _dims.height() + event.mouse.y - _draggedY));
+			resize(MAX(_borderWidth * 4, _dims.width()  + event.mouse.x - _draggedX),
+				   MAX(_borderWidth * 4, _dims.height() + event.mouse.y - _draggedY));
 
 			_draggedX = event.mouse.x;
 			_draggedY = event.mouse.y;
diff --git a/graphics/macgui/macwindow.h b/graphics/macgui/macwindow.h
index e9e2ffd..ce5cd1a 100644
--- a/graphics/macgui/macwindow.h
+++ b/graphics/macgui/macwindow.h
@@ -116,7 +116,7 @@ protected:
 
 	bool (*_callback)(WindowClick, Common::Event &, void *);
 	void *_dataPtr;
-	
+
 	MacWindowManager *_wm;
 };
 
@@ -130,7 +130,7 @@ public:
 	const Common::Rect &getInnerDimensions() { return _innerDims; }
 
 	bool draw(ManagedSurface *g, bool forceRedraw = false);
-	
+
 	void setActive(bool active);
 	void setTitle(Common::String &title) { _title = title; }
 	void setHighlight(WindowClick highlightedPart);
@@ -138,7 +138,7 @@ public:
 	bool processEvent(Common::Event &event);
 	bool hasAllFocus() { return _beingDragged || _beingResized; }
 
-	void setBorder(TransparentSurface &border, bool active);
+	void setBorder(TransparentSurface &border, bool active, int lo, int ro, int to, int bo);
 
 private:
 	void drawBorder();
@@ -149,7 +149,7 @@ private:
 	void fillRect(ManagedSurface *g, int x, int y, int w, int h, int color);
 	const Font *getTitleFont();
 	void updateInnerDims();
-	WindowClick isInBorder(int x, int y);	
+	WindowClick isInBorder(int x, int y);
 
 private:
 	ManagedSurface _borderSurface;
@@ -162,6 +162,10 @@ private:
 	bool _active;
 	bool _borderIsDirty;
 
+	bool _closeable;
+
+	int _borderWidth;
+
 	bool _beingDragged, _beingResized;
 	int _draggedX, _draggedY;
 
diff --git a/graphics/macgui/macwindowborder.cpp b/graphics/macgui/macwindowborder.cpp
index 761e1b6..b5fdcc3 100644
--- a/graphics/macgui/macwindowborder.cpp
+++ b/graphics/macgui/macwindowborder.cpp
@@ -4,7 +4,8 @@ namespace Graphics {
 
 MacWindowBorder::MacWindowBorder() : _activeInitialized(false), _inactiveInitialized(false) {
 	_activeBorder = nullptr;
-	_inactiveBorder = nullptr;	
+	_inactiveBorder = nullptr;
+	_hasOffsets = false;
 }
 
 
@@ -15,13 +16,13 @@ MacWindowBorder::~MacWindowBorder() {
 		delete _inactiveBorder;
 }
 
-bool MacWindowBorder::hasBorder(bool active) { 
-	return active ? _activeInitialized : _inactiveInitialized; 
+bool MacWindowBorder::hasBorder(bool active) {
+	return active ? _activeInitialized : _inactiveInitialized;
 }
 
 void MacWindowBorder::addActiveBorder(TransparentSurface &source) {
 	assert(!_activeBorder);
-	_activeBorder = new NinePatchBitmap(&source, false);	
+	_activeBorder = new NinePatchBitmap(&source, false);
 	_activeInitialized = true;
 }
 
@@ -31,6 +32,22 @@ void MacWindowBorder::addInactiveBorder(TransparentSurface &source) {
 	_inactiveInitialized = true;
 }
 
+bool MacWindowBorder::hasOffsets() {
+	return _hasOffsets;
+}
+
+void MacWindowBorder::setBorderOffsets(int left, int right, int top, int bottom) {
+	_borderOffsets[0] = left;
+	_borderOffsets[1] = right;
+	_borderOffsets[2] = top;
+	_borderOffsets[3] = bottom;
+	_hasOffsets = true;
+}
+
+int MacWindowBorder::getBorderOffset(MacBorderOffset offset) {
+	return _borderOffsets[offset];
+}
+
 void MacWindowBorder::blitBorderInto(ManagedSurface &destination, bool active) {
 
 	TransparentSurface srf;
diff --git a/graphics/macgui/macwindowborder.h b/graphics/macgui/macwindowborder.h
index 1e46e1a..f1d0d2c 100644
--- a/graphics/macgui/macwindowborder.h
+++ b/graphics/macgui/macwindowborder.h
@@ -57,6 +57,13 @@
 
 namespace Graphics {
 
+enum MacBorderOffset {
+	kBorderOffsetLeft = 0,
+	kBorderOffsetRight = 1,
+	kBorderOffsetTop = 2,
+	kBorderOffsetBottom	= 3
+};
+
 class MacWindowBorder {
 public:
 	MacWindowBorder();
@@ -65,6 +72,11 @@ public:
 	bool hasBorder(bool active);
 	void addActiveBorder(TransparentSurface &source);
 	void addInactiveBorder(TransparentSurface &source);
+
+	bool hasOffsets();
+	void setBorderOffsets(int left, int right, int top, int bottom);
+	int getBorderOffset(MacBorderOffset offset);
+
 	void blitBorderInto(ManagedSurface &destination, bool active);
 
 private:
@@ -75,8 +87,10 @@ private:
 	bool _activeInitialized;
 	bool _inactiveInitialized;
 
+	bool _hasOffsets;
+	int _borderOffsets[4];
+
 };
 
 } // End of namespace Graphics
 #endif
-


Commit: 2b586e7c5959c839323d24d1f788c9a836ece765
    https://github.com/scummvm/scummvm/commit/2b586e7c5959c839323d24d1f788c9a836ece765
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-07-31T14:47:22+02:00

Commit Message:
WAGE: Fallback to built-in borders

Changed paths:
    engines/wage/gui.cpp



diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp
index 6907679..a60395f 100644
--- a/engines/wage/gui.cpp
+++ b/engines/wage/gui.cpp
@@ -382,20 +382,9 @@ void Gui::loadBorder(Graphics::MacWindow *target, Common::String filename, bool
 
 	Image::BitmapDecoder bmpDecoder;
 	Common::SeekableReadStream *stream = borderfile.readStream(borderfile.size());
-	Graphics::Surface source;
-	Graphics::TransparentSurface *surface  = new Graphics::TransparentSurface();
-
 	if (stream) {
-		debug(4, "Loading %s border from %s", (active ? "active" : "inactive"), filename);
-		bmpDecoder.loadStream(*stream);
-		source = *(bmpDecoder.getSurface());
-
-		source.convertToInPlace(surface->getSupportedPixelFormat(), bmpDecoder.getPalette());
-		surface->create(source.w, source.h, source.format);
-		surface->copyFrom(source);
-		surface->applyColorKey(255, 0, 255, false);
 
-		target->setBorder(*surface, active, 10, 10, 1, 1);
+		target->loadBorder(*stream, active, 10, 10, 1, 1);
 
 		borderfile.close();
 


Commit: bc798d9ff4d46ba758fa2d225cdd741f4c94ff18
    https://github.com/scummvm/scummvm/commit/bc798d9ff4d46ba758fa2d225cdd741f4c94ff18
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-08-02T08:33:43+02:00

Commit Message:
GRAPHICS: Add custom border measures

Changed paths:
    graphics/macgui/macwindow.cpp
    graphics/macgui/macwindow.h
    graphics/macgui/macwindowborder.cpp
    graphics/macgui/macwindowborder.h
    graphics/macgui/macwindowmanager.cpp
    graphics/macgui/macwindowmanager.h
    graphics/nine_patch.cpp
    graphics/nine_patch.h



diff --git a/graphics/macgui/macwindow.cpp b/graphics/macgui/macwindow.cpp
index 3508784..e754f3c 100644
--- a/graphics/macgui/macwindow.cpp
+++ b/graphics/macgui/macwindow.cpp
@@ -50,6 +50,7 @@
 #include "common/events.h"
 #include "graphics/macgui/macwindowmanager.h"
 #include "graphics/macgui/macwindow.h"
+#include "image/bmp.h"
 
 namespace Graphics {
 
@@ -99,6 +100,8 @@ void MacWindow::setActive(bool active) {
 	_borderIsDirty = true;
 }
 
+bool MacWindow::isActive() { return _active; }
+
 void MacWindow::resize(int w, int h) {
 	if (_surface.w == w && _surface.h == h)
 		return;
@@ -177,13 +180,14 @@ static void drawPixelInverted(int x, int y, int color, void *data) {
 }
 
 void MacWindow::updateInnerDims() {
-	_innerDims = _dims;
 	if (_macBorder.hasBorder(_active) && _macBorder.hasOffsets()) {
-		int maxW = _innerDims.width() - _macBorder.getBorderOffset(kBorderOffsetLeft) - _macBorder.getBorderOffset(kBorderOffsetRight);
-		int maxH = _innerDims.width() - _macBorder.getBorderOffset(kBorderOffsetTop) - _macBorder.getBorderOffset(kBorderOffsetBottom);
-		_innerDims.clip(maxW, maxH);
-		_innerDims.translate(_macBorder.getBorderOffset(kBorderOffsetLeft), _macBorder.getBorderOffset(kBorderOffsetTop));
+		_innerDims = Common::Rect(
+			_dims.left + _macBorder.getOffset(kBorderOffsetLeft),
+			_dims.top + _macBorder.getOffset(kBorderOffsetTop),
+			_dims.right - _macBorder.getOffset(kBorderOffsetRight),
+			_dims.bottom - _macBorder.getOffset(kBorderOffsetBottom));
 	} else {
+		_innerDims = _dims;
 		_innerDims.grow(-kBorderWidth);
 	}
 }
@@ -192,12 +196,11 @@ void MacWindow::drawBorder() {
 	_borderIsDirty = false;
 
 	ManagedSurface *g = &_borderSurface;
-	prepareBorderSurface(g);
-
-	if (_macBorder.hasBorder(_active))
+	if (_macBorder.hasBorder(_active)) {
 		drawBorderFromSurface(g);
-	else
+	} else {
 		drawSimpleBorder(g);
+	}
 }
 
 void MacWindow::prepareBorderSurface(ManagedSurface *g) {
@@ -211,6 +214,11 @@ void MacWindow::prepareBorderSurface(ManagedSurface *g) {
 }
 
 void MacWindow::drawBorderFromSurface(ManagedSurface *g) {
+	g->clear(kColorGreen2);
+	Common::Rect inside = _innerDims;
+	inside.moveTo(_macBorder.getOffset(kBorderOffsetLeft), _macBorder.getOffset(kBorderOffsetTop));
+	g->fillRect(inside, kColorGreen);
+
 	_macBorder.blitBorderInto(_borderSurface, _active);
 }
 
@@ -223,6 +231,8 @@ void MacWindow::drawSimpleBorder(ManagedSurface *g) {
 	int width = _borderSurface.w;
 	int height = _borderSurface.h;
 
+	prepareBorderSurface(g);
+
 	drawBox(g, x,                    y,                     size,                 size);
 	drawBox(g, x + width - size - 1, y,                     size,                 size);
 	drawBox(g, x + width - size - 1, y + height - size - 1, size,                 size);
@@ -304,14 +314,33 @@ void MacWindow::setHighlight(WindowClick highlightedPart) {
 	_borderIsDirty = true;
  }
 
- void MacWindow::setBorder(TransparentSurface &border, bool active, int lo, int ro, int to, int bo) {
+ void MacWindow::loadBorder(Common::SeekableReadStream &file, bool active, int lo, int ro, int to, int bo) {
+
+	Image::BitmapDecoder bmpDecoder;
+	Graphics::Surface source;
+	Graphics::TransparentSurface *surface = new Graphics::TransparentSurface();
+
+	bmpDecoder.loadStream(file);
+	source = *(bmpDecoder.getSurface());
+
+	source.convertToInPlace(surface->getSupportedPixelFormat(), bmpDecoder.getPalette());
+	surface->create(source.w, source.h, source.format);
+	surface->copyFrom(source);
+	surface->applyColorKey(255, 0, 255, false);
+
 	 if (active)
-		 _macBorder.addActiveBorder(border);
+		 _macBorder.addActiveBorder(*surface);
 	 else
-		 _macBorder.addInactiveBorder(border);
+		 _macBorder.addInactiveBorder(*surface);
 
 		if (!_macBorder.hasOffsets())
-			_macBorder.setBorderOffsets(lo, ro, to, bo);
+			_macBorder.setOffsets(lo, ro, to, bo);
+
+		updateInnerDims();
+ }
+
+ void MacWindow::setCloseable(bool closeable) {
+	 _closeable = closeable;
  }
 
 void MacWindow::drawBox(ManagedSurface *g, int x, int y, int w, int h) {
@@ -331,18 +360,56 @@ WindowClick MacWindow::isInBorder(int x, int y) {
 	if (_innerDims.contains(x, y))
 		return kBorderInner;
 
-	if (x >= _innerDims.left - _borderWidth && x < _innerDims.left && y >= _innerDims.top - _borderWidth && y < _innerDims.top)
+	if (isInCloseButton(x, y))
 		return kBorderCloseButton;
 
 	if (_resizable)
-		if (x >= _innerDims.right && x < _innerDims.right + _borderWidth && y >= _innerDims.bottom && y < _innerDims.bottom + _borderWidth)
+		if (isInResizeButton(x, y))
 			return kBorderResizeButton;
 
-	if (_scrollable && x >= _innerDims.right && x < _innerDims.right + _borderWidth) {
-		if (y < _innerDims.top - _borderWidth)
+	if (_scrollable)
+	 	return isInScroll(x, y);
+
+	return kBorderBorder;
+}
+
+bool MacWindow::isInCloseButton(int x, int y) {
+	int bLeft = kBorderWidth;
+	int bTop = kBorderWidth;
+	if (_macBorder.hasOffsets()) {
+		bLeft = _macBorder.getOffset(kBorderOffsetLeft);
+		bTop = _macBorder.getOffset(kBorderOffsetTop);
+	}
+	return (x >= _innerDims.left - bLeft && x < _innerDims.left && y >= _innerDims.top - bTop && y < _innerDims.top);
+}
+
+bool MacWindow::isInResizeButton(int x, int y) {
+	int bRight = kBorderWidth;
+	int bBottom = kBorderWidth;
+	if (_macBorder.hasOffsets()) {
+		bRight = _macBorder.getOffset(kBorderOffsetRight);
+		bBottom = _macBorder.getOffset(kBorderOffsetBottom);
+	}
+	return (x >= _innerDims.right && x < _innerDims.right + bRight && y >= _innerDims.bottom && y < _innerDims.bottom + bBottom);
+}
+
+WindowClick MacWindow::isInScroll(int x, int y) {
+	int bLeft = kBorderWidth;
+	int bTop = kBorderWidth;
+	int bRight = kBorderWidth;
+	int bBottom = kBorderWidth;
+	if (_macBorder.hasOffsets()) {
+		bLeft = _macBorder.getOffset(kBorderOffsetLeft);
+		bTop = _macBorder.getOffset(kBorderOffsetTop);
+		bRight = _macBorder.getOffset(kBorderOffsetRight);
+		bBottom = _macBorder.getOffset(kBorderOffsetBottom);
+	}
+
+	if (x >= _innerDims.right && x < _innerDims.right + bRight) {
+		if (y < _innerDims.top - bTop)
 			return kBorderBorder;
 
-		if (y >= _innerDims.bottom + _borderWidth)
+		if (y >= _innerDims.bottom + bBottom)
 			return kBorderBorder;
 
 		if (y >= _innerDims.top + _innerDims.height() / 2)
@@ -351,6 +418,19 @@ WindowClick MacWindow::isInBorder(int x, int y) {
 		return kBorderScrollUp;
 	}
 
+	if (y >= _innerDims.bottom && y < _innerDims.bottom + bBottom) {
+		if (x < _innerDims.left - bTop)
+			return kBorderBorder;
+
+		if (x >= _innerDims.right + bRight)
+			return kBorderBorder;
+
+		if (x >= _innerDims.left + _innerDims.width() / 2)
+			return kBorderScrollRight;
+
+		return kBorderScrollLeft;
+	}
+
 	return kBorderBorder;
 }
 
@@ -397,6 +477,10 @@ bool MacWindow::processEvent(Common::Event &event) {
 			_draggedY = event.mouse.y;
 		}
 
+		if (click == kBorderCloseButton && _closeable) {
+			_wm->removeWindow(this);
+		}
+
 		break;
 	case Common::EVENT_LBUTTONUP:
 		_beingDragged = false;
diff --git a/graphics/macgui/macwindow.h b/graphics/macgui/macwindow.h
index ce5cd1a..763e215 100644
--- a/graphics/macgui/macwindow.h
+++ b/graphics/macgui/macwindow.h
@@ -75,6 +75,8 @@ namespace MacWindowConstants {
 		kBorderNone = 0,
 		kBorderScrollUp,
 		kBorderScrollDown,
+		kBorderScrollLeft,
+		kBorderScrollRight,
 		kBorderCloseButton,
 		kBorderInner,
 		kBorderBorder,
@@ -132,13 +134,18 @@ public:
 	bool draw(ManagedSurface *g, bool forceRedraw = false);
 
 	void setActive(bool active);
+	bool isActive();
+
 	void setTitle(Common::String &title) { _title = title; }
 	void setHighlight(WindowClick highlightedPart);
 	void setScroll(float scrollPos, float scrollSize);
 	bool processEvent(Common::Event &event);
 	bool hasAllFocus() { return _beingDragged || _beingResized; }
 
-	void setBorder(TransparentSurface &border, bool active, int lo, int ro, int to, int bo);
+	void loadBorder(Common::SeekableReadStream &file, bool active, int lo, int ro, int to, int bo);
+	//void setBorder(TransparentSurface &border, bool active);
+
+	void setCloseable(bool closeable);
 
 private:
 	void drawBorder();
@@ -151,6 +158,10 @@ private:
 	void updateInnerDims();
 	WindowClick isInBorder(int x, int y);
 
+	bool isInCloseButton(int x, int y);
+	bool isInResizeButton(int x, int y);
+	WindowClick isInScroll(int x, int y);
+
 private:
 	ManagedSurface _borderSurface;
 	ManagedSurface _composeSurface;
@@ -177,6 +188,8 @@ private:
 	Common::String _title;
 };
 
+
+
 } // End of namespace Graphics
 
 #endif
diff --git a/graphics/macgui/macwindowborder.cpp b/graphics/macgui/macwindowborder.cpp
index b5fdcc3..f5458cb 100644
--- a/graphics/macgui/macwindowborder.cpp
+++ b/graphics/macgui/macwindowborder.cpp
@@ -1,14 +1,20 @@
 #include "macwindowborder.h"
 
+#include "common/system.h"
+
+#include "graphics/macgui/macwindowmanager.h"
+
+
 namespace Graphics {
 
+using namespace Graphics::MacGUIConstants;
+
 MacWindowBorder::MacWindowBorder() : _activeInitialized(false), _inactiveInitialized(false) {
 	_activeBorder = nullptr;
 	_inactiveBorder = nullptr;
 	_hasOffsets = false;
 }
 
-
 MacWindowBorder::~MacWindowBorder() {
 	if (_activeBorder)
 		delete _activeBorder;
@@ -36,7 +42,7 @@ bool MacWindowBorder::hasOffsets() {
 	return _hasOffsets;
 }
 
-void MacWindowBorder::setBorderOffsets(int left, int right, int top, int bottom) {
+void MacWindowBorder::setOffsets(int left, int right, int top, int bottom) {
 	_borderOffsets[0] = left;
 	_borderOffsets[1] = right;
 	_borderOffsets[2] = top;
@@ -44,7 +50,7 @@ void MacWindowBorder::setBorderOffsets(int left, int right, int top, int bottom)
 	_hasOffsets = true;
 }
 
-int MacWindowBorder::getBorderOffset(MacBorderOffset offset) {
+int MacWindowBorder::getOffset(MacBorderOffset offset) {
 	return _borderOffsets[offset];
 }
 
@@ -53,10 +59,14 @@ void MacWindowBorder::blitBorderInto(ManagedSurface &destination, bool active) {
 	TransparentSurface srf;
 	NinePatchBitmap *src = active ? _activeBorder : _inactiveBorder;
 
-	srf.create(destination.w, destination.h, src->getSource()->format);
+	srf.create(destination.w, destination.h, destination.format);
+	srf.fillRect(Common::Rect(0, 0, srf.w, srf.h), kColorGreen2);
+
+	byte palette[kColorCount];
+	g_system->getPaletteManager()->grabPalette(palette, 0, kColorCount);
 
-	src->blit(srf, 0, 0, srf.w, srf.h);
-	destination.transBlitFrom(srf, destination.format.ARGBToColor(0, 255, 255, 255));
+	src->blit(srf, 0, 0, srf.w, srf.h, palette, kColorCount);
+	destination.transBlitFrom(srf, kColorGreen2);
 }
 
 } // End of namespace Graphics
diff --git a/graphics/macgui/macwindowborder.h b/graphics/macgui/macwindowborder.h
index f1d0d2c..3c41ef2 100644
--- a/graphics/macgui/macwindowborder.h
+++ b/graphics/macgui/macwindowborder.h
@@ -74,8 +74,8 @@ public:
 	void addInactiveBorder(TransparentSurface &source);
 
 	bool hasOffsets();
-	void setBorderOffsets(int left, int right, int top, int bottom);
-	int getBorderOffset(MacBorderOffset offset);
+	void setOffsets(int left, int right, int top, int bottom);
+	int getOffset(MacBorderOffset offset);
 
 	void blitBorderInto(ManagedSurface &destination, bool active);
 
diff --git a/graphics/macgui/macwindowmanager.cpp b/graphics/macgui/macwindowmanager.cpp
index da573e6..de94acf 100644
--- a/graphics/macgui/macwindowmanager.cpp
+++ b/graphics/macgui/macwindowmanager.cpp
@@ -184,6 +184,11 @@ void MacWindowManager::setActive(int id) {
     _fullRefresh = true;
 }
 
+void MacWindowManager::removeWindow(MacWindow *target) {
+	_windowsToRemove.push_back(target);
+	_needsRemoval = true;
+}
+
 struct PlotData {
 	Graphics::ManagedSurface *surface;
 	MacPatterns *patterns;
@@ -242,6 +247,8 @@ void MacWindowManager::drawDesktop() {
 void MacWindowManager::draw() {
     assert(_screen);
 
+		removeMarked();
+
 	if (_fullRefresh)
 		drawDesktop();
 
@@ -269,9 +276,9 @@ bool MacWindowManager::processEvent(Common::Event &event) {
 	if (_menu && _menu->processEvent(event))
 		return true;
 
-    if (event.type != Common::EVENT_MOUSEMOVE && event.type != Common::EVENT_LBUTTONDOWN &&
-            event.type != Common::EVENT_LBUTTONUP)
-        return false;
+  if (event.type != Common::EVENT_MOUSEMOVE && event.type != Common::EVENT_LBUTTONDOWN &&
+          event.type != Common::EVENT_LBUTTONUP)
+      return false;
 
 	if (_windows[_activeWindow]->isEditable() && _windows[_activeWindow]->getType() == kWindowWindow &&
 			((MacWindow *)_windows[_activeWindow])->getInnerDimensions().contains(event.mouse.x, event.mouse.y)) {
@@ -302,6 +309,42 @@ bool MacWindowManager::processEvent(Common::Event &event) {
     return false;
 }
 
+void MacWindowManager::removeMarked() {
+	if (!_needsRemoval) return;
+
+	Common::List<BaseMacWindow *>::const_iterator it;
+	for (it = _windowsToRemove.begin(); it != _windowsToRemove.end(); it++) {
+		removeFromStack(*it);
+		removeFromWindowList(*it);
+		delete *it;
+		_activeWindow = 0;
+		_fullRefresh = true;
+	}
+	_windowsToRemove.clear();
+	_needsRemoval = false;
+}
+
+void MacWindowManager::removeFromStack(BaseMacWindow *target) {
+	Common::List<BaseMacWindow *>::iterator stackIt;
+	for (stackIt = _windowStack.begin(); stackIt != _windowStack.end(); stackIt++) {
+		if (*stackIt == target) {
+			stackIt = _windowStack.erase(stackIt);
+			stackIt--;
+		}
+	}
+}
+
+void MacWindowManager::removeFromWindowList(BaseMacWindow *target) {
+	int size = _windows.size();
+	int ndx = 0;
+	for (int i = 0; i < size; i++) {
+		if (_windows[i] == target) {
+			ndx = i;
+		}
+	}
+	_windows.remove_at(ndx);
+}
+
 //////////////////////
 // Font stuff
 //////////////////////
diff --git a/graphics/macgui/macwindowmanager.h b/graphics/macgui/macwindowmanager.h
index 21bc381..c208089 100644
--- a/graphics/macgui/macwindowmanager.h
+++ b/graphics/macgui/macwindowmanager.h
@@ -56,7 +56,7 @@
 #include "graphics/fontman.h"
 #include "graphics/macgui/macwindow.h"
 
-namespace Graphics {	
+namespace Graphics {
 
 namespace MacGUIConstants {
 	enum {
@@ -68,7 +68,8 @@ namespace MacGUIConstants {
 		kColorGray = 1,
 		kColorWhite = 2,
 		kColorGreen = 3,
-		kColorGreen2 = 4
+		kColorGreen2 = 4,
+		kColorCount
 	};
 
 	enum {
@@ -98,6 +99,7 @@ public:
 	MacWindow *addWindow(bool scrollable, bool resizable, bool editable);
 	Menu *addMenu();
 	void setActive(int id);
+	void removeWindow(MacWindow *target);
 
 	void setFullRefresh(bool redraw) { _fullRefresh = true; }
 
@@ -117,12 +119,19 @@ private:
 	void drawDesktop();
 	void loadFonts();
 
+	void removeMarked();
+	void removeFromStack(BaseMacWindow *target);
+	void removeFromWindowList(BaseMacWindow *target);
+
 private:
 	ManagedSurface *_screen;
 
 	Common::List<BaseMacWindow *> _windowStack;
 	Common::Array<BaseMacWindow *> _windows;
 
+	Common::List<BaseMacWindow *> _windowsToRemove;
+	bool _needsRemoval;
+
 	int _lastId;
 	int _activeWindow;
 
diff --git a/graphics/nine_patch.cpp b/graphics/nine_patch.cpp
index 8ac6977..89c534f 100644
--- a/graphics/nine_patch.cpp
+++ b/graphics/nine_patch.cpp
@@ -48,6 +48,8 @@
 #include "graphics/transparent_surface.h"
 #include "graphics/nine_patch.h"
 
+#include "graphics/managed_surface.h"
+
 namespace Graphics {
 
 NinePatchSide::~NinePatchSide() {
@@ -201,7 +203,7 @@ bad_bitmap:
 	}
 }
 
-void NinePatchBitmap::blit(Graphics::Surface &target, int dx, int dy, int dw, int dh) {
+void NinePatchBitmap::blit(Graphics::Surface &target, int dx, int dy, int dw, int dh, byte *palette, byte numColors) {
 	/* don't draw bitmaps that are smaller than the fixed area */
 	if (dw < _h._fix || dh < _v._fix)
 		return;
@@ -223,15 +225,50 @@ void NinePatchBitmap::blit(Graphics::Surface &target, int dx, int dy, int dw, in
 		_cached_dh = dh;
 	}
 
+	/* Handle CLUT8 */
+	if (target.format.bytesPerPixel == 1) {
+		if (!palette)
+			warning("Trying to blit into a surface with 1bpp, you need the palette.");
+
+		Surface srf;
+		srf.create(target.w, target.h, _bmp->format);
+
+		drawRegions(srf, dx, dy, dw, dh);
+
+		byte black = getColorIndex(TS_RGB(0, 0, 0), palette);
+		byte white = getColorIndex(TS_RGB(255, 255, 255), palette);
+
+		for (uint i = 0; i < srf.w; ++i) {
+			for (uint j = 0; j < srf.h; ++j) {
+				uint32 color = *(uint32*)srf.getBasePtr(i, j);
+				if (color > 0) {
+					*((byte *)target.getBasePtr(i, j)) = closestGrayscale(color, palette, numColors);
+				}
+			}
+		}
+
+		return;
+	}
+
+	/* Else, draw regions normally */
+	drawRegions(target, dx, dy, dw, dh);
+}
+
+NinePatchBitmap::~NinePatchBitmap() {
+	if (_destroy_bmp)
+		delete _bmp;
+}
+
+void NinePatchBitmap::drawRegions(Graphics::Surface &target, int dx, int dy, int dw, int dh) {
 	/* draw each region */
 	for (uint i = 0; i < _v._m.size(); ++i) {
 		for (uint j = 0; j < _h._m.size(); ++j) {
 			Common::Rect r(_h._m[j]->offset, _v._m[i]->offset,
-						_h._m[j]->offset + _h._m[j]->length, _v._m[i]->offset + _v._m[i]->length);
+				_h._m[j]->offset + _h._m[j]->length, _v._m[i]->offset + _v._m[i]->length);
 
 			_bmp->blit(target, dx + _h._m[j]->dest_offset, dy + _v._m[i]->dest_offset,
-					Graphics::FLIP_NONE, &r, TS_ARGB(255, 255, 255, 255),
-					_h._m[j]->dest_length, _v._m[i]->dest_length);
+				Graphics::FLIP_NONE, &r, TS_ARGB(255, 255, 255, 255),
+				_h._m[j]->dest_length, _v._m[i]->dest_length);
 		}
 	}
 }
@@ -271,9 +308,47 @@ void NinePatchBitmap::blitClip(Graphics::Surface &target, Common::Rect clip, int
 	}
 }
 
-NinePatchBitmap::~NinePatchBitmap() {
-	if (_destroy_bmp)
-		delete _bmp;
+byte NinePatchBitmap::getColorIndex(uint32 target, byte* palette) {
+	byte *pal = palette;
+	uint i = 0;
+	uint32 color = TS_RGB(pal[0], pal[1], pal[2]);
+	while (color != target) {
+		i += 3;
+		color = TS_RGB(pal[i], pal[i + 1], pal[i + 2]);
+	}
+	return (i / 3);
+}
+
+uint32 NinePatchBitmap::grayscale(uint32 color) {
+	byte r, g, b;
+	_bmp->format.colorToRGB(color, r, g, b);
+	return grayscale(r, g, b);
+}
+
+uint32 NinePatchBitmap::grayscale(byte r, byte g, byte b) {
+	return (0.29 * r + 0.58 * g + 0.11 * b) / 3;
+}
+
+static inline uint32 dist(uint32 a, uint32 b) {
+	if (a > b)
+		return (a - b);
+
+	return b - a;
+}
+
+byte NinePatchBitmap::closestGrayscale(uint32 color, byte* palette, byte paletteLength) {
+	byte target = grayscale(color);
+	byte bestNdx = 0;
+	byte bestColor = grayscale(palette[0], palette[1], palette[2]);
+	for (byte i = 1; i < paletteLength; ++i) {
+		byte current = grayscale(palette[i * 3], palette[(i * 3) + 1], palette[(i * 3) + 2]);
+		if (dist(target, bestColor) >= dist(target, current)) {
+			bestColor = current;
+			bestNdx = i;
+		}
+	}
+
+	return bestNdx;
 }
 
 } // end of namespace Graphics
diff --git a/graphics/nine_patch.h b/graphics/nine_patch.h
index eaebac3..d0fc1af 100644
--- a/graphics/nine_patch.h
+++ b/graphics/nine_patch.h
@@ -86,15 +86,25 @@ public:
 	NinePatchBitmap(Graphics::TransparentSurface *bmp, bool owns_bitmap);
 	~NinePatchBitmap();
 
-	void blit(Graphics::Surface &target, int dx, int dy, int dw, int dh);
+	void blit(Graphics::Surface &target, int dx, int dy, int dw, int dh, byte *palette = NULL, byte numColours = 0);
 	void blitClip(Graphics::Surface &target, Common::Rect clip, int dx, int dy, int dw, int dh);
-
+		
 	int getWidth() { return _width; }
 	int getHeight() { return _height; }
 	int getMinWidth() { return _h._fix; }
 	int getMinHeight() { return _v._fix; }
 	Graphics::TransparentSurface *getSource() { return _bmp; }
 	Common::Rect &getPadding() { return _padding; }
+
+private:
+
+	void drawRegions(Graphics::Surface &target, int dx, int dy, int dw, int dh);
+
+	// Assumes color is in the palette
+	byte getColorIndex(uint32 target, byte *palette);
+	uint32 grayscale(uint32 color);
+	uint32 grayscale(byte r, byte g, byte b);
+	byte closestGrayscale(uint32 color, byte* palette, byte paletteLength);
 };
 
 } // end of namespace Graphics


Commit: 38f80f10f823d62bbefc25f81a7be8575eb505d6
    https://github.com/scummvm/scummvm/commit/38f80f10f823d62bbefc25f81a7be8575eb505d6
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-08-02T08:33:50+02:00

Commit Message:
WAGE: Remove leftover files

Changed paths:
  R engines/wage/macmenu.cpp
  R engines/wage/macwindowmanager.cpp



diff --git a/engines/wage/macmenu.cpp b/engines/wage/macmenu.cpp
deleted file mode 100644
index b776223..0000000
--- a/engines/wage/macmenu.cpp
+++ /dev/null
@@ -1,565 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * MIT License:
- *
- * Copyright (c) 2009 Alexei Svitkine, Eugene Sandulenko
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following
- * conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- */
-
-#include "common/system.h"
-#include "common/keyboard.h"
-
-#include "graphics/primitives.h"
-#include "graphics/font.h"
-#include "graphics/macgui/macwindowmanager.h"
-#include "graphics/macgui/macwindow.h"
-
-#include "wage/macmenu.h"
-
-namespace Graphics {
-
-enum {
-	kMenuHeight = 20,
-	kMenuLeftMargin = 7,
-	kMenuSpacing = 13,
-	kMenuPadding = 16,
-	kMenuDropdownPadding = 14,
-	kMenuDropdownItemHeight = 16,
-	kMenuItemHeight = 20
-};
-
-struct MenuSubItem {
-	Common::String text;
-	int action;
-	int style;
-	char shortcut;
-	bool enabled;
-	Common::Rect bbox;
-
-	MenuSubItem(const char *t, int a, int s = 0, char sh = 0, bool e = true) : text(t), action(a), style(s), shortcut(sh), enabled(e) {}
-};
-
-typedef Common::Array<MenuSubItem *> SubItemArray;
-
-struct MenuItem {
-	Common::String name;
-	SubItemArray subitems;
-	Common::Rect bbox;
-	Common::Rect subbbox;
-
-	MenuItem(const char *n) : name(n) {}
-};
-
-Menu::Menu(int id, const Common::Rect &bounds, MacWindowManager *wm)
-		: BaseMacWindow(id, false, wm) {
-	_font = getMenuFont();
-
-	_screen.create(bounds.width(), bounds.height(), PixelFormat::createFormatCLUT8());
-
-	_bbox.left = 0;
-	_bbox.top = 0;
-	_bbox.right = _screen.w;
-	_bbox.bottom = kMenuHeight;
-
-	_menuActivated = false;
-	_activeItem = -1;
-	_activeSubItem = -1;
-
-	_ccallback = NULL;
-	_cdata = NULL;
-
-	_tempSurface.create(_screen.w, _font->getFontHeight(), PixelFormat::createFormatCLUT8());
-}
-
-Menu::~Menu() {
-	for (uint i = 0; i < _items.size(); i++) {
-		for (uint j = 0; j < _items[i]->subitems.size(); j++)
-			delete _items[i]->subitems[j];
-		delete _items[i];
-	}
-}
-
-void Menu::addStaticMenus(const MenuData *data) {
-	MenuItem *about = new MenuItem(_wm->hasBuiltInFonts() ? "\xa9" : "\xf0"); // (c) Symbol as the most resembling apple
-	_items.push_back(about);
-
-	for (int i = 0; data[i].menunum; i++) {
-		const MenuData *m = &data[i];
-
-		if (m->menunum == kMenuHighLevel) {
-			MenuItem *item = new MenuItem(m->title);
-			_items.push_back(item);
-
-			continue;
-		}
-
-		_items[m->menunum]->subitems.push_back(new MenuSubItem(m->title, m->action, 0, m->shortcut, m->enabled));
-	}
-}
-
-int Menu::addMenuItem(const char *name) {
-	MenuItem *i = new MenuItem(name);
-	_items.push_back(i);
-
-	return _items.size() - 1;
-}
-
-void Menu::addMenuSubItem(int id, const char *text, int action, int style, char shortcut, bool enabled) {
-	_items[id]->subitems.push_back(new MenuSubItem(text, action, style, shortcut, enabled));
-
-	calcMenuBounds(_items[id]);
-}
-
-void Menu::calcDimensions() {
-	// Calculate menu dimensions
-	int y = 1;
-	int x = 18;
-
-	for (uint i = 0; i < _items.size(); i++) {
-		int w = _font->getStringWidth(_items[i]->name);
-
-		if (_items[i]->bbox.bottom == 0) {
-			_items[i]->bbox.left = x - kMenuLeftMargin;
-			_items[i]->bbox.top = y;
-			_items[i]->bbox.right = x + w + kMenuSpacing - kMenuLeftMargin;
-			_items[i]->bbox.bottom = y + _font->getFontHeight() + (_wm->hasBuiltInFonts() ? 3 : 2);
-		}
-
-		calcMenuBounds(_items[i]);
-
-		x += w + kMenuSpacing;
-	}
-}
-
-void Menu::clearSubMenu(int id) {
-	MenuItem *menu = _items[id];
-
-	for (uint j = 0; j < menu->subitems.size(); j++)
-		delete menu->subitems[j];
-
-	menu->subitems.clear();
-}
-
-void Menu::createSubMenuFromString(int id, const char *str) {
-	clearSubMenu(id);
-
-	MenuItem *menu = _items[id];
-	Common::String string(str);
-
-	Common::String item;
-
-	for (uint i = 0; i < string.size(); i++) {
-		while(i < string.size() && string[i] != ';') // Read token
-			item += string[i++];
-
-		if (item == "(-") {
-			menu->subitems.push_back(new MenuSubItem(NULL, 0));
-		} else {
-			bool enabled = true;
-			int style = 0;
-			char shortcut = 0;
-			const char *shortPtr = strrchr(item.c_str(), '/');
-			if (shortPtr != NULL) {
-				if (strlen(shortPtr) >= 2) {
-					shortcut = shortPtr[1];
-					item.deleteChar(shortPtr - item.c_str());
-					item.deleteChar(shortPtr - item.c_str());
-				} else {
-					error("Unexpected shortcut: '%s', item '%s' in menu '%s'", shortPtr, item.c_str(), string.c_str());
-				}
-			}
-
-			while (item.size() >= 2 && item[item.size() - 2] == '<') {
-				char c = item.lastChar();
-				if (c == 'B') {
-					style |= kFontStyleBold;
-				} else if (c == 'I') {
-					style |= kFontStyleItalic;
-				} else if (c == 'U') {
-					style |= kFontStyleUnderline;
-				} else if (c == 'O') {
-					style |= kFontStyleOutline;
-				} else if (c == 'S') {
-					style |= kFontStyleShadow;
-				} else if (c == 'C') {
-					style |= kFontStyleCondensed;
-				} else if (c == 'E') {
-					style |= kFontStyleExtended;
-				}
-				item.deleteLastChar();
-				item.deleteLastChar();
-			}
-
-			Common::String tmpitem(item);
-			tmpitem.trim();
-			if (tmpitem[0] == '(') {
-				enabled = false;
-
-				for (uint j = 0; j < item.size(); j++)
-					if (item[j] == '(') {
-						item.deleteChar(j);
-						break;
-					}
-			}
-
-			menu->subitems.push_back(new MenuSubItem(item.c_str(), kMenuActionCommand, style, shortcut, enabled));
-		}
-
-		item.clear();
-	}
-
-	calcMenuBounds(menu);
-}
-
-const Font *Menu::getMenuFont() {
-	return _wm->getFont("Chicago-12", FontManager::kBigGUIFont);
-}
-
-const char *Menu::getAcceleratorString(MenuSubItem *item, const char *prefix) {
-	static char res[20];
-	*res = 0;
-
-	if (item->shortcut != 0)
-		sprintf(res, "%s%c%c", prefix, (_wm->hasBuiltInFonts() ? '^' : '\x11'), item->shortcut);
-
-	return res;
-}
-
-int Menu::calculateMenuWidth(MenuItem *menu) {
-	int maxWidth = 0;
-	for (uint i = 0; i < menu->subitems.size(); i++) {
-		MenuSubItem *item = menu->subitems[i];
-		if (!item->text.empty()) {
-			Common::String text(item->text);
-			Common::String acceleratorText(getAcceleratorString(item, "  "));
-			if (!acceleratorText.empty()) {
-				text += acceleratorText;
-			}
-
-			int width = _font->getStringWidth(text);
-			if (width > maxWidth) {
-				maxWidth = width;
-			}
-		}
-	}
-	return maxWidth;
-}
-
-void Menu::calcMenuBounds(MenuItem *menu) {
-	// TODO: cache maxWidth
-	int maxWidth = calculateMenuWidth(menu);
-	int x1 = menu->bbox.left - 1;
-	int y1 = menu->bbox.bottom + 1;
-	int x2 = x1 + maxWidth + kMenuDropdownPadding * 2 - 4;
-	int y2 = y1 + menu->subitems.size() * kMenuDropdownItemHeight + 2;
-
-	menu->subbbox.left = x1;
-	menu->subbbox.top = y1;
-	menu->subbbox.right = x2;
-	menu->subbbox.bottom = y2;
-}
-
-static void drawPixelPlain(int x, int y, int color, void *data) {
-	ManagedSurface *surface = (ManagedSurface *)data;
-
-	if (x >= 0 && x < surface->w && y >= 0 && y < surface->h)
-		*((byte *)surface->getBasePtr(x, y)) = (byte)color;
-}
-
-static void drawFilledRoundRect(ManagedSurface *surface, Common::Rect &rect, int arc, int color) {
-	drawRoundRect(rect, arc, color, true, drawPixelPlain, surface);
-}
-
-bool Menu::draw(ManagedSurface *g, bool forceRedraw) {
-	Common::Rect r(_bbox);
-
-	if (!_contentIsDirty && !forceRedraw)
-		return false;
-
-	_contentIsDirty = false;
-
-	_screen.clear(kColorGreen);
-
-	drawFilledRoundRect(&_screen, r, kDesktopArc, kColorWhite);
-	r.top = 7;
-	_screen.fillRect(r, kColorWhite);
-	r.top = kMenuHeight - 1;
-	r.bottom++;
-	_screen.fillRect(r, kColorGreen);
-	r.bottom--;
-	_screen.fillRect(r, kColorBlack);
-
-	for (uint i = 0; i < _items.size(); i++) {
-		int color = kColorBlack;
-		MenuItem *it = _items[i];
-
-		if ((uint)_activeItem == i) {
-			Common::Rect hbox = it->bbox;
-
-			hbox.left -= 1;
-			hbox.right += 3;
-			hbox.bottom += 1;
-
-			_screen.fillRect(hbox, kColorBlack);
-			color = kColorWhite;
-
-			if (!it->subitems.empty())
-				renderSubmenu(it);
-		}
-
-		_font->drawString(&_screen, it->name, it->bbox.left + kMenuLeftMargin, it->bbox.top + (_wm->hasBuiltInFonts() ? 2 : 1), it->bbox.width(), color);
-	}
-
-	g->transBlitFrom(_screen, kColorGreen);
-
-	g_system->copyRectToScreen(g->getPixels(), g->pitch, 0, 0, g->w, g->h);
-
-	return true;
-}
-
-void Menu::renderSubmenu(MenuItem *menu) {
-	Common::Rect *r = &menu->subbbox;
-
-	if (r->width() == 0 || r->height() == 0)
-		return;
-
-	_screen.fillRect(*r, kColorWhite);
-	_screen.frameRect(*r, kColorBlack);
-	_screen.vLine(r->right, r->top + 3, r->bottom + 1, kColorBlack);
-	_screen.vLine(r->right + 1, r->top + 3, r->bottom + 1, kColorBlack);
-	_screen.hLine(r->left + 3, r->bottom, r->right + 1, kColorBlack);
-	_screen.hLine(r->left + 3, r->bottom + 1, r->right + 1, kColorBlack);
-
-	int x = r->left + kMenuDropdownPadding;
-	int y = r->top + 1;
-	for (uint i = 0; i < menu->subitems.size(); i++) {
-		Common::String text(menu->subitems[i]->text);
-		Common::String acceleratorText(getAcceleratorString(menu->subitems[i], ""));
-		int accelX = r->right - 25;
-
-		int color = kColorBlack;
-		if (i == (uint)_activeSubItem && !text.empty() && menu->subitems[i]->enabled) {
-			color = kColorWhite;
-			Common::Rect trect(r->left, y - (_wm->hasBuiltInFonts() ? 1 : 0), r->right, y + _font->getFontHeight());
-
-			_screen.fillRect(trect, kColorBlack);
-		}
-
-		if (!text.empty()) {
-			ManagedSurface *s = &_screen;
-			int tx = x, ty = y;
-
-			if (!menu->subitems[i]->enabled) {
-				s = &_tempSurface;
-				tx = 0;
-				ty = 0;
-				accelX -= x;
-
-				_tempSurface.clear(kColorGreen);
-			}
-
-			_font->drawString(s, text, tx, ty, r->width(), color);
-
-			if (!acceleratorText.empty())
-				_font->drawString(s, acceleratorText, accelX, ty, r->width(), color);
-
-			if (!menu->subitems[i]->enabled) {
-				// I am lazy to extend drawString() with plotProc as a parameter, so
-				// fake it here
-				for (int ii = 0; ii < _tempSurface.h; ii++) {
-					const byte *src = (const byte *)_tempSurface.getBasePtr(0, ii);
-					byte *dst = (byte *)_screen.getBasePtr(x, y+ii);
-					byte pat = _wm->getPatterns()[kPatternCheckers2 - 1][ii % 8];
-					for (int j = 0; j < r->width(); j++) {
-						if (*src != kColorGreen && (pat & (1 << (7 - (x + j) % 8))))
-							*dst = *src;
-						src++;
-						dst++;
-					}
-				}
-			}
-		} else { // Delimiter
-			bool flip = r->left & 2;
-			byte *ptr = (byte *)_screen.getBasePtr(r->left + 1, y + kMenuDropdownItemHeight / 2);
-			for (int xx = r->left + 1; xx <= r->right - 1; xx++, ptr++) {
-				*ptr = flip ? kColorBlack : kColorWhite;
-				flip = !flip;
-			}
-		}
-
-		y += kMenuDropdownItemHeight;
-	}
-
-	_contentIsDirty = true;
-	//g_system->copyRectToScreen(_screen.getBasePtr(r->left, r->top), _screen.pitch, r->left, r->top, r->width() + 2, r->height() + 2);
-}
-
-bool Menu::processEvent(Common::Event &event) {
-	switch (event.type) {
-	case Common::EVENT_KEYDOWN:
-		return keyEvent(event);
-	case Common::EVENT_LBUTTONDOWN:
-		return mouseClick(event.mouse.x, event.mouse.y);
-	case Common::EVENT_LBUTTONUP:
-		return mouseRelease(event.mouse.x, event.mouse.y);
-	case Common::EVENT_MOUSEMOVE:
-		return mouseMove(event.mouse.x, event.mouse.y);
-	default:
-		return false;
-	}
-}
-
-bool Menu::keyEvent(Common::Event &event) {
-	if (event.type != Common::EVENT_KEYDOWN)
-		return false;
-
-	if (event.kbd.flags & (Common::KBD_ALT | Common::KBD_CTRL | Common::KBD_META)) {
-		if (event.kbd.ascii >= 0x20 && event.kbd.ascii <= 0x7f) {
-			return processMenuShortCut(event.kbd.flags, event.kbd.ascii);
-		}
-	}
-
-	return false;
-}
-
-bool Menu::mouseClick(int x, int y) {
-	if (_bbox.contains(x, y)) {
-		for (uint i = 0; i < _items.size(); i++)
-			if (_items[i]->bbox.contains(x, y)) {
-			  if ((uint)_activeItem == i)
-					return false;
-
-				if (_activeItem != -1) { // Restore background
-					Common::Rect r(_items[_activeItem]->subbbox);
-					r.right += 3;
-					r.bottom += 3;
-
-					_wm->setFullRefresh(true);
-				}
-
-				_activeItem = i;
-				_activeSubItem = -1;
-				_menuActivated = true;
-
-				_contentIsDirty = true;
-
-				return true;
-			}
-	} else if (_menuActivated && _items[_activeItem]->subbbox.contains(x, y)) {
-		MenuItem *it = _items[_activeItem];
-		int numSubItem = (y - it->subbbox.top) / kMenuDropdownItemHeight;
-
-		if (numSubItem != _activeSubItem) {
-			_activeSubItem = numSubItem;
-
-			renderSubmenu(_items[_activeItem]);
-			_contentIsDirty = true;
-		}
-	} else if (_menuActivated && _activeItem != -1) {
-		_activeSubItem = -1;
-
-		renderSubmenu(_items[_activeItem]);
-		_contentIsDirty = true;
-	}
-
-	return false;
-}
-
-bool Menu::mouseMove(int x, int y) {
-	if (_menuActivated)
-		if (mouseClick(x, y))
-			return true;
-
-	return false;
-}
-
-bool Menu::mouseRelease(int x, int y) {
-	if (_menuActivated) {
-		_menuActivated = false;
-
-		if (_activeItem != -1 && _activeSubItem != -1 && _items[_activeItem]->subitems[_activeSubItem]->enabled)
-			(*_ccallback)(_items[_activeItem]->subitems[_activeSubItem]->action,
-					_items[_activeItem]->subitems[_activeSubItem]->text, _cdata);
-
-		_activeItem = -1;
-		_activeSubItem = -1;
-
-		_wm->setFullRefresh(true);
-
-		return true;
-	}
-
-	return false;
-}
-
-bool Menu::processMenuShortCut(byte flags, uint16 ascii) {
-	ascii = tolower(ascii);
-
-	if (flags & (Common::KBD_CTRL | Common::KBD_META)) {
-		for (uint i = 0; i < _items.size(); i++)
-			for (uint j = 0; j < _items[i]->subitems.size(); j++)
-				if (_items[i]->subitems[j]->enabled && tolower(_items[i]->subitems[j]->shortcut) == ascii) {
-					(*_ccallback)(_items[i]->subitems[j]->action, _items[i]->subitems[j]->text, _cdata);
-					return true;
-				}
-	}
-
-	return false;
-}
-
-void Menu::enableCommand(int menunum, int action, bool state) {
-	for (uint i = 0; i < _items[menunum]->subitems.size(); i++)
-		if (_items[menunum]->subitems[i]->action == action)
-			_items[menunum]->subitems[i]->enabled = state;
-
-	_contentIsDirty = true;
-}
-
-void Menu::disableAllMenus() {
-	for (uint i = 1; i < _items.size(); i++) // Leave About menu on
-		for (uint j = 0; j < _items[i]->subitems.size(); j++)
-			_items[i]->subitems[j]->enabled = false;
-
-	_contentIsDirty = true;
-}
-
-} // End of namespace Wage
diff --git a/engines/wage/macwindowmanager.cpp b/engines/wage/macwindowmanager.cpp
deleted file mode 100644
index 6ca2efd..0000000
--- a/engines/wage/macwindowmanager.cpp
+++ /dev/null
@@ -1,379 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * MIT License:
- *
- * Copyright (c) 2009 Alexei Svitkine, Eugene Sandulenko
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following
- * conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- */
-
-#include "common/array.h"
-#include "common/events.h"
-#include "common/list.h"
-#include "common/unzip.h"
-#include "common/system.h"
-#include "common/stream.h"
-
-#include "graphics/cursorman.h"
-#include "graphics/fonts/bdf.h"
-#include "graphics/managed_surface.h"
-#include "graphics/palette.h"
-#include "graphics/primitives.h"
-
-#include "wage/macwindowmanager.h"
-#include "wage/macwindow.h"
-#include "wage/macmenu.h"
-
-namespace Wage {
-
-static const byte palette[] = {
-	0, 0, 0,           // Black
-	0x80, 0x80, 0x80,  // Gray
-	0xff, 0xff, 0xff,  // White
-	0x00, 0xff, 0x00,  // Green
-	0x00, 0xcf, 0x00   // Green2
-};
-
-static byte fillPatterns[][8] = { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, // kPatternSolid
-								  { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 }, // kPatternStripes
-								  { 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55 }, // kPatternCheckers
-								  { 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa }  // kPatternCheckers2
-};
-
-static const byte macCursorArrow[] = {
-	2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3,
-	2, 0, 2, 3, 3, 3, 3, 3, 3, 3, 3,
-	2, 0, 0, 2, 3, 3, 3, 3, 3, 3, 3,
-	2, 0, 0, 0, 2, 3, 3, 3, 3, 3, 3,
-	2, 0, 0, 0, 0, 2, 3, 3, 3, 3, 3,
-	2, 0, 0, 0, 0, 0, 2, 3, 3, 3, 3,
-	2, 0, 0, 0, 0, 0, 0, 2, 3, 3, 3,
-	2, 0, 0, 0, 0, 0, 0, 0, 2, 3, 3,
-	2, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3,
-	2, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2,
-	2, 0, 0, 2, 0, 0, 2, 3, 3, 3, 3,
-	2, 0, 2, 3, 2, 0, 0, 2, 3, 3, 3,
-	2, 2, 3, 3, 2, 0, 0, 2, 3, 3, 3,
-	2, 3, 3, 3, 3, 2, 0, 0, 2, 3, 3,
-	3, 3, 3, 3, 3, 2, 0, 0, 2, 3, 3,
-	3, 3, 3, 3, 3, 3, 2, 2, 2, 3, 3
-};
-
-static const byte macCursorBeam[] = {
-	0, 0, 3, 3, 3, 0, 0, 3, 3, 3, 3,
-	3, 3, 0, 3, 0, 3, 3, 3, 3, 3, 3,
-	3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3,
-	3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3,
-	3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3,
-	3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3,
-	3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3,
-	3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3,
-	3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3,
-	3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3,
-	3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3,
-	3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3,
-	3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3,
-	3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3,
-	3, 3, 0, 3, 0, 3, 3, 3, 3, 3, 3,
-	0, 0, 3, 3, 3, 0, 0, 3, 3, 3, 3,
-};
-
-MacWindowManager::MacWindowManager() {
-	_screen = 0;
-	_lastId = 0;
-	_activeWindow = -1;
-
-	_menu = 0;
-
-	_fullRefresh = true;
-
-	_builtInFonts = true;
-
-	for (int i = 0; i < ARRAYSIZE(fillPatterns); i++)
-		_patterns.push_back(fillPatterns[i]);
-
-	loadFonts();
-
-	g_system->getPaletteManager()->setPalette(palette, 0, ARRAYSIZE(palette) / 3);
-
-	CursorMan.replaceCursorPalette(palette, 0, ARRAYSIZE(palette) / 3);
-	CursorMan.replaceCursor(macCursorArrow, 11, 16, 1, 1, 3);
-	_cursorIsArrow = true;
-	CursorMan.showMouse(true);
-}
-
-MacWindowManager::~MacWindowManager() {
-	for (int i = 0; i < _lastId; i++)
-		delete _windows[i];
-}
-
-MacWindow *MacWindowManager::addWindow(bool scrollable, bool resizable, bool editable) {
-	MacWindow *w = new MacWindow(_lastId, scrollable, resizable, editable, this);
-
-	_windows.push_back(w);
-	_windowStack.push_back(w);
-
-	setActive(_lastId);
-
-	_lastId++;
-
-	return w;
-}
-
-Menu *MacWindowManager::addMenu() {
-	_menu = new Menu(_lastId, _screen->getBounds(), this);
-
-	_windows.push_back(_menu);
-
-	_lastId++;
-
-	return _menu;
-}
-
-void MacWindowManager::setActive(int id) {
-	if (_activeWindow == id)
-		return;
-
-	if (_activeWindow != -1)
-		_windows[_activeWindow]->setActive(false);
-
-	_activeWindow = id;
-
-	_windows[id]->setActive(true);
-
-	_windowStack.remove(_windows[id]);
-	_windowStack.push_back(_windows[id]);
-
-	_fullRefresh = true;
-}
-
-struct PlotData {
-	Graphics::ManagedSurface *surface;
-	Patterns *patterns;
-	uint fillType;
-	int thickness;
-
-	PlotData(Graphics::ManagedSurface *s, Patterns *p, int f, int t) :
-		surface(s), patterns(p), fillType(f), thickness(t) {}
-};
-
-static void drawPixel(int x, int y, int color, void *data) {
-	PlotData *p = (PlotData *)data;
-
-	if (p->fillType > p->patterns->size())
-		return;
-
-	byte *pat = p->patterns->operator[](p->fillType - 1);
-
-	if (p->thickness == 1) {
-		if (x >= 0 && x < p->surface->w && y >= 0 && y < p->surface->h) {
-			uint xu = (uint)x; // for letting compiler optimize it
-			uint yu = (uint)y;
-
-			*((byte *)p->surface->getBasePtr(xu, yu)) =
-				(pat[yu % 8] & (1 << (7 - xu % 8))) ?
-					color : kColorWhite;
-		}
-	} else {
-		int x1 = x;
-		int x2 = x1 + p->thickness;
-		int y1 = y;
-		int y2 = y1 + p->thickness;
-
-		for (y = y1; y < y2; y++)
-			for (x = x1; x < x2; x++)
-				if (x >= 0 && x < p->surface->w && y >= 0 && y < p->surface->h) {
-					uint xu = (uint)x; // for letting compiler optimize it
-					uint yu = (uint)y;
-					*((byte *)p->surface->getBasePtr(xu, yu)) =
-						(pat[yu % 8] & (1 << (7 - xu % 8))) ?
-							color : kColorWhite;
-				}
-	}
-}
-
-void MacWindowManager::drawDesktop() {
-	Common::Rect r(_screen->getBounds());
-
-	PlotData pd(_screen, &_patterns, kPatternCheckers, 1);
-
-	Graphics::drawRoundRect(r, kDesktopArc, kColorBlack, true, drawPixel, &pd);
-
-	g_system->copyRectToScreen(_screen->getPixels(), _screen->pitch, 0, 0, _screen->w, _screen->h);
-}
-
-void MacWindowManager::draw() {
-	assert(_screen);
-
-	if (_fullRefresh)
-		drawDesktop();
-
-	for (Common::List<BaseMacWindow *>::const_iterator it = _windowStack.begin(); it != _windowStack.end(); it++) {
-		BaseMacWindow *w = *it;
-		if (w->draw(_screen, _fullRefresh)) {
-			w->setDirty(false);
-
-			Common::Rect clip(w->getDimensions().left - 2, w->getDimensions().top - 2, w->getDimensions().right - 2, w->getDimensions().bottom - 2);
-			clip.clip(_screen->getBounds());
-
-			g_system->copyRectToScreen(_screen->getBasePtr(clip.left, clip.top), _screen->pitch, clip.left, clip.top, clip.width(), clip.height());
-		}
-	}
-
-	// Menu is drawn on top of everything and always
-	if (_menu)
-		_menu->draw(_screen, _fullRefresh);
-
-	_fullRefresh = false;
-}
-
-bool MacWindowManager::processEvent(Common::Event &event) {
-	// Menu gets events first fir shortcuts and menu bar
-	if (_menu && _menu->processEvent(event))
-		return true;
-
-	if (event.type != Common::EVENT_MOUSEMOVE && event.type != Common::EVENT_LBUTTONDOWN &&
-			event.type != Common::EVENT_LBUTTONUP)
-		return false;
-
-	if (_windows[_activeWindow]->isEditable() && _windows[_activeWindow]->getType() == kWindowWindow &&
-			((MacWindow *)_windows[_activeWindow])->getInnerDimensions().contains(event.mouse.x, event.mouse.y)) {
-		if (_cursorIsArrow) {
-			CursorMan.replaceCursor(macCursorBeam, 11, 16, 3, 8, 3);
-			_cursorIsArrow = false;
-		}
-	} else {
-		if (_cursorIsArrow == false) {
-			CursorMan.replaceCursor(macCursorArrow, 11, 16, 1, 1, 3);
-			_cursorIsArrow = true;
-		}
-	}
-
-	for (Common::List<BaseMacWindow *>::const_iterator it = _windowStack.end(); it != _windowStack.begin();) {
-		it--;
-		BaseMacWindow *w = *it;
-
-		if (w->hasAllFocus() || w->getDimensions().contains(event.mouse.x, event.mouse.y)) {
-			if (event.type == Common::EVENT_LBUTTONDOWN || event.type == Common::EVENT_LBUTTONUP)
-				setActive(w->getId());
-
-			return w->processEvent(event);
-		}
-	}
-
-	return false;
-}
-
-//////////////////////
-// Font stuff
-//////////////////////
-void MacWindowManager::loadFonts() {
-	Common::Archive *dat;
-
-	dat = Common::makeZipArchive("classicmacfonts.dat");
-
-	if (!dat) {
-		warning("Could not find classicmacfonts.dat. Falling back to built-in fonts");
-		_builtInFonts = true;
-
-		return;
-	}
-
-	Common::ArchiveMemberList list;
-	dat->listMembers(list);
-
-	for (Common::ArchiveMemberList::iterator it = list.begin(); it != list.end(); ++it) {
-		Common::SeekableReadStream *stream = dat->createReadStreamForMember((*it)->getName());
-
-		Graphics::BdfFont *font = Graphics::BdfFont::loadFont(*stream);
-
-		delete stream;
-
-		Common::String fontName = (*it)->getName();
-
-		// Trim the .bdf extension
-		for (int i = fontName.size() - 1; i >= 0; --i) {
-			if (fontName[i] == '.') {
-				while ((uint)i < fontName.size()) {
-					fontName.deleteLastChar();
-				}
-				break;
-			}
-		}
-
-		FontMan.assignFontToName(fontName, font);
-
-		debug(2, " %s", fontName.c_str());
-	}
-
-	_builtInFonts = false;
-
-	delete dat;
-}
-
-const Graphics::Font *MacWindowManager::getFont(const char *name, Graphics::FontManager::FontUsage fallback) {
-	const Graphics::Font *font = 0;
-
-	if (!_builtInFonts) {
-		font = FontMan.getFontByName(name);
-
-		if (!font)
-			warning("Cannot load font %s", name);
-	}
-
-	if (_builtInFonts || !font)
-		font = FontMan.getFontByUsage(fallback);
-
-	return font;
-}
-
-/////////////////
-// Cursor stuff
-/////////////////
-void MacWindowManager::pushArrowCursor() {
-	CursorMan.pushCursor(macCursorArrow, 11, 16, 1, 1, 3);
-}
-
-void MacWindowManager::popCursor() {
-	CursorMan.popCursor();
-}
-
-} // End of namespace Wage


Commit: 7bc8d472ab879b49f9670cccc16fd0bf8bf0a6a7
    https://github.com/scummvm/scummvm/commit/7bc8d472ab879b49f9670cccc16fd0bf8bf0a6a7
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-08-02T08:33:50+02:00

Commit Message:
GRAPHICS: Fix style and spelling

Changed paths:
    graphics/macgui/macwindow.cpp
    graphics/nine_patch.h



diff --git a/graphics/macgui/macwindow.cpp b/graphics/macgui/macwindow.cpp
index e754f3c..1b4ed01 100644
--- a/graphics/macgui/macwindow.cpp
+++ b/graphics/macgui/macwindow.cpp
@@ -196,6 +196,7 @@ void MacWindow::drawBorder() {
 	_borderIsDirty = false;
 
 	ManagedSurface *g = &_borderSurface;
+
 	if (_macBorder.hasBorder(_active)) {
 		drawBorderFromSurface(g);
 	} else {
@@ -303,19 +304,18 @@ void MacWindow::setHighlight(WindowClick highlightedPart) {
 
 	_highlightedPart = highlightedPart;
 	_borderIsDirty = true;
- }
+}
 
- void MacWindow::setScroll(float scrollPos, float scrollSize) {
+void MacWindow::setScroll(float scrollPos, float scrollSize) {
 	if (_scrollPos == scrollPos && _scrollSize == scrollSize)
 		return;
 
 	_scrollPos = scrollPos;
 	_scrollSize = scrollSize;
 	_borderIsDirty = true;
- }
-
- void MacWindow::loadBorder(Common::SeekableReadStream &file, bool active, int lo, int ro, int to, int bo) {
+}
 
+void MacWindow::loadBorder(Common::SeekableReadStream &file, bool active, int lo, int ro, int to, int bo) {
 	Image::BitmapDecoder bmpDecoder;
 	Graphics::Surface source;
 	Graphics::TransparentSurface *surface = new Graphics::TransparentSurface();
@@ -328,20 +328,20 @@ void MacWindow::setHighlight(WindowClick highlightedPart) {
 	surface->copyFrom(source);
 	surface->applyColorKey(255, 0, 255, false);
 
-	 if (active)
-		 _macBorder.addActiveBorder(*surface);
-	 else
-		 _macBorder.addInactiveBorder(*surface);
+	if (active)
+		_macBorder.addActiveBorder(*surface);
+	else
+		_macBorder.addInactiveBorder(*surface);
 
-		if (!_macBorder.hasOffsets())
-			_macBorder.setOffsets(lo, ro, to, bo);
+	if (!_macBorder.hasOffsets())
+		_macBorder.setOffsets(lo, ro, to, bo);
 
-		updateInnerDims();
- }
+	updateInnerDims();
+}
 
- void MacWindow::setCloseable(bool closeable) {
-	 _closeable = closeable;
- }
+void MacWindow::setCloseable(bool closeable) {
+	_closeable = closeable;
+}
 
 void MacWindow::drawBox(ManagedSurface *g, int x, int y, int w, int h) {
 	Common::Rect r(x, y, x + w + 1, y + h + 1);
diff --git a/graphics/nine_patch.h b/graphics/nine_patch.h
index d0fc1af..b40f3bf 100644
--- a/graphics/nine_patch.h
+++ b/graphics/nine_patch.h
@@ -51,8 +51,8 @@
 
 namespace Graphics {
 
-	class TransparentSurface;
-	class Surface;
+class TransparentSurface;
+class Surface;
 
 struct NinePatchMark {
 	int offset;
@@ -86,7 +86,7 @@ public:
 	NinePatchBitmap(Graphics::TransparentSurface *bmp, bool owns_bitmap);
 	~NinePatchBitmap();
 
-	void blit(Graphics::Surface &target, int dx, int dy, int dw, int dh, byte *palette = NULL, byte numColours = 0);
+	void blit(Graphics::Surface &target, int dx, int dy, int dw, int dh, byte *palette = NULL, byte numColors = 0);
 	void blitClip(Graphics::Surface &target, Common::Rect clip, int dx, int dy, int dw, int dh);
 		
 	int getWidth() { return _width; }


Commit: f92873ae3766c31cfd46fdd84da1ba62a1d7ea82
    https://github.com/scummvm/scummvm/commit/f92873ae3766c31cfd46fdd84da1ba62a1d7ea82
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-08-02T08:33:50+02:00

Commit Message:
GRAPHICS: Add missing file header

Changed paths:
    graphics/macgui/macwindowborder.cpp



diff --git a/graphics/macgui/macwindowborder.cpp b/graphics/macgui/macwindowborder.cpp
index f5458cb..76bba9e 100644
--- a/graphics/macgui/macwindowborder.cpp
+++ b/graphics/macgui/macwindowborder.cpp
@@ -1,3 +1,50 @@
+/* ScummVM - Graphic Adventure Engine
+*
+* ScummVM is the legal property of its developers, whose names
+* are too numerous to list here. Please refer to the COPYRIGHT
+* file distributed with this source distribution.
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*
+* MIT License:
+*
+* Copyright (c) 2016 Borja Lorente
+*
+* Permission is hereby granted, free of charge, to any person
+* obtaining a copy of this software and associated documentation
+* files (the "Software"), to deal in the Software without
+* restriction, including without limitation the rights to use,
+* copy, modify, merge, publish, distribute, sublicense, and/or sell
+* copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following
+* conditions:
+*
+* The above copyright notice and this permission notice shall be
+* included in all copies or substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+* OTHER DEALINGS IN THE SOFTWARE.
+*
+*/
+
 #include "macwindowborder.h"
 
 #include "common/system.h"


Commit: 95beba7b6398c2ab14deb6ab4d1f65c9e820849c
    https://github.com/scummvm/scummvm/commit/95beba7b6398c2ab14deb6ab4d1f65c9e820849c
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-08-02T08:33:50+02:00

Commit Message:
GRAPHICS: Fix spacing issues in MacWindowManager

Changed paths:
    graphics/macgui/macwindowmanager.cpp



diff --git a/graphics/macgui/macwindowmanager.cpp b/graphics/macgui/macwindowmanager.cpp
index de94acf..9d3b729 100644
--- a/graphics/macgui/macwindowmanager.cpp
+++ b/graphics/macgui/macwindowmanager.cpp
@@ -116,9 +116,9 @@ static const byte macCursorBeam[] = {
 };
 
 MacWindowManager::MacWindowManager() {
-    _screen = 0;
-    _lastId = 0;
-    _activeWindow = -1;
+	_screen = 0;
+	_lastId = 0;
+	_activeWindow = -1;
 
 	_menu = 0;
 
@@ -140,21 +140,21 @@ MacWindowManager::MacWindowManager() {
 }
 
 MacWindowManager::~MacWindowManager() {
-    for (int i = 0; i < _lastId; i++)
-        delete _windows[i];
+	for (int i = 0; i < _lastId; i++)
+		delete _windows[i];
 }
 
 MacWindow *MacWindowManager::addWindow(bool scrollable, bool resizable, bool editable) {
 	MacWindow *w = new MacWindow(_lastId, scrollable, resizable, editable, this);
 
-    _windows.push_back(w);
-    _windowStack.push_back(w);
+	_windows.push_back(w);
+	_windowStack.push_back(w);
 
-    setActive(_lastId);
+	setActive(_lastId);
 
-    _lastId++;
+	_lastId++;
 
-    return w;
+	return w;
 }
 
 Menu *MacWindowManager::addMenu() {
@@ -168,20 +168,20 @@ Menu *MacWindowManager::addMenu() {
 }
 
 void MacWindowManager::setActive(int id) {
-    if (_activeWindow == id)
-        return;
+	if (_activeWindow == id)
+		return;
 
-    if (_activeWindow != -1)
-        _windows[_activeWindow]->setActive(false);
+	if (_activeWindow != -1)
+		_windows[_activeWindow]->setActive(false);
 
-    _activeWindow = id;
+	_activeWindow = id;
 
-    _windows[id]->setActive(true);
+	_windows[id]->setActive(true);
 
-    _windowStack.remove(_windows[id]);
-    _windowStack.push_back(_windows[id]);
+	_windowStack.remove(_windows[id]);
+	_windowStack.push_back(_windows[id]);
 
-    _fullRefresh = true;
+	_fullRefresh = true;
 }
 
 void MacWindowManager::removeWindow(MacWindow *target) {
@@ -245,30 +245,30 @@ void MacWindowManager::drawDesktop() {
 }
 
 void MacWindowManager::draw() {
-    assert(_screen);
+	assert(_screen);
 
-		removeMarked();
+	removeMarked();
 
 	if (_fullRefresh)
 		drawDesktop();
 
-    for (Common::List<BaseMacWindow *>::const_iterator it = _windowStack.begin(); it != _windowStack.end(); it++) {
+	for (Common::List<BaseMacWindow *>::const_iterator it = _windowStack.begin(); it != _windowStack.end(); it++) {
 		BaseMacWindow *w = *it;
-        if (w->draw(_screen, _fullRefresh)) {
-            w->setDirty(false);
+		if (w->draw(_screen, _fullRefresh)) {
+			w->setDirty(false);
 
 			Common::Rect clip(w->getDimensions().left - 2, w->getDimensions().top - 2, w->getDimensions().right - 2, w->getDimensions().bottom - 2);
 			clip.clip(_screen->getBounds());
 
-            g_system->copyRectToScreen(_screen->getBasePtr(clip.left, clip.top), _screen->pitch, clip.left, clip.top, clip.width(), clip.height());
-        }
-    }
+			g_system->copyRectToScreen(_screen->getBasePtr(clip.left, clip.top), _screen->pitch, clip.left, clip.top, clip.width(), clip.height());
+		}
+	}
 
 	// Menu is drawn on top of everything and always
 	if (_menu)
 		_menu->draw(_screen, _fullRefresh);
 
-    _fullRefresh = false;
+	_fullRefresh = false;
 }
 
 bool MacWindowManager::processEvent(Common::Event &event) {
@@ -276,9 +276,9 @@ bool MacWindowManager::processEvent(Common::Event &event) {
 	if (_menu && _menu->processEvent(event))
 		return true;
 
-  if (event.type != Common::EVENT_MOUSEMOVE && event.type != Common::EVENT_LBUTTONDOWN &&
-          event.type != Common::EVENT_LBUTTONUP)
-      return false;
+	if (event.type != Common::EVENT_MOUSEMOVE && event.type != Common::EVENT_LBUTTONDOWN &&
+			event.type != Common::EVENT_LBUTTONUP)
+		return false;
 
 	if (_windows[_activeWindow]->isEditable() && _windows[_activeWindow]->getType() == kWindowWindow &&
 			((MacWindow *)_windows[_activeWindow])->getInnerDimensions().contains(event.mouse.x, event.mouse.y)) {
@@ -293,20 +293,20 @@ bool MacWindowManager::processEvent(Common::Event &event) {
 		}
 	}
 
-    for (Common::List<BaseMacWindow *>::const_iterator it = _windowStack.end(); it != _windowStack.begin();) {
-        it--;
+	for (Common::List<BaseMacWindow *>::const_iterator it = _windowStack.end(); it != _windowStack.begin();) {
+		it--;
 		BaseMacWindow *w = *it;
 
 
-        if (w->hasAllFocus() || w->getDimensions().contains(event.mouse.x, event.mouse.y)) {
-            if (event.type == Common::EVENT_LBUTTONDOWN || event.type == Common::EVENT_LBUTTONUP)
-                setActive(w->getId());
+		if (w->hasAllFocus() || w->getDimensions().contains(event.mouse.x, event.mouse.y)) {
+			if (event.type == Common::EVENT_LBUTTONDOWN || event.type == Common::EVENT_LBUTTONUP)
+				setActive(w->getId());
 
-            return w->processEvent(event);
-        }
-    }
+			return w->processEvent(event);
+		}
+	}
 
-    return false;
+	return false;
 }
 
 void MacWindowManager::removeMarked() {


Commit: da33e52539b79629dd51b44fb1bc7e713c265f24
    https://github.com/scummvm/scummvm/commit/da33e52539b79629dd51b44fb1bc7e713c265f24
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-08-02T08:33:50+02:00

Commit Message:
GRAPHICS: Reorder modules to preserve alphabetical order

Changed paths:
    graphics/module.mk



diff --git a/graphics/module.mk b/graphics/module.mk
index 1af6d28..f0f5af6 100644
--- a/graphics/module.mk
+++ b/graphics/module.mk
@@ -12,6 +12,10 @@ MODULE_OBJS := \
 	fonts/ttf.o \
 	fonts/winfont.o \
 	maccursor.o \
+	macgui/macmenu.o \
+	macgui/macwindow.o \
+	macgui/macwindowborder.o \
+	macgui/macwindowmanager.o\
 	managed_surface.o \
 	nine_patch.o \
 	pixelformat.o \
@@ -28,11 +32,7 @@ MODULE_OBJS := \
 	VectorRenderer.o \
 	VectorRendererSpec.o \
 	wincursor.o \
-	yuv_to_rgb.o \
-	macgui/macwindowmanager.o\
-	macgui/macwindow.o \
-	macgui/macmenu.o \
-	macgui/macwindowborder.o
+	yuv_to_rgb.o
 
 ifdef USE_SCALERS
 MODULE_OBJS += \


Commit: f7ba1cb812afc2bb508018b46dd0aaa4572a6bdc
    https://github.com/scummvm/scummvm/commit/f7ba1cb812afc2bb508018b46dd0aaa4572a6bdc
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-08-02T08:33:50+02:00

Commit Message:
GRAPHICS: Rename header guards in macgui

Changed paths:
    graphics/macgui/macmenu.h
    graphics/macgui/macwindow.h
    graphics/macgui/macwindowborder.h
    graphics/macgui/macwindowmanager.h



diff --git a/graphics/macgui/macmenu.h b/graphics/macgui/macmenu.h
index 5c08f4f..7114066 100644
--- a/graphics/macgui/macmenu.h
+++ b/graphics/macgui/macmenu.h
@@ -45,8 +45,8 @@
  *
  */
 
-#ifndef GRAPHICS_MACMENU_H
-#define GRAPHICS_MACMENU_H
+#ifndef GRAPHICS_MACGUI_MACMENU_H
+#define GRAPHICS_MACGUI_MACMENU_H
 
 namespace Graphics {
 
diff --git a/graphics/macgui/macwindow.h b/graphics/macgui/macwindow.h
index 763e215..285a9e9 100644
--- a/graphics/macgui/macwindow.h
+++ b/graphics/macgui/macwindow.h
@@ -45,8 +45,8 @@
  *
  */
 
-#ifndef GRAPHICS_MACWINDOW_H
-#define GRAPHICS_MACWINDOW_H
+#ifndef GRAPHICS_MACGUI_MACWINDOW_H
+#define GRAPHICS_MACGUI_MACWINDOW_H
 
 #include "graphics/managed_surface.h"
 #include "graphics/transparent_surface.h"
diff --git a/graphics/macgui/macwindowborder.h b/graphics/macgui/macwindowborder.h
index 3c41ef2..295f554 100644
--- a/graphics/macgui/macwindowborder.h
+++ b/graphics/macgui/macwindowborder.h
@@ -45,8 +45,8 @@
 *
 */
 
-#ifndef GRAPHICS_MACWINDOWBORDER_H
-#define GRAPHICS_MACWINDOWBORDER_H
+#ifndef GRAPHICS_MACGUI_MACWINDOWBORDER_H
+#define GRAPHICS_MACGUI_MACWINDOWBORDER_H
 
 #include "common/str.h"
 #include "common/list.h"
diff --git a/graphics/macgui/macwindowmanager.h b/graphics/macgui/macwindowmanager.h
index c208089..2d8a6a3 100644
--- a/graphics/macgui/macwindowmanager.h
+++ b/graphics/macgui/macwindowmanager.h
@@ -45,8 +45,8 @@
  *
  */
 
-#ifndef GRAPHICS_MACWINDOWMANAGER_H
-#define GRAPHICS_MACWINDOWMANAGER_H
+#ifndef GRAPHICS_MACGUI_MACWINDOWMANAGER_H
+#define GRAPHICS_MACGUI_MACWINDOWMANAGER_H
 
 #include "common/array.h"
 #include "common/list.h"


Commit: 6d8b6ad4f82dbb1d81d201d7def2572e84a159b3
    https://github.com/scummvm/scummvm/commit/6d8b6ad4f82dbb1d81d201d7def2572e84a159b3
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-08-02T08:33:50+02:00

Commit Message:
GRAPHICS: Fix include path in macwindowborder

Changed paths:
    graphics/macgui/macwindowborder.cpp



diff --git a/graphics/macgui/macwindowborder.cpp b/graphics/macgui/macwindowborder.cpp
index 76bba9e..b77fa35 100644
--- a/graphics/macgui/macwindowborder.cpp
+++ b/graphics/macgui/macwindowborder.cpp
@@ -45,13 +45,11 @@
 *
 */
 
-#include "macwindowborder.h"
-
 #include "common/system.h"
 
+#include "graphics/macgui/macwindowborder.h"
 #include "graphics/macgui/macwindowmanager.h"
 
-
 namespace Graphics {
 
 using namespace Graphics::MacGUIConstants;


Commit: a0bea8567b9f0d8751815ecbfab0c952fd7b80b7
    https://github.com/scummvm/scummvm/commit/a0bea8567b9f0d8751815ecbfab0c952fd7b80b7
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-08-02T08:33:50+02:00

Commit Message:
WAGE: Revert indentation

Changed paths:
    engines/wage/design.cpp
    engines/wage/gui.cpp



diff --git a/engines/wage/design.cpp b/engines/wage/design.cpp
index ef50a28..86b325e 100644
--- a/engines/wage/design.cpp
+++ b/engines/wage/design.cpp
@@ -102,7 +102,7 @@ void Design::paint(Graphics::ManagedSurface *surface, Graphics::MacPatterns &pat
 		_surface->create(_bounds->width(), _bounds->height(), Graphics::PixelFormat::createFormatCLUT8());
 
 		_surface->clear(kColorGreen);
-		
+
 		needRender = true;
 	}
 
@@ -265,7 +265,7 @@ void drawPixelPlain(int x, int y, int color, void *data) {
 }
 
 void Design::drawRect(Graphics::ManagedSurface *surface, Common::ReadStream &in,
-	Graphics::MacPatterns &patterns, byte fillType, byte borderThickness, byte borderFillType) {
+				Graphics::MacPatterns &patterns, byte fillType, byte borderThickness, byte borderFillType) {
 	int16 y1 = in.readSint16BE();
 	int16 x1 = in.readSint16BE();
 	int16 y2 = in.readSint16BE();
@@ -294,7 +294,7 @@ void Design::drawRect(Graphics::ManagedSurface *surface, Common::ReadStream &in,
 }
 
 void Design::drawRoundRect(Graphics::ManagedSurface *surface, Common::ReadStream &in,
-	Graphics::MacPatterns &patterns, byte fillType, byte borderThickness, byte borderFillType) {
+				Graphics::MacPatterns &patterns, byte fillType, byte borderThickness, byte borderFillType) {
 	int16 y1 = in.readSint16BE();
 	int16 x1 = in.readSint16BE();
 	int16 y2 = in.readSint16BE();
@@ -397,7 +397,7 @@ void Design::drawPolygon(Graphics::ManagedSurface *surface, Common::ReadStream &
 }
 
 void Design::drawOval(Graphics::ManagedSurface *surface, Common::ReadStream &in,
-	Graphics::MacPatterns &patterns, byte fillType, byte borderThickness, byte borderFillType) {
+			Graphics::MacPatterns &patterns, byte fillType, byte borderThickness, byte borderFillType) {
 	int16 y1 = in.readSint16BE();
 	int16 x1 = in.readSint16BE();
 	int16 y2 = in.readSint16BE();
diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp
index a60395f..86c2a9b 100644
--- a/engines/wage/gui.cpp
+++ b/engines/wage/gui.cpp
@@ -66,18 +66,18 @@ static const Graphics::MenuData menuSubItems[] = {
 	{ kMenuHighLevel, "Edit",	0, 0, false },
 	{ kMenuFile, "New",			kMenuActionNew, 0, false },
 	{ kMenuFile, "Open...",		kMenuActionOpen, 0, true },
-	{ kMenuFile, "Close",			kMenuActionClose, 0, true },
-	{ kMenuFile, "Save",			kMenuActionSave, 0, true },
+	{ kMenuFile, "Close",		kMenuActionClose, 0, true },
+	{ kMenuFile, "Save",		kMenuActionSave, 0, true },
 	{ kMenuFile, "Save as...",	kMenuActionSaveAs, 0, true },
 	{ kMenuFile, "Revert",		kMenuActionRevert, 0, false },
-	{ kMenuFile, "Quit",			kMenuActionQuit, 0, true },
-
-	{ kMenuEdit, "Undo",			kMenuActionUndo, 'Z', false },
-	{ kMenuEdit, NULL,				0, 0, false },
-	{ kMenuEdit, "Cut",				kMenuActionCut, 'K', false },
-	{ kMenuEdit, "Copy",			kMenuActionCopy, 'C', false },
-	{ kMenuEdit, "Paste",			kMenuActionPaste, 'V', false },
-	{ kMenuEdit, "Clear",			kMenuActionClear, 'B', false },
+	{ kMenuFile, "Quit",		kMenuActionQuit, 0, true },
+
+	{ kMenuEdit, "Undo",		kMenuActionUndo, 'Z', false },
+	{ kMenuEdit, NULL,			0, 0, false },
+	{ kMenuEdit, "Cut",			kMenuActionCut, 'K', false },
+	{ kMenuEdit, "Copy",		kMenuActionCopy, 'C', false },
+	{ kMenuEdit, "Paste",		kMenuActionPaste, 'V', false },
+	{ kMenuEdit, "Clear",		kMenuActionClear, 'B', false },
 
 	{ 0, NULL,			0, 0, false }
 };


Commit: e809320f588941693b09881fc25efda80b8cdfb8
    https://github.com/scummvm/scummvm/commit/e809320f588941693b09881fc25efda80b8cdfb8
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-08-02T08:33:50+02:00

Commit Message:
GRAPHICS: Fix indentation

Changed paths:
    graphics/macgui/macwindow.h
    graphics/macgui/macwindowmanager.h
    graphics/nine_patch.cpp



diff --git a/graphics/macgui/macwindow.h b/graphics/macgui/macwindow.h
index 285a9e9..13233f2 100644
--- a/graphics/macgui/macwindow.h
+++ b/graphics/macgui/macwindow.h
@@ -61,27 +61,27 @@ class MacWindowManager;
 class MacWindowBorder;
 
 namespace MacWindowConstants {
-	enum WindowType {
-		kWindowUnknown,
-		kWindowWindow,
-		kWindowMenu
-	};
-
-	enum {
-		kBorderWidth = 17
-	};
-
-	enum WindowClick {
-		kBorderNone = 0,
-		kBorderScrollUp,
-		kBorderScrollDown,
-		kBorderScrollLeft,
-		kBorderScrollRight,
-		kBorderCloseButton,
-		kBorderInner,
-		kBorderBorder,
-		kBorderResizeButton
-	};
+enum WindowType {
+	kWindowUnknown,
+	kWindowWindow,
+	kWindowMenu
+};
+
+enum {
+	kBorderWidth = 17
+};
+
+enum WindowClick {
+	kBorderNone = 0,
+	kBorderScrollUp,
+	kBorderScrollDown,
+	kBorderScrollLeft,
+	kBorderScrollRight,
+	kBorderCloseButton,
+	kBorderInner,
+	kBorderBorder,
+	kBorderResizeButton
+};
 }
 using namespace MacWindowConstants;
 
diff --git a/graphics/macgui/macwindowmanager.h b/graphics/macgui/macwindowmanager.h
index 2d8a6a3..c25149c 100644
--- a/graphics/macgui/macwindowmanager.h
+++ b/graphics/macgui/macwindowmanager.h
@@ -59,25 +59,25 @@
 namespace Graphics {
 
 namespace MacGUIConstants {
-	enum {
-		kDesktopArc = 7
-	};
-
-	enum {
-		kColorBlack = 0,
-		kColorGray = 1,
-		kColorWhite = 2,
-		kColorGreen = 3,
-		kColorGreen2 = 4,
-		kColorCount
-	};
-
-	enum {
-		kPatternSolid = 1,
-		kPatternStripes = 2,
-		kPatternCheckers = 3,
-		kPatternCheckers2 = 4
-	};
+enum {
+	kDesktopArc = 7
+};
+
+enum {
+	kColorBlack = 0,
+	kColorGray = 1,
+	kColorWhite = 2,
+	kColorGreen = 3,
+	kColorGreen2 = 4,
+	kColorCount
+};
+
+enum {
+	kPatternSolid = 1,
+	kPatternStripes = 2,
+	kPatternCheckers = 3,
+	kPatternCheckers2 = 4
+};
 }
 using namespace MacGUIConstants;
 
diff --git a/graphics/nine_patch.cpp b/graphics/nine_patch.cpp
index 89c534f..331344f 100644
--- a/graphics/nine_patch.cpp
+++ b/graphics/nine_patch.cpp
@@ -264,11 +264,11 @@ void NinePatchBitmap::drawRegions(Graphics::Surface &target, int dx, int dy, int
 	for (uint i = 0; i < _v._m.size(); ++i) {
 		for (uint j = 0; j < _h._m.size(); ++j) {
 			Common::Rect r(_h._m[j]->offset, _v._m[i]->offset,
-				_h._m[j]->offset + _h._m[j]->length, _v._m[i]->offset + _v._m[i]->length);
+						_h._m[j]->offset + _h._m[j]->length, _v._m[i]->offset + _v._m[i]->length);
 
 			_bmp->blit(target, dx + _h._m[j]->dest_offset, dy + _v._m[i]->dest_offset,
-				Graphics::FLIP_NONE, &r, TS_ARGB(255, 255, 255, 255),
-				_h._m[j]->dest_length, _v._m[i]->dest_length);
+					Graphics::FLIP_NONE, &r, TS_ARGB(255, 255, 255, 255),
+					_h._m[j]->dest_length, _v._m[i]->dest_length);
 		}
 	}
 }


Commit: 03f2d9b01ed392488269647d557b25f41a86fc84
    https://github.com/scummvm/scummvm/commit/03f2d9b01ed392488269647d557b25f41a86fc84
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-08-02T08:33:50+02:00

Commit Message:
GRAPHICS: Remove unused variables

Changed paths:
    graphics/macgui/macwindow.cpp
    graphics/nine_patch.cpp



diff --git a/graphics/macgui/macwindow.cpp b/graphics/macgui/macwindow.cpp
index 1b4ed01..dbb600b 100644
--- a/graphics/macgui/macwindow.cpp
+++ b/graphics/macgui/macwindow.cpp
@@ -394,12 +394,10 @@ bool MacWindow::isInResizeButton(int x, int y) {
 }
 
 WindowClick MacWindow::isInScroll(int x, int y) {
-	int bLeft = kBorderWidth;
 	int bTop = kBorderWidth;
 	int bRight = kBorderWidth;
 	int bBottom = kBorderWidth;
 	if (_macBorder.hasOffsets()) {
-		bLeft = _macBorder.getOffset(kBorderOffsetLeft);
 		bTop = _macBorder.getOffset(kBorderOffsetTop);
 		bRight = _macBorder.getOffset(kBorderOffsetRight);
 		bBottom = _macBorder.getOffset(kBorderOffsetBottom);
diff --git a/graphics/nine_patch.cpp b/graphics/nine_patch.cpp
index 331344f..f89a0f2 100644
--- a/graphics/nine_patch.cpp
+++ b/graphics/nine_patch.cpp
@@ -235,9 +235,6 @@ void NinePatchBitmap::blit(Graphics::Surface &target, int dx, int dy, int dw, in
 
 		drawRegions(srf, dx, dy, dw, dh);
 
-		byte black = getColorIndex(TS_RGB(0, 0, 0), palette);
-		byte white = getColorIndex(TS_RGB(255, 255, 255), palette);
-
 		for (uint i = 0; i < srf.w; ++i) {
 			for (uint j = 0; j < srf.h; ++j) {
 				uint32 color = *(uint32*)srf.getBasePtr(i, j);


Commit: 02a18134c380acbddd8a7d3fa11a19fff3f21a55
    https://github.com/scummvm/scummvm/commit/02a18134c380acbddd8a7d3fa11a19fff3f21a55
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-08-02T08:33:50+02:00

Commit Message:
GRAPHICS: Add basic caching to 9patch colors

Changed paths:
    graphics/nine_patch.cpp
    graphics/nine_patch.h



diff --git a/graphics/nine_patch.cpp b/graphics/nine_patch.cpp
index f89a0f2..fa2ef20 100644
--- a/graphics/nine_patch.cpp
+++ b/graphics/nine_patch.cpp
@@ -235,6 +235,11 @@ void NinePatchBitmap::blit(Graphics::Surface &target, int dx, int dy, int dw, in
 
 		drawRegions(srf, dx, dy, dw, dh);
 
+		//TODO: This can be further optimized by keeping the data between draws,
+		// and using a unique identifier for each palette, so that it only gets
+		// recalculated when the palette changes.
+		_cached_colors.clear();
+
 		for (uint i = 0; i < srf.w; ++i) {
 			for (uint j = 0; j < srf.h; ++j) {
 				uint32 color = *(uint32*)srf.getBasePtr(i, j);
@@ -334,18 +339,21 @@ static inline uint32 dist(uint32 a, uint32 b) {
 }
 
 byte NinePatchBitmap::closestGrayscale(uint32 color, byte* palette, byte paletteLength) {
-	byte target = grayscale(color);
-	byte bestNdx = 0;
-	byte bestColor = grayscale(palette[0], palette[1], palette[2]);
-	for (byte i = 1; i < paletteLength; ++i) {
-		byte current = grayscale(palette[i * 3], palette[(i * 3) + 1], palette[(i * 3) + 2]);
-		if (dist(target, bestColor) >= dist(target, current)) {
-			bestColor = current;
-			bestNdx = i;
+	if (!_cached_colors.contains(color)) {
+		byte target = grayscale(color);
+		byte bestNdx = 0;
+		byte bestColor = grayscale(palette[0], palette[1], palette[2]);
+		for (byte i = 1; i < paletteLength; ++i) {
+			byte current = grayscale(palette[i * 3], palette[(i * 3) + 1], palette[(i * 3) + 2]);
+			if (dist(target, bestColor) >= dist(target, current)) {
+				bestColor = current;
+				bestNdx = i;
+			}
 		}
+		_cached_colors[color] = bestNdx;
 	}
 
-	return bestNdx;
+	return _cached_colors[color];
 }
 
 } // end of namespace Graphics
diff --git a/graphics/nine_patch.h b/graphics/nine_patch.h
index b40f3bf..aa81a2f 100644
--- a/graphics/nine_patch.h
+++ b/graphics/nine_patch.h
@@ -48,6 +48,7 @@
 
 #include "common/array.h"
 #include "common/rect.h"
+#include "common/hashmap.h"
 
 namespace Graphics {
 
@@ -81,6 +82,7 @@ class NinePatchBitmap {
 	bool _destroy_bmp;
 	int _width, _height;
 	int _cached_dw, _cached_dh;
+	Common::HashMap<uint32, int> _cached_colors;
 
 public:
 	NinePatchBitmap(Graphics::TransparentSurface *bmp, bool owns_bitmap);
@@ -88,7 +90,7 @@ public:
 
 	void blit(Graphics::Surface &target, int dx, int dy, int dw, int dh, byte *palette = NULL, byte numColors = 0);
 	void blitClip(Graphics::Surface &target, Common::Rect clip, int dx, int dy, int dw, int dh);
-		
+
 	int getWidth() { return _width; }
 	int getHeight() { return _height; }
 	int getMinWidth() { return _h._fix; }


Commit: d7010637af855ab99dd57d692d038f14c57786a8
    https://github.com/scummvm/scummvm/commit/d7010637af855ab99dd57d692d038f14c57786a8
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-08-02T08:33:50+02:00

Commit Message:
GRAPHICS: Add documentation to MacWindowBorder

Changed paths:
    graphics/macgui/macwindowborder.h



diff --git a/graphics/macgui/macwindowborder.h b/graphics/macgui/macwindowborder.h
index 295f554..54938e5 100644
--- a/graphics/macgui/macwindowborder.h
+++ b/graphics/macgui/macwindowborder.h
@@ -64,19 +64,72 @@ enum MacBorderOffset {
 	kBorderOffsetBottom	= 3
 };
 
+/**
+ * A representation of a custom border, which allows for arbitrary border offsets
+ * and nine-patch resizable displays for both active and inactive states.
+ * However, the border offsets are the same for both active and inactive states.
+ */
 class MacWindowBorder {
 public:
 	MacWindowBorder();
 	~MacWindowBorder();
 
+	/**
+	 * Accessor to check whether or not a border is loaded.
+	 * @param active State that we want to check. If true it checks for active border, if false it checks for inactive.
+	 * @return True if the checked state has a border loaded, false otherwise.
+	 */
 	bool hasBorder(bool active);
+
+	/**
+	 * Add the given surface as the display of the border in the active state.
+	 * Will fail if there is already an active border.
+	 * @param The surface that will be displayed.
+	 */
 	void addActiveBorder(TransparentSurface &source);
+
+	/**
+	 * Add the given surface as the display of the border in the inactive state.
+	 * Will fail if there is already an inactive border.
+	 * @param The surface that will be displayed.
+	 */
 	void addInactiveBorder(TransparentSurface &source);
 
+	/**
+	 * Accessor function for the custom offsets.
+	 * @return True if custom offsets have been indicated (setOffsets has been called previously).
+	 */
 	bool hasOffsets();
+
+	/**
+	 * Mutator method to indicate the custom border offsets.
+	 * These should be set to the desired thickness of each side of the border.
+	 * e.g. For a border that is 10 pixels wide and 5 pixels tall, the call should be:
+	 * setOffsets(10, 10, 5, 5)
+	 * Note that this function does not check whether those borders form
+	 * a valid rect when combined with the window dimensions.
+	 * @param left Thickness (in pixels) of the left side of the border.
+	 * @param right Thickness (in pixels) of the right side of the border.
+	 * @param top Thickness (in pixels) of the top side of the border.
+	 * @param bottom Thickness (in pixels) of the bottom side of the border.
+	 */
 	void setOffsets(int left, int right, int top, int bottom);
+
+	/**
+	 * Accessor method to retrieve a given border.
+	 * Note that it does not check for validity, and thus if setOffsets
+	 * was not called before it might return garbage.
+	 * @param offset The identifier of the offset wanted.
+	 * @return The desired offset in pixels.
+	 */
 	int getOffset(MacBorderOffset offset);
 
+	/**
+	 * Blit the desired border (active or inactive) into a destination surface.
+	 * It automatically resizes the border to fit the given surface.
+	 * @param destination The surface we want to blit into.
+	 * @param active True if we want to blit the active border, false otherwise.
+	 */
 	void blitBorderInto(ManagedSurface &destination, bool active);
 
 private:


Commit: c4f6c4c2fda1bfdc591741614092abc11af7a942
    https://github.com/scummvm/scummvm/commit/c4f6c4c2fda1bfdc591741614092abc11af7a942
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-08-02T08:33:50+02:00

Commit Message:
GRAPHICS: Add documentation to BaseMacWindow

Changed paths:
    graphics/macgui/macwindow.h



diff --git a/graphics/macgui/macwindow.h b/graphics/macgui/macwindow.h
index 13233f2..e6fe3a3 100644
--- a/graphics/macgui/macwindow.h
+++ b/graphics/macgui/macwindow.h
@@ -85,24 +85,92 @@ enum WindowClick {
 }
 using namespace MacWindowConstants;
 
+/**
+ * Abstract class that defines common functionality for all window classes.
+ * It supports event callbacks and drawing.
+ */
 class BaseMacWindow {
 public:
+	/**
+	 * Base constructor.
+	 * @param id ID of the window.
+	 * @param editable True if the window is editable (e.g. for resizing).
+	 * @param wm Pointer to the MacWindowManager that owns the window.
+	 */
 	BaseMacWindow(int id, bool editable, MacWindowManager *wm);
 	virtual ~BaseMacWindow() {}
 
+	/**
+	 * Accessor method for the complete dimensions of the window.
+	 * @return Dimensions of the window (including border) relative to the WM's screen.
+	 */
 	const Common::Rect &getDimensions() { return _dims; }
+
+	/**
+	 * Accessor method to the id of the window.
+	 * @return The id set in the constructor.
+	 */
 	int getId() { return _id; }
+
+	/**
+	 * Accessor method to the type of window.
+	 * Each subclass must indicate it's type.
+	 * @return The type of the window.
+	 */
 	WindowType getType() { return _type; }
+
+	/**
+	 * Accessor method to check whether the window is editable (e.g. for resizing).
+	 * @return True if the window is editable as indicated in the constructor.
+	 */
 	bool isEditable() { return _editable; }
+
+	/**
+	 * Method to access the entire surface of the window (e.g. to draw an image).
+	 * @return A pointer to the entire surface of the window.
+	 */
 	ManagedSurface *getSurface() { return &_surface; }
+
+	/**
+	 * Abstract method for indicating whether the window is active or inactive.
+	 * Used by the WM to handle focus on windows, etc.
+	 * @param active Desired state of the window.
+	 */
 	virtual void setActive(bool active) = 0;
+
+	/**
+	 * Method for marking the window for redraw.
+	 * @param dirty True if the window needs to be redrawn.
+	 */
 	void setDirty(bool dirty) { _contentIsDirty = dirty; }
 
+	/**
+	 * Method called to draw the window into the target surface.
+	 * This method is most often called by the WM, and relies on
+	 * the window being marked as dirty unless otherwise specified.
+	 * @param g Surface on which to draw the window.
+	 * @param forceRedraw It's behavior depends on the subclass.
+	 */
 	virtual bool draw(ManagedSurface *g, bool forceRedraw = false) = 0;
+
+	/**
+	 * Method called by the WM when there is an event concerning the window.
+	 * Note that depending on the subclass of the window, it might not be called
+	 * if the window is not active.
+	 * @param event Event to be processed.
+	 * @return true If the event was successfully consumed and processed.
+	 */
 	virtual bool processEvent(Common::Event &event) = 0;
 
 	virtual bool hasAllFocus() = 0;
 
+	/**
+	 * Set the callback that will be used when an event needs to be processed.
+	 * @param callback A function pointer to a function that accepts:
+	 *					- A WindowClick, the pert of the window that was clicked.
+	 *					- The event to be processed.
+	 *					- Any additional required data (e.g. the engine's GUI).
+	 */
 	void setCallback(bool (*callback)(WindowClick, Common::Event &, void *), void *data) { _callback = callback; _dataPtr = data; }
 
 protected:


Commit: 5ce231a527e4f741063e9b427113d3b331ab10d9
    https://github.com/scummvm/scummvm/commit/5ce231a527e4f741063e9b427113d3b331ab10d9
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-08-02T08:33:50+02:00

Commit Message:
GRAPHICS: Add macwindow documentation

Changed paths:
    graphics/macgui/macwindow.h



diff --git a/graphics/macgui/macwindow.h b/graphics/macgui/macwindow.h
index e6fe3a3..c40c1a4 100644
--- a/graphics/macgui/macwindow.h
+++ b/graphics/macgui/macwindow.h
@@ -94,7 +94,7 @@ public:
 	/**
 	 * Base constructor.
 	 * @param id ID of the window.
-	 * @param editable True if the window is editable (e.g. for resizing).
+	 * @param editable True if the window is editable.
 	 * @param wm Pointer to the MacWindowManager that owns the window.
 	 */
 	BaseMacWindow(int id, bool editable, MacWindowManager *wm);
@@ -190,29 +190,116 @@ protected:
 	MacWindowManager *_wm;
 };
 
+/**
+ * An implementation of an ordinary window in the Mac interface.
+ * It supports custom resizing, scrolling, borders, etc.
+ */
 class MacWindow : public BaseMacWindow {
 public:
+	/**
+	 * Construct a simple window, with the default settings.
+	 * Note that the scroll must be implemented in the event handling,
+	 * even if the scrollable flag is set to true.
+	 * @param id See BaseMacWindow.
+	 * @param scrollable True if the window can be scrolled.
+	 * @param resizable True if the window can be resized.
+	 * @param editable See BaseMacWindow.
+	 * @param wm See BaseMacWindow.
+	 */
 	MacWindow(int id, bool scrollable, bool resizable, bool editable, MacWindowManager *wm);
 	virtual ~MacWindow();
+
+	/**
+	 * Change the window's location to fixed coordinates (not delta).
+	 * @param x New left position of the window relative to the WM's screen.
+	 * @param y New top position of the window relative to the WM's screen.
+	 */
 	void move(int x, int y);
+
+	/*
+	 * Change the width and the height of the window.
+	 * @param w New width of the window.
+	 * @param h New height of the window.
+	 */
 	void resize(int w, int h);
+
+	/**
+	 * Change the dimensions of the window ([0, 0, 0, 0] by default).
+	 * Note that this can be used to update both the position and the size
+	 * of the window, although move() and resize() might be more comfortable.
+	 * @param r The desired dimensions of the window.
+	 */
 	void setDimensions(const Common::Rect &r);
+
+	/**
+	 * Accessor to retrieve the dimensions of the inner surface of the window
+	 * (i.e. without taking borders into account).
+	 * Note that the returned dimensions' position is relative to the WM's
+	 * screen, just like in getDimensions().
+	 * @return The inner dimensions of the window.
+	 */
 	const Common::Rect &getInnerDimensions() { return _innerDims; }
 
+	/**
+	 * Similar to that described in BaseMacWindow.
+	 * @param g See BaseMacWindow.
+	 * @param forceRedraw If true, the borders are guarranteed to redraw.
+	 */
 	bool draw(ManagedSurface *g, bool forceRedraw = false);
 
+	/**
+	 * Mutator to change the active state of the window.
+	 * Most often called from the WM.
+	 * @param active Target state.
+	 */
 	void setActive(bool active);
+	/**
+	 * Accessor to determine whether a window is active.
+	 * @return True if the window is active.
+	 */
 	bool isActive();
 
+	/**
+	 * Mutator to change the title of the window.
+	 * @param title Target title of the window.
+	 */
 	void setTitle(Common::String &title) { _title = title; }
+	/**
+	 * Highlight the target part of the window.
+	 * Used for the default borders.
+	 * @param highlightedPart Part to be highlighted.
+	 */
 	void setHighlight(WindowClick highlightedPart);
+	/**
+	 * Set the scroll poisition.
+	 * @param scrollPos Target scroll position.
+	 * @param scrollSize Size of the scrolling bar.
+	 */
 	void setScroll(float scrollPos, float scrollSize);
+	/**
+	 * See BaseMacWindow.
+	 */
 	bool processEvent(Common::Event &event);
 	bool hasAllFocus() { return _beingDragged || _beingResized; }
 
+	/**
+	 * Set arbitrary border from a BMP data stream, with custom border offsets.
+	 * Note that the BMP has to be 9patch compliant. For examples, go to:
+	 * https://github.com/blorente/MacVenture-Extract-Guide/tree/master/borders
+	 * @param file The BMP data stream with the desired border.
+	 * @param active Whether the border corresponds with the active state of the window.
+	 * @param lo Width of the left side of the border, in pixels.
+	 * @param ro Width of the right side of the border, in pixels.
+	 * @param to Width of the top side of the border, in pixels.
+	 * @param bo Width of the bottom side of the border, in pixels.
+	 */
 	void loadBorder(Common::SeekableReadStream &file, bool active, int lo, int ro, int to, int bo);
 	//void setBorder(TransparentSurface &border, bool active);
 
+	/**
+	 * Indicate whether the window can be closed (false by default).
+	 * @param closeable True if the window can be closed.
+	 */
 	void setCloseable(bool closeable);
 
 private:


Commit: ff9b1ccb57fad47b9bb32bb77c83a06c6fd75958
    https://github.com/scummvm/scummvm/commit/ff9b1ccb57fad47b9bb32bb77c83a06c6fd75958
Author: Borja Lorente (blorente at ucm.es)
Date: 2016-08-02T08:33:50+02:00

Commit Message:
GRAPHICS: Add most of the documentation to MacWindowManager

Changed paths:
    graphics/macgui/macwindowmanager.h



diff --git a/graphics/macgui/macwindowmanager.h b/graphics/macgui/macwindowmanager.h
index c25149c..22731a1 100644
--- a/graphics/macgui/macwindowmanager.h
+++ b/graphics/macgui/macwindowmanager.h
@@ -87,28 +87,96 @@ class Menu;
 
 typedef Common::Array<byte *> MacPatterns;
 
+/**
+ * A manager class to handle window creation, destruction,
+ * drawing, moving and event handling.
+ */
 class MacWindowManager {
 public:
 	MacWindowManager();
 	~MacWindowManager();
 
+	/**
+	 * Mutator to indicate the surface onto which the desktop will be drawn.
+	 * Note that this method should be called as soon as the WM is created.
+	 * @param screen Surface on which the desktop will be drawn.
+	 */
 	void setScreen(ManagedSurface *screen) { _screen = screen; }
+	/**
+	 * Accessor method to check the presence of built-in fonts.
+	 * @return True if there are bult-in fonts.
+	 */
 	bool hasBuiltInFonts() { return _builtInFonts; }
+	/**
+	 * Retrieve a font from the available ones.
+	 * @param name Name of the desired font.
+	 * @param fallback Fallback policy in case the desired font isn't there.
+	 * @return The requested font or the fallback.
+	 */
 	const Font *getFont(const char *name, FontManager::FontUsage fallback);
 
+	/**
+	 * Create a window with the given parameters.
+	 * Note that this method allocates the necessary memory for the window.
+	 * @param scrollable True if the window has to be scrollable.
+	 * @param resizable True if the window can be resized.
+	 * @param editable True if the window can be edited.
+	 * @return Pointer to the newly created window.
+	 */
 	MacWindow *addWindow(bool scrollable, bool resizable, bool editable);
+	/**
+	 * Add the menu to the desktop.
+	 * Note that the returned menu is empty, and therefore must be filled
+	 * afterwards.
+	 * @return Pointer to a new empty menu.
+	 */
 	Menu *addMenu();
+	/**
+	 * Set the desired window state to active.
+	 * @param id ID of the window that has to be set to active.
+	 */
 	void setActive(int id);
+	/**
+	 * Mark a window for removal.
+	 * Note that the window data will be destroyed.
+	 * @param target Window to be removed.
+	 */
 	void removeWindow(MacWindow *target);
 
+	/**
+	 * Mutator to indicate that the entire desktop must be refreshed.
+	 * @param redraw Currently unused.
+	 */
 	void setFullRefresh(bool redraw) { _fullRefresh = true; }
 
+	/**
+	 * Method to draw the desktop into the screen,
+	 * It will take into accout the contents set as dirty.
+	 * Note that this method does not refresh the screen,
+	 * g_system must be called separately.
+	 */
 	void draw();
 
+	/**
+	 * Method to process the events from the engine.
+	 * Most often this method will be called from the engine's GUI, and
+	 * will send the event to the relevant windows for them to process.
+	 * @param event The event to be processed.
+	 * @return True if the event was processed.
+	 */
 	bool processEvent(Common::Event &event);
 
+	/**
+	 * Accessor to retrieve an arbitrary window.
+	 * @param id The id of the desired window.
+	 * @return Pointer to the requested window, if it exists.
+	 */
 	BaseMacWindow *getWindow(int id) { return _windows[id]; }
 
+	/**
+	 * Retrieve the patterns used to fill surfaces.
+	 * @return A MacPatterns object reference with the patterns.
+	 */
 	MacPatterns &getPatterns() { return _patterns; }
 	void drawFilledRoundRect(ManagedSurface *surface, Common::Rect &rect, int arc, int color);
 


Commit: a00272c62c012ed4f6ee98ada7415064e8faac5a
    https://github.com/scummvm/scummvm/commit/a00272c62c012ed4f6ee98ada7415064e8faac5a
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2016-08-03T14:37:38+02:00

Commit Message:
Merge pull request #796 from blorente/move-macgui

GRAPHICS/WAGE: Extract Mac GUI system.

Changed paths:
  A graphics/macgui/macmenu.cpp
  A graphics/macgui/macmenu.h
  A graphics/macgui/macwindow.cpp
  A graphics/macgui/macwindow.h
  A graphics/macgui/macwindowborder.cpp
  A graphics/macgui/macwindowborder.h
  A graphics/macgui/macwindowmanager.cpp
  A graphics/macgui/macwindowmanager.h
  R engines/wage/macmenu.cpp
  R engines/wage/macmenu.h
  R engines/wage/macwindow.cpp
  R engines/wage/macwindow.h
  R engines/wage/macwindowmanager.cpp
  R engines/wage/macwindowmanager.h
    engines/wage/design.cpp
    engines/wage/design.h
    engines/wage/dialog.cpp
    engines/wage/entities.cpp
    engines/wage/gui-console.cpp
    engines/wage/gui.cpp
    engines/wage/gui.h
    engines/wage/module.mk
    engines/wage/world.cpp
    engines/wage/world.h
    graphics/module.mk
    graphics/nine_patch.cpp
    graphics/nine_patch.h









More information about the Scummvm-git-logs mailing list