Brunot
Loading...
Searching...
No Matches
Mouse.h
Go to the documentation of this file.
1
15// ____ __ __ __
16// /\__ _\/\ \ /\ \/\ \
17// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
18// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
19// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
20// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
21// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
22
23
24
25#pragma once
26
27#include <utility>
28#include "System/opengl.h"
30
35class Mouse
36{
37public:
38
39 Mouse();
40
41 auto update(float dt) -> void;
42 auto showMenu() -> void;
43
44
46 auto getEnabled() const -> bool;
48 auto setEnabled(bool newState) -> void;
49
51 auto getInputMap() const -> const std::unordered_map<int, std::string>&;
52
57 auto getMousePosition() const -> std::pair<float, float>;
58
62 auto getMouseWorldCoords() const -> const Vector4D&;
63
65 static auto mouseButtonCallback(GLFWwindow* window, int pressedButton, int action, int mods) -> void;
66
67
69 static constexpr auto getMouseDeviceID() -> int
70 {
71 return mouseDeviceID;
72 }
73
74private:
75
76 bool enabled = true;
77
79
80 Vector4D mouseWorldCoords = {0.f, 0.f, 0.f, 1.f};
81
83 std::unordered_map<int, std::string> mouseButtonMap;
84
86 static constexpr auto mouseDeviceID = -2;
87
88};
auto getEnabled() const -> bool
Returns if mouse input is currently enabled or not.
Definition Mouse.cpp:89
auto update(float dt) -> void
Definition Mouse.cpp:57
auto getInputMap() const -> const std::unordered_map< int, std::string > &
Returns the map of all the registered mouse buttons and their corresponding event.
Definition Mouse.cpp:99
static auto mouseButtonCallback(GLFWwindow *window, int pressedButton, int action, int mods) -> void
Callback used by GLFW whenever a button on the mouse is pressed/released. Broadcasts a message on pre...
Definition Mouse.cpp:129
static constexpr auto mouseDeviceID
ID representing all mouse input done.
Definition Mouse.h:86
Vector4D mouseWorldCoords
Definition Mouse.h:80
static constexpr auto getMouseDeviceID() -> int
Used to keep our use of the Mouse input device ID consistent.
Definition Mouse.h:69
Mouse()
Definition Mouse.cpp:47
static const Vector4D outOfBoundsPosition
Definition Mouse.h:78
auto getMousePosition() const -> std::pair< float, float >
Gets the mouse position in GLFW space (top left is 0,0).
Definition Mouse.cpp:104
auto getMouseWorldCoords() const -> const Vector4D &
Gets the mouse position in the world of the gameplay viewport (center is 0,0).
Definition Mouse.cpp:112
auto setEnabled(bool newState) -> void
Sets whether input from the mouse is accepted or not.
Definition Mouse.cpp:94
auto showMenu() -> void
Definition Mouse.cpp:73
std::unordered_map< int, std::string > mouseButtonMap
A map that takes GLFW mouse codes and maps them to input event names.
Definition Mouse.h:83
bool enabled
Definition Mouse.h:76
Definition Vector4D.h:23