Mercurial > hg > openttd
changeset 11047:4a7256b556b3 draft
(svn r15387) -Codechange: Add a drop down list item type for char* strings.
author | peter1138 <peter1138@openttd.org> |
---|---|
date | Sat, 07 Feb 2009 00:37:35 +0000 |
parents | 6aabd80be58f |
children | fcbd990b6c2b |
files | src/widgets/dropdown.cpp src/widgets/dropdown_type.h |
diffstat | 2 files changed, 25 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/widgets/dropdown.cpp +++ b/src/widgets/dropdown.cpp @@ -39,6 +39,16 @@ return this->string; } +uint DropDownListCharStringItem::Width() const +{ + return GetStringBoundingBox(this->string).width; +} + +void DropDownListCharStringItem::Draw(int x, int y, uint width, uint height, bool sel, int bg_colour) const +{ + DoDrawStringTruncated(this->string, x + 2, y, sel ? TC_WHITE : TC_BLACK, width); +} + /** * Delete all items of a drop down list and the list itself * @param list List to delete.
--- a/src/widgets/dropdown_type.h +++ b/src/widgets/dropdown_type.h @@ -57,6 +57,21 @@ }; /** + * List item containing a C char string. + */ +class DropDownListCharStringItem : public DropDownListItem { +public: + const char *string; + + DropDownListCharStringItem(const char *string, int result, bool masked) : DropDownListItem(result, masked), string(string) {} + virtual ~DropDownListCharStringItem() {} + + virtual bool Selectable() const { return true; } + virtual uint Width() const; + virtual void Draw(int x, int y, uint width, uint height, bool sel, int bg_colour) const; +}; + +/** * A drop down list is a collection of drop down list items. */ typedef std::list<DropDownListItem *> DropDownList;