Changeset - r26669:b1cb0e0a0887
[Not reviewed]
master
0 2 0
Peter Nelson - 18 months ago 2022-12-18 12:34:14
peter1138@openttd.org
Add: Optionally disable child sprites drawing relative to parent sprites offsets.
2 files changed with 11 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/viewport.cpp
Show inline comments
 
@@ -134,6 +134,7 @@ struct ChildScreenSpriteToDraw {
 
	const SubSprite *sub;           ///< only draw a rectangular part of the sprite
 
	int32 x;
 
	int32 y;
 
	bool relative;
 
	int next;                       ///< next child to draw (-1 at the end)
 
};
 

	
 
@@ -816,8 +817,10 @@ bool IsInsideRotatedRectangle(int x, int
 
 * @param y sprite y-offset (screen coordinates) relative to parent sprite.
 
 * @param transparent if true, switch the palette between the provided palette and the transparent palette,
 
 * @param sub Only draw a part of the sprite.
 
 * @param scale if true, scale offsets to base zoom level.
 
 * @param relative if true, draw sprite relative to parent sprite offsets.
 
 */
 
void AddChildSpriteScreen(SpriteID image, PaletteID pal, int x, int y, bool transparent, const SubSprite *sub, bool scale)
 
void AddChildSpriteScreen(SpriteID image, PaletteID pal, int x, int y, bool transparent, const SubSprite *sub, bool scale, bool relative)
 
{
 
	assert((image & SPRITE_MASK) < MAX_SPRITES);
 

	
 
@@ -838,6 +841,7 @@ void AddChildSpriteScreen(SpriteID image
 
	cs.sub = sub;
 
	cs.x = scale ? x * ZOOM_LVL_BASE : x;
 
	cs.y = scale ? y * ZOOM_LVL_BASE : y;
 
	cs.relative = relative;
 
	cs.next = -1;
 

	
 
	/* Append the sprite to the active ChildSprite list.
 
@@ -1634,7 +1638,11 @@ static void ViewportDrawParentSprites(co
 
		while (child_idx >= 0) {
 
			const ChildScreenSpriteToDraw *cs = csstdv->data() + child_idx;
 
			child_idx = cs->next;
 
			DrawSpriteViewport(cs->image, cs->pal, ps->left + cs->x, ps->top + cs->y, cs->sub);
 
			if (cs->relative) {
 
				DrawSpriteViewport(cs->image, cs->pal, ps->left + cs->x, ps->top + cs->y, cs->sub);
 
			} else {
 
				DrawSpriteViewport(cs->image, cs->pal, ps->x + cs->x, ps->y + cs->y, cs->sub);
 
			}
 
		}
 
	}
 
}
src/viewport_func.h
Show inline comments
 
@@ -51,7 +51,7 @@ void OffsetGroundSprite(int x, int y);
 
void DrawGroundSprite(SpriteID image, PaletteID pal, const SubSprite *sub = nullptr, int extra_offs_x = 0, int extra_offs_y = 0);
 
void DrawGroundSpriteAt(SpriteID image, PaletteID pal, int32 x, int32 y, int z, const SubSprite *sub = nullptr, int extra_offs_x = 0, int extra_offs_y = 0);
 
void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int w, int h, int dz, int z, bool transparent = false, int bb_offset_x = 0, int bb_offset_y = 0, int bb_offset_z = 0, const SubSprite *sub = nullptr);
 
void AddChildSpriteScreen(SpriteID image, PaletteID pal, int x, int y, bool transparent = false, const SubSprite *sub = nullptr, bool scale = true);
 
void AddChildSpriteScreen(SpriteID image, PaletteID pal, int x, int y, bool transparent = false, const SubSprite *sub = nullptr, bool scale = true, bool relative = true);
 
void ViewportAddString(const DrawPixelInfo *dpi, ZoomLevel small_from, const ViewportSign *sign, StringID string_normal, StringID string_small, StringID string_small_shadow, uint64 params_1, uint64 params_2 = 0, Colours colour = INVALID_COLOUR);
 

	
 

	
0 comments (0 inline, 0 general)