OpenTTD Source  1.11.2
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 WIDGETS_DROPDOWN_TYPE_H
11 #define WIDGETS_DROPDOWN_TYPE_H
12 
13 #include "../window_type.h"
14 #include "../gfx_func.h"
15 #include "../core/smallvec_type.hpp"
16 #include "table/strings.h"
17 
23 public:
24  int result;
25  bool masked;
26 
28  virtual ~DropDownListItem() {}
29 
30  virtual bool Selectable() const { return false; }
31  virtual uint Height(uint width) const { return FONT_HEIGHT_NORMAL; }
32  virtual uint Width() const { return 0; }
33  virtual void Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const;
34 };
35 
40 public:
42 
44 
45  bool Selectable() const override { return true; }
46  uint Width() const override;
47  void Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const override;
48  virtual StringID String() const { return this->string; }
49 
50  static bool NatSortFunc(std::unique_ptr<const DropDownListItem> const &first, std::unique_ptr<const DropDownListItem> const &second);
51 };
52 
57 public:
58  uint64 decode_params[10];
59 
61 
62  StringID String() const override;
63  void SetParam(uint index, uint64 value) { decode_params[index] = value; }
64  void SetParamStr(uint index, const char *str) { this->SetParam(index, (uint64)(size_t)str); }
65 };
66 
71 public:
72  std::string raw_string;
73 
74  DropDownListCharStringItem(const std::string &raw_string, int result, bool masked) : DropDownListStringItem(STR_JUST_RAW_STRING, result, masked), raw_string(raw_string) {}
75 
76  StringID String() const override;
77 };
78 
83  SpriteID sprite;
84  PaletteID pal;
85  Dimension dim;
86  uint sprite_y;
87 public:
88  DropDownListIconItem(SpriteID sprite, PaletteID pal, StringID string, int result, bool masked);
89 
90  uint Height(uint width) const override;
91  uint Width() const override;
92  void Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const override;
93  void SetDimension(Dimension d);
94 };
95 
99 typedef std::vector<std::unique_ptr<const DropDownListItem>> DropDownList;
100 
101 void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button, Rect wi_rect, Colours wi_colour, bool auto_width = false, bool instant_close = false);
102 
103 void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button, uint width = 0, bool auto_width = false, bool instant_close = false);
104 
105 #endif /* WIDGETS_DROPDOWN_TYPE_H */
DropDownListStringItem::string
StringID string
String ID of item.
Definition: dropdown_type.h:41
DropDownListItem::result
int result
Result code to return to window on selection.
Definition: dropdown_type.h:24
DropDownListParamStringItem
String list item with parameters.
Definition: dropdown_type.h:56
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:27
DropDownList
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Definition: dropdown_type.h:99
DropDownListCharStringItem
List item containing a C char string.
Definition: dropdown_type.h:70
DropDownListItem
Base list item class from which others are derived.
Definition: dropdown_type.h:22
ShowDropDownList
void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button, uint width=0, bool auto_width=false, bool instant_close=false)
Show a drop down list.
Definition: dropdown.cpp:447
SpriteID
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
DropDownListStringItem
Common string list item.
Definition: dropdown_type.h:39
DropDownListParamStringItem::decode_params
uint64 decode_params[10]
Parameters of the string.
Definition: dropdown_type.h:58
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:179
PaletteID
uint32 PaletteID
The number of the palette.
Definition: gfx_type.h:18
ShowDropDownListAt
void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button, Rect wi_rect, Colours wi_colour, bool auto_width=false, bool instant_close=false)
Show a drop down list.
Definition: dropdown.cpp:360
Window
Data structure for an opened window.
Definition: window_gui.h:277
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:47
DropDownListItem::masked
bool masked
Masked and unselectable item.
Definition: dropdown_type.h:25
DropDownListIconItem
List item with icon and string.
Definition: dropdown_type.h:82
DropDownListStringItem::NatSortFunc
static bool NatSortFunc(std::unique_ptr< const DropDownListItem > const &first, std::unique_ptr< const DropDownListItem > const &second)
Natural sorting comparator function for DropDownList::sort().
Definition: dropdown.cpp:52