The Battle for Wesnoth  1.15.2+dev
Public Member Functions | Private Attributes | List of all members
sdl::window Class Reference

The wrapper class for the SDL_Window class. More...

#include <window.hpp>

Public Member Functions

 window (const window &)=delete
 
windowoperator= (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 ()
 
 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...
 

Detailed Description

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 44 of file window.hpp.

Constructor & Destructor Documentation

◆ window() [1/2]

sdl::window::window ( const window )
delete

◆ window() [2/2]

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.

Parameters
titleUsed as title for SDL_CreateWindow.
xUsed as x for SDL_CreateWindow.
yUsed as y for SDL_CreateWindow.
wUsed as w for SDL_CreateWindow.
hUsed as x for SDL_CreateWindow.
window_flagsUsed as flags for SDL_CreateWindow.
render_flagsUsed as flags for SDL_CreateRenderer.

Definition at line 25 of file window.cpp.

References fill(), lg::info(), pixel_format_, render(), and window_.

◆ ~window()

sdl::window::~window ( )

Definition at line 74 of file window.cpp.

References window_.

Member Function Documentation

◆ center()

void sdl::window::center ( )

Dummy function for centering the window.

Definition at line 102 of file window.cpp.

References window_.

◆ fill()

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.

Parameters
rRed value of the color.
gGreen value of the color.
bBlue value of the color.

Definition at line 127 of file window.cpp.

Referenced by window().

◆ full_screen()

void sdl::window::full_screen ( )

Dummy function for setting the window to fullscreen mode.

Definition at line 122 of file window.cpp.

References window_.

◆ get_display_index()

int sdl::window::get_display_index ( )

Definition at line 161 of file window.cpp.

References window_.

◆ get_flags()

uint32_t sdl::window::get_flags ( )

Definition at line 151 of file window.cpp.

References window_.

◆ get_output_size()

SDL_Point sdl::window::get_output_size ( )

Gets the window's renderer output size, in pixels.

Definition at line 94 of file window.cpp.

◆ get_size()

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.

  • vultraz, 6/27/2017

Definition at line 86 of file window.cpp.

◆ maximize()

void sdl::window::maximize ( )

Dummy function for maximizing the window.

Definition at line 107 of file window.cpp.

References window_.

◆ operator SDL_Renderer *()

sdl::window::operator SDL_Renderer * ( )

Conversion operator to a SDL_Renderer*.

Definition at line 171 of file window.cpp.

References window_.

◆ operator SDL_Window *()

sdl::window::operator SDL_Window * ( )

Conversion operator to a SDL_Window*.

Definition at line 166 of file window.cpp.

References window_.

◆ operator=()

window& sdl::window::operator= ( const window )
delete

◆ render()

void sdl::window::render ( )

Renders the contents of the window.

Definition at line 136 of file window.cpp.

Referenced by window().

◆ restore()

void sdl::window::restore ( )

Dummy function for restoring the window.

Definition at line 117 of file window.cpp.

References window_.

◆ set_icon()

void sdl::window::set_icon ( const surface icon)

Sets the icon of the window.

This is a wrapper for SDL_SetWindowIcon.

Note
The icon is a SDL_Surface and not a SDL_Texture, this is part of the SDL 2 API.
Parameters
iconThe new icon for the window.

Definition at line 146 of file window.cpp.

References window_.

◆ set_minimum_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 156 of file window.cpp.

References window_.

◆ set_size()

void sdl::window::set_size ( const int  w,
const int  h 
)

Wrapper for SDL_SetWindowSize.

Parameters
wUsed as w for SDL_SetWindowSize.
hUsed as x for SDL_SetWindowSize.

Definition at line 81 of file window.cpp.

References window_.

◆ set_title()

void sdl::window::set_title ( const std::string &  title)

Sets the title of the window.

This is a wrapper for SDL_SetWindowTitle.

Parameters
titleThe new title for the window.

Definition at line 141 of file window.cpp.

References window_.

◆ to_window()

void sdl::window::to_window ( )

Dummy function for returning the window to windowed mode.

Definition at line 112 of file window.cpp.

References window_.

Member Data Documentation

◆ pixel_format_

uint32_t sdl::window::pixel_format_
private

The preferred pixel format for the renderer.

Definition at line 189 of file window.hpp.

Referenced by window().

◆ window_

SDL_Window* sdl::window::window_
private

The documentation for this class was generated from the following files: