Chromium Code Reviews| 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 #ifndef InputHandler_DEFINED | |
| 9 #define InputHandler_DEFINED | |
| 10 | |
| 11 #include <string.h> | |
| 12 | |
| 13 class InputHandler | |
| 14 { | |
| 15 public: | |
| 16 InputHandler(); | |
| 17 | |
| 18 void onKeyDown(unsigned char key); // Handle key down event | |
| 19 void onKeyUp(unsigned char key); // Handle key up event | |
| 20 void onMouseDown(unsigned int h, unsigned int v); // Handle mouse down eve nt | |
| 21 void onMouseUp(); // Handle mouse up event | |
| 22 | |
| 23 bool isKeyDown(unsigned char key) { | |
|
bsalomon
2016/04/05 14:24:43
should the getters be const?
jvanverth1
2016/04/05 18:16:48
Done.
| |
| 24 return fKeys[key]; | |
| 25 } | |
| 26 bool isKeyUp(unsigned char key) { | |
| 27 return !fKeys[key]; | |
| 28 } | |
| 29 bool isKeyPressed(unsigned char key) { | |
| 30 return fKeyPressed[key]; | |
| 31 } | |
| 32 | |
| 33 bool isKeyReleased(unsigned char key) { | |
| 34 return fKeyReleased[key]; | |
| 35 } | |
| 36 | |
| 37 bool isMouseDown(unsigned int& h, unsigned int& v) { | |
|
bsalomon
2016/04/05 14:24:43
To be consistent with our style h and v should be
jvanverth1
2016/04/05 18:16:48
Done.
| |
| 38 if (fMouseDown) | |
| 39 { | |
| 40 h = fMouseX; | |
| 41 v = fMouseY; | |
| 42 return true; | |
| 43 } | |
| 44 return false; | |
| 45 } | |
| 46 | |
| 47 bool isMousePressed(unsigned int& h, unsigned int& v) { | |
|
bsalomon
2016/04/05 14:24:43
ditto
jvanverth1
2016/04/05 18:16:48
Done.
| |
| 48 if (fMousePressed) | |
| 49 { | |
| 50 h = fMouseX; | |
| 51 v = fMouseY; | |
| 52 return true; | |
| 53 } | |
| 54 return false; | |
| 55 } | |
| 56 | |
| 57 bool IsMouseReleased() { | |
| 58 return fMouseReleased; | |
| 59 } | |
| 60 | |
| 61 inline void Update() { | |
| 62 memset(fKeyPressed, 0, sizeof(bool) * 256); | |
| 63 memset(fKeyReleased, 0, sizeof(bool) * 256); | |
| 64 fMousePressed = false; | |
| 65 fMouseReleased = false; | |
| 66 } | |
| 67 | |
| 68 private: | |
| 69 // assumes ASCII keystrokes only | |
| 70 bool fKeys[256]; | |
| 71 bool fKeyPressed[256]; | |
| 72 bool fKeyReleased[256]; | |
| 73 | |
| 74 bool fMouseDown; | |
| 75 bool fMousePressed; | |
| 76 bool fMouseReleased; | |
| 77 unsigned int fMouseX; | |
| 78 unsigned int fMouseY; | |
| 79 | |
| 80 InputHandler(const InputHandler& other); | |
| 81 InputHandler& operator=(const InputHandler& other); | |
| 82 }; | |
| 83 | |
| 84 #endif | |
| OLD | NEW |