-
Notifications
You must be signed in to change notification settings - Fork 0
/
mouse.js
executable file
·49 lines (42 loc) · 1.02 KB
/
mouse.js
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
function Mouse()
{
this.LEFT = 0;
this.MIDDLE = 1;
this.RIGHT = 2;
this.buttonDown = {}
this.xPos = 0;
this.yPos = 0;
this.Initialise = function(canvas)
{
var self = this;
var context = canvas.getContext('2d');
canvas.addEventListener('mousemove', function(evt)
{
var rect = canvas.getBoundingClientRect();
self.xPos = evt.x - rect.left;
self.yPos = evt.y - rect.top;
});
canvas.addEventListener('mousedown', function(evt)
{
self.buttonDown[evt.button] = true;
});
canvas.addEventListener('mouseup', function(evt)
{
self.buttonDown[evt.button] = false;
});
}
this.GetX = function()
{
return this.xPos;
}
this.GetY = function()
{
return this.yPos;
}
this.isButtonPressed = function(button)
{
//console.log(this.buttonDown[button])
return this.buttonDown[button];
}
}
var mouse = new Mouse();