OpenTTD Source  20241108-master-g80f628063a
dropdown_type.h
Go to the documentation of this file.
1 /*
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/>.
6  */
7 
10 #ifndef DROPDOWN_TYPE_H
11 #define DROPDOWN_TYPE_H
12 
13 #include "window_type.h"
14 #include "gfx_func.h"
15 #include "gfx_type.h"
16 #include "palette_func.h"
17 #include "window_gui.h"
18 
23 public:
24  int result;
25  bool masked;
26  bool shaded;
27 
28  explicit DropDownListItem(int result, bool masked = false, bool shaded = false) : result(result), masked(masked), shaded(shaded) {}
29  virtual ~DropDownListItem() = default;
30 
31  virtual bool Selectable() const { return true; }
32  virtual uint Height() const { return 0; }
33  virtual uint Width() const { return 0; }
34 
35  virtual void Draw(const Rect &full, const Rect &, bool, Colours bg_colour) const
36  {
37  if (this->masked) GfxFillRect(full, GetColourGradient(bg_colour, SHADE_LIGHT), FILLRECT_CHECKER);
38  }
39 
40  TextColour GetColour(bool sel) const
41  {
42  if (this->shaded) return (sel ? TC_SILVER : TC_GREY) | TC_NO_SHADE;
43  return sel ? TC_WHITE : TC_BLACK;
44  }
45 };
46 
50 typedef std::vector<std::unique_ptr<const DropDownListItem>> DropDownList;
51 
52 void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, WidgetID button, Rect wi_rect, Colours wi_colour, bool instant_close = false, bool persist = false);
53 
54 void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width = 0, bool instant_close = false, bool persist = false);
55 
57 
58 void ReplaceDropDownList(Window *parent, DropDownList &&list);
59 
60 #endif /* DROPDOWN_TYPE_H */
Base list item class from which others are derived.
Definition: dropdown_type.h:22
bool masked
Masked and unselectable item.
Definition: dropdown_type.h:25
int result
Result value to return to window on selection.
Definition: dropdown_type.h:24
bool shaded
Shaded item, affects text colour.
Definition: dropdown_type.h:26
void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, WidgetID button, Rect wi_rect, Colours wi_colour, bool instant_close=false, bool persist=false)
Show a drop down list.
Definition: dropdown.cpp:386
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Definition: dropdown_type.h:50
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width=0, bool instant_close=false, bool persist=false)
Show a drop down list.
Definition: dropdown.cpp:404
Dimension GetDropDownListDimension(const DropDownList &list)
Determine width and height required to fully display a DropDownList.
Definition: dropdown.cpp:363
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition: gfx.cpp:114
Functions related to the gfx engine.
Types related to the graphics and/or input devices.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:260
@ TC_NO_SHADE
Do not add shading to this text colour.
Definition: gfx_type.h:284
@ FILLRECT_CHECKER
Draw only every second pixel, used for greying-out.
Definition: gfx_type.h:299
uint8_t GetColourGradient(Colours colour, ColourShade shade)
Get colour gradient palette index.
Definition: palette.cpp:314
Functions related to palettes.
Dimensions (a width and height) of a rectangle in 2D.
Specification of a rectangle with absolute coordinates of all edges.
Data structure for an opened window.
Definition: window_gui.h:273
int16_t Height
Fixed point type for heights.
Definition: tgp.cpp:153
Functions, definitions and such used only by the GUI.
Types related to windows.
int WidgetID
Widget ID.
Definition: window_type.h:18