The Battle for Wesnoth  1.15.0-dev
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
CVideo Class Reference

#include <video.hpp>

Classes

struct  error
 
class  quit
 Type that can be thrown as an exception to quit to desktop. More...
 
class  video_event_handler
 Helper class to manage SDL events. More...
 

Public Types

enum  FAKE_TYPES { NO_FAKE, FAKE, FAKE_TEST }
 

Public Member Functions

 CVideo (const CVideo &)=delete
 
CVideooperator= (const CVideo &)=delete
 
 CVideo (FAKE_TYPES type=NO_FAKE)
 
 ~CVideo ()
 
void make_fake ()
 
void make_test_fake (const unsigned width=1024, const unsigned height=768)
 Creates a fake frame buffer for the unit tests. More...
 
bool faked () const
 
bool non_interactive () const
 
void init_window ()
 Initializes a new SDL window instance, taking into account any preiously saved states. More...
 
sdl::windowget_window ()
 Returns a pointer to the underlying SDL window. More...
 
SDL_Renderer * get_renderer ()
 Returns a pointer to the underlying window's renderer. More...
 
void set_fullscreen (bool ison)
 
void toggle_fullscreen ()
 
bool is_fullscreen () const
 
bool set_resolution (const unsigned width, const unsigned height)
 
bool set_resolution (const point &resolution)
 Set the window resolution. More...
 
point current_resolution ()
 
std::vector< pointget_available_resolutions (const bool include_current=false)
 Returns the list of available screen resolutions. More...
 
SDL_Rect screen_area (bool as_pixels=true) const
 Returns the current window renderer area, either in pixels or screen coordinates. More...
 
int get_width (bool as_pixels=true) const
 Returns the window renderer width in pixels or screen coordinates. More...
 
int get_height (bool as_pixels=true) const
 Returns the window renderer height in pixels or in screen coordinates. More...
 
std::pair< float, float > get_dpi_scale_factor () const
 The current scale factor on High-DPI screens. More...
 
bool window_has_flags (uint32_t flags) const
 Tests whether the given flags are currently set on the SDL window. More...
 
void set_window_title (const std::string &title)
 Sets the title of the main window. More...
 
void set_window_icon (surface &icon)
 Sets the icon of the main window. More...
 
void render_copy (const texture &txt, SDL_Rect *src_rect=nullptr, SDL_Rect *dst_rect=nullptr, const bool flip_h=false, const bool flip_v=false)
 
void clear_screen ()
 Clear the screen contents. More...
 
void lock_updates (bool value)
 Stop the screen being redrawn. More...
 
bool update_locked () const
 Whether the screen has been 'locked' or not. More...
 
void lock_flips (bool)
 

Static Public Member Functions

static CVideoget_singleton ()
 
static void delay (unsigned int milliseconds)
 Waits a given number of milliseconds before returning. More...
 

Private Types

enum  MODE_EVENT { TO_RES, TO_FULLSCREEN, TO_WINDOWED, TO_MAXIMIZED_WINDOW }
 

Private Member Functions

void set_window_mode (const MODE_EVENT mode, const point &size)
 Sets the window's mode - ie, changing it to fullscreen, maximizing, etc. More...
 
void render_screen ()
 Renders the screen. More...
 
void initSDL ()
 Initializes the SDL video subsystem. More...
 

Private Attributes

std::unique_ptr< sdl::windowwindow
 The SDL window object. More...
 
bool fake_screen_
 
std::pair< unsigned, unsigned > fake_size_
 
video_event_handler event_handler_
 
int updated_locked_
 
int flip_locked_
 

Static Private Attributes

static CVideosingleton_ = nullptr
 

Friends

void events::run_event_loop ()
 events::run_event_loop() is the only place that should call render_screen(). More...
 

Detailed Description

Definition at line 36 of file video.hpp.

Member Enumeration Documentation

◆ FAKE_TYPES

Enumerator
NO_FAKE 
FAKE 
FAKE_TEST 

Definition at line 42 of file video.hpp.

◆ MODE_EVENT

enum CVideo::MODE_EVENT
private
Enumerator
TO_RES 
TO_FULLSCREEN 
TO_WINDOWED 
TO_MAXIMIZED_WINDOW 

Definition at line 84 of file video.hpp.

Constructor & Destructor Documentation

◆ CVideo() [1/2]

CVideo::CVideo ( const CVideo )
delete

◆ CVideo() [2/2]

CVideo::CVideo ( FAKE_TYPES  type = NO_FAKE)

Definition at line 44 of file video.cpp.

References FAKE, FAKE_TEST, initSDL(), make_fake(), make_test_fake(), NO_FAKE, and singleton_.

◆ ~CVideo()

CVideo::~CVideo ( )

