Aegis2D
Modular C++26 2D game engine for networked games
Loading...
Searching...
No Matches
window.hpp
Go to the documentation of this file.
1
4#pragma once
5
6#include <aegis2d/platform/export.hpp>
11
12#include <cstddef>
13#include <cstdint>
14#include <memory>
15#include <stdexcept>
16#include <string>
17
18namespace aegis2d::platform {
19
22class AEGIS2D_PLATFORM_EXPORT WindowError : public std::runtime_error {
23public:
24 using std::runtime_error::runtime_error;
25};
26
30enum class GraphicsApi : std::uint8_t {
32 None,
34 OpenGL,
35};
36
40 std::string title = "Aegis2D";
42 int width = 1280;
44 int height = 720;
46 bool resizable = true;
49};
50
52struct Extent {
54 int width = 0;
56 int height = 0;
57};
58
61class AEGIS2D_PLATFORM_EXPORT Window {
62public:
67 explicit Window(const WindowConfig& config);
68
69 Window(const Window&) = delete;
70 Window& operator=(const Window&) = delete;
72 Window(Window&& other) noexcept;
75 Window& operator=(Window&& other) noexcept;
78
86
90 [[nodiscard]] const Keyboard& keyboard() const noexcept;
91
95 [[nodiscard]] const Mouse& mouse() const noexcept;
96
102 void set_text_input(bool active);
103
106 [[nodiscard]] const TextInput& text_input() const noexcept;
107
115 [[nodiscard]] const Gamepad& gamepad() const noexcept;
116
119 [[nodiscard]] std::size_t gamepad_count() const noexcept;
120
123 [[nodiscard]] bool close_requested() const noexcept;
124
126 void request_close() noexcept;
127
130 [[nodiscard]] std::string title() const;
131
134 void set_title(const std::string& title);
135
138 [[nodiscard]] Extent size() const;
139
143 [[nodiscard]] Extent pixel_size() const;
144
147 [[nodiscard]] GraphicsApi graphics() const noexcept;
148
153 [[nodiscard]] std::uint32_t id() const noexcept;
154
155private:
156 struct Impl;
157 std::unique_ptr<Impl> impl_;
158};
159
160} // namespace aegis2d::platform
Buttons held down, and those pressed or released since the start of the frame, with the position of t...
Definition gamepad.hpp:139
Keys held down, and those pressed or released since the start of the frame.
Definition keyboard.hpp:150
Position of the mouse, buttons held, and those pressed or released and the wheel turned since the sta...
Definition mouse.hpp:38
UTF-8 text typed during a frame, following the user's keyboard layout.
Definition text_input.hpp:25
Thrown when the window cannot be created.
Definition window.hpp:22
Desktop window: creation, size and events. Drawing is left to a render backend.
Definition window.hpp:61
const Keyboard & keyboard() const noexcept
State of the keyboard, updated by poll_events().
Window(const WindowConfig &config)
Opens the window.
~Window()
Closes the window.
Window & operator=(const Window &)=delete
void poll_events()
Handles every pending window event.
Window(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.
Gamepad buttons, sticks and triggers, with no SDL type.
Keyboard keys, their names, and the state of the keyboard during a frame.
Mouse buttons, and the state of the mouse during a frame.
Window and input on top of SDL3, independent of the graphics API (client only).
Definition actions.hpp:19
GraphicsApi
Graphics API the window is prepared for.
Definition window.hpp:30
@ None
No API-specific setup (APIs that only need the native window, or none).
@ OpenGL
The window can receive an OpenGL context (render::opengl::Context).
Definition endpoint.hpp:85
Width and height of a window or a framebuffer.
Definition window.hpp:52
int height
Vertical size.
Definition window.hpp:56
int width
Horizontal size.
Definition window.hpp:54
Settings of a new window.
Definition window.hpp:38
std::string title
Text of the title bar.
Definition window.hpp:40
GraphicsApi graphics
Graphics API the render backend will use with this window.
Definition window.hpp:48
int width
Width of the window, in screen coordinates.
Definition window.hpp:42
int height
Height of the window, in screen coordinates.
Definition window.hpp:44
bool resizable
Whether the user can resize the window.
Definition window.hpp:46
UTF-8 text typed during a frame, following the user's keyboard layout.