Skip to content

Commit f918942

Browse files
committed
Pointer has methods that expose the state of the buttons
1 parent 87edd6c commit f918942

1 file changed

Lines changed: 45 additions & 7 deletions

File tree

v3/src/input/Pointer.js

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ var Pointer = new Class({
1414

1515
this.event;
1616

17-
this.button = 0;
17+
// 0 : No button or un-initialized
18+
// 1 : Left button
19+
// 2 : Right button
20+
// 4 : Wheel button or middle button
21+
// 8 : 4th button (typically the "Browser Back" button)
22+
// 16 : 5th button (typically the "Browser Forward" button)
23+
this.buttons = 0;
1824

1925
this.x = 0;
2026
this.y = 0;
@@ -30,6 +36,8 @@ var Pointer = new Class({
3036

3137
reset: function ()
3238
{
39+
this.buttons = 0;
40+
3341
this.dirty = false;
3442
this.isDown = false;
3543
this.justDown = false;
@@ -39,9 +47,9 @@ var Pointer = new Class({
3947

4048
move: function (event)
4149
{
42-
if (event.button !== undefined)
50+
if (event.buttons)
4351
{
44-
this.button = event.button;
52+
this.buttons = event.buttons;
4553
}
4654

4755
this.event = event;
@@ -56,9 +64,9 @@ var Pointer = new Class({
5664

5765
down: function (event)
5866
{
59-
if (event.button !== undefined)
67+
if (event.buttons)
6068
{
61-
this.button = event.button;
69+
this.buttons = event.buttons;
6270
}
6371

6472
this.event = event;
@@ -74,9 +82,9 @@ var Pointer = new Class({
7482

7583
up: function (event)
7684
{
77-
if (event.button !== undefined)
85+
if (event.buttons)
7886
{
79-
this.button = event.button;
87+
this.buttons = event.buttons;
8088
}
8189

8290
this.event = event;
@@ -88,6 +96,36 @@ var Pointer = new Class({
8896
this.isDown = false;
8997

9098
this.dirty = true;
99+
},
100+
101+
noButtonDown: function ()
102+
{
103+
return (this.buttons === 0);
104+
},
105+
106+
leftButtonDown: function ()
107+
{
108+
return (this.buttons & 1);
109+
},
110+
111+
rightButtonDown: function ()
112+
{
113+
return (this.buttons & 2);
114+
},
115+
116+
middleButtonDown: function ()
117+
{
118+
return (this.buttons & 4);
119+
},
120+
121+
backButtonDown: function ()
122+
{
123+
return (this.buttons & 8);
124+
},
125+
126+
forwardButtonDown: function ()
127+
{
128+
return (this.buttons & 16);
91129
}
92130

93131
});

0 commit comments

Comments
 (0)