2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 /** @file dropdown_type.h Types related to the drop down widget. */
10 #ifndef DROPDOWN_TYPE_H
11 #define DROPDOWN_TYPE_H
13 #include "window_type.h"
16 #include "palette_func.h"
17 #include "window_gui.h"
20 * Base list item class from which others are derived.
22 class DropDownListItem
{
24 int result
; ///< Result value to return to window on selection.
25 bool masked
; ///< Masked and unselectable item.
26 bool shaded
; ///< Shaded item, affects text colour.
28 explicit DropDownListItem(int result
, bool masked
= false, bool shaded
= false) : result(result
), masked(masked
), shaded(shaded
) {}
29 virtual ~DropDownListItem() = default;
31 virtual bool Selectable() const { return true; }
32 virtual uint
Height() const { return 0; }
33 virtual uint
Width() const { return 0; }
35 virtual void Draw(const Rect
&full
, const Rect
&, bool, Colours bg_colour
) const
37 if (this->masked
) GfxFillRect(full
, GetColourGradient(bg_colour
, SHADE_LIGHT
), FILLRECT_CHECKER
);
40 TextColour
GetColour(bool sel
) const
42 if (this->shaded
) return (sel
? TC_SILVER
: TC_GREY
) | TC_NO_SHADE
;
43 return sel
? TC_WHITE
: TC_BLACK
;
48 * A drop down list is a collection of drop down list items.
50 typedef std::vector
<std::unique_ptr
<const DropDownListItem
>> DropDownList
;
52 void ShowDropDownListAt(Window
*w
, DropDownList
&&list
, int selected
, WidgetID button
, Rect wi_rect
, Colours wi_colour
, bool instant_close
= false, bool persist
= false);
54 void ShowDropDownList(Window
*w
, DropDownList
&&list
, int selected
, WidgetID button
, uint width
= 0, bool instant_close
= false, bool persist
= false);
56 Dimension
GetDropDownListDimension(const DropDownList
&list
);
58 void ReplaceDropDownList(Window
*parent
, DropDownList
&&list
);
60 #endif /* DROPDOWN_TYPE_H */