OpenTTD Source: src/dropdown.cpp Source File

OpenTTD Source 15.0-beta1

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 "dropdown_type.h"
12#include "dropdown_func.h"
13#include "dropdown_common_type.h"
14#include "strings_func.h"
15#include "timer/timer.h"
16#include "timer/timer_window.h"
17#include "window_gui.h"
18#include "window_func.h"
19#include "zoom_func.h"
20
21#include "widgets/dropdown_widget.h"
22
23#include "safeguards.h"
24
25std::unique_ptr<DropDownListItem> MakeDropDownListDividerItem()
26{
27 return std::make_unique<DropDownListDividerItem>(-1);
28}
29
30std::unique_ptr<DropDownListItem> MakeDropDownListStringItem(StringID str, int value, bool masked, bool shaded)
31{
32 return std::make_unique<DropDownListStringItem>(str, value, masked, shaded);
33}
34
35std::unique_ptr<DropDownListItem> MakeDropDownListStringItem(const std::string &str, int value, bool masked, bool shaded)
36{
37 return std::make_unique<DropDownListStringItem>(str, value, masked, shaded);
38}
39
40std::unique_ptr<DropDownListItem> MakeDropDownListIconItem(SpriteID sprite, PaletteID palette, StringID str, int value, bool masked, bool shaded)
41{
42 return std::make_unique<DropDownListIconItem>(sprite, palette, str, value, masked, shaded);
43}
44
45std::unique_ptr<DropDownListItem> MakeDropDownListIconItem(const Dimension &dim, SpriteID sprite, PaletteID palette, StringID str, int value, bool masked, bool shaded)
46{
47 return std::make_unique<DropDownListIconItem>(dim, sprite, palette, str, value, masked, shaded);
48}
49
50std::unique_ptr<DropDownListItem> MakeDropDownListCheckedItem(bool checked, StringID str, int value, bool masked, bool shaded)
51{
52 return std::make_unique<DropDownListCheckedItem>(checked, str, value, masked, shaded);
53}
54
55static constexpr NWidgetPart _nested_dropdown_menu_widgets[] = {
56 NWidget(NWID_HORIZONTAL),
57 NWidget(WWT_PANEL, COLOUR_END, WID_DM_ITEMS), SetScrollbar(WID_DM_SCROLL), EndContainer(),
58 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_DM_SHOW_SCROLL),
59 NWidget(NWID_VSCROLLBAR, COLOUR_END, WID_DM_SCROLL),
60 EndContainer(),
61 EndContainer(),
62};
63
64static WindowDesc _dropdown_desc(
65 WDP_MANUAL, nullptr, 0, 0,
66 WC_DROPDOWN_MENU, WC_NONE,
67 WDF_NO_FOCUS,
68 _nested_dropdown_menu_widgets
69);
70
72 struct DropdownWindow : Window {
73 WidgetID parent_button;
74 Rect wi_rect;
75 DropDownList list;
76 int selected_result;
77 uint8_t click_delay = 0;
78 bool drag_mode = true;
79 bool instant_close;
80 bool persist;
81 int scrolling = 0;
82 Point position;
83 Scrollbar *vscroll;
84
85 Dimension items_dim;
86
98 DropdownWindow(Window *parent, DropDownList &&list, int selected, WidgetID button, const Rect wi_rect, bool instant_close, Colours wi_colour, bool persist)
99 : Window(_dropdown_desc)
100 , parent_button(button)
101 , wi_rect(wi_rect)
102 , list(std::move(list))
103 , selected_result(selected)
104 , instant_close(instant_close)
105 , persist(persist)
106 {
107 assert(!this->list.empty());
108
109 this->parent = parent;
110
111 this->CreateNestedTree();
112
113 this->GetWidget<NWidgetCore>(WID_DM_ITEMS)->colour = wi_colour;
114 this->GetWidget<NWidgetCore>(WID_DM_SCROLL)->colour = wi_colour;
115 this->vscroll = this->GetScrollbar(WID_DM_SCROLL);
116 this->UpdateSizeAndPosition();
117
118 this->FinishInitNested(0);
119 CLRBITS(this->flags, WF_WHITE_BORDER);
120 }
121
122 void Close([[maybe_unused]] int data = 0) override
123 {
124 /* Finish closing the dropdown, so it doesn't affect new window placement.
125 * Also mark it dirty in case the callback deals with the screen. (e.g. screenshots). */
126 this->Window::Close();
127
128 Point pt = _cursor.pos;
129 pt.x -= this->parent->left;
130 pt.y -= this->parent->top;
131 this->parent->OnDropdownClose(pt, this->parent_button, this->selected_result, this->instant_close);
132
133 /* Set flag on parent widget to indicate that we have just closed. */
134 NWidgetCore *nwc = this->parent->GetWidget<NWidgetCore>(this->parent_button);
135 if (nwc != nullptr) SetBit(nwc->disp_flags, NDB_DROPDOWN_CLOSED);
136 }
137
138 void OnFocusLost(bool closing) override
139 {
140 if (!closing) {
141 this->instant_close = false;
142 this->Close();
143 }
144 }
145
152 void FitAvailableHeight(Dimension &desired, const Dimension &list, uint available_height)
153 {
154 if (desired.height < available_height) return;
155
156 /* If the dropdown doesn't fully fit, we a need a dropdown. */
157 uint avg_height = list.height / (uint)this->list.size();
158 uint rows = std::max((available_height - WidgetDimensions::scaled.dropdownlist.Vertical()) / avg_height, 1U);
159
160 desired.width = std::max(list.width, desired.width - NWidgetScrollbar::GetVerticalDimension().width);
161 desired.height = rows * avg_height + WidgetDimensions::scaled.dropdownlist.Vertical();
162 }
163
167 void UpdateSizeAndPosition()
168 {
169 Rect button_rect = this->wi_rect.Translate(this->parent->left, this->parent->top);
170
171 /* Get the dimensions required for the list. */
172 Dimension list_dim = GetDropDownListDimension(this->list);
173
174 /* Set up dimensions for the items widget. */
175 Dimension widget_dim = list_dim;
176 widget_dim.width += WidgetDimensions::scaled.dropdownlist.Horizontal();
177 widget_dim.height += WidgetDimensions::scaled.dropdownlist.Vertical();
178
179 /* Width should match at least the width of the parent widget. */
180 widget_dim.width = std::max<uint>(widget_dim.width, button_rect.Width());
181
182 /* Available height below (or above, if the dropdown is placed above the widget). */
183 uint available_height_below = std::max(GetMainViewBottom() - button_rect.bottom - 1, 0);
184 uint available_height_above = std::max(button_rect.top - 1 - GetMainViewTop(), 0);
185
186 /* Is it better to place the dropdown above the widget? */
187 if (widget_dim.height > available_height_below && available_height_above > available_height_below) {
188 FitAvailableHeight(widget_dim, list_dim, available_height_above);
189 this->position.y = button_rect.top - widget_dim.height;
190 } else {
191 FitAvailableHeight(widget_dim, list_dim, available_height_below);
192 this->position.y = button_rect.bottom + 1;
193 }
194
195 if (_current_text_dir == TD_RTL) {
196 /* In case the list is wider than the parent button, the list should be right aligned to the button and overflow to the left. */
197 this->position.x = button_rect.right + 1 - (int)(widget_dim.width + (list_dim.height > widget_dim.height ? NWidgetScrollbar::GetVerticalDimension().width : 0));
198 } else {
199 this->position.x = button_rect.left;
200 }
201
202 this->items_dim = widget_dim;
203 this->GetWidget<NWidgetStacked>(WID_DM_SHOW_SCROLL)->SetDisplayedPlane(list_dim.height > widget_dim.height ? 0 : SZSP_NONE);
204
205 /* Capacity is the average number of items visible */
206 this->vscroll->SetCapacity((widget_dim.height - WidgetDimensions::scaled.dropdownlist.Vertical()) * this->list.size() / list_dim.height);
207 this->vscroll->SetCount(this->list.size());
208
209 /* If the dropdown is positioned above the parent widget, start selection at the bottom. */
210 if (this->position.y < button_rect.top && list_dim.height > widget_dim.height) this->vscroll->UpdatePosition(INT_MAX);
211 }
212
213 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
214 {
215 if (widget == WID_DM_ITEMS) size = this->items_dim;
216 }
217
218 Point OnInitialPosition([[maybe_unused]] int16_t sm_width, [[maybe_unused]] int16_t sm_height, [[maybe_unused]] int window_number) override
219 {
220 return this->position;
221 }
222
228 bool GetDropDownItem(int &value)
229 {
230 if (GetWidgetFromPos(this, _cursor.pos.x - this->left, _cursor.pos.y - this->top) < 0) return false;
231
232 const Rect &r = this->GetWidget<NWidgetBase>(WID_DM_ITEMS)->GetCurrentRect().Shrink(WidgetDimensions::scaled.dropdownlist);
233 int y = _cursor.pos.y - this->top - r.top;
234 int pos = this->vscroll->GetPosition();
235
236 for (const auto &item : this->list) {
237 /* Skip items that are scrolled up */
238 if (--pos >= 0) continue;
239
240 int item_height = item->Height();
241
242 if (y < item_height) {
243 if (item->masked || !item->Selectable()) return false;
244 value = item->result;
245 return true;
246 }
247
248 y -= item_height;
249 }
250
251 return false;
252 }
253
254 void DrawWidget(const Rect &r, WidgetID widget) const override
255 {
256 if (widget != WID_DM_ITEMS) return;
257
258 Colours colour = this->GetWidget<NWidgetCore>(widget)->colour;
259
260 Rect ir = r.Shrink(WidgetDimensions::scaled.dropdownlist);
261 int y = ir.top;
262 int pos = this->vscroll->GetPosition();
263 for (const auto &item : this->list) {
264 int item_height = item->Height();
265
266 /* Skip items that are scrolled up */
267 if (--pos >= 0) continue;
268
269 if (y + item_height - 1 <= ir.bottom) {
270 Rect full{ir.left, y, ir.right, y + item_height - 1};
271
272 bool selected = (this->selected_result == item->result) && item->Selectable();
273 if (selected) GfxFillRect(full, PC_BLACK);
274
275 item->Draw(full, full.Shrink(WidgetDimensions::scaled.dropdowntext, RectPadding::zero), selected, colour);
276 }
277 y += item_height;
278 }
279 }
280
281 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
282 {
283 if (widget != WID_DM_ITEMS) return;
284 int item;
285 if (this->GetDropDownItem(item)) {
286 this->click_delay = 4;
287 this->selected_result = item;
288 this->SetDirty();
289 }
290 }
291
293 IntervalTimer<TimerWindow> scroll_interval = {std::chrono::milliseconds(30), [this](auto) {
294 if (this->scrolling == 0) return;
295
296 if (this->vscroll->UpdatePosition(this->scrolling)) this->SetDirty();
297
298 this->scrolling = 0;
299 }};
300
301 void OnMouseLoop() override
302 {
303 if (this->click_delay != 0 && --this->click_delay == 0) {
304 /* Close the dropdown, so it doesn't affect new window placement.
305 * Also mark it dirty in case the callback deals with the screen. (e.g. screenshots). */
306 if (!this->persist) this->Close();
307 this->parent->OnDropdownSelect(this->parent_button, this->selected_result);
308 return;
309 }
310
311 if (this->drag_mode) {
312 int item;
313
314 if (!_left_button_clicked) {
315 this->drag_mode = false;
316 if (!this->GetDropDownItem(item)) {
317 if (this->instant_close) this->Close();
318 return;
319 }
320 this->click_delay = 2;
321 } else {
322 if (_cursor.pos.y <= this->top + WidgetDimensions::scaled.dropdownlist.top) {
323 /* Cursor is above the list, set scroll up */
324 this->scrolling = -1;
325 return;
326 } else if (_cursor.pos.y >= this->top + this->height - WidgetDimensions::scaled.dropdownlist.bottom) {
327 /* Cursor is below list, set scroll down */
328 this->scrolling = 1;
329 return;
330 }
331
332 if (!this->GetDropDownItem(item)) return;
333 }
334
335 if (this->selected_result != item) {
336 this->selected_result = item;
337 this->SetDirty();
338 }
339 }
340 }
341
342 void ReplaceList(DropDownList &&list)
343 {
344 this->list = std::move(list);
345 this->UpdateSizeAndPosition();
346 this->ReInit(0, 0);
347 this->InitializePositionSize(this->position.x, this->position.y, this->nested_root->smallest_x, this->nested_root->smallest_y);
348 this->SetDirty();
349 }
350};
351
352void ReplaceDropDownList(Window *parent, DropDownList &&list)
353{
354 DropdownWindow *ddw = dynamic_cast<DropdownWindow *>(parent->FindChildWindow(WC_DROPDOWN_MENU));
355 if (ddw != nullptr) ddw->ReplaceList(std::move(list));
356}
357
363 Dimension GetDropDownListDimension(const DropDownList &list)
364{
365 Dimension dim{};
366 for (const auto &item : list) {
367 dim.height += item->Height();
368 dim.width = std::max(dim.width, item->Width());
369 }
370 dim.width += WidgetDimensions::scaled.dropdowntext.Horizontal();
371 return dim;
372}
373
386 void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, WidgetID button, Rect wi_rect, Colours wi_colour, bool instant_close, bool persist)
387{
388 CloseWindowByClass(WC_DROPDOWN_MENU);
389 new DropdownWindow(w, std::move(list), selected, button, wi_rect, instant_close, wi_colour, persist);
390}
391
404 void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, bool instant_close, bool persist)
405{
406 /* Our parent's button widget is used to determine where to place the drop
407 * down list window. */
408 NWidgetCore *nwi = w->GetWidget<NWidgetCore>(button);
409 Rect wi_rect = nwi->GetCurrentRect();
410 Colours wi_colour = nwi->colour;
411
412 if ((nwi->type & WWT_MASK) == NWID_BUTTON_DROPDOWN) {
413 nwi->disp_flags |= ND_DROPDOWN_ACTIVE;
414 } else {
415 nwi->SetLowered(true);
416 }
417 nwi->SetDirty(w);
418
419 if (width != 0) {
420 if (_current_text_dir == TD_RTL) {
421 wi_rect.left = wi_rect.right + 1 - ScaleGUITrad(width);
422 } else {
423 wi_rect.right = wi_rect.left + ScaleGUITrad(width) - 1;
424 }
425 }
426
427 ShowDropDownListAt(w, std::move(list), selected, button, wi_rect, wi_colour, instant_close, persist);
428}
429
441 void ShowDropDownMenu(Window *w, std::span<const StringID> strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width)
442{
443 DropDownList list;
444
445 uint i = 0;
446 for (auto string : strings) {
447 if (!HasBit(hidden_mask, i)) {
448 list.push_back(MakeDropDownListStringItem(string, i, HasBit(disabled_mask, i)));
449 }
450 ++i;
451 }
452
453 if (!list.empty()) ShowDropDownList(w, std::move(list), selected, button, width);
454}
HasBit
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition bitmath_func.hpp:103
CLRBITS
#define CLRBITS(x, y)
Clears several bits in a variable.
Definition bitmath_func.hpp:166
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition bitmath_func.hpp:121
IntervalTimer
An interval timer will fire every interval, and will continue to fire until it is deleted.
Definition timer.h:76
NWidgetBase::SetDirty
virtual void SetDirty(const Window *w) const
Mark the widget as 'dirty' (in need of repaint).
Definition widget.cpp:904
NWidgetBase::type
WidgetType type
Type of the widget / nested widget.
Definition widget_type.h:233
NWidgetCore
Base class for a 'real' widget.
Definition widget_type.h:371
NWidgetCore::disp_flags
NWidgetDisplay disp_flags
Flags that affect display and interaction with the widget.
Definition widget_type.h:391
NWidgetCore::colour
Colours colour
Colour of this widget.
Definition widget_type.h:392
NWidgetCore::SetLowered
void SetLowered(bool lowered)
Lower or raise the widget.
Definition widget_type.h:429
Scrollbar
Scrollbar data structure.
Definition widget_type.h:694
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition widget_type.h:780
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:824
Scrollbar::SetCapacity
void SetCapacity(size_t capacity)
Set the capacity of visible elements.
Definition widget_type.h:794
Scrollbar::GetPosition
size_type GetPosition() const
Gets the position of the first visible element in the list.
Definition widget_type.h:740
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:28
WidgetDimensions::dropdownlist
RectPadding dropdownlist
Padding of complete drop down list.
Definition window_gui.h:53
WidgetDimensions::dropdowntext
RectPadding dropdowntext
Padding of drop down list item.
Definition window_gui.h:52
ShowDropDownMenu
void ShowDropDownMenu(Window *w, std::span< 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:441
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:404
GetDropDownListDimension
Dimension GetDropDownListDimension(const DropDownList &list)
Determine width and height required to fully display a DropDownList.
Definition dropdown.cpp:363
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:386
dropdown_common_type.h
Common drop down list components.
dropdown_func.h
Functions related to the drop down widget.
dropdown_type.h
Types related to the drop down widget.
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:50
dropdown_widget.h
Types related to the dropdown widgets.
WID_DM_ITEMS
@ WID_DM_ITEMS
Panel showing the dropdown items.
Definition dropdown_widget.h:15
WID_DM_SCROLL
@ WID_DM_SCROLL
Scrollbar.
Definition dropdown_widget.h:17
WID_DM_SHOW_SCROLL
@ WID_DM_SHOW_SCROLL
Hide scrollbar if too few items.
Definition dropdown_widget.h:16
_left_button_clicked
bool _left_button_clicked
Is left mouse button clicked?
Definition gfx.cpp:42
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:114
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:18
PaletteID
uint32_t PaletteID
The number of the palette.
Definition gfx_type.h:19
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition widget_type.h:1295
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition widget_type.h:1320
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition widget_type.h:1191
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition window.cpp:940
PC_BLACK
static const uint8_t PC_BLACK
Black palette colour.
Definition palette_func.h:67
safeguards.h
A number of safeguards to prevent using unsafe methods.
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition strings.cpp:56
strings_func.h
Functions related to OTTD's strings.
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition strings_type.h:24
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:16
CursorVars::pos
Point pos
logical mouse position
Definition gfx_type.h:125
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition geometry_type.hpp:30
DropdownWindow
Drop-down menu window.
Definition dropdown.cpp:72
DropdownWindow::OnInitialPosition
Point OnInitialPosition(int16_t sm_width, int16_t sm_height, int window_number) override
Compute the initial position of the window.
Definition dropdown.cpp:218
DropdownWindow::parent_button
WidgetID parent_button
Parent widget number where the window is dropped from.
Definition dropdown.cpp:73
DropdownWindow::OnMouseLoop
void OnMouseLoop() override
Called for every mouse loop run, which is at least once per (game) tick.
Definition dropdown.cpp:301
DropdownWindow::persist
bool persist
Persist dropdown menu.
Definition dropdown.cpp:80
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:98
DropdownWindow::scroll_interval
IntervalTimer< TimerWindow > scroll_interval
Rate limit how fast scrolling happens.
Definition dropdown.cpp:293
DropdownWindow::UpdateSizeAndPosition
void UpdateSizeAndPosition()
Update size and position of window to fit dropdown list into available space.
Definition dropdown.cpp:167
DropdownWindow::wi_rect
Rect wi_rect
Rect of the button that opened the dropdown.
Definition dropdown.cpp:74
DropdownWindow::OnClick
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition dropdown.cpp:281
DropdownWindow::instant_close
bool instant_close
Close the window when the mouse button is raised.
Definition dropdown.cpp:79
DropdownWindow::items_dim
Dimension items_dim
Calculated cropped and padded dimension for the items widget.
Definition dropdown.cpp:85
DropdownWindow::UpdateWidgetSize
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
Definition dropdown.cpp:213
DropdownWindow::click_delay
uint8_t click_delay
Timer to delay selection.
Definition dropdown.cpp:77
DropdownWindow::selected_result
int selected_result
Result value of the selected item in the list.
Definition dropdown.cpp:76
DropdownWindow::Close
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
Definition dropdown.cpp:122
DropdownWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition dropdown.cpp:254
DropdownWindow::GetDropDownItem
bool GetDropDownItem(int &value)
Find the dropdown item under the cursor.
Definition dropdown.cpp:228
DropdownWindow::list
DropDownList list
List with dropdown menu items.
Definition dropdown.cpp:75
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:152
DropdownWindow::position
Point position
Position of the topleft corner of the window.
Definition dropdown.cpp:82
DropdownWindow::scrolling
int scrolling
If non-zero, auto-scroll the item list (one time).
Definition dropdown.cpp:81
DropdownWindow::OnFocusLost
void OnFocusLost(bool closing) override
The window has lost focus.
Definition dropdown.cpp:138
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition widget_type.h:1075
Point
Coordinates of a point in 2D.
Definition geometry_type.hpp:21
RectPadding::Horizontal
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
Definition geometry_type.hpp:63
RectPadding::Vertical
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Definition geometry_type.hpp:69
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition geometry_type.hpp:75
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition geometry_type.hpp:98
Rect::Translate
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
Definition geometry_type.hpp:174
WindowDesc
High level window description.
Definition window_gui.h:159
Window
Data structure for an opened window.
Definition window_gui.h:273
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:952
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:1047
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1733
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:1402
Window::parent
Window * parent
Parent window.
Definition window_gui.h:328
Window::resize
ResizeInfo resize
Resize information.
Definition window_gui.h:314
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1723
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:287
Window::OnDropdownSelect
virtual void OnDropdownSelect(WidgetID widget, int index)
A dropdown option associated to this window has been selected.
Definition window_gui.h:763
Window::left
int left
x position of left edge of the window
Definition window_gui.h:309
Window::FindChildWindow
Window * FindChildWindow(WindowClass wc=WC_INVALID) const
Find the Window whose parent pointer points to this window.
Definition window.cpp:1022
Window::top
int top
y position of top edge of the window
Definition window_gui.h:310
Window::GetWidget
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition window_gui.h:977
Window::flags
WindowFlags flags
Window flags.
Definition window_gui.h:300
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition window.cpp:314
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:302
timer.h
Definition of Interval and OneShot timers.
timer_window.h
Definition of the Window system.
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:268
ScaleGUITrad
static RectPadding ScaleGUITrad(const RectPadding &r)
Scale a RectPadding to GUI zoom level.
Definition widget.cpp:35
SZSP_NONE
@ SZSP_NONE
Display plane with zero size in both directions (none filling and resizing).
Definition widget_type.h:484
ND_DROPDOWN_ACTIVE
@ ND_DROPDOWN_ACTIVE
Bit value of the 'dropdown active' flag.
Definition widget_type.h:359
NDB_DROPDOWN_CLOSED
@ NDB_DROPDOWN_CLOSED
Dropdown menu of the dropdown widget has closed.
Definition widget_type.h:351
NWID_BUTTON_DROPDOWN
@ NWID_BUTTON_DROPDOWN
Button with a drop-down.
Definition widget_type.h:83
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:75
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:50
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition widget_type.h:85
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition widget_type.h:80
GetMainViewTop
int GetMainViewTop()
Return the top of the main view available for general use.
Definition window.cpp:2062
CloseWindowByClass
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition window.cpp:1152
GetMainViewBottom
int GetMainViewBottom()
Return the bottom of the main view available for general use.
Definition window.cpp:2073
window_func.h
Window functions not directly related to making/drawing windows.
window_gui.h
Functions, definitions and such used only by the GUI.
WF_WHITE_BORDER
@ WF_WHITE_BORDER
Window white border counter bit mask.
Definition window_gui.h:236
WDF_NO_FOCUS
@ WDF_NO_FOCUS
This window won't get focus/make any other window lose focus when click.
Definition window_gui.h:205
WDP_MANUAL
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition window_gui.h:146
WidgetID
int WidgetID
Widget ID.
Definition window_type.h:18
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:45
WC_DROPDOWN_MENU
@ WC_DROPDOWN_MENU
Drop down menu; Window numbers:
Definition window_type.h:156
zoom_func.h
Functions related to zooming.