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
|
/* 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.
*
* $URL$
* $Id$
*
*/
#include "draci/draci.h"
#include "draci/mouse.h"
#include "draci/barchive.h"
namespace Draci {
Mouse::Mouse(DraciEngine *vm) {
_x = 0;
_y = 0;
_lButton = false;
_rButton = false;
_cursorType = kUninitializedCursor;
_vm = vm;
}
void Mouse::handleEvent(Common::Event event) {
switch (event.type) {
case Common::EVENT_LBUTTONDOWN:
debugC(6, kDraciGeneralDebugLevel, "Left button down (x: %u y: %u)", _x, _y);
_lButton = true;
break;
case Common::EVENT_LBUTTONUP:
debugC(6, kDraciGeneralDebugLevel, "Left button up (x: %u y: %u)", _x, _y);
// Don't set _lButton to false, because some touchpads generate
// down and up at such a quick succession, that they will
// cancel each other in the same call of handleEvents(). Let
// the game clear this flag by calling lButtonSet() instead.
break;
case Common::EVENT_RBUTTONDOWN:
debugC(6, kDraciGeneralDebugLevel, "Right button down (x: %u y: %u)", _x, _y);
_rButton = true;
break;
case Common::EVENT_RBUTTONUP:
debugC(6, kDraciGeneralDebugLevel, "Right button up (x: %u y: %u)", _x, _y);
break;
case Common::EVENT_MOUSEMOVE:
debugC(6, kDraciGeneralDebugLevel, "Mouse move (x: %u y: %u)", _x, _y);
_x = (uint16) event.mouse.x;
_y = (uint16) event.mouse.y;
break;
default:
break;
}
}
void Mouse::cursorOn() {
CursorMan.showMouse(true);
}
void Mouse::cursorOff() {
CursorMan.showMouse(false);
}
bool Mouse::isCursorOn() const {
return CursorMan.isVisible();
}
void Mouse::setPosition(uint16 x, uint16 y) {
_vm->_system->warpMouse(x, y);
}
void Mouse::setCursorType(CursorType cur) {
if (cur == getCursorType()) {
return;
}
_cursorType = cur;
const BAFile *f;
f = _vm->_iconsArchive->getFile(cur);
Sprite sp(f->_data, f->_length, 0, 0, true);
CursorMan.replaceCursorPalette(_vm->_screen->getPalette(), 0, kNumColours);
CursorMan.replaceCursor(sp.getBuffer(), sp.getWidth(), sp.getHeight(),
sp.getWidth() / 2, sp.getHeight() / 2);
}
void Mouse::loadItemCursor(int itemID, bool highlighted) {
int archiveIndex = 2 * itemID + highlighted;
CursorType newCursor = static_cast<CursorType> (kItemCursor + archiveIndex);
if (newCursor == getCursorType()) {
return;
}
_cursorType = newCursor;
const BAFile *f;
f = _vm->_itemImagesArchive->getFile(archiveIndex);
Sprite sp(f->_data, f->_length, 0, 0, true);
CursorMan.replaceCursorPalette(_vm->_screen->getPalette(), 0, kNumColours);
CursorMan.replaceCursor(sp.getBuffer(), sp.getWidth(), sp.getHeight(),
sp.getWidth() / 2, sp.getHeight() / 2);
}
}
|