The wrapper class for the SDL_Window class. More...
#include <window.hpp>
Public Member Functions | |
window (const window &)=delete | |
window & | operator= (const window &)=delete |
window (const std::string &title, const int x, const int y, const int w, const int h, const uint32_t window_flags, const uint32_t render_flags) | |
Constructor. More... | |
~window () | |
void | set_size (const int w, const int h) |
Wrapper for SDL_SetWindowSize. More... | |
SDL_Point | get_size () |
Gets the window's size, in screen coordinates. More... | |
SDL_Point | get_output_size () |
Gets the window's renderer output size, in pixels. More... | |
void | center () |
Dummy function for centering the window. More... | |
void | maximize () |
Dummy function for maximizing the window. More... | |
void | restore () |
Dummy function for restoring the window. More... | |
void | to_window () |
Dummy function for returning the window to windowed mode. More... | |
void | full_screen () |
Dummy function for setting the window to fullscreen mode. More... | |
void | fill (uint8_t r, uint8_t g, uint8_t b, uint8_t a=0) |
Clears the contents of the window with a given color. More... | |
void | render () |
Renders the contents of the window. More... | |
void | set_title (const std::string &title) |
Sets the title of the window. More... | |
void | set_icon (const surface &icon) |
Sets the icon of the window. More... | |
uint32_t | get_flags () |
void | set_minimum_size (int min_w, int min_h) |
Set minimum size of the window. More... | |
int | get_display_index () |
void | set_logical_size (int w, int h) |
Sets the desired size of the rendering surface. More... | |
void | set_logical_size (const point &p) |
point | get_logical_size () const |
void | get_logical_size (int &w, int &h) const |
uint32_t | pixel_format () |
The current pixel format of the renderer. More... | |
operator SDL_Window * () | |
Conversion operator to a SDL_Window*. More... | |
operator SDL_Renderer * () | |
Conversion operator to a SDL_Renderer*. More... | |
Private Attributes | |
SDL_Window * | window_ |
The SDL_Window we own. More... | |
uint32_t | pixel_format_ |
The preferred pixel format for the renderer. More... | |
The wrapper class for the SDL_Window class.
At the moment of writing it is not certain yet how many windows will be created. At least one as main window, but maybe the GUI dialogs will have their own window. Once that is known it might be a good idea to evaluate whether the class should become a singleton or not.
The class also wraps several functions operating on SDL_Window objects. For functions not wrapped the class offers an implicit conversion operator to a pointer to the SDL_Window object it owns.
Definition at line 47 of file window.hpp.
|
delete |
sdl::window::window | ( | const std::string & | title, |
const int | x, | ||
const int | y, | ||
const int | w, | ||
const int | h, | ||
const uint32_t | window_flags, | ||
const uint32_t | render_flags | ||
) |
Constructor.
The function calls SDL_CreateWindow and SDL_CreateRenderer.
title | Used as title for SDL_CreateWindow. |
x | Used as x for SDL_CreateWindow. |
y | Used as y for SDL_CreateWindow. |
w | Used as w for SDL_CreateWindow. |
h | Used as x for SDL_CreateWindow. |
window_flags | Used as flags for SDL_CreateWindow. |
render_flags | Used as flags for SDL_CreateRenderer. |
Definition at line 26 of file window.cpp.
References fill(), lg::info(), pixel_format_, render(), and window_.
sdl::window::~window | ( | ) |
Definition at line 91 of file window.cpp.
References window_.
void sdl::window::center | ( | ) |
Dummy function for centering the window.
Definition at line 119 of file window.cpp.
References window_.
void sdl::window::fill | ( | uint8_t | r, |
uint8_t | g, | ||
uint8_t | b, | ||
uint8_t | a = 0 |
||
) |
Clears the contents of the window with a given color.
r | Red value of the color. |
g | Green value of the color. |
b | Blue value of the color. |
a | Alpha value. |
Definition at line 144 of file window.cpp.
Referenced by window().
void sdl::window::full_screen | ( | ) |
Dummy function for setting the window to fullscreen mode.
Definition at line 139 of file window.cpp.
References window_.
int sdl::window::get_display_index | ( | ) |
Definition at line 178 of file window.cpp.
References window_.
uint32_t sdl::window::get_flags | ( | ) |
Definition at line 168 of file window.cpp.
References window_.
point sdl::window::get_logical_size | ( | ) | const |
Definition at line 194 of file window.cpp.
void sdl::window::get_logical_size | ( | int & | w, |
int & | h | ||
) | const |
Definition at line 202 of file window.cpp.
SDL_Point sdl::window::get_output_size | ( | ) |
Gets the window's renderer output size, in pixels.
Definition at line 111 of file window.cpp.
SDL_Point sdl::window::get_size | ( | ) |
Gets the window's size, in screen coordinates.
For the most part, this seems to return the same result as get_output_size. However, SDL indicates for high DPI displays these two functions could differ. I could not observe any change in behavior with DPI virtualization on or off, but to be safe, I'm keeping the two functions separate and using this for matters of window resolution.
Definition at line 103 of file window.cpp.
void sdl::window::maximize | ( | ) |
Dummy function for maximizing the window.
Definition at line 124 of file window.cpp.
References window_.
sdl::window::operator SDL_Renderer * | ( | ) |
Conversion operator to a SDL_Renderer*.
Definition at line 218 of file window.cpp.
sdl::window::operator SDL_Window * | ( | ) |
Conversion operator to a SDL_Window*.
Definition at line 213 of file window.cpp.
uint32_t sdl::window::pixel_format | ( | ) |
The current pixel format of the renderer.
Definition at line 208 of file window.cpp.
References pixel_format_.
void sdl::window::render | ( | ) |
Renders the contents of the window.
Definition at line 153 of file window.cpp.
Referenced by window().
void sdl::window::restore | ( | ) |
Dummy function for restoring the window.
Definition at line 134 of file window.cpp.
References window_.
void sdl::window::set_icon | ( | const surface & | icon | ) |
Sets the icon of the window.
This is a wrapper for SDL_SetWindowIcon.
icon
is a SDL_Surface and not a SDL_Texture, this is part of the SDL 2 API.icon | The new icon for the window. |
Definition at line 163 of file window.cpp.
References window_.
void sdl::window::set_logical_size | ( | const point & | p | ) |
Definition at line 189 of file window.cpp.
References p, and set_logical_size().
void sdl::window::set_logical_size | ( | int | w, |
int | h | ||
) |
Sets the desired size of the rendering surface.
Input event coordinates will be scaled as if the window were also of this size. For best results this should be an integer fraction of the window size.
This is a wrapper for SDL_RenderSetLogicalSize.
w | Width of the window's rendering surface |
h | Height of the window's rendering surface |
Definition at line 183 of file window.cpp.
Referenced by set_logical_size().
void sdl::window::set_minimum_size | ( | int | min_w, |
int | min_h | ||
) |
Set minimum size of the window.
This is a wrapper for SDL_SetWindowMinimumWindowSize.
Definition at line 173 of file window.cpp.
References window_.
void sdl::window::set_size | ( | const int | w, |
const int | h | ||
) |
Wrapper for SDL_SetWindowSize.
w | Used as w for SDL_SetWindowSize. |
h | Used as x for SDL_SetWindowSize. |
Definition at line 98 of file window.cpp.
void sdl::window::set_title | ( | const std::string & | title | ) |
Sets the title of the window.
This is a wrapper for SDL_SetWindowTitle.
title | The new title for the window. |
Definition at line 158 of file window.cpp.
References window_.
void sdl::window::to_window | ( | ) |
Dummy function for returning the window to windowed mode.
Definition at line 129 of file window.cpp.
References window_.
|
private |
The preferred pixel format for the renderer.
Definition at line 212 of file window.hpp.
Referenced by pixel_format(), and window().
|
private |
The SDL_Window we own.
Definition at line 209 of file window.hpp.
Referenced by center(), full_screen(), get_display_index(), get_flags(), get_logical_size(), maximize(), restore(), set_icon(), set_logical_size(), set_minimum_size(), set_size(), set_title(), to_window(), window(), and ~window().