forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPointer.js
More file actions
236 lines (176 loc) · 5.71 KB
/
Copy pathPointer.js
File metadata and controls
236 lines (176 loc) · 5.71 KB
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
// Phaser.Input.Pointer
var Class = require('../utils/Class');
// DOM event button value:
// A number representing a given button:
// 0: Main button pressed, usually the left button or the un-initialized state
// 1: Auxiliary button pressed, usually the wheel button or the middle button (if present)
// 2: Secondary button pressed, usually the right button
// 3: Fourth button, typically the Browser Back button
// 4: Fifth button, typically the Browser Forward button
// For a mouse configured for left-handed use, the button actions are reversed. In this case, the values are read from right to left.
var Pointer = new Class({
initialize:
function Pointer (manager, id)
{
this.manager = manager;
this.id = id;
this.event;
// The camera the Pointer interacted with during its last update
// A Pointer can only ever interact with 1 camera at once, which will be the top-most camera
// in the list should multiple cameras be positioned on-top of each other.
this.camera = null;
// 0 : No button or un-initialized
// 1 : Left button
// 2 : Right button
// 4 : Wheel button or middle button
// 8 : 4th button (typically the "Browser Back" button)
// 16 : 5th button (typically the "Browser Forward" button)
this.buttons = 0;
this.x = 0;
this.y = 0;
// Coordinates and time of the pointer when Button 1 (left button), or Touch, was pressed, used for dragging objects
this.downX = 0;
this.downY = 0;
this.downTime = 0;
// Coordinates and time of the pointer when Button 1 (left button), or Touch, was released, used for dragging objects
this.upX = 0;
this.upY = 0;
this.upTime = 0;
// Is the primary button down? (usually button 0, the left mouse button)
this.primaryDown = false;
// 0 = Not dragging anything
// 1 = Being checked if dragging
// 2 = Dragging something
this.dragState = 0;
// Is *any* button on this pointer considered as being down?
this.isDown = false;
this.dirty = false;
this.justDown = false;
this.justUp = false;
this.justMoved = false;
},
reset: function ()
{
this.buttons = 0;
this.dirty = false;
this.isDown = false;
this.justDown = false;
this.justUp = false;
this.justMoved = false;
},
touchmove: function (event, time)
{
this.event = event;
this.x = this.manager.transformX(event.changedTouches[0].pageX);
this.y = this.manager.transformY(event.changedTouches[0].pageY);
this.justMoved = true;
this.dirty = true;
},
move: function (event, time)
{
if (event.buttons)
{
this.buttons = event.buttons;
}
this.event = event;
this.x = this.manager.transformX(event.pageX);
this.y = this.manager.transformY(event.pageY);
this.justMoved = true;
this.dirty = true;
},
down: function (event, time)
{
if (event.buttons)
{
this.buttons = event.buttons;
}
this.event = event;
this.x = this.manager.transformX(event.pageX);
this.y = this.manager.transformY(event.pageY);
// 0: Main button pressed, usually the left button or the un-initialized state
if (event.button === 0)
{
this.primaryDown = true;
this.downX = this.x;
this.downY = this.y;
this.downTime = time;
}
this.justDown = true;
this.isDown = true;
this.dirty = true;
},
touchstart: function (event, time)
{
this.buttons = 1;
this.event = event;
this.x = this.manager.transformX(event.changedTouches[0].pageX);
this.y = this.manager.transformY(event.changedTouches[0].pageY);
this.primaryDown = true;
this.downX = this.x;
this.downY = this.y;
this.downTime = time;
this.justDown = true;
this.isDown = true;
this.dirty = true;
},
up: function (event, time)
{
if (event.buttons)
{
this.buttons = event.buttons;
}
this.event = event;
this.x = this.manager.transformX(event.pageX);
this.y = this.manager.transformY(event.pageY);
// 0: Main button pressed, usually the left button or the un-initialized state
if (event.button === 0)
{
this.primaryDown = false;
this.upX = this.x;
this.upY = this.y;
this.upTime = time;
}
this.justUp = true;
this.isDown = false;
this.dirty = true;
},
touchend: function (event, time)
{
this.buttons = 0;
this.event = event;
this.x = this.manager.transformX(event.changedTouches[0].pageX);
this.y = this.manager.transformY(event.changedTouches[0].pageY);
this.primaryDown = false;
this.upX = this.x;
this.upY = this.y;
this.upTime = time;
this.justUp = true;
this.isDown = false;
this.dirty = true;
},
noButtonDown: function ()
{
return (this.buttons === 0);
},
leftButtonDown: function ()
{
return (this.buttons & 1);
},
rightButtonDown: function ()
{
return (this.buttons & 2);
},
middleButtonDown: function ()
{
return (this.buttons & 4);
},
backButtonDown: function ()
{
return (this.buttons & 8);
},
forwardButtonDown: function ()
{
return (this.buttons & 16);
}
});
module.exports = Pointer;