Changeset - r11217:943bc05933f0
[Not reviewed]
master
0 1 0
yexo - 16 years ago 2009-02-24 22:23:47
yexo@openttd.org
(svn r15570) -Fix: Too long strings in the advanced settings window are now truncated.
1 file changed with 15 insertions and 12 deletions:
0 comments (0 inline, 0 general)
src/settings_gui.cpp
Show inline comments
 
@@ -645,16 +645,16 @@ struct SettingEntry {
 
	void FoldAll();
 
	void SetButtons(byte new_val);
 

	
 
	uint Length() const;
 
	SettingEntry *FindEntry(uint row, uint *cur_row);
 

	
 
	uint Draw(GameSettings *settings_ptr, int base_x, int base_y, uint first_row, uint max_row, uint cur_row, uint parent_last);
 
	uint Draw(GameSettings *settings_ptr, int base_x, int base_y, int max_x, uint first_row, uint max_row, uint cur_row, uint parent_last);
 

	
 
private:
 
	void DrawSetting(GameSettings *settings_ptr, const SettingDesc *sd, int x, int y, int state);
 
	void DrawSetting(GameSettings *settings_ptr, const SettingDesc *sd, int x, int y, int max_x, int state);
 
};
 

	
 
/** Data structure describing one page of settings in the settings window. */
 
struct SettingsPage {
 
	SettingEntry *entries; ///< Array of setting entries of the page.
 
