(svn r5626) CodeChange : Remove the global _make_screenshot and implement a more flexible mechanism

Simplification of the handling of the main_gui menus,
Removal of repetitions and Hiding the internals of screenshots.
Thanks to glx, Rubidium and Truelight for pointers
pull/155/head
belugas 18 years ago
parent ee91a45718
commit e4474db35f

@ -19,6 +19,7 @@
#include "vehicle.h"
#include "station.h"
#include "strings.h"
#include "screenshot.h"
#ifdef ENABLE_NETWORK
#include "table/strings.h"
@ -914,10 +915,10 @@ DEF_CONSOLE_CMD(ConScreenShot)
if (argc > 3) return false;
_make_screenshot = 1;
SetScreenshotType(SC_VIEWPORT);
if (argc > 1) {
if (strcmp(argv[1], "big") == 0 || (argc == 3 && strcmp(argv[2], "big") == 0))
_make_screenshot = 2;
SetScreenshotType(SC_WORLD);
if (strcmp(argv[1], "no_con") == 0 || (argc == 3 && strcmp(argv[2], "no_con") == 0))
IConsoleClose();

@ -28,6 +28,7 @@
#include "variables.h"
#include "train.h"
#include "unmovable_map.h"
#include "screenshot.h"
#include "network_data.h"
#include "network_client.h"
@ -403,14 +404,24 @@ static void MenuClickNewspaper(int index)
}
}
static void MenuClickSmallScreenshot(void)
{
SetScreenshotType(SC_VIEWPORT);
}
static void MenuClickWorldScreenshot(void)
{
SetScreenshotType(SC_WORLD);
}
static void MenuClickHelp(int index)
{
switch (index) {
case 0: PlaceLandBlockInfo(); break;
case 2: IConsoleSwitch(); break;
case 3: _make_screenshot = 1; break;
case 4: _make_screenshot = 2; break;
case 5: ShowAboutWindow(); break;
case 0: PlaceLandBlockInfo(); break;
case 2: IConsoleSwitch(); break;
case 3: MenuClickSmallScreenshot(); break;
case 4: MenuClickWorldScreenshot(); break;
case 5: ShowAboutWindow(); break;
}
}
@ -1894,8 +1905,8 @@ static void MainToolbarWndProc(Window *w, WindowEvent *e)
case WKC_SHIFT | WKC_F10:ShowBuildAirToolbar(); break;
case WKC_SHIFT | WKC_F11: ShowBuildTreesToolbar(); break;
case WKC_SHIFT | WKC_F12: ShowMusicWindow(); break;
case WKC_CTRL | 'S': _make_screenshot = 1; break;
case WKC_CTRL | 'G': _make_screenshot = 2; break;
case WKC_CTRL | 'S': MenuClickSmallScreenshot(); break;
case WKC_CTRL | 'G': MenuClickWorldScreenshot(); break;
case WKC_CTRL | WKC_ALT | 'C': if (!_networking) ShowCheatWindow(); break;
case 'A': ShowBuildRailToolbar(_last_built_railtype, 4); break; /* Invoke Autorail */
case 'L': ShowTerraformToolbar(); break;
@ -2095,8 +2106,8 @@ static void ScenEditToolbarWndProc(Window *w, WindowEvent *e)
case WKC_F9: ToolbarScenPlaceSign(w); break;
case WKC_F10: ShowMusicWindow(); break;
case WKC_F11: PlaceLandBlockInfo(); break;
case WKC_CTRL | 'S': _make_screenshot = 1; break;
case WKC_CTRL | 'G': _make_screenshot = 2; break;
case WKC_CTRL | 'S': MenuClickSmallScreenshot(); break;
case WKC_CTRL | 'G': MenuClickWorldScreenshot(); break;
case 'L': ShowEditorTerraformToolBar(); break;
}
break;

