Changeset - r13810:c776710d89fa
[Not reviewed]
master
0 1 0
alberth - 15 years ago 2009-11-29 21:16:37
alberth@openttd.org
(svn r18346) -Codechange: Compute size of face part display buttons only once in face window.
1 file changed with 33 insertions and 26 deletions:
0 comments (0 inline, 0 general)
src/company_gui.cpp
Show inline comments
 
@@ -1081,8 +1081,11 @@ class SelectCompanyManagerFaceWindow : p
 
	bool is_female;     ///< Female face.
 
	bool is_moust_male; ///< Male face with a moustache.
 

	
 
	static const StringID PART_TEXTS_IS_FEMALE[];
 
	static const StringID PART_TEXTS[];
 
	Dimension yesno_dim;  ///< Dimension of a yes/no button of a part in the advanced face window.
 
	Dimension number_dim; ///< Dimension of a number widget of a part in the advanced face window.
 

	
 
	static const StringID PART_TEXTS_IS_FEMALE[]; ///< Strings depending on #is_female, used to describe parts (2 entries for a part).
 
	static const StringID PART_TEXTS[];           ///< Fixed strings to describe parts of the face.
 

	
 
	/**
 
	 * Draw dynamic a label to the left of the button and a value in the button
 
@@ -1150,6 +1153,29 @@ public:
 
		}
 
	}
 

	
 
	virtual void OnInit()
 
	{
 
		/* Size of the boolean yes/no button. */
 
		Dimension yesno_dim = maxdim(GetStringBoundingBox(STR_FACE_YES), GetStringBoundingBox(STR_FACE_NO));
 
		yesno_dim.width  += WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
 
		yesno_dim.height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
 
		/* Size of the number button + arrows. */
 
		Dimension number_dim = {0, 0};
 
		for (int val = 1; val <= 12; val++) {
 
			SetDParam(0, val);
 
			number_dim = maxdim(number_dim, GetStringBoundingBox(STR_JUST_INT));
 
		}
 
		uint arrows_width = GetSpriteSize(SPR_ARROW_LEFT).width + GetSpriteSize(SPR_ARROW_RIGHT).width + 2 * (WD_IMGBTN_LEFT + WD_IMGBTN_RIGHT);
 
		number_dim.width += WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT + arrows_width;
 
		number_dim.height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
 
		/* Compute width of both buttons. */
 
		yesno_dim.width = max(yesno_dim.width, number_dim.width);
 
		number_dim.width = yesno_dim.width - arrows_width;
 

	
 
		this->yesno_dim = yesno_dim;
 
		this->number_dim = number_dim;
 
	}
 

	
 
	virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
 
	{
 
		switch (widget) {
 
@@ -1184,6 +1210,9 @@ public:
 

	
 
			case SCMFW_WIDGET_HAS_MOUSTACHE_EARRING:
 
			case SCMFW_WIDGET_HAS_GLASSES:
 
				*size = this->yesno_dim;
 
				break;
 

	
 
			case SCMFW_WIDGET_EYECOLOUR:
 
			case SCMFW_WIDGET_CHIN:
 
			case SCMFW_WIDGET_EYEBROWS:
 
@@ -1193,33 +1222,11 @@ public:
 
			case SCMFW_WIDGET_JACKET:
 
			case SCMFW_WIDGET_COLLAR:
 
			case SCMFW_WIDGET_TIE_EARRING:
 
			case SCMFW_WIDGET_GLASSES: {
 
				/* Size of the boolean yes/no button. */
 
				Dimension yesno_dim = maxdim(GetStringBoundingBox(STR_FACE_YES), GetStringBoundingBox(STR_FACE_NO));
 
				yesno_dim.width  += WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
 
				yesno_dim.height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
 
				/* Size of the number button + arrows. */
 
				Dimension number_dim = {0, 0};
 
				for (int val = 1; val <= 12; val++) {
 
					SetDParam(0, val);
 
					number_dim = maxdim(number_dim, GetStringBoundingBox(STR_JUST_INT));
 
				}
 
				uint arrows_width = GetSpriteSize(SPR_ARROW_LEFT).width + GetSpriteSize(SPR_ARROW_RIGHT).width + 2 * (WD_IMGBTN_LEFT + WD_IMGBTN_RIGHT);
 
				number_dim.width += WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT + arrows_width;
 
				number_dim.height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
 
				/* Compute width of yes/no button. */
 
				yesno_dim.width = max(yesno_dim.width, number_dim.width);
 
				number_dim.width = yesno_dim.width - arrows_width;
 

	
 
				if (widget == SCMFW_WIDGET_HAS_MOUSTACHE_EARRING || widget == SCMFW_WIDGET_HAS_GLASSES) {
 
					*size = yesno_dim;
 
				} else {
 
					*size = number_dim;
 
				}
 
			case SCMFW_WIDGET_GLASSES:
 
				*size = this->number_dim;
 
				break;
 
			}
 
		}
 
	}
 

	
 
	virtual void OnPaint()
 
	{
0 comments (0 inline, 0 general)