The Battle for Wesnoth  1.19.0-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...
 
void set_logical_size (const point &p)
 
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 47 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 26 of file window.cpp.

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

◆ ~window()

sdl::window::~window ( )

Definition at line 91 of file window.cpp.

References window_.

Member Function Documentation

◆ center()

void sdl::window::center ( )

Dummy function for centering the window.

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

References a, b, and g.

Referenced by window().

◆ full_screen()

void sdl::window::full_screen ( )

Dummy function for setting the window to fullscreen mode.

Definition at line 139 of file window.cpp.

References window_.

◆ get_display_index()

int sdl::window::get_display_index ( )

Definition at line 178 of file window.cpp.

References window_.

◆ get_flags()

uint32_t sdl::window::get_flags ( )

Definition at line 168 of file window.cpp.

References window_.

◆ get_logical_size() [1/2]

point sdl::window::get_logical_size ( ) const

Definition at line 194 of file window.cpp.

References h, w, and window_.

◆ get_logical_size() [2/2]

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

Definition at line 202 of file window.cpp.

References h, w, and window_.

◆ get_output_size()

SDL_Point sdl::window::get_output_size ( )

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

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

◆ maximize()

void sdl::window::maximize ( )

Dummy function for maximizing the window.

Definition at line 124 of file window.cpp.

References window_.

◆ operator SDL_Renderer *()

sdl::window::operator SDL_Renderer * ( )

Conversion operator to a SDL_Renderer*.

Definition at line 218 of file window.cpp.

◆ operator SDL_Window *()

sdl::window::operator SDL_Window * ( )

Conversion operator to a SDL_Window*.

Definition at line 213 of file window.cpp.

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

References pixel_format_.

◆ render()

void sdl::window::render ( )

Renders the contents of the window.

Definition at line 153 of file window.cpp.

Referenced by window().

◆ restore()

void sdl::window::restore ( )

Dummy function for restoring the window.

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

References window_.

◆ set_logical_size() [1/2]

void sdl::window::set_logical_size ( const point p)

Definition at line 189 of file window.cpp.

References p, and set_logical_size().

◆ set_logical_size() [2/2]

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

References h, w, and window_.

Referenced by set_logical_size().

◆ 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 173 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 98 of file window.cpp.

References h, w, 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 158 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 129 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 212 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: