diff options
author | Patric Stout <truebrain@openttd.org> | 2021-01-22 16:16:33 +0100 |
---|---|---|
committer | Patric Stout <github@truebrain.nl> | 2021-03-04 22:23:05 +0100 |
commit | ac5e77ea3b3e8e769d2198b0e8f4b6e56bb8fc91 (patch) | |
tree | e4fa407b4acdb700ddb380fd19ca9d6fd0d1e0f6 /src/console_cmds.cpp | |
parent | 879eb9c34803ac468afb582ffb348493f0a32e39 (diff) | |
download | openttd-ac5e77ea3b3e8e769d2198b0e8f4b6e56bb8fc91.tar.xz |
Feature: allow custom width/height of screenshot via console
Reworked how the screenshot command works while keeping it backwards
compatible. It can now more freely understand arguments, and has
the ability to make SC_DEFAULTZOOM screenshots.
Diffstat (limited to 'src/console_cmds.cpp')
-rw-r--r-- | src/console_cmds.cpp | 86 |
1 files changed, 58 insertions, 28 deletions
diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index 905a41c3e..3f454b1aa 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -1409,46 +1409,76 @@ DEF_CONSOLE_CMD(ConAlias) DEF_CONSOLE_CMD(ConScreenShot) { if (argc == 0) { - IConsoleHelp("Create a screenshot of the game. Usage: 'screenshot [big | giant | no_con | minimap] [file name]'"); - IConsoleHelp("'big' makes a zoomed-in screenshot of the visible area, 'giant' makes a screenshot of the " - "whole map, 'no_con' hides the console to create the screenshot. 'big' or 'giant' " - "screenshots are always drawn without console. " - "'minimap' makes a top-viewed minimap screenshot of whole world which represents one tile by one pixel."); + IConsoleHelp("Create a screenshot of the game. Usage: 'screenshot [viewport | normal | big | giant | minimap] [no_con] [size <width> <height>] [<filename>]'"); + IConsoleHelp("'viewport' (default) makes a screenshot of the current viewport (including menus, windows, ..), " + "'normal' makes a screenshot of the visible area, " + "'big' makes a zoomed-in screenshot of the visible area, " + "'giant' makes a screenshot of the whole map, " + "'minimap' makes a top-viewed minimap screenshot of the whole world which represents one tile by one pixel. " + "'no_con' hides the console to create the screenshot (only useful in combination with 'viewport'). " + "'size' sets the width and height of the viewport to make a screenshot of (only useful in combination with 'normal' or 'big')."); return true; } - if (argc > 3) return false; + if (argc > 7) return false; ScreenshotType type = SC_VIEWPORT; + uint32 width = 0; + uint32 height = 0; const char *name = nullptr; - - if (argc > 1) { - if (strcmp(argv[1], "big") == 0) { - /* screenshot big [filename] */ + uint32 arg_index = 1; + + if (argc > arg_index) { + if (strcmp(argv[arg_index], "viewport") == 0) { + type = SC_VIEWPORT; + arg_index += 1; + } else if (strcmp(argv[arg_index], "normal") == 0) { + type = SC_DEFAULTZOOM; + arg_index += 1; + } else if (strcmp(argv[arg_index], "big") == 0) { type = SC_ZOOMEDIN; - if (argc > 2) name = argv[2]; - } else if (strcmp(argv[1], "giant") == 0) { - /* screenshot giant [filename] */ + arg_index += 1; + } else if (strcmp(argv[arg_index], "giant") == 0) { type = SC_WORLD; - if (argc > 2) name = argv[2]; - } else if (strcmp(argv[1], "minimap") == 0) { - /* screenshot minimap [filename] */ + arg_index += 1; + } else if (strcmp(argv[arg_index], "minimap") == 0) { type = SC_MINIMAP; - if (argc > 2) name = argv[2]; - } else if (strcmp(argv[1], "no_con") == 0) { - /* screenshot no_con [filename] */ - IConsoleClose(); - if (argc > 2) name = argv[2]; - } else if (argc == 2) { - /* screenshot filename */ - name = argv[1]; - } else { - /* screenshot argv[1] argv[2] - invalid */ - return false; + arg_index += 1; + } + } + + if (argc > arg_index && strcmp(argv[arg_index], "no_con") == 0) { + if (type != SC_VIEWPORT) { + IConsoleError("'no_con' can only be used in combination with 'viewport'"); + return true; + } + IConsoleClose(); + arg_index += 1; + } + + if (argc > arg_index + 2 && strcmp(argv[arg_index], "size") == 0) { + /* size <width> <height> */ + if (type != SC_DEFAULTZOOM && type != SC_ZOOMEDIN) { + IConsoleError("'size' can only be used in combination with 'normal' or 'big'"); + return true; } + GetArgumentInteger(&width, argv[arg_index + 1]); + GetArgumentInteger(&height, argv[arg_index + 2]); + arg_index += 3; + } + + if (argc > arg_index) { + /* Last parameter that was not one of the keywords must be the filename. */ + name = argv[arg_index]; + arg_index += 1; + } + + if (argc > arg_index) { + /* We have parameters we did not process; means we misunderstood any of the above. */ + return false; } - MakeScreenshot(type, name); + MakeScreenshot(type, name, width, height); return true; } |