/
Viewer.js
55 lines (41 loc) · 1.08 KB
/
Viewer.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
function stateBrowseInit()
{
}
function stateBrowseCyclic()
{
}
// >>> Section: State machine
function StateMachine(initialstate)
{
var state;
var nextstate = initialstate;
this.update = function(t, dt)
{
if(this.state == nextstate)
{
this.state(t, dt);
return true; // Draw frame
}
else
{
this.state = nextstate;
return false; // Skip drawing frame and reset timer
}
}
this.getState = function()
{
return this.state;
}
this.setState = function(newstate)
{
nextstate = newstate;
}
}
var statemachine = new StateMachine(stateBrowseInit);
// >>> Section: Mouse and keyboard mappings
// Connect actions to key-down and key-up events of specific keys when the statemachine is in a given state
// Syntax: keymap[state][key_code] = [key_down_action, key_up_action];
var keymap = {};
// Connect actions to button-down and button-up events of specific mouse buttons when the statemachine is in a given state
// Syntax: mousebuttonmap[state][key_code] = [key_down_action, key_up_action, mouse_move_while_key_down_action];
var mousebuttonmap = {}, mousewheelmap = {};