diff options
author | alberth <alberth@openttd.org> | 2012-05-12 10:11:41 +0000 |
---|---|---|
committer | alberth <alberth@openttd.org> | 2012-05-12 10:11:41 +0000 |
commit | 2dd71035d03b63603f56fb3a8f08c1e099836bb4 (patch) | |
tree | b6e57f16fdab1356e48c72b1132fef1627abd726 /src | |
parent | fc213a6dae5e1e8342dd32863f2cb662400e69d1 (diff) | |
download | openttd-2dd71035d03b63603f56fb3a8f08c1e099836bb4.tar.xz |
(svn r24236) -Add: Add code to retrieve help strings from the setting tree and compute max height.
Diffstat (limited to 'src')
-rw-r--r-- | src/settings_gui.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index e4ebff0c2..9fc9d2934 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -1011,9 +1011,20 @@ struct SettingEntry { uint Length() const; SettingEntry *FindEntry(uint row, uint *cur_row); + uint GetMaxHelpHeight(int maxw); 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); + /** + * Get the help text of a single setting. + * @return The requested help text. + */ + inline StringID GetHelpText() + { + assert((this->flags & SEF_KIND_MASK) == SEF_SETTING_KIND); + return this->d.entry.setting->desc.str_help; + } + private: void DrawSetting(GameSettings *settings_ptr, const SettingDesc *sd, int x, int y, int max_x, int state); }; @@ -1028,6 +1039,7 @@ struct SettingsPage { uint Length() const; SettingEntry *FindEntry(uint row, uint *cur_row) const; + uint GetMaxHelpHeight(int maxw); 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; }; @@ -1154,6 +1166,20 @@ SettingEntry *SettingEntry::FindEntry(uint row_num, uint *cur_row) } /** + * Get the biggest height of the help text(s), if the width is at least \a maxw. Help text gets wrapped if needed. + * @param maxw Maximal width of a line help text. + * @return Biggest height needed to display any help text of this node (and its descendants). + */ +uint SettingEntry::GetMaxHelpHeight(int maxw) +{ + switch (this->flags & SEF_KIND_MASK) { + case SEF_SETTING_KIND: return GetStringHeight(this->GetHelpText(), maxw); + case SEF_SUBTREE_KIND: return this->d.sub.page->GetMaxHelpHeight(maxw); + default: NOT_REACHED(); + } +} + +/** * Draw a row in the settings panel. * * See SettingsPage::Draw() for an explanation about how drawing is performed. @@ -1352,6 +1378,20 @@ SettingEntry *SettingsPage::FindEntry(uint row_num, uint *cur_row) const } /** + * Get the biggest height of the help texts, if the width is at least \a maxw. Help text gets wrapped if needed. + * @param maxw Maximal width of a line help text. + * @return Biggest height needed to display any help text of this (sub-)tree. + */ +uint SettingsPage::GetMaxHelpHeight(int maxw) +{ + uint biggest = 0; + for (uint field = 0; field < this->num; field++) { + biggest = max(biggest, this->entries[field].GetMaxHelpHeight(maxw)); + } + return biggest; +} + +/** * Draw a selected part of the settings page. * * The scrollbar uses rows of the page, while the page data strucure is a tree of #SettingsPage and #SettingEntry objects. |