OpenTTD Source: src/dropdown_type.h Source File

OpenTTD Source 15.0-RC2

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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#ifndef DROPDOWN_TYPE_H
11#define DROPDOWN_TYPE_H
12
13#include "core/enum_type.hpp"
14#include "window_type.h"
15#include "gfx_func.h"
16#include "gfx_type.h"
17#include "palette_func.h"
18#include "window_gui.h"
19
23 class DropDownListItem {
24public:
25 int result;
26 bool masked;
27 bool shaded;
28
29 explicit DropDownListItem(int result, bool masked = false, bool shaded = false) : result(result), masked(masked), shaded(shaded) {}
30 virtual ~DropDownListItem() = default;
31
32 virtual bool Selectable() const { return true; }
33 virtual uint Height() const { return 0; }
34 virtual uint Width() const { return 0; }
35
36 virtual int OnClick(const Rect &, const Point &) const
37 {
38 return -1;
39 }
40
41 virtual void Draw(const Rect &full, const Rect &, bool, int, Colours bg_colour) const
42 {
43 if (this->masked) GfxFillRect(full, GetColourGradient(bg_colour, SHADE_LIGHT), FILLRECT_CHECKER);
44 }
45
46 TextColour GetColour(bool sel) const
47 {
48 if (this->shaded) return (sel ? TC_SILVER : TC_GREY) | TC_NO_SHADE;
49 return sel ? TC_WHITE : TC_BLACK;
50 }
51};
52
56 typedef std::vector<std::unique_ptr<const DropDownListItem>> DropDownList;
57
58 enum class DropDownOption : uint8_t {
59 InstantClose,
60 Persist,
61};
62using DropDownOptions = EnumBitSet<DropDownOption, uint8_t>;
63
64void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, WidgetID button, Rect wi_rect, Colours wi_colour, DropDownOptions options = {});
65
66void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width = 0, DropDownOptions options = {});
67
68 Dimension GetDropDownListDimension(const DropDownList &list);
69
70void ReplaceDropDownList(Window *parent, DropDownList &&list, std::optional<int> selected_result = std::nullopt);
71
72#endif /* DROPDOWN_TYPE_H */
DropDownListItem
Base list item class from which others are derived.
Definition dropdown_type.h:23
DropDownListItem::masked
bool masked
Masked and unselectable item.
Definition dropdown_type.h:26
DropDownListItem::result
int result
Result value to return to window on selection.
Definition dropdown_type.h:25
DropDownListItem::shaded
bool shaded
Shaded item, affects text colour.
Definition dropdown_type.h:27
EnumBitSet< DropDownOption, uint8_t >
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:56
DropDownOption
DropDownOption
Definition dropdown_type.h:58
DropDownOption::InstantClose
@ InstantClose
Set if releasing mouse button should close the list regardless of where the cursor is.
DropDownOption::Persist
@ Persist
Set if this dropdown should stay open after an option is selected.
ShowDropDownListAt
void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, WidgetID button, Rect wi_rect, Colours wi_colour, DropDownOptions options={})
Show a drop down list.
Definition dropdown.cpp:402
ShowDropDownList
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width=0, DropDownOptions options={})
Show a drop down list.
Definition dropdown.cpp:418
GetDropDownListDimension
Dimension GetDropDownListDimension(const DropDownList &list)
Determine width and height required to fully display a DropDownList.
Definition dropdown.cpp:381
enum_type.hpp
Type (helpers) for enums.
GfxFillRect
void GfxFillRect(int left, int top, int right, int bottom, const std::variant< PixelColour, PaletteID > &colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition gfx.cpp:115
gfx_func.h
Functions related to the gfx engine.
gfx_type.h
Types related to the graphics and/or input devices.
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition gfx_type.h:307
TC_NO_SHADE
@ TC_NO_SHADE
Do not add shading to this text colour.
Definition gfx_type.h:331
FILLRECT_CHECKER
@ FILLRECT_CHECKER
Draw only every second pixel, used for greying-out.
Definition gfx_type.h:346
GetColourGradient
PixelColour GetColourGradient(Colours colour, ColourShade shade)
Get colour gradient palette index.
Definition palette.cpp:388
palette_func.h
Functions related to palettes.
Coord2D< int >
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition geometry_type.hpp:56
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition geometry_type.hpp:101
Window
Data structure for an opened window.
Definition window_gui.h:274
Height
int16_t Height
Fixed point type for heights.
Definition tgp.cpp:153
window_gui.h
Functions, definitions and such used only by the GUI.
window_type.h
Types related to windows.
WidgetID
int WidgetID
Widget ID.
Definition window_type.h:20