23 #include <SDL2/SDL_render.h>
33 const uint32_t window_flags,
34 const uint32_t render_flags)
35 : window_(SDL_CreateWindow(
36 title.c_str(), x, y,
w,
h, window_flags | SDL_WINDOW_HIDDEN))
37 , pixel_format_(SDL_PIXELFORMAT_UNKNOWN)
40 throw exception(
"Failed to create a SDL_Window object.",
true);
46 SDL_SetHint(SDL_HINT_RENDER_BATCHING,
"0");
49 if(!SDL_CreateRenderer(
window_, -1, render_flags)) {
50 throw exception(
"Failed to create a SDL_Renderer object.",
true);
53 SDL_RendererInfo
info;
54 if(SDL_GetRendererInfo(*
this, &
info) != 0) {
55 throw exception(
"Failed to retrieve the information of the renderer.",
59 if(
info.num_texture_formats == 0) {
60 throw exception(
"The renderer has no texture information available.\n",
64 if((
info.flags & SDL_RENDERER_TARGETTEXTURE) == 0) {
65 throw exception(
"Render-to-texture not supported or enabled!",
false);
69 SDL_SetRenderDrawBlendMode(*
this, SDL_BLENDMODE_BLEND);
73 SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS,
"0");
82 if(!(window_flags & SDL_WINDOW_HIDDEN)) {
102 SDL_GetWindowSize(*
this, &res.x, &res.y);
110 SDL_GetRendererOutputSize(*
this, &res.x, &res.y);
117 SDL_SetWindowPosition(
window_, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
127 SDL_SetWindowFullscreen(
window_, 0);
137 SDL_SetWindowFullscreen(
window_, SDL_WINDOW_FULLSCREEN_DESKTOP);
142 SDL_SetRenderDrawColor(*
this, r,
g,
b,
a);
143 if(SDL_RenderClear(*
this) != 0) {
144 throw exception(
"Failed to clear the SDL_Renderer object.",
151 SDL_RenderPresent(*
this);
156 SDL_SetWindowTitle(
window_, title.c_str());
161 SDL_SetWindowIcon(
window_, icon);
166 return SDL_GetWindowFlags(
window_);
171 SDL_SetWindowMinimumSize(
window_, min_w, min_h);
176 return SDL_GetWindowDisplayIndex(
window_);
181 SDL_Renderer* r = SDL_GetRenderer(
window_);
182 SDL_RenderSetLogicalSize(r,
w,
h);
192 SDL_Renderer* r = SDL_GetRenderer(
window_);
194 SDL_RenderGetLogicalSize(r, &
w, &
h);
200 SDL_Renderer* r = SDL_GetRenderer(
window_);
201 SDL_RenderGetLogicalSize(r, &
w, &
h);
209 window::operator SDL_Window*()
214 window::operator SDL_Renderer*()
216 return SDL_GetRenderer(window_);
SDL_Point get_output_size()
Gets the window's renderer output size, in pixels.
void set_size(const int w, const int h)
Wrapper for SDL_SetWindowSize.
void to_window()
Dummy function for returning the window to windowed mode.
uint32_t pixel_format()
The current pixel format of the renderer.
window(const window &)=delete
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.
point get_logical_size() const
void center()
Dummy function for centering the window.
void render()
Renders the contents of the window.
void restore()
Dummy function for restoring the window.
void set_minimum_size(int min_w, int min_h)
Set minimum size of the window.
SDL_Window * window_
The SDL_Window we own.
void full_screen()
Dummy function for setting the window to fullscreen mode.
SDL_Point get_size()
Gets the window's size, in screen coordinates.
void set_icon(const surface &icon)
Sets the icon of the window.
void set_logical_size(int w, int h)
Sets the desired size of the rendering surface.
void maximize()
Dummy function for maximizing the window.
uint32_t pixel_format_
The preferred pixel format for the renderer.
void set_title(const std::string &title)
Sets the title of the window.
bool runtime_at_least(uint8_t major, uint8_t minor=0, uint8_t patch=0)
Returns true if the runtime SDL version is at or greater than the specified version,...
Contains a basic exception class for SDL operations.
Contains a wrapper class for the SDL_Window class.