#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... | |
bool | has_window () |
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< point > | get_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 () 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) |
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... | |
surface & | getSurface () |
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 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... | |
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 90 of file video.cpp.
References FAKE, FAKE_TEST, initSDL(), make_fake(), make_test_fake(), NO_FAKE, and singleton_.
CVideo::~CVideo | ( | ) |
Definition at line 125 of file video.cpp.
References LOG_DP, sdl_get_version(), and singleton_.
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.
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 clippin rect. If not null, the surface will only be drawn within the bounds of the given rectangle. |
Definition at line 168 of file video.cpp.
References getSurface(), and sdl_blit().
Referenced by gui::dialog_frame::draw_border(), gui::tristate_button::draw_contents(), gui::scrollbar::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(), and display::refresh_report().
void CVideo::clear_all_help_strings | ( | ) |
Removes all help strings.
Definition at line 558 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 550 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 365 of file video.cpp.
References window.
Referenced by editor::editor_display::editor_display(), and game_display::game_display().
|
inline |
Definition at line 164 of file video.hpp.
References blit_surface().
Referenced by display::draw_wrap().
point CVideo::current_resolution | ( | ) |
Definition at line 508 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 321 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().
|
static |
|
inline |
Definition at line 65 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().
void CVideo::flip | ( | ) |
Renders the screen.
Should normally not be called directly!
Definition at line 328 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 | ) |
Returns the list of available screen resolutions.
Definition at line 446 of file video.cpp.
References current_resolution(), get_dpi_scale_factor(), i, preferences::min_window_height, preferences::min_window_width, sort(), 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 407 of file video.cpp.
References desktop::apple::get_scale_factor(), 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 436 of file video.cpp.
References get_dpi().
Referenced by get_available_resolutions(), screen_area(), and gui2::settings::update_screen_size_variables().
int CVideo::get_height | ( | bool | as_pixels = true | ) | const |
Returns the window renderer height in pixels or in screen coordinates.
Definition at line 316 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().
|
inlinestatic |
Definition at line 48 of file video.hpp.
Referenced by gui2::canvas::blit(), gui2::dialogs::loading_screen::display(), do_replay(), gui2::event::sdl_event_handler::draw(), 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(), 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(), events::pump(), events::raise_resize_event(), 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(), help::show_help(), gui2::dialogs::mp_lobby::show_preferences_button_callback(), show_tooltip(), preferences::theme(), preferences::turbo(), gui2::settings::update_screen_size_variables(), gui2::window::window(), and editor::context_manager::~context_manager().
int CVideo::get_width | ( | bool | as_pixels = true | ) | const |
Returns the window renderer width in pixels or screen coordinates.
Definition at line 311 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 374 of file video.cpp.
References window.
Referenced by sdl::draw_rectangle(), sdl::fill_rectangle(), and windows_tray_notification::get_window_handle().
surface & CVideo::getSurface | ( | ) |
Returns a reference to the framebuffer.
Definition at line 503 of file video.cpp.
Referenced by 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(), font::draw_text(), display::flip(), gui2::dialogs::make_screenshot(), display::refresh_report(), surface_restorer::restore(), display::screenshot(), display::scroll(), gui2::window::show(), gui2::window::undraw(), and surface_restorer::update().
|
inline |
Definition at line 80 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 218 of file video.cpp.
References event_handler_, preferences::fullscreen(), h, events::sdl_handler::join_global(), preferences::maximized(), preferences::min_window_height, preferences::min_window_width, refresh_rate_, preferences::resolution(), update_framebuffer(), w, window, point::x, and point::y.
|
private |
bool CVideo::is_fullscreen | ( | ) | const |
void CVideo::lock_flips | ( | bool | lock | ) |
Definition at line 620 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 339 of file video.cpp.
References updated_locked_.
Referenced by display::display().
void CVideo::make_fake | ( | ) |
Definition at line 177 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 189 of file video.cpp.
References refresh_rate_.
Referenced by CVideo(), and test_utils::get_fake_display().
bool CVideo::non_interactive | ( | ) | const |
SDL_Rect CVideo::screen_area | ( | bool | as_pixels = true | ) | const |
Returns the current window renderer area, either in pixels or screen coordinates.
as_pixels | Whether to return the area in pixels (default true) or DPI-independent (DIP) screen coordinates. |
Definition at line 291 of file video.cpp.
References get_dpi_scale_factor(), utf8::size(), and window.
Referenced by gui2::window::draw(), gui::textbox::draw_contents(), draw_label(), draw_panel(), gui::menu::draw_row(), gui::dialog_frame::draw_title(), get_height(), gui::menu::get_item_rect_internal(), get_width(), gui::scrollarea::handle_event(), gui2::event::sdl_event_handler::handle_event(), gui::dialog_frame::layout(), display::layout_buttons(), events::pump(), display::redraw_everything(), display::refresh_report(), display::set_theme(), help::show_help(), gui2::dialogs::mp_lobby::show_preferences_button_callback(), show_tooltip(), and gui2::settings::update_screen_size_variables().
void CVideo::set_fullscreen | ( | bool | ison | ) |
Definition at line 563 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 518 of file video.cpp.
References font::add_floating_label(), font::get_floating_label_rect(), get_height(), get_width(), help_string_, font::line_width(), font::move_floating_label(), 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 592 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 597 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 | ) |
|
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 259 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 353 of file video.cpp.
References window.
Referenced by editor::context_manager::set_window_title(), and editor::context_manager::~context_manager().
void CVideo::toggle_fullscreen | ( | ) |
Definition at line 587 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_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 201 of file video.cpp.
References sdl_get_version(), and window.
Referenced by init_window(), events::peek_for_resize(), and set_window_mode().
bool CVideo::update_locked | ( | ) | const |
Whether the screen has been 'locked' or not.
Definition at line 348 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 398 of file video.cpp.
References window.
Referenced by controller_base::handle_scroll(), and desktop::notifications::send().
|
private |
Definition at line 285 of file video.hpp.
Referenced by init_window().
|
private |
Definition at line 267 of file video.hpp.
Referenced by flip(), make_fake(), and set_window_mode().
|
private |
Definition at line 291 of file video.hpp.
Referenced by flip(), and lock_flips().
|
private |
Curent ID of the help string.
Definition at line 288 of file video.hpp.
Referenced by clear_all_help_strings(), clear_help_string(), and set_help_string().
|
private |
Definition at line 292 of file video.hpp.
Referenced by init_window(), make_fake(), and make_test_fake().
|
staticprivate |
|
private |
Definition at line 290 of file video.hpp.
Referenced by lock_updates(), and update_locked().
|
private |
The SDL window object.
Definition at line 261 of file video.hpp.
Referenced by clear_screen(), current_resolution(), flip(), get_available_resolutions(), get_dpi(), get_window(), init_window(), is_fullscreen(), non_interactive(), screen_area(), set_fullscreen(), set_window_icon(), set_window_mode(), set_window_title(), update_framebuffer(), and window_has_flags().