ECSTASY
All in the name
Loading...
Searching...
No Matches
ecstasy::integration::event::Mouse Class Reference

Current mouse state. More...

#include <Mouse.hpp>

Inheritance diagram for ecstasy::integration::event::Mouse:
Collaboration diagram for ecstasy::integration::event::Mouse:

Public Types

enum class  Button {
  Left , Right , Middle , Extra1 ,
  Extra2 , Extra3 , Count
}
 Mouse buttons. More...
 
enum class  Wheel { Horizontal , Vertical , Count }
 Mouse wheels. More...
 

Public Member Functions

 Mouse () noexcept
 Construct a new Mouse resource.
 
virtual ~Mouse () noexcept=default
 Destroy the Mouse resource.
 
constexpr bool isButtonDown (Button button) const
 Check whether a mouse button is down.
 
constexpr bool isButtonUp (Button button) const
 Check whether a mouse button is up.
 
constexpr void setButtonState (Button button, bool down)
 Update a given button state.
 
constexpr int getX () const noexcept
 Get the X position of the mouse on the window.
 
constexpr void setX (int x) noexcept
 Update the mouse x position.
 
constexpr int getY () const noexcept
 Get the y position of the mouse on the window.
 
constexpr void setY (int y) noexcept
 Update the mouse y position.
 
constexpr std::pair< int, int > getPosition () noexcept
 Get the mouse position on the window.
 
constexpr void setPosition (int x, int y) noexcept
 Set the mouse position.
 
- Public Member Functions inherited from ecstasy::IResource
virtual ~IResource ()=default
 Default destructor.
 

Static Public Member Functions

static constexpr void assertButtonValid (Button button)
 Assert the validity of a mouse button.
 

Private Attributes

std::array< bool, static_cast< int >(Button::Count)> _buttons
 
int _x
 
int _y
 

Detailed Description

Current mouse state.

Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-04)

Definition at line 30 of file Mouse.hpp.

Member Enumeration Documentation

◆ Button

Mouse buttons.

Enumerator
Left 

The left mouse button.

Right 

The right mouse button.

Middle 

The middle (wheel) mouse button.

Extra1 

The first extra mouse button.

Extra2 

The second extra mouse button.

Extra3 

The third extra mouse button.

Count 

Keep last – the total number of mouse buttons.

Definition at line 39 of file Mouse.hpp.

39 {
40 Left,
41 Right,
42 Middle,
43 Extra1,
44 Extra2,
45 Extra3,
46
47 Count
48 };
@ Extra1
The first extra mouse button.
@ Extra2
The second extra mouse button.
@ Middle
The middle (wheel) mouse button.
@ Extra3
The third extra mouse button.
@ Count
Keep last – the total number of mouse buttons.

◆ Wheel

Mouse wheels.

Enumerator
Horizontal 

Horizontal mouse wheel (common)

Vertical 

Vertical mouse wheel.

Count 

Keep last – the total number of mouse wheels.

Definition at line 52 of file Mouse.hpp.

52 {
54 Vertical,
55
56 Count
57 };
@ Horizontal
Horizontal mouse wheel (common)

Constructor & Destructor Documentation

◆ Mouse()

ecstasy::integration::event::Mouse::Mouse ( )
inlinenoexcept

Construct a new Mouse resource.

Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-05)

Definition at line 65 of file Mouse.hpp.

65: _buttons({false}), _x(0), _y(0){};
std::array< bool, static_cast< int >(Button::Count)> _buttons
Definition Mouse.hpp:233

◆ ~Mouse()

virtual ecstasy::integration::event::Mouse::~Mouse ( )
virtualdefaultnoexcept

Destroy the Mouse resource.

Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-05)

Member Function Documentation

◆ assertButtonValid()

static constexpr void ecstasy::integration::event::Mouse::assertButtonValid ( Button  button)
inlinestaticconstexpr

Assert the validity of a mouse button.

Parameters
[in]buttonButton to assert.
Exceptions
std::invalid_argumentIf the button is invalid.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-10-13)

Definition at line 225 of file Mouse.hpp.

226 {
227 if (static_cast<std::size_t>(button) >= static_cast<std::size_t>(Button::Count)) [[unlikely]]
228 throw std::invalid_argument("Invalid mouse button");
229 }

