21 #include <SDL2/SDL_hints.h>
22 #include <SDL2/SDL_render.h>
25 #include <SDL2/SDL_mouse.h>
36 const uint32_t window_flags,
37 const uint32_t render_flags)
38 : window_(SDL_CreateWindow(
39 title.c_str(), x, y,
w,
h, window_flags | SDL_WINDOW_HIDDEN))
40 , pixel_format_(SDL_PIXELFORMAT_UNKNOWN)
43 throw exception(
"Failed to create a SDL_Window object.",
true);
55 SDL_SetHint(SDL_HINT_RENDER_DRIVER,
"direct3d11");
59 SDL_SetHint(SDL_HINT_ORIENTATIONS,
"LandscapeLeft LandscapeRight");
62 if(!SDL_CreateRenderer(
window_, -1, render_flags)) {
63 throw exception(
"Failed to create a SDL_Renderer object.",
true);
66 SDL_RendererInfo
info;
67 if(SDL_GetRendererInfo(*
this, &
info) != 0) {
68 throw exception(
"Failed to retrieve the information of the renderer.",
72 if(
info.num_texture_formats == 0) {
73 throw exception(
"The renderer has no texture information available.\n",
77 if((
info.flags & SDL_RENDERER_TARGETTEXTURE) == 0) {
78 throw exception(
"Render-to-texture not supported or enabled!",
false);
82 SDL_SetRenderDrawBlendMode(*
this, SDL_BLENDMODE_BLEND);
86 SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS,
"0");
95 if(!(window_flags & SDL_WINDOW_HIDDEN)) {
110 SDL_RenderSetLogicalSize(SDL_GetRenderer(
window_),
w,
h);
111 SDL_WarpMouseInWindow(
window_,
w / 2,
h / 2);
121 SDL_RenderGetLogicalSize(SDL_GetRenderer(
window_), &res.x, &res.y);
123 SDL_GetWindowSize(*
this, &res.x, &res.y);
132 SDL_GetRendererOutputSize(*
this, &res.x, &res.y);
140 SDL_SetWindowPosition(
window_, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
154 SDL_SetWindowFullscreen(
window_, 0);
168 SDL_SetWindowFullscreen(
window_, SDL_WINDOW_FULLSCREEN_DESKTOP);
174 SDL_SetRenderDrawColor(*
this, r,
g,
b, a);
175 if(SDL_RenderClear(*
this) != 0) {
176 throw exception(
"Failed to clear the SDL_Renderer object.",
183 SDL_RenderPresent(*
this);
189 SDL_SetWindowTitle(
window_, title.c_str());
194 SDL_SetWindowIcon(
window_, icon);
199 SDL_SetWindowMinimumSize(
window_, min_w, min_h);
209 return SDL_GetWindowFlags(
window_);
214 return SDL_GetWindowDisplayIndex(
window_);
219 SDL_Renderer* r = SDL_GetRenderer(
window_);
220 SDL_RenderSetLogicalSize(r,
w,
h);
230 SDL_Renderer* r = SDL_GetRenderer(
window_);
232 SDL_RenderGetLogicalSize(r, &
w, &
h);
238 SDL_Renderer* r = SDL_GetRenderer(
window_);
239 SDL_RenderGetLogicalSize(r, &
w, &
h);
247 window::operator SDL_Window*()
252 window::operator SDL_Renderer*()
254 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.
Contains a basic exception class for SDL operations.
Contains a wrapper class for the SDL_Window class.