OpenTTD Source  13.1
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 "../zoom_func.h"
17 #include "dropdown_type.h"
18 
19 #include "dropdown_widget.h"
20 
21 #include "../safeguards.h"
22 
23 
24 void DropDownListItem::Draw(const Rect &r, bool sel, Colours bg_colour) const
25 {
26  int c1 = _colour_gradient[bg_colour][3];
27  int c2 = _colour_gradient[bg_colour][7];
28 
29  int mid = CenterBounds(r.top, r.bottom, 0);
30  GfxFillRect(r.left, mid - WidgetDimensions::scaled.bevel.bottom, r.right, mid - 1, c1);
31  GfxFillRect(r.left, mid, r.right, mid + WidgetDimensions::scaled.bevel.top - 1, c2);
32 }
33 
34 uint DropDownListStringItem::Width() const
35 {
36  char buffer[512];
37  GetString(buffer, this->String(), lastof(buffer));
39 }
40 
41 void DropDownListStringItem::Draw(const Rect &r, bool sel, Colours bg_colour) const
42 {
43  Rect ir = r.Shrink(WidgetDimensions::scaled.dropdowntext);
44  DrawString(ir.left, ir.right, r.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  this->sprite_y = dim.height;
78 }
79 
80 uint DropDownListIconItem::Height(uint width) const
81 {
82  return std::max(this->dim.height, (uint)FONT_HEIGHT_NORMAL);
83 }
84 
85 uint DropDownListIconItem::Width() const
86 {
87  return DropDownListParamStringItem::Width() + this->dim.width + WidgetDimensions::scaled.hsep_wide;
88 }
89 
90 void DropDownListIconItem::Draw(const Rect &r, bool sel, Colours bg_colour) const
91 {
92  bool rtl = _current_text_dir == TD_RTL;
93  Rect ir = r.Shrink(WidgetDimensions::scaled.dropdowntext);
94  Rect tr = ir.Indent(this->dim.width + WidgetDimensions::scaled.hsep_normal, rtl);
95  DrawSprite(this->sprite, this->pal, ir.WithWidth(this->dim.width, rtl).left, CenterBounds(r.top, r.bottom, this->sprite_y));
96  DrawString(tr.left, tr.right, CenterBounds(r.top, r.bottom, FONT_HEIGHT_NORMAL), this->String(), sel ? TC_WHITE : TC_BLACK);
97 }
98 
99 void DropDownListIconItem::SetDimension(Dimension d)
100 {
101  this->dim = d;
102 }
103 
104 static const NWidgetPart _nested_dropdown_menu_widgets[] = {
107  NWidget(NWID_SELECTION, INVALID_COLOUR, WID_DM_SHOW_SCROLL),
108  NWidget(NWID_VSCROLLBAR, COLOUR_END, WID_DM_SCROLL),
109  EndContainer(),
110  EndContainer(),
111 };
112 
113 static WindowDesc _dropdown_desc(
114  WDP_MANUAL, nullptr, 0, 0,
116  WDF_NO_FOCUS,
117  _nested_dropdown_menu_widgets, lengthof(_nested_dropdown_menu_widgets)
118 );
119 
127  byte click_delay;
128  bool drag_mode;
130  int scrolling;
133  Scrollbar *vscroll;
134 
147  DropdownWindow(Window *parent, DropDownList &&list, int selected, int button, bool instant_close, const Point &position, const Dimension &size, Colours wi_colour, bool scroll)
148  : Window(&_dropdown_desc), list(std::move(list))
149  {
150  assert(this->list.size() > 0);
151 
152  this->position = position;
153 
154  this->CreateNestedTree();
155 
156  this->vscroll = this->GetScrollbar(WID_DM_SCROLL);
157 
158  uint items_width = size.width - (scroll ? NWidgetScrollbar::GetVerticalDimension().width : 0);
159  NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_DM_ITEMS);
160  nwi->SetMinimalSizeAbsolute(items_width, size.height + WidgetDimensions::scaled.fullbevel.Vertical() * 2);
161  nwi->colour = wi_colour;
162 
163  nwi = this->GetWidget<NWidgetCore>(WID_DM_SCROLL);
164  nwi->colour = wi_colour;
165 
166  this->GetWidget<NWidgetStacked>(WID_DM_SHOW_SCROLL)->SetDisplayedPlane(scroll ? 0 : SZSP_NONE);
167 
168  this->FinishInitNested(0);
169  CLRBITS(this->flags, WF_WHITE_BORDER);
170 
171  /* Total length of list */
172  int list_height = 0;
173  for (const auto &item : this->list) {
174  list_height += item->Height(items_width);
175  }
176 
177  /* Capacity is the average number of items visible */
178  this->vscroll->SetCapacity(size.height * (uint16)this->list.size() / list_height);
179  this->vscroll->SetCount((uint16)this->list.size());
180 
181  this->parent_wnd_class = parent->window_class;
182  this->parent_wnd_num = parent->window_number;
183  this->parent_button = button;
184  this->selected_index = selected;
185  this->click_delay = 0;
186  this->drag_mode = true;
187  this->instant_close = instant_close;
188  this->scrolling_timer = GUITimer(MILLISECONDS_PER_TICK);
189  }
190 
191  void Close() override
192  {
193  /* Finish closing the dropdown, so it doesn't affect new window placement.
194  * Also mark it dirty in case the callback deals with the screen. (e.g. screenshots). */
195  this->Window::Close();
196 
197  Window *w2 = FindWindowById(this->parent_wnd_class, this->parent_wnd_num);
198  if (w2 != nullptr) {
199  Point pt = _cursor.pos;
200  pt.x -= w2->left;
201  pt.y -= w2->top;
202  w2->OnDropdownClose(pt, this->parent_button, this->selected_index, this->instant_close);
203  }
204  }
205 
206  Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number) override
207  {
208  return this->position;
209  }
210 
216  bool GetDropDownItem(int &value)
217  {
218  if (GetWidgetFromPos(this, _cursor.pos.x - this->left, _cursor.pos.y - this->top) < 0) return false;
219 
220  const Rect &r = this->GetWidget<NWidgetBase>(WID_DM_ITEMS)->GetCurrentRect().Shrink(WidgetDimensions::scaled.fullbevel);
221  int y = _cursor.pos.y - this->top - r.top - WidgetDimensions::scaled.fullbevel.top;
222  int width = r.Width();
223  int pos = this->vscroll->GetPosition();
224 
225  for (const auto &item : this->list) {
226  /* Skip items that are scrolled up */
227  if (--pos >= 0) continue;
228 
229  int item_height = item->Height(width);
230 
231  if (y < item_height) {
232  if (item->masked || !item->Selectable()) return false;
233  value = item->result;
234  return true;
235  }
236 
237  y -= item_height;
238  }
239 
240  return false;
241  }
242 
243  void DrawWidget(const Rect &r, int widget) const override
244  {
245  if (widget != WID_DM_ITEMS) return;
246 
247  Colours colour = this->GetWidget<NWidgetCore>(widget)->colour;
248 
249  Rect ir = r.Shrink(WidgetDimensions::scaled.fullbevel).Shrink(RectPadding::zero, WidgetDimensions::scaled.fullbevel);
250  int y = ir.top;
251  int pos = this->vscroll->GetPosition();
252  for (const auto &item : this->list) {
253  int item_height = item->Height(ir.Width());
254 
255  /* Skip items that are scrolled up */
256  if (--pos >= 0) continue;
257 
258  if (y + item_height - 1 <= ir.bottom) {
259  bool selected = (this->selected_index == item->result);
260  if (selected) GfxFillRect(ir.left, y, ir.right, y + item_height - 1, PC_BLACK);
261 
262  item->Draw({ir.left, y, ir.right, y + item_height - 1}, selected, colour);
263 
264  if (item->masked) {
265  GfxFillRect(ir.left, y, ir.right, y + item_height - 1, _colour_gradient[colour][5], FILLRECT_CHECKER);
266  }
267  }
268  y += item_height;
269  }
270  }
271 
272  void OnClick(Point pt, int widget, int click_count) override
273  {
274  if (widget != WID_DM_ITEMS) return;
275  int item;
276  if (this->GetDropDownItem(item)) {
277  this->click_delay = 4;
278  this->selected_index = item;
279  this->SetDirty();
280  }
281  }
282 
283  void OnRealtimeTick(uint delta_ms) override
284  {
285  if (!this->scrolling_timer.Elapsed(delta_ms)) return;
286  this->scrolling_timer.SetInterval(MILLISECONDS_PER_TICK);
287 
288  if (this->scrolling != 0) {
289  int pos = this->vscroll->GetPosition();
290 
291  this->vscroll->UpdatePosition(this->scrolling);
292  this->scrolling = 0;
293 
294  if (pos != this->vscroll->GetPosition()) {
295  this->SetDirty();
296  }
297  }
298  }
299 
300  void OnMouseLoop() override
301  {
302  Window *w2 = FindWindowById(this->parent_wnd_class, this->parent_wnd_num);
303  if (w2 == nullptr) {
304  this->Close();
305  return;
306  }
307 
308  if (this->click_delay != 0 && --this->click_delay == 0) {
309  /* Close the dropdown, so it doesn't affect new window placement.
310  * Also mark it dirty in case the callback deals with the screen. (e.g. screenshots). */
311  this->Close();
312  w2->OnDropdownSelect(this->parent_button, this->selected_index);
313  return;
314  }
315 
316  if (this->drag_mode) {
317  int item;
318 
319  if (!_left_button_clicked) {
320  this->drag_mode = false;
321  if (!this->GetDropDownItem(item)) {
322  if (this->instant_close) this->Close();
323  return;
324  }
325  this->click_delay = 2;
326  } else {
327  if (_cursor.pos.y <= this->top + 2) {
328  /* Cursor is above the list, set scroll up */
329  this->scrolling = -1;
330  return;
331  } else if (_cursor.pos.y >= this->top + this->height - 2) {
332  /* Cursor is below list, set scroll down */
333  this->scrolling = 1;
334  return;
335  }
336 
337  if (!this->GetDropDownItem(item)) return;
338  }
339 
340  if (this->selected_index != item) {
341  this->selected_index = item;
342  this->SetDirty();
343  }
344  }
345  }
346 };
347 
361 void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button, Rect wi_rect, Colours wi_colour, bool auto_width, bool instant_close)
362 {
364 
365  /* The preferred position is just below the dropdown calling widget */
366  int top = w->top + wi_rect.bottom + 1;
367 
368  /* The preferred width equals the calling widget */
369  uint width = wi_rect.Width();
370 
371  /* Longest item in the list, if auto_width is enabled */
372  uint max_item_width = 0;
373 
374  /* Total height of list */
375  uint height = 0;
376 
377  for (const auto &item : list) {
378  height += item->Height(width);
379  if (auto_width) max_item_width = std::max(max_item_width, item->Width());
380  }
381 
382  if (auto_width) max_item_width += WidgetDimensions::scaled.fullbevel.Horizontal();
383 
384  /* Scrollbar needed? */
385  bool scroll = false;
386 
387  /* Is it better to place the dropdown above the widget? */
388  bool above = false;
389 
390  /* Available height below (or above, if the dropdown is placed above the widget). */
391  uint available_height = std::max(GetMainViewBottom() - top - (int)WidgetDimensions::scaled.fullbevel.Vertical() * 2, 0);
392 
393  /* If the dropdown doesn't fully fit below the widget... */
394  if (height > available_height) {
395 
396  uint available_height_above = std::max(w->top + wi_rect.top - GetMainViewTop() - (int)WidgetDimensions::scaled.fullbevel.Vertical() * 2, 0);
397 
398  /* Put the dropdown above if there is more available space. */
399  if (available_height_above > available_height) {
400  above = true;
401  available_height = available_height_above;
402  }
403 
404  /* If the dropdown doesn't fully fit, we need a dropdown. */
405  if (height > available_height) {
406  scroll = true;
407  uint avg_height = height / (uint)list.size();
408 
409  /* Check at least there is space for one item. */
410  assert(available_height >= avg_height);
411 
412  /* Fit the list. */
413  uint rows = available_height / avg_height;
414  height = rows * avg_height;
415 
416  /* Add space for the scrollbar. */
417  max_item_width += NWidgetScrollbar::GetVerticalDimension().width;
418  }
419 
420  /* Set the top position if needed. */
421  if (above) {
422  top = w->top + wi_rect.top - height - WidgetDimensions::scaled.fullbevel.Vertical() * 2;
423  }
424  }
425 
426  if (auto_width) width = std::max(width, max_item_width);
427 
428  Point dw_pos = { w->left + (_current_text_dir == TD_RTL ? wi_rect.right + 1 - (int)width : wi_rect.left), top};
429  Dimension dw_size = {width, height};
430  DropdownWindow *dropdown = new DropdownWindow(w, std::move(list), selected, button, instant_close, dw_pos, dw_size, wi_colour, scroll);
431 
432  /* The dropdown starts scrolling downwards when opening it towards
433  * the top and holding down the mouse button. It can be fooled by
434  * opening the dropdown scrolled to the very bottom. */
435  if (above && scroll) dropdown->vscroll->UpdatePosition(INT_MAX);
436 }
437 
450 void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button, uint width, bool auto_width, bool instant_close)
451 {
452  /* Our parent's button widget is used to determine where to place the drop
453  * down list window. */
454  NWidgetCore *nwi = w->GetWidget<NWidgetCore>(button);
455  Rect wi_rect = nwi->GetCurrentRect();
456  Colours wi_colour = nwi->colour;
457 
458  if ((nwi->type & WWT_MASK) == NWID_BUTTON_DROPDOWN) {
460  } else {
461  w->LowerWidget(button);
462  }
463  w->SetWidgetDirty(button);
464 
465  if (width != 0) {
466  if (_current_text_dir == TD_RTL) {
467  wi_rect.left = wi_rect.right + 1 - ScaleGUITrad(width);
468  } else {
469  wi_rect.right = wi_rect.left + ScaleGUITrad(width) - 1;
470  }
471  }
472 
473  ShowDropDownListAt(w, std::move(list), selected, button, wi_rect, wi_colour, auto_width, instant_close);
474 }
475 
487 void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width)
488 {
489  DropDownList list;
490 
491  for (uint i = 0; strings[i] != INVALID_STRING_ID; i++) {
492  if (!HasBit(hidden_mask, i)) {
493  list.emplace_back(new DropDownListStringItem(strings[i], i, HasBit(disabled_mask, i)));
494  }
495  }
496 
497  if (!list.empty()) ShowDropDownList(w, std::move(list), selected, button, width);
498 }
499 
506 {
507  for (Window *w : Window::Iterate()) {
508  if (w->window_class != WC_DROPDOWN_MENU) continue;
509 
510  DropdownWindow *dw = dynamic_cast<DropdownWindow*>(w);
511  assert(dw != nullptr);
512  if (pw->window_class == dw->parent_wnd_class &&
513  pw->window_number == dw->parent_wnd_num) {
514  int parent_button = dw->parent_button;
515  dw->Close();
516  return parent_button;
517  }
518  }
519 
520  return -1;
521 }
522 
SZSP_NONE
@ SZSP_NONE
Display plane with zero size in both directions (none filling and resizing).
Definition: widget_type.h:426
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:147
DropdownWindow::parent_button
int parent_button
Parent widget number where the window is dropped from.
Definition: dropdown.cpp:124
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:1208
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:320
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:92
DropdownWindow::selected_index
int selected_index
Index of the selected item in the list.
Definition: dropdown.cpp:126
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:1771
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
DropdownWindow::OnRealtimeTick
void OnRealtimeTick(uint delta_ms) override
Called periodically.
Definition: dropdown.cpp:283
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1157
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
DropdownWindow::OnInitialPosition
Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number) override
Compute the initial position of the window.
Definition: dropdown.cpp:206
Scrollbar::SetCount
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:715
WDF_NO_FOCUS
@ WDF_NO_FOCUS
This window won't get focus/make any other window lose focus when click.
Definition: window_gui.h:146
FILLRECT_CHECKER
@ FILLRECT_CHECKER
Draw only every second pixel, used for greying-out.
Definition: gfx_type.h:295
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:644
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:293
WindowNumber
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:713
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:634
DropdownWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: dropdown.cpp:243
_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:55
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:196
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:973
DropdownWindow::Close
void Close() override
Hide the window and all its child windows, and mark them for a later deletion.
Definition: dropdown.cpp:191
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:890
DropdownWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: dropdown.cpp:272
DropdownWindow::scrolling_timer
GUITimer scrolling_timer
Timer for auto-scroll of the item list.
Definition: dropdown.cpp:131
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:102
Window::GetWidget
const NWID * GetWidget(uint widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition: window_gui.h:865
ND_DROPDOWN_ACTIVE
@ ND_DROPDOWN_ACTIVE
Bit value of the 'dropdown active' flag.
Definition: widget_type.h:303
Scrollbar::UpdatePosition
bool UpdatePosition(int difference, ScrollbarStepping unit=SS_SMALL)
Updates the position of the first visible element by the given amount.
Definition: widget_type.h:761
GUITimer
Definition: guitimer_func.h:13
WidgetDimensions::hsep_normal
int hsep_normal
Normal horizontal spacing.
Definition: window_gui.h:63
NWidgetBase::type
WidgetType type
Type of the widget / nested widget.
Definition: widget_type.h:185
WF_WHITE_BORDER
@ WF_WHITE_BORDER
Window white border counter bit mask.
Definition: window_gui.h:176
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:1004
DropdownWindow::GetDropDownItem
bool GetDropDownItem(int &value)
Find the dropdown item under the cursor.
Definition: dropdown.cpp:216
RectPadding::Horizontal
uint Horizontal() const
Get total horizontal padding of RectPadding.
Definition: geometry_type.hpp:59
WidgetDimensions::hsep_wide
int hsep_wide
Wide horizontal spacing.
Definition: window_gui.h:64
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:450
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:399
DropdownWindow::click_delay
byte click_delay
Timer to delay selection.
Definition: dropdown.cpp:127
dropdown_widget.h
dropdown_type.h
GetMainViewTop
int GetMainViewTop()
Return the top of the main view available for general use.
Definition: window.cpp:2120
Window::OnDropdownSelect
virtual void OnDropdownSelect(int widget, int index)
A dropdown option associated to this window has been selected.
Definition: window_gui.h:653
DropdownWindow::list
const DropDownList list
List with dropdown menu items.
Definition: dropdown.cpp:125
DropdownWindow
Drop-down menu window.
Definition: dropdown.cpp:121
Window::parent
Window * parent
Parent window.
Definition: window_gui.h:266
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:246
Window::flags
WindowFlags flags
Window flags.
Definition: window_gui.h:239
Rect::Indent
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Definition: geometry_type.hpp:192
WindowClass
WindowClass
Window classes.
Definition: window_type.h:37
WidgetDimensions::dropdowntext
RectPadding dropdowntext
Offsets of text within a dropdown widget.
Definition: window_gui.h:57
DropdownWindow::parent_wnd_class
WindowClass parent_wnd_class
Parent window class.
Definition: dropdown.cpp:122
Rect::WithWidth
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Definition: geometry_type.hpp:179
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:1058
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:487
PC_BLACK
static const uint8 PC_BLACK
Black palette colour.
Definition: gfx_func.h:242
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:241
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:116
DropdownWindow::instant_close
bool instant_close
Close the window when the mouse button is raised.
Definition: dropdown.cpp:129
RectPadding::Vertical
uint Vertical() const
Get total vertical padding of RectPadding.
Definition: geometry_type.hpp:65
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
Window::AllWindows
Iterable ensemble of all valid Windows.
Definition: window_gui.h:803
DropdownWindow::position
Point position
Position of the topleft corner of the window.
Definition: dropdown.cpp:132
DropdownWindow::scrolling
int scrolling
If non-zero, auto-scroll the item list (one time).
Definition: dropdown.cpp:130
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:993
Scrollbar::SetCapacity
void SetCapacity(int capacity)
Set the capacity of visible elements.
Definition: widget_type.h:731
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:1094
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:82
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:335
HideDropDownMenu
int HideDropDownMenu(Window *pw)
Delete the drop-down menu from window pw.
Definition: dropdown.cpp:505
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:206
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1227
WidgetDimensions::fullbevel
RectPadding fullbevel
Always-scaled bevel border.
Definition: window_gui.h:46
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:1012
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:676
WidgetDimensions::bevel
RectPadding bevel
Widths of bevel border.
Definition: window_gui.h:45
Window::window_class
WindowClass window_class
Window class.
Definition: window_gui.h:240
NWidgetCore::colour
Colours colour
Colour of this widget.
Definition: widget_type.h:336
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1787
Window::top
int top
y position of top edge of the window
Definition: window_gui.h:247
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:361
MILLISECONDS_PER_TICK
static const uint MILLISECONDS_PER_TICK
The number of milliseconds per game tick.
Definition: gfx_type.h:317
CenterBounds
static int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
Definition: gfx_func.h:178
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:386
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:248
WDP_MANUAL
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition: window_gui.h:89
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force)
Close a window by its class and window number (if it is open).
Definition: window.cpp:1187
DropdownWindow::OnMouseLoop
void OnMouseLoop() override
Called for every mouse loop run, which is at least once per (game) tick.
Definition: dropdown.cpp:300
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:737
Window
Data structure for an opened window.
Definition: window_gui.h:213
Rect::Width
int Width() const
Get width of Rect.
Definition: geometry_type.hpp:79
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
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:314
DropdownWindow::parent_wnd_num
WindowNumber parent_wnd_num
Parent window number.
Definition: dropdown.cpp:123
Window::SetWidgetDirty
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:619
GetMainViewBottom
int GetMainViewBottom()
Return the bottom of the main view available for general use.
Definition: window.cpp:2131
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:69
Window::LowerWidget
void LowerWidget(byte widget_index)
Marks a widget as lowered.
Definition: window_gui.h:403
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
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:402
NWidgetResizeBase::SetMinimalSizeAbsolute
void SetMinimalSizeAbsolute(uint min_x, uint min_y)
Set absolute (post-scaling) minimal size of the widget.
Definition: widget.cpp:1093
_left_button_clicked
bool _left_button_clicked
Is left mouse button clicked?
Definition: gfx.cpp:42
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:49
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:297
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
ScaleGUITrad
static RectPadding ScaleGUITrad(const RectPadding &r)
Scale a RectPadding to GUI zoom level.
Definition: widget.cpp:168
Window::Close
virtual void Close()
Hide the window and all its child windows, and mark them for a later deletion.
Definition: window.cpp:1103
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:54