@ -936,19 +936,7 @@ void GameLoop(void)
if (_dirkeys) HandleKeyScrolling();
// make a screenshot?
if (_make_screenshot != 0) {
switch (_make_screenshot) {
case 1: // make small screenshot
UndrawMouseCursor();
ShowScreenshotResult(MakeScreenshot());
break;
case 2: // make large screenshot
ShowScreenshotResult(MakeWorldScreenshot(-(int)MapMaxX() * TILE_PIXELS, 0, (MapMaxX() + MapMaxY()) * TILE_PIXELS, (MapMaxX() + MapMaxY()) * TILE_PIXELS >> 1, 0));
break;
}
_make_screenshot = 0;
}
if (IsScreenshotRequested()) ShowScreenshotResult(MakeScreenshot());
// switch game mode?
if (_switch_mode != SM_NONE) {

@ -16,6 +16,7 @@
char _screenshot_format_name[8];
uint _num_screenshot_formats;
uint _cur_screenshot_format;
ScreenshotType current_screenshot_type;
// called by the ScreenShot proc to generate screenshot lines.
typedef void ScreenshotCallback(void *userdata, Pixel *buf, uint y, uint pitch, uint n);
@ -431,6 +432,7 @@ void InitializeScreenshotFormats(void)
}
_cur_screenshot_format = j;
_num_screenshot_formats = lengthof(_screenshot_formats);
make_screenshot = SC_NONE;
}
const char *GetScreenshotFormatDesc(int i)
@ -518,27 +520,52 @@ static char *MakeScreenshotName(const char *ext)
return filename;
}
bool MakeScreenshot(void)
void SetScreenshotType(ScreenshotType t)
{
current_screenshot_type = t;
}
bool IsScreenshotRequested(void)
{
return (current_screenshot_type != SC_NONE);
}
static bool MakeSmallScreenshot(void)
{
const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format;
return sf->proc(MakeScreenshotName(sf->extension), CurrentScreenCallback, NULL, _screen.width, _screen.height, 8, _cur_palette);
}
bool MakeWorldScreenshot(int left, int top, int width, int height, int zoom)
static bool MakeWorldScreenshot(void)
{
ViewPort vp;
const ScreenshotFormat *sf;
vp.zoom = zoom;
vp.zoom = 0;
vp.left = 0;
vp.top = 0;
vp.virtual_width = width;
vp.width = width >> zoom;
vp.virtual_height = height;
vp.height = height >> zoom;
vp.virtual_left = left;
vp.virtual_top = top;
vp.virtual_left = -(int)MapMaxX() * TILE_PIXELS;
vp.virtual_top = 0;
vp.virtual_width = (MapMaxX() + MapMaxY()) * TILE_PIXELS;
vp.width = vp.virtual_width;
vp.virtual_height = (MapMaxX() + MapMaxY()) * TILE_PIXELS >> 1;
vp.height = vp.virtual_height;
sf = _screenshot_formats + _cur_screenshot_format;
return sf->proc(MakeScreenshotName(sf->extension), LargeWorldCallback, &vp, vp.width, vp.height, 8, _cur_palette);
}
bool MakeScreenshot(void)
{
switch (current_screenshot_type) {
case SC_VIEWPORT:
UndrawMouseCursor();
current_screenshot_type = SC_NONE;
return MakeSmallScreenshot();
case SC_WORLD:
current_screenshot_type = SC_NONE;
return MakeWorldScreenshot();
default: return false;
}
}

@ -8,8 +8,15 @@ void InitializeScreenshotFormats(void);
const char *GetScreenshotFormatDesc(int i);
void SetScreenshotFormat(int i);
typedef enum ScreenshotType {
SC_NONE,
SC_VIEWPORT,
SC_WORLD
} ScreenshotType;
bool MakeScreenshot(void);
bool MakeWorldScreenshot(int left, int top, int width, int height, int zoom);
void SetScreenshotType(ScreenshotType t);
bool IsScreenshotRequested(void);
extern char _screenshot_format_name[8];
extern uint _num_screenshot_formats;

@ -307,7 +307,6 @@ VARDEF byte _switch_mode;
VARDEF StringID _switch_mode_errorstr;
VARDEF bool _exit_game;
VARDEF SmallFiosItem _file_to_saveload;
VARDEF byte _make_screenshot;
VARDEF byte _get_z_hint; // used as a hint to getslopez to return the right height at a bridge.

Loading…
Cancel
Save