Cleanup: Remove unnecessary pressed button offset code.

This commit is contained in:
Peter Nelson 2023-12-04 18:19:55 +00:00 committed by Peter Nelson
parent 884b9e6690
commit 58c252b81a
13 changed files with 25 additions and 38 deletions

View File

@ -234,7 +234,7 @@ public:
for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < (int)this->bridges.size(); i++) {
const BuildBridgeData &bridge_data = this->bridges.at(i);
const BridgeSpec *b = bridge_data.spec;
DrawSpriteIgnorePadding(b->sprite, b->pal, tr.WithWidth(this->icon_width, rtl), false, SA_HOR_CENTER | SA_BOTTOM);
DrawSpriteIgnorePadding(b->sprite, b->pal, tr.WithWidth(this->icon_width, rtl), SA_HOR_CENTER | SA_BOTTOM);
DrawStringMultiLine(tr.Indent(this->icon_width + WidgetDimensions::scaled.hsep_normal, rtl), GetBridgeSelectString(bridge_data));
tr = tr.Translate(0, this->resize.step_height);
}

View File

@ -1080,7 +1080,7 @@ void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_li
}
if (has_variants) {
Rect fr = ir.Indent(indent, rtl).WithWidth(circle_width, rtl);
DrawSpriteIgnorePadding(is_folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED, PAL_NONE, {fr.left, y, fr.right, y + ir.Height() - 1}, false, SA_CENTER);
DrawSpriteIgnorePadding(is_folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED, PAL_NONE, {fr.left, y, fr.right, y + ir.Height() - 1}, SA_CENTER);
}
if (indent > 0) {
/* Draw tree lines */

View File

@ -356,7 +356,7 @@ struct DepotWindow : Window {
DrawString(text, STR_DEPOT_NO_ENGINE);
} else {
Rect flag = r.WithWidth(this->flag_size.width, rtl).WithHeight(this->flag_size.height).Translate(0, diff_y);
DrawSpriteIgnorePadding((v->vehstatus & VS_STOPPED) ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, PAL_NONE, flag, false, SA_CENTER);
DrawSpriteIgnorePadding((v->vehstatus & VS_STOPPED) ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, PAL_NONE, flag, SA_CENTER);
SetDParam(0, v->unitnumber);
DrawString(text, STR_JUST_COMMA, (v->max_age - CalendarTime::DAYS_IN_LEAP_YEAR) >= v->age ? TC_BLACK : TC_RED);

View File

@ -89,7 +89,7 @@ Dimension GetSpriteSize(SpriteID sprid, Point *offset = nullptr, ZoomLevel zoom
Dimension GetScaledSpriteSize(SpriteID sprid); /* widget.cpp */
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 DrawSpriteIgnorePadding(SpriteID img, PaletteID pal, const Rect &r, bool clicked, StringAlignment align); /* widget.cpp */
void DrawSpriteIgnorePadding(SpriteID img, PaletteID pal, const Rect &r, StringAlignment align); /* widget.cpp */
std::unique_ptr<uint32_t[]> DrawSpriteToRgbaBuffer(SpriteID spriteId, ZoomLevel zoom = ZOOM_LVL_GUI);
int DrawString(int left, int right, int top, std::string_view str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FS_NORMAL);

View File

@ -961,7 +961,7 @@ struct PaymentRatesGraphWindow : BaseGraphWindow {
/* Redraw frame if lowered */
if (lowered) DrawFrameRect(line, COLOUR_BROWN, FR_LOWERED);
const Rect text = line.Shrink(WidgetDimensions::scaled.framerect).Translate(lowered ? WidgetDimensions::scaled.pressed : 0, lowered ? WidgetDimensions::scaled.pressed : 0);
const Rect text = line.Shrink(WidgetDimensions::scaled.framerect);
/* Cargo-colour box with outline */
const Rect cargo = text.WithWidth(this->legend_width, rtl);
@ -1209,9 +1209,8 @@ struct PerformanceRatingDetailWindow : Window {
if (IsInsideMM(widget, WID_PRD_COMPANY_FIRST, WID_PRD_COMPANY_LAST + 1)) {
if (this->IsWidgetDisabled(widget)) return;
CompanyID cid = (CompanyID)(widget - WID_PRD_COMPANY_FIRST);
int offset = (cid == this->company) ? WidgetDimensions::scaled.pressed : 0;
Dimension sprite_size = GetSpriteSize(SPR_COMPANY_ICON);
DrawCompanyIcon(cid, CenterBounds(r.left, r.right, sprite_size.width) + offset, CenterBounds(r.top, r.bottom, sprite_size.height) + offset);
DrawCompanyIcon(cid, CenterBounds(r.left, r.right, sprite_size.width), CenterBounds(r.top, r.bottom, sprite_size.height));
return;
}

View File

@ -614,7 +614,6 @@ void LinkGraphLegendWindow::UpdateWidgetSize(int widget, Dimension *size, [[mayb
void LinkGraphLegendWindow::DrawWidget(const Rect &r, int widget) const
{
Rect br = r.Shrink(WidgetDimensions::scaled.bevel);
if (this->IsWidgetLowered(widget)) br = br.Translate(WidgetDimensions::scaled.pressed, WidgetDimensions::scaled.pressed);
if (IsInsideMM(widget, WID_LGL_COMPANY_FIRST, WID_LGL_COMPANY_LAST + 1)) {
if (this->IsWidgetDisabled(widget)) return;
CompanyID cid = (CompanyID)(widget - WID_LGL_COMPANY_FIRST);

View File

@ -790,7 +790,7 @@ void QueryString::DrawEditBox(const Window *w, int wid) const
Rect fr = r.Indent(clearbtn_width, !rtl);
DrawFrameRect(cr, wi->colour, wi->IsLowered() ? FR_LOWERED : FR_NONE);
DrawSpriteIgnorePadding(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT, PAL_NONE, cr, wi->IsLowered(), SA_CENTER);
DrawSpriteIgnorePadding(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT, PAL_NONE, cr, SA_CENTER);
if (this->text.bytes == 1) GfxFillRect(cr.Shrink(WidgetDimensions::scaled.bevel), _colour_gradient[wi->colour & 0xF][2], FILLRECT_CHECKER);
DrawFrameRect(fr, wi->colour, FR_LOWERED | FR_DARKENED);

View File

@ -853,9 +853,8 @@ struct ScriptDebugWindow : public Window {
{
if (this->IsWidgetDisabled(widget)) return;
CompanyID cid = (CompanyID)(widget - start);
int offset = (cid == script_debug_company) ? WidgetDimensions::scaled.pressed : 0;
Dimension sprite_size = GetSpriteSize(SPR_COMPANY_ICON);
DrawCompanyIcon(cid, CenterBounds(r.left, r.right, sprite_size.width) + offset, CenterBounds(r.top, r.bottom, sprite_size.height) + offset);
DrawCompanyIcon(cid, CenterBounds(r.left, r.right, sprite_size.width), CenterBounds(r.top, r.bottom, sprite_size.height));
}
/**

View File

@ -2667,8 +2667,8 @@ void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clic
DrawFrameRect(lr, button_colour, (state == 1) ? FR_LOWERED : FR_NONE);
DrawFrameRect(rr, button_colour, (state == 2) ? FR_LOWERED : FR_NONE);
DrawSpriteIgnorePadding(SPR_ARROW_LEFT, PAL_NONE, lr, (state == 1), SA_CENTER);
DrawSpriteIgnorePadding(SPR_ARROW_RIGHT, PAL_NONE, rr, (state == 2), SA_CENTER);
DrawSpriteIgnorePadding(SPR_ARROW_LEFT, PAL_NONE, lr, SA_CENTER);
DrawSpriteIgnorePadding(SPR_ARROW_RIGHT, PAL_NONE, rr, SA_CENTER);
/* Grey out the buttons that aren't clickable */
bool rtl = _current_text_dir == TD_RTL;
@ -2695,7 +2695,7 @@ void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool cl
Rect r = {x, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 1};
DrawFrameRect(r, button_colour, state ? FR_LOWERED : FR_NONE);
DrawSpriteIgnorePadding(SPR_ARROW_DOWN, PAL_NONE, r, state, SA_CENTER);
DrawSpriteIgnorePadding(SPR_ARROW_DOWN, PAL_NONE, r, SA_CENTER);
if (!clickable) {
GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), colour, FILLRECT_CHECKER);

View File

@ -517,8 +517,6 @@ public:
if (widget >= WID_STL_CARGOSTART) {
Rect br = r.Shrink(WidgetDimensions::scaled.bevel);
const CargoSpec *cs = _sorted_cargo_specs[widget - WID_STL_CARGOSTART];
int cg_ofst = HasBit(this->filter.cargoes, cs->Index()) ? WidgetDimensions::scaled.pressed : 0;
br = br.Translate(cg_ofst, cg_ofst);
GfxFillRect(br, cs->rating_colour);
TextColour tc = GetContrastColour(cs->rating_colour);
DrawString(br.left, br.right, CenterBounds(br.top, br.bottom, GetCharacterHeight(FS_SMALL)), cs->abbrev, tc, SA_HOR_CENTER, false, FS_SMALL);

View File

@ -3080,10 +3080,9 @@ public:
/* Draw the flag plus orders. */
bool rtl = (_current_text_dir == TD_RTL);
uint icon_width = std::max({GetScaledSpriteSize(SPR_WARNING_SIGN).width, GetScaledSpriteSize(SPR_FLAG_VEH_STOPPED).width, GetScaledSpriteSize(SPR_FLAG_VEH_RUNNING).width});
int lowered = this->IsWidgetLowered(widget) ? WidgetDimensions::scaled.pressed : 0;
Rect tr = r.Shrink(WidgetDimensions::scaled.framerect).Translate(lowered, lowered);
Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
SpriteID image = ((v->vehstatus & VS_STOPPED) != 0) ? SPR_FLAG_VEH_STOPPED : (HasBit(v->vehicle_flags, VF_PATHFINDER_LOST)) ? SPR_WARNING_SIGN : SPR_FLAG_VEH_RUNNING;
DrawSpriteIgnorePadding(image, PAL_NONE, tr.WithWidth(icon_width, rtl), false, SA_CENTER);
DrawSpriteIgnorePadding(image, PAL_NONE, tr.WithWidth(icon_width, rtl), SA_CENTER);
tr = tr.Indent(icon_width + WidgetDimensions::scaled.imgbtn.Horizontal(), rtl);
DrawString(tr.left, tr.right, CenterBounds(tr.top, tr.bottom, GetCharacterHeight(FS_NORMAL)), str, text_colour, SA_HOR_CENTER);
}

View File

@ -154,7 +154,6 @@ const WidgetDimensions WidgetDimensions::unscaled = {
{3, 3, 3, 3}, ///< picker
{10, 8, 10, 8}, ///< sparse window padding
{10, 8, 10, 1}, ///< resizable sparse window padding
0, ///< pressed
1, ///< vsep_picker
WD_PAR_VSEP_NORMAL, ///< vsep_normal
4, ///< vsep_sparse
@ -227,7 +226,6 @@ void SetupWidgetDimensions()
WidgetDimensions::scaled.dropdowntext = ScaleGUITrad(WidgetDimensions::unscaled.dropdowntext);
WidgetDimensions::scaled.modalpopup = ScaleGUITrad(WidgetDimensions::unscaled.modalpopup);
WidgetDimensions::scaled.pressed = ScaleGUITrad(WidgetDimensions::unscaled.pressed);
WidgetDimensions::scaled.vsep_normal = ScaleGUITrad(WidgetDimensions::unscaled.vsep_normal);
WidgetDimensions::scaled.vsep_wide = ScaleGUITrad(WidgetDimensions::unscaled.vsep_wide);
WidgetDimensions::scaled.hsep_normal = ScaleGUITrad(WidgetDimensions::unscaled.hsep_normal);
@ -453,7 +451,7 @@ void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, Fra
}
}
void DrawSpriteIgnorePadding(SpriteID img, PaletteID pal, const Rect &r, bool clicked, StringAlignment align)
void DrawSpriteIgnorePadding(SpriteID img, PaletteID pal, const Rect &r, StringAlignment align)
{
Point offset;
Dimension d = GetSpriteSize(img, &offset);
@ -461,8 +459,7 @@ void DrawSpriteIgnorePadding(SpriteID img, PaletteID pal, const Rect &r, bool cl
d.height -= offset.y;
Point p = GetAlignedPosition(r, d, align);
int o = clicked ? WidgetDimensions::scaled.pressed : 0;
DrawSprite(img, pal, p.x + o - offset.x, p.y + o - offset.y);
DrawSprite(img, pal, p.x - offset.x, p.y - offset.y);
}
/**
@ -470,7 +467,7 @@ void DrawSpriteIgnorePadding(SpriteID img, PaletteID pal, const Rect &r, bool cl
* @param r Rectangle of the button.
* @param type Widget type (#WWT_IMGBTN or #WWT_IMGBTN_2).
* @param colour Colour of the button.
* @param clicked Button is lowered.
* @param clicked Button is clicked.
* @param img Sprite to draw.
* @param align Alignment of the sprite.
*/
@ -480,14 +477,14 @@ 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);
if ((type & WWT_MASK) == WWT_IMGBTN_2 && clicked) img++; // Show different image when clicked for #WWT_IMGBTN_2.
DrawSpriteIgnorePadding(img, PAL_NONE, r, clicked, align);
DrawSpriteIgnorePadding(img, PAL_NONE, r, align);
}
/**
* 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).
* @param clicked Label is rendered lowered.
* @param clicked Label is clicked.
* @param colour Colour of the text.
* @param str Text to draw.
* @param align Alignment of the text.
@ -499,8 +496,7 @@ static inline void DrawLabel(const Rect &r, WidgetType type, bool clicked, TextC
if ((type & WWT_MASK) == WWT_TEXTBTN_2 && clicked) str++;
Dimension d = GetStringBoundingBox(str, fs);
Point p = GetAlignedPosition(r, d, align);
int o = clicked ? WidgetDimensions::scaled.pressed : 0;
DrawString(r.left + o, r.right + o, p.y + o, str, colour, align, false, fs);
DrawString(r.left, r.right, p.y, str, colour, align, false, fs);
}
/**
@ -783,7 +779,7 @@ static inline void DrawDebugBox(const Rect &r, Colours colour, bool clicked)
static inline void DrawResizeBox(const Rect &r, Colours colour, bool at_left, bool clicked)
{
DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE);
DrawSpriteIgnorePadding(at_left ? SPR_WINDOW_RESIZE_LEFT : SPR_WINDOW_RESIZE_RIGHT, PAL_NONE, r.Shrink(ScaleGUITrad(2)), clicked, at_left ? (SA_LEFT | SA_BOTTOM | SA_FORCE) : (SA_RIGHT | SA_BOTTOM | SA_FORCE));
DrawSpriteIgnorePadding(at_left ? SPR_WINDOW_RESIZE_LEFT : SPR_WINDOW_RESIZE_RIGHT, PAL_NONE, r.Shrink(ScaleGUITrad(2)), at_left ? (SA_LEFT | SA_BOTTOM | SA_FORCE) : (SA_RIGHT | SA_BOTTOM | SA_FORCE));
}
/**
@ -835,8 +831,8 @@ void DrawCaption(const Rect &r, Colours colour, Owner owner, TextColour text_col
* Draw a button with a dropdown (#WWT_DROPDOWN and #NWID_BUTTON_DROPDOWN).
* @param r Rectangle containing the widget.
* @param colour Background colour of the widget.
* @param clicked_button The button-part is lowered.
* @param clicked_dropdown The drop-down part is lowered.
* @param clicked_button The button-part is clicked.
* @param clicked_dropdown The drop-down part is clicked.
* @param str Text of the button.
* @param align Alignment of the text within the dropdown.
*
@ -850,15 +846,13 @@ static inline void DrawButtonDropdown(const Rect &r, Colours colour, bool clicke
DrawFrameRect(r.left, r.top, r.right - dd_width, r.bottom, colour, clicked_button ? FR_LOWERED : FR_NONE);
DrawImageButtons(r.WithWidth(dd_width, true), WWT_DROPDOWN, colour, clicked_dropdown, SPR_ARROW_DOWN, SA_CENTER);
if (str != STR_NULL) {
int o = clicked_button ? WidgetDimensions::scaled.pressed : 0;
DrawString(r.left + WidgetDimensions::scaled.dropdowntext.left + o, r.right - dd_width - WidgetDimensions::scaled.dropdowntext.right + o, CenterBounds(r.top, r.bottom, GetCharacterHeight(FS_NORMAL)) + o, str, TC_BLACK, align);
DrawString(r.left + WidgetDimensions::scaled.dropdowntext.left, r.right - dd_width - WidgetDimensions::scaled.dropdowntext.right, CenterBounds(r.top, r.bottom, GetCharacterHeight(FS_NORMAL)), str, TC_BLACK, align);
}
} else {
DrawFrameRect(r.left + dd_width, r.top, r.right, r.bottom, colour, clicked_button ? FR_LOWERED : FR_NONE);
DrawImageButtons(r.WithWidth(dd_width, false), WWT_DROPDOWN, colour, clicked_dropdown, SPR_ARROW_DOWN, SA_CENTER);
if (str != STR_NULL) {
int o = clicked_button ? WidgetDimensions::scaled.pressed : 0;
DrawString(r.left + dd_width + WidgetDimensions::scaled.dropdowntext.left + o, r.right - WidgetDimensions::scaled.dropdowntext.right + o, CenterBounds(r.top, r.bottom, GetCharacterHeight(FS_NORMAL)) + o, str, TC_BLACK, align);
DrawString(r.left + dd_width + WidgetDimensions::scaled.dropdowntext.left, r.right - WidgetDimensions::scaled.dropdowntext.right, CenterBounds(r.top, r.bottom, GetCharacterHeight(FS_NORMAL)), str, TC_BLACK, align);
}
}
}
@ -908,7 +902,7 @@ void Window::DrawSortButtonState(int widget, SortButtonState state) const
/* Sort button uses the same sprites as vertical scrollbar */
Dimension dim = NWidgetScrollbar::GetVerticalDimension();
DrawSpriteIgnorePadding(state == SBS_DOWN ? SPR_ARROW_DOWN : SPR_ARROW_UP, PAL_NONE, r.WithWidth(dim.width, _current_text_dir == TD_LTR), this->IsWidgetLowered(widget), SA_CENTER);
DrawSpriteIgnorePadding(state == SBS_DOWN ? SPR_ARROW_DOWN : SPR_ARROW_UP, PAL_NONE, r.WithWidth(dim.width, _current_text_dir == TD_LTR), SA_CENTER);
}
/**

View File

@ -54,7 +54,6 @@ struct WidgetDimensions {
RectPadding sparse; ///< Padding used for 'sparse' widget window, usually containing multiple frames.
RectPadding sparse_resize; ///< Padding used for a resizeable 'sparse' widget window, usually containing multiple frames.
int pressed; ///< Offset for contents of depressed widget.
int vsep_picker; ///< Vertical spacing of picker-window widgets.
int vsep_normal; ///< Normal vertical spacing.
int vsep_sparse; ///< Normal vertical spacing for 'sparse' widget window.