Changeset - r18043:a7c48c3d52ed
[Not reviewed]
master
0 1 0
planetmaker - 13 years ago 2011-09-02 15:55:52
planetmaker@openttd.org
(svn r22868) -Change: Resize the company league window according to the company icon's size
1 file changed with 11 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/graph_gui.cpp
Show inline comments
 
@@ -1152,12 +1152,14 @@ static inline StringID GetPerformanceTit
 

	
 
class CompanyLeagueWindow : public Window {
 
private:
 
	GUIList<const Company*> companies;
 
	uint ordinal_width; ///< The width of the ordinal number
 
	uint text_width;    ///< The width of the actual text
 
	uint icon_width;    ///< The width of the company icon
 
	int line_height;    ///< Height of the text lines
 

	
 
	/**
 
	 * (Re)Build the company league list
 
	 */
 
	void BuildCompanyList()
 
	{
 
@@ -1197,14 +1199,14 @@ public:
 
	}
 

	
 
	virtual void DrawWidget(const Rect &r, int widget) const
 
	{
 
		if (widget != CLW_BACKGROUND) return;
 

	
 
		uint y = r.top + WD_FRAMERECT_TOP;
 
		int icon_y_offset = 1 + (FONT_HEIGHT_NORMAL - 10) / 2;
 
		int icon_y_offset = 1 + (FONT_HEIGHT_NORMAL - this->line_height) / 2;
 
		uint y = r.top + WD_FRAMERECT_TOP - icon_y_offset;
 

	
 
		bool rtl = _current_text_dir == TD_RTL;
 
		uint ordinal_left  = rtl ? r.right - WD_FRAMERECT_LEFT - this->ordinal_width : r.left + WD_FRAMERECT_LEFT;
 
		uint ordinal_right = rtl ? r.right - WD_FRAMERECT_LEFT : r.left + WD_FRAMERECT_LEFT + this->ordinal_width;
 
		uint icon_left     = r.left + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT + (rtl ? this->text_width : this->ordinal_width);
 
		uint text_left     = rtl ? r.left + WD_FRAMERECT_LEFT : r.right - WD_FRAMERECT_LEFT - this->text_width;
 
@@ -1217,13 +1219,13 @@ public:
 
			DrawCompanyIcon(c->index, icon_left, y + icon_y_offset);
 

	
 
			SetDParam(0, c->index);
 
			SetDParam(1, c->index);
 
			SetDParam(2, GetPerformanceTitleFromValue(c->old_economy[0].performance_history));
 
			DrawString(text_left, text_right, y, STR_COMPANY_LEAGUE_COMPANY_NAME);
 
			y += FONT_HEIGHT_NORMAL;
 
			y += this->line_height;
 
		}
 
	}
 

	
 
	virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
 
	{
 
		if (widget != CLW_BACKGROUND) return;
 
@@ -1241,23 +1243,28 @@ public:
 
			if (width > widest_width) {
 
				widest_title = i;
 
				widest_width = width;
 
			}
 
		}
 

	
 
		Dimension d = GetSpriteSize(SPR_COMPANY_ICON);
 
		this->icon_width = d.width + 2;
 
		this->line_height = max<int>(d.height + 2, FONT_HEIGHT_NORMAL);
 

	
 
		const Company *c;
 
		FOR_ALL_COMPANIES(c) {
 
			SetDParam(0, c->index);
 
			SetDParam(1, c->index);
 
			SetDParam(2, _performance_titles[widest_title]);
 
			widest_width = max(widest_width, GetStringBoundingBox(STR_COMPANY_LEAGUE_COMPANY_NAME).width);
 
		}
 

	
 
		this->text_width = widest_width + 30; // Keep some extra spacing
 

	
 
		size->width = WD_FRAMERECT_LEFT + this->ordinal_width + WD_FRAMERECT_RIGHT + 16 + WD_FRAMERECT_LEFT + this->text_width + WD_FRAMERECT_RIGHT;
 
		size->width = WD_FRAMERECT_LEFT + this->ordinal_width + WD_FRAMERECT_RIGHT + this->icon_width + WD_FRAMERECT_LEFT + this->text_width + WD_FRAMERECT_RIGHT;
 
		size->height = WD_FRAMERECT_TOP + this->line_height * MAX_COMPANIES + WD_FRAMERECT_BOTTOM;
 
	}
 

	
 

	
 
	virtual void OnTick()
 
	{
 
		if (this->companies.NeedResort()) {
0 comments (0 inline, 0 general)