OpenTTD Source: src/widgets/dropdown.cpp Source File

OpenTTD Source 14.1

dropdown.cpp
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 #include "../stdafx.h"
11 #include "../window_gui.h"
12 #include "../string_func.h"
13 #include "../strings_func.h"
14 #include "../window_func.h"
15 #include "../zoom_func.h"
16 #include "../timer/timer.h"
17 #include "../timer/timer_window.h"
18 #include "dropdown_type.h"
19
20 #include "dropdown_widget.h"
21
22 #include "../safeguards.h"
23
24
25 static constexpr NWidgetPart _nested_dropdown_menu_widgets[] = {
26 NWidget(NWID_HORIZONTAL),
27 NWidget(WWT_PANEL, COLOUR_END, WID_DM_ITEMS), SetScrollbar(WID_DM_SCROLL), EndContainer(),
28 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_DM_SHOW_SCROLL),
29 NWidget(NWID_VSCROLLBAR, COLOUR_END, WID_DM_SCROLL),
30 EndContainer(),
31 EndContainer(),
32 };
33
34 static WindowDesc _dropdown_desc(__FILE__, __LINE__,
35 WDP_MANUAL, nullptr, 0, 0,
36 WC_DROPDOWN_MENU, WC_NONE,
37 WDF_NO_FOCUS,
38 std::begin(_nested_dropdown_menu_widgets), std::end(_nested_dropdown_menu_widgets)
39 );
40
42 struct DropdownWindow : Window {
43 WidgetID parent_button;
44 Rect wi_rect;
45 DropDownList list;
46 int selected_result;
47 byte click_delay = 0;
48 bool drag_mode = true;
49 bool instant_close;
50 bool persist;
51 int scrolling = 0;
52 Point position;
53 Scrollbar *vscroll;
54
55 Dimension items_dim;
56
68 DropdownWindow(Window *parent, DropDownList &&list, int selected, WidgetID button, const Rect wi_rect, bool instant_close, Colours wi_colour, bool persist)
69 : Window(&_dropdown_desc)
70 , parent_button(button)
71 , wi_rect(wi_rect)
72 , list(std::move(list))
73 , selected_result(selected)
74 , instant_close(instant_close)
75 , persist(persist)
76 {
77 assert(!this->list.empty());
78
79 this->parent = parent;
80
81 this->CreateNestedTree();
82
83 this->GetWidget<NWidgetCore>(WID_DM_ITEMS)->colour = wi_colour;
84 this->GetWidget<NWidgetCore>(WID_DM_SCROLL)->colour = wi_colour;
85 this->vscroll = this->GetScrollbar(WID_DM_SCROLL);
86 this->UpdateSizeAndPosition();
87
88 this->FinishInitNested(0);
89 CLRBITS(this->flags, WF_WHITE_BORDER);
90 }
91
92 void Close([[maybe_unused]] int data = 0) override
93 {
94 /* Finish closing the dropdown, so it doesn't affect new window placement.
95 * Also mark it dirty in case the callback deals with the screen. (e.g. screenshots). */
96 this->Window::Close();
97
98 Point pt = _cursor.pos;
99 pt.x -= this->parent->left;
100 pt.y -= this->parent->top;
101 this->parent->OnDropdownClose(pt, this->parent_button, this->selected_result, this->instant_close);
102
103 /* Set flag on parent widget to indicate that we have just closed. */
104 NWidgetCore *nwc = this->parent->GetWidget<NWidgetCore>(this->parent_button);
105 if (nwc != nullptr) SetBit(nwc->disp_flags, NDB_DROPDOWN_CLOSED);
106 }
107
108 void OnFocusLost(bool closing) override
109 {
110 if (!closing) {
111 this->instant_close = false;
112 this->Close();
113 }
114 }
115
122 void FitAvailableHeight(Dimension &desired, const Dimension &list, uint available_height)
123 {
124 if (desired.height < available_height) return;
125
126 /* If the dropdown doesn't fully fit, we a need a dropdown. */
127 uint avg_height = list.height / (uint)this->list.size();
128 uint rows = std::max((available_height - WidgetDimensions::scaled.dropdownlist.Vertical()) / avg_height, 1U);
129
130 desired.width = std::max(list.width, desired.width - NWidgetScrollbar::GetVerticalDimension().width);
131 desired.height = rows * avg_height + WidgetDimensions::scaled.dropdownlist.Vertical();
132 }
133
137 void UpdateSizeAndPosition()
138 {
139 Rect button_rect = this->wi_rect.Translate(this->parent->left, this->parent->top);
140
141 /* Get the dimensions required for the list. */
142 Dimension list_dim = GetDropDownListDimension(this->list);
143
144 /* Set up dimensions for the items widget. */
145 Dimension widget_dim = list_dim;
146 widget_dim.width += WidgetDimensions::scaled.dropdownlist.Horizontal();
147 widget_dim.height += WidgetDimensions::scaled.dropdownlist.Vertical();
148
149 /* Width should match at least the width of the parent widget. */
150 widget_dim.width = std::max<uint>(widget_dim.width, button_rect.Width());
151
152 /* Available height below (or above, if the dropdown is placed above the widget). */
153 uint available_height_below = std::max(GetMainViewBottom() - button_rect.bottom - 1, 0);
154 uint available_height_above = std::max(button_rect.top - 1 - GetMainViewTop(), 0);
155
156 /* Is it better to place the dropdown above the widget? */
157 if (widget_dim.height > available_height_below && available_height_above > available_height_below) {
158 FitAvailableHeight(widget_dim, list_dim, available_height_above);
159 this->position.y = button_rect.top - widget_dim.height;
160 } else {
161 FitAvailableHeight(widget_dim, list_dim, available_height_below);
162 this->position.y = button_rect.bottom + 1;
163 }
164
165 if (_current_text_dir == TD_RTL) {
166 /* In case the list is wider than the parent button, the list should be right aligned to the button and overflow to the left. */
167 this->position.x = button_rect.right + 1 - (int)(widget_dim.width + (list_dim.height > widget_dim.height ? NWidgetScrollbar::GetVerticalDimension().width : 0));
168 } else {
169 this->position.x = button_rect.left;
170 }
171
172 this->items_dim = widget_dim;
173 this->GetWidget<NWidgetStacked>(WID_DM_SHOW_SCROLL)->SetDisplayedPlane(list_dim.height > widget_dim.height ? 0 : SZSP_NONE);
174
175 /* Capacity is the average number of items visible */
176 this->vscroll->SetCapacity((widget_dim.height - WidgetDimensions::scaled.dropdownlist.Vertical()) * this->list.size() / list_dim.height);
177 this->vscroll->SetCount(this->list.size());
178
179 /* If the dropdown is positioned above the parent widget, start selection at the bottom. */
180 if (this->position.y < button_rect.top && list_dim.height > widget_dim.height) this->vscroll->UpdatePosition(INT_MAX);
181 }
182
183 void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
184 {
185 if (widget == WID_DM_ITEMS) *size = this->items_dim;
186 }
187
188 Point OnInitialPosition([[maybe_unused]] int16_t sm_width, [[maybe_unused]] int16_t sm_height, [[maybe_unused]] int window_number) override
189 {
190 return this->position;
191 }
192
198 bool GetDropDownItem(int &value)
199 {
200 if (GetWidgetFromPos(this, _cursor.pos.x - this->left, _cursor.pos.y - this->top) < 0) return false;
201
202 const Rect &r = this->GetWidget<NWidgetBase>(WID_DM_ITEMS)->GetCurrentRect().Shrink(WidgetDimensions::scaled.dropdownlist);
203 int y = _cursor.pos.y - this->top - r.top;
204 int pos = this->vscroll->GetPosition();
205
206 for (const auto &item : this->list) {
207 /* Skip items that are scrolled up */
208 if (--pos >= 0) continue;
209
210 int item_height = item->Height();
211
212 if (y < item_height) {
213 if (item->masked || !item->Selectable()) return false;
214 value = item->result;
215 return true;
216 }
217
218 y -= item_height;
219 }
220
221 return false;
222 }
223
224 void DrawWidget(const Rect &r, WidgetID widget) const override
225 {
226 if (widget != WID_DM_ITEMS) return;
227
228 Colours colour = this->GetWidget<NWidgetCore>(widget)->colour;
229
230 Rect ir = r.Shrink(WidgetDimensions::scaled.dropdownlist);
231 int y = ir.top;
232 int pos = this->vscroll->GetPosition();
233 for (const auto &item : this->list) {
234 int item_height = item->Height();
235
236 /* Skip items that are scrolled up */
237 if (--pos >= 0) continue;
238
239 if (y + item_height - 1 <= ir.bottom) {
240 Rect full{ir.left, y, ir.right, y + item_height - 1};
241
242 bool selected = (this->selected_result == item->result) && item->Selectable();
243 if (selected) GfxFillRect(full, PC_BLACK);
244
245 item->Draw(full, full.Shrink(WidgetDimensions::scaled.dropdowntext, RectPadding::zero), selected, colour);
246 }
247 y += item_height;
248 }
249 }
250
251 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
252 {
253 if (widget != WID_DM_ITEMS) return;
254 int item;
255 if (this->GetDropDownItem(item)) {
256 this->click_delay = 4;
257 this->selected_result = item;
258 this->SetDirty();
259 }
260 }
261
263 IntervalTimer<TimerWindow> scroll_interval = {std::chrono::milliseconds(30), [this](auto) {
264 if (this->scrolling == 0) return;
265
266 if (this->vscroll->UpdatePosition(this->scrolling)) this->SetDirty();
267
268 this->scrolling = 0;
269 }};
270
271 void OnMouseLoop() override
272 {
273 if (this->click_delay != 0 && --this->click_delay == 0) {
274 /* Close the dropdown, so it doesn't affect new window placement.
275 * Also mark it dirty in case the callback deals with the screen. (e.g. screenshots). */
276 if (!this->persist) this->Close();
277 this->parent->OnDropdownSelect(this->parent_button, this->selected_result);
278 return;
279 }
280
281 if (this->drag_mode) {
282 int item;
283
284 if (!_left_button_clicked) {
285 this->drag_mode = false;
286 if (!this->GetDropDownItem(item)) {
287 if (this->instant_close) this->Close();
288 return;
289 }
290 this->click_delay = 2;
291 } else {
292 if (_cursor.pos.y <= this->top + 2) {
293 /* Cursor is above the list, set scroll up */
294 this->scrolling = -1;
295 return;
296 } else if (_cursor.pos.y >= this->top + this->height - 2) {
297 /* Cursor is below list, set scroll down */
298 this->scrolling = 1;
299 return;
300 }
301
302 if (!this->GetDropDownItem(item)) return;
303 }
304
305 if (this->selected_result != item) {
306 this->selected_result = item;
307 this->SetDirty();
308 }
309 }
310 }
311
312 void ReplaceList(DropDownList &&list)
313 {
314 this->list = std::move(list);
315 this->UpdateSizeAndPosition();
316 this->ReInit(0, 0);
317 this->InitializePositionSize(this->position.x, this->position.y, this->nested_root->smallest_x, this->nested_root->smallest_y);
318 this->SetDirty();
319 }
320 };
321
322 void ReplaceDropDownList(Window *parent, DropDownList &&list)
323 {
324 DropdownWindow *ddw = dynamic_cast<DropdownWindow *>(parent->FindChildWindow(WC_DROPDOWN_MENU));
325 if (ddw != nullptr) ddw->ReplaceList(std::move(list));
326 }
327
333 Dimension GetDropDownListDimension(const DropDownList &list)
334 {
335 Dimension dim{};
336 for (const auto &item : list) {
337 dim.height += item->Height();
338 dim.width = std::max(dim.width, item->Width());
339 }
340 dim.width += WidgetDimensions::scaled.dropdowntext.Horizontal();
341 return dim;
342 }
343
356 void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, WidgetID button, Rect wi_rect, Colours wi_colour, bool instant_close, bool persist)
357 {
358 CloseWindowByClass(WC_DROPDOWN_MENU);
359 new DropdownWindow(w, std::move(list), selected, button, wi_rect, instant_close, wi_colour, persist);
360 }
361
374 void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, bool instant_close, bool persist)
375 {
376 /* Our parent's button widget is used to determine where to place the drop
377 * down list window. */
378 NWidgetCore *nwi = w->GetWidget<NWidgetCore>(button);
379 Rect wi_rect = nwi->GetCurrentRect();
380 Colours wi_colour = nwi->colour;
381
382 if ((nwi->type & WWT_MASK) == NWID_BUTTON_DROPDOWN) {
383 nwi->disp_flags |= ND_DROPDOWN_ACTIVE;
384 } else {
385 nwi->SetLowered(true);
386 }
387 nwi->SetDirty(w);
388
389 if (width != 0) {
390 if (_current_text_dir == TD_RTL) {
391 wi_rect.left = wi_rect.right + 1 - ScaleGUITrad(width);
392 } else {
393 wi_rect.right = wi_rect.left + ScaleGUITrad(width) - 1;
394 }
395 }
396
397 ShowDropDownListAt(w, std::move(list), selected, button, wi_rect, wi_colour, instant_close, persist);
398 }
399
411 void ShowDropDownMenu(Window *w, const StringID *strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width)
412 {
413 DropDownList list;
414
415 for (uint i = 0; strings[i] != INVALID_STRING_ID; i++) {
416 if (!HasBit(hidden_mask, i)) {
417 list.push_back(std::make_unique<DropDownListStringItem>(strings[i], i, HasBit(disabled_mask, i)));
418 }
419 }
420
421 if (!list.empty()) ShowDropDownList(w, std::move(list), selected, button, width);
422 }
SZSP_NONE
@ SZSP_NONE
Display plane with zero size in both directions (none filling and resizing).
Definition: widget_type.h:469
WID_DM_SCROLL
@ WID_DM_SCROLL
Scrollbar.
Definition: dropdown_widget.h:17
CloseWindowByClass
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition: window.cpp:1153
WID_DM_ITEMS
@ WID_DM_ITEMS
Panel showing the dropdown items.
Definition: dropdown_widget.h:15
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
WidgetDimensions::dropdownlist
RectPadding dropdownlist
Padding of complete drop down list.
Definition: window_gui.h:53
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:30
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:98
DropdownWindow::selected_result
int selected_result
Result value of the selected item in the list.
Definition: dropdown.cpp:46
DropdownWindow::persist
bool persist
Persist dropdown menu.
Definition: dropdown.cpp:50
Window::OnDropdownClose
virtual void OnDropdownClose(Point pt, WidgetID widget, int index, bool instant_close)
A dropdown window associated to this window has been closed.
Definition: window.cpp:288
Window::InitializePositionSize
void InitializePositionSize(int x, int y, int min_width, int min_height)
Set the position and smallest size of the window.
Definition: window.cpp:1403
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
NDB_DROPDOWN_CLOSED
@ NDB_DROPDOWN_CLOSED
Dropdown menu of the dropdown widget has closed.
Definition: widget_type.h:336
DropdownWindow::wi_rect
Rect wi_rect
Rect of the button that opened the dropdown.
Definition: dropdown.cpp:44
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:210
IntervalTimer< TimerWindow >
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:77
Window::Close
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition: window.cpp:1048
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1153
WDF_NO_FOCUS
@ WDF_NO_FOCUS
This window won't get focus/make any other window lose focus when click.
Definition: window_gui.h:199
RectPadding::Vertical
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Definition: geometry_type.hpp:69
DropdownWindow::items_dim
Dimension items_dim
Calculated cropped and padded dimension for the items widget.
Definition: dropdown.cpp:55
GetWidgetFromPos
WidgetID GetWidgetFromPos(const Window *w, int x, int y)
Returns the index for the widget located at the given position relative to the window.
Definition: widget.cpp:266
NWidgetCore::SetLowered
void SetLowered(bool lowered)
Lower or raise the widget.
Definition: widget_type.h:414
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:680
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:315
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:1040
Scrollbar::GetPosition
uint16_t GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:722
WindowDesc
High level window description.
Definition: window_gui.h:153
WidgetID
int WidgetID
Widget ID.
Definition: window_type.h:18
RectPadding::Horizontal
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
Definition: geometry_type.hpp:63
ScaleGUITrad
int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Definition: zoom_func.h:117
ND_DROPDOWN_ACTIVE
@ ND_DROPDOWN_ACTIVE
Bit value of the 'dropdown active' flag.
Definition: widget_type.h:344
Scrollbar::UpdatePosition
bool UpdatePosition(int difference, ScrollbarStepping unit=SS_SMALL)
Updates the position of the first visible element by the given amount.
Definition: widget_type.h:806
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:308
DropdownWindow::list
DropDownList list
List with dropdown menu items.
Definition: dropdown.cpp:45
DropdownWindow::FitAvailableHeight
void FitAvailableHeight(Dimension &desired, const Dimension &list, uint available_height)
Fit dropdown list into available height, rounding to average item size.
Definition: dropdown.cpp:122
Rect::Translate
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
Definition: geometry_type.hpp:174
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1246
NWidgetBase::type
WidgetType type
Type of the widget / nested widget.
Definition: widget_type.h:222
WF_WHITE_BORDER
@ WF_WHITE_BORDER
Window white border counter bit mask.
Definition: window_gui.h:230
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:941
DropdownWindow::GetDropDownItem
bool GetDropDownItem(int &value)
Find the dropdown item under the cursor.
Definition: dropdown.cpp:198
ShowDropDownListAt
void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, WidgetID button, Rect wi_rect, Colours wi_colour, bool instant_close, bool persist)
Show a drop down list.
Definition: dropdown.cpp:356
DropdownWindow::click_delay
byte click_delay
Timer to delay selection.
Definition: dropdown.cpp:47
dropdown_widget.h
dropdown_type.h
GetMainViewTop
int GetMainViewTop()
Return the top of the main view available for general use.
Definition: window.cpp:2067
Window::ReInit
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition: window.cpp:953
DropdownWindow
Drop-down menu window.
Definition: dropdown.cpp:42
Window::parent
Window * parent
Parent window.
Definition: window_gui.h:322
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1260
Window::left
int left
x position of left edge of the window
Definition: window_gui.h:303
Window::flags
WindowFlags flags
Window flags.
Definition: window_gui.h:294
WID_DM_SHOW_SCROLL
@ WID_DM_SHOW_SCROLL
Hide scrollbar if too few items.
Definition: dropdown_widget.h:16
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
Scrollbar::SetCapacity
void SetCapacity(size_t capacity)
Set the capacity of visible elements.
Definition: widget_type.h:776
ShowDropDownMenu
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width)
Show a dropdown menu window near a widget of the parent window.
Definition: dropdown.cpp:411
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:296
GfxFillRect
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:113
DropdownWindow::instant_close
bool instant_close
Close the window when the mouse button is raised.
Definition: dropdown.cpp:49
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:45
DropdownWindow::position
Point position
Position of the topleft corner of the window.
Definition: dropdown.cpp:52
DropdownWindow::scrolling
int scrolling
If non-zero, auto-scroll the item list (one time).
Definition: dropdown.cpp:51
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1724
WidgetDimensions::dropdowntext
RectPadding dropdowntext
Padding of drop down list item.
Definition: window_gui.h:52
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:86
NWidgetCore::disp_flags
NWidgetDisplay disp_flags
Flags that affect display and interaction with the widget.
Definition: widget_type.h:376
DropdownWindow::OnFocusLost
void OnFocusLost(bool closing) override
The window has lost focus.
Definition: dropdown.cpp:108
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:52
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition: widget_type.h:762
DropdownWindow::UpdateSizeAndPosition
void UpdateSizeAndPosition()
Update size and position of window to fit dropdown list into available space.
Definition: dropdown.cpp:137
NWidgetCore::colour
Colours colour
Colour of this widget.
Definition: widget_type.h:377
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1734
Window::OnDropdownSelect
virtual void OnDropdownSelect([[maybe_unused]] WidgetID widget, [[maybe_unused]] int index)
A dropdown option associated to this window has been selected.
Definition: window_gui.h:757
PC_BLACK
static const uint8_t PC_BLACK
Black palette colour.
Definition: palette_func.h:55
ShowDropDownList
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, bool instant_close, bool persist)
Show a drop down list.
Definition: dropdown.cpp:374
Window::top
int top
y position of top edge of the window
Definition: window_gui.h:304
NWidgetBase::SetDirty
virtual void SetDirty(const Window *w) const
Mark the widget as 'dirty' (in need of repaint).
Definition: widget.cpp:903
WDP_MANUAL
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition: window_gui.h:140
DropdownWindow::OnMouseLoop
void OnMouseLoop() override
Called for every mouse loop run, which is at least once per (game) tick.
Definition: dropdown.cpp:271
Window
Data structure for an opened window.
Definition: window_gui.h:267
GetDropDownListDimension
Dimension GetDropDownListDimension(const DropDownList &list)
Determine width and height required to fully display a DropDownList.
Definition: dropdown.cpp:333
Rect::Width
int Width() const
Get width of Rect.
Definition: geometry_type.hpp:85
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:82
NWidgetCore
Base class for a 'real' widget.
Definition: widget_type.h:356
DropdownWindow::parent_button
WidgetID parent_button
Parent widget number where the window is dropped from.
Definition: dropdown.cpp:43
GetMainViewBottom
int GetMainViewBottom()
Return the bottom of the main view available for general use.
Definition: window.cpp:2078
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:75
CursorVars::pos
Point pos
logical mouse position
Definition: gfx_type.h:117
WC_DROPDOWN_MENU
@ WC_DROPDOWN_MENU
Drop down menu; Window numbers:
Definition: window_type.h:156
CLRBITS
#define CLRBITS(x, y)
Clears several bits in a variable.
Definition: bitmath_func.hpp:166
_left_button_clicked
bool _left_button_clicked
Is left mouse button clicked?
Definition: gfx.cpp:41
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:56
DropdownWindow::scroll_interval
IntervalTimer< TimerWindow > scroll_interval
Rate limit how fast scrolling happens.
Definition: dropdown.cpp:263
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
DropdownWindow::DropdownWindow
DropdownWindow(Window *parent, DropDownList &&list, int selected, WidgetID button, const Rect wi_rect, bool instant_close, Colours wi_colour, bool persist)
Create a dropdown menu.
Definition: dropdown.cpp:68
NWID_BUTTON_DROPDOWN
@ NWID_BUTTON_DROPDOWN
Button with a drop-down.
Definition: widget_type.h:84
Window::FindChildWindow
Window * FindChildWindow(WindowClass wc=WC_INVALID) const
Find the Window whose parent pointer points to this window.
Definition: window.cpp:1023
Window::GetWidget
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition: window_gui.h:971
HasBit
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103