Changeset - r22610:f339fa87a305
[Not reviewed]
master
0 2 0
peter1138 - 7 years ago 2017-03-23 22:00:00
peter1138@openttd.org
(svn r27821) -Change: Draw images in centre of buttons (inspired by Juanjo)
2 files changed with 21 insertions and 10 deletions:
0 comments (0 inline, 0 general)
src/gfx_func.h
Show inline comments
 
@@ -139,12 +139,24 @@ void MarkWholeScreenDirty();
 

	
 
void GfxInitPalettes();
 
void CheckBlitter();
 

	
 
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 */
 
void DrawOverlappedWindowForAll(int left, int top, int right, int bottom);
 

	
 
void SetMouseCursorBusy(bool busy);
 
void SetMouseCursor(CursorID cursor, PaletteID pal);
 
void SetAnimatedMouseCursor(const AnimCursor *table);
src/widget.cpp
Show inline comments
 
@@ -218,13 +218,14 @@ void DrawFrameRect(int left, int top, in
 
static inline void DrawImageButtons(const Rect &r, WidgetType type, Colours colour, bool clicked, SpriteID img)
 
{
 
	assert(img != 0);
 
	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.
 
	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);
 
}
 

	
 
/**
 
 * Draw the label-part of a widget.
 
 * @param r       Rectangle of the label background.
 
 * @param type    Widget type (#WWT_TEXTBTN, #WWT_TEXTBTN_2, or #WWT_LABEL).
 
@@ -456,50 +457,46 @@ static inline void DrawFrame(const Rect 
 
 * @param r       Rectangle of the box.
 
 * @param colour  Colour of the shade box.
 
 * @param clicked Box is lowered.
 
 */
 
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);
 
	DrawSprite((clicked) ? SPR_WINDOW_SHADE : SPR_WINDOW_UNSHADE, PAL_NONE, r.left + WD_SHADEBOX_LEFT + clicked, r.top + WD_SHADEBOX_TOP + clicked);
 
	DrawImageButtons(r, WWT_SHADEBOX, colour, clicked, clicked ? SPR_WINDOW_SHADE: SPR_WINDOW_UNSHADE);
 
}
 

	
 
/**
 
 * Draw a sticky box.
 
 * @param r       Rectangle of the box.
 
 * @param colour  Colour of the sticky box.
 
 * @param clicked Box is lowered.
 
 */
 
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);
 
	DrawSprite((clicked) ? SPR_PIN_UP : SPR_PIN_DOWN, PAL_NONE, r.left + WD_STICKYBOX_LEFT + clicked, r.top + WD_STICKYBOX_TOP + clicked);
 
	DrawImageButtons(r, WWT_STICKYBOX, colour, clicked, clicked ? SPR_PIN_UP : SPR_PIN_DOWN);
 
}
 

	
 
/**
 
 * Draw a defsize box.
 
 * @param r       Rectangle of the box.
 
 * @param colour  Colour of the defsize box.
 
 * @param clicked Box is lowered.
 
 */
 
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);
 
	DrawSprite(SPR_WINDOW_DEFSIZE, PAL_NONE, r.left + WD_DEFSIZEBOX_LEFT + clicked, r.top + WD_DEFSIZEBOX_TOP + clicked);
 
	DrawImageButtons(r, WWT_DEFSIZEBOX, colour, clicked, SPR_WINDOW_DEFSIZE);
 
}
 

	
 
/**
 
 * Draw a NewGRF debug box.
 
 * @param r       Rectangle of the box.
 
 * @param colour  Colour of the debug box.
 
 * @param clicked Box is lowered.
 
 */
 
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);
 
	DrawSprite(SPR_WINDOW_DEBUG, PAL_NONE, r.left + WD_DEBUGBOX_LEFT + clicked, r.top + WD_DEBUGBOX_TOP + clicked);
 
	DrawImageButtons(r, WWT_DEBUGBOX, colour, clicked, SPR_WINDOW_DEBUG);
 
}
 

	
 
/**
 
 * Draw a resize box.
 
 * @param r       Rectangle of the box.
 
 * @param colour  Colour of the resize box.
 
@@ -523,13 +520,15 @@ static inline void DrawResizeBox(const R
 
 * @param r      Rectangle of the box.
 
 * @param colour Colour of the close box.
 
 */
 
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);
 
	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));
 
}
 

	
 
/**
 
 * Draw a caption bar.
 
 * @param r      Rectangle of the bar.
 
 * @param colour Colour of the window.
0 comments (0 inline, 0 general)