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 enable() -> void;
52
54 auto disable() -> void;
55
57 auto getInputMap() const -> const std::unordered_map<int, std::string>&;
58
59
63 auto getMouseWorldCoords() const -> const Vector4D&;
64
66 static auto mouseButtonCallback(GLFWwindow* window, int pressedButton, int action, int mods) -> void;
67
68
70 static constexpr auto getMouseDeviceID() -> int
71 {
72 return mouseDeviceID;
73 }
74
75private:
76
81 static auto getAbsoluteMousePosition() -> std::pair<float, float>;
82
83 bool enabled = true;
84
86
87 Vector4D mouseWorldCoords = {0.f, 0.f, 0.f, 1.f};
88 Vector4D oldMouseWorldCoords = {0.f, 0.f, 0.f, 1.f};
89
91 std::unordered_map<int, std::string> mouseButtonMap;
92
94 static constexpr auto mouseDeviceID = -2;
95
96};
auto getEnabled() const -> bool
Returns if mouse input is currently enabled or not.
Definition Mouse.cpp:116
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:139
auto disable() -> void
disables mouse input while also hiding the cursor
Definition Mouse.cpp:132
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:170
static constexpr auto mouseDeviceID
ID representing all mouse input done.
Definition Mouse.h:94
Vector4D mouseWorldCoords
Definition Mouse.h:87
static constexpr auto getMouseDeviceID() -> int
Used to keep our use of the Mouse input device ID consistent.
Definition Mouse.h:70
static auto getAbsoluteMousePosition() -> std::pair< float, float >
Helper function that gets the mouse position in GLFW space (top left is 0,0).
Definition Mouse.cpp:144
Mouse()
Definition Mouse.cpp:47
static const Vector4D outOfBoundsPosition
Definition Mouse.h:85
auto getMouseWorldCoords() const -> const Vector4D &
Gets the mouse position in the world of the gameplay viewport (center is 0,0).
Definition Mouse.cpp:152
auto setEnabled(bool newState) -> void
Sets whether input from the mouse is accepted or not.
Definition Mouse.cpp:121
auto showMenu() -> void
Definition Mouse.cpp:99
std::unordered_map< int, std::string > mouseButtonMap
A map that takes GLFW mouse codes and maps them to input event names.
Definition Mouse.h:91
Vector4D oldMouseWorldCoords
Definition Mouse.h:88
bool enabled
Definition Mouse.h:83
auto enable() -> void
Enables mouse input while also making the selector visible.
Definition Mouse.cpp:126
Definition Vector4D.h:28