Changeset - r28245:9bcf5717d348
[Not reviewed]
master
0 13 0
Peter Nelson - 12 months ago 2023-12-04 18:19:55
peter1138@openttd.org
Cleanup: Remove unnecessary pressed button offset code.
13 files changed with 25 insertions and 38 deletions:
0 comments (0 inline, 0 general)
src/bridge_gui.cpp
Show inline comments
 
@@ -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);
 
				}
src/build_vehicle_gui.cpp
Show inline comments
 
@@ -1080,7 +1080,7 @@ void DrawEngineList(VehicleType type, co
 
		}
 
		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 */
src/depot_gui.cpp
Show inline comments
 
@@ -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);
src/gfx_func.h
Show inline comments
 
@@ -89,7 +89,7 @@ Dimension GetSpriteSize(SpriteID sprid, 
 
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);
src/graph_gui.cpp
Show inline comments
 
@@ -961,7 +961,7 @@ struct PaymentRatesGraphWindow : BaseGra
 
			/* 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 : W
 
		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;
 
		}
 

	
src/linkgraph/linkgraph_gui.cpp
Show inline comments
 
@@ -614,7 +614,6 @@ void LinkGraphLegendWindow::UpdateWidget
 
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);
src/misc_gui.cpp
Show inline comments
 
@@ -790,7 +790,7 @@ void QueryString::DrawEditBox(const Wind
 
	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);
src/script/script_gui.cpp
Show inline comments
 
@@ -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));
 
	}
 

	
 
	/**
src/settings_gui.cpp
Show inline comments
 
@@ -2667,8 +2667,8 @@ void DrawArrowButtons(int x, int y, Colo
 

	
 
	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, Co
 
	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);
src/station_gui.cpp
Show inline comments
 
@@ -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);
src/vehicle_gui.cpp
Show inline comments
 
@@ -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);
 
	}
src/widget.cpp
Show inline comments
 
@@ -154,7 +154,6 @@ const WidgetDimensions WidgetDimensions:
 
	{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, in
 
	}
 
}
 

	
 
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 im
 
	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 im
 
 * @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(cons
 
	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 
 
	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 Re
 
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 
 
 * 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(co
 
		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 wid
 
	/* 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);
 
}
 

	
 
/**
src/window_gui.h
Show inline comments
 
@@ -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.
0 comments (0 inline, 0 general)