Merge branch 'master' into jgrpp-beta
# Conflicts: # src/command.cpp # src/console_cmds.cpp # src/group_gui.cpp # src/lang/catalan.txt # src/lang/czech.txt # src/lang/danish.txt # src/lang/greek.txt # src/lang/hungarian.txt # src/lang/irish.txt # src/lang/japanese.txt # src/lang/luxembourgish.txt # src/lang/norwegian_bokmal.txt # src/lang/romanian.txt # src/lang/russian.txt # src/lang/serbian.txt # src/lang/simplified_chinese.txt # src/lang/slovak.txt # src/lang/spanish_MX.txt # src/lang/swedish.txt # src/lang/tamil.txt # src/lang/traditional_chinese.txt # src/lang/turkish.txt # src/lang/ukrainian.txt # src/lang/vietnamese.txt # src/network/network.cpp # src/network/network_client.cpp # src/network/network_func.h # src/network/network_internal.h # src/network/network_server.cpp # src/network/network_server.h # src/saveload/afterload.cpp # src/saveload/newgrf_sl.cpp # src/saveload/saveload.h # src/script/script_instance.cpp # src/toolbar_gui.cpp # src/toolbar_gui.h # src/vehicle_gui.cpp # src/widgets/rail_widget.h # src/widgets/vehicle_widget.h # src/window.cpp
This commit is contained in:
56
src/gfx.cpp
56
src/gfx.cpp
@@ -1085,18 +1085,19 @@ void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub,
|
||||
/**
|
||||
* The code for setting up the blitter mode and sprite information before finally drawing the sprite.
|
||||
* @param sprite The sprite to draw.
|
||||
* @param x The X location to draw.
|
||||
* @param y The Y location to draw.
|
||||
* @param mode The settings for the blitter to pass.
|
||||
* @param sub Whether to only draw a sub set of the sprite.
|
||||
* @param zoom The zoom level at which to draw the sprites.
|
||||
* @param x The X location to draw.
|
||||
* @param y The Y location to draw.
|
||||
* @param mode The settings for the blitter to pass.
|
||||
* @param sub Whether to only draw a sub set of the sprite.
|
||||
* @param zoom The zoom level at which to draw the sprites.
|
||||
* @param dst Optional parameter for a different blitting destination.
|
||||
* @tparam ZOOM_BASE The factor required to get the sub sprite information into the right size.
|
||||
* @tparam SCALED_XY Whether the X and Y are scaled or unscaled.
|
||||
*/
|
||||
template <int ZOOM_BASE, bool SCALED_XY>
|
||||
static void GfxBlitter(const Sprite * const sprite, int x, int y, BlitterMode mode, const SubSprite * const sub, SpriteID sprite_id, ZoomLevel zoom)
|
||||
static void GfxBlitter(const Sprite * const sprite, int x, int y, BlitterMode mode, const SubSprite * const sub, SpriteID sprite_id, ZoomLevel zoom, const DrawPixelInfo *dst = nullptr)
|
||||
{
|
||||
const DrawPixelInfo *dpi = _cur_dpi;
|
||||
const DrawPixelInfo *dpi = (dst != nullptr) ? dst : _cur_dpi;
|
||||
Blitter::BlitterParams bp;
|
||||
|
||||
if (SCALED_XY) {
|
||||
@@ -1210,6 +1211,47 @@ static void GfxBlitter(const Sprite * const sprite, int x, int y, BlitterMode mo
|
||||
BlitterFactory::GetCurrentBlitter()->Draw(&bp, mode, zoom);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a sprite to a new RGBA buffer (see Colour union) instead of drawing to the screen.
|
||||
*
|
||||
* @param spriteId The sprite to draw.
|
||||
* @return Pixel buffer, or nullptr if an 8bpp blitter is being used.
|
||||
*/
|
||||
std::unique_ptr<uint32[]> DrawSpriteToRgbaBuffer(SpriteID spriteId)
|
||||
{
|
||||
Blitter *blitter = BlitterFactory::GetCurrentBlitter();
|
||||
if (!blitter->Is32BppSupported()) return nullptr;
|
||||
|
||||
/* Gather information about the sprite to write, reserve memory */
|
||||
const SpriteID real_sprite = GB(spriteId, 0, SPRITE_WIDTH);
|
||||
const Sprite *sprite = GetSprite(real_sprite, ST_NORMAL);
|
||||
std::unique_ptr<uint32[]> result(new uint32[sprite->width * sprite->height]);
|
||||
|
||||
/* Prepare new DrawPixelInfo - Normally this would be the screen but we want to draw to another buffer here.
|
||||
* Normally, pitch would be scaled screen width, but in our case our "screen" is only the sprite width wide. */
|
||||
DrawPixelInfo dpi;
|
||||
dpi.dst_ptr = result.get();
|
||||
dpi.pitch = sprite->width;
|
||||
dpi.left = 0;
|
||||
dpi.top = 0;
|
||||
dpi.width = sprite->width;
|
||||
dpi.height = sprite->height;
|
||||
dpi.zoom = ZOOM_LVL_NORMAL;
|
||||
|
||||
/* Zero out the allocated memory, there may be garbage present. */
|
||||
uint32 *writeHead = (uint32*)result.get();
|
||||
for (int i = 0; i < sprite->width * sprite->height; i++) {
|
||||
writeHead[i] = 0;
|
||||
}
|
||||
|
||||
/* Temporarily disable screen animations while blitting - This prevents 40bpp_anim from writing to the animation buffer. */
|
||||
_screen_disable_anim = true;
|
||||
GfxBlitter<1, false>(sprite, 0, 0, BM_NORMAL, nullptr, real_sprite, ZOOM_LVL_NORMAL, &dpi);
|
||||
_screen_disable_anim = false;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void GfxMainBlitterViewport(const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub, SpriteID sprite_id)
|
||||
{
|
||||
GfxBlitter<ZOOM_LVL_BASE, false>(sprite, x, y, mode, sub, sprite_id, _cur_dpi->zoom);
|
||||
|
Reference in New Issue
Block a user