	byte num;              ///< Number of entries on the page (statically filled).
 
@@ -662,13 +662,13 @@ struct SettingsPage {
 
	void Init(byte level = 0);
 
	void FoldAll();
 

	
 
	uint Length() const;
 
	SettingEntry *FindEntry(uint row, uint *cur_row) const;
 

	
 
	uint Draw(GameSettings *settings_ptr, int base_x, int base_y, uint first_row, uint max_row, uint cur_row = 0, uint parent_last = 0) const;
 
	uint Draw(GameSettings *settings_ptr, int base_x, int base_y, int max_x, uint first_row, uint max_row, uint cur_row = 0, uint parent_last = 0) const;
 
};
 

	
 

	
 
/* == SettingEntry methods == */
 

	
 
/**
 
@@ -805,19 +805,20 @@ SettingEntry *SettingEntry::FindEntry(ui
 
 * The left-most vertical line is not wanted. It is prevented by setting the
 
 * appropiate bit in the \a parent_last parameter.
 
 *
 
 * @param settings_ptr Pointer to current values of all settings
 
 * @param base_x       Left-most position in window/panel to start drawing \a first_row
 
 * @param base_y       Upper-most position in window/panel to start drawing \a first_row
 
 * @param max_x        The maximum x position to draw strings add.
 
 * @param first_row    First row number to draw
 
 * @param max_row      Row-number to stop drawing (the row-number of the row below the last row to draw)
 
 * @param cur_row      Current row number (internal variable)
 
 * @param parent_last  Last-field booleans of parent page level (page level \e i sets bit \e i to 1 if it is its last field)
 
 * @return Row number of the next row to draw
 
 */
 
uint SettingEntry::Draw(GameSettings *settings_ptr, int base_x, int base_y, uint first_row, uint max_row, uint cur_row, uint parent_last)
 
uint SettingEntry::Draw(GameSettings *settings_ptr, int base_x, int base_y, int max_x, uint first_row, uint max_row, uint cur_row, uint parent_last)
 
{
 
	if (cur_row >= max_row) return cur_row;
 

	
 
	int x = base_x;
 
	int y = base_y;
 
	if (cur_row >= first_row) {
 
@@ -838,29 +839,29 @@ uint SettingEntry::Draw(GameSettings *se
 
		x += LEVEL_WIDTH;
 
	}
 

	
 
	switch(this->flags & SEF_KIND_MASK) {
 
		case SEF_SETTING_KIND:
 
			if (cur_row >= first_row) {
 
				DrawSetting(settings_ptr, this->d.entry.setting, x, y, this->flags & SEF_BUTTONS_MASK);
 
				DrawSetting(settings_ptr, this->d.entry.setting, x, y, max_x, this->flags & SEF_BUTTONS_MASK);
 
			}
 
			cur_row++;
 
			break;
 
		case SEF_SUBTREE_KIND:
 
			if (cur_row >= first_row) {
 
				DrawSprite((this->d.sub.folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED), PAL_NONE, x, y);
 
				DrawString(x + 12, y, this->d.sub.title, TC_FROMSTRING);
 
				DrawStringTruncated(x + 12, y, this->d.sub.title, TC_FROMSTRING, max_x - x - 12);
 
			}
 
			cur_row++;
 
			if (!this->d.sub.folded) {
 
				if (this->flags & SEF_LAST_FIELD) {
 
					assert(this->level < sizeof(parent_last));
 
					SetBit(parent_last, this->level); // Add own last-field state
 
				}
 

	
 
				cur_row = this->d.sub.page->Draw(settings_ptr, base_x, base_y, first_row, max_row, cur_row, parent_last);
 
				cur_row = this->d.sub.page->Draw(settings_ptr, base_x, base_y, max_x, first_row, max_row, cur_row, parent_last);
 
			}
 
			break;
 
		default: NOT_REACHED();
 
	}
 
	return cur_row;
 
}
 
@@ -868,15 +869,16 @@ uint SettingEntry::Draw(GameSettings *se
 
/**
 
 * Private function to draw setting value (button + text + current value)
 
 * @param settings_ptr Pointer to current values of all settings
 
 * @param sd           Pointer to value description of setting to draw
 
 * @param x            Left-most position in window/panel to start drawing
 
 * @param y            Upper-most position in window/panel to start drawing
 
 * @param max_x        The maximum x position to draw strings add.
 
 * @param state        State of the left + right arrow buttons to draw for the setting
 
 */
 
void SettingEntry::DrawSetting(GameSettings *settings_ptr, const SettingDesc *sd, int x, int y, int state)
 
void SettingEntry::DrawSetting(GameSettings *settings_ptr, const SettingDesc *sd, int x, int y, int max_x, int state)
 
{
 
	const SettingDescBase *sdb = &sd->desc;
 
	const void *var = GetVariableAddress(settings_ptr, &sd->save);
 
	bool editable = true;
 
	bool disabled = false;
 

	
 
@@ -911,13 +913,13 @@ void SettingEntry::DrawSetting(GameSetti
 
			} else {
 
				SetDParam(0, (sdb->flags & SGF_NOCOMMA) ? STR_CONFIG_SETTING_INT32 : STR_7024);
 
			}
 
			SetDParam(1, value);
 
		}
 
	}
 
	DrawString(x + 25, y, (sdb->str) + disabled, TC_FROMSTRING);
 
	DrawStringTruncated(x + 25, y, (sdb->str) + disabled, TC_FROMSTRING, max_x - x - 25);
 
}
 

	
 

	
 
/* == SettingsPage methods == */
 

	
 
/**
 
@@ -975,24 +977,25 @@ SettingEntry *SettingsPage::FindEntry(ui
 
 * As a result, the drawing routing traverses the tree from top to bottom, counting rows in \a cur_row until it reaches \a first_row.
 
 * Then it enables drawing rows while traversing until \a max_row is reached, at which point drawing is terminated.
 
 *
 
 * @param settings_ptr Pointer to current values of all settings
 
 * @param base_x       Left-most position in window/panel to start drawing of each setting row
 
 * @param base_y       Upper-most position in window/panel to start drawing of row number \a first_row
 
 * @param max_x        The maximum x position to draw strings add.
 
 * @param first_row    Number of first row to draw
 
 * @param max_row      Row-number to stop drawing (the row-number of the row below the last row to draw)
 
 * @param cur_row      Current row number (internal variable)
 
 * @param parent_last  Last-field booleans of parent page level (page level \e i sets bit \e i to 1 if it is its last field)
 
 * @return Row number of the next row to draw
 
 */
 
uint SettingsPage::Draw(GameSettings *settings_ptr, int base_x, int base_y, uint first_row, uint max_row, uint cur_row, uint parent_last) const
 
uint SettingsPage::Draw(GameSettings *settings_ptr, int base_x, int base_y, int max_x, uint first_row, uint max_row, uint cur_row, uint parent_last) const
 
{
 
	if (cur_row >= max_row) return cur_row;
 

	
 
	for (uint i = 0; i < this->num; i++) {
 
		cur_row = this->entries[i].Draw(settings_ptr, base_x, base_y, first_row, max_row, cur_row, parent_last);
 
		cur_row = this->entries[i].Draw(settings_ptr, base_x, base_y, max_x, first_row, max_row, cur_row, parent_last);
 
		if (cur_row >= max_row) {
 
			break;
 
		}
 
	}
 
	return cur_row;
 
}
 
@@ -1273,13 +1276,13 @@ struct GameSettingsWindow : Window {
 
	}
 

	
 
	virtual void OnPaint()
 
	{
 
		this->DrawWidgets();
 
		_settings_main_page.Draw(settings_ptr, SETTINGTREE_LEFT_OFFSET, SETTINGTREE_TOP_OFFSET,
 
						this->vscroll.pos, this->vscroll.pos + this->vscroll.cap);
 
				this->width - 13, this->vscroll.pos, this->vscroll.pos + this->vscroll.cap);
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget)
 
	{
 
		if (widget != SETTINGSEL_OPTIONSPANEL) return;
 

	
0 comments (0 inline, 0 general)