Aegis2D
Modular C++26 2D game engine for networked games
Loading...
Searching...
No Matches
aegis2d::platform::Mouse Class Reference

Position of the mouse, buttons held, and those pressed or released and the wheel turned since the start of the frame. More...

#include <aegis2d/platform/mouse.hpp>

Public Member Functions

void begin_frame () noexcept
 Starts a frame: forgets the presses, releases and wheel of the previous one.
 
void move_to (Vec2 position) noexcept
 Records that the mouse moved.
 
void press (MouseButton button) noexcept
 Records that a button went down.
 
void release (MouseButton button) noexcept
 Records that a button went up.
 
void release_all () noexcept
 Releases every held button, as when the window loses the focus.
 
void scroll (Vec2 delta) noexcept
 Records that the wheel turned.
 
Vec2 position () const noexcept
 Where the mouse is.
 
bool moved () const noexcept
 Tells whether the mouse moved during the frame.
 
bool held (MouseButton button) const noexcept
 Tells whether a button is down.
 
bool pressed (MouseButton button) const noexcept
 Tells whether a button went down during the frame.
 
bool released (MouseButton button) const noexcept
 Tells whether a button went up during the frame.
 
Vec2 wheel () const noexcept
 How much the wheel turned during the frame.
 
std::uint64_t frame () const noexcept
 Number of frames started so far.
 

Detailed Description

Position of the mouse, buttons held, and those pressed or released and the wheel turned since the start of the frame.

The window feeds it in Window::poll_events(), which starts a new frame first, like the Keyboard: a click pressed and released within one frame is still seen as pressed. The position is in the window's coordinates, from its top-left corner (the units of Window::size()); the renderer turns it into logical pixels (render::opengl::Renderer::to_logical()), and a camera into world coordinates.

Member Function Documentation

◆ begin_frame()

void aegis2d::platform::Mouse::begin_frame ( )
noexcept

Starts a frame: forgets the presses, releases and wheel of the previous one.

◆ frame()

std::uint64_t aegis2d::platform::Mouse::frame ( ) const
noexcept

Number of frames started so far.

Returns
0 before the first begin_frame(), then 1, 2...

◆ held()

bool aegis2d::platform::Mouse::held ( MouseButton  button) const
noexcept

Tells whether a button is down.

Parameters
buttonButton to test.
Returns
true if it was pressed and not released yet.

◆ move_to()

void aegis2d::platform::Mouse::move_to ( Vec2  position)
noexcept

Records that the mouse moved.

Parameters
positionNew position, in window coordinates.

◆ moved()

bool aegis2d::platform::Mouse::moved ( ) const
noexcept

Tells whether the mouse moved during the frame.

Returns
true if move_to() was called since begin_frame().

◆ position()

Vec2 aegis2d::platform::Mouse::position ( ) const
noexcept

Where the mouse is.

Returns
The last position, in window coordinates; (0, 0) before the first move.

◆ press()

void aegis2d::platform::Mouse::press ( MouseButton  button)
noexcept

Records that a button went down.

Parameters
buttonButton pressed; ignored if it is already held.

◆ pressed()

bool aegis2d::platform::Mouse::pressed ( MouseButton  button) const
noexcept

Tells whether a button went down during the frame.

Parameters
buttonButton to test.
Returns
true if it was pressed since begin_frame(), even if it is released again.

◆ release()

void aegis2d::platform::Mouse::release ( MouseButton  button)
noexcept

Records that a button went up.

Parameters
buttonButton released; ignored if it is not held.

◆ release_all()

void aegis2d::platform::Mouse::release_all ( )
noexcept

Releases every held button, as when the window loses the focus.

◆ released()

bool aegis2d::platform::Mouse::released ( MouseButton  button) const
noexcept

Tells whether a button went up during the frame.

Parameters
buttonButton to test.
Returns
true if it was released since begin_frame().

◆ scroll()

void aegis2d::platform::Mouse::scroll ( Vec2  delta)
noexcept

Records that the wheel turned.

Parameters
deltaSteps turned: y above 0 away from the player (scroll up), x above 0 to the right. Steps of one frame add up.

◆ wheel()

Vec2 aegis2d::platform::Mouse::wheel ( ) const
noexcept

How much the wheel turned during the frame.

Returns
The steps given to scroll() since begin_frame(), added up; (0, 0) if none.

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