diff options
author | johndoe123 | 2011-07-11 12:21:56 +0000 |
---|---|---|
committer | Willem Jan Palenstijn | 2013-05-08 20:38:47 +0200 |
commit | 9f6e6c6f7fde2e1c927deee732cb03cf34d18455 (patch) | |
tree | fe1d446c2f691865ad76ef63db18b30962951193 /engines/neverhood | |
parent | c39fb81951dd1a442c9811ba7ce202fa3619be70 (diff) | |
download | scummvm-rg350-9f6e6c6f7fde2e1c927deee732cb03cf34d18455.tar.gz scummvm-rg350-9f6e6c6f7fde2e1c927deee732cb03cf34d18455.tar.bz2 scummvm-rg350-9f6e6c6f7fde2e1c927deee732cb03cf34d18455.zip |
NEVERHOOD: Implement MouseCursorResource and Mouse433 mouse cursor
Diffstat (limited to 'engines/neverhood')
-rw-r--r-- | engines/neverhood/gamemodule.cpp | 10 | ||||
-rw-r--r-- | engines/neverhood/gamemodule.h | 1 | ||||
-rw-r--r-- | engines/neverhood/graphics.cpp | 6 | ||||
-rw-r--r-- | engines/neverhood/graphics.h | 2 | ||||
-rw-r--r-- | engines/neverhood/module.h | 1 | ||||
-rw-r--r-- | engines/neverhood/module.mk | 1 | ||||
-rw-r--r-- | engines/neverhood/module1000.cpp | 2 | ||||
-rw-r--r-- | engines/neverhood/mouse.cpp | 131 | ||||
-rw-r--r-- | engines/neverhood/mouse.h | 48 | ||||
-rw-r--r-- | engines/neverhood/neverhood.cpp | 1 | ||||
-rw-r--r-- | engines/neverhood/neverhood.h | 4 | ||||
-rw-r--r-- | engines/neverhood/resource.cpp | 52 | ||||
-rw-r--r-- | engines/neverhood/resource.h | 18 | ||||
-rw-r--r-- | engines/neverhood/scene.cpp | 26 | ||||
-rw-r--r-- | engines/neverhood/scene.h | 2 |
15 files changed, 286 insertions, 19 deletions
diff --git a/engines/neverhood/gamemodule.cpp b/engines/neverhood/gamemodule.cpp index 9989bba727..c2d3e6d887 100644 --- a/engines/neverhood/gamemodule.cpp +++ b/engines/neverhood/gamemodule.cpp @@ -58,6 +58,16 @@ GameModule::~GameModule() { } +void GameModule::handleMouseMove(int16 x, int16 y) { + if (_childObject) { + NPoint mousePos; + mousePos.x = x; + mousePos.y = y; + debug("GameModule::handleMouseMove(%d, %d)", x, y); + _childObject->sendPointMessage(0, mousePos, this); + } +} + void GameModule::handleMouseDown(int16 x, int16 y) { if (_childObject) { NPoint mousePos; diff --git a/engines/neverhood/gamemodule.h b/engines/neverhood/gamemodule.h index 7fce9ebaea..876506ce0c 100644 --- a/engines/neverhood/gamemodule.h +++ b/engines/neverhood/gamemodule.h @@ -34,6 +34,7 @@ class GameModule : public Module { public: GameModule(NeverhoodEngine *vm); virtual ~GameModule(); + void handleMouseMove(int16 x, int16 y); void handleMouseDown(int16 x, int16 y); protected: Entity *_prevChildObject; diff --git a/engines/neverhood/graphics.cpp b/engines/neverhood/graphics.cpp index f6ae118fa6..68134bda97 100644 --- a/engines/neverhood/graphics.cpp +++ b/engines/neverhood/graphics.cpp @@ -101,6 +101,12 @@ void BaseSurface::drawAnimResource(AnimResource &animResource, uint frameIndex, } } +void BaseSurface::drawMouseCursorResource(MouseCursorResource &mouseCursorResource, int frameNum) { + if (frameNum < 3) { + mouseCursorResource.draw(frameNum, (byte*)_surface->pixels, _surface->pitch); + } +} + // Misc void parseBitmapResource(byte *sprite, bool *rle, NDimensions *dimensions, NPoint *position, byte **palette, byte **pixels) { diff --git a/engines/neverhood/graphics.h b/engines/neverhood/graphics.h index 59db1e5ee5..2bddea3156 100644 --- a/engines/neverhood/graphics.h +++ b/engines/neverhood/graphics.h @@ -52,6 +52,7 @@ struct NDrawRect { class AnimResource; class SpriteResource; +class MouseCursorResource; // NOTE: "Restore" methods aren't need in the reimplementation as they're DirectDraw-specific @@ -65,6 +66,7 @@ public: void drawSpriteResource(SpriteResource &spriteResource); void drawSpriteResourceEx(SpriteResource &spriteResource, bool flipX, bool flipY, int16 width, int16 height); void drawAnimResource(AnimResource &animResource, uint frameIndex, bool flipX, bool flipY, int16 width, int16 height); + void drawMouseCursorResource(MouseCursorResource &mouseCursorResource, int frameNum); int getPriority() const { return _priority; } void setPriority(int priority) { _priority = priority; } NDrawRect& getDrawRect() { return _drawRect; } diff --git a/engines/neverhood/module.h b/engines/neverhood/module.h index 7911e44072..790130a3e4 100644 --- a/engines/neverhood/module.h +++ b/engines/neverhood/module.h @@ -30,6 +30,7 @@ #include "neverhood/collisionman.h" #include "neverhood/entity.h" #include "neverhood/graphics.h" +#include "neverhood/mouse.h" #include "neverhood/palette.h" #include "neverhood/screen.h" diff --git a/engines/neverhood/module.mk b/engines/neverhood/module.mk index 7961bc9a2a..e39041e24d 100644 --- a/engines/neverhood/module.mk +++ b/engines/neverhood/module.mk @@ -12,6 +12,7 @@ MODULE_OBJS = \ module.o \ module1000.o \ module1500.o \ + mouse.o \ neverhood.o \ palette.o \ resource.o \ diff --git a/engines/neverhood/module1000.cpp b/engines/neverhood/module1000.cpp index d31044c517..547f8c1ee0 100644 --- a/engines/neverhood/module1000.cpp +++ b/engines/neverhood/module1000.cpp @@ -492,7 +492,7 @@ Scene1001::Scene1001(NeverhoodEngine *vm, Module *parentModule, int which) _background = addBackground(new DirtyBackground(_vm, 0x4086520E, 0, 0)); _palette = new Palette(_vm, 0x4086520E); _palette->usePalette(); - // TODO _mouseCursor = addSprite(new Class433(_vm, 6520A400, 0)); + _mouseCursor = addSprite(new Mouse433(_vm, 0x6520A400, NULL)); if (which < 0) { setRectList(0x004B49F0); diff --git a/engines/neverhood/mouse.cpp b/engines/neverhood/mouse.cpp new file mode 100644 index 0000000000..5693048ed5 --- /dev/null +++ b/engines/neverhood/mouse.cpp @@ -0,0 +1,131 @@ +/* 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 "neverhood/mouse.h" + +namespace Neverhood { + +// TODO: Use CursorMan + +Mouse433::Mouse433(NeverhoodEngine *vm, uint32 fileHash, NRect *mouseRect) + : StaticSprite(vm, 2000), _mouseCursorResource(vm), _frameNum(0) { + + debug("Mouse433::Mouse433(%08X)", fileHash); + + if (mouseRect) { + _mouseRect = *mouseRect; + } else { + _mouseRect.x1 = -1; + _mouseRect.y1 = -1; + _mouseRect.x2 = -1; + _mouseRect.y2 = -1; + } + _mouseCursorResource.load(fileHash); + _x = _vm->getMouseX(); + _y = _vm->getMouseY(); + if (_x >= _mouseRect.x1 && _x <= _mouseRect.x2 && + _y >= _mouseRect.y1 && _y <= _mouseRect.y2) { + _mouseCursorResource.setCursorNum(1); + } else { + _mouseCursorResource.setCursorNum(4); + } + createSurface(2000, 32, 32); + SetUpdateHandler(&Mouse433::update); + SetMessageHandler(&Mouse433::handleMessage); + _drawRect.x = 0; + _drawRect.y = 0; + _drawRect.width = 32; + _drawRect.height = 32; + _deltaRect.x = 0; + _deltaRect.y = 0; + _deltaRect.width = 32; + _deltaRect.height = 32; + processDelta(); + _needRefresh = true; + updateCursor(); +} + +void Mouse433::load(uint32 fileHash) { + _mouseCursorResource.load(fileHash); + _needRefresh = true; +} + +void Mouse433::update() { + debug("Mouse433::update()"); + updateCursor(); + _frameNum++; + if (_frameNum >= 6) + _frameNum = 0; + _needRefresh = _frameNum % 2 == 0; +} + +uint32 Mouse433::handleMessage(int messageNum, const MessageParam ¶m, Entity *sender) { + debug("Mouse433::handleMessage(%04X)", messageNum); + uint32 messageResult = 0; + if (messageNum != 5) { + messageResult = Sprite::handleMessage(messageNum, param, sender); + switch (messageNum) { + case 0x4002: + _x = param.asPoint().x; + _y = param.asPoint().y; + if (_x >= _mouseRect.x1 && _x <= _mouseRect.x2 && + _y >= _mouseRect.y1 && _y <= _mouseRect.y2) { + _mouseCursorResource.setCursorNum(1); + } else { + _mouseCursorResource.setCursorNum(4); + } + processDelta(); + break; + } + } else { + // TODO: Debug stuff + } + return messageResult; +} + +void Mouse433::updateCursor() { + debug("Mouse433::updateCursor()"); + + if (!_surface) + return; + + if (_doDeltaX) { + _surface->getDrawRect().x = filterX(_x - _drawRect.width - _drawRect.x + 1); + } else { + _surface->getDrawRect().x = filterX(_x + _drawRect.x); + } + + if (_doDeltaY) { + _surface->getDrawRect().y = filterY(_y - _drawRect.height - _drawRect.y + 1); + } else { + _surface->getDrawRect().y = filterY(_y + _drawRect.y); + } + + if (_needRefresh) { + _needRefresh = false; + _drawRect = _mouseCursorResource.getRect(); + _surface->drawMouseCursorResource(_mouseCursorResource, _frameNum / 2); + } + +} + +} // End of namespace Neverhood diff --git a/engines/neverhood/mouse.h b/engines/neverhood/mouse.h new file mode 100644 index 0000000000..d03588f4e0 --- /dev/null +++ b/engines/neverhood/mouse.h @@ -0,0 +1,48 @@ +/* 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 NEVERHOOD_MOUSE_H +#define NEVERHOOD_MOUSE_H + +#include "neverhood/neverhood.h" +#include "neverhood/sprite.h" +#include "neverhood/graphics.h" +#include "neverhood/resource.h" + +namespace Neverhood { + +class Mouse433 : public StaticSprite { +public: + Mouse433(NeverhoodEngine *vm, uint32 fileHash, NRect *mouseRect); + void load(uint32 fileHash); +protected: + MouseCursorResource _mouseCursorResource; + int _frameNum; + NRect _mouseRect; + void update(); + uint32 handleMessage(int messageNum, const MessageParam ¶m, Entity *sender); + void updateCursor(); +}; + +} // End of namespace Neverhood + +#endif /* NEVERHOOD_MOUSE_H */ diff --git a/engines/neverhood/neverhood.cpp b/engines/neverhood/neverhood.cpp index 77483c52ca..ab3cdc6a8f 100644 --- a/engines/neverhood/neverhood.cpp +++ b/engines/neverhood/neverhood.cpp @@ -158,6 +158,7 @@ Common::Error NeverhoodEngine::run() { case Common::EVENT_MOUSEMOVE: _mouseX = event.mouse.x; _mouseY = event.mouse.y; + _gameModule->handleMouseMove(event.mouse.x, event.mouse.y); break; case Common::EVENT_LBUTTONDOWN: diff --git a/engines/neverhood/neverhood.h b/engines/neverhood/neverhood.h index 0070f0867e..4f6131a746 100644 --- a/engines/neverhood/neverhood.h +++ b/engines/neverhood/neverhood.h @@ -69,7 +69,7 @@ public: Common::RandomSource *_rnd; - int _mouseX, _mouseY; + int16 _mouseX, _mouseY; Common::KeyCode _keyState; uint16 _buttonState; @@ -116,6 +116,8 @@ public: #endif GameState& gameState() { return _gameState; } + int16 getMouseX() const { return _mouseX; } + int16 getMouseY() const { return _mouseY; } public: diff --git a/engines/neverhood/resource.cpp b/engines/neverhood/resource.cpp index 83078afe60..841827a4bd 100644 --- a/engines/neverhood/resource.cpp +++ b/engines/neverhood/resource.cpp @@ -297,6 +297,58 @@ int16 AnimResource::getFrameIndex(uint32 frameHash) { return -1; } +MouseCursorResource::MouseCursorResource(NeverhoodEngine *vm) + : _cursorSprite(vm), _cursorNum(4), _currFileHash(0) { + + _rect.width = 32; + _rect.height = 32; +} + +void MouseCursorResource::load(uint32 fileHash) { + if (_currFileHash != fileHash) { + if (_cursorSprite.load(fileHash) && !_cursorSprite.isRle() && + _cursorSprite.getDimensions().width == 96 && _cursorSprite.getDimensions().height == 224) { + debug("load ok"); + _currFileHash = fileHash; + } else { + unload(); + } + } +} + +void MouseCursorResource::unload() { + _cursorSprite.unload(); + _currFileHash = 0; + _cursorNum = 4; +} + +NDrawRect& MouseCursorResource::getRect() { + static const NPoint kCursorHotSpots[] = { + {-15, -5}, + {-17, -25}, + {-17, -30}, + {-14, -1}, + {-3, -7}, + {-30, -18}, + {-1, -18} + }; + _rect.x = kCursorHotSpots[_cursorNum].x; + _rect.y = kCursorHotSpots[_cursorNum].y; + return _rect; +} + +void MouseCursorResource::draw(int frameNum, byte *dest, int destPitch) { + if (_cursorSprite.getPixels()) { + int sourcePitch = (_cursorSprite.getDimensions().width + 3) & 0xFFFC; // 4 byte alignment + byte *source = _cursorSprite.getPixels() + _cursorNum * (sourcePitch * 32) + frameNum * 32; + for (int16 yc = 0; yc < 32; yc++) { + memcpy(dest, source, 32); + source += sourcePitch; + dest += destPitch; + } + } +} + SoundResource::SoundResource(NeverhoodEngine *vm) : _vm(vm) { } diff --git a/engines/neverhood/resource.h b/engines/neverhood/resource.h index 7540956954..b2a98c7670 100644 --- a/engines/neverhood/resource.h +++ b/engines/neverhood/resource.h @@ -38,6 +38,8 @@ public: void unload(); const NDimensions& getDimensions() { return _dimensions; } NPoint& getPosition() { return _position; } + bool isRle() const { return _rle; } + byte *getPixels() const { return _pixels; } protected: NeverhoodEngine *_vm; int _resourceHandle; @@ -99,6 +101,22 @@ protected: Common::Array<AnimFrameInfo> _frames; }; +class MouseCursorResource { +public: + MouseCursorResource(NeverhoodEngine *vm); + void load(uint32 fileHash); + void unload(); + NDrawRect& getRect(); + void draw(int frameNum, byte *dest, int destPitch); + int getCursorNum() const { return _cursorNum; } + void setCursorNum(int value) { _cursorNum = value; } +protected: + int _cursorNum; + SpriteResource _cursorSprite; + NDrawRect _rect; + uint32 _currFileHash; +}; + // TODO: Dummy class atm class SoundResource { diff --git a/engines/neverhood/scene.cpp b/engines/neverhood/scene.cpp index ebf92d8b63..3851cfa3ad 100644 --- a/engines/neverhood/scene.cpp +++ b/engines/neverhood/scene.cpp @@ -38,7 +38,7 @@ Scene::Scene(NeverhoodEngine *vm, Module *parentModule, bool clearHitRects) _rectList = NULL; // TODO _someRects = NULL; _klayman = NULL; - // TODO _mouseSprite = NULL; + _mouseCursor = NULL; _palette = NULL; _background = NULL; // TODO _field_8E = -1; @@ -221,11 +221,9 @@ void Scene::update() { uint32 Scene::handleMessage(int messageNum, const MessageParam ¶m, Entity *sender) { switch (messageNum) { case 0: // mouse moved -#if 0 - if (_mouseSprite && _mouseSprite->hasMessageHandler()) - _mouseSprite->sendMessage(0x4002, param, this); - queryPositionSomeRects(param.asPoint().x, param.asPoint().y); -#endif + if (_mouseCursor && _mouseCursor->hasMessageHandler()) + _mouseCursor->sendMessage(0x4002, param, this); + // TODO queryPositionSomeRects(param.asPoint().x, param.asPoint().y); break; case 1: // mouse clicked debug("mouse clicked"); @@ -268,20 +266,16 @@ uint32 Scene::handleMessage(int messageNum, const MessageParam ¶m, Entity *s } break; case 0x101D: -#if 0 - if (_mouseSprite) { - _prevVisible = _mouseSprite->_drawSurface->_visible; - _mouseSprite->_drawSurface->_visible = false; + if (_mouseCursor) { + _prevVisible = _mouseCursor->getSurface()->getVisible(); + _mouseCursor->getSurface()->setVisible(false); } -#endif break; case 0x101E: -#if 0 - if (_prevVisible && _mouseSprite) { - _mouseSprite->_drawSurface->_visible = true; - _mouseSprite->sendMessage(0x4002, g_Screen->_mousePos, this); + if (_prevVisible && _mouseCursor) { + _mouseCursor->getSurface()->setVisible(false); + // TODO _mouseCursor->sendMessage(0x4002, g_Screen->_mousePos, this); } -#endif break; case 0x1022: setSurfacePriority(((Sprite*)sender)->getSurface(), param.asInteger()); diff --git a/engines/neverhood/scene.h b/engines/neverhood/scene.h index 34f3c1e759..0878380ccd 100644 --- a/engines/neverhood/scene.h +++ b/engines/neverhood/scene.h @@ -68,7 +68,7 @@ protected: // TODO 00000088 someRects dd ? // TODO 0000008C someRectsCount dw ? // TODO 0000008E field_8E dw ? - // TODO 00000094 mouseSprite dd ? + Sprite *_mouseCursor; Klayman *_klayman; Palette *_palette; Background *_background; |