OpenTTD

dropdown.cpp
Go to the documentation of this file.
1 /* $Id: dropdown.cpp 27820 2017-03-23 20:07:59Z peter1138 $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
9
12 #include "../stdafx.h"
13 #include "../window_gui.h"
14 #include "../string_func.h"
15 #include "../strings_func.h"
16 #include "../window_func.h"
17 #include "dropdown_type.h"
18
19 #include "dropdown_widget.h"
20
21 #include "../safeguards.h"
22
23
24 void DropDownListItem::Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const
25 {
26 int c1 = _colour_gradient[bg_colour][3];
27 int c2 = _colour_gradient[bg_colour][7];
28
29 int mid = top + this->Height(0) / 2;
30 GfxFillRect(left + 1, mid - 2, right - 1, mid - 2, c1);
31 GfxFillRect(left + 1, mid - 1, right - 1, mid - 1, c2);
32 }
33
34 uint DropDownListStringItem::Width() const
35 {
36 char buffer[512];
37 GetString(buffer, this->String(), lastof(buffer));
38 return GetStringBoundingBox(buffer).width;
39 }
40
41 void DropDownListStringItem::Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const
42 {
43 DrawString(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, this->String(), sel ? TC_WHITE : TC_BLACK);
44 }
45
53 /* static */ int DropDownListStringItem::NatSortFunc(const DropDownListItem * const *first, const DropDownListItem * const * second)
54 {
55 char buffer1[512], buffer2[512];
56 GetString(buffer1, static_cast<const DropDownListStringItem*>(*first)->String(), lastof(buffer1));
57 GetString(buffer2, static_cast<const DropDownListStringItem*>(*second)->String(), lastof(buffer2));
58 return strnatcmp(buffer1, buffer2);
59 }
60
61 StringID DropDownListParamStringItem::String() const
62 {
63 for (uint i = 0; i < lengthof(this->decode_params); i++) SetDParam(i, this->decode_params[i]);
64 return this->string;
65 }
66
67 StringID DropDownListCharStringItem::String() const
68 {
69 SetDParamStr(0, this->raw_string);
70 return this->string;
71 }
72
73 static const NWidgetPart _nested_dropdown_menu_widgets[] = {
74 NWidget(NWID_HORIZONTAL),
75 NWidget(WWT_PANEL, COLOUR_END, WID_DM_ITEMS), SetMinimalSize(1, 1), SetScrollbar(WID_DM_SCROLL), EndContainer(),
76 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_DM_SHOW_SCROLL),
77 NWidget(NWID_VSCROLLBAR, COLOUR_END, WID_DM_SCROLL),
78 EndContainer(),
79 EndContainer(),
80 };
81
82 static WindowDesc _dropdown_desc(
83 WDP_MANUAL, NULL, 0, 0,
84 WC_DROPDOWN_MENU, WC_NONE,
85 WDF_NO_FOCUS,
86 _nested_dropdown_menu_widgets, lengthof(_nested_dropdown_menu_widgets)
87 );
88
90 struct DropdownWindow : Window {
91 WindowClass parent_wnd_class;
92 WindowNumber parent_wnd_num;
93 int parent_button;
94 const DropDownList *list;
95 int selected_index;
96 byte click_delay;
97 bool drag_mode;
98 bool instant_close;
99 int scrolling;
100 Point position;
101 Scrollbar *vscroll;
102
116 DropdownWindow(Window *parent, const DropDownList *list, int selected, int button, bool instant_close, const Point &position, const Dimension &size, Colours wi_colour, bool scroll)
117 : Window(&_dropdown_desc)
118 {
119 assert(list->Length() > 0);
120
121 this->position = position;
122
123 this->CreateNestedTree();
124
125 this->vscroll = this->GetScrollbar(WID_DM_SCROLL);
126
127 uint items_width = size.width - (scroll ? NWidgetScrollbar::GetVerticalDimension().width : 0);
128 NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_DM_ITEMS);
129 nwi->SetMinimalSize(items_width, size.height + 4);
130 nwi->colour = wi_colour;
131
132 nwi = this->GetWidget<NWidgetCore>(WID_DM_SCROLL);
133 nwi->colour = wi_colour;
134
135 this->GetWidget<NWidgetStacked>(WID_DM_SHOW_SCROLL)->SetDisplayedPlane(scroll ? 0 : SZSP_NONE);
136
137 this->FinishInitNested(0);
138 CLRBITS(this->flags, WF_WHITE_BORDER);
139
140 /* Total length of list */
141 int list_height = 0;
142 for (const DropDownListItem * const *it = list->Begin(); it != list->End(); ++it) {
143 const DropDownListItem *item = *it;
144 list_height += item->Height(items_width);
145 }
146
147 /* Capacity is the average number of items visible */
148 this->vscroll->SetCapacity(size.height * (uint16)list->Length() / list_height);
149 this->vscroll->SetCount((uint16)list->Length());
150
151 this->parent_wnd_class = parent->window_class;
152 this->parent_wnd_num = parent->window_number;
153 this->parent_button = button;
154 this->list = list;
155 this->selected_index = selected;
156 this->click_delay = 0;
157 this->drag_mode = true;
158 this->instant_close = instant_close;
159 }
160
161 ~DropdownWindow()
162 {
163 /* Make the dropdown "invisible", so it doesn't affect new window placement.
164 * Also mark it dirty in case the callback deals with the screen. (e.g. screenshots). */
165 this->window_class = WC_INVALID;
166 this->SetDirty();
167
168 Window *w2 = FindWindowById(this->parent_wnd_class, this->parent_wnd_num);
169 if (w2 != NULL) {
170 Point pt = _cursor.pos;
171 pt.x -= w2->left;
172 pt.y -= w2->top;
173 w2->OnDropdownClose(pt, this->parent_button, this->selected_index, this->instant_close);
174 }
175 delete this->list;
176 }
177
178 virtual Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number)
179 {
180 return this->position;
181 }
182
188 bool GetDropDownItem(int &value)
189 {
190 if (GetWidgetFromPos(this, _cursor.pos.x - this->left, _cursor.pos.y - this->top) < 0) return false;
191
192 NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_DM_ITEMS);
193 int y = _cursor.pos.y - this->top - nwi->pos_y - 2;
194 int width = nwi->current_x - 4;
195 int pos = this->vscroll->GetPosition();
196
197 const DropDownList *list = this->list;
198
199 for (const DropDownListItem * const *it = list->Begin(); it != list->End(); ++it) {
200 /* Skip items that are scrolled up */
201 if (--pos >= 0) continue;
202
203 const DropDownListItem *item = *it;
204 int item_height = item->Height(width);
205
206 if (y < item_height) {
207 if (item->masked || !item->Selectable()) return false;
208 value = item->result;
209 return true;
210 }
211
212 y -= item_height;
213 }
214
215 return false;
216 }
217
218 virtual void DrawWidget(const Rect &r, int widget) const
219 {
220 if (widget != WID_DM_ITEMS) return;
221
222 Colours colour = this->GetWidget<NWidgetCore>(widget)->colour;
223
224 int y = r.top + 2;
225 int pos = this->vscroll->GetPosition();
226 for (const DropDownListItem * const *it = this->list->Begin(); it != this->list->End(); ++it) {
227 const DropDownListItem *item = *it;
228 int item_height = item->Height(r.right - r.left + 1);
229
230 /* Skip items that are scrolled up */
231 if (--pos >= 0) continue;
232
233 if (y + item_height < r.bottom) {
234 bool selected = (this->selected_index == item->result);
235 if (selected) GfxFillRect(r.left + 2, y, r.right - 1, y + item_height - 1, PC_BLACK);
236
237 item->Draw(r.left, r.right, y, y + item_height, selected, colour);
238
239 if (item->masked) {
240 GfxFillRect(r.left + 1, y, r.right - 1, y + item_height - 1, _colour_gradient[colour][5], FILLRECT_CHECKER);
241 }
242 }
243 y += item_height;
244 }
245 }
246
247 virtual void OnClick(Point pt, int widget, int click_count)
248 {
249 if (widget != WID_DM_ITEMS) return;
250 int item;
251 if (this->GetDropDownItem(item)) {
252 this->click_delay = 4;
253 this->selected_index = item;
254 this->SetDirty();
255 }
256 }
257
258 virtual void OnTick()
259 {
260 if (this->scrolling != 0) {
261 int pos = this->vscroll->GetPosition();
262
263 this->vscroll->UpdatePosition(this->scrolling);
264 this->scrolling = 0;
265
266 if (pos != this->vscroll->GetPosition()) {
267 this->SetDirty();
268 }
269 }
270 }
271
272 virtual void OnMouseLoop()
273 {
274 Window *w2 = FindWindowById(this->parent_wnd_class, this->parent_wnd_num);
275 if (w2 == NULL) {
276 delete this;
277 return;
278 }
279
280 if (this->click_delay != 0 && --this->click_delay == 0) {
281 /* Make the dropdown "invisible", so it doesn't affect new window placement.
282 * Also mark it dirty in case the callback deals with the screen. (e.g. screenshots). */
283 this->window_class = WC_INVALID;
284 this->SetDirty();
285
286 w2->OnDropdownSelect(this->parent_button, this->selected_index);
287 delete this;
288 return;
289 }
290
291 if (this->drag_mode) {
292 int item;
293
294 if (!_left_button_clicked) {
295 this->drag_mode = false;
296 if (!this->GetDropDownItem(item)) {
297 if (this->instant_close) delete this;
298 return;
299 }
300 this->click_delay = 2;
301 } else {
302 if (_cursor.pos.y <= this->top + 2) {
303 /* Cursor is above the list, set scroll up */
304 this->scrolling = -1;
305 return;
306 } else if (_cursor.pos.y >= this->top + this->height - 2) {
307 /* Cursor is below list, set scroll down */
308 this->scrolling = 1;
309 return;
310 }
311
312 if (!this->GetDropDownItem(item)) return;
313 }
314
315 if (this->selected_index != item) {
316 this->selected_index = item;
317 this->SetDirty();
318 }
319 }
320 }
321 };
322
337 void ShowDropDownListAt(Window *w, const DropDownList *list, int selected, int button, Rect wi_rect, Colours wi_colour, bool auto_width, bool instant_close)
338 {
339 DeleteWindowById(WC_DROPDOWN_MENU, 0);
340
341 /* The preferred position is just below the dropdown calling widget */
342 int top = w->top + wi_rect.bottom + 1;
343
344 /* The preferred width equals the calling widget */
345 uint width = wi_rect.right - wi_rect.left + 1;
346
347 /* Longest item in the list, if auto_width is enabled */
348 uint max_item_width = 0;
349
350 /* Total length of list */
351 int height = 0;
352
353 for (const DropDownListItem * const *it = list->Begin(); it != list->End(); ++it) {
354 const DropDownListItem *item = *it;
355 height += item->Height(width);
356 if (auto_width) max_item_width = max(max_item_width, item->Width() + 5);
357 }
358
359 /* Check if the status bar is visible, as we don't want to draw over it */
360 int screen_bottom = GetMainViewBottom();
361 bool scroll = false;
362
363 /* Check if the dropdown will fully fit below the widget */
364 if (top + height + 4 >= screen_bottom) {
365 /* If not, check if it will fit above the widget */
366 int screen_top = GetMainViewTop();
367 if (w->top + wi_rect.top > screen_top + height) {
368 top = w->top + wi_rect.top - height - 4;
369 } else {
370 /* If it doesn't fit above the widget, we need to enable a scrollbar... */
371 int avg_height = height / (int)list->Length();
372 scroll = true;
373
374 /* ... and choose whether to put the list above or below the widget. */
375 bool put_above = false;
376 int available_height = screen_bottom - w->top - wi_rect.bottom;
377 if (w->top + wi_rect.top - screen_top > available_height) {
378 // Put it above.
379 available_height = w->top + wi_rect.top - screen_top;
380 put_above = true;
381 }
382
383 /* Check at least there is space for one item. */
384 assert(available_height >= avg_height);
385
386 /* And lastly, fit the list... */
387 int rows = available_height / avg_height;
388 height = rows * avg_height;
389
390 /* Add space for the scroll bar if we automatically determined
391 * the width of the list. */
392 max_item_width += NWidgetScrollbar::GetVerticalDimension().width;
393
394 /* ... and set the top position if needed. */
395 if (put_above) {
396 top = w->top + wi_rect.top - height - 4;
397 }
398 }
399 }
400
401 if (auto_width) width = max(width, max_item_width);
402
403 Point dw_pos = { w->left + (_current_text_dir == TD_RTL ? wi_rect.right + 1 - (int)width : wi_rect.left), top};
404 Dimension dw_size = {width, (uint)height};
405 new DropdownWindow(w, list, selected, button, instant_close, dw_pos, dw_size, wi_colour, scroll);
406 }
407
421 void ShowDropDownList(Window *w, const DropDownList *list, int selected, int button, uint width, bool auto_width, bool instant_close)
422 {
423 /* Our parent's button widget is used to determine where to place the drop
424 * down list window. */
425 Rect wi_rect;
426 NWidgetCore *nwi = w->GetWidget<NWidgetCore>(button);
427 wi_rect.left = nwi->pos_x;
428 wi_rect.right = nwi->pos_x + nwi->current_x - 1;
429 wi_rect.top = nwi->pos_y;
430 wi_rect.bottom = nwi->pos_y + nwi->current_y - 1;
431 Colours wi_colour = nwi->colour;
432
433 if ((nwi->type & WWT_MASK) == NWID_BUTTON_DROPDOWN) {
434 nwi->disp_flags |= ND_DROPDOWN_ACTIVE;
435 } else {
436 w->LowerWidget(button);
437 }
438 w->SetWidgetDirty(button);
439
440 if (width != 0) {
441 if (_current_text_dir == TD_RTL) {
442 wi_rect.left = wi_rect.right + 1 - width;
443 } else {
444 wi_rect.right = wi_rect.left + width - 1;
445 }
446 }
447
448 ShowDropDownListAt(w, list, selected, button, wi_rect, wi_colour, auto_width, instant_close);
449 }
450
462 void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width)
463 {
464 DropDownList *list = new DropDownList();
465
466 for (uint i = 0; strings[i] != INVALID_STRING_ID; i++) {
467 if (!HasBit(hidden_mask, i)) {
468 *list->Append() = new DropDownListStringItem(strings[i], i, HasBit(disabled_mask, i));
469 }
470 }
471
472 /* No entries in the list? */
473 if (list->Length() == 0) {
474 delete list;
475 return;
476 }
477
478 ShowDropDownList(w, list, selected, button, width);
479 }
480
486 int HideDropDownMenu(Window *pw)
487 {
488 Window *w;
489 FOR_ALL_WINDOWS_FROM_BACK(w) {
490 if (w->window_class != WC_DROPDOWN_MENU) continue;
491
492 DropdownWindow *dw = dynamic_cast<DropdownWindow*>(w);
493 assert(dw != NULL);
494 if (pw->window_class == dw->parent_wnd_class &&
495 pw->window_number == dw->parent_wnd_num) {
496 int parent_button = dw->parent_button;
497 delete dw;
498 return parent_button;
499 }
500 }
501
502 return -1;
503 }
504
NWidgetCore::colour
Colours colour
Colour of this widget.
Definition: widget_type.h:303
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:462
dropdown_widget.h
Types related to the dropdown widgets.
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:112
CursorVars::pos
Point pos
logical mouse position
Definition: gfx_type.h:119
DropdownWindow::OnInitialPosition
virtual Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number)
Compute the initial position of the window.
Definition: dropdown.cpp:178
WindowDesc
High level window description.
Definition: window_gui.h:168
NWidgetResizeBase::SetMinimalSize
void SetMinimalSize(uint min_x, uint min_y)
Set minimal size of the widget.
Definition: widget.cpp:817
Window::left
int left
x position of left edge of the window
Definition: window_gui.h:312
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:589
DropdownWindow::instant_close
bool instant_close
Close the window when the mouse button is raised.
Definition: dropdown.cpp:98
Window::SetWidgetDirty
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:577
NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:75
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1105
_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:53
NWidgetBase::type
WidgetType type
Type of the widget / nested widget.
Definition: widget_type.h:163
ShowDropDownList
void ShowDropDownList(Window *w, const DropDownList *list, int selected, int button, uint width, bool auto_width, bool instant_close)
Show a drop down list.
Definition: dropdown.cpp:421
DropdownWindow::parent_wnd_class
WindowClass parent_wnd_class
Parent window class.
Definition: dropdown.cpp:91
DropdownWindow::selected_index
int selected_index
Index of the selected item in the list.
Definition: dropdown.cpp:95
Window::top
int top
y position of top edge of the window
Definition: window_gui.h:313
WID_DM_SCROLL
Scrollbar.
Definition: dropdown_widget.h:19
SmallVector::Begin
const T * Begin() const
Get the pointer to the first item (const)
Definition: smallvec_type.hpp:272
DropdownWindow::OnMouseLoop
virtual void OnMouseLoop()
Called for every mouse loop run, which is at least once per (game) tick.
Definition: dropdown.cpp:272
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: depend.cpp:50
WindowClass
WindowClass
Window classes.
Definition: window_type.h:39
CLRBITS
#define CLRBITS(x, y)
Clears several bits in a variable.
Definition: bitmath_func.hpp:168
WC_INVALID
Invalid window.
Definition: window_type.h:684
max
static T max(const T a, const T b)
Returns the maximum of two values.
Definition: math_func.hpp:26
DropDownListStringItem
Common string list item.
Definition: dropdown_type.h:41
SmallVector::End
const T * End() const
Get the pointer behind the last valid item (const)
Definition: smallvec_type.hpp:292
DropdownWindow::list
const DropDownList * list
List with dropdown menu items.
Definition: dropdown.cpp:94
HideDropDownMenu
int HideDropDownMenu(Window *pw)
Delete the drop-down menu from window pw.
Definition: dropdown.cpp:486
_left_button_clicked
bool _left_button_clicked
Is left mouse button clicked?
Definition: gfx.cpp:40
SmallVector::Append
T * Append(uint to_add=1)
Append an item and return it.
Definition: smallvec_type.hpp:134
Scrollbar::SetCapacity
void SetCapacity(int capacity)
Set the capacity of visible elements.
Definition: widget_type.h:686
Scrollbar::SetCount
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:670
GetMainViewBottom
int GetMainViewBottom()
Return the bottom of the main view available for general use.
Definition: window.cpp:2163
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:910
Window
Data structure for an opened window.
Definition: window_gui.h:271
DropdownWindow::click_delay
byte click_delay
Timer to delay selection.
Definition: dropdown.cpp:96
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:279
ND_DROPDOWN_ACTIVE
Bit value of the &#39;dropdown active&#39; flag.
Definition: widget_type.h:273
SmallVector::Length
uint Length() const
Get the number of items in the list.
Definition: smallvec_type.hpp:262
NWidgetBase::pos_y
uint pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:178
DropdownWindow::OnTick
virtual void OnTick()
Called once per (game) tick.
Definition: dropdown.cpp:258
NWidgetBase::current_y
uint current_y
Current vertical size (after resizing).
Definition: widget_type.h:175
AutoDeleteSmallVector
Simple vector template class, with automatic delete.
Definition: smallvec_type.hpp:401
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:947
DropDownListItem::masked
bool masked
Masked and unselectable item.
Definition: dropdown_type.h:27
GetMainViewTop
int GetMainViewTop()
Return the top of the main view available for general use.
Definition: window.cpp:2152
WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:50
Window::LowerWidget
void LowerWidget(byte widget_index)
Marks a widget as lowered.
Definition: window_gui.h:469
Window::OnDropdownSelect
virtual void OnDropdownSelect(int widget, int index)
A dropdown option associated to this window has been selected.
Definition: window_gui.h:705
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:162
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new &#39;real&#39; widget.
Definition: widget_type.h:1114
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:126
NWID_BUTTON_DROPDOWN
Button with a drop-down.
Definition: widget_type.h:82
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:499
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:42
NWidgetBase::pos_x
uint pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:177
SZSP_NONE
Display plane with zero size in both directions (none filling and resizing).
Definition: widget_type.h:390
dropdown_type.h
Types related to the drop down widget.
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
DropdownWindow::scrolling
int scrolling
If non-zero, auto-scroll the item list (one time).
Definition: dropdown.cpp:99
PC_BLACK
static const uint8 PC_BLACK
Black palette colour.
Definition: gfx_func.h:207
DropdownWindow
Drop-down menu window.
Definition: dropdown.cpp:90
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:699
FILLRECT_CHECKER
Draw only every second pixel, used for greying-out.
Definition: gfx_type.h:284
WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:40
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:1137
DropdownWindow::parent_wnd_num
WindowNumber parent_wnd_num
Parent window number.
Definition: dropdown.cpp:92
DropdownWindow::GetDropDownItem
bool GetDropDownItem(int &value)
Find the dropdown item under the cursor.
Definition: dropdown.cpp:188
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:247
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:569
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:714
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:52
DropDownListItem::result
int result
Result code to return to window on selection.
Definition: dropdown_type.h:26
WDF_NO_FOCUS
This window won&#39;t get focus/make any other window lose focus when click.
Definition: window_gui.h:212
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME, WWT_INSET, or WWT_PANEL).
Definition: widget_type.h:999
DropdownWindow::position
Point position
Position of the topleft corner of the window.
Definition: dropdown.cpp:100
NWidgetBase::current_x
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:174
DropdownWindow::parent_button
int parent_button
Parent widget number where the window is dropped from.
Definition: dropdown.cpp:93
DropdownWindow::DrawWidget
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
Definition: dropdown.cpp:218
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:28
DropdownWindow::DropdownWindow
DropdownWindow(Window *parent, const 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:116
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:19
WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:63
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:105
WindowNumber
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:695
Window::window_class
WindowClass window_class
Window class.
Definition: window_gui.h:306
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:40
NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:84
TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:26
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:307
WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition: window_gui.h:155
NWidgetCore::disp_flags
NWidgetDisplay disp_flags
Flags that affect display and interaction with the widget.
Definition: widget_type.h:302
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:280
NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:80
WID_DM_SHOW_SCROLL
Hide scrollbar if too few items.
Definition: dropdown_widget.h:18
Window::GetWidget
const NWID * GetWidget(uint widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition: window_gui.h:827
WF_WHITE_BORDER
Window white border counter bit mask.
Definition: window_gui.h:242
SetScrollbar
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1095
DropDownListItem
Base list item class from which others are derived.
Definition: dropdown_type.h:24
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:34
WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:62
ShowDropDownListAt
void ShowDropDownListAt(Window *w, const 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:337
WID_DM_ITEMS
Panel showing the dropdown items.
Definition: dropdown_widget.h:17
WC_DROPDOWN_MENU
Drop down menu; Window numbers:
Definition: window_type.h:151
DropDownList
AutoDeleteSmallVector< const DropDownListItem *, 4 > DropDownList
A drop down list is a collection of drop down list items.
Definition: dropdown_type.h:86
Scrollbar::GetPosition
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:631
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:201
NWidgetCore
Base class for a &#39;real&#39; widget.
Definition: widget_type.h:284
DropDownListStringItem::NatSortFunc
static int CDECL NatSortFunc(const DropDownListItem *const *first, const DropDownListItem *const *second)
Natural sorting comparator function for DropDownList::sort().
Definition: dropdown.cpp:53