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

OpenTTD Source 1.11.0-RC1

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 "../guitimer_func.h"
16 #include "dropdown_type.h"
17
18 #include "dropdown_widget.h"
19
20 #include "../safeguards.h"
21
22
23 void DropDownListItem::Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const
24 {
25 int c1 = _colour_gradient[bg_colour][3];
26 int c2 = _colour_gradient[bg_colour][7];
27
28 int mid = top + this->Height(0) / 2;
29 GfxFillRect(left + 1, mid - 2, right - 1, mid - 2, c1);
30 GfxFillRect(left + 1, mid - 1, right - 1, mid - 1, c2);
31 }
32
33 uint DropDownListStringItem::Width() const
34 {
35 char buffer[512];
36 GetString(buffer, this->String(), lastof(buffer));
37 return GetStringBoundingBox(buffer).width;
38 }
39
40 void DropDownListStringItem::Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const
41 {
42 DrawString(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, this->String(), sel ? TC_WHITE : TC_BLACK);
43 }
44
52 /* static */ bool DropDownListStringItem::NatSortFunc(std::unique_ptr<const DropDownListItem> const &first, std::unique_ptr<const DropDownListItem> const &second)
53 {
54 char buffer1[512], buffer2[512];
55 GetString(buffer1, static_cast<const DropDownListStringItem*>(first.get())->String(), lastof(buffer1));
56 GetString(buffer2, static_cast<const DropDownListStringItem*>(second.get())->String(), lastof(buffer2));
57 return strnatcmp(buffer1, buffer2) < 0;
58 }
59
60 StringID DropDownListParamStringItem::String() const
61 {
62 for (uint i = 0; i < lengthof(this->decode_params); i++) SetDParam(i, this->decode_params[i]);
63 return this->string;
64 }
65
66 StringID DropDownListCharStringItem::String() const
67 {
68 SetDParamStr(0, this->raw_string.c_str());
69 return this->string;
70 }
71
72 DropDownListIconItem::DropDownListIconItem(SpriteID sprite, PaletteID pal, StringID string, int result, bool masked) : DropDownListParamStringItem(string, result, masked), sprite(sprite), pal(pal)
73 {
74 this->dim = GetSpriteSize(sprite);
75 if (this->dim.height < (uint)FONT_HEIGHT_NORMAL) {
76 this->sprite_y = (FONT_HEIGHT_NORMAL - dim.height) / 2;
77 this->text_y = 0;
78 } else {
79 this->sprite_y = 0;
80 this->text_y = (dim.height - FONT_HEIGHT_NORMAL) / 2;
81 }
82 }
83
84 uint DropDownListIconItem::Height(uint width) const
85 {
86 return std::max(this->dim.height, (uint)FONT_HEIGHT_NORMAL);
87 }
88
89 uint DropDownListIconItem::Width() const
90 {
91 return DropDownListStringItem::Width() + this->dim.width + WD_FRAMERECT_LEFT;
92 }
93
94 void DropDownListIconItem::Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const
95 {
96 bool rtl = _current_text_dir == TD_RTL;
97 DrawSprite(this->sprite, this->pal, rtl ? right - this->dim.width - WD_FRAMERECT_RIGHT : left + WD_FRAMERECT_LEFT, top + this->sprite_y);
98 DrawString(left + WD_FRAMERECT_LEFT + (rtl ? 0 : (this->dim.width + WD_FRAMERECT_LEFT)), right - WD_FRAMERECT_RIGHT - (rtl ? (this->dim.width + WD_FRAMERECT_RIGHT) : 0), top + this->text_y, this->String(), sel ? TC_WHITE : TC_BLACK);
99 }
100
101 void DropDownListIconItem::SetDimension(Dimension d)
102 {
103 this->dim = d;
104 }
105
106 static const NWidgetPart _nested_dropdown_menu_widgets[] = {
107 NWidget(NWID_HORIZONTAL),
108 NWidget(WWT_PANEL, COLOUR_END, WID_DM_ITEMS), SetMinimalSize(1, 1), SetScrollbar(WID_DM_SCROLL), EndContainer(),
109 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_DM_SHOW_SCROLL),
110 NWidget(NWID_VSCROLLBAR, COLOUR_END, WID_DM_SCROLL),
111 EndContainer(),
112 EndContainer(),
113 };
114
115 static WindowDesc _dropdown_desc(
116 WDP_MANUAL, nullptr, 0, 0,
117 WC_DROPDOWN_MENU, WC_NONE,
118 WDF_NO_FOCUS,
119 _nested_dropdown_menu_widgets, lengthof(_nested_dropdown_menu_widgets)
120 );
121
123 struct DropdownWindow : Window {
124 WindowClass parent_wnd_class;
125 WindowNumber parent_wnd_num;
126 int parent_button;
127 const DropDownList list;
128 int selected_index;
129 byte click_delay;
130 bool drag_mode;
131 bool instant_close;
132 int scrolling;
133 GUITimer scrolling_timer;
134 Point position;
135 Scrollbar *vscroll;
136
149 DropdownWindow(Window *parent, DropDownList &&list, int selected, int button, bool instant_close, const Point &position, const Dimension &size, Colours wi_colour, bool scroll)
150 : Window(&_dropdown_desc), list(std::move(list))
151 {
152 assert(this->list.size() > 0);
153
154 this->position = position;
155
156 this->CreateNestedTree();
157
158 this->vscroll = this->GetScrollbar(WID_DM_SCROLL);
159
160 uint items_width = size.width - (scroll ? NWidgetScrollbar::GetVerticalDimension().width : 0);
161 NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_DM_ITEMS);
162 nwi->SetMinimalSize(items_width, size.height + 4);
163 nwi->colour = wi_colour;
164
165 nwi = this->GetWidget<NWidgetCore>(WID_DM_SCROLL);
166 nwi->colour = wi_colour;
167
168 this->GetWidget<NWidgetStacked>(WID_DM_SHOW_SCROLL)->SetDisplayedPlane(scroll ? 0 : SZSP_NONE);
169
170 this->FinishInitNested(0);
171 CLRBITS(this->flags, WF_WHITE_BORDER);
172
173 /* Total length of list */
174 int list_height = 0;
175 for (const auto &item : this->list) {
176 list_height += item->Height(items_width);
177 }
178
179 /* Capacity is the average number of items visible */
180 this->vscroll->SetCapacity(size.height * (uint16)this->list.size() / list_height);
181 this->vscroll->SetCount((uint16)this->list.size());
182
183 this->parent_wnd_class = parent->window_class;
184 this->parent_wnd_num = parent->window_number;
185 this->parent_button = button;
186 this->selected_index = selected;
187 this->click_delay = 0;
188 this->drag_mode = true;
189 this->instant_close = instant_close;
190 this->scrolling_timer = GUITimer(MILLISECONDS_PER_TICK);
191 }
192
193 ~DropdownWindow()
194 {
195 /* Make the dropdown "invisible", so it doesn't affect new window placement.
196 * Also mark it dirty in case the callback deals with the screen. (e.g. screenshots). */
197 this->window_class = WC_INVALID;
198 this->SetDirty();
199
200 Window *w2 = FindWindowById(this->parent_wnd_class, this->parent_wnd_num);
201 if (w2 != nullptr) {
202 Point pt = _cursor.pos;
203 pt.x -= w2->left;
204 pt.y -= w2->top;
205 w2->OnDropdownClose(pt, this->parent_button, this->selected_index, this->instant_close);
206 }
207 }
208
209 virtual Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number)
210 {
211 return this->position;
212 }
213
219 bool GetDropDownItem(int &value)
220 {
221 if (GetWidgetFromPos(this, _cursor.pos.x - this->left, _cursor.pos.y - this->top) < 0) return false;
222
223 NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_DM_ITEMS);
224 int y = _cursor.pos.y - this->top - nwi->pos_y - 2;
225 int width = nwi->current_x - 4;
226 int pos = this->vscroll->GetPosition();
227
228 for (const auto &item : this->list) {
229 /* Skip items that are scrolled up */
230 if (--pos >= 0) continue;
231
232 int item_height = item->Height(width);
233
234 if (y < item_height) {
235 if (item->masked || !item->Selectable()) return false;
236 value = item->result;
237 return true;
238 }
239
240 y -= item_height;
241 }
242
243 return false;
244 }
245
246 virtual void DrawWidget(const Rect &r, int widget) const
247 {
248 if (widget != WID_DM_ITEMS) return;
249
250 Colours colour = this->GetWidget<NWidgetCore>(widget)->colour;
251
252 int y = r.top + 2;
253 int pos = this->vscroll->GetPosition();
254 for (const auto &item : this->list) {
255 int item_height = item->Height(r.right - r.left + 1);
256
257 /* Skip items that are scrolled up */
258 if (--pos >= 0) continue;
259
260 if (y + item_height < r.bottom) {
261 bool selected = (this->selected_index == item->result);
262 if (selected) GfxFillRect(r.left + 2, y, r.right - 1, y + item_height - 1, PC_BLACK);
263
264 item->Draw(r.left, r.right, y, y + item_height, selected, colour);
265
266 if (item->masked) {
267 GfxFillRect(r.left + 1, y, r.right - 1, y + item_height - 1, _colour_gradient[colour][5], FILLRECT_CHECKER);
268 }
269 }
270 y += item_height;
271 }
272 }
273
274 virtual void OnClick(Point pt, int widget, int click_count)
275 {
276 if (widget != WID_DM_ITEMS) return;
277 int item;
278 if (this->GetDropDownItem(item)) {
279 this->click_delay = 4;
280 this->selected_index = item;
281 this->SetDirty();
282 }
283 }
284
285 virtual void OnRealtimeTick(uint delta_ms)
286 {
287 if (!this->scrolling_timer.Elapsed(delta_ms)) return;
288 this->scrolling_timer.SetInterval(MILLISECONDS_PER_TICK);
289
290 if (this->scrolling != 0) {
291 int pos = this->vscroll->GetPosition();
292
293 this->vscroll->UpdatePosition(this->scrolling);
294 this->scrolling = 0;
295
296 if (pos != this->vscroll->GetPosition()) {
297 this->SetDirty();
298 }
299 }
300 }
301
302 virtual void OnMouseLoop()
303 {
304 Window *w2 = FindWindowById(this->parent_wnd_class, this->parent_wnd_num);
305 if (w2 == nullptr) {
306 delete this;
307 return;
308 }
309
310 if (this->click_delay != 0 && --this->click_delay == 0) {
311 /* Make the dropdown "invisible", so it doesn't affect new window placement.
312 * Also mark it dirty in case the callback deals with the screen. (e.g. screenshots). */
313 this->window_class = WC_INVALID;
314 this->SetDirty();
315
316 w2->OnDropdownSelect(this->parent_button, this->selected_index);
317 delete this;
318 return;
319 }
320
321 if (this->drag_mode) {
322 int item;
323
324 if (!_left_button_clicked) {
325 this->drag_mode = false;
326 if (!this->GetDropDownItem(item)) {
327 if (this->instant_close) delete this;
328 return;
329 }
330 this->click_delay = 2;
331 } else {
332 if (_cursor.pos.y <= this->top + 2) {
333 /* Cursor is above the list, set scroll up */
334 this->scrolling = -1;
335 return;
336 } else if (_cursor.pos.y >= this->top + this->height - 2) {
337 /* Cursor is below list, set scroll down */
338 this->scrolling = 1;
339 return;
340 }
341
342 if (!this->GetDropDownItem(item)) return;
343 }
344
345 if (this->selected_index != item) {
346 this->selected_index = item;
347 this->SetDirty();
348 }
349 }
350 }
351 };
352
366 void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button, Rect wi_rect, Colours wi_colour, bool auto_width, bool instant_close)
367 {
368 DeleteWindowById(WC_DROPDOWN_MENU, 0);
369
370 /* The preferred position is just below the dropdown calling widget */
371 int top = w->top + wi_rect.bottom + 1;
372
373 /* The preferred width equals the calling widget */
374 uint width = wi_rect.right - wi_rect.left + 1;
375
376 /* Longest item in the list, if auto_width is enabled */
377 uint max_item_width = 0;
378
379 /* Total height of list */
380 uint height = 0;
381
382 for (const auto &item : list) {
383 height += item->Height(width);
384 if (auto_width) max_item_width = std::max(max_item_width, item->Width() + 5);
385 }
386
387 /* Scrollbar needed? */
388 bool scroll = false;
389
390 /* Is it better to place the dropdown above the widget? */
391 bool above = false;
392
393 /* Available height below (or above, if the dropdown is placed above the widget). */
394 uint available_height = std::max(GetMainViewBottom() - top - 4, 0);
395
396 /* If the dropdown doesn't fully fit below the widget... */
397 if (height > available_height) {
398
399 uint available_height_above = std::max(w->top + wi_rect.top - GetMainViewTop() - 4, 0);
400
401 /* Put the dropdown above if there is more available space. */
402 if (available_height_above > available_height) {
403 above = true;
404 available_height = available_height_above;
405 }
406
407 /* If the dropdown doesn't fully fit, we need a dropdown. */
408 if (height > available_height) {
409 scroll = true;
410 uint avg_height = height / (uint)list.size();
411
412 /* Check at least there is space for one item. */
413 assert(available_height >= avg_height);
414
415 /* Fit the list. */
416 uint rows = available_height / avg_height;
417 height = rows * avg_height;
418
419 /* Add space for the scrollbar. */
420 max_item_width += NWidgetScrollbar::GetVerticalDimension().width;
421 }
422
423 /* Set the top position if needed. */
424 if (above) {
425 top = w->top + wi_rect.top - height - 4;
426 }
427 }
428
429 if (auto_width) width = std::max(width, max_item_width);
430
431 Point dw_pos = { w->left + (_current_text_dir == TD_RTL ? wi_rect.right + 1 - (int)width : wi_rect.left), top};
432 Dimension dw_size = {width, height};
433 DropdownWindow *dropdown = new DropdownWindow(w, std::move(list), selected, button, instant_close, dw_pos, dw_size, wi_colour, scroll);
434
435 /* The dropdown starts scrolling downwards when opening it towards
436 * the top and holding down the mouse button. It can be fooled by
437 * opening the dropdown scrolled to the very bottom. */
438 if (above && scroll) dropdown->vscroll->UpdatePosition(INT_MAX);
439 }
440
453 void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button, uint width, bool auto_width, bool instant_close)
454 {
455 /* Our parent's button widget is used to determine where to place the drop
456 * down list window. */
457 Rect wi_rect;
458 NWidgetCore *nwi = w->GetWidget<NWidgetCore>(button);
459 wi_rect.left = nwi->pos_x;
460 wi_rect.right = nwi->pos_x + nwi->current_x - 1;
461 wi_rect.top = nwi->pos_y;
462 wi_rect.bottom = nwi->pos_y + nwi->current_y - 1;
463 Colours wi_colour = nwi->colour;
464
465 if ((nwi->type & WWT_MASK) == NWID_BUTTON_DROPDOWN) {
466 nwi->disp_flags |= ND_DROPDOWN_ACTIVE;
467 } else {
468 w->LowerWidget(button);
469 }
470 w->SetWidgetDirty(button);
471
472 if (width != 0) {
473 if (_current_text_dir == TD_RTL) {
474 wi_rect.left = wi_rect.right + 1 - width;
475 } else {
476 wi_rect.right = wi_rect.left + width - 1;
477 }
478 }
479
480 ShowDropDownListAt(w, std::move(list), selected, button, wi_rect, wi_colour, auto_width, instant_close);
481 }
482
494 void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width)
495 {
496 DropDownList list;
497
498 for (uint i = 0; strings[i] != INVALID_STRING_ID; i++) {
499 if (!HasBit(hidden_mask, i)) {
500 list.emplace_back(new DropDownListStringItem(strings[i], i, HasBit(disabled_mask, i)));
501 }
502 }
503
504 if (!list.empty()) ShowDropDownList(w, std::move(list), selected, button, width);
505 }
506
512 int HideDropDownMenu(Window *pw)
513 {
514 Window *w;
515 FOR_ALL_WINDOWS_FROM_BACK(w) {
516 if (w->window_class != WC_DROPDOWN_MENU) continue;
517
518 DropdownWindow *dw = dynamic_cast<DropdownWindow*>(w);
519 assert(dw != nullptr);
520 if (pw->window_class == dw->parent_wnd_class &&
521 pw->window_number == dw->parent_wnd_num) {
522 int parent_button = dw->parent_button;
523 delete dw;
524 return parent_button;
525 }
526 }
527
528 return -1;
529 }
530
SZSP_NONE
@ SZSP_NONE
Display plane with zero size in both directions (none filling and resizing).
Definition: widget_type.h:389
DropdownWindow::DropdownWindow
DropdownWindow(Window *parent, DropDownList &&list, int selected, int button, bool instant_close, const Point &position, const Dimension &size, Colours wi_colour, bool scroll)
Create a dropdown menu.
Definition: dropdown.cpp:149
DropdownWindow::parent_button
int parent_button
Parent widget number where the window is dropped from.
Definition: dropdown.cpp:126
WC_INVALID
@ WC_INVALID
Invalid window.
Definition: window_type.h:700
DropDownListStringItem::string
StringID string
String ID of item.
Definition: dropdown_type.h:41
DropDownListParamStringItem
String list item with parameters.
Definition: dropdown_type.h:56
SetScrollbar
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1094
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:27
Window::GetScrollbar
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:309
DropdownWindow::selected_index
int selected_index
Index of the selected item in the list.
Definition: dropdown.cpp:128
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:100
Window::CreateNestedTree
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1832
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1133
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
Scrollbar::SetCount
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:669
WDF_NO_FOCUS
@ WDF_NO_FOCUS
This window won't get focus/make any other window lose focus when click.
Definition: window_gui.h:210
FILLRECT_CHECKER
@ FILLRECT_CHECKER
Draw only every second pixel, used for greying-out.
Definition: gfx_type.h:288
DrawString
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:640
Window::OnDropdownClose
virtual void OnDropdownClose(Point pt, int widget, int index, bool instant_close)
A dropdown window associated to this window has been closed.
Definition: window.cpp:282
WindowNumber
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:711
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:588
_colour_gradient
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: gfx.cpp:52
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:199
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:909
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:842
DropdownWindow::scrolling_timer
GUITimer scrolling_timer
Timer for auto-scroll of the item list.
Definition: dropdown.cpp:133
SpriteID
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
WindowDesc
High level window description.
Definition: window_gui.h:166
Window::GetWidget
const NWID * GetWidget(uint widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition: window_gui.h:844
ND_DROPDOWN_ACTIVE
@ ND_DROPDOWN_ACTIVE
Bit value of the 'dropdown active' flag.
Definition: widget_type.h:271
GUITimer
Definition: guitimer_func.h:13
NWidgetBase::type
WidgetType type
Type of the widget / nested widget.
Definition: widget_type.h:161
WF_WHITE_BORDER
@ WF_WHITE_BORDER
Window white border counter bit mask.
Definition: window_gui.h:240
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:984
WD_FRAMERECT_LEFT
@ WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:60
DropdownWindow::GetDropDownItem
bool GetDropDownItem(int &value)
Find the dropdown item under the cursor.
Definition: dropdown.cpp:219
DropdownWindow::OnMouseLoop
virtual void OnMouseLoop()
Called for every mouse loop run, which is at least once per (game) tick.
Definition: dropdown.cpp:302
WD_FRAMERECT_RIGHT
@ WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:61
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:124
ShowDropDownList
void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button, uint width, bool auto_width, bool instant_close)
Show a drop down list.
Definition: dropdown.cpp:453
GetWidgetFromPos
int 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:160
DropdownWindow::click_delay
byte click_delay
Timer to delay selection.
Definition: dropdown.cpp:129
dropdown_widget.h
dropdown_type.h
GetMainViewTop
int GetMainViewTop()
Return the top of the main view available for general use.
Definition: window.cpp:2189
Window::OnDropdownSelect
virtual void OnDropdownSelect(int widget, int index)
A dropdown option associated to this window has been selected.
Definition: window_gui.h:722
DropdownWindow::list
const DropDownList list
List with dropdown menu items.
Definition: dropdown.cpp:127
DropdownWindow
Drop-down menu window.
Definition: dropdown.cpp:123
Window::parent
Window * parent
Parent window.
Definition: window_gui.h:337
DropDownListStringItem
Common string list item.
Definition: dropdown_type.h:39
Window::left
int left
x position of left edge of the window
Definition: window_gui.h:317
DropdownWindow::OnClick
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
Definition: dropdown.cpp:274
Window::flags
WindowFlags flags
Window flags.
Definition: window_gui.h:310
WindowClass
WindowClass
Window classes.
Definition: window_type.h:37
DropdownWindow::parent_wnd_class
WindowClass parent_wnd_class
Parent window class.
Definition: dropdown.cpp:124
DrawSprite
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Definition: gfx.cpp:978
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
ShowDropDownMenu
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width)
Show a dropdown menu window near a widget of the parent window.
Definition: dropdown.cpp:494
PC_BLACK
static const uint8 PC_BLACK
Black palette colour.
Definition: gfx_func.h:206
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:312
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
DropdownWindow::instant_close
bool instant_close
Close the window when the mouse button is raised.
Definition: dropdown.cpp:131
NWidgetBase::current_y
uint current_y
Current vertical size (after resizing).
Definition: widget_type.h:173
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
DropdownWindow::position
Point position
Position of the topleft corner of the window.
Definition: dropdown.cpp:134
DropdownWindow::scrolling
int scrolling
If non-zero, auto-scroll the item list (one time).
Definition: dropdown.cpp:132
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:913
Scrollbar::SetCapacity
void SetCapacity(int capacity)
Set the capacity of visible elements.
Definition: widget_type.h:685
DropdownWindow::OnInitialPosition
virtual Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number)
Compute the initial position of the window.
Definition: dropdown.cpp:209
DropDownListParamStringItem::decode_params
uint64 decode_params[10]
Parameters of the string.
Definition: dropdown_type.h:58
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:998
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:82
DeleteWindowById
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
Definition: window.cpp:1165
WID_DM_SHOW_SCROLL
@ WID_DM_SHOW_SCROLL
Hide scrollbar if too few items.
Definition: dropdown_widget.h:16
NWidgetCore::disp_flags
NWidgetDisplay disp_flags
Flags that affect display and interaction with the widget.
Definition: widget_type.h:301
NWidgetBase::pos_x
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:175
HideDropDownMenu
int HideDropDownMenu(Window *pw)
Delete the drop-down menu from window pw.
Definition: dropdown.cpp:512
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:179
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1113
PaletteID
uint32 PaletteID
The number of the palette.
Definition: gfx_type.h:18
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:946
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:48
WID_DM_ITEMS
@ WID_DM_ITEMS
Panel showing the dropdown items.
Definition: dropdown_widget.h:15
Scrollbar::GetPosition
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:630
Window::window_class
WindowClass window_class
Window class.
Definition: window_gui.h:311
NWidgetCore::colour
Colours colour
Colour of this widget.
Definition: widget_type.h:302
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1848
Window::top
int top
y position of top edge of the window
Definition: window_gui.h:318
GUITimer::Elapsed
bool Elapsed(uint delta)
Test if a timer has elapsed.
Definition: guitimer_func.h:55
ShowDropDownListAt
void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button, Rect wi_rect, Colours wi_colour, bool auto_width, bool instant_close)
Show a drop down list.
Definition: dropdown.cpp:366
MILLISECONDS_PER_TICK
static const uint MILLISECONDS_PER_TICK
The number of milliseconds per game tick.
Definition: gfx_type.h:310
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:367
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:319
WDP_MANUAL
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition: window_gui.h:153
NWidgetBase::pos_y
int pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:176
strnatcmp
int strnatcmp(const char *s1, const char *s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
Definition: string.cpp:625
Scrollbar::UpdatePosition
void UpdatePosition(int difference, ScrollbarStepping unit=SS_SMALL)
Updates the position of the first visible element by the given amount.
Definition: widget_type.h:713
Window
Data structure for an opened window.
Definition: window_gui.h:276
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:78
NWidgetCore
Base class for a 'real' widget.
Definition: widget_type.h:282
DropdownWindow::parent_wnd_num
WindowNumber parent_wnd_num
Parent window number.
Definition: dropdown.cpp:125
Window::SetWidgetDirty
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:597
GetMainViewBottom
int GetMainViewBottom()
Return the bottom of the main view available for general use.
Definition: window.cpp:2200
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:47
Window::LowerWidget
void LowerWidget(byte widget_index)
Marks a widget as lowered.
Definition: window_gui.h:474
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:149
CLRBITS
#define CLRBITS(x, y)
Clears several bits in a variable.
Definition: bitmath_func.hpp:166
NWidgetBase::current_x
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:172
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:383
DropdownWindow::DrawWidget
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
Definition: dropdown.cpp:246
NWidgetResizeBase::SetMinimalSize
void SetMinimalSize(uint min_x, uint min_y)
Set minimal size of the widget.
Definition: widget.cpp:815
_left_button_clicked
bool _left_button_clicked
Is left mouse button clicked?
Definition: gfx.cpp:39
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:48
WID_DM_SCROLL
@ WID_DM_SCROLL
Scrollbar.
Definition: dropdown_widget.h:17
SetDParamStr
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:286
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
NWID_BUTTON_DROPDOWN
@ NWID_BUTTON_DROPDOWN
Button with a drop-down.
Definition: widget_type.h:80
DropdownWindow::OnRealtimeTick
virtual void OnRealtimeTick(uint delta_ms)
Called periodically.
Definition: dropdown.cpp:285
DropDownListStringItem::NatSortFunc
static bool NatSortFunc(std::unique_ptr< const DropDownListItem > const &first, std::unique_ptr< const DropDownListItem > const &second)
Natural sorting comparator function for DropDownList::sort().
Definition: dropdown.cpp:52