Definition at line 81 of file video.cpp.

References LOG_DP, and singleton_.

Member Function Documentation

◆ clear_screen()

void CVideo::clear_screen ( )

Clear the screen contents.

Definition at line 309 of file video.cpp.

References window.

Referenced by editor::editor_display::editor_display(), game_display::game_display(), and events::run_event_loop().

◆ current_resolution()

point CVideo::current_resolution ( )

◆ delay()

void CVideo::delay ( unsigned int  milliseconds)
static

Waits a given number of milliseconds before returning.

Definition at line 232 of file video.cpp.

References game_config::no_delay.

Referenced by game_lua_kernel::intf_delay(), controller_base::play_slice(), unit_animator::wait_for_end(), and unit_animator::wait_until().

◆ faked()

bool CVideo::faked ( ) const
inline

◆ get_available_resolutions()

std::vector< point > CVideo::get_available_resolutions ( const bool  include_current = false)

◆ get_dpi_scale_factor()

std::pair< float, float > CVideo::get_dpi_scale_factor ( ) const

The current scale factor on High-DPI screens.

Definition at line 341 of file video.cpp.

References MAGIC_DPI_SCALE_NUMBER, and window.

Referenced by get_available_resolutions(), and screen_area().

◆ get_height()

int CVideo::get_height ( bool  as_pixels = true) const

Returns the window renderer height in pixels or in screen coordinates.

Definition at line 227 of file video.cpp.

References screen_area().

Referenced by controller_base::handle_scroll(), and events::raise_resize_event().

◆ get_renderer()

SDL_Renderer * CVideo::get_renderer ( )

Returns a pointer to the underlying window's renderer.

Definition at line 323 of file video.cpp.

References window.

Referenced by image::create_texture_from_file(), sdl::draw_rectangle(), sdl::fill_rectangle(), texture::reset(), display::screenshot(), and texture::texture().

◆ get_singleton()

static CVideo& CVideo::get_singleton ( )
inlinestatic

◆ get_width()

int CVideo::get_width ( bool  as_pixels = true) const

Returns the window renderer width in pixels or screen coordinates.

Definition at line 222 of file video.cpp.

References screen_area().

Referenced by help::unit_topic_generator::generate(), controller_base::handle_scroll(), and events::raise_resize_event().

◆ get_window()

sdl::window * CVideo::get_window ( )

Returns a pointer to the underlying SDL window.

Definition at line 318 of file video.cpp.

References window.

Referenced by windows_tray_notification::get_window_handle().

◆ init_window()

void CVideo::init_window ( )

Initializes a new SDL window instance, taking into account any preiously saved states.

Definition at line 121 of file video.cpp.

References event_handler_, preferences::fullscreen(), h, events::sdl_handler::join_global(), preferences::maximized(), preferences::min_window_height, preferences::min_window_width, render_screen(), preferences::resolution(), w, window, point::x, and point::y.

Referenced by game_launcher::init_video().

◆ initSDL()

void CVideo::initSDL ( )
private

Initializes the SDL video subsystem.

Definition at line 71 of file video.cpp.

References ERR_DP, and error().

Referenced by CVideo().

◆ is_fullscreen()

bool CVideo::is_fullscreen ( ) const

Definition at line 421 of file video.cpp.

References window.

Referenced by set_fullscreen().

◆ lock_flips()

void CVideo::lock_flips ( bool  lock)

Definition at line 475 of file video.cpp.

References flip_locked_.

◆ lock_updates()

void CVideo::lock_updates ( bool  value)

Stop the screen being redrawn.

Anything that happens while the updates are locked will be hidden from the user's view.

Note that this function is re-entrant, meaning that if lock_updates(true) is called twice, lock_updates(false) must be called twice to unlock updates.

Definition at line 283 of file video.cpp.

References updated_locked_.

Referenced by display::display().

◆ make_fake()

void CVideo::make_fake ( )

Definition at line 108 of file video.cpp.

References fake_screen_, and fake_size_.

Referenced by CVideo(), and game_launcher::init_video().

◆ make_test_fake()

void CVideo::make_test_fake ( const unsigned  width = 1024,
const unsigned  height = 768 
)

Creates a fake frame buffer for the unit tests.

Parameters
widthThe width of the buffer.
heightThe height of the buffer

Definition at line 114 of file video.cpp.

References fake_size_.

Referenced by CVideo(), and test_utils::get_fake_display().

◆ non_interactive()

bool CVideo::non_interactive ( ) const

Definition at line 90 of file video.cpp.

References window.

Referenced by display::display().

◆ operator=()

CVideo& CVideo::operator= ( const CVideo )
delete

◆ render_copy()

