File diff r27105:4235592d0ef1 → r27106:2d95beb51290
src/gfx.cpp
Show inline comments
 
@@ -71,13 +71,13 @@ int _gui_scale_cfg;                     
 
 * This rectangle defines the area which should be repaint by the video driver.
 
 *
 
 * @ingroup dirty
 
 */
 
static Rect _invalid_rect;
 
static const byte *_colour_remap_ptr;
 
static byte _string_colourremap[3]; ///< Recoloursprite for stringdrawing. The grf loader ensures that #ST_FONT sprites only use colours 0 to 2.
 
static byte _string_colourremap[3]; ///< Recoloursprite for stringdrawing. The grf loader ensures that #SpriteType::Font sprites only use colours 0 to 2.
 

	
 
static const uint DIRTY_BLOCK_HEIGHT   = 8;
 
static const uint DIRTY_BLOCK_WIDTH    = 64;
 

	
 
static uint _dirty_bytes_per_line = 0;
 
static byte *_dirty_blocks = nullptr;
 
@@ -989,13 +989,13 @@ void DrawCharCentered(WChar c, const Rec
 
 * @param zoom The zoom level applicable to the sprite.
 
 * @return Sprite size in pixels.
 
 * @note The size assumes (0, 0) as top-left coordinate and ignores any part of the sprite drawn at the left or above that position.
 
 */
 
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
 
{
 
	const Sprite *sprite = GetSprite(sprid, ST_NORMAL);
 
	const Sprite *sprite = GetSprite(sprid, SpriteType::Normal);
 

	
 
	if (offset != nullptr) {
 
		offset->x = UnScaleByZoom(sprite->x_offs, zoom);
 
		offset->y = UnScaleByZoom(sprite->y_offs, zoom);
 
	}
 

	
 
@@ -1029,23 +1029,23 @@ static BlitterMode GetBlitterMode(Palett
 
 * @param sub  If available, draw only specified part of the sprite
 
 */
 
void DrawSpriteViewport(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub)
 
{
 
	SpriteID real_sprite = GB(img, 0, SPRITE_WIDTH);
 
	if (HasBit(img, PALETTE_MODIFIER_TRANSPARENT)) {
 
		_colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1;
 
		GfxMainBlitterViewport(GetSprite(real_sprite, ST_NORMAL), x, y, BM_TRANSPARENT, sub, real_sprite);
 
		_colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), SpriteType::Recolour) + 1;
 
		GfxMainBlitterViewport(GetSprite(real_sprite, SpriteType::Normal), x, y, BM_TRANSPARENT, sub, real_sprite);
 
	} else if (pal != PAL_NONE) {
 
		if (HasBit(pal, PALETTE_TEXT_RECOLOUR)) {
 
			SetColourRemap((TextColour)GB(pal, 0, PALETTE_WIDTH));
 
		} else {
 
			_colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1;
 
			_colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), SpriteType::Recolour) + 1;
 
		}
 
		GfxMainBlitterViewport(GetSprite(real_sprite, ST_NORMAL), x, y, GetBlitterMode(pal), sub, real_sprite);
 
		GfxMainBlitterViewport(GetSprite(real_sprite, SpriteType::Normal), x, y, GetBlitterMode(pal), sub, real_sprite);
 
	} else {
 
		GfxMainBlitterViewport(GetSprite(real_sprite, ST_NORMAL), x, y, BM_NORMAL, sub, real_sprite);
 
		GfxMainBlitterViewport(GetSprite(real_sprite, SpriteType::Normal), x, y, BM_NORMAL, sub, real_sprite);
 
	}
 
}
 

	
 
/**
 
 * Draw a sprite, not in a viewport
 
 * @param img  Image number to draw
 
@@ -1056,23 +1056,23 @@ void DrawSpriteViewport(SpriteID img, Pa
 
 * @param zoom Zoom level of sprite
 
 */
 
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
 
{
 
	SpriteID real_sprite = GB(img, 0, SPRITE_WIDTH);
 
	if (HasBit(img, PALETTE_MODIFIER_TRANSPARENT)) {
 
		_colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1;
 
		GfxMainBlitter(GetSprite(real_sprite, ST_NORMAL), x, y, BM_TRANSPARENT, sub, real_sprite, zoom);
 
		_colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), SpriteType::Recolour) + 1;
 
		GfxMainBlitter(GetSprite(real_sprite, SpriteType::Normal), x, y, BM_TRANSPARENT, sub, real_sprite, zoom);
 
	} else if (pal != PAL_NONE) {
 
		if (HasBit(pal, PALETTE_TEXT_RECOLOUR)) {
 
			SetColourRemap((TextColour)GB(pal, 0, PALETTE_WIDTH));
 
		} else {
 
			_colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1;
 
			_colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), SpriteType::Recolour) + 1;
 
		}
 
		GfxMainBlitter(GetSprite(real_sprite, ST_NORMAL), x, y, GetBlitterMode(pal), sub, real_sprite, zoom);
 
		GfxMainBlitter(GetSprite(real_sprite, SpriteType::Normal), x, y, GetBlitterMode(pal), sub, real_sprite, zoom);
 
	} else {
 
		GfxMainBlitter(GetSprite(real_sprite, ST_NORMAL), x, y, BM_NORMAL, sub, real_sprite, zoom);
 
		GfxMainBlitter(GetSprite(real_sprite, SpriteType::Normal), x, y, BM_NORMAL, sub, real_sprite, zoom);
 
	}
 
}
 

	
 
/**
 
 * The code for setting up the blitter mode and sprite information before finally drawing the sprite.
 
 * @param sprite The sprite to draw.
 
@@ -1217,13 +1217,13 @@ std::unique_ptr<uint32[]> DrawSpriteToRg
 

	
 
	Blitter *blitter = BlitterFactory::GetCurrentBlitter();
 
	if (blitter->GetScreenDepth() != 8 && blitter->GetScreenDepth() != 32) 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);
 
	const Sprite *sprite = GetSprite(real_sprite, SpriteType::Normal);
 
	Dimension dim = GetSpriteSize(real_sprite, nullptr, zoom);
 
	size_t dim_size = static_cast<size_t>(dim.width) * dim.height;
 
	std::unique_ptr<uint32[]> result(new uint32[dim_size]);
 
	/* Set buffer to fully transparent. */
 
	MemSetT(result.get(), 0, dim_size);
 

	
 
@@ -1840,13 +1840,13 @@ void UpdateCursorSize()
 
	/* Ignore setting any cursor before the sprites are loaded. */
 
	if (GetMaxSpriteID() == 0) return;
 

	
 
	static_assert(lengthof(_cursor.sprite_seq) == lengthof(_cursor.sprite_pos));
 
	assert(_cursor.sprite_count <= lengthof(_cursor.sprite_seq));
 
	for (uint i = 0; i < _cursor.sprite_count; ++i) {
 
		const Sprite *p = GetSprite(GB(_cursor.sprite_seq[i].sprite, 0, SPRITE_WIDTH), ST_NORMAL);
 
		const Sprite *p = GetSprite(GB(_cursor.sprite_seq[i].sprite, 0, SPRITE_WIDTH), SpriteType::Normal);
 
		Point offs, size;
 
		offs.x = UnScaleGUI(p->x_offs) + _cursor.sprite_pos[i].x;
 
		offs.y = UnScaleGUI(p->y_offs) + _cursor.sprite_pos[i].y;
 
		size.x = UnScaleGUI(p->width);
 
		size.y = UnScaleGUI(p->height);