OpenTTD: src/widgets/dropdown_type.h Source File

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

dropdown_type.h
Go to the documentation of this file.
1 /* $Id: dropdown_type.h 26088 2013-11-24 15:17:53Z rubidium $ */
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
24 class DropDownListItem {
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, int bg_colour) const;
36 };
37
41 class DropDownListStringItem : public DropDownListItem {
42 public:
43 StringID string;
44
45 DropDownListStringItem(StringID string, int result, bool masked) : DropDownListItem(result, masked), string(string) {}
46 virtual ~DropDownListStringItem() {}
47
48 virtual bool Selectable() const { return true; }
49 virtual uint Width() const;
50 virtual void Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const;
51 virtual StringID String() const { return this->string; }
52
53 static int CDECL NatSortFunc(const DropDownListItem * const *first, const DropDownListItem * const *second);
54 };
55
59 class DropDownListParamStringItem : public DropDownListStringItem {
60 public:
61 uint64 decode_params[10];
62
63 DropDownListParamStringItem(StringID string, int result, bool masked) : DropDownListStringItem(string, result, masked) {}
64 virtual ~DropDownListParamStringItem() {}
65
66 virtual StringID String() const;
67 virtual void SetParam(uint index, uint64 value) { decode_params[index] = value; }
68 };
69
73 class DropDownListCharStringItem : public DropDownListStringItem {
74 public:
75 const char *raw_string;
76
77 DropDownListCharStringItem(const char *raw_string, int result, bool masked) : DropDownListStringItem(STR_JUST_RAW_STRING, result, masked), raw_string(raw_string) {}
78 virtual ~DropDownListCharStringItem() {}
79
80 virtual StringID String() const;
81 };
82
86 typedef AutoDeleteSmallVector<const DropDownListItem *, 4> DropDownList;
87
88 void ShowDropDownListAt(Window *w, const DropDownList *list, int selected, int button, Rect wi_rect, Colours wi_colour, bool auto_width = false, bool instant_close = false);
89
90 void ShowDropDownList(Window *w, const DropDownList *list, int selected, int button, uint width = 0, bool auto_width = false, bool instant_close = false);
91
92 #endif /* WIDGETS_DROPDOWN_TYPE_H */