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

Desktop window: creation, size and events. Drawing is left to a render backend. More...

#include <aegis2d/platform/window.hpp>

Public Member Functions

 Window (const WindowConfig &config)
 Opens the window.
 
 Window (const Window &)=delete
 
Window & operator= (const Window &)=delete
 
 Window (Window &&other) noexcept
 Takes over the window of other, which must not be used afterwards.
 
Window & operator= (Window &&other) noexcept
 Closes this window and takes over the window of other.
 
 ~Window ()
 Closes the window.
 
void poll_events ()
 Handles every pending window event.
 
const Keyboard & keyboard () const noexcept
 State of the keyboard, updated by poll_events().
 
const Mouse & mouse () const noexcept
 State of the mouse, updated by poll_events().
 
void set_text_input (bool active)
 Starts or stops text input, as when a text field gains or loses the focus.
 
const TextInput & text_input () const noexcept
 Text typed during the last poll_events(), while text input is on.
 
const Gamepad & gamepad () const noexcept
 State of the gamepads plugged in, updated by poll_events().
 
std::size_t gamepad_count () const noexcept
 Number of gamepads plugged in.
 
bool close_requested () const noexcept
 Tells whether the user asked to close the window.
 
void request_close () noexcept
 Marks the window as asked to close, as if the user had closed it.
 
std::string title () const
 Text of the title bar.
 
void set_title (const std::string &title)
 Changes the text of the title bar.
 
Extent size () const
 Size of the window, in screen coordinates.
 
Extent pixel_size () const
 Size of the window's framebuffer, in pixels.
 
GraphicsApi graphics () const noexcept
 Graphics API the window was created for.
 
std::uint32_t id () const noexcept
 Identifier of the window, never 0.
 

Detailed Description

Desktop window: creation, size and events. Drawing is left to a render backend.

SDL requires windows to be created and their events polled on the main thread.

Constructor & Destructor Documentation

◆ Window() [1/3]

aegis2d::platform::Window::Window ( const WindowConfig &  config)
explicit

Opens the window.

Parameters
configTitle, size, behaviour and graphics API of the window.
Exceptions
std::invalid_argumentif the width or the height is not positive.
WindowErrorif SDL cannot initialize video (no display) or create the window.

◆ Window() [2/3]

aegis2d::platform::Window::Window ( const Window &  )
delete

◆ Window() [3/3]

aegis2d::platform::Window::Window ( Window &&  other)
noexcept

Takes over the window of other, which must not be used afterwards.

◆ ~Window()

aegis2d::platform::Window::~Window ( )

Closes the window.

Member Function Documentation

◆ close_requested()

bool aegis2d::platform::Window::close_requested ( ) const
noexcept

Tells whether the user asked to close the window.

Returns
true once a quit event has been polled or request_close() was called.

◆ gamepad()

const Gamepad & aegis2d::platform::Window::gamepad ( ) const
noexcept

State of the gamepads plugged in, updated by poll_events().

Every pad drives the same player: the states of all pads are merged (Gamepad::merge()), so the player can pick up any of them. Not connected when no pad is plugged in, or when SDL cannot open gamepads (the game goes on with the keyboard). Read it through an ActionMap.

Returns
Buttons held, pressed or released during the last poll_events(), and the sticks and triggers.

◆ gamepad_count()

std::size_t aegis2d::platform::Window::gamepad_count ( ) const
noexcept

Number of gamepads plugged in.

Returns
The pads opened by poll_events() and not unplugged since.

◆ graphics()

GraphicsApi aegis2d::platform::Window::graphics ( ) const
noexcept

Graphics API the window was created for.

Returns
The API given in the WindowConfig.

◆ id()

std::uint32_t aegis2d::platform::Window::id ( ) const
noexcept

Identifier of the window, never 0.

Render backends use it to reach the underlying SDL window, so no SDL type appears in the engine's public headers.

Returns
The SDL window ID.

◆ keyboard()

const Keyboard & aegis2d::platform::Window::keyboard ( ) const
noexcept

State of the keyboard, updated by poll_events().

Read it through an ActionMap, so gameplay never depends on raw keys.

Returns
Keys held, and those pressed or released during the last poll_events().

◆ mouse()

const Mouse & aegis2d::platform::Window::mouse ( ) const
noexcept

State of the mouse, updated by poll_events().

Returns
Position in window coordinates, buttons held, pressed or released and the wheel turned during the last poll_events().

◆ operator=() [1/2]

Window & aegis2d::platform::Window::operator= ( const Window &  )
delete

◆ operator=() [2/2]

Window & aegis2d::platform::Window::operator= ( Window &&  other)
noexcept

Closes this window and takes over the window of other.

Returns
This window.

◆ pixel_size()

Extent aegis2d::platform::Window::pixel_size ( ) const

Size of the window's framebuffer, in pixels.

Larger than size() on high-density displays; use it for the viewport.

Returns
The current framebuffer size.

◆ poll_events()

void aegis2d::platform::Window::poll_events ( )

Handles every pending window event.

Starts a new keyboard, mouse and gamepad frame, then applies the key events to keyboard(), the mouse events to mouse() and the gamepad events to gamepad(); a quit request (close button, Alt+F4, Cmd+Q) sets close_requested(). Losing the focus releases every key and button, so no action stays held. Gamepads plugged in are opened, those unplugged are closed (their buttons are released). Call it once per frame.

◆ request_close()

void aegis2d::platform::Window::request_close ( )
noexcept

Marks the window as asked to close, as if the user had closed it.

◆ set_text_input()

void aegis2d::platform::Window::set_text_input ( bool  active)

Starts or stops text input, as when a text field gains or loses the focus.

While on, the characters typed reach text_input() as UTF-8 following the user's keyboard layout, and platforms with an on-screen keyboard show it. Off by default, and whenever typing should drive actions again.

Parameters
activetrue to collect typed text.

◆ set_title()

void aegis2d::platform::Window::set_title ( const std::string &  title)

Changes the text of the title bar.

Parameters
titleNew title, in UTF-8.

◆ size()

Extent aegis2d::platform::Window::size ( ) const

Size of the window, in screen coordinates.

Returns
The current size, which changes when the user resizes the window.

◆ text_input()

const TextInput & aegis2d::platform::Window::text_input ( ) const
noexcept

Text typed during the last poll_events(), while text input is on.

Returns
The frame's UTF-8 text, in the order it was typed.

◆ title()

std::string aegis2d::platform::Window::title ( ) const

Text of the title bar.

Returns
The title given in the WindowConfig or by set_title().

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