Commited patch #3880 from grzywacz: "make screenshot" hotkey.

This commit is contained in:
Philippe Plantier 2005-04-17 20:42:10 +00:00
parent e5fc9e7cb3
commit bad9cdea56
8 changed files with 41 additions and 2 deletions

View file

@ -17,6 +17,7 @@
#include "cursor.hpp"
#include "display.hpp"
#include "events.hpp"
#include "filesystem.hpp"
#include "font.hpp"
#include "game_config.hpp"
#include "gamestatus.hpp"
@ -452,6 +453,29 @@ void display::default_zoom()
zoom(DefaultZoom - zoom_);
}
void display::screenshot()
{
std::string datadir = get_screenshot_dir();
unsigned int counter = 0;
std::string name;
do {
std::stringstream filename;
filename << datadir << "/" << _("Screenshot") << "_";
filename.width(5);
filename.fill('0');
filename.setf(std::ios_base::right);
filename << counter << ".bmp";
counter++;
name = filename.str();
} while(file_exists(name));
SDL_SaveBMP(screen_.getSurface().get(), name.c_str());
}
void display::scroll_to_tile(int x, int y, SCROLL_TYPE scroll_type, bool check_fogged)
{
if(screen_.update_locked() || (check_fogged && fogged(x,y)))

View file

@ -85,6 +85,9 @@ public:
//function to take the zoom amount to the default.
void default_zoom();
//function to make a screenshot and save it in a default location
void screenshot();
//function which returns the size of a hex in pixels
//(from top tip to bottom tip or left edge to right edge)
int hex_size() const;

View file

@ -276,6 +276,12 @@ std::string get_intl_dir()
return res;
}
std::string get_screenshot_dir()
{
const std::string dir_path = get_user_data_dir() + "/screenshots";
return get_dir(dir_path);
}
std::string get_dir(const std::string& dir_path)
{
#ifdef _WIN32

View file

@ -50,6 +50,7 @@ std::string get_save_index_file();
std::string get_saves_dir();
std::string get_cache_dir();
std::string get_intl_dir();
std::string get_screenshot_dir();
std::string get_user_data_dir();
std::string get_cwd();

View file

@ -51,6 +51,7 @@ const struct {
{ hotkey::HOTKEY_ZOOM_OUT, "zoomout", N_("Zoom Out"), false },
{ hotkey::HOTKEY_ZOOM_DEFAULT, "zoomdefault", N_("Default Zoom"), false },
{ hotkey::HOTKEY_FULLSCREEN, "fullscreen", N_("Toggle Full Screen"), false },
{ hotkey::HOTKEY_SCREENSHOT, "screenshot", N_("Screenshot"), false },
{ hotkey::HOTKEY_ACCELERATED, "accelerated", N_("Accelerated"), false },
{ hotkey::HOTKEY_UNIT_DESCRIPTION, "describeunit", N_("Unit Description"), false },
{ hotkey::HOTKEY_RENAME_UNIT, "renameunit", N_("Rename Unit"), false },
@ -394,6 +395,9 @@ void execute_command(display& disp, HOTKEY_COMMAND command, command_executor* ex
case HOTKEY_FULLSCREEN:
preferences::set_fullscreen(!preferences::fullscreen());
break;
case HOTKEY_SCREENSHOT:
disp.screenshot();
break;
case HOTKEY_ACCELERATED:
preferences::set_turbo(!preferences::turbo());
break;

View file

@ -31,7 +31,7 @@ enum HOTKEY_COMMAND {
HOTKEY_CYCLE_UNITS, HOTKEY_END_UNIT_TURN, HOTKEY_LEADER,
HOTKEY_UNDO, HOTKEY_REDO,
HOTKEY_ZOOM_IN, HOTKEY_ZOOM_OUT, HOTKEY_ZOOM_DEFAULT,
HOTKEY_FULLSCREEN, HOTKEY_ACCELERATED,
HOTKEY_FULLSCREEN, HOTKEY_SCREENSHOT, HOTKEY_ACCELERATED,
HOTKEY_UNIT_DESCRIPTION, HOTKEY_RENAME_UNIT, HOTKEY_SAVE_GAME, HOTKEY_LOAD_GAME,
HOTKEY_RECRUIT, HOTKEY_REPEAT_RECRUIT, HOTKEY_RECALL, HOTKEY_ENDTURN,
HOTKEY_TOGGLE_GRID, HOTKEY_STATUS_TABLE, HOTKEY_MUTE,

View file

@ -1040,6 +1040,7 @@ bool turn_info::can_execute_command(hotkey::HOTKEY_COMMAND command) const
case hotkey::HOTKEY_ZOOM_OUT:
case hotkey::HOTKEY_ZOOM_DEFAULT:
case hotkey::HOTKEY_FULLSCREEN:
case hotkey::HOTKEY_SCREENSHOT:
case hotkey::HOTKEY_ACCELERATED:
case hotkey::HOTKEY_TOGGLE_GRID:
case hotkey::HOTKEY_STATUS_TABLE:

View file

@ -294,7 +294,7 @@ private:
bool can_execute_command(hotkey::HOTKEY_COMMAND cmd) const
{
return topic_.empty() == false && cmd == hotkey::HOTKEY_HELP;
return (topic_.empty() == false && cmd == hotkey::HOTKEY_HELP) || cmd == hotkey::HOTKEY_SCREENSHOT;
}
display& disp_;