The Battle for Wesnoth  1.17.10+dev
Classes | Enumerations | Functions
video Namespace Reference

Classes

struct  error
 An error specifically indicating video subsystem problems. More...
 
class  quit
 Type that can be thrown as an exception to quit to desktop. More...
 

Enumerations

enum  fake { fake::none, fake::window, fake::draw }
 For describing the type of faked display, if any. More...
 

Functions

void render_screen ()
 
static void init_window ()
 
static void init_test_window ()
 
static void init_fake ()
 
static void init_test ()
 
static bool update_framebuffer ()
 
static bool update_test_framebuffer ()
 Returns true if the buffer was changed. More...
 
static point draw_offset ()
 
void init (fake fake_type=fake::none)
 Initialize the video subsystem. More...
 
void deinit ()
 Deinitialize the video subsystem. More...
 
bool headless ()
 The game is running headless. More...
 
bool testing ()
 The game is running unit tests. More...
 
point output_size ()
 Returns the size of the final render target. More...
 
point window_size ()
 Returns the size of the window in display units / screen coordinates. More...
 
rect game_canvas ()
 The game canvas area, in drawing coordinates. More...
 
point game_canvas_size ()
 The size of the game canvas, in drawing coordinates / game pixels. More...
 
point draw_size ()
 The size of the current render target in drawing coordinates. More...
 
rect draw_area ()
 The current drawable area. More...
 
rect output_area ()
 {0, 0, output_size().x, output_size().y} More...
 
rect to_output (const rect &draw_space_rect)
 Convert coordinates in draw space to coordinates in render space. More...
 
rect input_area ()
 Returns the input area of the window, in display coordinates. More...
 
int get_pixel_scale ()
 Get the current active pixel scale multiplier. More...
 
int current_refresh_rate ()
 The refresh rate of the screen. More...
 
void force_render_target (const texture &t)
 Set the render target, without any provided way of setting it back. More...
 
void clear_render_target ()
 Reset the render target to the main window / screen. More...
 
texture get_render_target ()
 Get the current render target. More...
 
surface read_pixels (SDL_Rect *r=nullptr)
 Copy back a portion of the render target that is already drawn. More...
 
surface read_pixels_low_res (SDL_Rect *r=nullptr)
 The same as read_pixels, but returns a low-resolution surface suitable for use with the old drawing system. 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...
 
SDL_Renderer * get_renderer ()
 
SDL_Window * get_window ()
 
std::string current_driver ()
 The current video driver in use, or else "<not initialized>". More...
 
std::vector< std::string > enumerate_drivers ()
 A list of available video drivers. More...
 
static bool window_has_flags (uint32_t flags)
 Tests whether the given flags are currently set on the SDL window. More...
 
bool window_is_visible ()
 True iff the window is not hidden. More...
 
bool window_has_focus ()
 True iff the window has mouse or input focus. More...
 
bool window_has_mouse_focus ()
 True iff the window has mouse focus. More...
 
std::vector< pointget_available_resolutions (bool include_current=false)
 Returns the list of available screen resolutions. More...
 
point current_resolution ()
 The current window size in desktop coordinates. More...
 
bool is_fullscreen ()
 Whether we are currently in fullscreen mode. More...
 
void set_fullscreen (bool)
 Set the fullscreen state. More...
 
void toggle_fullscreen ()
 Toggle fullscreen mode. More...
 
bool set_resolution (const point &resolution)
 Set the window resolution. More...
 
void update_buffers (bool autoupdate=true)
 Update buffers to match current resolution and pixel scale settings. More...
 

Enumeration Type Documentation

◆ fake

enum video::fake
strong

For describing the type of faked display, if any.

fake::window never tries to create a window, or draw anything. fake::draw does create an offscreen window, but does not draw to it.

Enumerator
none 
window 
draw 

Definition at line 44 of file video.hpp.

Function Documentation

◆ clear_render_target()

void video::clear_render_target ( )

Reset the render target to the main window / screen.

Definition at line 513 of file video.cpp.

References force_render_target().

Referenced by render_screen().

◆ current_driver()

std::string video::current_driver ( )

The current video driver in use, or else "<not initialized>".

Definition at line 643 of file video.cpp.

◆ current_refresh_rate()

int video::current_refresh_rate ( )

The refresh rate of the screen.

If a refresh cannot be detected, this may return 0, or it may return a substitute value.

Definition at line 476 of file video.cpp.

Referenced by draw_manager::get_frame_length(), and display::update_fps_count().

◆ current_resolution()

point video::current_resolution ( )

The current window size in desktop coordinates.

Definition at line 739 of file video.cpp.

References draw::point(), and window.

Referenced by get_available_resolutions(), set_resolution(), and gui2::dialogs::preferences_dialog::set_resolution_list().

◆ deinit()

void video::deinit ( )

Deinitialize the video subsystem.

This flushes all texture caches and disconnects the SDL video subsystem.

Definition at line 113 of file video.cpp.

References gui::menu::bluebg_style, image::flush_cache(), font::flush_texture_cache(), LOG_DP, gui::menu::imgsel_style::unload_images(), and window.

Referenced by game_launcher::~game_launcher().

◆ draw_area()

rect video::draw_area ( )

The current drawable area.

Equivalent to {0, 0, draw_size().x, draw_size().y}.

Definition at line 432 of file video.cpp.

Referenced by draw::get_viewport(), read_pixels(), and update_framebuffer().

◆ draw_offset()

point video::draw_offset ( )
static

Definition at line 437 of file video.cpp.

References draw_size(), output_size(), and xbrz::scale().

Referenced by to_output().

◆ draw_size()

point video::draw_size ( )

The size of the current render target in drawing coordinates.

This will be the same as game_canvas_size() unless the render target has been manually changed.

Definition at line 427 of file video.cpp.

Referenced by draw_offset(), and read_pixels_low_res().

◆ enumerate_drivers()

std::vector< std::string > video::enumerate_drivers ( )

A list of available video drivers.

Definition at line 649 of file video.cpp.

References n.

◆ force_render_target()

void video::force_render_target ( const texture t)

Set the render target, without any provided way of setting it back.

End-users should not use this function directly. In stead use draw::set_render_target(), which returns a setter object which will automatically restore the render target upon leaving scope.

Parameters
tThe new render target. This must be a texture created with SDL_TEXTUREACCESS_TARGET, or an empty texture to indicate the underlying window.

Definition at line 482 of file video.cpp.

References DBG_DP, texture::draw_size(), ERR_DP, texture::get(), texture::get_raw_size(), get_renderer(), texture::h(), t, texture::w(), and window.

Referenced by clear_render_target(), render_screen(), draw::render_target_setter::render_target_setter(), update_framebuffer(), update_test_framebuffer(), and draw::render_target_setter::~render_target_setter().

◆ game_canvas()

rect video::game_canvas ( )

The game canvas area, in drawing coordinates.

This is the "screen area", as seen by game systems, and as used for specifying where to draw things on-screen. It may differ, in high-dpi contexts, from input area, window area, and output area.

Usually this is the only area game components should use or care about.

The units it uses can be considered "pixels". Final output will be rendered in higher resolution automatically if and when appropriate.

Definition at line 417 of file video.cpp.

Referenced by display::draw_all_panels(), display::draw_label(), display::draw_panel(), gui::menu::draw_row(), gui::dialog_frame::draw_title(), draw_manager::invalidate_all(), gui::dialog_frame::layout(), display::layout_buttons(), display::map_outside_area(), display::minimap_area(), display::palette_area(), controller_base::play_slice(), display::queue_rerender(), display::refresh_report(), display::screen_location(), display::set_theme(), display::unit_image_area(), and display::update_render_textures().

◆ game_canvas_size()

point video::game_canvas_size ( )

◆ get_available_resolutions()

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

Returns the list of available screen resolutions.

Definition at line 687 of file video.cpp.

References current_resolution(), i, preferences::min_window_height, preferences::min_window_width, PLAIN_LOG, and window.

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

◆ get_pixel_scale()

int video::get_pixel_scale ( )

Get the current active pixel scale multiplier.

This is equal to output_size() / game_canvas_size(). Currently it is always integer, and the same in both dimensions.

This may differ from preferences::pixel_scale() in some cases, For example if the window is too small to fit the desired scale.

Returns
The currently active pixel scale multiplier.

Definition at line 471 of file video.cpp.

Referenced by draw::tiled_highres(), font::pango_text::update_pixel_scale(), and display::update_render_textures().

◆ get_render_target()

texture video::get_render_target ( )

Get the current render target.

Will return an empty texture if the render target is the underlying window.

Definition at line 518 of file video.cpp.

References get_renderer().

Referenced by draw::render_target_setter::render_target_setter().

◆ get_renderer()

SDL_Renderer * video::get_renderer ( )

◆ get_window()

SDL_Window * video::get_window ( )

◆ headless()

bool video::headless ( )

◆ init()

void video::init ( fake  fake_type = fake::none)

Initialize the video subsystem.

This must be called before attempting to use any video functions.

Definition at line 87 of file video.cpp.

References draw, ERR_DP, init_fake(), init_test(), init_window(), LOG_DP, none, and window.

Referenced by test_utils::fake_display_manager::fake_display_manager(), and game_launcher::init_video().

◆ init_fake()

void video::init_fake ( )
static

Definition at line 153 of file video.cpp.

Referenced by init().

◆ init_test()

void video::init_test ( )
static

Definition at line 160 of file video.cpp.

References init_test_window().

Referenced by init().

◆ init_test_window()

void video::init_test_window ( )
static

Definition at line 331 of file video.cpp.

References LOG_DP, update_test_framebuffer(), and window.

Referenced by init_test().

◆ init_window()

void video::init_window ( )
static

◆ input_area()

rect video::input_area ( )

Returns the input area of the window, in display coordinates.

This can be slightly offset within the window, if the drawable area is not the same as the full window area. This will happen if output size is not a perfect multiple of the draw size.

In general this will be almost, but not quite, equal to window_size().

input_area() represents the portion of the window corresponding to game_canvas().

Definition at line 466 of file video.cpp.

Referenced by sdl::get_mouse_state().

◆ is_fullscreen()

bool video::is_fullscreen ( )

Whether we are currently in fullscreen mode.

Definition at line 747 of file video.cpp.

References window.

Referenced by set_fullscreen().

◆ output_area()

rect video::output_area ( )

{0, 0, output_size().x, output_size().y}

Definition at line 450 of file video.cpp.

References output_size(), and p.

◆ output_size()

point video::output_size ( )

Returns the size of the final render target.

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

Definition at line 400 of file video.cpp.

References window.

Referenced by draw_offset(), output_area(), and php_crypt_blowfish_rn().

◆ read_pixels()

surface video::read_pixels ( SDL_Rect *  r = nullptr)

Copy back a portion of the render target that is already drawn.

This area is specified in draw coordinates, not render coordinates. Thus the size of the retrieved surface may not match the size of r.

If not null, r will be automatically clipped to the drawing area.

Note: This is a very slow function! Its use should be phased out for everything except maybe screenshots.

Parameters
rThe portion of the render target to retrieve, in draw coordinates. If not null, this will be modified to reflect the portion of the draw area that has been returned.

Definition at line 563 of file video.cpp.

References rect::clip(), DBG_DP, draw_area(), texture::draw_size(), ERR_DP, texture::get(), texture::get_raw_size(), s, t, to_output(), window, and WRN_DP.

Referenced by gui2::dialogs::make_screenshot(), read_pixels_low_res(), and display::screenshot().

◆ read_pixels_low_res()

surface video::read_pixels_low_res ( SDL_Rect *  r = nullptr)

The same as read_pixels, but returns a low-resolution surface suitable for use with the old drawing system.

This should be considered deprecated, and phased out ASAP.

Definition at line 603 of file video.cpp.

References draw_size(), read_pixels(), s, scale_surface(), window, and WRN_DP.

Referenced by gui2::canvas::draw().

◆ render_screen()

void video::render_screen ( )

Definition at line 528 of file video.cpp.

References clear_render_target(), ERR_DP, force_render_target(), window, and WRN_DP.

Referenced by draw_manager::sparkle().

◆ set_fullscreen()

void video::set_fullscreen ( bool  )

Set the fullscreen state.

If the setting matches the current fullscreen state, the window state will not be changed.

If false and the window is fullscreen, the window will be restored to its last saved non-fullscreen configuration.

Definition at line 755 of file video.cpp.

References preferences::_set_fullscreen(), is_fullscreen(), preferences::maximized(), update_buffers(), and window.

Referenced by gui2::dialogs::preferences_dialog::fullscreen_toggle_callback(), and toggle_fullscreen().

◆ set_resolution()

bool video::set_resolution ( const point resolution)

Set the window resolution.

Todo:
this is no longer useful as fullscreen is always native resolution.
Parameters
resolutionThe new width and height.
Returns
Whether the resolution was successfully changed.

Definition at line 784 of file video.cpp.

References preferences::_set_maximized(), preferences::_set_resolution(), current_resolution(), LOG_DP, preferences::resolution(), update_buffers(), update_test_framebuffer(), and window.

Referenced by test_utils::get_fake_display(), and gui2::dialogs::preferences_dialog::handle_res_select().

◆ set_window_icon()

void video::set_window_icon ( surface icon)

Sets the icon of the main window.

Definition at line 623 of file video.cpp.

References window.

Referenced by game_launcher::init_video().

◆ set_window_title()

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

◆ testing()

bool video::testing ( )

The game is running unit tests.

There is a window and offscreen render buffer, but performing actual rendering is unnecessary.

Definition at line 148 of file video.cpp.

Referenced by playsingle_controller::init_gui(), and draw_manager::sparkle().

◆ to_output()

rect video::to_output ( const rect r)

Convert coordinates in draw space to coordinates in render space.

Definition at line 456 of file video.cpp.

References draw_offset(), rect::pos(), rect::size(), and utf8::size().

Referenced by read_pixels(), and update_framebuffer().

◆ toggle_fullscreen()

void video::toggle_fullscreen ( )

Toggle fullscreen mode.

Equivalent to set_fullscreen(!is_fullscreen()).

Definition at line 779 of file video.cpp.

References preferences::fullscreen(), and set_fullscreen().

Referenced by hotkey::command_executor::execute_command_wrap(), gui2::dialogs::preferences_dialog::initialize_callbacks(), and gui2::window::window().

◆ update_buffers()

void video::update_buffers ( bool  autoupdate = true)

Update buffers to match current resolution and pixel scale settings.

If autoupdate is true and buffers are changed by this call, a full redraw is also triggered.

If nothing has changed, it will not generate any new buffers or queue the redraw.

Definition at line 814 of file video.cpp.

References draw_manager::invalidate_all(), LOG_DP, and update_framebuffer().

Referenced by gui2::dialogs::preferences_dialog::apply_pixel_scale(), events::pump(), set_fullscreen(), and set_resolution().

◆ update_framebuffer()

bool video::update_framebuffer ( )
static

◆ update_test_framebuffer()

bool video::update_test_framebuffer ( )
static

Returns true if the buffer was changed.

Definition at line 168 of file video.cpp.

References force_render_target(), h, LOG_DP, w, and window.

Referenced by init_test_window(), set_resolution(), and update_framebuffer().

◆ window_has_flags()

static bool video::window_has_flags ( uint32_t  flags)
static

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

Parameters
flagsThe flags to test, OR'd together.

Definition at line 667 of file video.cpp.

References window.

Referenced by window_has_focus(), window_has_mouse_focus(), and window_is_visible().

◆ window_has_focus()

bool video::window_has_focus ( )

True iff the window has mouse or input focus.

Definition at line 677 of file video.cpp.

References window_has_flags().

Referenced by desktop::notifications::send().

◆ window_has_mouse_focus()

bool video::window_has_mouse_focus ( )

True iff the window has mouse focus.

Definition at line 682 of file video.cpp.

References window_has_flags().

Referenced by controller_base::handle_scroll().

◆ window_is_visible()

bool video::window_is_visible ( )

True iff the window is not hidden.

Definition at line 672 of file video.cpp.

References window_has_flags().

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

◆ window_size()

point video::window_size ( )

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

References window.

Referenced by preferences::prefs_event_handler::handle_window_event(), and events::raise_resize_event().