OpenTTD
dropdown_type.h
Go to the documentation of this file.
1 /* $Id$ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * 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.
6  * 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.
7  * 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  */
9 
12 #ifndef WIDGETS_DROPDOWN_TYPE_H
13 #define WIDGETS_DROPDOWN_TYPE_H
14 
15 #include "../window_type.h"
16 #include "../gfx_func.h"
17 #include "../core/smallvec_type.hpp"
18 #include "table/strings.h"
19 
25 public:
26  int result;
27  bool masked;
28 
29  DropDownListItem(int result, bool masked) : result(result), masked(masked) {}
30  virtual ~DropDownListItem() {}
31 
32  virtual bool Selectable() const { return false; }
33  virtual uint Height(uint width) const { return FONT_HEIGHT_NORMAL; }
34  virtual uint Width() const { return 0; }
35  virtual void Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const;
36 };
37 
42 public:
44 
45  DropDownListStringItem(StringID string, int result, bool masked) : DropDownListItem(result, masked), string(string) {}
46 
47  bool Selectable() const override { return true; }
48  uint Width() const override;
49  void Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const override;
50  virtual StringID String() const { return this->string; }
51 
52  static bool NatSortFunc(std::unique_ptr<const DropDownListItem> const &first, std::unique_ptr<const DropDownListItem> const &second);
53 };
54 
59 public:
60  uint64 decode_params[10];
61 
62  DropDownListParamStringItem(StringID string, int result, bool masked) : DropDownListStringItem(string, result, masked) {}
63 
64  StringID String() const override;
65  void SetParam(uint index, uint64 value) { decode_params[index] = value; }
66 };
67 
72 public:
73  const char *raw_string;
74 
75  DropDownListCharStringItem(const char *raw_string, int result, bool masked) : DropDownListStringItem(STR_JUST_RAW_STRING, result, masked), raw_string(raw_string) {}
76 
77  StringID String() const override;
78 };
79 
84  SpriteID sprite;
85  PaletteID pal;
86  Dimension dim;
87  uint sprite_y;
88  uint text_y;
89 public:
90  DropDownListIconItem(SpriteID sprite, PaletteID pal, StringID string, int result, bool masked);
91 
92  uint Height(uint width) const override;
93  uint Width() const override;
94  void Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const override;
95  void SetDimension(Dimension d);
96 };
97 
101 typedef std::vector<std::unique_ptr<const DropDownListItem>> DropDownList;
102 
103 void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button, Rect wi_rect, Colours wi_colour, bool auto_width = false, bool instant_close = false);
104 
105 void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button, uint width = 0, bool auto_width = false, bool instant_close = false);
106 
107 #endif /* WIDGETS_DROPDOWN_TYPE_H */
uint32 PaletteID
The number of the palette.
Definition: gfx_type.h:20
Common string list item.
Definition: dropdown_type.h:41
Data structure for an opened window.
Definition: window_gui.h:278
List item with icon and string.
Definition: dropdown_type.h:83
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:178
bool masked
Masked and unselectable item.
Definition: dropdown_type.h:27
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
StringID string
String ID of item.
Definition: dropdown_type.h:43
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:19
int result
Result code to return to window on selection.
Definition: dropdown_type.h:26
List item containing a C char string.
Definition: dropdown_type.h:71
Specification of a rectangle with absolute coordinates of all edges.
String list item with parameters.
Definition: dropdown_type.h:58
Base list item class from which others are derived.
Definition: dropdown_type.h:24
Dimensions (a width and height) of a rectangle in 2D.