Mercurial > hg > openttd
changeset 4184:0a14166e8dd5 draft
(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
author | belugas <belugas@openttd.org> |
---|---|
date | Fri, 28 Jul 2006 21:51:00 +0000 |
parents | cd2e1b12f33c |
children | 391db8b4c3b9 |
files | console_cmds.c main_gui.c openttd.c screenshot.c screenshot.h variables.h |
diffstat | 6 files changed, 68 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/console_cmds.c +++ b/console_cmds.c @@ -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 @@ 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();
--- a/main_gui.c +++ b/main_gui.c @@ -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 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 @@ 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 @@ 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;
--- a/openttd.c +++ b/openttd.c @@ -936,19 +936,7 @@ 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) {
--- a/screenshot.c +++ b/screenshot.c @@ -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 @@ } _cur_screenshot_format = j; _num_screenshot_formats = lengthof(_screenshot_formats); + make_screenshot = SC_NONE; } const char *GetScreenshotFormatDesc(int i) @@ -518,27 +520,52 @@ 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; + } +} +
--- a/screenshot.h +++ b/screenshot.h @@ -8,8 +8,15 @@ 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;