diff options
author | Borja Lorente | 2016-07-29 11:43:28 +0200 |
---|---|---|
committer | Borja Lorente | 2016-07-30 09:41:54 +0200 |
commit | 3d4087b9d0c199ba48a6f69d7d20a2850215f72f (patch) | |
tree | 97a1e03561a21a579246b0054af7ed1c023a28b0 | |
parent | f50d9feee1e04a8ca9271b21859bda48172b7ff5 (diff) | |
download | scummvm-rg350-3d4087b9d0c199ba48a6f69d7d20a2850215f72f.tar.gz scummvm-rg350-3d4087b9d0c199ba48a6f69d7d20a2850215f72f.tar.bz2 scummvm-rg350-3d4087b9d0c199ba48a6f69d7d20a2850215f72f.zip |
WAGE: Extract MacWindowManager
-rw-r--r-- | engines/wage/design.cpp | 4 | ||||
-rw-r--r-- | engines/wage/design.h | 26 | ||||
-rw-r--r-- | engines/wage/dialog.cpp | 3 | ||||
-rw-r--r-- | engines/wage/gui.cpp | 2 | ||||
-rw-r--r-- | engines/wage/gui.h | 5 | ||||
-rw-r--r-- | engines/wage/macmenu.cpp | 4 | ||||
-rw-r--r-- | engines/wage/macmenu.h | 6 | ||||
-rw-r--r-- | engines/wage/macwindow.cpp | 6 | ||||
-rw-r--r-- | engines/wage/macwindow.h | 12 | ||||
-rw-r--r-- | engines/wage/module.mk | 1 | ||||
-rw-r--r-- | engines/wage/world.h | 4 | ||||
-rw-r--r-- | graphics/macgui/macwindowmanager.cpp | 380 | ||||
-rw-r--r-- | graphics/macgui/macwindowmanager.h (renamed from engines/wage/macwindowmanager.h) | 64 | ||||
-rw-r--r-- | graphics/module.mk | 3 |
14 files changed, 467 insertions, 53 deletions
diff --git a/engines/wage/design.cpp b/engines/wage/design.cpp index 2bfea9df7d..a578a84f79 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 86225c9224..c64ae6d065 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 86080c9a6f..a2013db852 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 cdc646f649..b87a28c5f1 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 ba1bb5ef3b..ef93f6e014 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 b29903c674..5d799061cc 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 e73e4c48a9..239c4fc75c 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 db8ef38c39..1100c0ba4b 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 4c6e9efeff..4d824bd399 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/module.mk b/engines/wage/module.mk index 1f397b5a71..43f0f0fdfc 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 918616c9c1..b3908be81c 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 0000000000..7df635a1ff --- /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/engines/wage/macwindowmanager.h b/graphics/macgui/macwindowmanager.h index 13f85cddd4..ccc9234a6c 100644 --- a/engines/wage/macwindowmanager.h +++ b/graphics/macgui/macwindowmanager.h @@ -45,8 +45,8 @@ * */ -#ifndef WAGE_MACWINDOWMANAGER_H -#define WAGE_MACWINDOWMANAGER_H +#ifndef GRAPHICS_MACWINDOWMANAGER_H +#define GRAPHICS_MACWINDOWMANAGER_H #include "common/array.h" #include "common/list.h" @@ -55,11 +55,15 @@ #include "graphics/fontman.h" -namespace Graphics { -class ManagedSurface; -} +#include "engines\wage\macwindow.h" namespace Wage { + class MacWindow; + class BaseMacWindow; + class Menu; +} + +namespace Graphics { enum { kDesktopArc = 7 @@ -80,9 +84,7 @@ enum { kPatternCheckers2 = 4 }; -class BaseMacWindow; -class MacWindow; -class Menu; +class ManagedSurface; typedef Common::Array<byte *> Patterns; @@ -91,12 +93,12 @@ public: MacWindowManager(); ~MacWindowManager(); - void setScreen(Graphics::ManagedSurface *screen) { _screen = screen; } + void setScreen(ManagedSurface *screen) { _screen = screen; } bool hasBuiltInFonts() { return _builtInFonts; } - const Graphics::Font *getFont(const char *name, Graphics::FontManager::FontUsage fallback); + const Font *getFont(const char *name, FontManager::FontUsage fallback); - MacWindow *addWindow(bool scrollable, bool resizable, bool editable); - Menu *addMenu(); + Wage::MacWindow *addWindow(bool scrollable, bool resizable, bool editable); + Wage::Menu *addMenu(); void setActive(int id); void setFullRefresh(bool redraw) { _fullRefresh = true; } @@ -105,10 +107,10 @@ public: bool processEvent(Common::Event &event); - BaseMacWindow *getWindow(int id) { return _windows[id]; } + Wage::BaseMacWindow *getWindow(int id) { return _windows[id]; } Patterns &getPatterns() { return _patterns; } - void drawFilledRoundRect(Graphics::ManagedSurface *surface, Common::Rect &rect, int arc, int color); + void drawFilledRoundRect(ManagedSurface *surface, Common::Rect &rect, int arc, int color); void pushArrowCursor(); void popCursor(); @@ -118,10 +120,10 @@ private: void loadFonts(); private: - Graphics::ManagedSurface *_screen; + ManagedSurface *_screen; - Common::List<BaseMacWindow *> _windowStack; - Common::Array<BaseMacWindow *> _windows; + Common::List<Wage::BaseMacWindow *> _windowStack; + Common::Array<Wage::BaseMacWindow *> _windows; int _lastId; int _activeWindow; @@ -130,12 +132,36 @@ private: Patterns _patterns; - Menu *_menu; + Wage::Menu *_menu; bool _builtInFonts; bool _cursorIsArrow; }; -} // End of namespace Wage +} // 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 7331a56c93..4d6c11bf6d 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 += \ |