OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2016 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #include "InputHandler.h" | |
9 #include <ctype.h> | |
10 | |
11 InputHandler::InputHandler() : fMouseDown(false), fMousePressed(false), fMouseRe
leased(false) | |
12 , fMouseX(0), fMouseY(0) { | |
13 // clear key states | |
14 memset(fKeys, 0, sizeof(bool) * 256); | |
15 memset(fKeyPressed, 0, sizeof(bool) * 256); | |
16 memset(fKeyReleased, 0, sizeof(bool) * 256); | |
17 } | |
18 | |
19 void InputHandler::onKeyDown(unsigned char key) { | |
20 if (!fKeys[key]) { | |
21 fKeys[key] = true; | |
22 fKeyPressed[key] = true; | |
23 } | |
24 } | |
25 | |
26 void InputHandler::onKeyUp(unsigned char key) { | |
27 if (fKeys[key]) { | |
28 fKeys[key] = false; | |
29 fKeyReleased[key] = true; | |
30 } | |
31 } | |
32 | |
33 void InputHandler::onMouseDown(unsigned int h, unsigned int v) { | |
34 if (!fMouseDown) { | |
35 fMouseDown = true; | |
36 fMousePressed = true; | |
37 } | |
38 | |
39 fMouseX = h; | |
40 fMouseY = v; | |
41 } | |
42 | |
43 void InputHandler::onMouseUp() { | |
44 if (fMouseDown) { | |
45 fMouseDown = false; | |
46 fMouseReleased = true; | |
47 } | |
48 } | |
OLD | NEW |