From bdd0f8762dc1426a273afb6904e06a4d8b18d1b4 Mon Sep 17 00:00:00 2001 From: frosch Date: Fri, 27 Nov 2009 16:46:17 +0000 Subject: [PATCH] (svn r18308) -Codechange: Use GetSpriteSize() instead of hardcoded width in dropdowns with company icon. --- src/toolbar_gui.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index 51230b8d01..d606547b3d 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -147,10 +147,14 @@ public: * Drop down list entry for showing a company entry, with companies 'blob'. */ class DropDownListCompanyItem : public DropDownListItem { + uint icon_width; public: bool greyed; - DropDownListCompanyItem(int result, bool masked, bool greyed) : DropDownListItem(result, masked), greyed(greyed) {} + DropDownListCompanyItem(int result, bool masked, bool greyed) : DropDownListItem(result, masked), greyed(greyed) + { + this->icon_width = GetSpriteSize(SPR_COMPANY_ICON).width; + } virtual ~DropDownListCompanyItem() {} @@ -161,12 +165,10 @@ public: uint Width() const { - char buffer[512]; CompanyID company = (CompanyID)this->result; SetDParam(0, company); SetDParam(1, company); - GetString(buffer, STR_COMPANY_NAME_COMPANY_NUM, lastof(buffer)); - return GetStringBoundingBox(buffer).width + 19; + return GetStringBoundingBox(STR_COMPANY_NAME_COMPANY_NUM).width + this->icon_width + 3; } void Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const @@ -177,7 +179,7 @@ public: /* It's possible the company is deleted while the dropdown is open */ if (!Company::IsValidID(company)) return; - DrawCompanyIcon(company, rtl ? right - 14 - WD_FRAMERECT_RIGHT : left + WD_FRAMERECT_LEFT, top + 1 + (FONT_HEIGHT_NORMAL - 10) / 2); + DrawCompanyIcon(company, rtl ? right - this->icon_width - WD_FRAMERECT_RIGHT : left + WD_FRAMERECT_LEFT, top + 1 + (FONT_HEIGHT_NORMAL - 10) / 2); SetDParam(0, company); SetDParam(1, company); @@ -187,7 +189,7 @@ public: } else { col = sel ? TC_WHITE : TC_BLACK; } - DrawString(left + WD_FRAMERECT_LEFT + (rtl ? 0 : 17), right - WD_FRAMERECT_RIGHT - (rtl ? 17 : 0), top, STR_COMPANY_NAME_COMPANY_NUM, col); + DrawString(left + WD_FRAMERECT_LEFT + (rtl ? 0 : 3 + this->icon_width), right - WD_FRAMERECT_RIGHT - (rtl ? 3 + this->icon_width : 0), top, STR_COMPANY_NAME_COMPANY_NUM, col); } };