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

Unified Diff: tools/vulkan/InputHandler.cpp

Issue 1848833005: First pass at VulkanViewer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Revise setup and event handling 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/InputHandler.cpp
diff --git a/tools/vulkan/InputHandler.cpp b/tools/vulkan/InputHandler.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..200d838fab855af22495f1ee7aec725878e9e2fd
--- /dev/null
+++ b/tools/vulkan/InputHandler.cpp
@@ -0,0 +1,56 @@
+/*
+* Copyright 2016 Google Inc.
+*
+* Use of this source code is governed by a BSD-style license that can be
+* found in the LICENSE file.
+*/
+
+#include "InputHandler.h"
+#include <ctype.h>
+
+InputHandler::InputHandler() : fMouseDown(false), fMousePressed(false), fMouseReleased(false)
+ , fMouseX(0), fMouseY(0) {
+ // clear key states
+ memset(fKeys, 0, sizeof(bool) * 256);
+ memset(fKeyPressed, 0, sizeof(bool) * 256);
+ memset(fKeyReleased, 0, sizeof(bool) * 256);
+}
+
+void InputHandler::onKeyDown(unsigned char key) {
+ if (isupper(key)) {
+ key = tolower(key);
+ }
+
+ if (!fKeys[key]) {
+ fKeys[key] = true;
+ fKeyPressed[key] = true;
+ }
+}
+
+void InputHandler::onKeyUp(unsigned char key) {
+ if (isupper(key)) {
+ key = tolower(key);
+ }
+
+ if (fKeys[key]) {
+ fKeys[key] = false;
+ fKeyReleased[key] = true;
+ }
+}
+
+void InputHandler::onMouseDown(unsigned int h, unsigned int v) {
+ if (!fMouseDown) {
+ fMouseDown = true;
+ fMousePressed = true;
+ }
+
+ fMouseX = h;
+ fMouseY = v;
+}
+
+void InputHandler::onMouseUp() {
+ if (fMouseDown) {
+ fMouseDown = false;
+ fMouseReleased = true;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698