20 #include <SDL2/SDL_render.h> 30 const uint32_t window_flags,
31 const uint32_t render_flags)
32 : window_(SDL_CreateWindow(title.c_str(), x, y, w, h, window_flags))
33 , pixel_format_(SDL_PIXELFORMAT_UNKNOWN)
36 throw exception(
"Failed to create a SDL_Window object.",
true);
39 #if SDL_VERSION_ATLEAST(2, 0, 10) 42 SDL_SetHint(SDL_HINT_RENDER_BATCHING,
"0");
45 if(!SDL_CreateRenderer(
window_, -1, render_flags)) {
46 throw exception(
"Failed to create a SDL_Renderer object.",
true);
49 SDL_RendererInfo
info;
50 if(SDL_GetRendererInfo(*
this, &info) != 0) {
51 throw exception(
"Failed to retrieve the information of the renderer.",
55 if(info.num_texture_formats == 0) {
56 throw exception(
"The renderer has no texture information available.\n",
61 SDL_SetRenderDrawBlendMode(*
this, SDL_BLENDMODE_BLEND);
65 SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS,
"0");
83 SDL_SetWindowSize(
window_, w, h);
89 SDL_GetWindowSize(*
this, &res.x, &res.y);
97 SDL_GetRendererOutputSize(*
this, &res.x, &res.y);
104 SDL_SetWindowPosition(
window_, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
114 SDL_SetWindowFullscreen(
window_, 0);
124 SDL_SetWindowFullscreen(
window_, SDL_WINDOW_FULLSCREEN_DESKTOP);
129 SDL_SetRenderDrawColor(*
this, r, g, b, a);
130 if(SDL_RenderClear(*
this) != 0) {
131 throw exception(
"Failed to clear the SDL_Renderer object.",
138 SDL_RenderPresent(*
this);
143 SDL_SetWindowTitle(
window_, title.c_str());
148 SDL_SetWindowIcon(
window_, icon);
153 return SDL_GetWindowFlags(
window_);
158 SDL_SetWindowMinimumSize(
window_, min_w, min_h);
163 return SDL_GetWindowDisplayIndex(
window_);
166 window::operator SDL_Window*()
171 window::operator SDL_Renderer*()
173 return SDL_GetRenderer(
window_);
void full_screen()
Dummy function for setting the window to fullscreen mode.
void set_size(const int w, const int h)
Wrapper for SDL_SetWindowSize.
void restore()
Dummy function for restoring the window.
uint32_t pixel_format_
The preferred pixel format for the renderer.
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.
void set_icon(const surface &icon)
Sets the icon of the window.
void maximize()
Dummy function for maximizing the window.
SDL_Point get_size()
Gets the window's size, in screen coordinates.
SDL_Point get_output_size()
Gets the window's renderer output size, in pixels.
void set_title(const std::string &title)
Sets the title of the window.
SDL_Window * window_
The SDL_Window we own.
window(const window &)=delete
Contains a basic exception class for SDL operations.
void set_minimum_size(int min_w, int min_h)
Set minimum size of the window.
Contains a wrapper class for the SDL_Window class.
void render()
Renders the contents of the window.
void to_window()
Dummy function for returning the window to windowed mode.
void center()
Dummy function for centering the window.