summaryrefslogtreecommitdiff
path: root/src/widgets/dropdown.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/dropdown.cpp')
-rw-r--r--src/widgets/dropdown.cpp34
1 files changed, 34 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(),