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::setTitle(const std::string& title) {
13 SDL_SetWindowTitle(asw::display::window, title.c_str());
14}
15
16void asw::display::setIcon(const std::string& path) {
17 SDL_Surface* icon = IMG_Load(path.c_str());
18
19 if (icon == nullptr) {
20 return;
21 }
22
23 SDL_SetWindowIcon(asw::display::window, icon);
24}
25
26void asw::display::setFullscreen(bool fullscreen) {
27 SDL_SetWindowFullscreen(asw::display::window, fullscreen);
28}
29
30void asw::display::setResolution(int w, int h) {
31 SDL_SetWindowSize(asw::display::window, w, h);
32}
33
34void asw::display::setResizable(bool resizable) {
35 SDL_SetWindowResizable(asw::display::window, resizable);
36}
37
39 SDL_Point size;
40 SDL_GetWindowSize(asw::display::window, &size.x, &size.y);
41 return size;
42}
43
45 SDL_Point size;
46 SDL_GetRenderLogicalPresentation(asw::display::renderer, &size.x, &size.y,
47 nullptr);
48 return size;
49}
50
52 SDL_FPoint scale;
53 SDL_GetRenderScale(asw::display::renderer, &scale.x, &scale.y);
54 return scale;
55}
56
58 SDL_SetRenderTarget(asw::display::renderer, texture.get());
59}
60
62 SDL_SetRenderTarget(asw::display::renderer, nullptr);
63}
64
66 SDL_RenderClear(asw::display::renderer);
67}
68
70 SDL_RenderPresent(asw::display::renderer);
71}
Display and window routines for the ASW library.
void setRenderTarget(const asw::Texture &texture)
Set the render target to the window.
Definition display.cpp:57
void setIcon(const std::string &path)
Set the icon to display on the window. If it does not exist, this will silently fail.
Definition display.cpp:16
SDL_Point getSize()
Get the size of the window.
Definition display.cpp:38
void setResizable(bool resizable)
Set resizable flag of the window.
Definition display.cpp:34
void present()
Present the window.
Definition display.cpp:69
void clear()
Clear the window.
Definition display.cpp:65
SDL_Point getLogicalSize()
Get the logical size of the window. This may differ from the actual size if scaling is enabled.
Definition display.cpp:44
SDL_FPoint getScale()
Get the scale of the window. This is equivalent to the logical size divided by the actual size.
Definition display.cpp:51
void setResolution(int w, int h)
Set the resolution of the window.
Definition display.cpp:30
void resetRenderTarget()
Reset the render target to the default.
Definition display.cpp:61
void setFullscreen(bool fullscreen)
Set the window to fullscreen or windowed.
Definition display.cpp:26
asw::Renderer * renderer
The renderer for the display module.
Definition display.cpp:9
asw::Window * window
The window for the display module.
Definition display.cpp:10
void setTitle(const std::string &title)
Set the title of the window.
Definition display.cpp:12
std::shared_ptr< SDL_Texture > Texture
Alias for a shared pointer to an SDL_Texture.
Definition types.h:20
SDL_Window Window
Alias for a shared pointer to an SDL_Window.
Definition types.h:35
SDL_Renderer Renderer
Alias for a shared pointer to an SDL_Renderer.
Definition types.h:32
Types used throughout the ASW library.