From 2dfbfdbaba780ec4598556299af967f7eb0abf63 Mon Sep 17 00:00:00 2001 From: Borja Lorente Date: Thu, 21 Jul 2016 17:38:28 +0200 Subject: MACVENTURE: Implement in-engine window closing --- engines/macventure/dialog.h | 3 ++ engines/macventure/gui.cpp | 72 +++++++++----------------- engines/macventure/gui.h | 65 ++--------------------- engines/macventure/macventure.cpp | 2 +- engines/macventure/macventure.h | 3 +- engines/macventure/module.mk | 5 +- engines/macventure/prebuilt_dialogs.cpp | 53 +++++++++++++++++++ engines/macventure/prebuilt_dialogs.h | 32 ++---------- engines/macventure/windows.cpp | 60 ++++++++++++++++++++++ engines/macventure/windows.h | 91 +++++++++++++++++++++++++++++++++ 10 files changed, 245 insertions(+), 141 deletions(-) create mode 100644 engines/macventure/prebuilt_dialogs.cpp create mode 100644 engines/macventure/windows.cpp create mode 100644 engines/macventure/windows.h (limited to 'engines/macventure') diff --git a/engines/macventure/dialog.h b/engines/macventure/dialog.h index 66d68e358e..d40639a2d3 100644 --- a/engines/macventure/dialog.h +++ b/engines/macventure/dialog.h @@ -27,11 +27,14 @@ #include "macventure/macventure.h" #include "macventure/prebuilt_dialogs.h" + namespace MacVenture { using namespace Graphics::MacGUIConstants; class Gui; class DialogElement; +extern PrebuiltDialog prebuiltDialogs[]; + class Dialog { public: diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index d8db6656e5..6fcd48c9fc 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -598,6 +598,12 @@ void Gui::drawInventories() { srf->h + border.bottomOffset), kColorWhite); drawObjectsInWindow(data.refcon, srf); + if (MACVENTURE_DEBUG_GUI) { + Common::Rect innerDims = findWindow(data.refcon)->getInnerDimensions(); + innerDims = Common::Rect(17, 17, innerDims.width() + 17, innerDims.height() + 17); + srf->frameRect(innerDims, kColorGreen); + } + findWindow(data.refcon)->setDirty(true); } @@ -1034,6 +1040,18 @@ Common::Point Gui::localize(Common::Point point, WindowReference origin, WindowR return point; } +void Gui::removeInventoryWindow(WindowReference ref) { + _inventoryWindows.remove_at(ref - kInventoryStart); + bool found = false; + Common::List::iterator it; + for (it = _windowData->begin(); it != _windowData->end() && !found; it++) { + if (it->refcon == ref) { + _windowData->erase(it); + found = true; + } + } +} + /* HANDLERS */ void Gui::handleMenuAction(MenuAction action) { @@ -1147,13 +1165,12 @@ void Gui::invertWindowColors(WindowReference winID) { } } - bool Gui::tryCloseWindow(WindowReference winID) { WindowData data = findWindowData(winID); - if (winID < 0x80) { // Inventory window - warning("Window closing not implemented"); - } else { - warning("Window closing not implemented"); + Graphics::MacWindow *win = findWindow(winID); + _wm.removeWindow(win); + if (winID < 0x80) { + removeInventoryWindow(winID); } return true; } @@ -1297,15 +1314,7 @@ bool Gui::processInventoryEvents(WindowClick click, Common::Event & event) { if (ref == kNoWindow) return false; if (click == kBorderCloseButton) { - _inventoryWindows.remove_at(ref - kInventoryStart); - bool found = false; - Common::List::iterator it; - for (it = _windowData->begin(); it != _windowData->end() && !found; it++) { - if (it->refcon == ref) { - _windowData->erase(it); - found = true; - } - } + removeInventoryWindow(ref); return true; } } @@ -1352,40 +1361,5 @@ void Gui::ensureAssetLoaded(ObjID obj) { } } -/* Ugly switches */ - -BorderBounds Gui::borderBounds(MVWindowType type) { - switch (type) { - case MacVenture::kDocument: - break; - case MacVenture::kDBox: - break; - case MacVenture::kPlainDBox: - return BorderBounds(6, 6, 6, 6); - case MacVenture::kAltBox: - return BorderBounds(4, 4, 4, 4); // Hand-tested - break; - case MacVenture::kNoGrowDoc: - return BorderBounds(1, 17, 1, 1); - case MacVenture::kMovableDBox: - break; - case MacVenture::kZoomDoc: - return BorderBounds(1, 19, 16, 1); - case MacVenture::kZoomNoGrow: - break; - case MacVenture::kRDoc16: - break; - case MacVenture::kRDoc4: - return BorderBounds(0, 19, 1, 1); - case MacVenture::kRDoc6: - break; - case MacVenture::kRDoc10: - break; - default: - break; - } - - return BorderBounds(0, 0, 0, 0); -} } // End of namespace MacVenture diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index eb929cfcdd..95e1480762 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -35,6 +35,7 @@ #include "macventure/prebuilt_dialogs.h" #include "macventure/dialog.h" #include "macventure/controls.h" +#include "macventure/windows.h" namespace MacVenture { @@ -49,6 +50,9 @@ class CommandButton; class ImageAsset; class Dialog; +BorderBounds borderBounds(MVWindowType type); +extern PrebuiltDialog prebuiltDialogs[]; + enum MenuAction { kMenuActionAbout, kMenuActionNew, @@ -68,64 +72,6 @@ enum MenuAction { }; //} using namespace MacVentureMenuActions; -enum WindowReference { - kNoWindow = 0, - kInventoryStart = 1, - kCommandsWindow = 0x80, - kMainGameWindow = 0x81, - kOutConsoleWindow = 0x82, - kSelfWindow = 0x83, - kExitsWindow = 0x84, - kDiplomaWindow = 0x85 -}; - -enum MVWindowType { - kDocument = 0x00, - kDBox = 0x01, - kPlainDBox = 0x02, - kAltBox = 0x03, - kNoGrowDoc = 0x04, - kMovableDBox = 0x05, - kZoomDoc = 0x08, - kZoomNoGrow = 0x0c, - kRDoc16 = 0x10, - kRDoc4 = 0x12, - kRDoc6 = 0x14, - kRDoc10 = 0x16 -}; - - -struct DrawableObject { - ObjID obj; - byte mode; - DrawableObject(ObjID id, byte md) { - obj = id; - mode = md; - } -}; - -struct WindowData { - Common::Rect bounds; - MVWindowType type; - ObjID objRef; - uint16 visible; - uint16 hasCloseBox; - WindowReference refcon; - uint8 titleLength; - Common::String title; - Common::Array children; - bool updateScroll; -}; - -struct BorderBounds { - uint16 leftOffset; - uint16 topOffset; - uint16 rightOffset; - uint16 bottomOffset; - - BorderBounds(uint16 l, uint16 t, uint16 r, uint16 b) : leftOffset(l), topOffset(t), rightOffset(r), bottomOffset(b) {} -}; - struct DraggedObj { ObjID id; Common::Point pos; @@ -213,8 +159,6 @@ public: void loadGame(int slot); void saveInto(int slot); - // Ugly switches - BorderBounds borderBounds(MVWindowType type); private: // Attributes @@ -292,6 +236,7 @@ private: // Methods void handleDragRelease(Common::Point pos, bool shiftPressed, bool isDoubleClick); Common::Rect calculateClickRect(Common::Point clickPos, Common::Rect windowBounds); Common::Point localize(Common::Point point, WindowReference origin, WindowReference target); + void removeInventoryWindow(WindowReference ref); void ensureAssetLoaded(ObjID obj); diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 6cb6db5d42..ff4072dba3 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -930,7 +930,7 @@ Common::Rect MacVentureEngine::getObjBounds(ObjID objID) { WindowReference win = findParentWindow(objID); if (win != kNoWindow) { // If it's not in a window YET, we don't really care about the border - BorderBounds bounds = _gui->borderBounds(_gui->getWindowData(win).type); // HACK + BorderBounds bounds = borderBounds(_gui->getWindowData(win).type); // HACK pos.x += bounds.leftOffset; pos.y += bounds.topOffset; } diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 9d1677dd6b..b228a34713 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -39,7 +39,8 @@ #include "macventure/hufflists.h" #include "macventure/stringtable.h" #include "macventure/script.h" -#include "controls.h" +#include "macventure/controls.h" +#include "macventure/windows.h" struct ADGameDescription; diff --git a/engines/macventure/module.mk b/engines/macventure/module.mk index 66039d4c9f..48c8930520 100644 --- a/engines/macventure/module.mk +++ b/engines/macventure/module.mk @@ -10,7 +10,10 @@ MODULE_OBJS := \ macventure.o \ gui.o \ dialog.o \ - controls.o + controls.o \ + prebuilt_dialogs.o \ + windows.o + MODULE_DIRS += \ engines/macventure diff --git a/engines/macventure/prebuilt_dialogs.cpp b/engines/macventure/prebuilt_dialogs.cpp new file mode 100644 index 0000000000..13d2d446bf --- /dev/null +++ b/engines/macventure/prebuilt_dialogs.cpp @@ -0,0 +1,53 @@ +/* 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. +* +*/ + +#include "macventure/prebuilt_dialogs.h" + +namespace MacVenture { + +PrebuiltDialog prebuiltDialogs[kPrebuiltDialogCount] = { + + {/* kSaveAsDialog */ + Common::Rect(0, 146, 456, 254), + { + {kDEButton, "YES", kDASaveAs, Common::Point(24, 68), 120, 22}, + {kDEButton, "NO", kDACloseDialog, Common::Point(168, 68), 120, 22}, + {kDEButton, "CANCEL", kDACloseDialog, Common::Point(312, 68), 120, 22}, + {kDEPlainText, "Save As...", kDANone, Common::Point(100, 10), 340, 38}, + {kDETextInput, "", kDANone, Common::Point(100, 30), 340, 20}, + {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} + } + }, + + { /* kSpeakDialog */ + Common::Rect(20, 92, 400, 200), + { + {kDEButton, "OK", kDASubmit, Common::Point(10, 70), 50, 20}, + {kDEButton, "CANCEL", kDACloseDialog, Common::Point(96, 70), 50, 20}, + {kDEPlainText, "What would you like to say?", kDANone, Common::Point(10, 10), 400, 20}, + {kDETextInput, "", kDANone, Common::Point(10, 25), 350, 40}, + {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} + } + } + +}; +} // End of namespace MacVenture diff --git a/engines/macventure/prebuilt_dialogs.h b/engines/macventure/prebuilt_dialogs.h index 34df91e51b..1e708dbb67 100644 --- a/engines/macventure/prebuilt_dialogs.h +++ b/engines/macventure/prebuilt_dialogs.h @@ -1,4 +1,3 @@ - /* ScummVM - Graphic Adventure Engine * * ScummVM is the legal property of its developers, whose names @@ -24,7 +23,10 @@ #ifndef MACVENTURE_PREBUIT_DIALOGS_H #define MACVENTURE_PREBUIT_DIALOGS_H +#include "common/rect.h" + namespace MacVenture { + enum DialogAction { kDANone, kDACloseDialog, @@ -54,7 +56,6 @@ struct PrebuiltDialogElement { uint height; }; - // Prebuilt dialogs enum { // HACK @@ -65,33 +66,6 @@ struct PrebuiltDialog { Common::Rect bounds; PrebuiltDialogElement elements[kMaxPrebuiltDialogElements]; }; - -PrebuiltDialog prebuiltDialogs[kPrebuiltDialogCount] = { - - {/* kSaveAsDialog */ - Common::Rect(0, 146, 456, 254), - { - {kDEButton, "YES", kDASaveAs, Common::Point(24, 68), 120, 22}, - {kDEButton, "NO", kDACloseDialog, Common::Point(168, 68), 120, 22}, - {kDEButton, "CANCEL", kDACloseDialog, Common::Point(312, 68), 120, 22}, - {kDEPlainText, "Save As...", kDANone, Common::Point(100, 10), 340, 38}, - {kDETextInput, "", kDANone, Common::Point(100, 30), 340, 20}, - {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} - } - }, - - { /* kSpeakDialog */ - Common::Rect(20, 92, 400, 200), - { - {kDEButton, "OK", kDASubmit, Common::Point(10, 70), 50, 20}, - {kDEButton, "CANCEL", kDACloseDialog, Common::Point(96, 70), 50, 20}, - {kDEPlainText, "What would you like to say?", kDANone, Common::Point(10, 10), 400, 20}, - {kDETextInput, "", kDANone, Common::Point(10, 25), 350, 40}, - {kDEEnd, "", kDANone, Common::Point(0, 0), 0, 0} - } - } - -}; } // End of namespace MacVenture #endif diff --git a/engines/macventure/windows.cpp b/engines/macventure/windows.cpp new file mode 100644 index 0000000000..33a63709d2 --- /dev/null +++ b/engines/macventure/windows.cpp @@ -0,0 +1,60 @@ +/* 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. +* +*/ + +#include "macventure/windows.h" + +namespace MacVenture { + +BorderBounds borderBounds(MVWindowType type) { + switch (type) { + case MacVenture::kDocument: + break; + case MacVenture::kDBox: + break; + case MacVenture::kPlainDBox: + return BorderBounds(6, 6, 6, 6); + case MacVenture::kAltBox: + return BorderBounds(4, 4, 4, 4); // Hand-tested + break; + case MacVenture::kNoGrowDoc: + return BorderBounds(1, 17, 1, 1); + case MacVenture::kMovableDBox: + break; + case MacVenture::kZoomDoc: + return BorderBounds(1, 19, 16, 1); + case MacVenture::kZoomNoGrow: + break; + case MacVenture::kRDoc16: + break; + case MacVenture::kRDoc4: + return BorderBounds(0, 19, 1, 1); + case MacVenture::kRDoc6: + break; + case MacVenture::kRDoc10: + break; + default: + break; + } + + return BorderBounds(0, 0, 0, 0); +} +} // End of namespace MacVenture diff --git a/engines/macventure/windows.h b/engines/macventure/windows.h new file mode 100644 index 0000000000..70af446817 --- /dev/null +++ b/engines/macventure/windows.h @@ -0,0 +1,91 @@ +/* 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. +* +*/ + +#ifndef MACVENTURE_WINDOWS_H +#define MACVENTURE_WINDOWS_H + +#include "common/rect.h" +#include "common/array.h" + +namespace MacVenture { + // massive HACK +typedef uint32 ObjID; + +enum WindowReference { + kNoWindow = 0, + kInventoryStart = 1, + kCommandsWindow = 0x80, + kMainGameWindow = 0x81, + kOutConsoleWindow = 0x82, + kSelfWindow = 0x83, + kExitsWindow = 0x84, + kDiplomaWindow = 0x85 +}; + +enum MVWindowType { + kDocument = 0x00, + kDBox = 0x01, + kPlainDBox = 0x02, + kAltBox = 0x03, + kNoGrowDoc = 0x04, + kMovableDBox = 0x05, + kZoomDoc = 0x08, + kZoomNoGrow = 0x0c, + kRDoc16 = 0x10, + kRDoc4 = 0x12, + kRDoc6 = 0x14, + kRDoc10 = 0x16 +}; + +struct DrawableObject { + ObjID obj; + byte mode; + DrawableObject(ObjID id, byte md) { + obj = id; + mode = md; + } +}; + +struct WindowData { + Common::Rect bounds; + MVWindowType type; + ObjID objRef; + uint16 visible; + uint16 hasCloseBox; + WindowReference refcon; + uint8 titleLength; + Common::String title; + Common::Array children; + bool updateScroll; +}; + +struct BorderBounds { + uint16 leftOffset; + uint16 topOffset; + uint16 rightOffset; + uint16 bottomOffset; + + BorderBounds(uint16 l, uint16 t, uint16 r, uint16 b) : + leftOffset(l), topOffset(t), rightOffset(r), bottomOffset(b) {} +}; +} +#endif -- cgit v1.2.3