Aegis2D
Modular C++26 2D game engine for networked games
Loading...
Searching...
No Matches
letterbox.hpp
Go to the documentation of this file.
1
3#pragma once
4
7#include <aegis2d/render/export.hpp>
8
9#include <cstdint>
10
11namespace aegis2d::render {
12
14enum class ScaleMode : std::uint8_t {
16 Fit,
20 Integer,
21};
22
30 Vec2 size{1280.0F, 720.0F};
34 Color bars{.r = 0.0F, .g = 0.0F, .b = 0.0F, .a = 1.0F};
35};
36
38struct Letterbox {
40 int x = 0;
42 int y = 0;
44 int width = 0;
46 int height = 0;
48 float scale = 0.0F;
49
52 [[nodiscard]] constexpr bool empty() const noexcept { return width <= 0 || height <= 0; }
53
55 friend constexpr bool operator==(const Letterbox&, const Letterbox&) noexcept = default;
56};
57
69[[nodiscard]] AEGIS2D_RENDER_EXPORT Letterbox letterbox(Vec2 logical, int width, int height,
70 ScaleMode mode = ScaleMode::Fit) noexcept;
71
78[[nodiscard]] AEGIS2D_RENDER_EXPORT Vec2 to_logical(const Letterbox& box,
79 Vec2 framebuffer) noexcept;
80
81} // namespace aegis2d::render
RGBA color used by the renderer.
Vector and matrix types of the engine (GLM behind engine names).
OpenGL renderer: sprites, text and camera (client only).
Definition bitmap_font.hpp:16
Letterbox letterbox(Vec2 logical, int width, int height, ScaleMode mode=ScaleMode::Fit) noexcept
Fits a logical screen into a framebuffer, centered, keeping its aspect ratio.
aegis2d::Vec2 Vec2
2D vector of floats, in logical pixels: the engine-wide aegis2d::Vec2.
Definition renderer.hpp:17
ScaleMode
How a logical screen is scaled to the window.
Definition letterbox.hpp:14
@ Fit
As large as the window allows: the whole window is used on one axis.
@ Integer
The largest whole scale (x1, x2, x3...), so every logical pixel covers the same number of window pixe...
Vec2 to_logical(const Letterbox &box, Vec2 framebuffer) noexcept
Logical pixel under a point of the framebuffer, such as the mouse.
RGBA color with components in [0, 1].
Definition color.hpp:10
float r
Red component.
Definition color.hpp:12
Where the logical screen goes in the window's framebuffer.
Definition letterbox.hpp:38
int y
Top edge, in framebuffer pixels from the top.
Definition letterbox.hpp:42
int height
Height in framebuffer pixels.
Definition letterbox.hpp:46
int x
Left edge, in framebuffer pixels from the left.
Definition letterbox.hpp:40
float scale
Framebuffer pixels per logical pixel; 0 when nothing is shown.
Definition letterbox.hpp:48
constexpr bool empty() const noexcept
Tells whether the logical screen covers no pixel (a minimized window).
Definition letterbox.hpp:52
int width
Width in framebuffer pixels.
Definition letterbox.hpp:44
friend constexpr bool operator==(const Letterbox &, const Letterbox &) noexcept=default
Compares the areas.
The game's screen at a fixed size, whatever the window's.
Definition letterbox.hpp:28
Color bars
Color of the bars around the screen.
Definition letterbox.hpp:34
Vec2 size
Width and height in logical pixels, such as 1280 x 720.
Definition letterbox.hpp:30
ScaleMode mode
How the screen is scaled.
Definition letterbox.hpp:32