From 1467419d443e7ee8489837d19452ffad694d8dcb Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Mon, 27 Nov 2017 15:59:38 +1100 Subject: [PATCH] Hotkey/Command Executor: removed get_video() member in favor of singleton Also removed CVideo reference passed to make_screenshot() and its argument function, since the reference is only used in the one specific screenshot() function anyway. --- src/hotkey/command_executor.cpp | 21 +++++++-------------- src/hotkey/command_executor.hpp | 2 -- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/hotkey/command_executor.cpp b/src/hotkey/command_executor.cpp index afc3e3c9fbe7d..1e05d7cbdaba9 100644 --- a/src/hotkey/command_executor.cpp +++ b/src/hotkey/command_executor.cpp @@ -43,13 +43,13 @@ static lg::log_domain log_config("config"); namespace { -bool screenshot(const std::string& filename, CVideo& video) +bool screenshot(const std::string& filename) { - return image::save_image(video.getSurface(), filename); + return image::save_image(CVideo::get_singleton().getSurface(), filename); } template -void make_screenshot(const std::string& name, CVideo& video, const TFunc& func) +void make_screenshot(const std::string& name, const TFunc& func) { std::string filename = filesystem::get_screenshot_dir() + "/" + name + "_"; #ifdef HAVE_LIBPNG @@ -58,7 +58,7 @@ void make_screenshot(const std::string& name, CVideo& video, const TFunc& func) const std::string ext = ".bmp"; #endif filename = filesystem::get_next_filename(filename, ext); - const bool res = func(filename, video); + const bool res = func(filename); if (res) { gui2::dialogs::screenshot_notification::display(filename); } else { @@ -561,10 +561,10 @@ void execute_command(const hotkey_command& command, command_executor* executor, executor->recalculate_minimap(); break; case HOTKEY_FULLSCREEN: - executor->get_video().toggle_fullscreen(); + CVideo::get_singleton().toggle_fullscreen(); break; case HOTKEY_SCREENSHOT: - make_screenshot(_("Screenshot"), executor->get_video(), &::screenshot); + make_screenshot(_("Screenshot"), &::screenshot); break; case HOTKEY_ANIMATE_MAP: preferences::set_animate_map(!preferences::animate_map()); @@ -669,11 +669,6 @@ void command_executor_default::recalculate_minimap() get_display().recalculate_minimap(); } -CVideo& command_executor_default::get_video() -{ - return get_display().video(); -} - void command_executor_default::lua_console() { if (get_display().in_game()) { @@ -712,9 +707,7 @@ void command_executor_default::zoom_default() void command_executor_default::map_screenshot() { - make_screenshot(_("Map-Screenshot"), get_video(), - [this](const std::string& filename, const CVideo&) - { + make_screenshot(_("Map-Screenshot"), [this](const std::string& filename) { return get_display().screenshot(filename, true); }); } diff --git a/src/hotkey/command_executor.hpp b/src/hotkey/command_executor.hpp index b38bf10254c5c..75b8a3020ec29 100644 --- a/src/hotkey/command_executor.hpp +++ b/src/hotkey/command_executor.hpp @@ -119,7 +119,6 @@ class command_executor virtual void set_button_state() {} virtual void recalculate_minimap() {} - virtual CVideo& get_video() = 0; // execute_command's parameter is changed to "hotkey_command& command" and this not maybe that is too inconsitent. // Gets the action's image (if any). Displayed left of the action text in menus. @@ -142,7 +141,6 @@ class command_executor_default : public command_executor protected: virtual display& get_display() = 0; public: - CVideo& get_video(); void set_button_state(); void recalculate_minimap(); void lua_console();