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 (isupper(key)) { |
| 21 key = tolower(key); |
| 22 } |
| 23 |
| 24 if (!fKeys[key]) { |
| 25 fKeys[key] = true; |
| 26 fKeyPressed[key] = true; |
| 27 } |
| 28 } |
| 29 |
| 30 void InputHandler::onKeyUp(unsigned char key) { |
| 31 if (isupper(key)) { |
| 32 key = tolower(key); |
| 33 } |
| 34 |
| 35 if (fKeys[key]) { |
| 36 fKeys[key] = false; |
| 37 fKeyReleased[key] = true; |
| 38 } |
| 39 } |
| 40 |
| 41 void InputHandler::onMouseDown(unsigned int h, unsigned int v) { |
| 42 if (!fMouseDown) { |
| 43 fMouseDown = true; |
| 44 fMousePressed = true; |
| 45 } |
| 46 |
| 47 fMouseX = h; |
| 48 fMouseY = v; |
| 49 } |
| 50 |
| 51 void InputHandler::onMouseUp() { |
| 52 if (fMouseDown) { |
| 53 fMouseDown = false; |
| 54 fMouseReleased = true; |
| 55 } |
| 56 } |
OLD | NEW |