-
Notifications
You must be signed in to change notification settings - Fork 54
/
mouse.js
58 lines (50 loc) · 1.83 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
50
51
52
53
54
55
56
57
58
// The mouse sub-system.
define(["Node"], function (Node) {
var gWasInit = false;
var gX = 0;
var gY = 0;
var gButton = 0;
var initMouseModule = function () {
if (!gWasInit) {
var $canvas = $("#canvas");
$canvas.mousemove(function (event) {
var rect = this.getBoundingClientRect();
gX = event.clientX - rect.left;
gY = event.clientY - rect.top;
});
$canvas.mousedown(function (event) {
gButton = 1;
});
$canvas.mouseup(function (event) {
gButton = 0;
});
gWasInit = true;
}
};
var importSymbols = function (symbolTable) {
var symbol;
symbolTable.addNativeFunction("ShowCursor", Node.voidType, [], function (ctl) {
// I don't know what module this is in. It's not documented in the
// reference books.
});
symbolTable.addNativeFunction("HideCursor", Node.voidType, [], function (ctl) {
// I don't know what module this is in. It's not documented in the
// reference books.
});
symbol = symbolTable.addNativeFunction("GetMouseStatus", Node.voidType,
[Node.integerType, Node.integerType, Node.integerType],
function (ctl, x, y, button) {
initMouseModule();
// Set the parameters x, y, and button.
ctl.writeDstore(x, gX);
ctl.writeDstore(y, gY);
ctl.writeDstore(button, gButton);
});
symbol.type.parameters[0].byReference = true;
symbol.type.parameters[1].byReference = true;
symbol.type.parameters[2].byReference = true;
};
return {
importSymbols: importSymbols
};
});