OpenTTD Source 20250816-master-g94ba9b1454
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 "strings_func.h"
14#include "sound_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
22
23#include "table/strings.h"
24
26
27#include "safeguards.h"
28
29std::unique_ptr<DropDownListItem> MakeDropDownListDividerItem()
30{
31 return std::make_unique<DropDownListDividerItem>(-1);
32}
33
34std::unique_ptr<DropDownListItem> MakeDropDownListStringItem(StringID str, int value, bool masked, bool shaded)
35{
36 return MakeDropDownListStringItem(GetString(str), value, masked, shaded);
37}
38
39std::unique_ptr<DropDownListItem> MakeDropDownListStringItem(std::string &&str, int value, bool masked, bool shaded)
40{
41 return std::make_unique<DropDownListStringItem>(std::move(str), value, masked, shaded);
42}
43
44std::unique_ptr<DropDownListItem> MakeDropDownListIconItem(SpriteID sprite, PaletteID palette, StringID str, int value, bool masked, bool shaded)
45{
46 return std::make_unique<DropDownListIconItem>(sprite, palette, GetString(str), value, masked, shaded);
47}
48
49std::unique_ptr<DropDownListItem> MakeDropDownListIconItem(const Dimension &dim, SpriteID sprite, PaletteID palette, StringID str, int value, bool masked, bool shaded)
50{
51 return std::make_unique<DropDownListIconItem>(dim, sprite, palette, GetString(str), value, masked, shaded);
52}
53
54std::unique_ptr<DropDownListItem> MakeDropDownListCheckedItem(bool checked, StringID str, int value, bool masked, bool shaded, uint indent)
55{
56 return std::make_unique<DropDownListCheckedItem>(indent, checked, GetString(str), value, masked, shaded);
57}
58
59static constexpr NWidgetPart _nested_dropdown_menu_widgets[] = {
66};
67
68static WindowDesc _dropdown_desc(
69 WDP_MANUAL, {}, 0, 0,
72 _nested_dropdown_menu_widgets
73);
74
82 uint8_t click_delay = 0;
83 bool drag_mode = true;
84 bool instant_close = false;
85 bool persist = false;
86 int scrolling = 0;
88 Scrollbar *vscroll = nullptr;
89
91
103 DropdownWindow(Window *parent, DropDownList &&list, int selected, WidgetID button, const Rect wi_rect, bool instant_close, Colours wi_colour, bool persist)
104 : Window(_dropdown_desc)
105 , parent_button(button)
107 , list(std::move(list))
108 , selected_result(selected)
111 {
112 assert(!this->list.empty());
113
114 this->parent = parent;
115
116 this->CreateNestedTree();
117
118 this->GetWidget<NWidgetCore>(WID_DM_ITEMS)->colour = wi_colour;
119 this->GetWidget<NWidgetCore>(WID_DM_SCROLL)->colour = wi_colour;
120 this->vscroll = this->GetScrollbar(WID_DM_SCROLL);
121 this->UpdateSizeAndPosition();
122
123 this->FinishInitNested(0);
125 }
126
127 void Close([[maybe_unused]] int data = 0) override
128 {
129 /* Finish closing the dropdown, so it doesn't affect new window placement.
130 * Also mark it dirty in case the callback deals with the screen. (e.g. screenshots). */
131 this->Window::Close();
132
133 Point pt = _cursor.pos;
134 pt.x -= this->parent->left;
135 pt.y -= this->parent->top;
136 this->parent->OnDropdownClose(pt, this->parent_button, this->selected_result, this->selected_click_result, this->instant_close);
137
138 /* Set flag on parent widget to indicate that we have just closed. */
140 if (nwc != nullptr) nwc->disp_flags.Set(NWidgetDisplayFlag::DropdownClosed);
141 }
142
143 void OnFocusLost(bool closing) override
144 {
145 if (!closing) {
146 this->instant_close = false;
147 this->Close();
148 }
149 }
150
157 void FitAvailableHeight(Dimension &desired, const Dimension &list, uint available_height)
158 {
159 if (desired.height < available_height) return;
160
161 /* If the dropdown doesn't fully fit, we a need a dropdown. */
162 uint avg_height = list.height / (uint)this->list.size();
163 uint rows = std::max((available_height - WidgetDimensions::scaled.dropdownlist.Vertical()) / avg_height, 1U);
164
165 desired.width = std::max(list.width, desired.width - NWidgetScrollbar::GetVerticalDimension().width);
166 desired.height = rows * avg_height + WidgetDimensions::scaled.dropdownlist.Vertical();
167 }
168
173 {
174 Rect button_rect = this->wi_rect.Translate(this->parent->left, this->parent->top);
175
176 /* Get the dimensions required for the list. */
177 Dimension list_dim = GetDropDownListDimension(this->list);
178
179 /* Set up dimensions for the items widget. */
180 Dimension widget_dim = list_dim;
182 widget_dim.height += WidgetDimensions::scaled.dropdownlist.Vertical();
183
184 /* Width should match at least the width of the parent widget. */
185 widget_dim.width = std::max<uint>(widget_dim.width, button_rect.Width());
186
187 /* Available height below (or above, if the dropdown is placed above the widget). */
188 uint available_height_below = std::max(GetMainViewBottom() - button_rect.bottom - 1, 0);
189 uint available_height_above = std::max(button_rect.top - 1 - GetMainViewTop(), 0);
190
191 /* Is it better to place the dropdown above the widget? */
192 if (widget_dim.height > available_height_below && available_height_above > available_height_below) {
193 FitAvailableHeight(widget_dim, list_dim, available_height_above);
194 this->position.y = button_rect.top - widget_dim.height;
195 } else {
196 FitAvailableHeight(widget_dim, list_dim, available_height_below);
197 this->position.y = button_rect.bottom + 1;
198 }
199
200 if (_current_text_dir == TD_RTL) {
201 /* In case the list is wider than the parent button, the list should be right aligned to the button and overflow to the left. */
202 this->position.x = button_rect.right + 1 - (int)(widget_dim.width + (list_dim.height > widget_dim.height ? NWidgetScrollbar::GetVerticalDimension().width : 0));
203 } else {
204 this->position.x = button_rect.left;
205 }
206
207 this->items_dim = widget_dim;
208 this->GetWidget<NWidgetStacked>(WID_DM_SHOW_SCROLL)->SetDisplayedPlane(list_dim.height > widget_dim.height ? 0 : SZSP_NONE);
209
210 /* Capacity is the average number of items visible */
211 this->vscroll->SetCapacity((widget_dim.height - WidgetDimensions::scaled.dropdownlist.Vertical()) * this->list.size() / list_dim.height);
212 this->vscroll->SetCount(this->list.size());
213
214 /* If the dropdown is positioned above the parent widget, start selection at the bottom. */
215 if (this->position.y < button_rect.top && list_dim.height > widget_dim.height) this->vscroll->UpdatePosition(INT_MAX);
216 }
217
218 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
219 {
220 if (widget == WID_DM_ITEMS) size = this->items_dim;
221 }
222
223 Point OnInitialPosition([[maybe_unused]] int16_t sm_width, [[maybe_unused]] int16_t sm_height, [[maybe_unused]] int window_number) override
224 {
225 return this->position;
226 }
227
234 bool GetDropDownItem(int &result, int &click_result)
235 {
236 if (GetWidgetFromPos(this, _cursor.pos.x - this->left, _cursor.pos.y - this->top) < 0) return false;
237
238 const Rect &r = this->GetWidget<NWidgetBase>(WID_DM_ITEMS)->GetCurrentRect().Shrink(WidgetDimensions::scaled.dropdownlist).Shrink(WidgetDimensions::scaled.dropdowntext, RectPadding::zero);
239 int y = _cursor.pos.y - this->top - r.top;
240 int pos = this->vscroll->GetPosition();
241
242 for (const auto &item : this->list) {
243 /* Skip items that are scrolled up */
244 if (--pos >= 0) continue;
245
246 int item_height = item->Height();
247
248 if (y < item_height) {
249 if (item->masked || !item->Selectable()) return false;
250 result = item->result;
251 click_result = item->OnClick({r.left, 0, r.right, item_height - 1}, {_cursor.pos.x - this->left, y});
252 return true;
253 }
254
255 y -= item_height;
256 }
257
258 return false;
259 }
260
261 void DrawWidget(const Rect &r, WidgetID widget) const override
262 {
263 if (widget != WID_DM_ITEMS) return;
264
265 Colours colour = this->GetWidget<NWidgetCore>(widget)->colour;
266
267 Rect ir = r.Shrink(WidgetDimensions::scaled.dropdownlist);
268 int y = ir.top;
269 int pos = this->vscroll->GetPosition();
270 for (const auto &item : this->list) {
271 int item_height = item->Height();
272
273 /* Skip items that are scrolled up */
274 if (--pos >= 0) continue;
275
276 if (y + item_height - 1 <= ir.bottom) {
277 Rect full{ir.left, y, ir.right, y + item_height - 1};
278
279 bool selected = (this->selected_result == item->result) && item->Selectable();
280 if (selected) GfxFillRect(full, PC_BLACK);
281
282 item->Draw(full, full.Shrink(WidgetDimensions::scaled.dropdowntext, RectPadding::zero), selected, selected ? this->selected_click_result : -1, colour);
283 }
284 y += item_height;
285 }
286 }
287
288 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
289 {
290 if (widget != WID_DM_ITEMS) return;
291 int result, click_result;
292 if (this->GetDropDownItem(result, click_result)) {
293 this->click_delay = 4;
294 this->selected_result = result;
295 this->selected_click_result = click_result;
296 this->SetDirty();
297 }
298 }
299
301 const IntervalTimer<TimerWindow> scroll_interval = {std::chrono::milliseconds(30), [this](auto) {
302 if (this->scrolling == 0) return;
303
304 if (this->vscroll->UpdatePosition(this->scrolling)) this->SetDirty();
305
306 this->scrolling = 0;
307 }};
308
309 void OnMouseLoop() override
310 {
311 if (this->click_delay != 0 && --this->click_delay == 0) {
312 /* Close the dropdown, so it doesn't affect new window placement.
313 * Also mark it dirty in case the callback deals with the screen. (e.g. screenshots). */
314 if (!this->persist) this->Close();
315 this->parent->OnDropdownSelect(this->parent_button, this->selected_result, this->selected_click_result);
316 return;
317 }
318
319 if (this->drag_mode) {
320 int result, click_result;
321
323 this->drag_mode = false;
324 if (!this->GetDropDownItem(result, click_result)) {
325 if (this->instant_close) this->Close();
326 return;
327 }
328 this->click_delay = 2;
329 } else {
330 if (_cursor.pos.y <= this->top + WidgetDimensions::scaled.dropdownlist.top) {
331 /* Cursor is above the list, set scroll up */
332 this->scrolling = -1;
333 return;
334 } else if (_cursor.pos.y >= this->top + this->height - WidgetDimensions::scaled.dropdownlist.bottom) {
335 /* Cursor is below list, set scroll down */
336 this->scrolling = 1;
337 return;
338 }
339
340 if (!this->GetDropDownItem(result, click_result)) return;
341 }
342
343 if (this->selected_result != result || this->selected_click_result != click_result) {
344 this->selected_result = result;
345 this->selected_click_result = click_result;
346 this->SetDirty();
347 }
348 }
349 }
350
351 void ReplaceList(DropDownList &&list, std::optional<int> selected_result)
352 {
353 this->list = std::move(list);
354 if (selected_result.has_value()) this->selected_result = *selected_result;
355 this->UpdateSizeAndPosition();
356 this->ReInit(0, 0);
357 this->InitializePositionSize(this->position.x, this->position.y, this->nested_root->smallest_x, this->nested_root->smallest_y);
358 this->FindWindowPlacementAndResize(this->window_desc.GetDefaultWidth(), this->window_desc.GetDefaultHeight(), true);
359 this->SetDirty();
360 }
361};
362
363void ReplaceDropDownList(Window *parent, DropDownList &&list, std::optional<int> selected_result)
364{
365 DropdownWindow *ddw = dynamic_cast<DropdownWindow *>(parent->FindChildWindow(WC_DROPDOWN_MENU));
366 if (ddw != nullptr) ddw->ReplaceList(std::move(list), selected_result);
367}
368
375{
376 Dimension dim{};
377 for (const auto &item : list) {
378 dim.height += item->Height();
379 dim.width = std::max(dim.width, item->Width());
380 }
382 return dim;
383}
384
397void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, WidgetID button, Rect wi_rect, Colours wi_colour, bool instant_close, bool persist)
398{
400 new DropdownWindow(w, std::move(list), selected, button, wi_rect, instant_close, wi_colour, persist);
401}
402
415void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, bool instant_close, bool persist)
416{
417 /* Handle the beep of the player's click. */
418 SndClickBeep();
419
420 /* Our parent's button widget is used to determine where to place the drop
421 * down list window. */
422 NWidgetCore *nwi = w->GetWidget<NWidgetCore>(button);
423 Rect wi_rect = nwi->GetCurrentRect();
424 Colours wi_colour = nwi->colour;
425
426 if ((nwi->type & WWT_MASK) == NWID_BUTTON_DROPDOWN) {
428 } else {
429 nwi->SetLowered(true);
430 }
431 nwi->SetDirty(w);
432
433 if (width != 0) {
434 if (_current_text_dir == TD_RTL) {
435 wi_rect.left = wi_rect.right + 1 - ScaleGUITrad(width);
436 } else {
437 wi_rect.right = wi_rect.left + ScaleGUITrad(width) - 1;
438 }
439 }
440
441 ShowDropDownListAt(w, std::move(list), selected, button, wi_rect, wi_colour, instant_close, persist);
442}
443
455void ShowDropDownMenu(Window *w, std::span<const StringID> strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width)
456{
457 DropDownList list;
458
459 uint i = 0;
460 for (auto string : strings) {
461 if (!HasBit(hidden_mask, i)) {
462 list.push_back(MakeDropDownListStringItem(string, i, HasBit(disabled_mask, i)));
463 }
464 ++i;
465 }
466
467 if (!list.empty()) ShowDropDownList(w, std::move(list), selected, button, width);
468}
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
constexpr Timpl & Reset()
Reset all bits.
constexpr Timpl & Set()
Set all bits.
An interval timer will fire every interval, and will continue to fire until it is deleted.
Definition timer.h:76
virtual void SetDirty(const Window *w) const
Mark the widget as 'dirty' (in need of repaint).
Definition widget.cpp:942
WidgetType type
Type of the widget / nested widget.
Base class for a 'real' widget.
NWidgetDisplayFlags disp_flags
Flags that affect display and interaction with the widget.
Colours colour
Colour of this widget.
void SetLowered(bool lowered)
Lower or raise the widget.
Scrollbar data structure.
void SetCount(size_t num)
Sets the number of elements in the list.
bool UpdatePosition(int difference, ScrollbarStepping unit=SS_SMALL)
Updates the position of the first visible element by the given amount.
void SetCapacity(size_t capacity)
Set the capacity of visible elements.
size_type GetPosition() const
Gets the position of the first visible element in the list.
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:30
RectPadding dropdownlist
Padding of complete drop down list.
Definition window_gui.h:51
RectPadding dropdowntext
Padding of drop down list item.
Definition window_gui.h:50
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:455
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:415
Dimension GetDropDownListDimension(const DropDownList &list)
Determine width and height required to fully display a DropDownList.
Definition dropdown.cpp:374
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:397
Common drop down list components.
Functions related to the drop down widget.
Types related to the drop down widget.
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Types related to the dropdown widgets.
@ WID_DM_ITEMS
Panel showing the dropdown items.
@ WID_DM_SCROLL
Scrollbar.
@ WID_DM_SHOW_SCROLL
Hide scrollbar if too few items.
bool _left_button_clicked
Is left mouse button clicked?
Definition gfx.cpp:43
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:116
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
uint32_t PaletteID
The number of the palette.
Definition gfx_type.h:18
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition window.cpp:957
static constexpr PixelColour PC_BLACK
Black palette colour.
A number of safeguards to prevent using unsafe methods.
void SndClickBeep()
Play a beep sound for a click event if enabled in settings.
Definition sound.cpp:253
Functions related to sound.
Definition of base types and functions in a cross-platform compatible way.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:424
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition strings.cpp:56
Functions related to OTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
@ TD_RTL
Text is written right-to-left by default.
T y
Y coordinate.
T x
X coordinate.
Point pos
logical mouse position
Definition gfx_type.h:126
Dimensions (a width and height) of a rectangle in 2D.
Drop-down menu window.
Definition dropdown.cpp:76
Point OnInitialPosition(int16_t sm_width, int16_t sm_height, int window_number) override
Compute the initial position of the window.
Definition dropdown.cpp:223
WidgetID parent_button
Parent widget number where the window is dropped from.
Definition dropdown.cpp:77
void OnMouseLoop() override
Called for every mouse loop run, which is at least once per (game) tick.
Definition dropdown.cpp:309
bool persist
Persist dropdown menu.
Definition dropdown.cpp:85
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:103
void UpdateSizeAndPosition()
Update size and position of window to fit dropdown list into available space.
Definition dropdown.cpp:172
const IntervalTimer< TimerWindow > scroll_interval
Rate limit how fast scrolling happens.
Definition dropdown.cpp:301
Rect wi_rect
Rect of the button that opened the dropdown.
Definition dropdown.cpp:78
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:288
bool instant_close
Close the window when the mouse button is raised.
Definition dropdown.cpp:84
Dimension items_dim
Calculated cropped and padded dimension for the items widget.
Definition dropdown.cpp:90
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:218
uint8_t click_delay
Timer to delay selection.
Definition dropdown.cpp:82
int selected_result
Result value of the selected item in the list.
Definition dropdown.cpp:80
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
Definition dropdown.cpp:127
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition dropdown.cpp:261
DropDownList list
List with dropdown menu items.
Definition dropdown.cpp:79
int selected_click_result
Click result value, from the OnClick handler of the selected item.
Definition dropdown.cpp:81
void FitAvailableHeight(Dimension &desired, const Dimension &list, uint available_height)
Fit dropdown list into available height, rounding to average item size.
Definition dropdown.cpp:157
bool GetDropDownItem(int &result, int &click_result)
Find the dropdown item under the cursor.
Definition dropdown.cpp:234
Point position
Position of the topleft corner of the window.
Definition dropdown.cpp:87
int scrolling
If non-zero, auto-scroll the item list (one time).
Definition dropdown.cpp:86
void OnFocusLost(bool closing) override
The window has lost focus.
Definition dropdown.cpp:143
Partial widget specification to allow NWidgets to be written nested.
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Specification of a rectangle with absolute coordinates of all edges.
int Width() const
Get width of Rect.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
High level window description.
Definition window_gui.h:167
int16_t GetDefaultWidth() const
Determine default width of window.
Definition window.cpp:137
Data structure for an opened window.
Definition window_gui.h:273
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition window.cpp:969
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1093
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1780
void InitializePositionSize(int x, int y, int min_width, int min_height)
Set the position and smallest size of the window.
Definition window.cpp:1446
Window * parent
Parent window.
Definition window_gui.h:328
virtual void OnDropdownSelect(WidgetID widget, int index, int click_result)
A dropdown option associated to this window has been selected.
Definition window_gui.h:769
ResizeInfo resize
Resize information.
Definition window_gui.h:314
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1770
WindowDesc & window_desc
Window description.
Definition window_gui.h:299
virtual void FindWindowPlacementAndResize(int def_width, int def_height, bool allow_resize)
Resize window towards the default size.
Definition window.cpp:1465
virtual void OnDropdownClose(Point pt, WidgetID widget, int index, int click_result, bool instant_close)
A dropdown window associated to this window has been closed.
Definition window.cpp:286
int left
x position of left edge of the window
Definition window_gui.h:309
Window * FindChildWindow(WindowClass wc=WC_INVALID) const
Find the Window whose parent pointer points to this window.
Definition window.cpp:1038
int top
y position of top edge of the window
Definition window_gui.h:310
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition window_gui.h:982
WindowFlags flags
Window flags.
Definition window_gui.h:300
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition window.cpp:313
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:302
Definition of Interval and OneShot timers.
Definition of the Window system.
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:283
static RectPadding ScaleGUITrad(const RectPadding &r)
Scale a RectPadding to GUI zoom level.
Definition widget.cpp:49
@ NWID_BUTTON_DROPDOWN
Button with a drop-down.
Definition widget_type.h:75
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:67
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:40
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition widget_type.h:77
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition widget_type.h:72
@ DropdownClosed
Dropdown menu of the dropdown widget has closed.
@ DropdownActive
Dropdown menu of the button dropdown widget is active.
@ SZSP_NONE
Display plane with zero size in both directions (none filling and resizing).
int GetMainViewTop()
Return the top of the main view available for general use.
Definition window.cpp:2109
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition window.cpp:1196
int GetMainViewBottom()
Return the bottom of the main view available for general use.
Definition window.cpp:2120
Window functions not directly related to making/drawing windows.
Functions, definitions and such used only by the GUI.
@ NoFocus
This window won't get focus/make any other window lose focus when click.
@ WhiteBorder
Window white border counter bit mask.
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition window_gui.h:143
int WidgetID
Widget ID.
Definition window_type.h:20
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:47
@ WC_DROPDOWN_MENU
Drop down menu; Window numbers:
Functions related to zooming.