QuasarEngine
Cross-platform 3D engine and editor
Loading...
Searching...
No Matches
MouseEvent.h
Go to the documentation of this file.
1#pragma once
2
7
10
11#include <spdlog/fmt/fmt.h>
12
13#include <string>
14
15namespace Quasar
16{
21 class MouseMovedEvent final : public EventOf<EventType::MouseMoved, EventCategory::Input | EventCategory::Mouse>
22 {
23 public:
25 MouseMovedEvent(float x, float y) : m_X(x), m_Y(y) {}
26
28 float GetX() const { return m_X; }
29
31 float GetY() const { return m_Y; }
32
34 std::string ToString() const override { return fmt::format("{}: {}, {}", GetName(), m_X, m_Y); }
35
36 private:
37 float m_X = 0.0f;
38 float m_Y = 0.0f;
39 };
40
45 class MouseScrolledEvent final : public EventOf<EventType::MouseScrolled, EventCategory::Input | EventCategory::Mouse>
46 {
47 public:
49 MouseScrolledEvent(float xOffset, float yOffset) : m_XOffset(xOffset), m_YOffset(yOffset) {}
50
52 float GetXOffset() const { return m_XOffset; }
53
55 float GetYOffset() const { return m_YOffset; }
56
58 std::string ToString() const override { return fmt::format("{}: {}, {}", GetName(), m_XOffset, m_YOffset); }
59
60 private:
61 float m_XOffset = 0.0f;
62 float m_YOffset = 0.0f;
63 };
64
66 class MouseButtonPressedEvent final : public EventOf<EventType::MouseButtonPressed, EventCategory::Input | EventCategory::Mouse>
67 {
68 public:
70 explicit MouseButtonPressedEvent(MouseButton button) : m_Button(button) {}
71
73 MouseButton GetButton() const { return m_Button; }
74
76 std::string ToString() const override { return fmt::format("{}: {}", GetName(), static_cast<int>(m_Button)); }
77
78 private:
79 MouseButton m_Button;
80 };
81
83 class MouseButtonReleasedEvent final : public EventOf<EventType::MouseButtonReleased, EventCategory::Input | EventCategory::Mouse>
84 {
85 public:
87 explicit MouseButtonReleasedEvent(MouseButton button) : m_Button(button) {}
88
90 MouseButton GetButton() const { return m_Button; }
91
93 std::string ToString() const override { return fmt::format("{}: {}", GetName(), static_cast<int>(m_Button)); }
94
95 private:
96 MouseButton m_Button;
97 };
98}
Base class of all events, with their types and categories.
Codes of the mouse buttons, independent from GLFW.
Base class of each event class, which gives the event its type and its categories.
Definition Event.h:148
const char * GetName() const
Returns the name of the type of the event, for example "KeyPressed".
Definition Event.h:112
MouseButton GetButton() const
Returns the pressed button.
Definition MouseEvent.h:73
MouseButtonPressedEvent(MouseButton button)
Creates the event for the pressed button.
Definition MouseEvent.h:70
std::string ToString() const override
Returns the event with its button code, for example "MouseButtonPressed: 0" for the left button.
Definition MouseEvent.h:76
MouseButton GetButton() const
Returns the released button.
Definition MouseEvent.h:90
MouseButtonReleasedEvent(MouseButton button)
Creates the event for the released button.
Definition MouseEvent.h:87
std::string ToString() const override
Returns the event with its button code, for example "MouseButtonReleased: 0" for the left button.
Definition MouseEvent.h:93
MouseMovedEvent(float x, float y)
Creates the event with the new position of the cursor, in screen coordinates.
Definition MouseEvent.h:25
float GetY() const
Returns the vertical position of the cursor, from the top edge of the drawing area.
Definition MouseEvent.h:31
float GetX() const
Returns the horizontal position of the cursor, from the left edge of the drawing area.
Definition MouseEvent.h:28
std::string ToString() const override
Returns the event with the position, for example "MouseMoved: 640, 360.5".
Definition MouseEvent.h:34
float GetXOffset() const
Returns the horizontal offset. It is positive when scrolling to the right.
Definition MouseEvent.h:52
float GetYOffset() const
Returns the vertical offset. It is positive when the wheel turns away from the user.
Definition MouseEvent.h:55
std::string ToString() const override
Returns the event with the offsets, for example "MouseScrolled: 0, 1".
Definition MouseEvent.h:58
MouseScrolledEvent(float xOffset, float yOffset)
Creates the event with the scroll offsets.
Definition MouseEvent.h:49
Contains all the engine code.
MouseButton
Button of the mouse.
Definition MouseCodes.h:17