Implement taking smallmap screenshots.
This is largely based on this patch: http://www.tt-forums.net/viewtopic.php?p=849533#p849533 with the following changes: * this uses a button in the smallmap window instead of a console command * screenshot now uses zoom level and mode of smallmap window
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#include "sound_func.h"
|
||||
#include "window_func.h"
|
||||
#include "company_base.h"
|
||||
#include "screenshot.h"
|
||||
|
||||
#include "smallmap_gui.h"
|
||||
|
||||
@@ -936,7 +937,7 @@ void SmallMapWindow::DrawMapIndicators() const
|
||||
*
|
||||
* @param dpi pointer to pixel to write onto
|
||||
*/
|
||||
void SmallMapWindow::DrawSmallMap(DrawPixelInfo *dpi) const
|
||||
void SmallMapWindow::DrawSmallMap(DrawPixelInfo *dpi, bool draw_indicators) const
|
||||
{
|
||||
Blitter *blitter = BlitterFactory::GetCurrentBlitter();
|
||||
DrawPixelInfo *old_dpi;
|
||||
@@ -992,7 +993,7 @@ void SmallMapWindow::DrawSmallMap(DrawPixelInfo *dpi) const
|
||||
if (this->show_towns) this->DrawTowns(dpi);
|
||||
|
||||
/* Draw map indicators */
|
||||
this->DrawMapIndicators();
|
||||
if (draw_indicators) this->DrawMapIndicators();
|
||||
|
||||
_cur_dpi = old_dpi;
|
||||
}
|
||||
@@ -1487,6 +1488,10 @@ int SmallMapWindow::GetPositionOnLegend(Point pt)
|
||||
this->SetWidgetLoweredState(WID_SM_SHOW_HEIGHT, _smallmap_show_heightmap);
|
||||
this->SetDirty();
|
||||
break;
|
||||
|
||||
case WID_SM_SCREENSHOT:
|
||||
TakeScreenshot();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1650,6 +1655,71 @@ Point SmallMapWindow::GetStationMiddle(const Station *st) const
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a screenshot of the contents of the smallmap window, at the current zoom level and mode
|
||||
* This calls MakeSmallMapScreenshot which uses ScreenshotCallbackHandler as the screenshot callback
|
||||
*/
|
||||
void SmallMapWindow::TakeScreenshot()
|
||||
{
|
||||
int32 width = ((MapMaxX() + MapMaxY()) * 2) / this->zoom;
|
||||
int32 height = (MapMaxX() + MapMaxY() + 1) / this->zoom;
|
||||
|
||||
int32 saved_scroll_x = this->scroll_x;
|
||||
int32 saved_scroll_y = this->scroll_y;
|
||||
int32 saved_subscroll = this->subscroll;
|
||||
this->subscroll = 0;
|
||||
MakeSmallMapScreenshot(width, height, this);
|
||||
this->scroll_x = saved_scroll_x;
|
||||
this->scroll_y = saved_scroll_y;
|
||||
this->subscroll = saved_subscroll;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback called by the screenshot code to draw a section of the smallmap to the output buffer
|
||||
* @param buf Videobuffer with same bitdepth as current blitter
|
||||
* @param y First line to render
|
||||
* @param pitch Pitch of the videobuffer
|
||||
* @param n Number of lines to render
|
||||
*/
|
||||
void SmallMapWindow::ScreenshotCallbackHandler(void *buf, uint y, uint pitch, uint n)
|
||||
{
|
||||
DrawPixelInfo dpi, *old_dpi;
|
||||
|
||||
/* We are no longer rendering to the screen */
|
||||
DrawPixelInfo old_screen = _screen;
|
||||
bool old_disable_anim = _screen_disable_anim;
|
||||
|
||||
_screen.dst_ptr = buf;
|
||||
_screen.width = pitch;
|
||||
_screen.height = n;
|
||||
_screen.pitch = pitch;
|
||||
_screen_disable_anim = true;
|
||||
|
||||
old_dpi = _cur_dpi;
|
||||
_cur_dpi = &dpi;
|
||||
|
||||
dpi.dst_ptr = buf;
|
||||
dpi.height = n;
|
||||
dpi.width = ((MapMaxX() + MapMaxY()) * 2) / this->zoom;
|
||||
dpi.pitch = pitch;
|
||||
dpi.zoom = ZOOM_LVL_NORMAL;
|
||||
dpi.left = 0;
|
||||
dpi.top = y;
|
||||
|
||||
int32 pos = (((int32)MapMaxX() + 1) * TILE_PIXELS) / 4;
|
||||
this->scroll_x = pos;
|
||||
this->scroll_y = -pos;
|
||||
|
||||
/* make the screenshot */
|
||||
this->DrawSmallMap(&dpi, false);
|
||||
|
||||
_cur_dpi = old_dpi;
|
||||
|
||||
/* Switch back to rendering to the screen */
|
||||
_screen = old_screen;
|
||||
_screen_disable_anim = old_disable_anim;
|
||||
}
|
||||
|
||||
SmallMapWindow::SmallMapType SmallMapWindow::map_type = SMT_CONTOUR;
|
||||
bool SmallMapWindow::show_towns = true;
|
||||
int SmallMapWindow::max_heightlevel = -1;
|
||||
@@ -1798,6 +1868,7 @@ static const NWidgetPart _nested_smallmap_widgets[] = {
|
||||
NWidgetFunction(SmallMapDisplay), // Smallmap display and legend bar + image buttons.
|
||||
/* Bottom button row and resize box. */
|
||||
NWidget(NWID_HORIZONTAL),
|
||||
NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_SM_SCREENSHOT), SetDataTip(STR_SMALLMAP_SCREENSHOT, STR_NULL),
|
||||
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_SM_SELECT_BUTTONS),
|
||||
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
|
||||
NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_SM_ENABLE_ALL), SetDataTip(STR_SMALLMAP_ENABLE_ALL, STR_NULL),
|
||||
|
Reference in New Issue
Block a user