#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 | |
CVideo & | operator= (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::window * | get_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< point > | get_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... | |
surface & | getDrawingSurface () |
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 CVideo & | get_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::window > | window |
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 CVideo * | singleton_ = nullptr |
enum CVideo::FAKE_TYPES |
|
private |
|
delete |
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 | ( | ) |
Definition at line 130 of file video.cpp.
References LOG_DP, and singleton_.
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.
x | The x coordinate at which to draw. |
y | The y coordinate at which to draw. |
surf | The surface to draw. |
srcrect | The area of the surface to draw. This defaults to nullptr, which implies the entire thing. |
clip_rect | The 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().
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_.
void CVideo::clear_help_string | ( | int | handle | ) |
Removes the help string with the given handle.
Definition at line 659 of file video.cpp.
References help_string_, and font::remove_floating_label().
Referenced by editor::location_palette::adjust_size(), clear_all_help_strings(), editor::location_palette::hide(), editor::editor_palette< overlay >::hide(), gui::widget::process_help_string(), gui::menu::process_help_string(), and editor::location_palette::select_item().
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().
|
inline |
Definition at line 205 of file video.hpp.
References blit_surface().
Referenced by display::draw_wrap().
point CVideo::current_resolution | ( | ) |
Definition at line 612 of file video.cpp.
References window.
Referenced by get_available_resolutions(), set_resolution(), and gui2::dialogs::preferences_dialog::set_resolution_list().
|
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().
SDL_Rect CVideo::draw_area | ( | ) | const |
Returns the size and location of the current drawing area in pixels.
This will usually be an SDL_Rect indicating the full drawing surface.
Definition at line 376 of file video.cpp.
Referenced by gui2::window::draw(), gui::textbox::draw_contents(), draw_label(), draw_panel(), gui::menu::draw_row(), gui::dialog_frame::draw_title(), gui::menu::get_item_rect_internal(), gui::scrollarea::handle_event(), gui2::event::sdl_event_handler::handle_event(), gui::dialog_frame::layout(), display::layout_buttons(), display::redraw_everything(), display::refresh_report(), display::set_theme(), gui2::dialogs::mp_lobby::show_preferences_button_callback(), show_tooltip(), help::show_with_toplevel(), and gui2::settings::update_screen_size_variables().
|
static |
|
inline |
Definition at line 69 of file video.hpp.
Referenced by display_chat_manager::add_chat_message(), display::display(), game_lua_kernel::impl_run_animation(), show_tooltip(), display::turbo_speed(), and gui2::window::window().
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().
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().
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().
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().
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().
|
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().
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().
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().
surface & CVideo::getDrawingSurface | ( | ) |
Returns a reference to the drawing surface.
Definition at line 607 of file video.cpp.
Referenced by gui2::canvas::blit(), blit_surface(), display::display(), gui2::window::draw(), display::draw_all_panels(), gui::dialog_frame::draw_background(), gui::textbox::draw_contents(), help::help_text_area::draw_contents(), display::draw_image_for_report(), display::draw_minimap(), display::draw_minimap_units(), display::flip(), gui2::dialogs::make_screenshot(), font::pango_draw_text(), display::refresh_report(), surface_restorer::restore(), display::screenshot(), display::scroll(), gui2::window::show(), gui2::window::undraw(), and surface_restorer::update().
|
inline |
Definition at line 87 of file video.hpp.
References sound::current_driver(), and sound::enumerate_drivers().
void CVideo::init_window | ( | ) |
Initializes a new SDL window instance, taking into account any preiously saved states.
Definition at line 285 of file video.cpp.
References event_handler_, preferences::fullscreen(), h, events::sdl_handler::join_global(), LOG_DP, preferences::maximized(), preferences::min_window_height, preferences::min_window_width, refresh_rate_, preferences::resolution(), supports_vsync(), update_framebuffer(), preferences::vsync(), w, window, point::x, and point::y.
|
private |
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.
Referenced by events::pump().
bool CVideo::is_fullscreen | ( | ) | const |
void CVideo::lock_flips | ( | bool | lock | ) |
Definition at line 751 of file video.cpp.
References flip_locked_.
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().
void CVideo::make_fake | ( | ) |
Definition at line 176 of file video.cpp.
References fake_screen_, and refresh_rate_.
Referenced by CVideo().
void CVideo::make_test_fake | ( | const unsigned | width = 1024 , |
const unsigned | height = 768 |
||
) |
Creates a fake frame buffer for the unit tests.
width | The width of the buffer. |
height | The height of the buffer. |
Definition at line 184 of file video.cpp.
References refresh_rate_.
Referenced by CVideo(), and test_utils::get_fake_display().
bool CVideo::non_interactive | ( | ) | const |
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.
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().
void CVideo::set_fullscreen | ( | bool | ison | ) |
Definition at line 672 of file video.cpp.
References preferences::_set_fullscreen(), d, display::get_singleton(), is_fullscreen(), preferences::maximized(), preferences::resolution(), set_window_mode(), TO_FULLSCREEN, TO_MAXIMIZED_WINDOW, TO_WINDOWED, and window.
Referenced by gui2::dialogs::preferences_dialog::fullscreen_toggle_callback(), and toggle_fullscreen().
int CVideo::set_help_string | ( | const std::string & | str | ) |
Displays a help string with the given text.
A 'help string' is like a tooltip, but appears at the bottom of the screen so as to not be intrusive.
str | The text to display. |
Definition at line 627 of file video.cpp.
References font::add_floating_label(), font::get_floating_label_rect(), get_height(), get_width(), help_string_, font::move_floating_label(), font::pango_line_width(), font::remove_floating_label(), font::floating_label::set_bg_color(), font::floating_label::set_border_size(), font::floating_label::set_font_size(), font::floating_label::set_position(), utf8::size(), and font::SIZE_LARGE.
Referenced by editor::location_palette::adjust_size(), editor::editor_palette< overlay >::hide(), gui::widget::process_help_string(), gui::menu::process_help_string(), and editor::location_palette::select_item().
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().
bool CVideo::set_resolution | ( | const point & | resolution | ) |
Set the window resolution.
resolution | The new width and height. |
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.
void CVideo::set_window_icon | ( | surface & | icon | ) |
|
private |
Sets the window's mode - ie, changing it to fullscreen, maximizing, etc.
mode | The action to perform. |
size | The 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().
void CVideo::set_window_title | ( | const std::string & | title | ) |
Sets the title of the main window.
title | The 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().
bool CVideo::supports_vsync | ( | ) | const |
Definition at line 622 of file video.cpp.
References sdl_get_version().
Referenced by init_window().
void CVideo::toggle_fullscreen | ( | ) |
Definition at line 696 of file video.cpp.
References preferences::fullscreen(), and set_fullscreen().
Referenced by hotkey::command_executor::execute_command_wrap(), and gui2::window::window().
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().
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 192 of file video.cpp.
References preferences::auto_pixel_scale(), preferences::def_window_height, preferences::def_window_width, drawing_texture_, LOG_DP, preferences::max_pixel_scale, preferences::max_window_height, preferences::max_window_width, preferences::min_window_height, preferences::min_window_width, preferences::pixel_scale(), xbrz::scale(), sdl::update_input_dimensions(), and window.
Referenced by init_window(), events::peek_for_resize(), set_window_mode(), and update_buffers().
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().
bool CVideo::window_has_flags | ( | uint32_t | flags | ) | const |
Tests whether the given flags are currently set on the SDL window.
flags | The 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().
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().
|
private |
The drawing texture.
Definition at line 305 of file video.hpp.
Referenced by render_screen(), and update_framebuffer().
|
private |
Definition at line 329 of file video.hpp.
Referenced by init_window().
|
private |
Definition at line 311 of file video.hpp.
Referenced by make_fake(), render_screen(), and set_window_mode().
|
private |
Definition at line 335 of file video.hpp.
Referenced by lock_flips(), and render_screen().
|
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().
|
private |
Definition at line 336 of file video.hpp.
Referenced by init_window(), make_fake(), and make_test_fake().
|
staticprivate |
|
private |
Definition at line 334 of file video.hpp.
Referenced by lock_updates(), and update_locked().
|
private |
The SDL window object.
Definition at line 302 of file video.hpp.
Referenced by clear_screen(), current_resolution(), get_available_resolutions(), get_dpi(), get_renderer(), get_window(), init_window(), input_area(), is_fullscreen(), non_interactive(), output_size(), render_screen(), set_fullscreen(), set_window_icon(), set_window_mode(), set_window_title(), update_framebuffer(), window_has_flags(), and window_size().