The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | 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...
 
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...
 
int current_refresh_rate () const
 
void blit_surface (int x, int y, surface surf, SDL_Rect *srcrect=nullptr, SDL_Rect *clip_rect=nullptr)
 Draws a surface directly onto the screen framebuffer. More...
 
void flip ()
 Renders the screen. More...
 
void update_framebuffer ()
 Updates and ensures the framebuffer surface is valid. More...
 
void clear_screen ()
 Clear the screen contents. More...
 
surfacegetSurface ()
 Returns a reference to the framebuffer. 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)
 
int set_help_string (const std::string &str)
 Displays a help string with the given text. More...
 
void clear_help_string (int handle)
 Removes the help string with the given handle. More...
 
void clear_all_help_strings ()
 Removes all help strings. More...
 

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 initSDL ()
 Initializes the SDL video subsystem. More...
 

Private Attributes

std::unique_ptr< sdl::windowwindow
 The SDL window object. More...
 
bool fake_screen_
 
video_event_handler event_handler_
 
int help_string_
 Curent ID of the help string. More...
 
int updated_locked_
 
int flip_locked_
 
int refresh_rate_
 

Static Private Attributes

static CVideosingleton_ = nullptr
 

Detailed Description

Definition at line 31 of file video.hpp.

Member Enumeration Documentation

Enumerator
NO_FAKE 
FAKE 
FAKE_TEST 

Definition at line 37 of file video.hpp.

enum CVideo::MODE_EVENT
private
Enumerator
TO_RES 
TO_FULLSCREEN 
TO_WINDOWED 
TO_MAXIMIZED_WINDOW 

Definition at line 76 of file video.hpp.

Constructor & Destructor Documentation

CVideo::CVideo ( const CVideo )
delete
CVideo::CVideo ( FAKE_TYPES  type = NO_FAKE)

Definition at line 84 of file video.cpp.

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

CVideo::~CVideo ( )

Definition at line 119 of file video.cpp.

References LOG_DP, sdl_get_version(), and singleton_.

Member Function Documentation

void CVideo::blit_surface ( int  x,
int  y,
surface  surf,
SDL_Rect *  srcrect = nullptr,
SDL_Rect *  clip_rect = nullptr 
)

Draws a surface directly onto the screen framebuffer.

Parameters
xThe x coordinate at which to draw.
yThe y coordinate at which to draw.
surfThe surface to draw.
srcrectThe area of the surface to draw. This defaults to nullptr, which implies the entire thing.
clip_rectThe clippin rect. If not null, the surface will only be drawn within the bounds of the given rectangle.

Definition at line 162 of file video.cpp.

References getSurface(), and sdl_blit().

Referenced by gui::dialog_frame::draw_border(), gui::button::draw_contents(), gui::tristate_button::draw_contents(), gui::scrollbar::draw_contents(), draw_panel(), gui::menu::imgsel_style::draw_row(), gui::menu::draw_row(), gui::menu::imgsel_style::draw_row_bg(), and display::refresh_report().

void CVideo::clear_all_help_strings ( )

Removes all help strings.

Definition at line 523 of file video.cpp.

References clear_help_string(), and help_string_.

void CVideo::clear_help_string ( int  handle)
void CVideo::clear_screen ( )

Clear the screen contents.

Definition at line 370 of file video.cpp.

References window.

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

int CVideo::current_refresh_rate ( ) const
inline

Definition at line 147 of file video.hpp.

References refresh_rate_.

Referenced by display::draw_wrap().

point CVideo::current_resolution ( )
void CVideo::delay ( unsigned int  milliseconds)
static

Waits a given number of milliseconds before returning.

Definition at line 326 of file video.cpp.

References game_config::no_delay.

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

bool CVideo::faked ( ) const
inline
void CVideo::flip ( )

Renders the screen.

Should normally not be called directly!

Definition at line 333 of file video.cpp.

References fake_screen_, flip_locked_, and window.

Referenced by gui2::event::sdl_event_handler::draw(), display::flip(), and help::show_help().

std::vector< point > CVideo::get_available_resolutions ( const bool  include_current = false)
std::pair< float, float > CVideo::get_dpi_scale_factor ( ) const

The current scale factor on High-DPI screens.

Definition at line 393 of file video.cpp.

References MAGIC_DPI_SCALE_NUMBER, and window.

Referenced by get_available_resolutions(), and screen_area().

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

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

Definition at line 321 of file video.cpp.

References screen_area().

Referenced by controller_base::handle_scroll(), gui::menu::max_items_onscreen(), events::raise_resize_event(), and set_help_string().

static CVideo& CVideo::get_singleton ( )
inlinestatic
int CVideo::get_width ( bool  as_pixels = true) const

Returns the window renderer width in pixels or screen coordinates.

Definition at line 316 of file video.cpp.

References screen_area().

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

sdl::window * CVideo::get_window ( )

Returns a pointer to the underlying SDL window.

Definition at line 379 of file video.cpp.

References window.

Referenced by sdl::draw_rectangle(), sdl::fill_rectangle(), and windows_tray_notification::get_window_handle().

surface & CVideo::getSurface ( )
void CVideo::init_window ( )
void CVideo::initSDL ( )
private

Initializes the SDL video subsystem.

Definition at line 109 of file video.cpp.

References ERR_DP, and error().

Referenced by CVideo().

bool CVideo::is_fullscreen ( ) const

Definition at line 478 of file video.cpp.

References window.

Referenced by set_fullscreen().

void CVideo::lock_flips ( bool  lock)

Definition at line 585 of file video.cpp.

References flip_locked_.

Referenced by flip_locker::flip_locker(), and flip_locker::~flip_locker().

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 344 of file video.cpp.

References updated_locked_.

Referenced by display::display(), update_locker::unlock_update(), and update_locker::update_locker().

void CVideo::make_fake ( )

Definition at line 171 of file video.cpp.

References fake_screen_, refresh_rate_, and image::set_pixel_format().

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

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 185 of file video.cpp.

References refresh_rate_, and image::set_pixel_format().

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

bool CVideo::non_interactive ( ) const

Definition at line 134 of file video.cpp.

References window.

Referenced by display::display().

CVideo& CVideo::operator= ( const CVideo )
delete
SDL_Rect CVideo::screen_area ( bool  as_pixels = true) const
void CVideo::set_fullscreen ( bool  ison)
int CVideo::set_help_string ( const std::string &  str)
bool CVideo::set_resolution ( const unsigned  width,
const unsigned  height 
)

Definition at line 557 of file video.cpp.

bool CVideo::set_resolution ( const point resolution)

Set the window resolution.

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

Definition at line 562 of file video.cpp.

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

void CVideo::set_window_icon ( surface icon)

Sets the icon of the main window.

Parameters
iconThe new icon for the window.

Definition at line 364 of file video.cpp.

References window.

Referenced by game_launcher::init_video().

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 260 of file video.cpp.

References fake_screen_, image::set_pixel_format(), TO_FULLSCREEN, TO_MAXIMIZED_WINDOW, TO_RES, TO_WINDOWED, update_framebuffer(), window, point::x, and point::y.

Referenced by set_fullscreen(), and set_resolution().

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 358 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().

void CVideo::toggle_fullscreen ( )
void CVideo::update_framebuffer ( )

Updates and ensures the framebuffer surface is valid.

This needs to be invoked immediately after a resize event or the game will crash.

Definition at line 199 of file video.cpp.

References surface::clear_without_free(), sdl_get_version(), and window.

Referenced by init_window(), events::peek_for_resize(), and set_window_mode().

bool CVideo::update_locked ( ) const
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 384 of file video.cpp.

References window.

Referenced by controller_base::handle_scroll().

Member Data Documentation

video_event_handler CVideo::event_handler_
private

Definition at line 268 of file video.hpp.

Referenced by init_window().

bool CVideo::fake_screen_
private

Definition at line 250 of file video.hpp.

Referenced by faked(), flip(), make_fake(), and set_window_mode().

int CVideo::flip_locked_
private

Definition at line 274 of file video.hpp.

Referenced by flip(), and lock_flips().

int CVideo::help_string_
private

Curent ID of the help string.

Definition at line 271 of file video.hpp.

Referenced by clear_all_help_strings(), clear_help_string(), and set_help_string().

int CVideo::refresh_rate_
private

Definition at line 275 of file video.hpp.

Referenced by current_refresh_rate(), init_window(), make_fake(), and make_test_fake().

CVideo * CVideo::singleton_ = nullptr
staticprivate

Definition at line 241 of file video.hpp.

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

int CVideo::updated_locked_
private

Definition at line 273 of file video.hpp.

Referenced by lock_updates(), and update_locked().

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

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