The Battle for Wesnoth  1.17.4+dev
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...
 
SDL_Renderer * get_renderer ()
 Returns a pointer to the underlying window's renderer. More...
 
bool has_window ()
 
void set_fullscreen (bool ison)
 
void toggle_fullscreen ()
 
bool is_fullscreen () const
 
bool supports_vsync () const
 
bool set_resolution (const unsigned width, const unsigned height)
 
bool set_resolution (const point &resolution)
 Set the window resolution. More...
 
point current_resolution ()
 
void update_buffers ()
 Update buffers to match current resolution and pixel scale settings. More...
 
std::vector< pointget_available_resolutions (const bool include_current=false)
 Returns the list of available screen resolutions. More...
 
SDL_Point output_size () const
 Returns the size of the final render target. More...
 
SDL_Point window_size () const
 Returns the size of the window in display units / screen coordinates. More...
 
SDL_Rect draw_area () const
 Returns the size and location of the current drawing area in pixels. More...
 
SDL_Rect input_area () const
 Returns the size and location of the window's input area in pixels. More...
 
int get_width () const
 Returns the width of the drawing surface in pixels. More...
 
int get_height () const
 Returns the height of the drawing surface in pixels. More...
 
std::pair< float, float > get_dpi () const
 The current game screen dpi. 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)
 Copies an area of a surface to the drawing surface. More...
 
void render_screen ()
 Renders the screen. More...
 
void update_framebuffer ()
 Updates and ensures the framebuffer surface is valid. More...
 
void clear_screen ()
 Clear the screen contents. More...
 
surfacegetDrawingSurface ()
 Returns a reference to the drawing surface. 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 bool setup_completed ()
 
static CVideoget_singleton ()
 
static std::string current_driver ()
 
static std::vector< std::string > enumerate_drivers ()
 
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...
 
SDL_Texture * drawing_texture_
 The drawing texture. 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 35 of file video.hpp.

Member Enumeration Documentation

◆ FAKE_TYPES

Enumerator
NO_FAKE 
FAKE 
FAKE_TEST 

Definition at line 41 of file video.hpp.

◆ MODE_EVENT

enum CVideo::MODE_EVENT
private
Enumerator
TO_RES 
TO_FULLSCREEN 
TO_WINDOWED 
TO_MAXIMIZED_WINDOW 

Definition at line 97 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 94 of file video.cpp.

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

◆ ~CVideo()

CVideo::~CVideo ( )

Definition at line 130 of file video.cpp.

References LOG_DP, and singleton_.

Member Function Documentation

◆ blit_surface()

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

Copies an area of a surface to the drawing surface.

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 clipping rect. If not null, the surface will only be drawn within the bounds of the given rectangle.

Definition at line 167 of file video.cpp.

References getDrawingSurface(), and sdl_blit().

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

◆ clear_all_help_strings()

void CVideo::clear_all_help_strings ( )

Removes all help strings.

Definition at line 667 of file video.cpp.

References clear_help_string(), and help_string_.

◆ clear_help_string()

void CVideo::clear_help_string ( int  handle)

◆ clear_screen()

void CVideo::clear_screen ( )

Clear the screen contents.

Definition at line 461 of file video.cpp.

References window.

Referenced by editor::editor_display::editor_display().

◆ current_driver()

std::string CVideo::current_driver ( )
static

Definition at line 484 of file video.cpp.

◆ current_refresh_rate()

int CVideo::current_refresh_rate ( ) const
inline

Definition at line 205 of file video.hpp.

References blit_surface().

Referenced by display::draw_wrap().

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

References game_config::no_delay.

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

◆ draw_area()

SDL_Rect CVideo::draw_area ( ) const

◆ enumerate_drivers()

std::vector< std::string > CVideo::enumerate_drivers ( )
static

Definition at line 490 of file video.cpp.

References n.

◆ faked()

bool CVideo::faked ( ) const
inline

◆ get_available_resolutions()

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

Returns the list of available screen resolutions.

Definition at line 550 of file video.cpp.

References current_resolution(), get_dpi_scale_factor(), i, preferences::min_window_height, preferences::min_window_width, window, point::x, and point::y.

Referenced by gui2::dialogs::preferences_dialog::set_resolution_list().

◆ get_dpi()

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

The current game screen dpi.

Definition at line 512 of file video.cpp.

References desktop::apple::get_scale_factor(), sdl_get_version(), and window.

Referenced by get_dpi_scale_factor().

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

References get_dpi(), get_height(), get_width(), and window_size().

Referenced by get_available_resolutions(), and gui2::settings::update_screen_size_variables().

◆ get_height()

int CVideo::get_height ( ) const

Returns the height of the drawing surface in pixels.

Input coordinates are automatically scaled to correspond, so this also indicates the height of the input surface.

Definition at line 393 of file video.cpp.

Referenced by get_dpi_scale_factor(), gui2::event::sdl_event_handler::handle_event(), gui::menu::max_items_onscreen(), and set_help_string().

◆ get_renderer()

SDL_Renderer * CVideo::get_renderer ( )

Returns a pointer to the underlying window's renderer.

Definition at line 475 of file video.cpp.

References window.

Referenced by texture::reset(), and texture::texture().

◆ get_singleton()

static CVideo& CVideo::get_singleton ( )
inlinestatic

Definition at line 52 of file video.hpp.

Referenced by gui2::dialogs::preferences_dialog::apply_pixel_scale(), gui2::canvas::blit(), gui2::dialogs::loading_screen::display(), do_replay(), gui2::event::sdl_event_handler::draw(), gui2::widget::draw_background(), gui2::widget::draw_children(), gui2::widget::draw_foreground(), sdl::draw_rectangle(), gui::dialog_frame::draw_title(), hotkey::command_executor::execute_command_wrap(), sdl::fill_rectangle(), game_events::wml_event_pump::flush_messages(), gui2::dialogs::preferences_dialog::fullscreen_toggle_callback(), windows_tray_notification::get_window_handle(), gui2::event::sdl_event_handler::handle_event(), gui2::dialogs::preferences_dialog::handle_res_select(), controller_base::handle_scroll(), preferences::prefs_event_handler::handle_window_event(), gui2::minimap::impl_draw_background(), game_lua_kernel::impl_run_animation(), savegame::loadgame::load_game_ingame(), gui2::dialogs::make_screenshot(), help::unit_topic_generator::operator()(), events::peek_for_resize(), controller_base::play_slice(), campaign_controller::playsingle_scenario(), gui2::dialogs::preferences_dialog::post_build(), events::pump(), events::raise_resize_event(), texture::reset(), desktop::notifications::send(), gui2::dialogs::preferences_dialog::set_resolution_list(), editor::context_manager::set_window_title(), gui2::dialogs::modeless_dialog::show(), gui2::dialogs::modal_dialog::show(), gui2::dialogs::mp_lobby::show_preferences_button_callback(), show_tooltip(), help::show_with_toplevel(), texture::texture(), preferences::theme(), preferences::turbo(), gui2::settings::update_screen_size_variables(), gui2::window::window(), and editor::context_manager::~context_manager().

◆ get_width()

int CVideo::get_width ( ) const

Returns the width of the drawing surface in pixels.

Input coordinates are automatically scaled to correspond, so this also indicates the width of the input surface.

Definition at line 388 of file video.cpp.

Referenced by get_dpi_scale_factor(), gui2::event::sdl_event_handler::handle_event(), help::unit_topic_generator::operator()(), and set_help_string().

◆ get_window()

sdl::window * CVideo::get_window ( )

Returns a pointer to the underlying SDL window.

Definition at line 470 of file video.cpp.

References window.

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

◆ getDrawingSurface()

surface & CVideo::getDrawingSurface ( )

◆ has_window()

bool CVideo::has_window ( )
inline

Definition at line 87 of file video.hpp.

References sound::current_driver(), and sound::enumerate_drivers().

◆ init_window()

void CVideo::init_window ( )

◆ initSDL()

void CVideo::initSDL ( )
private

Initializes the SDL video subsystem.

Definition at line 120 of file video.cpp.

References ERR_DP.

Referenced by CVideo().

◆ input_area()

SDL_Rect CVideo::input_area ( ) const

Returns the size and location of the window's input area in pixels.

We use SDL_RendererSetLogicalSize to ensure this always matches draw_area(), but for clarity there are two separate functions.

Definition at line 381 of file video.cpp.

References p, and window.

Referenced by events::pump().

◆ is_fullscreen()

bool CVideo::is_fullscreen ( ) const

Definition at line 617 of file video.cpp.

References window.

Referenced by set_fullscreen().

◆ lock_flips()

void CVideo::lock_flips ( bool  lock)

Definition at line 751 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 435 of file video.cpp.

References updated_locked_.

Referenced by display::display().

◆ make_fake()

void CVideo::make_fake ( )

Definition at line 176 of file video.cpp.

References fake_screen_, and refresh_rate_.

Referenced by CVideo().

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

References refresh_rate_.

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

◆ non_interactive()

bool CVideo::non_interactive ( ) const

Definition at line 139 of file video.cpp.

References window.

Referenced by display::display().

◆ operator=()

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

◆ output_size()

SDL_Point CVideo::output_size ( ) const

Returns the size of the final render target.

This is irrelevant for most purposes. Use draw_area() in stead.

Definition at line 365 of file video.cpp.

References window.

◆ render_screen()

void CVideo::render_screen ( )

Renders the screen.

Should normally not be called directly!

Definition at line 405 of file video.cpp.

References drawing_texture_, fake_screen_, flip_locked_, and window.

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

◆ set_fullscreen()

void CVideo::set_fullscreen ( bool  ison)

◆ set_help_string()

int CVideo::set_help_string ( const std::string &  str)

◆ set_resolution() [1/2]

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

Definition at line 701 of file video.cpp.

Referenced by gui2::dialogs::preferences_dialog::handle_res_select().

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

References preferences::_set_maximized(), preferences::_set_resolution(), current_resolution(), d, display::get_singleton(), LOG_DP, 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 455 of file video.cpp.

References window.

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

References fake_screen_, TO_FULLSCREEN, TO_MAXIMIZED_WINDOW, TO_RES, TO_WINDOWED, update_framebuffer(), 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 449 of file video.cpp.

References window.

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

◆ setup_completed()

static bool CVideo::setup_completed ( )
inlinestatic

Definition at line 47 of file video.hpp.

◆ supports_vsync()

bool CVideo::supports_vsync ( ) const

Definition at line 622 of file video.cpp.

References sdl_get_version().

Referenced by init_window().

◆ toggle_fullscreen()

void CVideo::toggle_fullscreen ( )

◆ update_buffers()

void CVideo::update_buffers ( )

Update buffers to match current resolution and pixel scale settings.

Also triggers a full redraw.

Definition at line 730 of file video.cpp.

References d, display::get_singleton(), LOG_DP, events::raise_resize_event(), and update_framebuffer().

Referenced by gui2::dialogs::preferences_dialog::apply_pixel_scale().

◆ update_framebuffer()

void CVideo::update_framebuffer ( )

◆ update_locked()

bool CVideo::update_locked ( ) const

Whether the screen has been 'locked' or not.

Definition at line 444 of file video.cpp.

References updated_locked_.

Referenced by display::draw(), game_lua_kernel::impl_run_animation(), display::redraw_everything(), display::scroll(), display::scroll_to_xy(), and display::update_display().

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

References window.

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

◆ window_size()

SDL_Point CVideo::window_size ( ) const

Returns the size of the window in display units / screen coordinates.

This should match the value sent by window resize events, and also those used for setting resolution.

Definition at line 371 of file video.cpp.

References window.

Referenced by get_dpi_scale_factor(), and events::raise_resize_event().

Member Data Documentation

◆ drawing_texture_

SDL_Texture* CVideo::drawing_texture_
private

The drawing texture.

Definition at line 305 of file video.hpp.

Referenced by render_screen(), and update_framebuffer().

◆ event_handler_

video_event_handler CVideo::event_handler_
private

Definition at line 329 of file video.hpp.

Referenced by init_window().

◆ fake_screen_

bool CVideo::fake_screen_
private

Definition at line 311 of file video.hpp.

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

◆ flip_locked_

int CVideo::flip_locked_
private

Definition at line 335 of file video.hpp.

Referenced by lock_flips(), and render_screen().

◆ help_string_

int CVideo::help_string_
private

Curent ID of the help string.

Definition at line 332 of file video.hpp.

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

◆ refresh_rate_

int CVideo::refresh_rate_
private

Definition at line 336 of file video.hpp.

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

◆ singleton_

CVideo * CVideo::singleton_ = nullptr
staticprivate

Definition at line 299 of file video.hpp.

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

◆ updated_locked_

int CVideo::updated_locked_
private

Definition at line 334 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: