aboutsummaryrefslogtreecommitdiff
path: root/src/glfw
diff options
context:
space:
mode:
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);