mirror of https://github.com/OpenTTD/OpenTTD
(svn r27821) -Change: Draw images in centre of buttons (inspired by Juanjo)
parent
902663176d
commit
bcc5c9f81d
|
@ -142,6 +142,18 @@ void CheckBlitter();
|
||||||
|
|
||||||
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height);
|
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine where to draw a centred object inside a widget.
|
||||||
|
* @param min The top or left coordinate.
|
||||||
|
* @param max The bottom or right coordinate.
|
||||||
|
* @param size The height or width of the object to draw.
|
||||||
|
* @return Offset of where to start drawing the object.
|
||||||
|
*/
|
||||||
|
static inline int CenterBounds(int min, int max, uint size)
|
||||||
|
{
|
||||||
|
return min + (max - min - size + 1) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
/* window.cpp */
|
/* window.cpp */
|
||||||
void DrawOverlappedWindowForAll(int left, int top, int right, int bottom);
|
void DrawOverlappedWindowForAll(int left, int top, int right, int bottom);
|
||||||
|
|
||||||
|
|
|
@ -221,7 +221,8 @@ 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.
|
||||||
DrawSprite(img, PAL_NONE, r.left + WD_IMGBTN_LEFT + clicked, r.top + WD_IMGBTN_TOP + clicked);
|
Dimension d = GetSpriteSize(img);
|
||||||
|
DrawSprite(img, PAL_NONE, CenterBounds(r.left, r.right, d.width) + clicked, CenterBounds(r.top, r.bottom, d.height) + clicked);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -459,8 +460,7 @@ static inline void DrawFrame(const Rect &r, Colours colour, StringID str)
|
||||||
*/
|
*/
|
||||||
static inline void DrawShadeBox(const Rect &r, Colours colour, bool clicked)
|
static inline void DrawShadeBox(const Rect &r, Colours colour, bool clicked)
|
||||||
{
|
{
|
||||||
DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE);
|
DrawImageButtons(r, WWT_SHADEBOX, colour, clicked, clicked ? SPR_WINDOW_SHADE: SPR_WINDOW_UNSHADE);
|
||||||
DrawSprite((clicked) ? SPR_WINDOW_SHADE : SPR_WINDOW_UNSHADE, PAL_NONE, r.left + WD_SHADEBOX_LEFT + clicked, r.top + WD_SHADEBOX_TOP + clicked);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -471,8 +471,7 @@ static inline void DrawShadeBox(const Rect &r, Colours colour, bool clicked)
|
||||||
*/
|
*/
|
||||||
static inline void DrawStickyBox(const Rect &r, Colours colour, bool clicked)
|
static inline void DrawStickyBox(const Rect &r, Colours colour, bool clicked)
|
||||||
{
|
{
|
||||||
DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE);
|
DrawImageButtons(r, WWT_STICKYBOX, colour, clicked, clicked ? SPR_PIN_UP : SPR_PIN_DOWN);
|
||||||
DrawSprite((clicked) ? SPR_PIN_UP : SPR_PIN_DOWN, PAL_NONE, r.left + WD_STICKYBOX_LEFT + clicked, r.top + WD_STICKYBOX_TOP + clicked);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -483,8 +482,7 @@ static inline void DrawStickyBox(const Rect &r, Colours colour, bool clicked)
|
||||||
*/
|
*/
|
||||||
static inline void DrawDefSizeBox(const Rect &r, Colours colour, bool clicked)
|
static inline void DrawDefSizeBox(const Rect &r, Colours colour, bool clicked)
|
||||||
{
|
{
|
||||||
DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE);
|
DrawImageButtons(r, WWT_DEFSIZEBOX, colour, clicked, SPR_WINDOW_DEFSIZE);
|
||||||
DrawSprite(SPR_WINDOW_DEFSIZE, PAL_NONE, r.left + WD_DEFSIZEBOX_LEFT + clicked, r.top + WD_DEFSIZEBOX_TOP + clicked);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -495,8 +493,7 @@ static inline void DrawDefSizeBox(const Rect &r, Colours colour, bool clicked)
|
||||||
*/
|
*/
|
||||||
static inline void DrawDebugBox(const Rect &r, Colours colour, bool clicked)
|
static inline void DrawDebugBox(const Rect &r, Colours colour, bool clicked)
|
||||||
{
|
{
|
||||||
DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE);
|
DrawImageButtons(r, WWT_DEBUGBOX, colour, clicked, SPR_WINDOW_DEBUG);
|
||||||
DrawSprite(SPR_WINDOW_DEBUG, PAL_NONE, r.left + WD_DEBUGBOX_LEFT + clicked, r.top + WD_DEBUGBOX_TOP + clicked);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -526,7 +523,9 @@ 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);
|
||||||
DrawSprite(SPR_CLOSEBOX, (colour != COLOUR_WHITE ? TC_BLACK : TC_SILVER) | (1 << PALETTE_TEXT_RECOLOUR), r.left + WD_CLOSEBOX_LEFT, r.top + WD_CLOSEBOX_TOP);
|
Dimension d = GetSpriteSize(SPR_CLOSEBOX);
|
||||||
|
int s = UnScaleGUI(1); /* Offset to account for shadow of SPR_CLOSEBOX */
|
||||||
|
DrawSprite(SPR_CLOSEBOX, (colour != COLOUR_WHITE ? TC_BLACK : TC_SILVER) | (1 << PALETTE_TEXT_RECOLOUR), CenterBounds(r.left, r.right, d.width - s), CenterBounds(r.top, r.bottom, d.height - s));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue