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
|
/* ScummVM - Scumm Interpreter
* Copyright (C) 2005-2006 The ScummVM project
*
* 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 "lure/events.h"
#include "lure/system.h"
#include "lure/res.h"
namespace Lure {
static Mouse *int_mouse = NULL;
Mouse &Mouse::getReference() {
return *int_mouse;
}
Mouse::Mouse() {
int_mouse = this;
_lButton = false;
_rButton = false;
_cursorNum = 0;
setCursorNum(0);
}
Mouse::~Mouse() {
}
void Mouse::handleEvent(OSystem::Event event) {
_x = (int16) event.mouse.x;
_y = (int16) event.mouse.y;
switch (event.type) {
case OSystem::EVENT_LBUTTONDOWN:
_lButton = true;
break;
case OSystem::EVENT_LBUTTONUP:
_lButton = false;
break;
case OSystem::EVENT_RBUTTONDOWN:
_rButton = true;
break;
case OSystem::EVENT_RBUTTONUP:
_rButton = false;
break;
default:
break;
}
}
void Mouse::cursorOn() {
System::getReference().showMouse(true);
}
void Mouse::cursorOff() {
System::getReference().showMouse(false);
}
void Mouse::setCursorNum(uint8 cursorNum) {
int hotspotX = 7, hotspotY = 7;
if ((cursorNum == CURSOR_ARROW) || (cursorNum == CURSOR_MENUBAR)) {
hotspotX = 0;
hotspotY = 0;
}
setCursorNum(cursorNum, hotspotX, hotspotY);
}
void Mouse::setCursorNum(uint8 cursorNum, int hotspotX, int hotspotY) {
Resources &res = Resources::getReference();
OSystem &system = System::getReference();
_cursorNum = cursorNum;
byte *cursorAddr = res.getCursor(cursorNum);
system.setMouseCursor(cursorAddr, CURSOR_WIDTH, CURSOR_HEIGHT, hotspotX, hotspotY, 0);
}
void Mouse::setPosition(int newX, int newY) {
System::getReference().warpMouse(newX, newY);
}
void Mouse::waitForRelease() {
OSystem &system = System::getReference();
Events &e = Events::getReference();
do {
e.pollEvent();
system.delayMillis(20);
} while (!e.quitFlag && (lButton() || rButton()));
}
/*--------------------------------------------------------------------------*/
static Events *int_events = NULL;
Events::Events() {
int_events = this;
quitFlag = false;
}
Events &Events::getReference() {
return *int_events;
}
bool Events::pollEvent() {
if (!System::getReference().pollEvent(_event)) return false;
// Handle keypress
switch (_event.type) {
case OSystem::EVENT_QUIT:
quitFlag = true;
break;
case OSystem::EVENT_LBUTTONDOWN:
case OSystem::EVENT_LBUTTONUP:
case OSystem::EVENT_RBUTTONDOWN:
case OSystem::EVENT_RBUTTONUP:
case OSystem::EVENT_MOUSEMOVE:
case OSystem::EVENT_WHEELUP:
case OSystem::EVENT_WHEELDOWN:
Mouse::getReference().handleEvent(_event);
break;
default:
break;
}
return true;
}
void Events::waitForPress() {
OSystem &system = System::getReference();
bool keyButton = false;
while (!keyButton) {
if (pollEvent()) {
if (_event.type == OSystem::EVENT_QUIT) return;
else if (_event.type == OSystem::EVENT_KEYDOWN) keyButton = true;
else if ((_event.type == OSystem::EVENT_LBUTTONDOWN) ||
(_event.type == OSystem::EVENT_RBUTTONDOWN)) {
keyButton = true;
Mouse::getReference().waitForRelease();
}
}
system.delayMillis(20);
}
}
} // end of namespace Lure
|