summaryrefslogtreecommitdiff
path: root/src/toolbar_gui.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2009-11-27 16:46:17 +0000
committerfrosch <frosch@openttd.org>2009-11-27 16:46:17 +0000
commitbdd0f8762dc1426a273afb6904e06a4d8b18d1b4 (patch)
treeb3a8e35de529d1b50e65322123c909119144052f /src/toolbar_gui.cpp
parent5c6b7fd88ded50bf8feff83df2e971b2065dc28d (diff)
downloadopenttd-bdd0f8762dc1426a273afb6904e06a4d8b18d1b4.tar.xz
(svn r18308) -Codechange: Use GetSpriteSize() instead of hardcoded width in dropdowns with company icon.
Diffstat (limited to 'src/toolbar_gui.cpp')
-rw-r--r--src/toolbar_gui.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp
index 51230b8d0..d606547b3 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);
}
};