-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcursor.js
69 lines (63 loc) · 1.42 KB
/
cursor.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
Cursor = function() {
this.x = 0;
this.y = 0;
this.color = WHITE;
this.key;
this.isHoldingKey = false;
return this;
}
Cursor.prototype.move = function(event) {
this.x = event.offsetX;
this.y = event.offsetY;
if (this.key && this.isHoldingKey) {
this.key.updateMousePos(this);
}
};
Cursor.prototype.hoverOn = function() {
this.color = CURSOR_HOVER;
};
Cursor.prototype.hoverOff = function() {
this.color = WHITE;
};
Cursor.prototype.pressKey = function() {
if (this.key) {
if (this.key.disabled && not(this.isHoldingKey)) {
this.key.grab(this);
this.isHoldingKey = true;
}
else {
this.key.activate();
}
return this.key.getKey(false);
}
};
Cursor.prototype.releaseKey = function() {
if (this.key) {
if (this.key.disabled && this.isHoldingKey) {
this.key.release(this);
this.isHoldingKey = false;
}
else {
this.key.deactivate();
}
return this.key.getKey(true);
}
};
Cursor.prototype.render = function(context) {
context.fillStyle = this.color;
var x = this.x;
var y = this.y;
context.beginPath();
context.moveTo(x, y);
context.lineTo(x += 13, y += 13);
context.lineTo(x -= 8, y);
context.lineTo(this.x, this.y + 19);
context.closePath();
context.fill();
context.strokeStyle = BLACK;
context.lineWidth = 2;
context.stroke();
context.strokeStyle = CURSOR_OUTLINE;
context.lineWidth = 1;
context.stroke();
};