From 6f6073be5de8c8598c4af7f38c90c3f83b5bf1bf Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Tue, 18 Dec 2018 21:08:20 +0100 Subject: Hacky mouse-based fluid interaction --- src/glfw/window.cc | 15 ++++++++++++++- src/glfw/window.h | 5 ++++- 2 files changed, 18 insertions(+), 2 deletions(-) (limited to 'src/glfw') 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 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 #include #include @@ -26,7 +27,9 @@ public: int getWidth() const; int getHeight() const; - KeyWatcher getKeyWatcher(int key); + std::tuple getMouse() const; + + KeyWatcher getKeyWatcher(int key) const; template void init(F f); -- cgit v1.2.3