Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include "company_func.h"
|
||||
#include "strings_func.h"
|
||||
#include "error.h"
|
||||
#include "textbuf_gui.h"
|
||||
#include "window_gui.h"
|
||||
#include "window_func.h"
|
||||
#include "tile_map.h"
|
||||
@@ -81,7 +82,7 @@ PACK(struct BitmapFileHeader {
|
||||
uint32 reserved;
|
||||
uint32 off_bits;
|
||||
});
|
||||
assert_compile(sizeof(BitmapFileHeader) == 14);
|
||||
static_assert(sizeof(BitmapFileHeader) == 14);
|
||||
|
||||
/** BMP Info Header (stored in little endian) */
|
||||
struct BitmapInfoHeader {
|
||||
@@ -90,13 +91,13 @@ struct BitmapInfoHeader {
|
||||
uint16 planes, bitcount;
|
||||
uint32 compression, sizeimage, xpels, ypels, clrused, clrimp;
|
||||
};
|
||||
assert_compile(sizeof(BitmapInfoHeader) == 40);
|
||||
static_assert(sizeof(BitmapInfoHeader) == 40);
|
||||
|
||||
/** Format of palette data in BMP header */
|
||||
struct RgbQuad {
|
||||
byte blue, green, red, reserved;
|
||||
};
|
||||
assert_compile(sizeof(RgbQuad) == 4);
|
||||
static_assert(sizeof(RgbQuad) == 4);
|
||||
|
||||
/**
|
||||
* Generic .BMP writer
|
||||
@@ -182,7 +183,7 @@ static bool MakeBMPImage(const char *name, ScreenshotCallback *callb, void *user
|
||||
|
||||
/* Start at the bottom, since bitmaps are stored bottom up */
|
||||
do {
|
||||
uint n = min(h, maxlines);
|
||||
uint n = std::min(h, maxlines);
|
||||
h -= n;
|
||||
|
||||
/* Render the pixels */
|
||||
@@ -312,7 +313,7 @@ static bool MakePNGImage(const char *name, ScreenshotCallback *callb, void *user
|
||||
|
||||
char buf[8192];
|
||||
char *p = buf;
|
||||
p += seprintf(p, lastof(buf), "Graphics set: %s (%u)\n", BaseGraphics::GetUsedSet()->name, BaseGraphics::GetUsedSet()->version);
|
||||
p += seprintf(p, lastof(buf), "Graphics set: %s (%u)\n", BaseGraphics::GetUsedSet()->name.c_str(), BaseGraphics::GetUsedSet()->version);
|
||||
p = strecpy(p, "NewGRFs:\n", lastof(buf));
|
||||
for (const GRFConfig *c = _game_mode == GM_MENU ? nullptr : _grfconfig; c != nullptr; c = c->next) {
|
||||
p += seprintf(p, lastof(buf), "%08X ", BSWAP32(c->ident.grfid));
|
||||
@@ -376,7 +377,7 @@ static bool MakePNGImage(const char *name, ScreenshotCallback *callb, void *user
|
||||
y = 0;
|
||||
do {
|
||||
/* determine # lines to write */
|
||||
n = min(h - y, maxlines);
|
||||
n = std::min(h - y, maxlines);
|
||||
|
||||
/* render the pixels into the buffer */
|
||||
callb(userdata, buff, y, w, n);
|
||||
@@ -431,7 +432,7 @@ struct PcxHeader {
|
||||
uint16 height;
|
||||
byte filler[54];
|
||||
};
|
||||
assert_compile(sizeof(PcxHeader) == 128);
|
||||
static_assert(sizeof(PcxHeader) == 128);
|
||||
|
||||
/**
|
||||
* Generic .PCX file image writer.
|
||||
@@ -494,7 +495,7 @@ static bool MakePCXImage(const char *name, ScreenshotCallback *callb, void *user
|
||||
y = 0;
|
||||
do {
|
||||
/* determine # lines to write */
|
||||
uint n = min(h - y, maxlines);
|
||||
uint n = std::min(h - y, maxlines);
|
||||
uint i;
|
||||
|
||||
/* render the pixels into the buffer */
|
||||
@@ -624,7 +625,7 @@ static void CurrentScreenCallback(void *userdata, void *buf, uint y, uint pitch,
|
||||
*/
|
||||
static void LargeWorldCallback(void *userdata, void *buf, uint y, uint pitch, uint n)
|
||||
{
|
||||
ViewPort *vp = (ViewPort *)userdata;
|
||||
Viewport *vp = (Viewport *)userdata;
|
||||
DrawPixelInfo dpi, *old_dpi;
|
||||
int wx, left;
|
||||
|
||||
@@ -652,7 +653,7 @@ static void LargeWorldCallback(void *userdata, void *buf, uint y, uint pitch, ui
|
||||
/* Render viewport in blocks of 1600 pixels width */
|
||||
left = 0;
|
||||
while (vp->width - left != 0) {
|
||||
wx = min(vp->width - left, 1600);
|
||||
wx = std::min(vp->width - left, 1600);
|
||||
left += wx;
|
||||
|
||||
ViewportDoDraw(vp,
|
||||
@@ -693,7 +694,7 @@ static const char *MakeScreenshotName(const char *default_fn, const char *ext, b
|
||||
size_t len = strlen(_screenshot_name);
|
||||
seprintf(&_screenshot_name[len], lastof(_screenshot_name), ".%s", ext);
|
||||
|
||||
const char *screenshot_dir = crashlog ? _personal_dir : FiosGetScreenshotDir();
|
||||
const char *screenshot_dir = crashlog ? _personal_dir.c_str() : FiosGetScreenshotDir();
|
||||
|
||||
for (uint serial = 1;; serial++) {
|
||||
if (seprintf(_full_screenshot_name, lastof(_full_screenshot_name), "%s%s", screenshot_dir, _screenshot_name) >= (int)lengthof(_full_screenshot_name)) {
|
||||
@@ -719,11 +720,11 @@ static bool MakeSmallScreenshot(bool crashlog)
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure a ViewPort for rendering (a part of) the map into a screenshot.
|
||||
* Configure a Viewport for rendering (a part of) the map into a screenshot.
|
||||
* @param t Screenshot type
|
||||
* @param[out] vp Result viewport
|
||||
*/
|
||||
void SetupScreenshotViewport(ScreenshotType t, ViewPort *vp)
|
||||
void SetupScreenshotViewport(ScreenshotType t, Viewport *vp)
|
||||
{
|
||||
switch(t) {
|
||||
case SC_VIEWPORT:
|
||||
@@ -794,7 +795,7 @@ void SetupScreenshotViewport(ScreenshotType t, ViewPort *vp)
|
||||
*/
|
||||
static bool MakeLargeWorldScreenshot(ScreenshotType t)
|
||||
{
|
||||
ViewPort vp;
|
||||
Viewport vp;
|
||||
SetupScreenshotViewport(t, &vp);
|
||||
|
||||
const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format;
|
||||
@@ -844,11 +845,52 @@ bool MakeHeightmapScreenshot(const char *filename)
|
||||
return sf->proc(filename, HeightmapCallback, nullptr, MapSizeX(), MapSizeY(), 8, palette);
|
||||
}
|
||||
|
||||
static ScreenshotType _confirmed_screenshot_type; ///< Screenshot type the current query is about to confirm.
|
||||
|
||||
/**
|
||||
* Make an actual screenshot.
|
||||
* Callback on the confirmation window for huge screenshots.
|
||||
* @param w Window with viewport
|
||||
* @param confirmed true on confirmation
|
||||
*/
|
||||
static void ScreenshotConfirmationCallback(Window *w, bool confirmed)
|
||||
{
|
||||
if (confirmed) MakeScreenshot(_confirmed_screenshot_type, nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a screenshot.
|
||||
* Ask for confirmation first if the screenshot will be huge.
|
||||
* @param t Screenshot type: World, defaultzoom, heightmap or viewport screenshot
|
||||
* @see MakeScreenshot
|
||||
*/
|
||||
void MakeScreenshotWithConfirm(ScreenshotType t)
|
||||
{
|
||||
Viewport vp;
|
||||
SetupScreenshotViewport(t, &vp);
|
||||
|
||||
bool heightmap_or_minimap = t == SC_HEIGHTMAP || t == SC_MINIMAP;
|
||||
uint64_t width = (heightmap_or_minimap ? MapSizeX() : vp.width);
|
||||
uint64_t height = (heightmap_or_minimap ? MapSizeY() : vp.height);
|
||||
|
||||
if (width * height > 8192 * 8192) {
|
||||
/* Ask for confirmation */
|
||||
_confirmed_screenshot_type = t;
|
||||
SetDParam(0, width);
|
||||
SetDParam(1, height);
|
||||
ShowQuery(STR_WARNING_SCREENSHOT_SIZE_CAPTION, STR_WARNING_SCREENSHOT_SIZE_MESSAGE, nullptr, ScreenshotConfirmationCallback);
|
||||
} else {
|
||||
/* Less than 64M pixels, just do it */
|
||||
MakeScreenshot(t, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a screenshot.
|
||||
* Unconditionally take a screenshot of the requested type.
|
||||
* @param t the type of screenshot to make.
|
||||
* @param name the name to give to the screenshot.
|
||||
* @return true iff the screenshot was made successfully
|
||||
* @see MakeScreenshotWithConfirm
|
||||
*/
|
||||
bool MakeScreenshot(ScreenshotType t, const char *name)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user