Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Unified Diff: tools/vulkan/viewer/InputHandler.h

Issue 1848833005: First pass at VulkanViewer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Address comments, plus add GM rendering Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/vulkan/viewer/InputHandler.h
diff --git a/tools/vulkan/viewer/InputHandler.h b/tools/vulkan/viewer/InputHandler.h
new file mode 100644
index 0000000000000000000000000000000000000000..05d69428e74e59eb1097ee59938d4cd6a6336d7d
--- /dev/null
+++ b/tools/vulkan/viewer/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) const {
+ return fKeys[key];
+ }
+ bool isKeyUp(unsigned char key) const {
+ return !fKeys[key];
+ }
+ bool isKeyPressed(unsigned char key) const {
+ return fKeyPressed[key];
+ }
+
+ bool isKeyReleased(unsigned char key) const {
+ return fKeyReleased[key];
+ }
+
+ bool isMouseDown(unsigned int* h, unsigned int* v) const {
+ if (fMouseDown)
+ {
+ *h = fMouseX;
+ *v = fMouseY;
+ return true;
+ }
+ return false;
+ }
+
+ bool isMousePressed(unsigned int* h, unsigned int* v) const {
+ if (fMousePressed)
+ {
+ *h = fMouseX;
+ *v = fMouseY;
+ return true;
+ }
+ return false;
+ }
+
+ bool IsMouseReleased() const {
+ 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

Powered by Google App Engine
This is Rietveld 408576698