◆ getPosition()

constexpr std::pair< int, int > ecstasy::integration::event::Mouse::getPosition ( )
inlineconstexprnoexcept

Get the mouse position on the window.

Returns
std::pair<int, int> mouse position.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-05)

Definition at line 193 of file Mouse.hpp.

194 {
195 return std::make_pair(_x, _y);
196 }
T make_pair(T... args)

◆ getX()

constexpr int ecstasy::integration::event::Mouse::getX ( ) const
inlineconstexprnoexcept

Get the X position of the mouse on the window.

Returns
int x position.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-05)

Definition at line 137 of file Mouse.hpp.

138 {
139 return _x;
140 }

◆ getY()

constexpr int ecstasy::integration::event::Mouse::getY ( ) const
inlineconstexprnoexcept

Get the y position of the mouse on the window.

Returns
int y position.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-05)

Definition at line 165 of file Mouse.hpp.

166 {
167 return _y;
168 }

◆ isButtonDown()

constexpr bool ecstasy::integration::event::Mouse::isButtonDown ( Button  button) const
inlineconstexpr

Check whether a mouse button is down.

Parameters
[in]buttonevaluated button.
Returns
bool Whether the button is down or not.
Exceptions
std::invalid_argumentIf the button is invalid.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-05)

Definition at line 87 of file Mouse.hpp.

88 {
89 assertButtonValid(button);
90 return _buttons[static_cast<size_t>(button)];
91 }
static constexpr void assertButtonValid(Button button)
Assert the validity of a mouse button.
Definition Mouse.hpp:225

◆ isButtonUp()

constexpr bool ecstasy::integration::event::Mouse::isButtonUp ( Button  button) const
inlineconstexpr

Check whether a mouse button is up.

Parameters
[in]buttonevaluated button.
Returns
bool Whether the button is up or not.
Exceptions
std::invalid_argumentIf the button is invalid.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-05)

Definition at line 105 of file Mouse.hpp.

106 {
107 return !isButtonDown(button);
108 }
constexpr bool isButtonDown(Button button) const
Check whether a mouse button is down.
Definition Mouse.hpp:87

◆ setButtonState()

constexpr void ecstasy::integration::event::Mouse::setButtonState ( Button  button,
bool  down 
)
inlineconstexpr

Update a given button state.

Warning
It only update the internal state, no event is called.
Parameters
[in]buttonButton to update.
[in]downWhether the button must be set down or not.
Exceptions
std::invalid_argumentIf the button is invalid.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-05)

Definition at line 123 of file Mouse.hpp.

124 {
125 assertButtonValid(button);
126 _buttons[static_cast<size_t>(button)] = down;
127 }

◆ setPosition()

constexpr void ecstasy::integration::event::Mouse::setPosition ( int  x,
int  y 
)
inlineconstexprnoexcept

Set the mouse position.

Warning
It only update the internal state, no event is called.
Parameters
[in]xx position.
[in]yy position.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-05)

Definition at line 209 of file Mouse.hpp.

210 {
211 _x = x;
212 _y = y;
213 }

◆ setX()

constexpr void ecstasy::integration::event::Mouse::setX ( int  x)
inlineconstexprnoexcept

Update the mouse x position.

Warning
It only update the internal state, no event is called.
Parameters
[in]xnew x position.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-05)

Definition at line 152 of file Mouse.hpp.

153 {
154 _x = x;
155 }

◆ setY()

constexpr void ecstasy::integration::event::Mouse::setY ( int  y)
inlineconstexprnoexcept

Update the mouse y position.

Warning
It only update the internal state, no event is called.
Parameters
[in]ynew y position.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-11-05)

Definition at line 180 of file Mouse.hpp.

181 {
182 _y = y;
183 }

Member Data Documentation

◆ _buttons

std::array<bool, static_cast<int>(Button::Count)> ecstasy::integration::event::Mouse::_buttons
private

Definition at line 233 of file Mouse.hpp.

◆ _x

int ecstasy::integration::event::Mouse::_x
private

Definition at line 235 of file Mouse.hpp.

◆ _y

int ecstasy::integration::event::Mouse::_y
private

Definition at line 237 of file Mouse.hpp.


The documentation for this class was generated from the following file: