The Battle for Wesnoth  1.19.5+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 class  fake { none , no_window , no_draw , hide_window }
 For describing the type of faked display, if any. More...
 

Functions

void render_screen ()
 
static void init_window (bool hidden=false)
 
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...
 
bool has_window ()
 Whether the game has set up a window to render into. 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...
 
void reset_render_target ()
 Reset the render target to the primary render buffer. 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...
 
std::pair< float, float > get_dpi ()
 Retrieves the current game screen DPI for the build_info API. More...
 
std::vector< std::pair< std::string, std::string > > renderer_report ()
 Provides diagnostic information about the current renderer for the build_info API. More...
 

Enumeration Type Documentation

◆ fake

enum video::fake
strong

For describing the type of faked display, if any.

fake::no_window never tries to create a window, or draw anything. fake::no_draw does create an offscreen window, but does not draw to it. fake::hide_window creates a window as normal, but does not display it.

Enumerator
none 
no_window 
no_draw 
hide_window 

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

◆ current_refresh_rate()

int video::current_refresh_rate ( )

The refresh rate of the screen.

In most cases, this will be the native refresh rate of the display, but could be lower if FPS has been artificially capped (i.e., through –max-fps).

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

Definition at line 486 of file video.cpp.

References prefs::get().

Referenced by draw_manager::get_frame_length().

◆ current_resolution()

point video::current_resolution ( )

The current window size in desktop coordinates.

Definition at line 758 of file video.cpp.

References draw::point().

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

References image::flush_cache(), font::flush_texture_cache(), and LOG_DP.

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

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

◆ draw_offset()

point video::draw_offset ( )
static

Definition at line 447 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 437 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 668 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 496 of file video.cpp.

References DBG_DP, ERR_DP, get_renderer(), and t.

Referenced by clear_render_target(), draw::render_target_setter::render_target_setter(), reset_render_target(), 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 427 of file video.cpp.

Referenced by display::draw_all_panels(), display::draw_label(), display::draw_panel(), draw_manager::invalidate_all(), 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 ( const bool  include_current)

Returns the list of available screen resolutions.

Definition at line 706 of file video.cpp.

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

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

◆ get_dpi()

std::pair< float, float > video::get_dpi ( )

Retrieves the current game screen DPI for the build_info API.

Definition at line 845 of file video.cpp.

References desktop::apple::get_scale_factor(), and sdl::get_version().

◆ 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 prefs::get().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 481 of file video.cpp.

Referenced by gui2::rich_label::get_parsed_text(), draw::tiled_highres(), font::pango_text::update_pixel_scale(), display::update_render_textures(), and gui2::window::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 537 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 ( )

Definition at line 657 of file video.cpp.

Referenced by windows_tray_notification::get_window_handle().

◆ has_window()

bool video::has_window ( )

Whether the game has set up a window to render into.

Definition at line 405 of file video.cpp.

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

References ERR_DP, hide_window, init_fake(), init_test(), init_window(), LOG_DP, no_draw, no_window, and none.

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

References LOG_DP.

Referenced by init().

◆ init_test()

void video::init_test ( )
static

Definition at line 157 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, and update_test_framebuffer().

Referenced by init_test().

◆ init_window()

void video::init_window ( bool  hidden = false)
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 476 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 766 of file video.cpp.

Referenced by set_fullscreen().

◆ output_area()

rect video::output_area ( )

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

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

Referenced by draw_offset(), and output_area().

◆ 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 582 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(), 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 622 of file video.cpp.

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

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

◆ render_screen()

void video::render_screen ( )

Definition at line 547 of file video.cpp.

References clear_render_target(), ERR_DP, reset_render_target(), and WRN_DP.

Referenced by draw_manager::sparkle().

◆ renderer_report()

std::vector< std::pair< std::string, std::string > > video::renderer_report ( )

Provides diagnostic information about the current renderer for the build_info API.

Definition at line 865 of file video.cpp.

◆ reset_render_target()

void video::reset_render_target ( )

Reset the render target to the primary render buffer.

Definition at line 532 of file video.cpp.

References force_render_target().

Referenced by render_screen(), and draw::render_target_setter::render_target_setter().

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

References prefs::get(), is_fullscreen(), and update_buffers().

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

References current_resolution(), prefs::get(), LOG_DP, prefs::set_resolution(), update_buffers(), and update_test_framebuffer().

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

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

References draw_offset(), rect::origin(), 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 798 of file video.cpp.

References prefs::get(), and set_fullscreen().

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

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

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

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

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

References window_has_flags().

◆ window_has_mouse_focus()

bool video::window_has_mouse_focus ( )

True iff the window has mouse focus.

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

References window_has_flags().

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

Referenced by gui2::dialogs::help_browser::on_topic_select(), gui2::dialogs::help_browser::pre_show(), events::pump(), and events::raise_resize_event().