diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/widgets/dropdown.cpp | 34 | ||||
-rw-r--r-- | src/widgets/dropdown_type.h | 18 |
2 files changed, 52 insertions, 0 deletions
diff --git a/src/widgets/dropdown.cpp b/src/widgets/dropdown.cpp index fb235a6eb..f789b47b7 100644 --- a/src/widgets/dropdown.cpp +++ b/src/widgets/dropdown.cpp @@ -71,6 +71,40 @@ StringID DropDownListCharStringItem::String() const return this->string; } +DropDownListIconItem::DropDownListIconItem(SpriteID sprite, PaletteID pal, StringID string, int result, bool masked) : DropDownListParamStringItem(string, result, masked), sprite(sprite), pal(pal) +{ + this->dim = GetSpriteSize(sprite); + if (this->dim.height < (uint)FONT_HEIGHT_NORMAL) { + this->sprite_y = (FONT_HEIGHT_NORMAL - dim.height) / 2; + this->text_y = 0; + } else { + this->sprite_y = 0; + this->text_y = (dim.height - FONT_HEIGHT_NORMAL) / 2; + } +} + +uint DropDownListIconItem::Height(uint width) const +{ + return max(this->dim.height, (uint)FONT_HEIGHT_NORMAL); +} + +uint DropDownListIconItem::Width() const +{ + return DropDownListStringItem::Width() + this->dim.width + WD_FRAMERECT_LEFT; +} + +void DropDownListIconItem::Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const +{ + bool rtl = _current_text_dir == TD_RTL; + DrawSprite(this->sprite, this->pal, rtl ? right - this->dim.width - WD_FRAMERECT_RIGHT : left + WD_FRAMERECT_LEFT, top + this->sprite_y); + DrawString(left + WD_FRAMERECT_LEFT + (rtl ? 0 : (this->dim.width + WD_FRAMERECT_LEFT)), right - WD_FRAMERECT_RIGHT - (rtl ? (this->dim.width + WD_FRAMERECT_RIGHT) : 0), top + this->text_y, this->String(), sel ? TC_WHITE : TC_BLACK); +} + +void DropDownListIconItem::SetDimension(Dimension d) +{ + this->dim = d; +} + static const NWidgetPart _nested_dropdown_menu_widgets[] = { NWidget(NWID_HORIZONTAL), NWidget(WWT_PANEL, COLOUR_END, WID_DM_ITEMS), SetMinimalSize(1, 1), SetScrollbar(WID_DM_SCROLL), EndContainer(), diff --git a/src/widgets/dropdown_type.h b/src/widgets/dropdown_type.h index a5fe27f64..8300dd26d 100644 --- a/src/widgets/dropdown_type.h +++ b/src/widgets/dropdown_type.h @@ -78,6 +78,24 @@ public: }; /** + * List item with icon and string. + */ +class DropDownListIconItem : public DropDownListParamStringItem { + SpriteID sprite; + PaletteID pal; + Dimension dim; + uint sprite_y; + uint text_y; +public: + DropDownListIconItem(SpriteID sprite, PaletteID pal, StringID string, int result, bool masked); + + /* virtual */ uint Height(uint width) const; + /* virtual */ uint Width() const; + /* virtual */ void Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const; + void SetDimension(Dimension d); +}; + +/** * A drop down list is a collection of drop down list items. */ typedef AutoDeleteSmallVector<const DropDownListItem *, 4> DropDownList; |