From 137c8c190dff17b230677a0d4dc0949a3e488737 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Tue, 2 Jun 2015 14:12:36 +0100 Subject: [PATCH] add giant screenshot to file menu --- data/language/english_uk.txt | 1 + src/interface/screenshot.c | 99 +++++++++++++++++++++++++++++++++-- src/interface/screenshot.h | 1 + src/localisation/string_ids.h | 2 + src/windows/top_toolbar.c | 46 +++++++++------- 5 files changed, 127 insertions(+), 22 deletions(-) diff --git a/data/language/english_uk.txt b/data/language/english_uk.txt index e7ddefb659..ce815fca10 100644 --- a/data/language/english_uk.txt +++ b/data/language/english_uk.txt @@ -3593,3 +3593,4 @@ STR_5256 :Create a new theme to make changes to STR_5257 :{SMALLFONT}{BLACK}Create a new theme based on the current one STR_5258 :{SMALLFONT}{BLACK}Delete the current theme STR_5259 :{SMALLFONT}{BLACK}Rename the current theme +STR_5260 :Giant Screenshot \ No newline at end of file diff --git a/src/interface/screenshot.c b/src/interface/screenshot.c index 632c6eaba9..5afda79320 100644 --- a/src/interface/screenshot.c +++ b/src/interface/screenshot.c @@ -27,6 +27,7 @@ #include "../localisation/localisation.h" #include "../openrct2.h" #include "../platform/platform.h" +#include "../util/util.h" #include "../windows/error.h" #include "screenshot.h" #include "viewport.h" @@ -51,10 +52,10 @@ void screenshot_check() screenshotIndex = screenshot_dump(); if (screenshotIndex != -1) { - char *lang_3165 = (char*)0x009BC677; - sprintf(lang_3165, "SCR%d%s", screenshotIndex, _screenshot_format_extension[gConfigGeneral.screenshot_format]); + rct_string_id stringId = 3165; + sprintf((char*)language_get_string(stringId), "SCR%d%s", screenshotIndex, _screenshot_format_extension[gConfigGeneral.screenshot_format]); - RCT2_GLOBAL(0x013CE952, uint16) = 3165; + RCT2_GLOBAL(0x013CE952, uint16) = stringId; // RCT2_GLOBAL(0x013CE952, uint16) = STR_SCR_BMP; // RCT2_GLOBAL(0x013CE952 + 2, uint16) = screenshotIndex; RCT2_GLOBAL(0x009A8C29, uint8) |= 1; @@ -316,6 +317,98 @@ bool screenshot_write_png(rct_drawpixelinfo *dpi, const char *path) return true; } +void screenshot_giant() +{ + int originalRotation = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, uint8); + int originalZoom = 0; + + rct_window *mainWindow = window_get_main(); + if (mainWindow != NULL && mainWindow->viewport != NULL) + originalZoom = mainWindow->viewport->zoom; + + int rotation = originalRotation; + int zoom = originalZoom; + int mapSize = RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE, uint16); + int resolutionWidth = (mapSize * 32 * 2) >> zoom; + int resolutionHeight = (mapSize * 32 * 1) >> zoom; + + resolutionWidth += 8; + resolutionHeight += 128; + + rct_viewport viewport; + viewport.x = 0; + viewport.y = 0; + viewport.width = resolutionWidth; + viewport.height = resolutionHeight; + viewport.view_width = viewport.width; + viewport.view_height = viewport.height; + viewport.var_11 = 0; + viewport.flags = 0; + + int centreX = (mapSize / 2) * 32 + 16; + int centreY = (mapSize / 2) * 32 + 16; + + int x, y; + int z = map_element_height(centreX, centreY) & 0xFFFF; + switch (rotation) { + case 0: + x = centreY - centreX; + y = ((centreX + centreY) / 2) - z; + break; + case 1: + x = -centreY - centreX; + y = ((-centreX + centreY) / 2) - z; + break; + case 2: + x = -centreY + centreX; + y = ((-centreX - centreY) / 2) - z; + break; + case 3: + x = centreY + centreX; + y = ((centreX - centreY) / 2) - z; + break; + } + + viewport.view_x = x - ((viewport.view_width << zoom) / 2); + viewport.view_y = y - ((viewport.view_height << zoom) / 2); + viewport.zoom = zoom; + + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, uint8) = rotation; + + // Ensure sprites appear regardless of rotation + reset_all_sprite_quadrant_placements(); + + rct_drawpixelinfo dpi; + dpi.x = 0; + dpi.y = 0; + dpi.width = resolutionWidth; + dpi.height = resolutionHeight; + dpi.pitch = 0; + dpi.zoom_level = 0; + dpi.bits = malloc(dpi.width * dpi.height); + + viewport_render(&dpi, &viewport, 0, 0, viewport.width, viewport.height); + + // Get a free screenshot path + char path[MAX_PATH]; + int index; + if ((index = screenshot_get_next_path(path, SCREENSHOT_FORMAT_PNG)) == -1) { + log_error("Giant screenshot failed, unable to find a suitable destination path."); + window_error_open(STR_SCREENSHOT_FAILED, -1); + return; + } + + screenshot_write_png(&dpi, path); + + free(dpi.bits); + + // Show user that screenshot saved successfully + rct_string_id stringId = 3165; + strcpy((char*)language_get_string(stringId), path_get_filename(path)); + RCT2_GLOBAL(RCT2_ADDRESS_COMMON_FORMAT_ARGS, uint16) = stringId; + window_error_open(STR_SCREENSHOT_SAVED_AS, -1); +} + int cmdline_for_screenshot(const char **argv, int argc) { bool giantScreenshot = argc == 5 && _stricmp(argv[2], "giant") == 0; diff --git a/src/interface/screenshot.h b/src/interface/screenshot.h index 3b2c8ae6fa..0672a135bb 100644 --- a/src/interface/screenshot.h +++ b/src/interface/screenshot.h @@ -24,6 +24,7 @@ void screenshot_check(); int screenshot_dump(); +void screenshot_giant(); int cmdline_for_screenshot(const char **argv, int argc); #endif \ No newline at end of file diff --git a/src/localisation/string_ids.h b/src/localisation/string_ids.h index 9786f32fc4..07a7470199 100644 --- a/src/localisation/string_ids.h +++ b/src/localisation/string_ids.h @@ -1424,6 +1424,8 @@ enum { STR_FULLSCREEN_MODE = 5177, + STR_GIANT_SCREENSHOT = 5260, + // Have to include resource strings (from scenarios and objects) for the time being now that language is partially working STR_COUNT = 32768 }; diff --git a/src/windows/top_toolbar.c b/src/windows/top_toolbar.c index b80641d51e..87a3259214 100644 --- a/src/windows/top_toolbar.c +++ b/src/windows/top_toolbar.c @@ -25,6 +25,7 @@ #include "../input.h" #include "../sprites.h" #include "../audio/audio.h" +#include "../interface/screenshot.h" #include "../interface/widget.h" #include "../interface/window.h" #include "../interface/viewport.h" @@ -71,11 +72,12 @@ typedef enum { DDIDX_ABOUT = 3, DDIDX_OPTIONS = 4, DDIDX_SCREENSHOT = 5, + DDIDX_GIANT_SCREENSHOT = 6, // seperator - DDIDX_QUIT_TO_MENU = 7, - DDIDX_EXIT_OPENRCT2 = 8, + DDIDX_QUIT_TO_MENU = 8, + DDIDX_EXIT_OPENRCT2 = 9, // seperator - DDIDX_ENABLE_TWITCH = 10 + DDIDX_ENABLE_TWITCH = 11 } FILE_MENU_DDIDX; typedef enum { @@ -322,9 +324,10 @@ static void window_top_toolbar_mousedown(int widgetIndex, rct_window*w, rct_widg gDropdownItemsFormat[0] = STR_ABOUT; gDropdownItemsFormat[1] = STR_OPTIONS; gDropdownItemsFormat[2] = STR_SCREENSHOT; - gDropdownItemsFormat[3] = 0; - gDropdownItemsFormat[4] = STR_QUIT_TRACK_DESIGNS_MANAGER; - gDropdownItemsFormat[5] = STR_EXIT_OPENRCT2; + gDropdownItemsFormat[3] = STR_GIANT_SCREENSHOT; + gDropdownItemsFormat[4] = 0; + gDropdownItemsFormat[5] = STR_QUIT_TRACK_DESIGNS_MANAGER; + gDropdownItemsFormat[6] = STR_EXIT_OPENRCT2; if (RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & SCREEN_FLAGS_TRACK_DESIGNER) gDropdownItemsFormat[4] = STR_QUIT_ROLLERCOASTER_DESIGNER; @@ -337,10 +340,11 @@ static void window_top_toolbar_mousedown(int widgetIndex, rct_window*w, rct_widg gDropdownItemsFormat[3] = STR_ABOUT; gDropdownItemsFormat[4] = STR_OPTIONS; gDropdownItemsFormat[5] = STR_SCREENSHOT; - gDropdownItemsFormat[6] = 0; - gDropdownItemsFormat[7] = STR_QUIT_SCENARIO_EDITOR; - gDropdownItemsFormat[8] = STR_EXIT_OPENRCT2; - numItems = 9; + gDropdownItemsFormat[6] = STR_GIANT_SCREENSHOT; + gDropdownItemsFormat[7] = 0; + gDropdownItemsFormat[8] = STR_QUIT_SCENARIO_EDITOR; + gDropdownItemsFormat[9] = STR_EXIT_OPENRCT2; + numItems = 10; } else { gDropdownItemsFormat[0] = STR_LOAD_GAME; gDropdownItemsFormat[1] = STR_SAVE_GAME; @@ -348,18 +352,19 @@ static void window_top_toolbar_mousedown(int widgetIndex, rct_window*w, rct_widg gDropdownItemsFormat[3] = STR_ABOUT; gDropdownItemsFormat[4] = STR_OPTIONS; gDropdownItemsFormat[5] = STR_SCREENSHOT; - gDropdownItemsFormat[6] = 0; - gDropdownItemsFormat[7] = STR_QUIT_TO_MENU; - gDropdownItemsFormat[8] = STR_EXIT_OPENRCT2; - numItems = 9; + gDropdownItemsFormat[6] = STR_GIANT_SCREENSHOT; + gDropdownItemsFormat[7] = 0; + gDropdownItemsFormat[8] = STR_QUIT_TO_MENU; + gDropdownItemsFormat[9] = STR_EXIT_OPENRCT2; + numItems = 10; #ifndef DISABLE_TWITCH if (gConfigTwitch.channel != NULL && gConfigTwitch.channel[0] != 0) { _menuDropdownIncludesTwitch = true; - gDropdownItemsFormat[9] = 0; - gDropdownItemsFormat[10] = 1156; - gDropdownItemsArgs[10] = STR_TWITCH_ENABLE; - numItems = 11; + gDropdownItemsFormat[10] = 0; + gDropdownItemsFormat[11] = 1156; + gDropdownItemsArgs[11] = STR_TWITCH_ENABLE; + numItems = 12; } #endif } @@ -374,7 +379,7 @@ static void window_top_toolbar_mousedown(int widgetIndex, rct_window*w, rct_widg #ifndef DISABLE_TWITCH if (_menuDropdownIncludesTwitch && gTwitchEnable) - gDropdownItemsChecked |= (1 << 10); + gDropdownItemsChecked |= (1 << 11); #endif break; case WIDX_VIEW_MENU: @@ -444,6 +449,9 @@ static void window_top_toolbar_dropdown() case DDIDX_SCREENSHOT: RCT2_GLOBAL(RCT2_ADDRESS_SCREENSHOT_COUNTDOWN, sint8) = 10; break; + case DDIDX_GIANT_SCREENSHOT: + screenshot_giant(); + break; case DDIDX_QUIT_TO_MENU: window_close_by_class(WC_MANAGE_TRACK_DESIGN); window_close_by_class(WC_TRACK_DELETE_PROMPT);