aboutsummaryrefslogtreecommitdiff
path: root/src/glfw
diff options
context:
space:
mode:
authorAdrian Kummerlaender2018-12-18 21:08:20 +0100
committerAdrian Kummerlaender2018-12-18 21:08:20 +0100
commit6f6073be5de8c8598c4af7f38c90c3f83b5bf1bf (patch)
tree4dabb7259102afe4ddca25293ed3cc77640f95f8 /src/glfw
parentd58c4cbeb95e25ea08994e4d39f657d078a33782 (diff)
downloadcompustream-6f6073be5de8c8598c4af7f38c90c3f83b5bf1bf.tar
compustream-6f6073be5de8c8598c4af7f38c90c3f83b5bf1bf.tar.gz
compustream-6f6073be5de8c8598c4af7f38c90c3f83b5bf1bf.tar.bz2
compustream-6f6073be5de8c8598c4af7f38c90c3f83b5bf1bf.tar.lz
compustream-6f6073be5de8c8598c4af7f38c90c3f83b5bf1bf.tar.xz
compustream-6f6073be5de8c8598c4af7f38c90c3f83b5bf1bf.tar.zst
compustream-6f6073be5de8c8598c4af7f38c90c3f83b5bf1bf.zip
Hacky mouse-based fluid interaction
Diffstat (limited to 'src/glfw')
-rw-r--r--src/glfw/window.cc15
-rw-r--r--src/glfw/window.h5
2 files changed, 18 insertions, 2 deletions
diff --git a/src/glfw/window.cc b/src/glfw/window.cc
index 9e76b57..98890b7 100644
--- a/src/glfw/window.cc
+++ b/src/glfw/window.cc
@@ -37,6 +37,19 @@ int Window::getHeight() const {
return _height;
}
-KeyWatcher Window::getKeyWatcher(int key) {
+std::tuple<bool,int,int> Window::getMouse() const {
+ const bool clicked = glfwGetMouseButton(_handle, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS;
+
+ double x, y;
+ glfwGetCursorPos(_handle, &x, &y);
+
+ return std::make_tuple(
+ clicked,
+ x - int(getWidth()/2),
+ int(getHeight()/2 - y)
+ );
+}
+
+KeyWatcher Window::getKeyWatcher(int key) const {
return KeyWatcher(_handle, key);
}
diff --git a/src/glfw/window.h b/src/glfw/window.h
index ea6075b..af7ba4d 100644
--- a/src/glfw/window.h
+++ b/src/glfw/window.h
@@ -1,5 +1,6 @@
#pragma once
+#include <tuple>
#include <string>
#include <GL/glew.h>
@@ -26,7 +27,9 @@ public:
int getWidth() const;
int getHeight() const;
- KeyWatcher getKeyWatcher(int key);
+ std::tuple<bool,int,int> getMouse() const;
+
+ KeyWatcher getKeyWatcher(int key) const;
template <class F>
void init(F f);