ASW Lib
A.D.S. Games SDL Wrapper Library. A library targeted at Allegro4 users who want to switch to SDL3 and use modern c++.
Loading...
Searching...
No Matches
display.cpp
Go to the documentation of this file.
2
3#include <SDL3/SDL.h>
4#include <SDL3_image/SDL_image.h>
5#include <string>
6
8
11
12void asw::display::set_title(const std::string& title)
13{
14 SDL_SetWindowTitle(asw::display::window, title.c_str());
15}
16
17void asw::display::set_icon(const std::string& path)
18{
19 SDL_Surface* icon = IMG_Load(path.c_str());
20
21 if (icon == nullptr) {
22 return;
23 }
24
25 SDL_SetWindowIcon(asw::display::window, icon);
26}
27
28void asw::display::set_fullscreen(bool fullscreen)
29{
30 SDL_SetWindowFullscreen(asw::display::window, fullscreen);
31}
32
34{
35 SDL_SetWindowSize(asw::display::window, w, h);
36}
37
38void asw::display::set_resizable(bool resizable)
39{
40 SDL_SetWindowResizable(asw::display::window, resizable);
41}
42
44{
45 asw::Vec2<int> size;
46 SDL_GetWindowSize(asw::display::window, &size.x, &size.y);
47 return size;
48}
49
51{
52 asw::Vec2<int> size;
53
54 if (asw::display::renderer == nullptr) {
55 return size;
56 }
57
58 SDL_GetRenderLogicalPresentation(asw::display::renderer, &size.x, &size.y, nullptr);
59 return size;
60}
61
63{
64 asw::Vec2<float> scale;
65
66 if (asw::display::renderer == nullptr) {
67 return scale;
68 }
69
70 SDL_GetRenderScale(asw::display::renderer, &scale.x, &scale.y);
71 return scale;
72}
73
75{
76 if (asw::display::renderer == nullptr) {
77 return;
78 }
79
80 SDL_SetRenderTarget(asw::display::renderer, texture.get());
81}
82
84{
85 if (asw::display::renderer == nullptr) {
86 return;
87 }
88
89 SDL_SetRenderTarget(asw::display::renderer, nullptr);
90}
91
93{
94 if (asw::display::renderer == nullptr) {
95 return;
96 }
97
98 SDL_RenderClear(asw::display::renderer);
99}
100
102{
103 SDL_SetRenderDrawColor(asw::display::renderer, color.r, color.g, color.b, color.a);
104 SDL_RenderClear(asw::display::renderer);
105}
106
108{
109 if (asw::display::renderer == nullptr) {
110 return;
111 }
112
113 SDL_RenderPresent(asw::display::renderer);
114}
115
117{
118 SDL_SetRenderDrawBlendMode(asw::display::renderer, static_cast<SDL_BlendMode>(mode));
119}
A 2D vector in space.
Definition geometry.h:21
T y
The y component of the vector.
Definition geometry.h:196
T x
The x component of the vector.
Definition geometry.h:193
Display and window routines for the ASW library.
void set_icon(const std::string &path)
Set the icon to display on the window. If it does not exist, this will silently fail.
Definition display.cpp:17
asw::Vec2< float > get_scale()
Get the scale of the window. This is equivalent to the logical size divided by the actual size.
Definition display.cpp:62
void set_fullscreen(bool fullscreen)
Set the window to fullscreen or windowed.
Definition display.cpp:28
asw::Vec2< int > get_logical_size()
Get the logical size of the window. This may differ from the actual size if scaling is enabled.
Definition display.cpp:50
void set_blend_mode(asw::BlendMode mode)
Set the blend mode of a texture.
Definition display.cpp:116
void reset_render_target()
Reset the render target to the default.
Definition display.cpp:83
asw::Vec2< int > get_size()
Get the size of the window.
Definition display.cpp:43
void present()
Present the window.
Definition display.cpp:107
void set_render_target(const asw::Texture &texture)
Set the render target to the window.
Definition display.cpp:74
void clear()
Clear the window.
Definition display.cpp:92
asw::Renderer * renderer
The renderer for the display module.
Definition display.cpp:9
void set_title(const std::string &title)
Set the title of the window.
Definition display.cpp:12
void set_resolution(int w, int h)
Set the resolution of the window.
Definition display.cpp:33
asw::Window * window
The window for the display module.
Definition display.cpp:10
void set_resizable(bool resizable)
Set resizable flag of the window.
Definition display.cpp:38
std::shared_ptr< SDL_Texture > Texture
Alias for a shared pointer to an SDL_Texture.
Definition types.h:38
BlendMode
Mappings from SDL_BLENDMODE to ASW BlendMode.
Definition types.h:20
SDL_Window Window
Alias for a shared pointer to an SDL_Window.
Definition types.h:53
SDL_Renderer Renderer
Alias for a shared pointer to an SDL_Renderer.
Definition types.h:50
RGBA color struct with 8-bit channels.
Definition color.h:11
uint8_t b
Definition color.h:14
uint8_t r
Definition color.h:12
uint8_t g
Definition color.h:13
uint8_t a
Definition color.h:15
Types used throughout the ASW library.