Skip to content

Commit

Permalink
Hotkey/Command Executor: removed get_video() member in favor of singl…
Browse files Browse the repository at this point in the history
…eton

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.
  • Loading branch information
Vultraz authored and GregoryLundberg committed Nov 30, 2017
1 parent 4c5528f commit 1467419
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
21 changes: 7 additions & 14 deletions src/hotkey/command_executor.cpp
Expand Up @@ -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<typename TFunc>
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
Expand All @@ -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 {
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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);
});
}
Expand Down
2 changes: 0 additions & 2 deletions src/hotkey/command_executor.hpp
Expand Up @@ -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.
Expand All @@ -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();
Expand Down

0 comments on commit 1467419

Please sign in to comment.