1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #include "common/system.h"
24
25 #include "sludge/cursors.h"
26 #include "sludge/event.h"
27 #include "sludge/graphics.h"
28 #include "sludge/freeze.h"
29 #include "sludge/newfatal.h"
30 #include "sludge/people.h"
31 #include "sludge/sludge.h"
32 #include "sludge/sludger.h"
33
34 namespace Sludge {
35
CursorManager(SludgeEngine * vm)36 CursorManager::CursorManager(SludgeEngine *vm) {
37 _vm = vm;
38 init();
39 }
40
~CursorManager()41 CursorManager::~CursorManager() {
42 kill();
43 }
44
init()45 void CursorManager::init() {
46 _mouseCursorAnim = new PersonaAnimation();
47 _mouseCursorFrameNum = 0;
48 _mouseCursorCountUp = 0;
49 }
50
kill()51 void CursorManager::kill() {
52 if (_mouseCursorAnim) {
53 delete _mouseCursorAnim;
54 _mouseCursorAnim = nullptr;
55 }
56 _mouseCursorAnim = nullptr;
57 }
58
pickAnimCursor(PersonaAnimation * pp)59 void CursorManager::pickAnimCursor(PersonaAnimation *pp) {
60 if (_mouseCursorAnim) {
61 delete _mouseCursorAnim;
62 _mouseCursorAnim = nullptr;
63 }
64 _mouseCursorAnim = pp;
65 _mouseCursorFrameNum = 0;
66 _mouseCursorCountUp = 0;
67 }
68
displayCursor()69 void CursorManager::displayCursor() {
70 if (_mouseCursorAnim && _mouseCursorAnim->numFrames) {
71
72 int spriteNum = _mouseCursorAnim->frames[_mouseCursorFrameNum].frameNum;
73 int flipMe = 0;
74
75 if (spriteNum < 0) {
76 spriteNum = -spriteNum;
77 flipMe = 1;
78 if (spriteNum >= _mouseCursorAnim->theSprites->bank.total)
79 spriteNum = 0;
80 } else {
81 if (spriteNum >= _mouseCursorAnim->theSprites->bank.total)
82 flipMe = 2;
83 }
84
85 if (flipMe != 2) {
86 if (flipMe) {
87 _vm->_gfxMan->flipFontSprite(
88 _vm->_evtMan->mouseX(), _vm->_evtMan->mouseY(),
89 _mouseCursorAnim->theSprites->bank.sprites[spriteNum],
90 _mouseCursorAnim->theSprites->bank.myPalette /* ( spritePalette&) NULL*/);
91 } else {
92 _vm->_gfxMan->fontSprite(
93 _vm->_evtMan->mouseX(), _vm->_evtMan->mouseY(),
94 _mouseCursorAnim->theSprites->bank.sprites[spriteNum],
95 _mouseCursorAnim->theSprites->bank.myPalette /* ( spritePalette&) NULL*/);
96 }
97 }
98
99 if (++_mouseCursorCountUp >= _mouseCursorAnim->frames[_mouseCursorFrameNum].howMany) {
100 _mouseCursorCountUp = 0;
101 _mouseCursorFrameNum++;
102 _mouseCursorFrameNum %= _mouseCursorAnim->numFrames;
103 }
104 }
105 }
106
pasteCursor(int x,int y,PersonaAnimation * c)107 void CursorManager::pasteCursor(int x, int y, PersonaAnimation *c) {
108 if (c->numFrames)
109 _vm->_gfxMan->pasteSpriteToBackDrop(x, y, c->theSprites->bank.sprites[c->frames[0].frameNum], c->theSprites->bank.myPalette);
110 }
111
freeze(FrozenStuffStruct * frozenStuff)112 void CursorManager::freeze(FrozenStuffStruct *frozenStuff) {
113 frozenStuff->mouseCursorAnim = _mouseCursorAnim;
114 frozenStuff->mouseCursorFrameNum = _mouseCursorFrameNum;
115 _mouseCursorAnim = new PersonaAnimation();
116 _mouseCursorFrameNum = 0;
117 }
118
resotre(FrozenStuffStruct * frozenStuff)119 void CursorManager::resotre(FrozenStuffStruct *frozenStuff) {
120 if (_mouseCursorAnim) {
121 delete _mouseCursorAnim;
122 _mouseCursorAnim = nullptr;
123 }
124 _mouseCursorAnim = frozenStuff->mouseCursorAnim;
125 _mouseCursorFrameNum = frozenStuff->mouseCursorFrameNum;
126 }
127
saveCursor(Common::WriteStream * stream)128 void CursorManager::saveCursor(Common::WriteStream *stream) {
129 _mouseCursorAnim->save(stream);
130 stream->writeUint16BE(_mouseCursorFrameNum);
131 }
132
loadCursor(Common::SeekableReadStream * stream)133 bool CursorManager::loadCursor(Common::SeekableReadStream *stream) {
134 _mouseCursorAnim = new PersonaAnimation;
135 if (!checkNew(_mouseCursorAnim))
136 return false;
137 if (!_mouseCursorAnim->load(stream))
138 return false;
139 _mouseCursorFrameNum = stream->readUint16BE();
140 return true;
141 }
142
143 } // End of namespace Sludge
144