mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-02-08 23:34:15 +00:00
Add: Generic drop down list string item with icon.
This commit is contained in:
parent
fb35cb5ed2
commit
b56ea5ca27
@ -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(),
|
||||
|
@ -77,6 +77,24 @@ public:
|
||||
virtual StringID String() const;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user