1
0
Fork 0

(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
release/0.5
belugas 2006-07-28 21:51:00 +00:00
parent e1654fa017
commit ecc89d5965
6 changed files with 68 additions and 35 deletions

View File

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

View File

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

View File

@ -936,19 +936,7 @@ void GameLoop(void)
if (_dirkeys) HandleKeyScrolling(); if (_dirkeys) HandleKeyScrolling();
// make a screenshot? // make a screenshot?
if (_make_screenshot != 0) { if (IsScreenshotRequested()) ShowScreenshotResult(MakeScreenshot());
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;
}
// switch game mode? // switch game mode?
if (_switch_mode != SM_NONE) { if (_switch_mode != SM_NONE) {

View File

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

View File

@ -8,8 +8,15 @@ void InitializeScreenshotFormats(void);
const char *GetScreenshotFormatDesc(int i); const char *GetScreenshotFormatDesc(int i);
void SetScreenshotFormat(int i); void SetScreenshotFormat(int i);
typedef enum ScreenshotType {
SC_NONE,
SC_VIEWPORT,
SC_WORLD
} ScreenshotType;
bool MakeScreenshot(void); 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 char _screenshot_format_name[8];
extern uint _num_screenshot_formats; extern uint _num_screenshot_formats;

View File

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