OpenTTD Source  1.11.2
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  this->sprite_y = dim.height;
76 }
77 
78 uint DropDownListIconItem::Height(uint width) const
79 {
80  return std::max(this->dim.height, (uint)FONT_HEIGHT_NORMAL);
81 }
82 
83 uint DropDownListIconItem::Width() const
84 {
85  return DropDownListStringItem::Width() + this->dim.width + WD_FRAMERECT_LEFT;
86 }
87 
88 void DropDownListIconItem::Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const
89 {
90  bool rtl = _current_text_dir == TD_RTL;
91  DrawSprite(this->sprite, this->pal, rtl ? right - this->dim.width - WD_FRAMERECT_RIGHT : left + WD_FRAMERECT_LEFT, CenterBounds(top, bottom, this->sprite_y));
92  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), CenterBounds(top, bottom, FONT_HEIGHT_NORMAL), this->String(), sel ? TC_WHITE : TC_BLACK);
93 }
94 
95 void DropDownListIconItem::SetDimension(Dimension d)
96 {
97  this->dim = d;
98 }
99 
100 static const NWidgetPart _nested_dropdown_menu_widgets[] = {
103  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_DM_SHOW_SCROLL),
104  NWidget(NWID_VSCROLLBAR, COLOUR_END, WID_DM_SCROLL),
105  EndContainer(),
106  EndContainer(),
107 };
108 
109 static WindowDesc _dropdown_desc(
110  WDP_MANUAL, nullptr, 0, 0,
112  WDF_NO_FOCUS,
113  _nested_dropdown_menu_widgets, lengthof(_nested_dropdown_menu_widgets)
114 );
115 
123  byte click_delay;
124  bool drag_mode;
126  int scrolling;
129  Scrollbar *vscroll;
130 
143  DropdownWindow(Window *parent, DropDownList &&list, int selected, int button, bool instant_close, const Point &position, const Dimension &size, Colours wi_colour, bool scroll)
144  : Window(&_dropdown_desc), list(std::move(list))
145  {
146  assert(this->list.size() > 0);
147 
148  this->position = position;
149 
150  this->CreateNestedTree();
151 
152  this->vscroll = this->GetScrollbar(WID_DM_SCROLL);
153 
154  uint items_width = size.width - (scroll ? NWidgetScrollbar::GetVerticalDimension().width : 0);
155  NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_DM_ITEMS);
156  nwi->SetMinimalSize(items_width, size.height + 4);
157  nwi->colour = wi_colour;
158 
159  nwi = this->GetWidget<NWidgetCore>(WID_DM_SCROLL);
160  nwi->colour = wi_colour;
161 
162  this->GetWidget<NWidgetStacked>(WID_DM_SHOW_SCROLL)->SetDisplayedPlane(scroll ? 0 : SZSP_NONE);
163 
164  this->FinishInitNested(0);
165  CLRBITS(this->flags, WF_WHITE_BORDER);
166 
167  /* Total length of list */
168  int list_height = 0;
169  for (const auto &item : this->list) {
170  list_height += item->Height(items_width);
171  }
172 
173  /* Capacity is the average number of items visible */
174  this->vscroll->SetCapacity(size.height * (uint16)this->list.size() / list_height);
175  this->vscroll->SetCount((uint16)this->list.size());
176 
177  this->parent_wnd_class = parent->window_class;
178  this->parent_wnd_num = parent->window_number;
179  this->parent_button = button;
180  this->selected_index = selected;
181  this->click_delay = 0;
182  this->drag_mode = true;
183  this->instant_close = instant_close;
184  this->scrolling_timer = GUITimer(MILLISECONDS_PER_TICK);
185  }
186 
187  ~DropdownWindow()
188  {
189  /* Make the dropdown "invisible", so it doesn't affect new window placement.
190  * Also mark it dirty in case the callback deals with the screen. (e.g. screenshots). */
191  this->window_class = WC_INVALID;
192  this->SetDirty();
193 
194  Window *w2 = FindWindowById(this->parent_wnd_class, this->parent_wnd_num);
195  if (w2 != nullptr) {
196  Point pt = _cursor.pos;
197  pt.x -= w2->left;
198  pt.y -= w2->top;
199  w2->OnDropdownClose(pt, this->parent_button, this->selected_index, this->instant_close);
200  }
201  }
202 
203  virtual Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number)
204  {
205  return this->position;
206  }
207 
213  bool GetDropDownItem(int &value)
214  {
215  if (GetWidgetFromPos(this, _cursor.pos.x - this->left, _cursor.pos.y - this->top) < 0) return false;
216 
217  NWidgetBase *nwi = this->GetWidget<NWidgetBase>(WID_DM_ITEMS);
218  int y = _cursor.pos.y - this->top - nwi->pos_y - 2;
219  int width = nwi->current_x - 4;
220  int pos = this->vscroll->GetPosition();
221 
222  for (const auto &item : this->list) {
223  /* Skip items that are scrolled up */
224  if (--pos >= 0) continue;
225 
226  int item_height = item->Height(width);
227 
228  if (y < item_height) {
229  if (item->masked || !item->Selectable()) return false;
230  value = item->result;
231  return true;
232  }
233 
234  y -= item_height;
235  }
236 
237  return false;
238  }
239 
240  virtual void DrawWidget(const Rect &r, int widget) const
241  {
242  if (widget != WID_DM_ITEMS) return;
243 
244  Colours colour = this->GetWidget<NWidgetCore>(widget)->colour;
245 
246  int y = r.top + 2;
247  int pos = this->vscroll->GetPosition();
248  for (const auto &item : this->list) {
249  int item_height = item->Height(r.right - r.left + 1);
250 
251  /* Skip items that are scrolled up */
252  if (--pos >= 0) continue;
253 
254  if (y + item_height < r.bottom) {
255  bool selected = (this->selected_index == item->result);
256  if (selected) GfxFillRect(r.left + 2, y, r.right - 1, y + item_height - 1, PC_BLACK);
257 
258  item->Draw(r.left, r.right, y, y + item_height, selected, colour);
259 
260  if (item->masked) {
261  GfxFillRect(r.left + 1, y, r.right - 1, y + item_height - 1, _colour_gradient[colour][5], FILLRECT_CHECKER);
262  }
263  }
264  y += item_height;
265  }
266  }
267 
268  virtual void OnClick(Point pt, int widget, int click_count)
269  {
270  if (widget != WID_DM_ITEMS) return;
271  int item;
272  if (this->GetDropDownItem(item)) {
273  this->click_delay = 4;
274  this->selected_index = item;
275  this->SetDirty();
276  }
277  }
278 
279  virtual void OnRealtimeTick(uint delta_ms)
280  {
281  if (!this->scrolling_timer.Elapsed(delta_ms)) return;
282  this->scrolling_timer.SetInterval(MILLISECONDS_PER_TICK);
283 
284  if (this->scrolling != 0) {
285  int pos = this->vscroll->GetPosition();
286 
287  this->vscroll->UpdatePosition(this->scrolling);
288  this->scrolling = 0;
289 
290  if (pos != this->vscroll->GetPosition()) {
291  this->SetDirty();
292  }
293  }
294  }
295 
296  virtual void OnMouseLoop()
297  {
298  Window *w2 = FindWindowById(this->parent_wnd_class, this->parent_wnd_num);
299  if (w2 == nullptr) {
300  delete this;
301  return;
302  }
303 
304  if (this->click_delay != 0 && --this->click_delay == 0) {
305  /* Make the dropdown "invisible", so it doesn't affect new window placement.
306  * Also mark it dirty in case the callback deals with the screen. (e.g. screenshots). */
307  this->window_class = WC_INVALID;
308  this->SetDirty();
309 
310  w2->OnDropdownSelect(this->parent_button, this->selected_index);
311  delete this;
312  return;
313  }
314 
315  if (this->drag_mode) {
316  int item;
317 
318  if (!_left_button_clicked) {
319  this->drag_mode = false;
320  if (!this->GetDropDownItem(item)) {
321  if (this->instant_close) delete this;
322  return;
323  }
324  this->click_delay = 2;
325  } else {
326  if (_cursor.pos.y <= this->top + 2) {
327  /* Cursor is above the list, set scroll up */
328  this->scrolling = -1;
329  return;
330  } else if (_cursor.pos.y >= this->top + this->height - 2) {
331  /* Cursor is below list, set scroll down */
332  this->scrolling = 1;
333  return;
334  }
335 
336  if (!this->GetDropDownItem(item)) return;
337  }
338 
339  if (this->selected_index != item) {
340  this->selected_index = item;
341  this->SetDirty();
342  }
343  }
344  }
345 };
346 
360 void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button, Rect wi_rect, Colours wi_colour, bool auto_width, bool instant_close)
361 {
363 
364  /* The preferred position is just below the dropdown calling widget */
365  int top = w->top + wi_rect.bottom + 1;
366 
367  /* The preferred width equals the calling widget */
368  uint width = wi_rect.right - wi_rect.left + 1;
369 
370  /* Longest item in the list, if auto_width is enabled */
371  uint max_item_width = 0;
372 
373  /* Total height of list */
374  uint height = 0;
375 
376  for (const auto &item : list) {
377  height += item->Height(width);
378  if (auto_width) max_item_width = std::max(max_item_width, item->Width() + 5);
379  }
380 
381  /* Scrollbar needed? */
382  bool scroll = false;
383 
384  /* Is it better to place the dropdown above the widget? */
385  bool above = false;
386 
387  /* Available height below (or above, if the dropdown is placed above the widget). */
388  uint available_height = std::max(GetMainViewBottom() - top - 4, 0);
389 
390  /* If the dropdown doesn't fully fit below the widget... */
391  if (height > available_height) {
392 
393  uint available_height_above = std::max(w->top + wi_rect.top - GetMainViewTop() - 4, 0);
394 
395  /* Put the dropdown above if there is more available space. */
396  if (available_height_above > available_height) {
397  above = true;
398  available_height = available_height_above;
399  }
400 
401  /* If the dropdown doesn't fully fit, we need a dropdown. */
402  if (height > available_height) {
403  scroll = true;
404  uint avg_height = height / (uint)list.size();
405 
406  /* Check at least there is space for one item. */
407  assert(available_height >= avg_height);
408 
409  /* Fit the list. */
410  uint rows = available_height / avg_height;
411  height = rows * avg_height;
412 
413  /* Add space for the scrollbar. */
414  max_item_width += NWidgetScrollbar::GetVerticalDimension().width;
415  }
416 
417  /* Set the top position if needed. */
418  if (above) {
419  top = w->top + wi_rect.top - height - 4;
420  }
421  }
422 
423  if (auto_width) width = std::max(width, max_item_width);
424 
425  Point dw_pos = { w->left + (_current_text_dir == TD_RTL ? wi_rect.right + 1 - (int)width : wi_rect.left), top};
426  Dimension dw_size = {width, height};
427  DropdownWindow *dropdown = new DropdownWindow(w, std::move(list), selected, button, instant_close, dw_pos, dw_size, wi_colour, scroll);
428 
429  /* The dropdown starts scrolling downwards when opening it towards
430  * the top and holding down the mouse button. It can be fooled by
431  * opening the dropdown scrolled to the very bottom. */
432  if (above && scroll) dropdown->vscroll->UpdatePosition(INT_MAX);
433 }
434 
447 void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button, uint width, bool auto_width, bool instant_close)
448 {
449  /* Our parent's button widget is used to determine where to place the drop
450  * down list window. */
451  Rect wi_rect;
452  NWidgetCore *nwi = w->GetWidget<NWidgetCore>(button);
453  wi_rect.left = nwi->pos_x;
454  wi_rect.right = nwi->pos_x + nwi->current_x - 1;
455  wi_rect.top = nwi->pos_y;
456  wi_rect.bottom = nwi->pos_y + nwi->current_y - 1;
457  Colours wi_colour = nwi->colour;
458 
459  if ((nwi->type & WWT_MASK) == NWID_BUTTON_DROPDOWN) {
461  } else {
462  w->LowerWidget(button);
463  }
464  w->SetWidgetDirty(button);
465 
466  if (width != 0) {
467  if (_current_text_dir == TD_RTL) {
468  wi_rect.left = wi_rect.right + 1 - width;
469  } else {
470  wi_rect.right = wi_rect.left + width - 1;
471  }
472  }
473 
474  ShowDropDownListAt(w, std::move(list), selected, button, wi_rect, wi_colour, auto_width, instant_close);
475 }
476 
488 void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width)
489 {
490  DropDownList list;
491 
492  for (uint i = 0; strings[i] != INVALID_STRING_ID; i++) {
493  if (!HasBit(hidden_mask, i)) {
494  list.emplace_back(new DropDownListStringItem(strings[i], i, HasBit(disabled_mask, i)));
495  }
496  }
497 
498  if (!list.empty()) ShowDropDownList(w, std::move(list), selected, button, width);
499 }
500 
507 {
508  Window *w;
509  FOR_ALL_WINDOWS_FROM_BACK(w) {
510  if (w->window_class != WC_DROPDOWN_MENU) continue;
511 
512  DropdownWindow *dw = dynamic_cast<DropdownWindow*>(w);
513  assert(dw != nullptr);
514  if (pw->window_class == dw->parent_wnd_class &&
515  pw->window_number == dw->parent_wnd_num) {
516  int parent_button = dw->parent_button;
517  delete dw;
518  return parent_button;
519  }
520  }
521 
522  return -1;
523 }
524 
SZSP_NONE
@ SZSP_NONE
Display plane with zero size in both directions (none filling and resizing).
Definition: widget_type.h:399
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:143
DropdownWindow::parent_button
int parent_button
Parent widget number where the window is dropped from.
Definition: dropdown.cpp:120
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:1104
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:122
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:99
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:679
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:598
_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:919
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:127
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:845
ND_DROPDOWN_ACTIVE
@ ND_DROPDOWN_ACTIVE
Bit value of the 'dropdown active' flag.
Definition: widget_type.h:281
GUITimer
Definition: guitimer_func.h:13
NWidgetBase::type
WidgetType type
Type of the widget / nested widget.
Definition: widget_type.h:171
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:213
DropdownWindow::OnMouseLoop
virtual void OnMouseLoop()
Called for every mouse loop run, which is at least once per (game) tick.
Definition: dropdown.cpp:296
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:447
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:123
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:723
DropdownWindow::list
const DropDownList list
List with dropdown menu items.
Definition: dropdown.cpp:121
DropdownWindow
Drop-down menu window.
Definition: dropdown.cpp:117
Window::parent
Window * parent
Parent window.
Definition: window_gui.h:338
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:318
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:268
Window::flags
WindowFlags flags
Window flags.
Definition: window_gui.h:311
WindowClass
WindowClass
Window classes.
Definition: window_type.h:37
DropdownWindow::parent_wnd_class
WindowClass parent_wnd_class
Parent window class.
Definition: dropdown.cpp:118
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:488
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:313
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:125
NWidgetBase::current_y
uint current_y
Current vertical size (after resizing).
Definition: widget_type.h:183
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:128
DropdownWindow::scrolling
int scrolling
If non-zero, auto-scroll the item list (one time).
Definition: dropdown.cpp:126
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:695
DropdownWindow::OnInitialPosition
virtual Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number)
Compute the initial position of the window.
Definition: dropdown.cpp:203
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:1008
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:311
NWidgetBase::pos_x
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:185
HideDropDownMenu
int HideDropDownMenu(Window *pw)
Delete the drop-down menu from window pw.
Definition: dropdown.cpp:506
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:1123
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:956
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:640
Window::window_class
WindowClass window_class
Window class.
Definition: window_gui.h:312
NWidgetCore::colour
Colours colour
Colour of this widget.
Definition: widget_type.h:312
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:319
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:360
MILLISECONDS_PER_TICK
static const uint MILLISECONDS_PER_TICK
The number of milliseconds per game tick.
Definition: gfx_type.h:310
CenterBounds
static int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
Definition: gfx_func.h:151
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:369
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:320
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:186
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:643
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:723
Window
Data structure for an opened window.
Definition: window_gui.h:277
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:292
DropdownWindow::parent_wnd_num
WindowNumber parent_wnd_num
Parent window number.
Definition: dropdown.cpp:119
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:475
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:182
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:385
DropdownWindow::DrawWidget
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
Definition: dropdown.cpp:240
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:279
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