void CVideo::render_copy ( const texture txt,
SDL_Rect *  src_rect = nullptr,
SDL_Rect *  dst_rect = nullptr,
const bool  flip_h = false,
const bool  flip_v = false 
)

◆ render_screen()

void CVideo::render_screen ( )
private

Renders the screen.

Definition at line 239 of file video.cpp.

References fake_screen_, flip_locked_, and window.

Referenced by init_window(), and events::run_event_loop().

◆ screen_area()

SDL_Rect CVideo::screen_area ( bool  as_pixels = true) const

Returns the current window renderer area, either in pixels or screen coordinates.

Parameters
as_pixelsWhether to return the area in pixels (default true) or DPI-independent (DIP) screen coordinates.

Definition at line 194 of file video.cpp.

References fake_size_, get_dpi_scale_factor(), utf8::size(), and window.

Referenced by get_height(), get_width(), display::map_outside_area(), display::set_theme(), gui2::dialogs::mp_lobby::show_preferences_button_callback(), show_tooltip(), and gui2::settings::update_screen_size_variables().

◆ set_fullscreen()

void CVideo::set_fullscreen ( bool  ison)

◆ set_resolution() [1/2]

bool CVideo::set_resolution ( const unsigned  width,
const unsigned  height 
)

Definition at line 451 of file video.cpp.

◆ set_resolution() [2/2]

bool CVideo::set_resolution ( const point resolution)

Set the window resolution.

Parameters
resolutionThe new width and height.
Returns
Whether the resolution was successfully changed.

Definition at line 456 of file video.cpp.

References preferences::_set_maximized(), preferences::_set_resolution(), current_resolution(), events::raise_resize_event(), set_window_mode(), and TO_RES.

◆ set_window_icon()

void CVideo::set_window_icon ( surface icon)

Sets the icon of the main window.

Parameters
iconThe new icon for the window.

Definition at line 303 of file video.cpp.

References window.

Referenced by game_launcher::init_video().

◆ set_window_mode()

void CVideo::set_window_mode ( const MODE_EVENT  mode,
const point size 
)
private

Sets the window's mode - ie, changing it to fullscreen, maximizing, etc.

Parameters
modeThe action to perform.
sizeThe new window size. Utilized if mode is TO_RES.

Definition at line 164 of file video.cpp.

References fake_screen_, TO_FULLSCREEN, TO_MAXIMIZED_WINDOW, TO_RES, TO_WINDOWED, window, point::x, and point::y.

Referenced by set_fullscreen(), and set_resolution().

◆ set_window_title()

void CVideo::set_window_title ( const std::string &  title)

Sets the title of the main window.

Parameters
titleThe new title for the window.

Definition at line 297 of file video.cpp.

References window.

Referenced by game_launcher::change_language(), game_launcher::init_video(), editor::context_manager::set_window_title(), and editor::context_manager::~context_manager().

◆ toggle_fullscreen()

void CVideo::toggle_fullscreen ( )

◆ update_locked()

bool CVideo::update_locked ( ) const

Whether the screen has been 'locked' or not.

Definition at line 292 of file video.cpp.

References updated_locked_.

Referenced by display::draw_debugging_aids(), and display::scroll_to_xy().

◆ window_has_flags()

bool CVideo::window_has_flags ( uint32_t  flags) const

Tests whether the given flags are currently set on the SDL window.

Parameters
flagsThe flags to test, OR'd together.

Definition at line 332 of file video.cpp.

References window.

Referenced by controller_base::handle_scroll(), and desktop::notifications::send().

Friends And Related Function Documentation

◆ events::run_event_loop

void events::run_event_loop ( )
friend

events::run_event_loop() is the only place that should call render_screen().

Member Data Documentation

◆ event_handler_

video_event_handler CVideo::event_handler_
private

Definition at line 249 of file video.hpp.

Referenced by init_window().

◆ fake_screen_

bool CVideo::fake_screen_
private

Definition at line 229 of file video.hpp.

Referenced by make_fake(), render_screen(), and set_window_mode().

◆ fake_size_

std::pair<unsigned, unsigned> CVideo::fake_size_
private

Definition at line 231 of file video.hpp.

Referenced by make_fake(), make_test_fake(), and screen_area().

◆ flip_locked_

int CVideo::flip_locked_
private

Definition at line 252 of file video.hpp.

Referenced by lock_flips(), and render_screen().

◆ singleton_

CVideo * CVideo::singleton_ = nullptr
staticprivate

Definition at line 215 of file video.hpp.

Referenced by CVideo(), and ~CVideo().

◆ updated_locked_

int CVideo::updated_locked_
private

Definition at line 251 of file video.hpp.

Referenced by lock_updates(), and update_locked().

◆ window

std::unique_ptr<sdl::window> CVideo::window
private

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