1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
/* 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 "titanic/support/mouse_cursor.h"
#include "titanic/support/screen_manager.h"
#include "titanic/support/transparency_surface.h"
#include "titanic/support/video_surface.h"
#include "titanic/events.h"
#include "titanic/input_handler.h"
#include "titanic/messages/mouse_messages.h"
#include "titanic/titanic.h"
#include "graphics/cursorman.h"
#include "graphics/screen.h"
namespace Titanic {
#define CURSOR_SIZE 64
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::CursorEntry::~CursorEntry() {
delete _surface;
}
CMouseCursor::CMouseCursor(CScreenManager *screenManager) :
_screenManager(screenManager), _cursorId(CURSOR_HOURGLASS), _hideCounter(0),
_busyCount(0), _cursorSuppressed(false), _setCursorCount(0), _inputEnabled(true), _fieldE8(0) {
loadCursorImages();
setCursor(CURSOR_ARROW);
CursorMan.showMouse(true);
}
CMouseCursor::~CMouseCursor() {
}
void CMouseCursor::loadCursorImages() {
const CResourceKey key("ycursors.avi");
// Iterate through getting 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]);
// Create the surface
CVideoSurface *surface = _screenManager->createSurface(CURSOR_SIZE, CURSOR_SIZE);
// Open the cursors video and move to the given frame
OSMovie *movie = new OSMovie(key, surface);
movie->setFrame(idx);
Graphics::ManagedSurface *transSurface = movie->duplicateTransparency();
// Create a managed surface to hold the RGBA version of the cursor
Graphics::PixelFormat rgbaFormat(4, 8, 8, 8, 8, 24, 16, 8, 0);
_cursors[idx]._surface = new Graphics::ManagedSurface(CURSOR_SIZE, CURSOR_SIZE, rgbaFormat);
// Copy the cursor from the movie's video surface
surface->lock();
_cursors[idx]._surface->blitFrom(*surface->getRawSurface());
surface->unlock();
// We need to separately merge in the transparency surface
for (int y = 0; y < CURSOR_SIZE; ++y) {
const byte *srcP = (const byte *)transSurface->getBasePtr(0, y);
uint32 *destP = (uint32 *)_cursors[idx]._surface->getBasePtr(0, y);
for (int x = 0; x < CURSOR_SIZE; ++x, ++srcP, ++destP)
*destP = (*destP & ~0xff) | *srcP;
}
delete movie;
delete transSurface;
delete surface;
}
}
void CMouseCursor::incBusyCount() {
if (_busyCount == 0)
setCursor(CURSOR_HOURGLASS);
++_busyCount;
}
void CMouseCursor::decBusyCount() {
assert(_busyCount > 0);
if (--_busyCount == 0)
setCursor(CURSOR_ARROW);
}
void CMouseCursor::incHideCounter() {
if (_hideCounter++ == 0)
CursorMan.showMouse(false);
}
void CMouseCursor::decHideCounter() {
--_hideCounter;
assert(_hideCounter >= 0);
if (_hideCounter == 0)
CursorMan.showMouse(true);
}
void CMouseCursor::suppressCursor() {
_cursorSuppressed = true;
CursorMan.showMouse(false);
}
void CMouseCursor::unsuppressCursor() {
_cursorSuppressed = false;
if (_hideCounter == 0)
CursorMan.showMouse(true);
}
void CMouseCursor::setCursor(CursorId cursorId) {
++_setCursorCount;
if (cursorId != _cursorId && _busyCount == 0) {
const CursorEntry &ce = _cursors[cursorId - 1];
_cursorId = cursorId;
// Set the cursor
CursorMan.replaceCursor(ce._surface->getPixels(), CURSOR_SIZE, CURSOR_SIZE,
ce._centroid.x, ce._centroid.y, 0, false, &ce._surface->format);
}
}
void CMouseCursor::update() {
if (!_inputEnabled && _moveStartTime) {
uint32 time = CLIP(g_system->getMillis(), _moveStartTime, _moveEndTime);
Common::Point pt(
_moveStartPos.x + (_moveDestPos.x - _moveStartPos.x) *
(int)(time - _moveStartTime) / (int)(_moveEndTime - _moveStartTime),
_moveStartPos.y + (_moveDestPos.y - _moveStartPos.y) *
(int)(time - _moveStartTime) / (int)(_moveEndTime - _moveStartTime)
);
if (pt != g_vm->_events->getMousePos()) {
g_vm->_events->setMousePos(pt);
CInputHandler &inputHandler = *CScreenManager::_screenManagerPtr->_inputHandler;
CMouseMoveMsg msg(pt, 0);
inputHandler.handleMessage(msg, false);
}
if (time == _moveEndTime)
_moveStartTime = _moveEndTime = 0;
}
}
void CMouseCursor::disableControl() {
_inputEnabled = false;
CScreenManager::_screenManagerPtr->_inputHandler->incLockCount();
}
void CMouseCursor::enableControl() {
_inputEnabled = true;
_fieldE8 = 0;
CScreenManager::_screenManagerPtr->_inputHandler->decLockCount();
}
void CMouseCursor::setPosition(const Point &pt, double duration) {
_moveStartPos = g_vm->_events->getMousePos();
_moveDestPos = pt;
_moveStartTime = g_system->getMillis();
_moveEndTime = _moveStartTime + (int)duration;
update();
}
} // End of namespace Titanic
|