The Battle for Wesnoth  1.17.4+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 ()
 
void set_logical_size (int w, int h)
 Sets the desired size of the rendering surface. More...
 
SDL_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...
 

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 45 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 27 of file window.cpp.

References fill(), get_logical_size(), get_size(), lg::info(), pixel_format_, render(), sdl::update_input_dimensions(), and window_.

◆ ~window()

sdl::window::~window ( )

Definition at line 83 of file window.cpp.

References window_.

Member Function Documentation

◆ center()

void sdl::window::center ( )

Dummy function for centering the window.

Definition at line 112 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.
aAlpha value.

Definition at line 141 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 135 of file window.cpp.

References get_logical_size(), get_size(), sdl::update_input_dimensions(), and window_.

◆ get_display_index()

int sdl::window::get_display_index ( )

Definition at line 177 of file window.cpp.

References window_.

◆ get_flags()

uint32_t sdl::window::get_flags ( )

Definition at line 165 of file window.cpp.

References window_.

◆ get_logical_size() [1/2]

SDL_Point sdl::window::get_logical_size ( ) const

Definition at line 189 of file window.cpp.

References h, w, and window_.

Referenced by full_screen(), maximize(), restore(), set_logical_size(), set_minimum_size(), set_size(), to_window(), and window().

◆ get_logical_size() [2/2]

void sdl::window::get_logical_size ( int &  w,
int &  h 
) const

Definition at line 197 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 104 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 96 of file window.cpp.

Referenced by full_screen(), maximize(), restore(), set_logical_size(), set_minimum_size(), set_size(), to_window(), and window().

◆ maximize()

void sdl::window::maximize ( )

Dummy function for maximizing the window.

Definition at line 117 of file window.cpp.

References get_logical_size(), get_size(), sdl::update_input_dimensions(), and window_.

◆ operator SDL_Renderer *()

sdl::window::operator SDL_Renderer * ( )

Conversion operator to a SDL_Renderer*.

Definition at line 213 of file window.cpp.

References window_.

◆ operator SDL_Window *()

sdl::window::operator SDL_Window * ( )

Conversion operator to a SDL_Window*.

Definition at line 208 of file window.cpp.

References window_.

◆ operator=()

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

◆ pixel_format()

uint32_t sdl::window::pixel_format ( )

The current pixel format of the renderer.

Definition at line 203 of file window.cpp.

References pixel_format_.

◆ render()

void sdl::window::render ( )

Renders the contents of the window.

Definition at line 150 of file window.cpp.

Referenced by window().

◆ restore()

void sdl::window::restore ( )

Dummy function for restoring the window.

Definition at line 129 of file window.cpp.

References get_logical_size(), get_size(), sdl::update_input_dimensions(), and 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 160 of file window.cpp.

References window_.

◆ 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.

Parameters
wWidth of the window's rendering surface
hHeight of the window's rendering surface

Definition at line 182 of file window.cpp.

References get_logical_size(), get_size(), sdl::update_input_dimensions(), and 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 170 of file window.cpp.

References get_logical_size(), get_size(), sdl::update_input_dimensions(), and 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 90 of file window.cpp.

References get_logical_size(), get_size(), sdl::update_input_dimensions(), and 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 155 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 123 of file window.cpp.

References get_logical_size(), get_size(), sdl::update_input_dimensions(), and window_.

Member Data Documentation

◆ pixel_format_

uint32_t sdl::window::pixel_format_
private

The preferred pixel format for the renderer.

Definition at line 209 of file window.hpp.

Referenced by pixel_format(), and window().

◆ window_

SDL_Window* sdl::window::window_
private

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