cangine
Loading...
Searching...
No Matches
mouse.hpp
Go to the documentation of this file.
1#pragma once
2
3
4#include "../types/types.hpp"
5
6struct GLFWwindow;
7
8namespace cangine {
9 class Window; // forward declaration
10
12 enum class MouseButton {
13 Button1,
14 Button2,
15 Button3,
16 Button4,
17 Button5,
18 Button6,
19 Button7,
20 Button8,
21 Left = Button1,
22 Right = Button2,
24 };
25
35
43
50 class Mouse {
51 private:
54 void _mouseClickHandler(GLFWwindow* window, int button, int action, int mods);
56 void _mouseEnterHandler(GLFWwindow* window, int entered);
58 void _cursorMoveHandler(GLFWwindow* window);
60 void _scrollWheelInputHandler(GLFWwindow* window, Vector2 offset);
62 void _fireEvent(const MouseEvent* event);
63 static Mouse* instance;
64 friend class Window;
65
66 public:
73 Mouse();
78 static Mouse* getInstance();
79
80 };
81}
Singleton tracking mouse state and dispatching mouse events.
Definition mouse.hpp:50
static Mouse * instance
Singleton instance.
Definition mouse.hpp:63
void _fireEvent(const MouseEvent *event)
Dispatches a mouse event to listeners.
Definition mouse.cpp:86
Mouse()
Constructs the mouse tracker.
Definition mouse.cpp:97
static Mouse * getInstance()
Returns the singleton instance.
Definition mouse.cpp:102
void _cursorMoveHandler(GLFWwindow *window)
Handles a raw GLFW cursor move callback.
Definition mouse.cpp:57
Vector2 getCursorPosition()
Returns the current cursor position.
Definition mouse.cpp:93
void _mouseClickHandler(GLFWwindow *window, int button, int action, int mods)
Handles a raw GLFW mouse button callback.
Definition mouse.cpp:24
void _mouseEnterHandler(GLFWwindow *window, int entered)
Handles a raw GLFW cursor enter/leave callback.
Definition mouse.cpp:42
Vector2 cursorPos
Definition mouse.hpp:52
void _scrollWheelInputHandler(GLFWwindow *window, Vector2 offset)
Handles a raw GLFW scroll callback.
Definition mouse.cpp:72
Owns the application window, OpenGL context and the frame loop.
Definition window.hpp:34
Definition audiomanager.cpp:4
MouseButton
Mouse button identifiers, with named aliases for the common three.
Definition mouse.hpp:12
@ Button6
Sixth button.
@ Button8
Eighth button.
@ Button1
First button.
@ Button3
Third button.
@ Button4
Fourth button.
@ Button7
Seventh button.
@ Middle
Middle button (alias of Button3).
@ Button2
Second button.
@ Button5
Fifth button.
MouseEventType
The kind of mouse event that occurred.
Definition mouse.hpp:27
@ Scroll
The scroll wheel moved.
@ MouseClick
A button was pressed.
@ CursorLeave
Cursor left the window.
@ MouseRelease
A button was released.
@ CursorEnter
Cursor entered the window.
@ CursorMove
Cursor moved within the window.
A mouse event carrying its type, button, position and scroll offset.
Definition mouse.hpp:37
Vector2 pos
Cursor position at the time the event fired.
Definition mouse.hpp:40
Vector2 offset
Scroll offset; only meaningful for scroll events.
Definition mouse.hpp:41
MouseEventType event
The kind of event.
Definition mouse.hpp:38
MouseButton button
Button involved; only meaningful for click/release events.
Definition mouse.hpp:39
Two-component floating-point vector.
Definition vector2.hpp:13