From 7d2d624908e9265be108d650a161a378add9d40d Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 23 Mar 2016 20:51:42 -0400 Subject: TITANIC: More view event handling, beginnings of mouse cursor loading --- engines/titanic/core/game_object.cpp | 4 +- engines/titanic/core/game_object.h | 3 +- engines/titanic/core/link_item.cpp | 14 +++---- engines/titanic/core/link_item.h | 3 +- engines/titanic/core/saveable_object.cpp | 4 +- engines/titanic/core/view_item.cpp | 44 +++++++++++++++++++-- engines/titanic/core/view_item.h | 6 ++- engines/titanic/files_manager.cpp | 4 ++ engines/titanic/files_manager.h | 2 + engines/titanic/input_translator.cpp | 6 +-- engines/titanic/messages/messages.cpp | 2 +- engines/titanic/messages/mouse_messages.h | 14 +++---- engines/titanic/mouse_cursor.cpp | 65 ++++++++++++++++++++++++++++--- engines/titanic/mouse_cursor.h | 54 ++++++++++++++++++++++++- engines/titanic/movie.cpp | 64 ++++++++++++++++++++++++++++++ engines/titanic/movie.h | 41 +++++++++++++++++++ engines/titanic/screen_manager.cpp | 2 +- engines/titanic/video_surface.cpp | 2 +- engines/titanic/video_surface.h | 4 +- 19 files changed, 301 insertions(+), 37 deletions(-) (limited to 'engines/titanic') diff --git a/engines/titanic/core/game_object.cpp b/engines/titanic/core/game_object.cpp index 8f2b333990..e4ad4ccaea 100644 --- a/engines/titanic/core/game_object.cpp +++ b/engines/titanic/core/game_object.cpp @@ -46,7 +46,7 @@ CGameObject::CGameObject(): CNamedItem() { _field58 = 0; _field5C = 1; _field60 = 0; - _cursorId = 1; + _cursorId = CURSOR_1; _field78 = 0; _frameNumber = -1; _field90 = 0; @@ -77,7 +77,7 @@ void CGameObject::load(SimpleFile *file) { // Deliberate fall-through case 6: - val = _cursorId = file->readNumber(); + _cursorId = (CursorId)file->readNumber(); // Deliberate fall-through case 5: diff --git a/engines/titanic/core/game_object.h b/engines/titanic/core/game_object.h index b327671b6b..66aa9c400c 100644 --- a/engines/titanic/core/game_object.h +++ b/engines/titanic/core/game_object.h @@ -23,6 +23,7 @@ #ifndef TITANIC_GAME_OBJECT_H #define TITANIC_GAME_OBJECT_H +#include "titanic/mouse_cursor.h" #include "titanic/rect.h" #include "titanic/core/movie_clip.h" #include "titanic/core/named_item.h" @@ -94,7 +95,7 @@ protected: int _fieldB8; public: int _field60; - int _cursorId; + CursorId _cursorId; public: CLASSDEF CGameObject(); diff --git a/engines/titanic/core/link_item.cpp b/engines/titanic/core/link_item.cpp index 02b4215cfa..5ca64b1c59 100644 --- a/engines/titanic/core/link_item.cpp +++ b/engines/titanic/core/link_item.cpp @@ -32,7 +32,7 @@ CLinkItem::CLinkItem() : CNamedItem() { _nodeNumber = -1; _viewNumber = -1; _field30 = 0; - _field34 = 1; + _cursorId = CURSOR_1; _name = "Link"; } @@ -44,7 +44,7 @@ CString CLinkItem::formName() { void CLinkItem::save(SimpleFile *file, int indent) const { file->writeNumberLine(2, indent); file->writeQuotedLine("L", indent); - file->writeNumberLine(_field34, indent + 1); + file->writeNumberLine(_cursorId, indent + 1); file->writeNumberLine(_field30, indent + 1); file->writeNumberLine(_roomNumber, indent + 1); file->writeNumberLine(_nodeNumber, indent + 1); @@ -65,7 +65,7 @@ void CLinkItem::load(SimpleFile *file) { switch (val) { case 2: - _field34 = file->readNumber(); + _cursorId = (CursorId)file->readNumber(); // Deliberate fall-through case 1: @@ -93,16 +93,16 @@ void CLinkItem::load(SimpleFile *file) { if (val < 2) { switch (_field30) { case 2: - _field34 = 2; + _cursorId = CURSOR_2; break; case 3: - _field34 = 3; + _cursorId = CURSOR_3; break; case 5: - _field34 = 7; + _cursorId = CURSOR_7; break; default: - _field34 = 4; + _cursorId = CURSOR_4; break; } } diff --git a/engines/titanic/core/link_item.h b/engines/titanic/core/link_item.h index bbeef2c11c..83b2ce4f06 100644 --- a/engines/titanic/core/link_item.h +++ b/engines/titanic/core/link_item.h @@ -23,6 +23,7 @@ #ifndef TITANIC_LINK_ITEM_H #define TITANIC_LINK_ITEM_H +#include "titanic/mouse_cursor.h" #include "titanic/core/named_item.h" #include "titanic/core/movie_clip.h" @@ -44,9 +45,9 @@ protected: int _nodeNumber; int _viewNumber; int _field30; - int _field34; public: Rect _bounds; + CursorId _cursorId; public: CLASSDEF CLinkItem(); diff --git a/engines/titanic/core/saveable_object.cpp b/engines/titanic/core/saveable_object.cpp index 2c4eea5f3c..1f7448f655 100644 --- a/engines/titanic/core/saveable_object.cpp +++ b/engines/titanic/core/saveable_object.cpp @@ -818,7 +818,7 @@ DEFFN(CMouseMoveMsg) DEFFN(CMouseButtonMsg) DEFFN(CMouseButtonDownMsg) DEFFN(CMouseButtonUpMsg) -DEFFN(CMouseButtonDoubleClickMsg) +DEFFN(CMouseDoubleClickMsg) DEFFN(CMouseDragMsg) DEFFN(CMouseDragStartMsg) DEFFN(CMouseDragMoveMsg) @@ -1395,7 +1395,7 @@ void CSaveableObject::initClassList() { ADDFN(CMouseButtonMsg, CMouseMsg); ADDFN(CMouseButtonDownMsg, CMouseButtonMsg); ADDFN(CMouseButtonUpMsg, CMouseButtonMsg); - ADDFN(CMouseButtonDoubleClickMsg, CMouseButtonMsg); + ADDFN(CMouseDoubleClickMsg, CMouseButtonMsg); ADDFN(CMouseDragMsg, CMouseMsg); ADDFN(CMouseDragStartMsg, CMouseDragMsg); ADDFN(CMouseDragMoveMsg, CMouseDragMsg); diff --git a/engines/titanic/core/view_item.cpp b/engines/titanic/core/view_item.cpp index c48166698d..1b9a1dd1a6 100644 --- a/engines/titanic/core/view_item.cpp +++ b/engines/titanic/core/view_item.cpp @@ -180,7 +180,45 @@ bool CViewItem::handleEvent(CMouseButtonDownMsg &msg) { } } } - // TODO + } + + return true; +} + +bool CViewItem::handleEvent(CMouseButtonUpMsg &msg) { + if (msg._buttons & MB_LEFT) + handleMouseMsg(&msg, false); + + return true; +} + +bool CViewItem::handleEvent(CMouseDoubleClickMsg &msg) { + if (msg._buttons & MB_LEFT) + handleMouseMsg(&msg, false); + + return true; +} + +bool CViewItem::handleEvent(CMouseMoveMsg &msg) { + CScreenManager *screenManager = CScreenManager::_screenManagerPtr; + + if (handleMouseMsg(&msg, true)) { + screenManager->_mouseCursor->setCursor(CURSOR_1); + } else { + // Iterate through each link item, and if any is highlighted, + // change the mouse cursor to the designated cursor for the item + CLinkItem *linkItem = dynamic_cast(getFirstChild()); + while (linkItem) { + if (linkItem->_bounds.contains(msg._mousePos)) { + screenManager->_mouseCursor->setCursor(linkItem->_cursorId); + return true; + } + + linkItem = dynamic_cast(linkItem->getNextSibling()); + } + + if (!handleMouseMsg(&msg, false)) + screenManager->_mouseCursor->setCursor(CURSOR_1); } return true; @@ -212,8 +250,8 @@ bool CViewItem::handleMouseMsg(const CMouseMsg *msg, bool flag) { return false; for (int idx = (int)gameObjects.size() - 1; idx >= 0; ++idx) { - if (gameObjects[idx]->_cursorId != 12) { - CScreenManager::_screenManagerPtr->_mouseCursor->setCursorId(gameObjects[idx]->_cursorId); + if (gameObjects[idx]->_cursorId != CURSOR_12) { + CScreenManager::_screenManagerPtr->_mouseCursor->setCursor(gameObjects[idx]->_cursorId); break; } } diff --git a/engines/titanic/core/view_item.h b/engines/titanic/core/view_item.h index b1de0bb305..bc66122314 100644 --- a/engines/titanic/core/view_item.h +++ b/engines/titanic/core/view_item.h @@ -29,7 +29,8 @@ namespace Titanic { -class CViewItem : public CNamedItem { //, CMouseButtonDownMsgTarget { +class CViewItem : public CNamedItem, CMouseButtonDownMsgTarget, + CMouseButtonUpMsgTarget, CMouseMoveMsgTarget, CMouseDoubleClickMsgTarget { private: CTreeItem *_buttonUpTargets[4]; private: @@ -52,6 +53,9 @@ protected: int _field54; protected: virtual bool handleEvent(CMouseButtonDownMsg &msg); + virtual bool handleEvent(CMouseButtonUpMsg &msg); + virtual bool handleEvent(CMouseMoveMsg &msg); + virtual bool handleEvent(CMouseDoubleClickMsg &msg); public: int _viewNumber; public: diff --git a/engines/titanic/files_manager.cpp b/engines/titanic/files_manager.cpp index f56c9c5e45..5db75cd67c 100644 --- a/engines/titanic/files_manager.cpp +++ b/engines/titanic/files_manager.cpp @@ -81,6 +81,10 @@ void CFilesManager::resetView() { } } +void CFilesManager::fn4(const CString &name) { + warning("TODO: CFilesManager::fn4"); +} + void CFilesManager::fn5(const CString &name) { warning("TODO: CFilesManager::fn5"); } diff --git a/engines/titanic/files_manager.h b/engines/titanic/files_manager.h index 0785bfc3c0..74895d7877 100644 --- a/engines/titanic/files_manager.h +++ b/engines/titanic/files_manager.h @@ -77,6 +77,8 @@ public: */ void resetView(); + void fn4(const CString &name); + void fn5(const CString &name); }; diff --git a/engines/titanic/input_translator.cpp b/engines/titanic/input_translator.cpp index ceb2be87f6..2251c2fe7a 100644 --- a/engines/titanic/input_translator.cpp +++ b/engines/titanic/input_translator.cpp @@ -60,7 +60,7 @@ void CInputTranslator::leftButtonUp(int special, const Point &pt) { } void CInputTranslator::leftButtonDoubleClick(int special, const Point &pt) { - CMouseButtonDoubleClickMsg msg(pt, getButtons(special)); + CMouseDoubleClickMsg msg(pt, getButtons(special)); _inputHandler->handleMessage(msg); } @@ -75,7 +75,7 @@ void CInputTranslator::middleButtonUp(int special, const Point &pt) { } void CInputTranslator::middleButtonDoubleClick(int special, const Point &pt) { - CMouseButtonDoubleClickMsg msg(pt, getButtons(special)); + CMouseDoubleClickMsg msg(pt, getButtons(special)); _inputHandler->handleMessage(msg); } @@ -90,7 +90,7 @@ void CInputTranslator::rightButtonUp(int special, const Point &pt) { } void CInputTranslator::rightButtonDoubleClick(int special, const Point &pt) { - CMouseButtonDoubleClickMsg msg(pt, getButtons(special)); + CMouseDoubleClickMsg msg(pt, getButtons(special)); _inputHandler->handleMessage(msg); } diff --git a/engines/titanic/messages/messages.cpp b/engines/titanic/messages/messages.cpp index b44748d899..9202305353 100644 --- a/engines/titanic/messages/messages.cpp +++ b/engines/titanic/messages/messages.cpp @@ -84,7 +84,7 @@ bool CMessage::isMouseMoveMsg() const { } bool CMessage::isDoubleClickMsg() const { - return dynamic_cast(this) != nullptr; + return dynamic_cast(this) != nullptr; } bool CMessage::isEnterRoomMsg() const { diff --git a/engines/titanic/messages/mouse_messages.h b/engines/titanic/messages/mouse_messages.h index 77343fa6cd..6e2a74a046 100644 --- a/engines/titanic/messages/mouse_messages.h +++ b/engines/titanic/messages/mouse_messages.h @@ -108,19 +108,19 @@ public: } }; -MSGTARGET(CMouseButtonDoubleClickMsg); -class CMouseButtonDoubleClickMsg : public CMouseButtonMsg { +MSGTARGET(CMouseDoubleClickMsg); +class CMouseDoubleClickMsg : public CMouseButtonMsg { public: CLASSDEF - CMouseButtonDoubleClickMsg() : CMouseButtonMsg() {} - CMouseButtonDoubleClickMsg(const Point &pt, int buttons) : CMouseButtonMsg(pt, buttons) {} + CMouseDoubleClickMsg() : CMouseButtonMsg() {} + CMouseDoubleClickMsg(const Point &pt, int buttons) : CMouseButtonMsg(pt, buttons) {} static bool isSupportedBy(const CTreeItem *item) { - return dynamic_cast(item) != nullptr; + return dynamic_cast(item) != nullptr; } - virtual bool handleMessage(const CMouseButtonDoubleClickMsg &msg) { return false; } + virtual bool handleMessage(const CMouseDoubleClickMsg &msg) { return false; } virtual bool perform(CTreeItem *treeItem) { - CMouseButtonDoubleClickMsg *dest = dynamic_cast(treeItem); + CMouseDoubleClickMsg *dest = dynamic_cast(treeItem); return dest != nullptr && dest->handleMessage(*this); } }; diff --git a/engines/titanic/mouse_cursor.cpp b/engines/titanic/mouse_cursor.cpp index 578bf9981f..54c9ce8fbd 100644 --- a/engines/titanic/mouse_cursor.cpp +++ b/engines/titanic/mouse_cursor.cpp @@ -20,25 +20,80 @@ * */ +#include "graphics/cursorman.h" #include "common/textconsole.h" #include "titanic/mouse_cursor.h" +#include "titanic/movie.h" +#include "titanic/screen_manager.h" +#include "titanic/titanic.h" +#include "titanic/video_surface.h" +#include "titanic/core/resource_key.h" namespace Titanic { +static const int CURSOR_DATA[NUM_CURSORS][4] = { + { 1, 136, 19, 18 }, + { 2, 139, 1, 1 }, + { 3, 140, 32, 1 }, + { 4, 137, 13, 0 }, + { 5, 145, 13, 0 }, + { 6, 144, 13, 22 }, + { 7, 137, 14, 0 }, + { 8, 148, 22, 40 }, + { 9, 136, 19, 18 }, + { 10, 143, 11, 11 }, + { 11, 146, 11, 11 }, + { 12, 136, 19, 18 }, + { 13, 136, 19, 25 }, + { 14, 136, 13, 22 }, + { 15, 138, 20, 28 } +}; + +CMouseCursor::CMouseCursor(CScreenManager *screenManager) : + _screenManager(screenManager), _cursorId(CURSOR_1) { + loadCursorImages(); +} + +CMouseCursor::~CMouseCursor() { + for (int idx = 0; idx < NUM_CURSORS; ++idx) + delete _cursors[idx]._videoSurface; +} + +void CMouseCursor::loadCursorImages() { + const CString name("ycursors.avi"); + const CResourceKey key(name); + g_vm->_filesManager.fn4(name); + + // Iterate through each cursor + for (int idx = 0; idx < NUM_CURSORS; ++idx) { + assert(CURSOR_DATA[idx][0] == (idx + 1)); + _cursors[idx]._centroid = Common::Point(CURSOR_DATA[idx][2], + CURSOR_DATA[idx][3]); + + CVideoSurface *surface = _screenManager->createSurface(64, 64); + _cursors[idx]._videoSurface = surface; + + OSMovie movie(key, surface); + movie.setFrame(idx); + _cursors[idx]._ptrUnknown = movie.proc21(); + surface->set40(_cursors[idx]._ptrUnknown); + } +} + void CMouseCursor::show() { - warning("CMouseCursor::show"); + CursorMan.showMouse(true); } void CMouseCursor::hide() { - warning("CMouseCursor::hide"); + CursorMan.showMouse(false); } -void CMouseCursor::setCursorId(int id) { - warning("CMouseCursor::setCursorId"); +void CMouseCursor::setCursor(CursorId cursorId) { + warning("CMouseCursor::setCursor"); } void CMouseCursor::update() { - warning("CMouseCursor::update"); + // No implementation needed } } // End of namespace Titanic diff --git a/engines/titanic/mouse_cursor.h b/engines/titanic/mouse_cursor.h index c6df65d096..507f4ecc17 100644 --- a/engines/titanic/mouse_cursor.h +++ b/engines/titanic/mouse_cursor.h @@ -24,14 +24,66 @@ #define TITANIC_MOUSE_CURSOR_H #include "common/scummsys.h" +#include "common/rect.h" namespace Titanic { +#define NUM_CURSORS 15 + +enum CursorId { + CURSOR_1 = 1, + CURSOR_2 = 3, + CURSOR_3 = 3, + CURSOR_4 = 4, + CURSOR_5 = 5, + CURSOR_6 = 6, + CURSOR_7 = 7, + CURSOR_8 = 8, + CURSOR_9 = 9, + CURSOR_10 = 10, + CURSOR_11 = 11, + CURSOR_12 = 12, + CURSOR_13 = 13, + CURSOR_14 = 14, + CURSOR_15 = 15 +}; + +class CScreenManager; +class CVideoSurface; + class CMouseCursor { + struct CursorEntry { + CVideoSurface *_videoSurface; + void *_ptrUnknown; + Common::Point _centroid; + }; +private: + CScreenManager *_screenManager; + CursorId _cursorId; + CursorEntry _cursors[NUM_CURSORS]; + + /** + * Load the images for each cursor + */ + void loadCursorImages(); public: + CMouseCursor(CScreenManager *screenManager); + ~CMouseCursor(); + + /** + * Make the mouse cursor visible + */ void show(); + + /** + * Hide the mouse cursor + */ void hide(); - void setCursorId(int id); + + /** + * Set the cursor + */ + void setCursor(CursorId cursorId); /** * Updates the mouse cursor diff --git a/engines/titanic/movie.cpp b/engines/titanic/movie.cpp index 1eaeac638d..a41f0f4bc7 100644 --- a/engines/titanic/movie.cpp +++ b/engines/titanic/movie.cpp @@ -24,5 +24,69 @@ namespace Titanic { +OSMovie::OSMovie(const CResourceKey &name, CVideoSurface *surface) { + +} + +void OSMovie::proc8() { + warning("TODO: OSMovie::proc8"); +} + +void OSMovie::proc9() { + warning("TODO: OSMovie::proc9"); +} + +void OSMovie::proc10() { + warning("TODO: OSMovie::proc10"); +} + +void OSMovie::proc11() { + warning("TODO: OSMovie::proc11"); +} + +void OSMovie::proc12() { + warning("TODO: OSMovie::proc12"); +} + +void OSMovie::proc13() { + warning("TODO: OSMovie::proc13"); +} + +void OSMovie::proc14() { + warning("TODO: OSMovie::proc14"); +} + +void OSMovie::proc15() { + warning("TODO: OSMovie::proc15"); +} + +void OSMovie::proc16() { + warning("TODO: OSMovie::proc16"); +} + +void OSMovie::proc17() { + warning("TODO: OSMovie::proc17"); +} + +void OSMovie::proc18() { + warning("TODO: OSMovie::proc18"); +} + +void OSMovie::proc19() { + warning("TODO: OSMovie::proc19"); +} + +void OSMovie::proc20() { + warning("TODO: OSMovie::proc20"); +} + +void *OSMovie::proc21() { + warning("TODO: OSMovie::proc21"); + return nullptr; +} + +void OSMovie::setFrame(uint frameNumber) { + +} } // End of namespace Titanic diff --git a/engines/titanic/movie.h b/engines/titanic/movie.h index a213b7b891..1430e249e5 100644 --- a/engines/titanic/movie.h +++ b/engines/titanic/movie.h @@ -24,11 +24,52 @@ #define TITANIC_MOVIE_H #include "titanic/core/list.h" +#include "titanic/core/resource_key.h" +#include "titanic/video_surface.h" namespace Titanic { class CMovie : public ListItem { public: + virtual void proc8() = 0; + virtual void proc9() = 0; + virtual void proc10() = 0; + virtual void proc11() = 0; + virtual void proc12() = 0; + virtual void proc13() = 0; + virtual void proc14() = 0; + virtual void proc15() = 0; + virtual void proc16() = 0; + virtual void proc17() = 0; + virtual void proc18() = 0; + virtual void proc19() = 0; + virtual void proc20() = 0; + virtual void *proc21() = 0; +}; + +class OSMovie : public CMovie { +public: + OSMovie(const CResourceKey &name, CVideoSurface *surface); + + virtual void proc8(); + virtual void proc9(); + virtual void proc10(); + virtual void proc11(); + virtual void proc12(); + virtual void proc13(); + virtual void proc14(); + virtual void proc15(); + virtual void proc16(); + virtual void proc17(); + virtual void proc18(); + virtual void proc19(); + virtual void proc20(); + virtual void *proc21(); + + /** + * Set the current frame number + */ + void setFrame(uint frameNumber); }; } // End of namespace Titanic diff --git a/engines/titanic/screen_manager.cpp b/engines/titanic/screen_manager.cpp index 11063be2b6..5e38eca2d8 100644 --- a/engines/titanic/screen_manager.cpp +++ b/engines/titanic/screen_manager.cpp @@ -222,7 +222,7 @@ void OSScreenManager::loadCursors() { hideCursor(); delete _mouseCursor; } - _mouseCursor = new CMouseCursor(); + _mouseCursor = new CMouseCursor(this); showCursor(); if (!_textCursor) { diff --git a/engines/titanic/video_surface.cpp b/engines/titanic/video_surface.cpp index 0b935292b1..ef8d7a872f 100644 --- a/engines/titanic/video_surface.cpp +++ b/engines/titanic/video_surface.cpp @@ -31,7 +31,7 @@ int CVideoSurface::_videoSurfaceCounter = 0; CVideoSurface::CVideoSurface(CScreenManager *screenManager) : _screenManager(screenManager), _rawSurface(nullptr), _field34(nullptr), _pendingLoad(false), _blitStyleFlag(false), _blitFlag(false), - _field40(0), _field44(4), _field48(0), _field50(1) { + _field40(nullptr), _field44(4), _field48(0), _field50(1) { _videoSurfaceNum = _videoSurfaceCounter++; } diff --git a/engines/titanic/video_surface.h b/engines/titanic/video_surface.h index d89d3201c2..8d0b312ef0 100644 --- a/engines/titanic/video_surface.h +++ b/engines/titanic/video_surface.h @@ -58,7 +58,7 @@ protected: Graphics::ManagedSurface *_rawSurface; void *_field34; bool _pendingLoad; - int _field40; + void *_field40; int _field44; int _field48; int _videoSurfaceNum; @@ -157,6 +157,8 @@ public: * Blit from another surface */ void blitFrom(const Point &destPos, CVideoSurface *src, const Rect *srcRect = nullptr); + + void set40(void *v) { _field40 = v; } }; class OSVideoSurface : public CVideoSurface { -- cgit v1.2.3