Chromium Code Reviews| Index: tools/vulkan/InputHandler.h |
| diff --git a/tools/vulkan/InputHandler.h b/tools/vulkan/InputHandler.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6f5a97d0c98aaaf21ac55b378b5c99d7f8137757 |
| --- /dev/null |
| +++ b/tools/vulkan/InputHandler.h |
| @@ -0,0 +1,84 @@ |
| +/* |
| +* Copyright 2016 Google Inc. |
| +* |
| +* Use of this source code is governed by a BSD-style license that can be |
| +* found in the LICENSE file. |
| +*/ |
| + |
| +#ifndef InputHandler_DEFINED |
| +#define InputHandler_DEFINED |
| + |
| +#include <string.h> |
| + |
| +class InputHandler |
| +{ |
| +public: |
| + InputHandler(); |
| + |
| + void onKeyDown(unsigned char key); // Handle key down event |
| + void onKeyUp(unsigned char key); // Handle key up event |
| + void onMouseDown(unsigned int h, unsigned int v); // Handle mouse down event |
| + void onMouseUp(); // Handle mouse up event |
| + |
| + 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.
|
| + return fKeys[key]; |
| + } |
| + bool isKeyUp(unsigned char key) { |
| + return !fKeys[key]; |
| + } |
| + bool isKeyPressed(unsigned char key) { |
| + return fKeyPressed[key]; |
| + } |
| + |
| + bool isKeyReleased(unsigned char key) { |
| + return fKeyReleased[key]; |
| + } |
| + |
| + 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.
|
| + if (fMouseDown) |
| + { |
| + h = fMouseX; |
| + v = fMouseY; |
| + return true; |
| + } |
| + return false; |
| + } |
| + |
| + bool isMousePressed(unsigned int& h, unsigned int& v) { |
|
bsalomon
2016/04/05 14:24:43
ditto
jvanverth1
2016/04/05 18:16:48
Done.
|
| + if (fMousePressed) |
| + { |
| + h = fMouseX; |
| + v = fMouseY; |
| + return true; |
| + } |
| + return false; |
| + } |
| + |
| + bool IsMouseReleased() { |
| + return fMouseReleased; |
| + } |
| + |
| + inline void Update() { |
| + memset(fKeyPressed, 0, sizeof(bool) * 256); |
| + memset(fKeyReleased, 0, sizeof(bool) * 256); |
| + fMousePressed = false; |
| + fMouseReleased = false; |
| + } |
| + |
| +private: |
| + // assumes ASCII keystrokes only |
| + bool fKeys[256]; |
| + bool fKeyPressed[256]; |
| + bool fKeyReleased[256]; |
| + |
| + bool fMouseDown; |
| + bool fMousePressed; |
| + bool fMouseReleased; |
| + unsigned int fMouseX; |
| + unsigned int fMouseY; |
| + |
| + InputHandler(const InputHandler& other); |
| + InputHandler& operator=(const InputHandler& other); |
| +}; |
| + |
| +#endif |