-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMouse.h
54 lines (50 loc) · 1.32 KB
/
Mouse.h
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
#ifndef _MOUSE_H_
#define _MOUSE_H_
class RemoteHead;
class Mouse {
public:
Vec2 cursor_pos;
static const int BUTTON_MAX = 8;
int buttons[BUTTON_MAX];
bool toggled[BUTTON_MAX];
int mod_shift;
int mod_ctrl;
int mod_alt;
Mouse() {
memset(buttons,0,sizeof(buttons));
memset(toggled,0,sizeof(toggled));
}
void validateButtonIndex( unsigned int bti ) {
assert( (int)bti < BUTTON_MAX );
}
void updateButton( unsigned int button, int action, int modshift, int modctrl, int modalt ) {
validateButtonIndex(button);
if(action) {
if( !buttons[button] ) toggled[button] = true;
}
buttons[button] = action;
mod_shift = modshift;
mod_ctrl = modctrl;
mod_alt = modalt;
}
int getButton( unsigned int button ) {
validateButtonIndex(button);
return buttons[button];
}
int getToggled( unsigned int button ) {
validateButtonIndex(button);
return toggled[button];
}
void clearToggled( unsigned int button ) {
validateButtonIndex(button);
toggled[button] = false;
}
void updateCursorPosition( float x, float y ) {
cursor_pos.x = x;
cursor_pos.y = y;
}
Vec2 getCursorPos() {
return cursor_pos;
}
};
#endif