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