mirror of https://github.com/OpenTTD/OpenTTD
Change: Ignore offsets when drawing GUI sprite.
parent
b5693becdc
commit
d0add1e07f
|
@ -90,6 +90,7 @@ void RedrawScreenRect(int left, int top, int right, int bottom);
|
||||||
void GfxScroll(int left, int top, int width, int height, int xo, int yo);
|
void GfxScroll(int left, int top, int width, int height, int xo, int yo);
|
||||||
|
|
||||||
Dimension GetSpriteSize(SpriteID sprid, Point *offset = nullptr, ZoomLevel zoom = ZOOM_LVL_GUI);
|
Dimension GetSpriteSize(SpriteID sprid, Point *offset = nullptr, ZoomLevel zoom = ZOOM_LVL_GUI);
|
||||||
|
Dimension GetScaledSpriteSize(SpriteID sprid); /* widget.cpp */
|
||||||
void DrawSpriteViewport(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub = nullptr);
|
void DrawSpriteViewport(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub = nullptr);
|
||||||
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub = nullptr, ZoomLevel zoom = ZOOM_LVL_GUI);
|
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub = nullptr, ZoomLevel zoom = ZOOM_LVL_GUI);
|
||||||
std::unique_ptr<uint32[]> DrawSpriteToRgbaBuffer(SpriteID spriteId, ZoomLevel zoom = ZOOM_LVL_GUI);
|
std::unique_ptr<uint32[]> DrawSpriteToRgbaBuffer(SpriteID spriteId, ZoomLevel zoom = ZOOM_LVL_GUI);
|
||||||
|
|
|
@ -72,6 +72,19 @@ static inline Dimension ScaleGUITrad(const Dimension &dim)
|
||||||
return {(uint)ScaleGUITrad(dim.width), (uint)ScaleGUITrad(dim.height)};
|
return {(uint)ScaleGUITrad(dim.width), (uint)ScaleGUITrad(dim.height)};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scale sprite size for GUI.
|
||||||
|
* Offset is ignored.
|
||||||
|
*/
|
||||||
|
Dimension GetScaledSpriteSize(SpriteID sprid)
|
||||||
|
{
|
||||||
|
Point offset;
|
||||||
|
Dimension d = GetSpriteSize(sprid, &offset, ZOOM_LVL_OUT_4X);
|
||||||
|
d.width -= offset.x;
|
||||||
|
d.height -= offset.y;
|
||||||
|
return ScaleGUITrad(d);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set up pre-scaled versions of Widget Dimensions.
|
* Set up pre-scaled versions of Widget Dimensions.
|
||||||
*/
|
*/
|
||||||
|
@ -318,6 +331,17 @@ void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, Fra
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DrawSpriteIgnorePadding(const Rect &r, SpriteID img, int clicked, StringAlignment align)
|
||||||
|
{
|
||||||
|
Point offset;
|
||||||
|
Dimension d = GetSpriteSize(img, &offset);
|
||||||
|
d.width -= offset.x;
|
||||||
|
d.height -= offset.y;
|
||||||
|
|
||||||
|
Point p = GetAlignedPosition(r, d, align);
|
||||||
|
DrawSprite(img, PAL_NONE, p.x + clicked - offset.x, p.y + clicked - offset.y);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draw an image button.
|
* Draw an image button.
|
||||||
* @param r Rectangle of the button.
|
* @param r Rectangle of the button.
|
||||||
|
@ -333,9 +357,7 @@ static inline void DrawImageButtons(const Rect &r, WidgetType type, Colours colo
|
||||||
DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE);
|
DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE);
|
||||||
|
|
||||||
if ((type & WWT_MASK) == WWT_IMGBTN_2 && clicked) img++; // Show different image when clicked for #WWT_IMGBTN_2.
|
if ((type & WWT_MASK) == WWT_IMGBTN_2 && clicked) img++; // Show different image when clicked for #WWT_IMGBTN_2.
|
||||||
Dimension d = GetSpriteSize(img);
|
DrawSpriteIgnorePadding(r, img, clicked, align);
|
||||||
Point p = GetAlignedPosition(r, d, align);
|
|
||||||
DrawSprite(img, PAL_NONE, p.x + clicked, p.y + clicked);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -645,9 +667,12 @@ static inline void DrawResizeBox(const Rect &r, Colours colour, bool at_left, bo
|
||||||
static inline void DrawCloseBox(const Rect &r, Colours colour)
|
static inline void DrawCloseBox(const Rect &r, Colours colour)
|
||||||
{
|
{
|
||||||
if (colour != COLOUR_WHITE) DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, FR_NONE);
|
if (colour != COLOUR_WHITE) DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, FR_NONE);
|
||||||
Dimension d = GetSpriteSize(SPR_CLOSEBOX);
|
Point offset;
|
||||||
int s = UnScaleGUI(1); /* Offset to account for shadow of SPR_CLOSEBOX */
|
Dimension d = GetSpriteSize(SPR_CLOSEBOX, &offset);
|
||||||
DrawSprite(SPR_CLOSEBOX, (colour != COLOUR_WHITE ? TC_BLACK : TC_SILVER) | (1U << PALETTE_TEXT_RECOLOUR), CenterBounds(r.left, r.right, d.width - s), CenterBounds(r.top, r.bottom, d.height - s));
|
d.width -= offset.x;
|
||||||
|
d.height -= offset.y;
|
||||||
|
int s = ScaleGUITrad(1); /* Offset to account for shadow of SPR_CLOSEBOX */
|
||||||
|
DrawSprite(SPR_CLOSEBOX, (colour != COLOUR_WHITE ? TC_BLACK : TC_SILVER) | (1U << PALETTE_TEXT_RECOLOUR), CenterBounds(r.left, r.right, d.width - s) - offset.x, CenterBounds(r.top, r.bottom, d.height - s) - offset.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue