OpenTTD Source  13.2.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 
125  byte click_delay;
126  bool drag_mode;
128  int scrolling;
131  Scrollbar *vscroll;
132 
145  DropdownWindow(Window *parent, DropDownList &&list, int selected, int button, bool instant_close, const Point &position, const Dimension &size, Colours wi_colour, bool scroll)
146  : Window(&_dropdown_desc), list(std::move(list))
147  {
148  assert(this->list.size() > 0);
149 
150  this->position = position;
151 
152  this->CreateNestedTree();
153 
154  this->vscroll = this->GetScrollbar(WID_DM_SCROLL);
155 
156  uint items_width = size.width - (scroll ? NWidgetScrollbar::GetVerticalDimension().width : 0);
157  NWidgetCore *nwi = this->GetWidget<NWidgetCore>(WID_DM_ITEMS);
158  nwi->SetMinimalSizeAbsolute(items_width, size.height + WidgetDimensions::scaled.fullbevel.Vertical() * 2);
159  nwi->colour = wi_colour;
160 
161  nwi = this->GetWidget<NWidgetCore>(WID_DM_SCROLL);
162  nwi->colour = wi_colour;
163 
164  this->GetWidget<NWidgetStacked>(WID_DM_SHOW_SCROLL)->SetDisplayedPlane(scroll ? 0 : SZSP_NONE);
165 
166  this->FinishInitNested(0);
167  CLRBITS(this->flags, WF_WHITE_BORDER);
168 
169  /* Total length of list */
170  int list_height = 0;
171  for (const auto &item : this->list) {
172  list_height += item->Height(items_width);
173  }
174 
175  /* Capacity is the average number of items visible */
176  this->vscroll->SetCapacity(size.height * (uint16)this->list.size() / list_height);
177  this->vscroll->SetCount((uint16)this->list.size());
178 
179  this->parent = parent;
180  this->parent_button = button;
181  this->selected_index = selected;
182  this->click_delay = 0;
183  this->drag_mode = true;
184  this->instant_close = instant_close;
185  this->scrolling_timer = GUITimer(MILLISECONDS_PER_TICK);
186  }
187 
188  void Close() override
189  {
190  /* Finish closing the dropdown, so it doesn't affect new window placement.
191  * Also mark it dirty in case the callback deals with the screen. (e.g. screenshots). */
192  this->Window::Close();
193 
194  Point pt = _cursor.pos;
195  pt.x -= this->parent->left;
196  pt.y -= this->parent->top;
197  this->parent->OnDropdownClose(pt, this->parent_button, this->selected_index, this->instant_close);
198 
199  /* Set flag on parent widget to indicate that we have just closed. */
200  NWidgetCore *nwc = this->parent->GetWidget<NWidgetCore>(this->parent_button);
201  if (nwc != nullptr) SetBit(nwc->disp_flags, NDB_DROPDOWN_CLOSED);
202  }
203 
204  void OnFocusLost() override
205  {
206  this->Close();
207  }
208 
209  Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number) override
210  {
211  return this->position;
212  }
213 
219  bool GetDropDownItem(int &value)
220  {
221  if (GetWidgetFromPos(this, _cursor.pos.x - this->left, _cursor.pos.y - this->top) < 0) return false;
222 
223  const Rect &r = this->GetWidget<NWidgetBase>(WID_DM_ITEMS)->GetCurrentRect().Shrink(WidgetDimensions::scaled.fullbevel);
224  int y = _cursor.pos.y - this->top - r.top - WidgetDimensions::scaled.fullbevel.top;
225  int width = r.Width();
226  int pos = this->vscroll->GetPosition();
227 
228  for (const auto &item : this->list) {
229  /* Skip items that are scrolled up */
230  if (--pos >= 0) continue;
231 
232  int item_height = item->Height(width);
233 
234  if (y < item_height) {
235  if (item->masked || !item->Selectable()) return false;
236  value = item->result;
237  return true;
238  }
239 
240  y -= item_height;
241  }
242 
243  return false;
244  }
245 
246  void DrawWidget(const Rect &r, int widget) const override
247  {
248  if (widget != WID_DM_ITEMS) return;
249 
250  Colours colour = this->GetWidget<NWidgetCore>(widget)->colour;
251 
252  Rect ir = r.Shrink(WidgetDimensions::scaled.fullbevel).Shrink(RectPadding::zero, WidgetDimensions::scaled.fullbevel);
253  int y = ir.top;
254  int pos = this->vscroll->GetPosition();
255  for (const auto &item : this->list) {
256  int item_height = item->Height(ir.Width());
257 
258  /* Skip items that are scrolled up */
259  if (--pos >= 0) continue;
260 
261  if (y + item_height - 1 <= ir.bottom) {
262  bool selected = (this->selected_index == item->result);
263  if (selected) GfxFillRect(ir.left, y, ir.right, y + item_height - 1, PC_BLACK);
264 
265  item->Draw({ir.left, y, ir.right, y + item_height - 1}, selected, colour);
266 
267  if (item->masked) {
268  GfxFillRect(ir.left, y, ir.right, y + item_height - 1, _colour_gradient[colour][5], FILLRECT_CHECKER);
269  }
270  }
271  y += item_height;
272  }
273  }
274 
275  void OnClick(Point pt, int widget, int click_count) override
276  {
277  if (widget != WID_DM_ITEMS) return;
278  int item;
279  if (this->GetDropDownItem(item)) {
280  this->click_delay = 4;
281  this->selected_index = item;
282  this->SetDirty();
283  }
284  }
285 
286  void OnRealtimeTick(uint delta_ms) override
287  {
288  if (!this->scrolling_timer.Elapsed(delta_ms)) return;
289  this->scrolling_timer.SetInterval(MILLISECONDS_PER_TICK);
290 
291  if (this->scrolling != 0) {
292  int pos = this->vscroll->GetPosition();
293 
294  this->vscroll->UpdatePosition(this->scrolling);
295  this->scrolling = 0;
296 
297  if (pos != this->vscroll->GetPosition()) {
298  this->SetDirty();
299  }
300  }
301  }
302 
303  void OnMouseLoop() override
304  {
305  if (this->click_delay != 0 && --this->click_delay == 0) {
306  /* Close the dropdown, so it doesn't affect new window placement.
307  * Also mark it dirty in case the callback deals with the screen. (e.g. screenshots). */
308  this->Close();
309  this->parent->OnDropdownSelect(this->parent_button, this->selected_index);
310  return;
311  }
312 
313  if (this->drag_mode) {
314  int item;
315 
316  if (!_left_button_clicked) {
317  this->drag_mode = false;
318  if (!this->GetDropDownItem(item)) {
319  if (this->instant_close) this->Close();
320  return;
321  }
322  this->click_delay = 2;
323  } else {
324  if (_cursor.pos.y <= this->top + 2) {
325  /* Cursor is above the list, set scroll up */
326  this->scrolling = -1;
327  return;
328  } else if (_cursor.pos.y >= this->top + this->height - 2) {
329  /* Cursor is below list, set scroll down */
330  this->scrolling = 1;
331  return;
332  }
333 
334  if (!this->GetDropDownItem(item)) return;
335  }
336 
337  if (this->selected_index != item) {
338  this->selected_index = item;
339  this->SetDirty();
340  }
341  }
342  }
343 };
344 
358 void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button, Rect wi_rect, Colours wi_colour, bool auto_width, bool instant_close)
359 {
361 
362  /* The preferred position is just below the dropdown calling widget */
363  int top = w->top + wi_rect.bottom + 1;
364 
365  /* The preferred width equals the calling widget */
366  uint width = wi_rect.Width();
367 
368  /* Longest item in the list, if auto_width is enabled */
369  uint max_item_width = 0;
370 
371  /* Total height of list */
372  uint height = 0;
373 
374  for (const auto &item : list) {
375  height += item->Height(width);
376  if (auto_width) max_item_width = std::max(max_item_width, item->Width());
377  }
378 
379  if (auto_width) max_item_width += WidgetDimensions::scaled.fullbevel.Horizontal();
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 - (int)WidgetDimensions::scaled.fullbevel.Vertical() * 2, 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() - (int)WidgetDimensions::scaled.fullbevel.Vertical() * 2, 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  /* Fit the list; create at least one row, even if there is no height available. */
407  uint rows = std::max<uint>(available_height / avg_height, 1);
408  height = rows * avg_height;
409 
410  /* Add space for the scrollbar. */
411  max_item_width += NWidgetScrollbar::GetVerticalDimension().width;
412  }
413 
414  /* Set the top position if needed. */
415  if (above) {
416  top = w->top + wi_rect.top - height - WidgetDimensions::scaled.fullbevel.Vertical() * 2;
417  }
418  }
419 
420  if (auto_width) width = std::max(width, max_item_width);
421 
422  Point dw_pos = { w->left + (_current_text_dir == TD_RTL ? wi_rect.right + 1 - (int)width : wi_rect.left), top};
423  Dimension dw_size = {width, height};
424  DropdownWindow *dropdown = new DropdownWindow(w, std::move(list), selected, button, instant_close, dw_pos, dw_size, wi_colour, scroll);
425 
426  /* The dropdown starts scrolling downwards when opening it towards
427  * the top and holding down the mouse button. It can be fooled by
428  * opening the dropdown scrolled to the very bottom. */
429  if (above && scroll) dropdown->vscroll->UpdatePosition(INT_MAX);
430 }
431 
444 void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button, uint width, bool auto_width, bool instant_close)
445 {
446  /* Our parent's button widget is used to determine where to place the drop
447  * down list window. */
448  NWidgetCore *nwi = w->GetWidget<NWidgetCore>(button);
449  Rect wi_rect = nwi->GetCurrentRect();
450  Colours wi_colour = nwi->colour;
451 
452  if ((nwi->type & WWT_MASK) == NWID_BUTTON_DROPDOWN) {
454  } else {
455  w->LowerWidget(button);
456  }
457  w->SetWidgetDirty(button);
458 
459  if (width != 0) {
460  if (_current_text_dir == TD_RTL) {
461  wi_rect.left = wi_rect.right + 1 - ScaleGUITrad(width);
462  } else {
463  wi_rect.right = wi_rect.left + ScaleGUITrad(width) - 1;
464  }
465  }
466 
467  ShowDropDownListAt(w, std::move(list), selected, button, wi_rect, wi_colour, auto_width, instant_close);
468 }
469 
481 void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width)
482 {
483  DropDownList list;
484 
485  for (uint i = 0; strings[i] != INVALID_STRING_ID; i++) {
486  if (!HasBit(hidden_mask, i)) {
487  list.emplace_back(new DropDownListStringItem(strings[i], i, HasBit(disabled_mask, i)));
488  }
489  }
490 
491  if (!list.empty()) ShowDropDownList(w, std::move(list), selected, button, width);
492 }
SZSP_NONE
@ SZSP_NONE
Display plane with zero size in both directions (none filling and resizing).
Definition: widget_type.h:428
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:145
DropdownWindow::parent_button
int parent_button
Parent widget number where the window is dropped from.
Definition: dropdown.cpp:122
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:1210
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:319
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:124
NDB_DROPDOWN_CLOSED
@ NDB_DROPDOWN_CLOSED
Dropdown menu of the dropdown widget has closed.
Definition: widget_type.h:296
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:1775
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
DropdownWindow::OnRealtimeTick
void OnRealtimeTick(uint delta_ms) override
Called periodically.
Definition: dropdown.cpp:286
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:209
Scrollbar::SetCount
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:717
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:294
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:292
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:636
DropdownWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: dropdown.cpp:246
_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:975
DropdownWindow::Close
void Close() override
Hide the window and all its child windows, and mark them for a later deletion.
Definition: dropdown.cpp:188
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:275
DropdownWindow::scrolling_timer
GUITimer scrolling_timer
Timer for auto-scroll of the item list.
Definition: dropdown.cpp:129
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:304
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:763
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:1008
DropdownWindow::GetDropDownItem
bool GetDropDownItem(int &value)
Find the dropdown item under the cursor.
Definition: dropdown.cpp:219
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:444
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:125
dropdown_widget.h
dropdown_type.h
GetMainViewTop
int GetMainViewTop()
Return the top of the main view available for general use.
Definition: window.cpp:2124
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:123
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
WidgetDimensions::dropdowntext
RectPadding dropdowntext
Offsets of text within a dropdown widget.
Definition: window_gui.h:57
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:481
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::OnFocusLost
void OnFocusLost() override
Called when window loses focus.
Definition: dropdown.cpp:204
DropdownWindow::instant_close
bool instant_close
Close the window when the mouse button is raised.
Definition: dropdown.cpp:127
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
DropdownWindow::position
Point position
Position of the topleft corner of the window.
Definition: dropdown.cpp:130
DropdownWindow::scrolling
int scrolling
If non-zero, auto-scroll the item list (one time).
Definition: dropdown.cpp:128
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:733
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:1096
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:337
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:1229
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
CloseWindowByClass
void CloseWindowByClass(WindowClass cls)
Close all windows of a given class.
Definition: window.cpp:1203
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1014
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:678
WidgetDimensions::bevel
RectPadding bevel
Widths of bevel border.
Definition: window_gui.h:45
NWidgetCore::colour
Colours colour
Colour of this widget.
Definition: widget_type.h:338
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1791
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:358
MILLISECONDS_PER_TICK
static const uint MILLISECONDS_PER_TICK
The number of milliseconds per game tick.
Definition: gfx_type.h:316
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
SetBit
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
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
DropdownWindow::OnMouseLoop
void OnMouseLoop() override
Called for every mouse loop run, which is at least once per (game) tick.
Definition: dropdown.cpp:303
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:316
Window::SetWidgetDirty
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:621
GetMainViewBottom
int GetMainViewBottom()
Return the bottom of the main view available for general use.
Definition: window.cpp:2135
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:1107
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