OpenTTD
widget.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 "company_func.h"
12 #include "window_gui.h"
13 #include "viewport_func.h"
14 #include "zoom_func.h"
15 #include "strings_func.h"
16 #include "transparency.h"
17 #include "core/geometry_func.hpp"
18 #include "settings_type.h"
19 #include "querystring_gui.h"
20 
21 #include "table/sprites.h"
22 #include "table/strings.h"
23 #include "table/string_colours.h"
24 
25 #include "safeguards.h"
26 
36 static Point HandleScrollbarHittest(const Scrollbar *sb, int top, int bottom, bool horizontal)
37 {
38  /* Base for reversion */
39  int rev_base = top + bottom;
40  int button_size;
41  if (horizontal) {
42  button_size = NWidgetScrollbar::GetHorizontalDimension().width;
43  } else {
44  button_size = NWidgetScrollbar::GetVerticalDimension().height;
45  }
46  top += button_size; // top points to just below the up-button
47  bottom -= button_size; // bottom points to top of the down-button
48 
49  int height = (bottom - top);
50  int pos = sb->GetPosition();
51  int count = sb->GetCount();
52  int cap = sb->GetCapacity();
53 
54  if (count != 0) top += height * pos / count;
55 
56  if (cap > count) cap = count;
57  if (count != 0) bottom -= (count - pos - cap) * height / count;
58 
59  Point pt;
60  if (horizontal && _current_text_dir == TD_RTL) {
61  pt.x = rev_base - bottom;
62  pt.y = rev_base - top;
63  } else {
64  pt.x = top;
65  pt.y = bottom;
66  }
67  return pt;
68 }
69 
79 static void ScrollbarClickPositioning(Window *w, NWidgetScrollbar *sb, int x, int y, int mi, int ma)
80 {
81  int pos;
82  int button_size;
83  bool rtl = false;
84 
85  if (sb->type == NWID_HSCROLLBAR) {
86  pos = x;
87  rtl = _current_text_dir == TD_RTL;
88  button_size = NWidgetScrollbar::GetHorizontalDimension().width;
89  } else {
90  pos = y;
91  button_size = NWidgetScrollbar::GetVerticalDimension().height;
92  }
93  if (pos < mi + button_size) {
94  /* Pressing the upper button? */
96  if (_scroller_click_timeout <= 1) {
97  _scroller_click_timeout = 3;
98  sb->UpdatePosition(rtl ? 1 : -1);
99  }
100  w->mouse_capture_widget = sb->index;
101  } else if (pos >= ma - button_size) {
102  /* Pressing the lower button? */
104 
105  if (_scroller_click_timeout <= 1) {
106  _scroller_click_timeout = 3;
107  sb->UpdatePosition(rtl ? -1 : 1);
108  }
109  w->mouse_capture_widget = sb->index;
110  } else {
111  Point pt = HandleScrollbarHittest(sb, mi, ma, sb->type == NWID_HSCROLLBAR);
112 
113  if (pos < pt.x) {
114  sb->UpdatePosition(rtl ? 1 : -1, Scrollbar::SS_BIG);
115  } else if (pos > pt.y) {
116  sb->UpdatePosition(rtl ? -1 : 1, Scrollbar::SS_BIG);
117  } else {
118  _scrollbar_start_pos = pt.x - mi - button_size;
119  _scrollbar_size = ma - mi - button_size * 2;
120  w->mouse_capture_widget = sb->index;
121  _cursorpos_drag_start = _cursor.pos;
122  }
123  }
124 
125  w->SetDirty();
126 }
127 
136 void ScrollbarClickHandler(Window *w, NWidgetCore *nw, int x, int y)
137 {
138  int mi, ma;
139 
140  if (nw->type == NWID_HSCROLLBAR) {
141  mi = nw->pos_x;
142  ma = nw->pos_x + nw->current_x;
143  } else {
144  mi = nw->pos_y;
145  ma = nw->pos_y + nw->current_y;
146  }
147  NWidgetScrollbar *scrollbar = dynamic_cast<NWidgetScrollbar*>(nw);
148  assert(scrollbar != nullptr);
149  ScrollbarClickPositioning(w, scrollbar, x, y, mi, ma);
150 }
151 
160 int GetWidgetFromPos(const Window *w, int x, int y)
161 {
162  NWidgetCore *nw = w->nested_root->GetWidgetFromPos(x, y);
163  return (nw != nullptr) ? nw->index : -1;
164 }
165 
175 void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
176 {
177  assert(colour < COLOUR_END);
178 
179  uint dark = _colour_gradient[colour][3];
180  uint medium_dark = _colour_gradient[colour][5];
181  uint medium_light = _colour_gradient[colour][6];
182  uint light = _colour_gradient[colour][7];
183 
184  if (flags & FR_TRANSPARENT) {
185  GfxFillRect(left, top, right, bottom, PALETTE_TO_TRANSPARENT, FILLRECT_RECOLOUR);
186  } else {
187  uint interior;
188 
189  if (flags & FR_LOWERED) {
190  GfxFillRect(left, top, left, bottom, dark);
191  GfxFillRect(left + WD_BEVEL_LEFT, top, right, top, dark);
192  GfxFillRect(right, top + WD_BEVEL_TOP, right, bottom - WD_BEVEL_BOTTOM, light);
193  GfxFillRect(left + WD_BEVEL_LEFT, bottom, right, bottom, light);
194  interior = (flags & FR_DARKENED ? medium_dark : medium_light);
195  } else {
196  GfxFillRect(left, top, left, bottom - WD_BEVEL_BOTTOM, light);
197  GfxFillRect(left + WD_BEVEL_LEFT, top, right - WD_BEVEL_RIGHT, top, light);
198  GfxFillRect(right, top, right, bottom - WD_BEVEL_BOTTOM, dark);
199  GfxFillRect(left, bottom, right, bottom, dark);
200  interior = medium_dark;
201  }
202  if (!(flags & FR_BORDERONLY)) {
203  GfxFillRect(left + WD_BEVEL_LEFT, top + WD_BEVEL_TOP, right - WD_BEVEL_RIGHT, bottom - WD_BEVEL_BOTTOM, interior);
204  }
205  }
206 }
207 
216 static inline void DrawImageButtons(const Rect &r, WidgetType type, Colours colour, bool clicked, SpriteID img)
217 {
218  assert(img != 0);
219  DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE);
220 
221  if ((type & WWT_MASK) == WWT_IMGBTN_2 && clicked) img++; // Show different image when clicked for #WWT_IMGBTN_2.
222  Dimension d = GetSpriteSize(img);
223  DrawSprite(img, PAL_NONE, CenterBounds(r.left, r.right, d.width) + clicked, CenterBounds(r.top, r.bottom, d.height) + clicked);
224 }
225 
233 static inline void DrawLabel(const Rect &r, WidgetType type, bool clicked, StringID str)
234 {
235  if (str == STR_NULL) return;
236  if ((type & WWT_MASK) == WWT_TEXTBTN_2 && clicked) str++;
238  int offset = max(0, ((int)(r.bottom - r.top + 1) - (int)d.height) / 2); // Offset for rendering the text vertically centered
239  DrawString(r.left + clicked, r.right + clicked, r.top + offset + clicked, str, TC_FROMSTRING, SA_HOR_CENTER);
240 }
241 
248 static inline void DrawText(const Rect &r, TextColour colour, StringID str)
249 {
251  int offset = max(0, ((int)(r.bottom - r.top + 1) - (int)d.height) / 2); // Offset for rendering the text vertically centered
252  if (str != STR_NULL) DrawString(r.left, r.right, r.top + offset, str, colour);
253 }
254 
261 static inline void DrawInset(const Rect &r, Colours colour, StringID str)
262 {
263  DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, FR_LOWERED | FR_DARKENED);
264  if (str != STR_NULL) DrawString(r.left + WD_INSET_LEFT, r.right - WD_INSET_RIGHT, r.top + WD_INSET_TOP, str);
265 }
266 
276 static inline void DrawMatrix(const Rect &r, Colours colour, bool clicked, uint16 data, uint resize_x, uint resize_y)
277 {
278  DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE);
279 
280  int num_columns = GB(data, MAT_COL_START, MAT_COL_BITS); // Lower 8 bits of the widget data: Number of columns in the matrix.
281  int column_width; // Width of a single column in the matrix.
282  if (num_columns == 0) {
283  column_width = resize_x;
284  num_columns = (r.right - r.left + 1) / column_width;
285  } else {
286  column_width = (r.right - r.left + 1) / num_columns;
287  }
288 
289  int num_rows = GB(data, MAT_ROW_START, MAT_ROW_BITS); // Upper 8 bits of the widget data: Number of rows in the matrix.
290  int row_height; // Height of a single row in the matrix.
291  if (num_rows == 0) {
292  row_height = resize_y;
293  num_rows = (r.bottom - r.top + 1) / row_height;
294  } else {
295  row_height = (r.bottom - r.top + 1) / num_rows;
296  }
297 
298  int col = _colour_gradient[colour & 0xF][6];
299 
300  int x = r.left;
301  for (int ctr = num_columns; ctr > 1; ctr--) {
302  x += column_width;
303  GfxFillRect(x, r.top + 1, x, r.bottom - 1, col);
304  }
305 
306  x = r.top;
307  for (int ctr = num_rows; ctr > 1; ctr--) {
308  x += row_height;
309  GfxFillRect(r.left + 1, x, r.right - 1, x, col);
310  }
311 
312  col = _colour_gradient[colour & 0xF][4];
313 
314  x = r.left - 1;
315  for (int ctr = num_columns; ctr > 1; ctr--) {
316  x += column_width;
317  GfxFillRect(x, r.top + 1, x, r.bottom - 1, col);
318  }
319 
320  x = r.top - 1;
321  for (int ctr = num_rows; ctr > 1; ctr--) {
322  x += row_height;
323  GfxFillRect(r.left + 1, x, r.right - 1, x, col);
324  }
325 }
326 
336 static inline void DrawVerticalScrollbar(const Rect &r, Colours colour, bool up_clicked, bool bar_dragged, bool down_clicked, const Scrollbar *scrollbar)
337 {
338  int centre = (r.right - r.left) / 2;
339  int height = NWidgetScrollbar::GetVerticalDimension().height;
340 
341  /* draw up/down buttons */
342  DrawFrameRect(r.left, r.top, r.right, r.top + height - 1, colour, (up_clicked) ? FR_LOWERED : FR_NONE);
343  DrawSprite(SPR_ARROW_UP, PAL_NONE, r.left + 1 + up_clicked, r.top + 1 + up_clicked);
344 
345  DrawFrameRect(r.left, r.bottom - (height - 1), r.right, r.bottom, colour, (down_clicked) ? FR_LOWERED : FR_NONE);
346  DrawSprite(SPR_ARROW_DOWN, PAL_NONE, r.left + 1 + down_clicked, r.bottom - (height - 2) + down_clicked);
347 
348  int c1 = _colour_gradient[colour & 0xF][3];
349  int c2 = _colour_gradient[colour & 0xF][7];
350 
351  /* draw "shaded" background */
352  GfxFillRect(r.left, r.top + height, r.right, r.bottom - height, c2);
353  GfxFillRect(r.left, r.top + height, r.right, r.bottom - height, c1, FILLRECT_CHECKER);
354 
355  /* draw shaded lines */
356  GfxFillRect(r.left + centre - 3, r.top + height, r.left + centre - 3, r.bottom - height, c1);
357  GfxFillRect(r.left + centre - 2, r.top + height, r.left + centre - 2, r.bottom - height, c2);
358  GfxFillRect(r.left + centre + 2, r.top + height, r.left + centre + 2, r.bottom - height, c1);
359  GfxFillRect(r.left + centre + 3, r.top + height, r.left + centre + 3, r.bottom - height, c2);
360 
361  Point pt = HandleScrollbarHittest(scrollbar, r.top, r.bottom, false);
362  DrawFrameRect(r.left, pt.x, r.right, pt.y, colour, bar_dragged ? FR_LOWERED : FR_NONE);
363 }
364 
374 static inline void DrawHorizontalScrollbar(const Rect &r, Colours colour, bool left_clicked, bool bar_dragged, bool right_clicked, const Scrollbar *scrollbar)
375 {
376  int centre = (r.bottom - r.top) / 2;
377  int width = NWidgetScrollbar::GetHorizontalDimension().width;
378 
379  DrawFrameRect(r.left, r.top, r.left + width - 1, r.bottom, colour, left_clicked ? FR_LOWERED : FR_NONE);
380  DrawSprite(SPR_ARROW_LEFT, PAL_NONE, r.left + 1 + left_clicked, r.top + 1 + left_clicked);
381 
382  DrawFrameRect(r.right - (width - 1), r.top, r.right, r.bottom, colour, right_clicked ? FR_LOWERED : FR_NONE);
383  DrawSprite(SPR_ARROW_RIGHT, PAL_NONE, r.right - (width - 2) + right_clicked, r.top + 1 + right_clicked);
384 
385  int c1 = _colour_gradient[colour & 0xF][3];
386  int c2 = _colour_gradient[colour & 0xF][7];
387 
388  /* draw "shaded" background */
389  GfxFillRect(r.left + width, r.top, r.right - width, r.bottom, c2);
390  GfxFillRect(r.left + width, r.top, r.right - width, r.bottom, c1, FILLRECT_CHECKER);
391 
392  /* draw shaded lines */
393  GfxFillRect(r.left + width, r.top + centre - 3, r.right - width, r.top + centre - 3, c1);
394  GfxFillRect(r.left + width, r.top + centre - 2, r.right - width, r.top + centre - 2, c2);
395  GfxFillRect(r.left + width, r.top + centre + 2, r.right - width, r.top + centre + 2, c1);
396  GfxFillRect(r.left + width, r.top + centre + 3, r.right - width, r.top + centre + 3, c2);
397 
398  /* draw actual scrollbar */
399  Point pt = HandleScrollbarHittest(scrollbar, r.left, r.right, true);
400  DrawFrameRect(pt.x, r.top, pt.y, r.bottom, colour, bar_dragged ? FR_LOWERED : FR_NONE);
401 }
402 
409 static inline void DrawFrame(const Rect &r, Colours colour, StringID str)
410 {
411  int x2 = r.left; // by default the left side is the left side of the widget
412 
413  if (str != STR_NULL) x2 = DrawString(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, r.top, str);
414 
415  int c1 = _colour_gradient[colour][3];
416  int c2 = _colour_gradient[colour][7];
417 
418  /* If the frame has text, adjust the top bar to fit half-way through */
419  int dy1 = 4;
420  if (str != STR_NULL) dy1 = FONT_HEIGHT_NORMAL / 2 - 1;
421  int dy2 = dy1 + 1;
422 
423  if (_current_text_dir == TD_LTR) {
424  /* Line from upper left corner to start of text */
425  GfxFillRect(r.left, r.top + dy1, r.left + 4, r.top + dy1, c1);
426  GfxFillRect(r.left + 1, r.top + dy2, r.left + 4, r.top + dy2, c2);
427 
428  /* Line from end of text to upper right corner */
429  GfxFillRect(x2, r.top + dy1, r.right - 1, r.top + dy1, c1);
430  GfxFillRect(x2, r.top + dy2, r.right - 2, r.top + dy2, c2);
431  } else {
432  /* Line from upper left corner to start of text */
433  GfxFillRect(r.left, r.top + dy1, x2 - 2, r.top + dy1, c1);
434  GfxFillRect(r.left + 1, r.top + dy2, x2 - 2, r.top + dy2, c2);
435 
436  /* Line from end of text to upper right corner */
437  GfxFillRect(r.right - 5, r.top + dy1, r.right - 1, r.top + dy1, c1);
438  GfxFillRect(r.right - 5, r.top + dy2, r.right - 2, r.top + dy2, c2);
439  }
440 
441  /* Line from upper left corner to bottom left corner */
442  GfxFillRect(r.left, r.top + dy2, r.left, r.bottom - 1, c1);
443  GfxFillRect(r.left + 1, r.top + dy2 + 1, r.left + 1, r.bottom - 2, c2);
444 
445  /* Line from upper right corner to bottom right corner */
446  GfxFillRect(r.right - 1, r.top + dy2, r.right - 1, r.bottom - 2, c1);
447  GfxFillRect(r.right, r.top + dy1, r.right, r.bottom - 1, c2);
448 
449  GfxFillRect(r.left + 1, r.bottom - 1, r.right - 1, r.bottom - 1, c1);
450  GfxFillRect(r.left, r.bottom, r.right, r.bottom, c2);
451 }
452 
459 static inline void DrawShadeBox(const Rect &r, Colours colour, bool clicked)
460 {
461  DrawImageButtons(r, WWT_SHADEBOX, colour, clicked, clicked ? SPR_WINDOW_SHADE: SPR_WINDOW_UNSHADE);
462 }
463 
470 static inline void DrawStickyBox(const Rect &r, Colours colour, bool clicked)
471 {
472  DrawImageButtons(r, WWT_STICKYBOX, colour, clicked, clicked ? SPR_PIN_UP : SPR_PIN_DOWN);
473 }
474 
481 static inline void DrawDefSizeBox(const Rect &r, Colours colour, bool clicked)
482 {
483  DrawImageButtons(r, WWT_DEFSIZEBOX, colour, clicked, SPR_WINDOW_DEFSIZE);
484 }
485 
492 static inline void DrawDebugBox(const Rect &r, Colours colour, bool clicked)
493 {
494  DrawImageButtons(r, WWT_DEBUGBOX, colour, clicked, SPR_WINDOW_DEBUG);
495 }
496 
504 static inline void DrawResizeBox(const Rect &r, Colours colour, bool at_left, bool clicked)
505 {
506  DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE);
507  if (at_left) {
508  Dimension d = GetSpriteSize(SPR_WINDOW_RESIZE_LEFT);
509  DrawSprite(SPR_WINDOW_RESIZE_LEFT, PAL_NONE, r.left + WD_RESIZEBOX_RIGHT + clicked,
510  r.bottom + 1 - WD_RESIZEBOX_BOTTOM - d.height + clicked);
511  } else {
512  Dimension d = GetSpriteSize(SPR_WINDOW_RESIZE_RIGHT);
513  DrawSprite(SPR_WINDOW_RESIZE_RIGHT, PAL_NONE, r.right + 1 - WD_RESIZEBOX_RIGHT - d.width + clicked,
514  r.bottom + 1 - WD_RESIZEBOX_BOTTOM - d.height + clicked);
515  }
516 }
517 
523 static inline void DrawCloseBox(const Rect &r, Colours colour)
524 {
525  if (colour != COLOUR_WHITE) DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, FR_NONE);
526  Dimension d = GetSpriteSize(SPR_CLOSEBOX);
527  int s = UnScaleGUI(1); /* Offset to account for shadow of SPR_CLOSEBOX */
528  DrawSprite(SPR_CLOSEBOX, (colour != COLOUR_WHITE ? TC_BLACK : TC_SILVER) | (1 << PALETTE_TEXT_RECOLOUR), CenterBounds(r.left, r.right, d.width - s), CenterBounds(r.top, r.bottom, d.height - s));
529 }
530 
538 void DrawCaption(const Rect &r, Colours colour, Owner owner, StringID str)
539 {
540  bool company_owned = owner < MAX_COMPANIES;
541 
542  DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, FR_BORDERONLY);
543  DrawFrameRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, colour, company_owned ? FR_LOWERED | FR_DARKENED | FR_BORDERONLY : FR_LOWERED | FR_DARKENED);
544 
545  if (company_owned) {
546  GfxFillRect(r.left + 2, r.top + 2, r.right - 2, r.bottom - 2, _colour_gradient[_company_colours[owner]][4]);
547  }
548 
549  if (str != STR_NULL) {
551  int offset = max(0, ((int)(r.bottom - r.top + 1) - (int)d.height) / 2); // Offset for rendering the text vertically centered
552  DrawString(r.left + WD_CAPTIONTEXT_LEFT, r.right - WD_CAPTIONTEXT_RIGHT, r.top + offset, str, TC_FROMSTRING, SA_HOR_CENTER);
553  }
554 }
555 
566 static inline void DrawButtonDropdown(const Rect &r, Colours colour, bool clicked_button, bool clicked_dropdown, StringID str)
567 {
568  int text_offset = max(0, ((int)(r.bottom - r.top + 1) - FONT_HEIGHT_NORMAL) / 2); // Offset for rendering the text vertically centered
569 
570  int dd_width = NWidgetLeaf::dropdown_dimension.width;
571  int dd_height = NWidgetLeaf::dropdown_dimension.height;
572  int image_offset = max(0, ((int)(r.bottom - r.top + 1) - dd_height) / 2);
573 
574  if (_current_text_dir == TD_LTR) {
575  DrawFrameRect(r.left, r.top, r.right - dd_width, r.bottom, colour, clicked_button ? FR_LOWERED : FR_NONE);
576  DrawFrameRect(r.right + 1 - dd_width, r.top, r.right, r.bottom, colour, clicked_dropdown ? FR_LOWERED : FR_NONE);
577  DrawSprite(SPR_ARROW_DOWN, PAL_NONE, r.right - (dd_width - 2) + clicked_dropdown, r.top + image_offset + clicked_dropdown);
578  if (str != STR_NULL) DrawString(r.left + WD_DROPDOWNTEXT_LEFT + clicked_button, r.right - dd_width - WD_DROPDOWNTEXT_RIGHT + clicked_button, r.top + text_offset + clicked_button, str, TC_BLACK);
579  } else {
580  DrawFrameRect(r.left + dd_width, r.top, r.right, r.bottom, colour, clicked_button ? FR_LOWERED : FR_NONE);
581  DrawFrameRect(r.left, r.top, r.left + dd_width - 1, r.bottom, colour, clicked_dropdown ? FR_LOWERED : FR_NONE);
582  DrawSprite(SPR_ARROW_DOWN, PAL_NONE, r.left + 1 + clicked_dropdown, r.top + image_offset + clicked_dropdown);
583  if (str != STR_NULL) DrawString(r.left + dd_width + WD_DROPDOWNTEXT_LEFT + clicked_button, r.right - WD_DROPDOWNTEXT_RIGHT + clicked_button, r.top + text_offset + clicked_button, str, TC_BLACK);
584  }
585 }
586 
594 static inline void DrawDropdown(const Rect &r, Colours colour, bool clicked, StringID str)
595 {
596  DrawButtonDropdown(r, colour, false, clicked, str);
597 }
598 
603 {
604  this->nested_root->Draw(this);
605 
606  if (this->flags & WF_WHITE_BORDER) {
607  DrawFrameRect(0, 0, this->width - 1, this->height - 1, COLOUR_WHITE, FR_BORDERONLY);
608  }
609 
610  if (this->flags & WF_HIGHLIGHTED) {
611  extern bool _window_highlight_colour;
612  for (uint i = 0; i < this->nested_array_size; i++) {
613  const NWidgetBase *widget = this->GetWidget<NWidgetBase>(i);
614  if (widget == nullptr || !widget->IsHighlighted()) continue;
615 
616  int left = widget->pos_x;
617  int top = widget->pos_y;
618  int right = left + widget->current_x - 1;
619  int bottom = top + widget->current_y - 1;
620 
621  int colour = _string_colourmap[_window_highlight_colour ? widget->GetHighlightColour() : TC_WHITE];
622 
623  GfxFillRect(left, top, left, bottom - WD_BEVEL_BOTTOM, colour);
624  GfxFillRect(left + WD_BEVEL_LEFT, top, right - WD_BEVEL_RIGHT, top, colour);
625  GfxFillRect(right, top, right, bottom - WD_BEVEL_BOTTOM, colour);
626  GfxFillRect(left, bottom, right, bottom, colour);
627  }
628  }
629 }
630 
636 void Window::DrawSortButtonState(int widget, SortButtonState state) const
637 {
638  if (state == SBS_OFF) return;
639 
640  assert(this->nested_array != nullptr);
641  const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(widget);
642 
643  /* Sort button uses the same sprites as vertical scrollbar */
644  Dimension dim = NWidgetScrollbar::GetVerticalDimension();
645  int offset = this->IsWidgetLowered(widget) ? 1 : 0;
646  int x = offset + nwid->pos_x + (_current_text_dir == TD_LTR ? nwid->current_x - dim.width : 0);
647  int y = offset + nwid->pos_y + (nwid->current_y - dim.height) / 2;
648 
649  DrawSprite(state == SBS_DOWN ? SPR_ARROW_DOWN : SPR_ARROW_UP, PAL_NONE, x, y);
650 }
651 
657 {
658  return NWidgetScrollbar::GetVerticalDimension().width + 1;
659 }
660 
661 
720 {
721  this->type = tp;
722 }
723 
724 /* ~NWidgetContainer() takes care of #next and #prev data members. */
725 
773 void NWidgetBase::SetDirty(const Window *w) const
774 {
775  int abs_left = w->left + this->pos_x;
776  int abs_top = w->top + this->pos_y;
777  SetDirtyBlocks(abs_left, abs_top, abs_left + this->current_x, abs_top + this->current_y);
778 }
779 
794 {
795  return (this->type == tp) ? this : nullptr;
796 }
797 
805 {
806  this->fill_x = fill_x;
807  this->fill_y = fill_y;
808 }
809 
816 {
817  this->min_x = max(this->min_x, min_x);
818  this->min_y = max(this->min_y, min_y);
819 }
820 
827 void NWidgetResizeBase::SetMinimalTextLines(uint8 min_lines, uint8 spacing, FontSize size)
828 {
829  this->min_y = min_lines * GetCharacterHeight(size) + spacing;
830 }
831 
838 {
839  this->fill_x = fill_x;
840  this->fill_y = fill_y;
841 }
842 
849 {
850  this->resize_x = resize_x;
851  this->resize_y = resize_y;
852 }
853 
854 void NWidgetResizeBase::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
855 {
856  this->StoreSizePosition(sizing, x, y, given_width, given_height);
857 }
858 
868 NWidgetCore::NWidgetCore(WidgetType tp, Colours colour, uint fill_x, uint fill_y, uint32 widget_data, StringID tool_tip) : NWidgetResizeBase(tp, fill_x, fill_y)
869 {
870  this->colour = colour;
871  this->index = -1;
872  this->widget_data = widget_data;
873  this->tool_tip = tool_tip;
874  this->scrollbar_index = -1;
875 }
876 
882 {
883  assert(index >= 0);
884  this->index = index;
885 }
886 
893 {
894  this->widget_data = widget_data;
895  this->tool_tip = tool_tip;
896 }
897 
898 void NWidgetCore::FillNestedArray(NWidgetBase **array, uint length)
899 {
900  if (this->index >= 0 && (uint)(this->index) < length) array[this->index] = this;
901 }
902 
904 {
905  return (IsInsideBS(x, this->pos_x, this->current_x) && IsInsideBS(y, this->pos_y, this->current_y)) ? this : nullptr;
906 }
907 
913 {
914  this->head = nullptr;
915  this->tail = nullptr;
916 }
917 
918 NWidgetContainer::~NWidgetContainer()
919 {
920  while (this->head != nullptr) {
921  NWidgetBase *wid = this->head->next;
922  delete this->head;
923  this->head = wid;
924  }
925  this->tail = nullptr;
926 }
927 
929 {
930  if (this->type == tp) return this;
931  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
932  NWidgetBase *nwid = child_wid->GetWidgetOfType(tp);
933  if (nwid != nullptr) return nwid;
934  }
935  return nullptr;
936 }
937 
943 {
944  assert(wid->next == nullptr && wid->prev == nullptr);
945 
946  if (this->head == nullptr) {
947  this->head = wid;
948  this->tail = wid;
949  } else {
950  assert(this->tail != nullptr);
951  assert(this->tail->next == nullptr);
952 
953  this->tail->next = wid;
954  wid->prev = this->tail;
955  this->tail = wid;
956  }
957 }
958 
960 {
961  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
962  child_wid->FillNestedArray(array, length);
963  }
964 }
965 
970 {
971  this->index = -1;
972 }
973 
974 void NWidgetStacked::SetIndex(int index)
975 {
976  this->index = index;
977 }
978 
979 void NWidgetStacked::SetupSmallestSize(Window *w, bool init_array)
980 {
981  if (this->index >= 0 && init_array) { // Fill w->nested_array[]
982  assert(w->nested_array_size > (uint)this->index);
983  w->nested_array[this->index] = this;
984  }
985 
986  /* Zero size plane selected */
987  if (this->shown_plane >= SZSP_BEGIN) {
988  Dimension size = {0, 0};
989  Dimension padding = {0, 0};
990  Dimension fill = {(this->shown_plane == SZSP_HORIZONTAL), (this->shown_plane == SZSP_VERTICAL)};
991  Dimension resize = {(this->shown_plane == SZSP_HORIZONTAL), (this->shown_plane == SZSP_VERTICAL)};
992  /* Here we're primarily interested in the value of resize */
993  if (this->index >= 0) w->UpdateWidgetSize(this->index, &size, padding, &fill, &resize);
994 
995  this->smallest_x = size.width;
996  this->smallest_y = size.height;
997  this->fill_x = fill.width;
998  this->fill_y = fill.height;
999  this->resize_x = resize.width;
1000  this->resize_y = resize.height;
1001  return;
1002  }
1003 
1004  /* First sweep, recurse down and compute minimal size and filling. */
1005  this->smallest_x = 0;
1006  this->smallest_y = 0;
1007  this->fill_x = (this->head != nullptr) ? 1 : 0;
1008  this->fill_y = (this->head != nullptr) ? 1 : 0;
1009  this->resize_x = (this->head != nullptr) ? 1 : 0;
1010  this->resize_y = (this->head != nullptr) ? 1 : 0;
1011  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1012  child_wid->SetupSmallestSize(w, init_array);
1013 
1014  this->smallest_x = max(this->smallest_x, child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right);
1015  this->smallest_y = max(this->smallest_y, child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom);
1016  this->fill_x = LeastCommonMultiple(this->fill_x, child_wid->fill_x);
1017  this->fill_y = LeastCommonMultiple(this->fill_y, child_wid->fill_y);
1018  this->resize_x = LeastCommonMultiple(this->resize_x, child_wid->resize_x);
1019  this->resize_y = LeastCommonMultiple(this->resize_y, child_wid->resize_y);
1020  }
1021 }
1022 
1023 void NWidgetStacked::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
1024 {
1025  assert(given_width >= this->smallest_x && given_height >= this->smallest_y);
1026  this->StoreSizePosition(sizing, x, y, given_width, given_height);
1027 
1028  if (this->shown_plane >= SZSP_BEGIN) return;
1029 
1030  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1031  uint hor_step = (sizing == ST_SMALLEST) ? 1 : child_wid->GetHorizontalStepSize(sizing);
1032  uint child_width = ComputeMaxSize(child_wid->smallest_x, given_width - child_wid->padding_left - child_wid->padding_right, hor_step);
1033  uint child_pos_x = (rtl ? child_wid->padding_right : child_wid->padding_left);
1034 
1035  uint vert_step = (sizing == ST_SMALLEST) ? 1 : child_wid->GetVerticalStepSize(sizing);
1036  uint child_height = ComputeMaxSize(child_wid->smallest_y, given_height - child_wid->padding_top - child_wid->padding_bottom, vert_step);
1037  uint child_pos_y = child_wid->padding_top;
1038 
1039  child_wid->AssignSizePosition(sizing, x + child_pos_x, y + child_pos_y, child_width, child_height, rtl);
1040  }
1041 }
1042 
1044 {
1045  if (this->index >= 0 && (uint)(this->index) < length) array[this->index] = this;
1046  NWidgetContainer::FillNestedArray(array, length);
1047 }
1048 
1050 {
1051  if (this->shown_plane >= SZSP_BEGIN) return;
1052 
1053  int plane = 0;
1054  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; plane++, child_wid = child_wid->next) {
1055  if (plane == this->shown_plane) {
1056  child_wid->Draw(w);
1057  return;
1058  }
1059  }
1060 
1061  NOT_REACHED();
1062 }
1063 
1065 {
1066  if (this->shown_plane >= SZSP_BEGIN) return nullptr;
1067 
1068  if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return nullptr;
1069  int plane = 0;
1070  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; plane++, child_wid = child_wid->next) {
1071  if (plane == this->shown_plane) {
1072  return child_wid->GetWidgetFromPos(x, y);
1073  }
1074  }
1075  return nullptr;
1076 }
1077 
1083 {
1084  this->shown_plane = plane;
1085 }
1086 
1087 NWidgetPIPContainer::NWidgetPIPContainer(WidgetType tp, NWidContainerFlags flags) : NWidgetContainer(tp)
1088 {
1089  this->flags = flags;
1090 }
1091 
1101 void NWidgetPIPContainer::SetPIP(uint8 pip_pre, uint8 pip_inter, uint8 pip_post)
1102 {
1103  this->pip_pre = pip_pre;
1104  this->pip_inter = pip_inter;
1105  this->pip_post = pip_post;
1106 }
1107 
1109 {
1110  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1111  child_wid->Draw(w);
1112  }
1113 }
1114 
1116 {
1117  if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return nullptr;
1118 
1119  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1120  NWidgetCore *nwid = child_wid->GetWidgetFromPos(x, y);
1121  if (nwid != nullptr) return nwid;
1122  }
1123  return nullptr;
1124 }
1125 
1128 {
1129 }
1130 
1132 {
1133  this->smallest_x = 0; // Sum of minimal size of all children.
1134  this->smallest_y = 0; // Biggest child.
1135  this->fill_x = 0; // smallest non-zero child widget fill step.
1136  this->fill_y = 1; // smallest common child fill step.
1137  this->resize_x = 0; // smallest non-zero child widget resize step.
1138  this->resize_y = 1; // smallest common child resize step.
1139 
1140  /* 1a. Forward call, collect biggest nested array index, and longest/widest child length. */
1141  uint longest = 0; // Longest child found.
1142  uint max_vert_fill = 0; // Biggest vertical fill step.
1143  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1144  child_wid->SetupSmallestSize(w, init_array);
1145  longest = max(longest, child_wid->smallest_x);
1146  max_vert_fill = max(max_vert_fill, child_wid->GetVerticalStepSize(ST_SMALLEST));
1147  this->smallest_y = max(this->smallest_y, child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom);
1148  }
1149  /* 1b. Make the container higher if needed to accommodate all children nicely. */
1150  uint max_smallest = this->smallest_y + 3 * max_vert_fill; // Upper limit to computing smallest height.
1151  uint cur_height = this->smallest_y;
1152  for (;;) {
1153  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1154  uint step_size = child_wid->GetVerticalStepSize(ST_SMALLEST);
1155  uint child_height = child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom;
1156  if (step_size > 1 && child_height < cur_height) { // Small step sizes or already fitting children are not interesting.
1157  uint remainder = (cur_height - child_height) % step_size;
1158  if (remainder > 0) { // Child did not fit entirely, widen the container.
1159  cur_height += step_size - remainder;
1160  assert(cur_height < max_smallest); // Safeguard against infinite height expansion.
1161  /* Remaining children will adapt to the new cur_height, thus speeding up the computation. */
1162  }
1163  }
1164  }
1165  if (this->smallest_y == cur_height) break;
1166  this->smallest_y = cur_height; // Smallest height got changed, try again.
1167  }
1168  /* 2. For containers that must maintain equal width, extend child minimal size. */
1169  if (this->flags & NC_EQUALSIZE) {
1170  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1171  if (child_wid->fill_x == 1) child_wid->smallest_x = longest;
1172  }
1173  }
1174  /* 3. Move PIP space to the children, compute smallest, fill, and resize values of the container. */
1175  if (this->head != nullptr) this->head->padding_left += this->pip_pre;
1176  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1177  if (child_wid->next != nullptr) {
1178  child_wid->padding_right += this->pip_inter;
1179  } else {
1180  child_wid->padding_right += this->pip_post;
1181  }
1182 
1183  this->smallest_x += child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right;
1184  if (child_wid->fill_x > 0) {
1185  if (this->fill_x == 0 || this->fill_x > child_wid->fill_x) this->fill_x = child_wid->fill_x;
1186  }
1187  this->fill_y = LeastCommonMultiple(this->fill_y, child_wid->fill_y);
1188 
1189  if (child_wid->resize_x > 0) {
1190  if (this->resize_x == 0 || this->resize_x > child_wid->resize_x) this->resize_x = child_wid->resize_x;
1191  }
1192  this->resize_y = LeastCommonMultiple(this->resize_y, child_wid->resize_y);
1193  }
1194  /* We need to zero the PIP settings so we can re-initialize the tree. */
1195  this->pip_pre = this->pip_inter = this->pip_post = 0;
1196 }
1197 
1198 void NWidgetHorizontal::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
1199 {
1200  assert(given_width >= this->smallest_x && given_height >= this->smallest_y);
1201 
1202  /* Compute additional width given to us. */
1203  uint additional_length = given_width;
1204  if (sizing == ST_SMALLEST && (this->flags & NC_EQUALSIZE)) {
1205  /* For EQUALSIZE containers this does not sum to smallest_x during initialisation */
1206  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1207  additional_length -= child_wid->smallest_x + child_wid->padding_right + child_wid->padding_left;
1208  }
1209  } else {
1210  additional_length -= this->smallest_x;
1211  }
1212 
1213  this->StoreSizePosition(sizing, x, y, given_width, given_height);
1214 
1215  /* In principle, the additional horizontal space is distributed evenly over the available resizable children. Due to step sizes, this may not always be feasible.
1216  * To make resizing work as good as possible, first children with biggest step sizes are done. These may get less due to rounding down.
1217  * This additional space is then given to children with smaller step sizes. This will give a good result when resize steps of each child is a multiple
1218  * of the child with the smallest non-zero stepsize.
1219  *
1220  * Since child sizes are computed out of order, positions cannot be calculated until all sizes are known. That means it is not possible to compute the child
1221  * size and position, and directly call child->AssignSizePosition() with the computed values.
1222  * Instead, computed child widths and heights are stored in child->current_x and child->current_y values. That is allowed, since this method overwrites those values
1223  * then we call the child.
1224  */
1225 
1226  /* First loop: Find biggest stepsize, find number of children that want a piece of the pie, handle vertical size for all children,
1227  * handle horizontal size for non-resizing children.
1228  */
1229  int num_changing_childs = 0; // Number of children that can change size.
1230  uint biggest_stepsize = 0;
1231  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1232  uint hor_step = child_wid->GetHorizontalStepSize(sizing);
1233  if (hor_step > 0) {
1234  num_changing_childs++;
1235  biggest_stepsize = max(biggest_stepsize, hor_step);
1236  } else {
1237  child_wid->current_x = child_wid->smallest_x;
1238  }
1239 
1240  uint vert_step = (sizing == ST_SMALLEST) ? 1 : child_wid->GetVerticalStepSize(sizing);
1241  child_wid->current_y = ComputeMaxSize(child_wid->smallest_y, given_height - child_wid->padding_top - child_wid->padding_bottom, vert_step);
1242  }
1243 
1244  /* Second loop: Allocate the additional horizontal space over the resizing children, starting with the biggest resize steps. */
1245  while (biggest_stepsize > 0) {
1246  uint next_biggest_stepsize = 0;
1247  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1248  uint hor_step = child_wid->GetHorizontalStepSize(sizing);
1249  if (hor_step > biggest_stepsize) continue; // Already done
1250  if (hor_step == biggest_stepsize) {
1251  uint increment = additional_length / num_changing_childs;
1252  num_changing_childs--;
1253  if (hor_step > 1) increment -= increment % hor_step;
1254  child_wid->current_x = child_wid->smallest_x + increment;
1255  additional_length -= increment;
1256  continue;
1257  }
1258  next_biggest_stepsize = max(next_biggest_stepsize, hor_step);
1259  }
1260  biggest_stepsize = next_biggest_stepsize;
1261  }
1262  assert(num_changing_childs == 0);
1263 
1264  /* Third loop: Compute position and call the child. */
1265  uint position = rtl ? this->current_x : 0; // Place to put next child relative to origin of the container.
1266  NWidgetBase *child_wid = this->head;
1267  while (child_wid != nullptr) {
1268  uint child_width = child_wid->current_x;
1269  uint child_x = x + (rtl ? position - child_width - child_wid->padding_left : position + child_wid->padding_left);
1270  uint child_y = y + child_wid->padding_top;
1271 
1272  child_wid->AssignSizePosition(sizing, child_x, child_y, child_width, child_wid->current_y, rtl);
1273  uint padded_child_width = child_width + child_wid->padding_right + child_wid->padding_left;
1274  position = rtl ? position - padded_child_width : position + padded_child_width;
1275 
1276  child_wid = child_wid->next;
1277  }
1278 }
1279 
1282 {
1283  this->type = NWID_HORIZONTAL_LTR;
1284 }
1285 
1286 void NWidgetHorizontalLTR::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
1287 {
1288  NWidgetHorizontal::AssignSizePosition(sizing, x, y, given_width, given_height, false);
1289 }
1290 
1293 {
1294 }
1295 
1297 {
1298  this->smallest_x = 0; // Biggest child.
1299  this->smallest_y = 0; // Sum of minimal size of all children.
1300  this->fill_x = 1; // smallest common child fill step.
1301  this->fill_y = 0; // smallest non-zero child widget fill step.
1302  this->resize_x = 1; // smallest common child resize step.
1303  this->resize_y = 0; // smallest non-zero child widget resize step.
1304 
1305  /* 1a. Forward call, collect biggest nested array index, and longest/widest child length. */
1306  uint highest = 0; // Highest child found.
1307  uint max_hor_fill = 0; // Biggest horizontal fill step.
1308  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1309  child_wid->SetupSmallestSize(w, init_array);
1310  highest = max(highest, child_wid->smallest_y);
1311  max_hor_fill = max(max_hor_fill, child_wid->GetHorizontalStepSize(ST_SMALLEST));
1312  this->smallest_x = max(this->smallest_x, child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right);
1313  }
1314  /* 1b. Make the container wider if needed to accommodate all children nicely. */
1315  uint max_smallest = this->smallest_x + 3 * max_hor_fill; // Upper limit to computing smallest height.
1316  uint cur_width = this->smallest_x;
1317  for (;;) {
1318  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1319  uint step_size = child_wid->GetHorizontalStepSize(ST_SMALLEST);
1320  uint child_width = child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right;
1321  if (step_size > 1 && child_width < cur_width) { // Small step sizes or already fitting children are not interesting.
1322  uint remainder = (cur_width - child_width) % step_size;
1323  if (remainder > 0) { // Child did not fit entirely, widen the container.
1324  cur_width += step_size - remainder;
1325  assert(cur_width < max_smallest); // Safeguard against infinite width expansion.
1326  /* Remaining children will adapt to the new cur_width, thus speeding up the computation. */
1327  }
1328  }
1329  }
1330  if (this->smallest_x == cur_width) break;
1331  this->smallest_x = cur_width; // Smallest width got changed, try again.
1332  }
1333  /* 2. For containers that must maintain equal width, extend children minimal size. */
1334  if (this->flags & NC_EQUALSIZE) {
1335  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1336  if (child_wid->fill_y == 1) child_wid->smallest_y = highest;
1337  }
1338  }
1339  /* 3. Move PIP space to the child, compute smallest, fill, and resize values of the container. */
1340  if (this->head != nullptr) this->head->padding_top += this->pip_pre;
1341  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1342  if (child_wid->next != nullptr) {
1343  child_wid->padding_bottom += this->pip_inter;
1344  } else {
1345  child_wid->padding_bottom += this->pip_post;
1346  }
1347 
1348  this->smallest_y += child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom;
1349  if (child_wid->fill_y > 0) {
1350  if (this->fill_y == 0 || this->fill_y > child_wid->fill_y) this->fill_y = child_wid->fill_y;
1351  }
1352  this->fill_x = LeastCommonMultiple(this->fill_x, child_wid->fill_x);
1353 
1354  if (child_wid->resize_y > 0) {
1355  if (this->resize_y == 0 || this->resize_y > child_wid->resize_y) this->resize_y = child_wid->resize_y;
1356  }
1357  this->resize_x = LeastCommonMultiple(this->resize_x, child_wid->resize_x);
1358  }
1359  /* We need to zero the PIP settings so we can re-initialize the tree. */
1360  this->pip_pre = this->pip_inter = this->pip_post = 0;
1361 }
1362 
1363 void NWidgetVertical::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
1364 {
1365  assert(given_width >= this->smallest_x && given_height >= this->smallest_y);
1366 
1367  /* Compute additional height given to us. */
1368  uint additional_length = given_height;
1369  if (sizing == ST_SMALLEST && (this->flags & NC_EQUALSIZE)) {
1370  /* For EQUALSIZE containers this does not sum to smallest_y during initialisation */
1371  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1372  additional_length -= child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom;
1373  }
1374  } else {
1375  additional_length -= this->smallest_y;
1376  }
1377 
1378  this->StoreSizePosition(sizing, x, y, given_width, given_height);
1379 
1380  /* Like the horizontal container, the vertical container also distributes additional height evenly, starting with the children with the biggest resize steps.
1381  * It also stores computed widths and heights into current_x and current_y values of the child.
1382  */
1383 
1384  /* First loop: Find biggest stepsize, find number of children that want a piece of the pie, handle horizontal size for all children, handle vertical size for non-resizing child. */
1385  int num_changing_childs = 0; // Number of children that can change size.
1386  uint biggest_stepsize = 0;
1387  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1388  uint vert_step = child_wid->GetVerticalStepSize(sizing);
1389  if (vert_step > 0) {
1390  num_changing_childs++;
1391  biggest_stepsize = max(biggest_stepsize, vert_step);
1392  } else {
1393  child_wid->current_y = child_wid->smallest_y;
1394  }
1395 
1396  uint hor_step = (sizing == ST_SMALLEST) ? 1 : child_wid->GetHorizontalStepSize(sizing);
1397  child_wid->current_x = ComputeMaxSize(child_wid->smallest_x, given_width - child_wid->padding_left - child_wid->padding_right, hor_step);
1398  }
1399 
1400  /* Second loop: Allocate the additional vertical space over the resizing children, starting with the biggest resize steps. */
1401  while (biggest_stepsize > 0) {
1402  uint next_biggest_stepsize = 0;
1403  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1404  uint vert_step = child_wid->GetVerticalStepSize(sizing);
1405  if (vert_step > biggest_stepsize) continue; // Already done
1406  if (vert_step == biggest_stepsize) {
1407  uint increment = additional_length / num_changing_childs;
1408  num_changing_childs--;
1409  if (vert_step > 1) increment -= increment % vert_step;
1410  child_wid->current_y = child_wid->smallest_y + increment;
1411  additional_length -= increment;
1412  continue;
1413  }
1414  next_biggest_stepsize = max(next_biggest_stepsize, vert_step);
1415  }
1416  biggest_stepsize = next_biggest_stepsize;
1417  }
1418  assert(num_changing_childs == 0);
1419 
1420  /* Third loop: Compute position and call the child. */
1421  uint position = 0; // Place to put next child relative to origin of the container.
1422  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1423  uint child_x = x + (rtl ? child_wid->padding_right : child_wid->padding_left);
1424  uint child_height = child_wid->current_y;
1425 
1426  child_wid->AssignSizePosition(sizing, child_x, y + position + child_wid->padding_top, child_wid->current_x, child_height, rtl);
1427  position += child_height + child_wid->padding_top + child_wid->padding_bottom;
1428  }
1429 }
1430 
1437 {
1438  this->SetMinimalSize(length, height);
1439  this->SetResize(0, 0);
1440 }
1441 
1442 void NWidgetSpacer::SetupSmallestSize(Window *w, bool init_array)
1443 {
1444  this->smallest_x = this->min_x;
1445  this->smallest_y = this->min_y;
1446 }
1447 
1449 {
1450 }
1451 
1453 {
1454  /* Spacer widget is never visible. */
1455 }
1456 
1457 void NWidgetSpacer::SetDirty(const Window *w) const
1458 {
1459  /* Spacer widget never need repainting. */
1460 }
1461 
1463 {
1464  return nullptr;
1465 }
1466 
1467 NWidgetMatrix::NWidgetMatrix() : NWidgetPIPContainer(NWID_MATRIX, NC_EQUALSIZE), index(-1), clicked(-1), count(-1)
1468 {
1469 }
1470 
1471 void NWidgetMatrix::SetIndex(int index)
1472 {
1473  this->index = index;
1474 }
1475 
1476 void NWidgetMatrix::SetColour(Colours colour)
1477 {
1478  this->colour = colour;
1479 }
1480 
1485 void NWidgetMatrix::SetClicked(int clicked)
1486 {
1487  this->clicked = clicked;
1488  if (this->clicked >= 0 && this->sb != nullptr && this->widgets_x != 0) {
1489  int vpos = (this->clicked / this->widgets_x) * this->widget_h; // Vertical position of the top.
1490  /* Need to scroll down -> Scroll to the bottom.
1491  * However, last entry has no 'this->pip_inter' underneath, and we must stay below this->sb->GetCount() */
1492  if (this->sb->GetPosition() < vpos) vpos += this->widget_h - this->pip_inter - 1;
1493  this->sb->ScrollTowards(vpos);
1494  }
1495 }
1496 
1503 {
1504  this->count = count;
1505 
1506  if (this->sb == nullptr || this->widgets_x == 0) return;
1507 
1508  /* We need to get the number of pixels the matrix is high/wide.
1509  * So, determine the number of rows/columns based on the number of
1510  * columns/rows (one is constant/unscrollable).
1511  * Then multiply that by the height of a widget, and add the pre
1512  * and post spacing "offsets". */
1513  count = CeilDiv(count, this->sb->IsVertical() ? this->widgets_x : this->widgets_y);
1514  count *= (this->sb->IsVertical() ? this->head->smallest_y : this->head->smallest_x) + this->pip_inter;
1515  if (count > 0) count -= this->pip_inter; // We counted an inter too much in the multiplication above
1516  count += this->pip_pre + this->pip_post;
1517  this->sb->SetCount(count);
1518  this->sb->SetCapacity(this->sb->IsVertical() ? this->current_y : this->current_x);
1519  this->sb->SetStepSize(this->sb->IsVertical() ? this->widget_h : this->widget_w);
1520 }
1521 
1527 {
1528  this->sb = sb;
1529 }
1530 
1531 void NWidgetMatrix::SetupSmallestSize(Window *w, bool init_array)
1532 {
1533  assert(this->head != nullptr);
1534  assert(this->head->next == nullptr);
1535 
1536  if (this->index >= 0 && init_array) { // Fill w->nested_array[]
1537  assert(w->nested_array_size > (uint)this->index);
1538  w->nested_array[this->index] = this;
1539  }
1540 
1541  /* Reset the widget number. */
1542  NWidgetCore *nw = dynamic_cast<NWidgetCore *>(this->head);
1543  assert(nw != nullptr);
1544  SB(nw->index, 16, 16, 0);
1545  this->head->SetupSmallestSize(w, init_array);
1546 
1547  Dimension padding = { (uint)this->pip_pre + this->pip_post, (uint)this->pip_pre + this->pip_post};
1548  Dimension size = {this->head->smallest_x + padding.width, this->head->smallest_y + padding.height};
1549  Dimension fill = {0, 0};
1550  Dimension resize = {this->pip_inter + this->head->smallest_x, this->pip_inter + this->head->smallest_y};
1551 
1552  if (this->index >= 0) w->UpdateWidgetSize(this->index, &size, padding, &fill, &resize);
1553 
1554  this->smallest_x = size.width;
1555  this->smallest_y = size.height;
1556  this->fill_x = fill.width;
1557  this->fill_y = fill.height;
1558  this->resize_x = resize.width;
1559  this->resize_y = resize.height;
1560 }
1561 
1562 void NWidgetMatrix::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
1563 {
1564  assert(given_width >= this->smallest_x && given_height >= this->smallest_y);
1565 
1566  this->pos_x = x;
1567  this->pos_y = y;
1568  this->current_x = given_width;
1569  this->current_y = given_height;
1570 
1571  /* Determine the size of the widgets, and the number of visible widgets on each of the axis. */
1572  this->widget_w = this->head->smallest_x + this->pip_inter;
1573  this->widget_h = this->head->smallest_y + this->pip_inter;
1574 
1575  /* Account for the pip_inter is between widgets, so we need to account for that when
1576  * the division assumes pip_inter is used for all widgets. */
1577  this->widgets_x = CeilDiv(this->current_x - this->pip_pre - this->pip_post + this->pip_inter, this->widget_w);
1578  this->widgets_y = CeilDiv(this->current_y - this->pip_pre - this->pip_post + this->pip_inter, this->widget_h);
1579 
1580  /* When resizing, update the scrollbar's count. E.g. with a vertical
1581  * scrollbar becoming wider or narrower means the amount of rows in
1582  * the scrollbar becomes respectively smaller or higher. */
1583  this->SetCount(this->count);
1584 }
1585 
1587 {
1588  if (this->index >= 0 && (uint)(this->index) < length) array[this->index] = this;
1589  NWidgetContainer::FillNestedArray(array, length);
1590 }
1591 
1593 {
1594  /* Falls outside of the matrix widget. */
1595  if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return nullptr;
1596 
1597  int start_x, start_y, base_offs_x, base_offs_y;
1598  this->GetScrollOffsets(start_x, start_y, base_offs_x, base_offs_y);
1599 
1600  bool rtl = _current_text_dir == TD_RTL;
1601 
1602  int widget_col = (rtl ?
1603  -x + (int)this->pip_post + (int)this->pos_x + base_offs_x + (int)this->widget_w - 1 - (int)this->pip_inter :
1604  x - (int)this->pip_pre - (int)this->pos_x - base_offs_x
1605  ) / this->widget_w;
1606 
1607  int widget_row = (y - base_offs_y - (int)this->pip_pre - (int)this->pos_y) / this->widget_h;
1608 
1609  int sub_wid = (widget_row + start_y) * this->widgets_x + start_x + widget_col;
1610  if (sub_wid >= this->count) return nullptr;
1611 
1612  NWidgetCore *child = dynamic_cast<NWidgetCore *>(this->head);
1613  assert(child != nullptr);
1615  this->pos_x + (rtl ? this->pip_post - widget_col * this->widget_w : this->pip_pre + widget_col * this->widget_w) + base_offs_x,
1616  this->pos_y + this->pip_pre + widget_row * this->widget_h + base_offs_y,
1617  child->smallest_x, child->smallest_y, rtl);
1618 
1619  SB(child->index, 16, 16, sub_wid);
1620 
1621  return child->GetWidgetFromPos(x, y);
1622 }
1623 
1624 /* virtual */ void NWidgetMatrix::Draw(const Window *w)
1625 {
1626  /* Fill the background. */
1627  GfxFillRect(this->pos_x, this->pos_y, this->pos_x + this->current_x - 1, this->pos_y + this->current_y - 1, _colour_gradient[this->colour & 0xF][5]);
1628 
1629  /* Set up a clipping area for the previews. */
1630  bool rtl = _current_text_dir == TD_RTL;
1631  DrawPixelInfo tmp_dpi;
1632  if (!FillDrawPixelInfo(&tmp_dpi, this->pos_x + (rtl ? this->pip_post : this->pip_pre), this->pos_y + this->pip_pre, this->current_x - this->pip_pre - this->pip_post, this->current_y - this->pip_pre - this->pip_post)) return;
1633  DrawPixelInfo *old_dpi = _cur_dpi;
1634  _cur_dpi = &tmp_dpi;
1635 
1636  /* Get the appropriate offsets so we can draw the right widgets. */
1637  NWidgetCore *child = dynamic_cast<NWidgetCore *>(this->head);
1638  assert(child != nullptr);
1639  int start_x, start_y, base_offs_x, base_offs_y;
1640  this->GetScrollOffsets(start_x, start_y, base_offs_x, base_offs_y);
1641 
1642  int offs_y = base_offs_y;
1643  for (int y = start_y; y < start_y + this->widgets_y + 1; y++, offs_y += this->widget_h) {
1644  /* Are we within bounds? */
1645  if (offs_y + child->smallest_y <= 0) continue;
1646  if (offs_y >= (int)this->current_y) break;
1647 
1648  /* We've passed our amount of widgets. */
1649  if (y * this->widgets_x >= this->count) break;
1650 
1651  int offs_x = base_offs_x;
1652  for (int x = start_x; x < start_x + this->widgets_x + 1; x++, offs_x += rtl ? -this->widget_w : this->widget_w) {
1653  /* Are we within bounds? */
1654  if (offs_x + child->smallest_x <= 0) continue;
1655  if (offs_x >= (int)this->current_x) continue;
1656 
1657  /* Do we have this many widgets? */
1658  int sub_wid = y * this->widgets_x + x;
1659  if (sub_wid >= this->count) break;
1660 
1661  child->AssignSizePosition(ST_RESIZE, offs_x, offs_y, child->smallest_x, child->smallest_y, rtl);
1662  child->SetLowered(this->clicked == sub_wid);
1663  SB(child->index, 16, 16, sub_wid);
1664  child->Draw(w);
1665  }
1666  }
1667 
1668  /* Restore the clipping area. */
1669  _cur_dpi = old_dpi;
1670 }
1671 
1679 void NWidgetMatrix::GetScrollOffsets(int &start_x, int &start_y, int &base_offs_x, int &base_offs_y)
1680 {
1681  base_offs_x = _current_text_dir == TD_RTL ? this->widget_w * (this->widgets_x - 1) : 0;
1682  base_offs_y = 0;
1683  start_x = 0;
1684  start_y = 0;
1685  if (this->sb != nullptr) {
1686  if (this->sb->IsVertical()) {
1687  start_y = this->sb->GetPosition() / this->widget_h;
1688  base_offs_y += -this->sb->GetPosition() + start_y * this->widget_h;
1689  } else {
1690  start_x = this->sb->GetPosition() / this->widget_w;
1691  int sub_x = this->sb->GetPosition() - start_x * this->widget_w;
1692  if (_current_text_dir == TD_RTL) {
1693  base_offs_x += sub_x;
1694  } else {
1695  base_offs_x -= sub_x;
1696  }
1697  }
1698  }
1699 }
1700 
1710 NWidgetBackground::NWidgetBackground(WidgetType tp, Colours colour, int index, NWidgetPIPContainer *child) : NWidgetCore(tp, colour, 1, 1, 0x0, STR_NULL)
1711 {
1712  assert(tp == WWT_PANEL || tp == WWT_INSET || tp == WWT_FRAME);
1713  if (index >= 0) this->SetIndex(index);
1714  this->child = child;
1715 }
1716 
1717 NWidgetBackground::~NWidgetBackground()
1718 {
1719  if (this->child != nullptr) delete this->child;
1720 }
1721 
1730 {
1731  if (this->child == nullptr) {
1732  this->child = new NWidgetVertical();
1733  }
1734  this->child->Add(nwid);
1735 }
1736 
1747 void NWidgetBackground::SetPIP(uint8 pip_pre, uint8 pip_inter, uint8 pip_post)
1748 {
1749  if (this->child == nullptr) {
1750  this->child = new NWidgetVertical();
1751  }
1752  this->child->SetPIP(pip_pre, pip_inter, pip_post);
1753 }
1754 
1756 {
1757  if (init_array && this->index >= 0) {
1758  assert(w->nested_array_size > (uint)this->index);
1759  w->nested_array[this->index] = this;
1760  }
1761  if (this->child != nullptr) {
1762  this->child->SetupSmallestSize(w, init_array);
1763 
1764  this->smallest_x = this->child->smallest_x;
1765  this->smallest_y = this->child->smallest_y;
1766  this->fill_x = this->child->fill_x;
1767  this->fill_y = this->child->fill_y;
1768  this->resize_x = this->child->resize_x;
1769  this->resize_y = this->child->resize_y;
1770 
1771  /* Account for the size of the frame's text if that exists */
1772  if (w != nullptr && this->type == WWT_FRAME) {
1775  this->child->padding_top = max((int)WD_FRAMETEXT_TOP, this->widget_data != STR_NULL ? FONT_HEIGHT_NORMAL + WD_FRAMETEXT_TOP / 2 : 0);
1777 
1778  this->smallest_x += this->child->padding_left + this->child->padding_right;
1779  this->smallest_y += this->child->padding_top + this->child->padding_bottom;
1780 
1781  if (this->index >= 0) w->SetStringParameters(this->index);
1783  }
1784  } else {
1785  Dimension d = {this->min_x, this->min_y};
1786  Dimension fill = {this->fill_x, this->fill_y};
1787  Dimension resize = {this->resize_x, this->resize_y};
1788  if (w != nullptr) { // A non-nullptr window pointer acts as switch to turn dynamic widget size on.
1789  if (this->type == WWT_FRAME || this->type == WWT_INSET) {
1790  if (this->index >= 0) w->SetStringParameters(this->index);
1791  Dimension background = GetStringBoundingBox(this->widget_data);
1792  background.width += (this->type == WWT_FRAME) ? (WD_FRAMETEXT_LEFT + WD_FRAMERECT_RIGHT) : (WD_INSET_LEFT + WD_INSET_RIGHT);
1793  d = maxdim(d, background);
1794  }
1795  if (this->index >= 0) {
1796  static const Dimension padding = {0, 0};
1797  w->UpdateWidgetSize(this->index, &d, padding, &fill, &resize);
1798  }
1799  }
1800  this->smallest_x = d.width;
1801  this->smallest_y = d.height;
1802  this->fill_x = fill.width;
1803  this->fill_y = fill.height;
1804  this->resize_x = resize.width;
1805  this->resize_y = resize.height;
1806  }
1807 }
1808 
1809 void NWidgetBackground::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
1810 {
1811  this->StoreSizePosition(sizing, x, y, given_width, given_height);
1812 
1813  if (this->child != nullptr) {
1814  uint x_offset = (rtl ? this->child->padding_right : this->child->padding_left);
1815  uint width = given_width - this->child->padding_right - this->child->padding_left;
1816  uint height = given_height - this->child->padding_top - this->child->padding_bottom;
1817  this->child->AssignSizePosition(sizing, x + x_offset, y + this->child->padding_top, width, height, rtl);
1818  }
1819 }
1820 
1822 {
1823  if (this->index >= 0 && (uint)(this->index) < length) array[this->index] = this;
1824  if (this->child != nullptr) this->child->FillNestedArray(array, length);
1825 }
1826 
1828 {
1829  if (this->current_x == 0 || this->current_y == 0) return;
1830 
1831  Rect r;
1832  r.left = this->pos_x;
1833  r.right = this->pos_x + this->current_x - 1;
1834  r.top = this->pos_y;
1835  r.bottom = this->pos_y + this->current_y - 1;
1836 
1837  const DrawPixelInfo *dpi = _cur_dpi;
1838  if (dpi->left > r.right || dpi->left + dpi->width <= r.left || dpi->top > r.bottom || dpi->top + dpi->height <= r.top) return;
1839 
1840  switch (this->type) {
1841  case WWT_PANEL:
1842  assert(this->widget_data == 0);
1843  DrawFrameRect(r.left, r.top, r.right, r.bottom, this->colour, this->IsLowered() ? FR_LOWERED : FR_NONE);
1844  break;
1845 
1846  case WWT_FRAME:
1847  if (this->index >= 0) w->SetStringParameters(this->index);
1848  DrawFrame(r, this->colour, this->widget_data);
1849  break;
1850 
1851  case WWT_INSET:
1852  if (this->index >= 0) w->SetStringParameters(this->index);
1853  DrawInset(r, this->colour, this->widget_data);
1854  break;
1855 
1856  default:
1857  NOT_REACHED();
1858  }
1859 
1860  if (this->index >= 0) w->DrawWidget(r, this->index);
1861  if (this->child != nullptr) this->child->Draw(w);
1862 
1863  if (this->IsDisabled()) {
1864  GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, _colour_gradient[this->colour & 0xF][2], FILLRECT_CHECKER);
1865  }
1866 }
1867 
1869 {
1870  NWidgetCore *nwid = nullptr;
1871  if (IsInsideBS(x, this->pos_x, this->current_x) && IsInsideBS(y, this->pos_y, this->current_y)) {
1872  if (this->child != nullptr) nwid = this->child->GetWidgetFromPos(x, y);
1873  if (nwid == nullptr) nwid = this;
1874  }
1875  return nwid;
1876 }
1877 
1879 {
1880  NWidgetBase *nwid = nullptr;
1881  if (this->child != nullptr) nwid = this->child->GetWidgetOfType(tp);
1882  if (nwid == nullptr && this->type == tp) nwid = this;
1883  return nwid;
1884 }
1885 
1886 NWidgetViewport::NWidgetViewport(int index) : NWidgetCore(NWID_VIEWPORT, INVALID_COLOUR, 1, 1, 0x0, STR_NULL)
1887 {
1888  this->SetIndex(index);
1889 }
1890 
1892 {
1893  if (init_array && this->index >= 0) {
1894  assert(w->nested_array_size > (uint)this->index);
1895  w->nested_array[this->index] = this;
1896  }
1897  this->smallest_x = this->min_x;
1898  this->smallest_y = this->min_y;
1899 }
1900 
1902 {
1903  if (this->disp_flags & ND_NO_TRANSPARENCY) {
1905  _transparency_opt &= (1 << TO_SIGNS) | (1 << TO_LOADING); // Disable all transparency, except textual stuff
1906  w->DrawViewport();
1907  _transparency_opt = to_backup;
1908  } else {
1909  w->DrawViewport();
1910  }
1911 
1912  /* Optionally shade the viewport. */
1913  if (this->disp_flags & (ND_SHADE_GREY | ND_SHADE_DIMMED)) {
1914  GfxFillRect(this->pos_x, this->pos_y, this->pos_x + this->current_x - 1, this->pos_y + this->current_y - 1,
1916  }
1917 }
1918 
1925 void NWidgetViewport::InitializeViewport(Window *w, uint32 follow_flags, ZoomLevel zoom)
1926 {
1927  InitializeWindowViewport(w, this->pos_x, this->pos_y, this->current_x, this->current_y, follow_flags, zoom);
1928 }
1929 
1935 {
1936  ViewPort *vp = w->viewport;
1937  if (vp != nullptr) {
1938  vp->left = w->left + this->pos_x;
1939  vp->top = w->top + this->pos_y;
1940  vp->width = this->current_x;
1941  vp->height = this->current_y;
1942 
1943  vp->virtual_width = ScaleByZoom(vp->width, vp->zoom);
1944  vp->virtual_height = ScaleByZoom(vp->height, vp->zoom);
1945  }
1946 }
1947 
1957 int Scrollbar::GetScrolledRowFromWidget(int clickpos, const Window * const w, int widget, int padding, int line_height) const
1958 {
1959  uint pos = w->GetRowFromWidget(clickpos, widget, padding, line_height);
1960  if (pos != INT_MAX) pos += this->GetPosition();
1961  return (pos >= this->GetCount()) ? INT_MAX : pos;
1962 }
1963 
1971 void Scrollbar::SetCapacityFromWidget(Window *w, int widget, int padding)
1972 {
1973  NWidgetBase *nwid = w->GetWidget<NWidgetBase>(widget);
1974  if (this->IsVertical()) {
1975  this->SetCapacity(((int)nwid->current_y - padding) / (int)nwid->resize_y);
1976  } else {
1977  this->SetCapacity(((int)nwid->current_x - padding) / (int)nwid->resize_x);
1978  }
1979 }
1980 
1987 NWidgetScrollbar::NWidgetScrollbar(WidgetType tp, Colours colour, int index) : NWidgetCore(tp, colour, 1, 1, 0x0, STR_NULL), Scrollbar(tp != NWID_HSCROLLBAR)
1988 {
1989  assert(tp == NWID_HSCROLLBAR || tp == NWID_VSCROLLBAR);
1990  this->SetIndex(index);
1991 }
1992 
1994 {
1995  if (init_array && this->index >= 0) {
1996  assert(w->nested_array_size > (uint)this->index);
1997  w->nested_array[this->index] = this;
1998  }
1999  this->min_x = 0;
2000  this->min_y = 0;
2001 
2002  switch (this->type) {
2003  case NWID_HSCROLLBAR:
2004  this->SetMinimalSize(NWidgetScrollbar::GetHorizontalDimension().width * 3, NWidgetScrollbar::GetHorizontalDimension().height);
2005  this->SetResize(1, 0);
2006  this->SetFill(1, 0);
2007  this->SetDataTip(0x0, STR_TOOLTIP_HSCROLL_BAR_SCROLLS_LIST);
2008  break;
2009 
2010  case NWID_VSCROLLBAR:
2011  this->SetMinimalSize(NWidgetScrollbar::GetVerticalDimension().width, NWidgetScrollbar::GetVerticalDimension().height * 3);
2012  this->SetResize(0, 1);
2013  this->SetFill(0, 1);
2014  this->SetDataTip(0x0, STR_TOOLTIP_VSCROLL_BAR_SCROLLS_LIST);
2015  break;
2016 
2017  default: NOT_REACHED();
2018  }
2019 
2020  this->smallest_x = this->min_x;
2021  this->smallest_y = this->min_y;
2022 }
2023 
2025 {
2026  if (this->current_x == 0 || this->current_y == 0) return;
2027 
2028  Rect r;
2029  r.left = this->pos_x;
2030  r.right = this->pos_x + this->current_x - 1;
2031  r.top = this->pos_y;
2032  r.bottom = this->pos_y + this->current_y - 1;
2033 
2034  const DrawPixelInfo *dpi = _cur_dpi;
2035  if (dpi->left > r.right || dpi->left + dpi->width <= r.left || dpi->top > r.bottom || dpi->top + dpi->height <= r.top) return;
2036 
2037  bool up_lowered = HasBit(this->disp_flags, NDB_SCROLLBAR_UP);
2038  bool down_lowered = HasBit(this->disp_flags, NDB_SCROLLBAR_DOWN);
2039  bool middle_lowered = !(this->disp_flags & ND_SCROLLBAR_BTN) && w->mouse_capture_widget == this->index;
2040 
2041  if (this->type == NWID_HSCROLLBAR) {
2042  DrawHorizontalScrollbar(r, this->colour, up_lowered, middle_lowered, down_lowered, this);
2043  } else {
2044  DrawVerticalScrollbar(r, this->colour, up_lowered, middle_lowered, down_lowered, this);
2045  }
2046 
2047  if (this->IsDisabled()) {
2048  GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, _colour_gradient[this->colour & 0xF][2], FILLRECT_CHECKER);
2049  }
2050 }
2051 
2052 /* static */ void NWidgetScrollbar::InvalidateDimensionCache()
2053 {
2054  vertical_dimension.width = vertical_dimension.height = 0;
2055  horizontal_dimension.width = horizontal_dimension.height = 0;
2056 }
2057 
2058 /* static */ Dimension NWidgetScrollbar::GetVerticalDimension()
2059 {
2061  if (vertical_dimension.width == 0) {
2062  vertical_dimension = maxdim(GetSpriteSize(SPR_ARROW_UP), GetSpriteSize(SPR_ARROW_DOWN));
2063  vertical_dimension.width += extra.width;
2064  vertical_dimension.height += extra.height;
2065  }
2066  return vertical_dimension;
2067 }
2068 
2069 /* static */ Dimension NWidgetScrollbar::GetHorizontalDimension()
2070 {
2072  if (horizontal_dimension.width == 0) {
2073  horizontal_dimension = maxdim(GetSpriteSize(SPR_ARROW_LEFT), GetSpriteSize(SPR_ARROW_RIGHT));
2074  horizontal_dimension.width += extra.width;
2075  horizontal_dimension.height += extra.height;
2076  }
2077  return horizontal_dimension;
2078 }
2079 
2082 
2085 {
2086  shadebox_dimension.width = shadebox_dimension.height = 0;
2087  debugbox_dimension.width = debugbox_dimension.height = 0;
2088  defsizebox_dimension.width = defsizebox_dimension.height = 0;
2089  stickybox_dimension.width = stickybox_dimension.height = 0;
2090  resizebox_dimension.width = resizebox_dimension.height = 0;
2091  closebox_dimension.width = closebox_dimension.height = 0;
2092  dropdown_dimension.width = dropdown_dimension.height = 0;
2093 }
2094 
2102 
2111 NWidgetLeaf::NWidgetLeaf(WidgetType tp, Colours colour, int index, uint32 data, StringID tip) : NWidgetCore(tp, colour, 1, 1, data, tip)
2112 {
2113  assert(index >= 0 || tp == WWT_LABEL || tp == WWT_TEXT || tp == WWT_CAPTION || tp == WWT_RESIZEBOX || tp == WWT_SHADEBOX || tp == WWT_DEFSIZEBOX || tp == WWT_DEBUGBOX || tp == WWT_STICKYBOX || tp == WWT_CLOSEBOX);
2114  if (index >= 0) this->SetIndex(index);
2115  this->min_x = 0;
2116  this->min_y = 0;
2117  this->SetResize(0, 0);
2118 
2119  switch (tp) {
2120  case WWT_EMPTY:
2121  break;
2122 
2123  case WWT_PUSHBTN:
2124  case WWT_IMGBTN:
2125  case WWT_PUSHIMGBTN:
2126  case WWT_IMGBTN_2:
2127  case WWT_TEXTBTN:
2128  case WWT_PUSHTXTBTN:
2129  case WWT_TEXTBTN_2:
2130  case WWT_LABEL:
2131  case WWT_TEXT:
2132  case WWT_MATRIX:
2133  case NWID_BUTTON_DROPDOWN:
2134  case NWID_PUSHBUTTON_DROPDOWN:
2135  case WWT_ARROWBTN:
2136  case WWT_PUSHARROWBTN:
2137  this->SetFill(0, 0);
2138  break;
2139 
2140  case WWT_EDITBOX:
2141  this->SetFill(0, 0);
2142  break;
2143 
2144  case WWT_CAPTION:
2145  this->SetFill(1, 0);
2146  this->SetResize(1, 0);
2147  this->min_y = WD_CAPTION_HEIGHT;
2148  this->SetDataTip(data, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS);
2149  break;
2150 
2151  case WWT_STICKYBOX:
2152  this->SetFill(0, 0);
2154  this->SetDataTip(STR_NULL, STR_TOOLTIP_STICKY);
2155  break;
2156 
2157  case WWT_SHADEBOX:
2158  this->SetFill(0, 0);
2160  this->SetDataTip(STR_NULL, STR_TOOLTIP_SHADE);
2161  break;
2162 
2163  case WWT_DEBUGBOX:
2164  this->SetFill(0, 0);
2166  this->SetDataTip(STR_NULL, STR_TOOLTIP_DEBUG);
2167  break;
2168 
2169  case WWT_DEFSIZEBOX:
2170  this->SetFill(0, 0);
2172  this->SetDataTip(STR_NULL, STR_TOOLTIP_DEFSIZE);
2173  break;
2174 
2175  case WWT_RESIZEBOX:
2176  this->SetFill(0, 0);
2178  this->SetDataTip(STR_NULL, STR_TOOLTIP_RESIZE);
2179  break;
2180 
2181  case WWT_CLOSEBOX:
2182  this->SetFill(0, 0);
2184  this->SetDataTip(STR_NULL, STR_TOOLTIP_CLOSE_WINDOW);
2185  break;
2186 
2187  case WWT_DROPDOWN:
2188  this->SetFill(0, 0);
2189  this->min_y = WD_DROPDOWN_HEIGHT;
2190  break;
2191 
2192  default:
2193  NOT_REACHED();
2194  }
2195 }
2196 
2197 void NWidgetLeaf::SetupSmallestSize(Window *w, bool init_array)
2198 {
2199  if (this->index >= 0 && init_array) { // Fill w->nested_array[]
2200  assert(w->nested_array_size > (uint)this->index);
2201  w->nested_array[this->index] = this;
2202  }
2203 
2204  Dimension size = {this->min_x, this->min_y};
2205  Dimension fill = {this->fill_x, this->fill_y};
2206  Dimension resize = {this->resize_x, this->resize_y};
2207  /* Get padding, and update size with the real content size if appropriate. */
2208  const Dimension *padding = nullptr;
2209  switch (this->type) {
2210  case WWT_EMPTY: {
2211  static const Dimension extra = {0, 0};
2212  padding = &extra;
2213  break;
2214  }
2215  case WWT_MATRIX: {
2217  padding = &extra;
2218  break;
2219  }
2220  case WWT_SHADEBOX: {
2222  padding = &extra;
2223  if (NWidgetLeaf::shadebox_dimension.width == 0) {
2224  NWidgetLeaf::shadebox_dimension = maxdim(GetSpriteSize(SPR_WINDOW_SHADE), GetSpriteSize(SPR_WINDOW_UNSHADE));
2225  NWidgetLeaf::shadebox_dimension.width += extra.width;
2226  NWidgetLeaf::shadebox_dimension.height += extra.height;
2227  }
2228  size = maxdim(size, NWidgetLeaf::shadebox_dimension);
2229  break;
2230  }
2231  case WWT_DEBUGBOX:
2234  padding = &extra;
2235  if (NWidgetLeaf::debugbox_dimension.width == 0) {
2236  NWidgetLeaf::debugbox_dimension = GetSpriteSize(SPR_WINDOW_DEBUG);
2237  NWidgetLeaf::debugbox_dimension.width += extra.width;
2238  NWidgetLeaf::debugbox_dimension.height += extra.height;
2239  }
2240  size = maxdim(size, NWidgetLeaf::debugbox_dimension);
2241  } else {
2242  /* If the setting is disabled we don't want to see it! */
2243  size.width = 0;
2244  fill.width = 0;
2245  resize.width = 0;
2246  }
2247  break;
2248 
2249  case WWT_STICKYBOX: {
2251  padding = &extra;
2252  if (NWidgetLeaf::stickybox_dimension.width == 0) {
2253  NWidgetLeaf::stickybox_dimension = maxdim(GetSpriteSize(SPR_PIN_UP), GetSpriteSize(SPR_PIN_DOWN));
2254  NWidgetLeaf::stickybox_dimension.width += extra.width;
2255  NWidgetLeaf::stickybox_dimension.height += extra.height;
2256  }
2257  size = maxdim(size, NWidgetLeaf::stickybox_dimension);
2258  break;
2259  }
2260 
2261  case WWT_DEFSIZEBOX: {
2263  padding = &extra;
2264  if (NWidgetLeaf::defsizebox_dimension.width == 0) {
2265  NWidgetLeaf::defsizebox_dimension = GetSpriteSize(SPR_WINDOW_DEFSIZE);
2266  NWidgetLeaf::defsizebox_dimension.width += extra.width;
2267  NWidgetLeaf::defsizebox_dimension.height += extra.height;
2268  }
2269  size = maxdim(size, NWidgetLeaf::defsizebox_dimension);
2270  break;
2271  }
2272 
2273  case WWT_RESIZEBOX: {
2275  padding = &extra;
2276  if (NWidgetLeaf::resizebox_dimension.width == 0) {
2277  NWidgetLeaf::resizebox_dimension = maxdim(GetSpriteSize(SPR_WINDOW_RESIZE_LEFT), GetSpriteSize(SPR_WINDOW_RESIZE_RIGHT));
2278  NWidgetLeaf::resizebox_dimension.width += extra.width;
2279  NWidgetLeaf::resizebox_dimension.height += extra.height;
2280  }
2281  size = maxdim(size, NWidgetLeaf::resizebox_dimension);
2282  break;
2283  }
2284  case WWT_EDITBOX: {
2285  Dimension sprite_size = GetSpriteSize(_current_text_dir == TD_RTL ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT);
2286  size.width = max(size.width, 30 + sprite_size.width);
2287  size.height = max(sprite_size.height, GetStringBoundingBox("_").height + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
2288  }
2289  FALLTHROUGH;
2290  case WWT_PUSHBTN: {
2292  padding = &extra;
2293  break;
2294  }
2295  case WWT_IMGBTN:
2296  case WWT_IMGBTN_2:
2297  case WWT_PUSHIMGBTN: {
2299  padding = &extra;
2300  Dimension d2 = GetSpriteSize(this->widget_data);
2301  if (this->type == WWT_IMGBTN_2) d2 = maxdim(d2, GetSpriteSize(this->widget_data + 1));
2302  d2.width += extra.width;
2303  d2.height += extra.height;
2304  size = maxdim(size, d2);
2305  break;
2306  }
2307  case WWT_ARROWBTN:
2308  case WWT_PUSHARROWBTN: {
2310  padding = &extra;
2311  Dimension d2 = maxdim(GetSpriteSize(SPR_ARROW_LEFT), GetSpriteSize(SPR_ARROW_RIGHT));
2312  d2.width += extra.width;
2313  d2.height += extra.height;
2314  size = maxdim(size, d2);
2315  break;
2316  }
2317 
2318  case WWT_CLOSEBOX: {
2320  padding = &extra;
2321  if (NWidgetLeaf::closebox_dimension.width == 0) {
2322  NWidgetLeaf::closebox_dimension = GetSpriteSize(SPR_CLOSEBOX);
2323  NWidgetLeaf::closebox_dimension.width += extra.width;
2324  NWidgetLeaf::closebox_dimension.height += extra.height;
2325  }
2326  size = maxdim(size, NWidgetLeaf::closebox_dimension);
2327  break;
2328  }
2329  case WWT_TEXTBTN:
2330  case WWT_PUSHTXTBTN:
2331  case WWT_TEXTBTN_2: {
2333  padding = &extra;
2334  if (this->index >= 0) w->SetStringParameters(this->index);
2336  d2.width += extra.width;
2337  d2.height += extra.height;
2338  size = maxdim(size, d2);
2339  break;
2340  }
2341  case WWT_LABEL:
2342  case WWT_TEXT: {
2343  static const Dimension extra = {0, 0};
2344  padding = &extra;
2345  if (this->index >= 0) w->SetStringParameters(this->index);
2346  size = maxdim(size, GetStringBoundingBox(this->widget_data));
2347  break;
2348  }
2349  case WWT_CAPTION: {
2351  padding = &extra;
2352  if (this->index >= 0) w->SetStringParameters(this->index);
2354  d2.width += extra.width;
2355  d2.height += extra.height;
2356  size = maxdim(size, d2);
2357  break;
2358  }
2359  case WWT_DROPDOWN:
2360  case NWID_BUTTON_DROPDOWN:
2361  case NWID_PUSHBUTTON_DROPDOWN: {
2363  padding = &extra;
2364  if (NWidgetLeaf::dropdown_dimension.width == 0) {
2365  NWidgetLeaf::dropdown_dimension = GetSpriteSize(SPR_ARROW_DOWN);
2366  NWidgetLeaf::dropdown_dimension.width += WD_DROPDOWNTEXT_LEFT + WD_DROPDOWNTEXT_RIGHT;
2367  NWidgetLeaf::dropdown_dimension.height += WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM;
2368  extra.width = WD_DROPDOWNTEXT_LEFT + WD_DROPDOWNTEXT_RIGHT + NWidgetLeaf::dropdown_dimension.width;
2369  }
2370  if (this->index >= 0) w->SetStringParameters(this->index);
2372  d2.width += extra.width;
2373  d2.height = max(d2.height, NWidgetLeaf::dropdown_dimension.height) + extra.height;
2374  size = maxdim(size, d2);
2375  break;
2376  }
2377  default:
2378  NOT_REACHED();
2379  }
2380 
2381  if (this->index >= 0) w->UpdateWidgetSize(this->index, &size, *padding, &fill, &resize);
2382 
2383  this->smallest_x = size.width;
2384  this->smallest_y = size.height;
2385  this->fill_x = fill.width;
2386  this->fill_y = fill.height;
2387  this->resize_x = resize.width;
2388  this->resize_y = resize.height;
2389 }
2390 
2392 {
2393  if (this->current_x == 0 || this->current_y == 0) return;
2394 
2395  /* Setup a clipping rectangle... */
2396  DrawPixelInfo new_dpi;
2397  if (!FillDrawPixelInfo(&new_dpi, this->pos_x, this->pos_y, this->current_x, this->current_y)) return;
2398  /* ...but keep coordinates relative to the window. */
2399  new_dpi.left += this->pos_x;
2400  new_dpi.top += this->pos_y;
2401 
2402  DrawPixelInfo *old_dpi = _cur_dpi;
2403  _cur_dpi = &new_dpi;
2404 
2405  Rect r;
2406  r.left = this->pos_x;
2407  r.right = this->pos_x + this->current_x - 1;
2408  r.top = this->pos_y;
2409  r.bottom = this->pos_y + this->current_y - 1;
2410 
2411  bool clicked = this->IsLowered();
2412  switch (this->type) {
2413  case WWT_EMPTY:
2414  break;
2415 
2416  case WWT_PUSHBTN:
2417  assert(this->widget_data == 0);
2418  DrawFrameRect(r.left, r.top, r.right, r.bottom, this->colour, (clicked) ? FR_LOWERED : FR_NONE);
2419  break;
2420 
2421  case WWT_IMGBTN:
2422  case WWT_PUSHIMGBTN:
2423  case WWT_IMGBTN_2:
2424  DrawImageButtons(r, this->type, this->colour, clicked, this->widget_data);
2425  break;
2426 
2427  case WWT_TEXTBTN:
2428  case WWT_PUSHTXTBTN:
2429  case WWT_TEXTBTN_2:
2430  if (this->index >= 0) w->SetStringParameters(this->index);
2431  DrawFrameRect(r.left, r.top, r.right, r.bottom, this->colour, (clicked) ? FR_LOWERED : FR_NONE);
2432  DrawLabel(r, this->type, clicked, this->widget_data);
2433  break;
2434 
2435  case WWT_ARROWBTN:
2436  case WWT_PUSHARROWBTN: {
2437  SpriteID sprite;
2438  switch (this->widget_data) {
2439  case AWV_DECREASE: sprite = _current_text_dir != TD_RTL ? SPR_ARROW_LEFT : SPR_ARROW_RIGHT; break;
2440  case AWV_INCREASE: sprite = _current_text_dir == TD_RTL ? SPR_ARROW_LEFT : SPR_ARROW_RIGHT; break;
2441  case AWV_LEFT: sprite = SPR_ARROW_LEFT; break;
2442  case AWV_RIGHT: sprite = SPR_ARROW_RIGHT; break;
2443  default: NOT_REACHED();
2444  }
2445  DrawImageButtons(r, WWT_PUSHIMGBTN, this->colour, clicked, sprite);
2446  break;
2447  }
2448 
2449  case WWT_LABEL:
2450  if (this->index >= 0) w->SetStringParameters(this->index);
2451  DrawLabel(r, this->type, clicked, this->widget_data);
2452  break;
2453 
2454  case WWT_TEXT:
2455  if (this->index >= 0) w->SetStringParameters(this->index);
2456  DrawText(r, (TextColour)this->colour, this->widget_data);
2457  break;
2458 
2459  case WWT_MATRIX:
2460  DrawMatrix(r, this->colour, clicked, this->widget_data, this->resize_x, this->resize_y);
2461  break;
2462 
2463  case WWT_EDITBOX: {
2464  const QueryString *query = w->GetQueryString(this->index);
2465  if (query != nullptr) query->DrawEditBox(w, this->index);
2466  break;
2467  }
2468 
2469  case WWT_CAPTION:
2470  if (this->index >= 0) w->SetStringParameters(this->index);
2471  DrawCaption(r, this->colour, w->owner, this->widget_data);
2472  break;
2473 
2474  case WWT_SHADEBOX:
2475  assert(this->widget_data == 0);
2476  DrawShadeBox(r, this->colour, w->IsShaded());
2477  break;
2478 
2479  case WWT_DEBUGBOX:
2480  DrawDebugBox(r, this->colour, clicked);
2481  break;
2482 
2483  case WWT_STICKYBOX:
2484  assert(this->widget_data == 0);
2485  DrawStickyBox(r, this->colour, !!(w->flags & WF_STICKY));
2486  break;
2487 
2488  case WWT_DEFSIZEBOX:
2489  assert(this->widget_data == 0);
2490  DrawDefSizeBox(r, this->colour, clicked);
2491  break;
2492 
2493  case WWT_RESIZEBOX:
2494  assert(this->widget_data == 0);
2495  DrawResizeBox(r, this->colour, this->pos_x < (w->width / 2), !!(w->flags & WF_SIZING));
2496  break;
2497 
2498  case WWT_CLOSEBOX:
2499  DrawCloseBox(r, this->colour);
2500  break;
2501 
2502  case WWT_DROPDOWN:
2503  if (this->index >= 0) w->SetStringParameters(this->index);
2504  DrawDropdown(r, this->colour, clicked, this->widget_data);
2505  break;
2506 
2507  case NWID_BUTTON_DROPDOWN:
2508  case NWID_PUSHBUTTON_DROPDOWN:
2509  if (this->index >= 0) w->SetStringParameters(this->index);
2510  DrawButtonDropdown(r, this->colour, clicked, (this->disp_flags & ND_DROPDOWN_ACTIVE) != 0, this->widget_data);
2511  break;
2512 
2513  default:
2514  NOT_REACHED();
2515  }
2516  if (this->index >= 0) w->DrawWidget(r, this->index);
2517 
2518  if (this->IsDisabled()) {
2519  GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, _colour_gradient[this->colour & 0xF][2], FILLRECT_CHECKER);
2520  }
2521 
2522  _cur_dpi = old_dpi;
2523 }
2524 
2533 {
2534  if (_current_text_dir == TD_LTR) {
2535  int button_width = this->pos_x + this->current_x - NWidgetLeaf::dropdown_dimension.width;
2536  return pt.x < button_width;
2537  } else {
2538  int button_left = this->pos_x + NWidgetLeaf::dropdown_dimension.width;
2539  return pt.x >= button_left;
2540  }
2541 }
2542 
2543 /* == Conversion code from NWidgetPart array to NWidgetBase* tree == */
2544 
2560 static int MakeNWidget(const NWidgetPart *parts, int count, NWidgetBase **dest, bool *fill_dest, int *biggest_index)
2561 {
2562  int num_used = 0;
2563 
2564  *dest = nullptr;
2565  *fill_dest = false;
2566 
2567  while (count > num_used) {
2568  switch (parts->type) {
2569  case NWID_SPACER:
2570  if (*dest != nullptr) return num_used;
2571  *dest = new NWidgetSpacer(0, 0);
2572  break;
2573 
2574  case NWID_HORIZONTAL:
2575  if (*dest != nullptr) return num_used;
2576  *dest = new NWidgetHorizontal(parts->u.cont_flags);
2577  *fill_dest = true;
2578  break;
2579 
2580  case NWID_HORIZONTAL_LTR:
2581  if (*dest != nullptr) return num_used;
2582  *dest = new NWidgetHorizontalLTR(parts->u.cont_flags);
2583  *fill_dest = true;
2584  break;
2585 
2586  case WWT_PANEL:
2587  case WWT_INSET:
2588  case WWT_FRAME:
2589  if (*dest != nullptr) return num_used;
2590  *dest = new NWidgetBackground(parts->type, parts->u.widget.colour, parts->u.widget.index);
2591  *biggest_index = max(*biggest_index, (int)parts->u.widget.index);
2592  *fill_dest = true;
2593  break;
2594 
2595  case NWID_VERTICAL:
2596  if (*dest != nullptr) return num_used;
2597  *dest = new NWidgetVertical(parts->u.cont_flags);
2598  *fill_dest = true;
2599  break;
2600 
2601  case NWID_MATRIX: {
2602  if (*dest != nullptr) return num_used;
2603  NWidgetMatrix *nwm = new NWidgetMatrix();
2604  *dest = nwm;
2605  *fill_dest = true;
2606  nwm->SetIndex(parts->u.widget.index);
2607  nwm->SetColour(parts->u.widget.colour);
2608  *biggest_index = max(*biggest_index, (int)parts->u.widget.index);
2609  break;
2610  }
2611 
2612  case WPT_FUNCTION: {
2613  if (*dest != nullptr) return num_used;
2614  /* Ensure proper functioning even when the called code simply writes its largest index. */
2615  int biggest = -1;
2616  *dest = parts->u.func_ptr(&biggest);
2617  *biggest_index = max(*biggest_index, biggest);
2618  *fill_dest = false;
2619  break;
2620  }
2621 
2622  case WPT_RESIZE: {
2623  NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest);
2624  if (nwrb != nullptr) {
2625  assert(parts->u.xy.x >= 0 && parts->u.xy.y >= 0);
2626  nwrb->SetResize(parts->u.xy.x, parts->u.xy.y);
2627  }
2628  break;
2629  }
2630 
2631  case WPT_MINSIZE: {
2632  NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest);
2633  if (nwrb != nullptr) {
2634  assert(parts->u.xy.x >= 0 && parts->u.xy.y >= 0);
2635  nwrb->SetMinimalSize(ScaleGUITrad(parts->u.xy.x), ScaleGUITrad(parts->u.xy.y));
2636  }
2637  break;
2638  }
2639 
2640  case WPT_MINTEXTLINES: {
2641  NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest);
2642  if (nwrb != nullptr) {
2643  assert(parts->u.text_lines.size >= FS_BEGIN && parts->u.text_lines.size < FS_END);
2644  nwrb->SetMinimalTextLines(parts->u.text_lines.lines, parts->u.text_lines.spacing, parts->u.text_lines.size);
2645  }
2646  break;
2647  }
2648 
2649  case WPT_FILL: {
2650  NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest);
2651  if (nwrb != nullptr) nwrb->SetFill(parts->u.xy.x, parts->u.xy.y);
2652  break;
2653  }
2654 
2655  case WPT_DATATIP: {
2656  NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(*dest);
2657  if (nwc != nullptr) {
2658  nwc->widget_data = parts->u.data_tip.data;
2659  nwc->tool_tip = parts->u.data_tip.tooltip;
2660  }
2661  break;
2662  }
2663 
2664  case WPT_PADDING:
2665  if (*dest != nullptr) (*dest)->SetPadding(ScaleGUITrad(parts->u.padding.top), ScaleGUITrad(parts->u.padding.right), ScaleGUITrad(parts->u.padding.bottom), ScaleGUITrad(parts->u.padding.left));
2666  break;
2667 
2668  case WPT_PIPSPACE: {
2669  NWidgetPIPContainer *nwc = dynamic_cast<NWidgetPIPContainer *>(*dest);
2670  if (nwc != nullptr) nwc->SetPIP(parts->u.pip.pre, parts->u.pip.inter, parts->u.pip.post);
2671 
2672  NWidgetBackground *nwb = dynamic_cast<NWidgetBackground *>(*dest);
2673  if (nwb != nullptr) nwb->SetPIP(parts->u.pip.pre, parts->u.pip.inter, parts->u.pip.post);
2674  break;
2675  }
2676 
2677  case WPT_SCROLLBAR: {
2678  NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(*dest);
2679  if (nwc != nullptr) {
2680  nwc->scrollbar_index = parts->u.widget.index;
2681  }
2682  break;
2683  }
2684 
2685  case WPT_ENDCONTAINER:
2686  return num_used;
2687 
2688  case NWID_VIEWPORT:
2689  if (*dest != nullptr) return num_used;
2690  *dest = new NWidgetViewport(parts->u.widget.index);
2691  *biggest_index = max(*biggest_index, (int)parts->u.widget.index);
2692  break;
2693 
2694  case NWID_HSCROLLBAR:
2695  case NWID_VSCROLLBAR:
2696  if (*dest != nullptr) return num_used;
2697  *dest = new NWidgetScrollbar(parts->type, parts->u.widget.colour, parts->u.widget.index);
2698  *biggest_index = max(*biggest_index, (int)parts->u.widget.index);
2699  break;
2700 
2701  case NWID_SELECTION: {
2702  if (*dest != nullptr) return num_used;
2703  NWidgetStacked *nws = new NWidgetStacked();
2704  *dest = nws;
2705  *fill_dest = true;
2706  nws->SetIndex(parts->u.widget.index);
2707  *biggest_index = max(*biggest_index, (int)parts->u.widget.index);
2708  break;
2709  }
2710 
2711  default:
2712  if (*dest != nullptr) return num_used;
2713  assert((parts->type & WWT_MASK) < WWT_LAST || (parts->type & WWT_MASK) == NWID_BUTTON_DROPDOWN);
2714  *dest = new NWidgetLeaf(parts->type, parts->u.widget.colour, parts->u.widget.index, 0x0, STR_NULL);
2715  *biggest_index = max(*biggest_index, (int)parts->u.widget.index);
2716  break;
2717  }
2718  num_used++;
2719  parts++;
2720  }
2721 
2722  return num_used;
2723 }
2724 
2734 static int MakeWidgetTree(const NWidgetPart *parts, int count, NWidgetBase **parent, int *biggest_index)
2735 {
2736  /* If *parent == nullptr, only the first widget is read and returned. Otherwise, *parent must point to either
2737  * a #NWidgetContainer or a #NWidgetBackground object, and parts are added as much as possible. */
2738  NWidgetContainer *nwid_cont = dynamic_cast<NWidgetContainer *>(*parent);
2739  NWidgetBackground *nwid_parent = dynamic_cast<NWidgetBackground *>(*parent);
2740  assert(*parent == nullptr || (nwid_cont != nullptr && nwid_parent == nullptr) || (nwid_cont == nullptr && nwid_parent != nullptr));
2741 
2742  int total_used = 0;
2743  for (;;) {
2744  NWidgetBase *sub_widget = nullptr;
2745  bool fill_sub = false;
2746  int num_used = MakeNWidget(parts, count - total_used, &sub_widget, &fill_sub, biggest_index);
2747  parts += num_used;
2748  total_used += num_used;
2749 
2750  /* Break out of loop when end reached */
2751  if (sub_widget == nullptr) break;
2752 
2753  /* If sub-widget is a container, recursively fill that container. */
2754  WidgetType tp = sub_widget->type;
2755  if (fill_sub && (tp == NWID_HORIZONTAL || tp == NWID_HORIZONTAL_LTR || tp == NWID_VERTICAL || tp == NWID_MATRIX
2756  || tp == WWT_PANEL || tp == WWT_FRAME || tp == WWT_INSET || tp == NWID_SELECTION)) {
2757  NWidgetBase *sub_ptr = sub_widget;
2758  int num_used = MakeWidgetTree(parts, count - total_used, &sub_ptr, biggest_index);
2759  parts += num_used;
2760  total_used += num_used;
2761  }
2762 
2763  /* Add sub_widget to parent container if available, otherwise return the widget to the caller. */
2764  if (nwid_cont != nullptr) nwid_cont->Add(sub_widget);
2765  if (nwid_parent != nullptr) nwid_parent->Add(sub_widget);
2766  if (nwid_cont == nullptr && nwid_parent == nullptr) {
2767  *parent = sub_widget;
2768  return total_used;
2769  }
2770  }
2771 
2772  if (count == total_used) return total_used; // Reached the end of the array of parts?
2773 
2774  assert(total_used < count);
2775  assert(parts->type == WPT_ENDCONTAINER);
2776  return total_used + 1; // *parts is also 'used'
2777 }
2778 
2790 NWidgetContainer *MakeNWidgets(const NWidgetPart *parts, int count, int *biggest_index, NWidgetContainer *container)
2791 {
2792  *biggest_index = -1;
2793  if (container == nullptr) container = new NWidgetVertical();
2794  NWidgetBase *cont_ptr = container;
2795  MakeWidgetTree(parts, count, &cont_ptr, biggest_index);
2796  return container;
2797 }
2798 
2812 NWidgetContainer *MakeWindowNWidgetTree(const NWidgetPart *parts, int count, int *biggest_index, NWidgetStacked **shade_select)
2813 {
2814  *biggest_index = -1;
2815 
2816  /* Read the first widget recursively from the array. */
2817  NWidgetBase *nwid = nullptr;
2818  int num_used = MakeWidgetTree(parts, count, &nwid, biggest_index);
2819  assert(nwid != nullptr);
2820  parts += num_used;
2821  count -= num_used;
2822 
2823  NWidgetContainer *root = new NWidgetVertical;
2824  root->Add(nwid);
2825  if (count == 0) { // There is no body at all.
2826  *shade_select = nullptr;
2827  return root;
2828  }
2829 
2830  /* If the first widget looks like a titlebar, treat it as such.
2831  * If it has a shading box, silently add a shade selection widget in the tree. */
2832  NWidgetHorizontal *hor_cont = dynamic_cast<NWidgetHorizontal *>(nwid);
2833  NWidgetContainer *body;
2834  if (hor_cont != nullptr && hor_cont->GetWidgetOfType(WWT_CAPTION) != nullptr && hor_cont->GetWidgetOfType(WWT_SHADEBOX) != nullptr) {
2835  *shade_select = new NWidgetStacked;
2836  root->Add(*shade_select);
2837  body = new NWidgetVertical;
2838  (*shade_select)->Add(body);
2839  } else {
2840  *shade_select = nullptr;
2841  body = root;
2842  }
2843 
2844  /* Load the remaining parts into 'body'. */
2845  int biggest2 = -1;
2846  MakeNWidgets(parts, count, &biggest2, body);
2847 
2848  *biggest_index = max(*biggest_index, biggest2);
2849  return root;
2850 }
2851 
2862 NWidgetBase *MakeCompanyButtonRows(int *biggest_index, int widget_first, int widget_last, int max_length, StringID button_tooltip)
2863 {
2864  assert(max_length >= 1);
2865  NWidgetVertical *vert = nullptr; // Storage for all rows.
2866  NWidgetHorizontal *hor = nullptr; // Storage for buttons in one row.
2867  int hor_length = 0;
2868 
2869  Dimension sprite_size = GetSpriteSize(SPR_COMPANY_ICON);
2870  sprite_size.width += WD_MATRIX_LEFT + WD_MATRIX_RIGHT;
2871  sprite_size.height += WD_MATRIX_TOP + WD_MATRIX_BOTTOM + 1; // 1 for the 'offset' of being pressed
2872 
2873  for (int widnum = widget_first; widnum <= widget_last; widnum++) {
2874  /* Ensure there is room in 'hor' for another button. */
2875  if (hor_length == max_length) {
2876  if (vert == nullptr) vert = new NWidgetVertical();
2877  vert->Add(hor);
2878  hor = nullptr;
2879  hor_length = 0;
2880  }
2881  if (hor == nullptr) {
2882  hor = new NWidgetHorizontal();
2883  hor_length = 0;
2884  }
2885 
2886  NWidgetBackground *panel = new NWidgetBackground(WWT_PANEL, COLOUR_GREY, widnum);
2887  panel->SetMinimalSize(sprite_size.width, sprite_size.height);
2888  panel->SetFill(1, 1);
2889  panel->SetResize(1, 0);
2890  panel->SetDataTip(0x0, button_tooltip);
2891  hor->Add(panel);
2892  hor_length++;
2893  }
2894  *biggest_index = widget_last;
2895  if (vert == nullptr) return hor; // All buttons fit in a single row.
2896 
2897  if (hor_length > 0 && hor_length < max_length) {
2898  /* Last row is partial, add a spacer at the end to force all buttons to the left. */
2899  NWidgetSpacer *spc = new NWidgetSpacer(sprite_size.width, sprite_size.height);
2900  spc->SetFill(1, 1);
2901  spc->SetResize(1, 0);
2902  hor->Add(spc);
2903  }
2904  if (hor != nullptr) vert->Add(hor);
2905  return vert;
2906 }
Nested widget containing a viewport.
Definition: widget_type.h:79
Colours colour
Colour of this widget.
Definition: widget_type.h:301
Matrix container with implicitly equal sized (virtual) sub-widgets.
Definition: widget_type.h:491
Functions related to OTTD&#39;s strings.
static Dimension shadebox_dimension
Cached size of a shadebox widget.
Definition: widget_type.h:783
Owner
Enum for all companies/owners.
Definition: company_type.h:18
Empty widget, place holder to reserve space in widget array.
Definition: widget_type.h:46
SizingType
Different forms of sizing nested widgets, using NWidgetBase::AssignSizePosition() ...
Definition: widget_type.h:109
Left offset of sticky sprite.
Definition: window_gui.h:90
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition: widget.cpp:1901
Normal push-button (no toggle button) with image caption.
Definition: widget_type.h:103
NWidContainerFlags
Nested widget container flags,.
Definition: widget_type.h:423
static const PaletteID PALETTE_TO_TRANSPARENT
This sets the sprite to transparent.
Definition: sprites.h:1584
static void DrawResizeBox(const Rect &r, Colours colour, bool at_left, bool clicked)
Draw a resize box.
Definition: widget.cpp:504
void SetupSmallestSize(Window *w, bool init_array) override
Compute smallest size needed by the widget.
Definition: widget.cpp:1891
uint32 widget_data
Data of the widget.
Definition: widget_type.h:303
NWidgetBase(WidgetType tp)
Base class constructor.
Definition: widget.cpp:719
void InitializeWindowViewport(Window *w, int x, int y, int width, int height, uint32 follow_flags, ZoomLevel zoom)
Initialize viewport of the window for use.
Definition: viewport.cpp:220
Data about how and where to blit pixels.
Definition: gfx_type.h:154
Matrix container.
Definition: widget_type.h:76
Horizontally center the text.
Definition: gfx_func.h:95
const QueryString * GetQueryString(uint widnum) const
Return the querystring associated to a editbox.
Definition: window.cpp:329
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:110
Offset at right of a matrix cell.
Definition: window_gui.h:77
Point pos
logical mouse position
Definition: gfx_type.h:117
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition: widget.cpp:2391
uint resize_x
Horizontal resize step (0 means not resizable).
Definition: widget_type.h:164
NWidgetCore * GetWidgetFromPos(int x, int y) override
Retrieve a widget by its position.
Definition: widget.cpp:1115
static int UnScaleGUI(int value)
Short-hand to apply GUI zoom level.
Definition: zoom_func.h:66
Right offset of closebox string.
Definition: window_gui.h:119
Lowest bit of the number of columns.
Definition: widget_type.h:25
uint min_x
Minimal horizontal size of only this widget.
Definition: widget_type.h:244
(Toggle) Button with diff image when clicked
Definition: widget_type.h:51
signs
Definition: transparency.h:23
static void DrawDebugBox(const Rect &r, Colours colour, bool clicked)
Draw a NewGRF debug box.
Definition: widget.cpp:492
void FillNestedArray(NWidgetBase **array, uint length) override
Fill the Window::nested_array array with pointers to nested widgets in the tree.
Definition: widget.cpp:1448
void SetMinimalSize(uint min_x, uint min_y)
Set minimal size of the widget.
Definition: widget.cpp:815
Number of bits for the number of columns in the matrix.
Definition: widget_type.h:26
StringID tool_tip
Tooltip of the widget.
Definition: widget_type.h:304
WindowFlags flags
Window flags.
Definition: window_gui.h:310
int left
x position of left edge of the window
Definition: window_gui.h:317
NWidgetCore * GetWidgetFromPos(int x, int y) override
Retrieve a widget by its position.
Definition: widget.cpp:903
bool ButtonHit(const Point &pt)
For a NWID_BUTTON_DROPDOWN, test whether pt refers to the button or to the drop-down.
Definition: widget.cpp:2532
int height
Screen height of the viewport.
Definition: viewport_type.h:26
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:602
Width of left bevel border.
Definition: window_gui.h:54
Baseclass for container widgets.
Definition: widget_type.h:366
Left offset of scrollbar.
Definition: window_gui.h:48
Right offset of debug sprite.
Definition: window_gui.h:98
NWidgetHorizontal(NWidContainerFlags flags=NC_NONE)
Horizontal container widget.
Definition: widget.cpp:1127
Centered label.
Definition: widget_type.h:55
NWidgetStacked()
Widgets stacked on top of each other.
Definition: widget.cpp:969
void Add(NWidgetBase *nwid)
Add a child to the parent.
Definition: widget.cpp:1729
Height of a drop down widget.
Definition: window_gui.h:131
Scrollbar data structure.
Definition: widget_type.h:587
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition: fontcache.cpp:62
Base class for a resizable nested widget.
Definition: widget_type.h:233
Stacked widgets, widgets all occupying the same space in the window.
Definition: widget_type.h:403
static int MakeWidgetTree(const NWidgetPart *parts, int count, NWidgetBase **parent, int *biggest_index)
Build a nested widget tree by recursively filling containers with nested widgets read from their part...
Definition: widget.cpp:2734
static void DrawMatrix(const Rect &r, Colours colour, bool clicked, uint16 data, uint resize_x, uint resize_y)
Draw a matrix widget.
Definition: widget.cpp:276
Top offset of scrollbar.
Definition: window_gui.h:50
Offset at top to draw the frame rectangular area.
Definition: window_gui.h:62
static uint ComputeMaxSize(uint base, uint max_space, uint step)
Return the biggest possible size of a nested widget.
Definition: widget_type.h:796
Nested widget to display and control a scrollbar in a window.
Definition: widget_type.h:748
void UpdateViewportCoordinates(Window *w)
Update the position and size of the viewport (after eg a resize).
Definition: widget.cpp:1934
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Horizontal container.
Definition: widget_type.h:73
void FillNestedArray(NWidgetBase **array, uint length) override
Fill the Window::nested_array array with pointers to nested widgets in the tree.
Definition: widget.cpp:1586
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: gfx.cpp:52
Arrow to the right or in case of RTL to the left.
Definition: widget_type.h:36
Arrow to the left or in case of RTL to the right.
Definition: widget_type.h:35
Bit value of the &#39;no transparency&#39; flag.
Definition: widget_type.h:268
NewGRF debug box (at top-right of a window, between WWT_CAPTION and WWT_SHADEBOX) ...
Definition: widget_type.h:61
static int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Definition: zoom_func.h:76
WidgetType type
Type of the widget / nested widget.
Definition: widget_type.h:161
static Dimension vertical_dimension
Cached size of vertical scrollbar button.
Definition: widget_type.h:760
Bottom offset of shade sprite.
Definition: window_gui.h:86
NWidgetBase * tail
Pointer to last widget in container.
Definition: widget_type.h:381
Down-button is lowered bit.
Definition: widget_type.h:261
NWidContainerFlags flags
Flags of the container.
Definition: widget_type.h:442
static Dimension closebox_dimension
Cached size of a closebox widget.
Definition: widget_type.h:781
Left offset of shade sprite.
Definition: window_gui.h:83
uint8 pip_inter
Amount of space between widgets.
Definition: widget_type.h:444
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition: widget.cpp:1108
a textbox for typing
Definition: widget_type.h:69
int index
If non-negative, index in the Window::nested_array.
Definition: widget_type.h:419
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:66
int virtual_height
height << zoom
Definition: viewport_type.h:31
Pressed (inset) panel, most commonly used as combo box text area.
Definition: widget_type.h:49
If set the background is darker, allows for lowered frames with normal background colour when used wi...
Definition: window_gui.h:30
NWidgetResizeBase(WidgetType tp, uint fill_x, uint fill_y)
Constructor for resizable nested widgets.
Definition: widget.cpp:804
Horizontal container that doesn&#39;t change the direction of the widgets for RTL languages.
Definition: widget_type.h:464
void SetupSmallestSize(Window *w, bool init_array) override
Compute smallest size needed by the widget.
Definition: widget.cpp:2197
int top
y position of top edge of the window
Definition: window_gui.h:318
static Point HandleScrollbarHittest(const Scrollbar *sb, int top, int bottom, bool horizontal)
Compute the vertical position of the draggable part of scrollbar.
Definition: widget.cpp:36
int LeastCommonMultiple(int a, int b)
Compute least common multiple (lcm) of arguments a and b, the smallest integer value that is a multip...
Definition: math_func.cpp:24
void FillNestedArray(NWidgetBase **array, uint length) override
Fill the Window::nested_array array with pointers to nested widgets in the tree.
Definition: widget.cpp:898
static int ScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift left (when zoom > ZOOM_LVL_NORMAL) When shifting right...
Definition: zoom_func.h:22
static void DrawFrame(const Rect &r, Colours colour, StringID str)
Draw a frame widget.
Definition: widget.cpp:409
Normal push-button (no toggle button) with custom drawing.
Definition: widget_type.h:101
(Toggle) Button with an arrow
Definition: widget_type.h:52
Width of right bevel border.
Definition: window_gui.h:55
Close box (at top-left of a window)
Definition: widget_type.h:67
Offset at top of a matrix cell.
Definition: window_gui.h:78
Bit value of the &#39;shade to grey&#39; flag.
Definition: widget_type.h:269
uint8 pip_post
Amount of space after last widget.
Definition: widget_type.h:445
NWidgetFunctionType * func_ptr
Part with a function call.
Definition: widget_type.h:917
Bottom offset of defsize sprite.
Definition: window_gui.h:107
NWidgetContainer(WidgetType tp)
Constructor container baseclass.
Definition: widget.cpp:912
static Dimension resizebox_dimension
Cached size of a resizebox widget.
Definition: widget_type.h:780
NWidgetPartPIP pip
Part with pre/inter/post spaces.
Definition: widget_type.h:915
loading indicators
Definition: transparency.h:31
void SetDirty(const Window *w) const override
Mark the widget as &#39;dirty&#39; (in need of repaint).
Definition: widget.cpp:1457
void SetCount(int count)
Set the number of elements in this matrix.
Definition: widget.cpp:1502
void InitializeViewport(Window *w, uint32 follow_flags, ZoomLevel zoom)
Initialize the viewport of the window.
Definition: widget.cpp:1925
Step in cap units.
Definition: widget_type.h:600
Top offset of debug sprite.
Definition: window_gui.h:99
Spacer widget.
Definition: widget_type.h:527
Left offset of debug sprite.
Definition: window_gui.h:97
uint smallest_x
Smallest horizontal size of the widget in a filled window.
Definition: widget_type.h:169
static T max(const T a, const T b)
Returns the maximum of two values.
Definition: math_func.hpp:24
Widget part for specifying a padding.
Definition: widget_type.h:90
Widget part for specifying resizing.
Definition: widget_type.h:85
Widget part for specifying data and tooltip.
Definition: widget_type.h:89
Window is made sticky by user.
Definition: window_gui.h:238
Nested widget to display a viewport in a window.
Definition: widget_type.h:573
NWidgetPartWidget widget
Part with a start of a widget.
Definition: widget_type.h:913
NWidgetContainer * MakeNWidgets(const NWidgetPart *parts, int count, int *biggest_index, NWidgetContainer *container)
Construct a nested widget tree from an array of parts.
Definition: widget.cpp:2790
Pure simple text.
Definition: widget_type.h:56
NWidgetBase * GetWidgetOfType(WidgetType tp) override
Retrieve a widget by its type.
Definition: widget.cpp:1878
static void DrawText(const Rect &r, TextColour colour, StringID str)
Draw text.
Definition: widget.cpp:248
Point xy
Part with an x/y size.
Definition: widget_type.h:911
bool IsDisabled() const
Return whether the widget is disabled.
Definition: widget_type.h:356
static T SB(T &x, const uint8 s, const uint8 n, const U d)
Set n bits in x starting at bit s to d.
NWidgetBase * MakeCompanyButtonRows(int *biggest_index, int widget_first, int widget_last, int max_length, StringID button_tooltip)
Make a number of rows with button-like graphics, for enabling/disabling each company.
Definition: widget.cpp:2862
Functions, definitions and such used only by the GUI.
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
Definition: gfx.cpp:1481
virtual bool IsNewGRFInspectable() const
Is the data related to this window NewGRF inspectable?
Definition: window_gui.h:801
static void DrawDropdown(const Rect &r, Colours colour, bool clicked, StringID str)
Draw a dropdown WWT_DROPDOWN widget.
Definition: widget.cpp:594
static bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
Definition: math_func.hpp:248
FrameFlags
Flags to describe the look of the frame.
Definition: window_gui.h:25
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition: widget.cpp:175
Width of a close box widget.
Definition: window_gui.h:117
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:908
Functions related to (drawing on) viewports.
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
Definition: window_gui.h:583
Base for the GUIs that have an edit box in them.
void SetPIP(uint8 pip_pre, uint8 pip_inter, uint8 pip_post)
Set additional pre/inter/post space for the background widget.
Definition: widget.cpp:1747
Data structure for an opened window.
Definition: window_gui.h:276
NWidgetBase * next
Pointer to next widget in container. Managed by parent container widget.
Definition: widget_type.h:178
void FillNestedArray(NWidgetBase **array, uint length) override
Fill the Window::nested_array array with pointers to nested widgets in the tree.
Definition: widget.cpp:1043
Widget part for specifying fill.
Definition: widget_type.h:88
Bottom offset of image in the button.
Definition: window_gui.h:41
void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
Assign size and position to the widget.
Definition: widget.cpp:1363
Bottom offset of the text of the frame.
Definition: window_gui.h:73
static void DrawInset(const Rect &r, Colours colour, StringID str)
Draw an inset widget.
Definition: widget.cpp:261
StringID tooltip
Tooltip of the widget.
Definition: widget_type.h:858
void Add(NWidgetBase *wid)
Append widget wid to container.
Definition: widget.cpp:942
Lowest bit of the number of rows.
Definition: widget_type.h:29
NWidgetBase ** nested_array
Array of pointers into the tree. Do not access directly, use Window::GetWidget() instead.
Definition: window_gui.h:330
Invisible widget that takes some space.
Definition: widget_type.h:77
Right offset of resize sprite.
Definition: window_gui.h:112
void SetupSmallestSize(Window *w, bool init_array) override
Compute smallest size needed by the widget.
Definition: widget.cpp:1442
WidgetType type
Type of the part.
Definition: widget_type.h:909
Bit value of the &#39;dropdown active&#39; flag.
Definition: widget_type.h:271
Offset at bottom of a matrix cell.
Definition: window_gui.h:79
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX) ...
Definition: widget_type.h:63
Right offset of defsize sprite.
Definition: window_gui.h:105
int GetScrolledRowFromWidget(int clickpos, const Window *const w, int widget, int padding=0, int line_height=-1) const
Compute the row of a scrolled widget that a user clicked in.
Definition: widget.cpp:1957
Widget part for specifying pre/inter/post space for containers.
Definition: widget_type.h:91
static Dimension horizontal_dimension
Cached size of horizontal scrollbar button.
Definition: widget_type.h:761
uint32 data
Data value of the widget.
Definition: widget_type.h:857
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
Definition: window_gui.h:493
void SetDataTip(uint32 widget_data, StringID tool_tip)
Set data and tool tip of the nested widget.
Definition: widget.cpp:892
static void DrawVerticalScrollbar(const Rect &r, Colours colour, bool up_clicked, bool bar_dragged, bool down_clicked, const Scrollbar *scrollbar)
Draw a vertical scrollbar.
Definition: widget.cpp:336
void SetIndex(int index)
Set index of the nested widget in the widget array.
Definition: widget.cpp:881
void SetLowered(bool lowered)
Lower or raise the widget.
Definition: widget_type.h:335
First font.
Definition: gfx_type.h:208
void SetMinimalTextLines(uint8 min_lines, uint8 spacing, FontSize size)
Set minimal text lines for the widget.
Definition: widget.cpp:827
uint8 padding_top
Paddings added to the top of the widget. Managed by parent container widget.
Definition: widget_type.h:181
uint smallest_y
Smallest vertical size of the widget in a filled window.
Definition: widget_type.h:170
uint current_y
Current vertical size (after resizing).
Definition: widget_type.h:173
void SetupSmallestSize(Window *w, bool init_array) override
Compute smallest size needed by the widget.
Definition: widget.cpp:979
static Dimension stickybox_dimension
Cached size of a stickybox widget.
Definition: widget_type.h:786
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
Definition: window_gui.h:569
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:176
void SetFill(uint fill_x, uint fill_y)
Set the filling of the widget from initial size.
Definition: widget.cpp:837
Data stored about a string that can be modified in the GUI.
Number of bits for the number of rows in the matrix.
Definition: widget_type.h:30
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:78
Apply a recolour sprite to the screen content.
Definition: gfx_type.h:284
Display plane with zero size vertically, and filling and resizing horizontally.
Definition: widget_type.h:387
static void ScrollbarClickPositioning(Window *w, NWidgetScrollbar *sb, int x, int y, int mi, int ma)
Compute new position of the scrollbar after a click and updates the window flags. ...
Definition: widget.cpp:79
Types related to global configuration settings.
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition: widget.cpp:1827
void SetupSmallestSize(Window *w, bool init_array)
Compute smallest size needed by the widget.
Definition: widget.cpp:1131
Left offset of string.
Definition: window_gui.h:44
Bottom offset of resize sprite.
Definition: window_gui.h:114
Widget part for attaching a scrollbar.
Definition: widget_type.h:94
Definition of base types and functions in a cross-platform compatible way.
virtual NWidgetCore * GetWidgetFromPos(int x, int y)=0
Retrieve a widget by its position.
void SetupSmallestSize(Window *w, bool init_array) override
Compute smallest size needed by the widget.
Definition: widget.cpp:1993
Height of bottom bevel border.
Definition: window_gui.h:57
static void DrawHorizontalScrollbar(const Rect &r, Colours colour, bool left_clicked, bool bar_dragged, bool right_clicked, const Scrollbar *scrollbar)
Draw a horizontal scrollbar.
Definition: widget.cpp:374
NWidgetScrollbar(WidgetType tp, Colours colour, int index)
Scrollbar widget.
Definition: widget.cpp:1987
A number of safeguards to prevent using unsafe methods.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:245
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition: widget.cpp:1624
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:102
Vertical container.
Definition: widget_type.h:475
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition: widget.cpp:2024
Geometry functions.
uint fill_y
Vertical fill stepsize (from initial size, 0 means not resizable).
Definition: widget_type.h:163
void SetPIP(uint8 pip_pre, uint8 pip_inter, uint8 pip_post)
Set additional pre/inter/post space for the container.
Definition: widget.cpp:1101
Widget part for calling a user function.
Definition: widget_type.h:93
Simple depressed panel.
Definition: widget_type.h:48
static uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
Definition: math_func.hpp:314
Left offset of defsize sprite.
Definition: window_gui.h:104
Height of a title bar.
Definition: window_gui.h:124
void FillNestedArray(NWidgetBase **array, uint length) override
Fill the Window::nested_array array with pointers to nested widgets in the tree.
Definition: widget.cpp:959
static void InvalidateDimensionCache()
Reset the cached dimensions.
Definition: widget.cpp:2084
uint nested_array_size
Size of the nested array.
Definition: window_gui.h:331
NWidgetPartDataTip data_tip
Part with a data/tooltip.
Definition: widget_type.h:912
int16 index
Widget index in the widget array.
Definition: widget_type.h:867
void DrawSortButtonState(int widget, SortButtonState state) const
Draw a sort button&#39;s up or down arrow symbol.
Definition: widget.cpp:636
Horizontal scrollbar.
Definition: widget_type.h:81
static const PaletteID PALETTE_NEWSPAPER
Recolour sprite for newspaper-greying.
Definition: sprites.h:1586
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:175
Offset at left of a matrix cell.
Definition: window_gui.h:76
Top offset of resize sprite.
Definition: window_gui.h:113
NWidgetBackground(WidgetType tp, Colours colour, int index, NWidgetPIPContainer *child=nullptr)
Constructor parent nested widgets.
Definition: widget.cpp:1710
int GetRowFromWidget(int clickpos, int widget, int padding, int line_height=-1) const
Compute the row of a widget that a user clicked in.
Definition: window.cpp:201
Frame.
Definition: widget_type.h:58
uint8 padding_left
Paddings added to the left of the widget. Managed by parent container widget. (parent container may s...
Definition: widget_type.h:184
NWidgetCore * GetWidgetFromPos(int x, int y) override
Retrieve a widget by its position.
Definition: widget.cpp:1592
NWidgetBase * GetWidgetOfType(WidgetType tp) override
Retrieve a widget by its type.
Definition: widget.cpp:928
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
void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override
Assign size and position to the widget.
Definition: widget.cpp:1809
int scrollbar_index
Index of an attached scrollbar.
Definition: widget_type.h:305
static Dimension dropdown_dimension
Cached size of a dropdown widget.
Definition: widget_type.h:779
Bit value of the &#39;dimmed colours&#39; flag.
Definition: widget_type.h:270
int virtual_width
width << zoom
Definition: viewport_type.h:30
SortButtonState
State of a sort direction button.
Definition: window_gui.h:222
Right offset of sticky sprite.
Definition: window_gui.h:91
Offset at bottom to draw the frame rectangular area.
Definition: window_gui.h:63
Baseclass for nested widgets.
Definition: widget_type.h:124
Button with a drop-down.
Definition: widget_type.h:80
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition: widget.cpp:1452
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:498
NWidgetCore * GetWidgetFromPos(int x, int y) override
Retrieve a widget by its position.
Definition: widget.cpp:1064
TransparencyOptionBits _transparency_opt
The bits that should be transparent.
Offset of the caption text at the left.
Definition: window_gui.h:125
void SetDirtyBlocks(int left, int top, int right, int bottom)
This function extends the internal _invalid_rect rectangle as it now contains the rectangle defined b...
Definition: gfx.cpp:1419
Right offset of the text of the frame.
Definition: window_gui.h:71
uint resize_y
Vertical resize step (0 means not resizable).
Definition: widget_type.h:165
Container with pre/inter/post child space.
Definition: widget_type.h:432
Grid of rows and columns.
Definition: widget_type.h:57
void SetupSmallestSize(Window *w, bool init_array) override
Compute smallest size needed by the widget.
Definition: widget.cpp:1531
void StoreSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height)
Store size and position.
Definition: widget_type.h:216
virtual void Draw(const Window *w)=0
Draw the widgets of the tree.
NWidgetBase * prev
Pointer to previous widget in container. Managed by parent container widget.
Definition: widget_type.h:179
Right offset of the image in the button.
Definition: window_gui.h:39
Top offset of the text of the frame.
Definition: window_gui.h:72
Left offset of the text of the frame.
Definition: window_gui.h:70
Top offset of defsize sprite.
Definition: window_gui.h:106
Force the arrow to the left.
Definition: widget_type.h:37
Window has a widget that has a highlight.
Definition: window_gui.h:241
NWidgetPIPContainer * child
Child widget.
Definition: widget_type.h:561
static Dimension debugbox_dimension
Cached size of a debugbox widget.
Definition: widget_type.h:784
Horizontal container.
Definition: widget_type.h:452
Base class that provides memory initialization on dynamically created objects.
Definition: alloc_type.hpp:85
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition: widget.cpp:656
uint8 post
Amount of space before/between/after child widgets.
Definition: widget_type.h:883
uint min_y
Minimal vertical size of only this widget.
Definition: widget_type.h:245
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
Text is written left-to-right by default.
Definition: strings_type.h:23
Window is being resized.
Definition: window_gui.h:237
Left offset of resize sprite.
Definition: window_gui.h:111
Bottom offset of closebox string.
Definition: window_gui.h:121
static void DrawShadeBox(const Rect &r, Colours colour, bool clicked)
Draw a shade box.
Definition: widget.cpp:459
uint8 padding_bottom
Paddings added to the bottom of the widget. Managed by parent container widget.
Definition: widget_type.h:183
static void DrawCloseBox(const Rect &r, Colours colour)
Draw a close box.
Definition: widget.cpp:523
Initialize nested widget tree to smallest size. Also updates current_x and current_y.
Definition: widget_type.h:110
Draw border only, no background.
Definition: window_gui.h:28
NWidgetPartTextLines text_lines
Part with text line data.
Definition: widget_type.h:916
NWidgetLeaf(WidgetType tp, Colours colour, int index, uint32 data, StringID tip)
Nested leaf widget.
Definition: widget.cpp:2111
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:984
NWidgetVertical(NWidContainerFlags flags=NC_NONE)
Vertical container widget.
Definition: widget.cpp:1292
NWidgetCore * GetWidgetFromPos(int x, int y) override
Retrieve a widget by its position.
Definition: widget.cpp:1462
Offset of the caption text at the top.
Definition: window_gui.h:127
bool newgrf_developer_tools
activate NewGRF developer tools and allow modifying NewGRFs in an existing game
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:700
static void DrawLabel(const Rect &r, WidgetType type, bool clicked, StringID str)
Draw the label-part of a widget.
Definition: widget.cpp:233
uint16 GetCount() const
Gets the number of elements in the list.
Definition: widget_type.h:611
int left
Screen coordinate left edge of the viewport.
Definition: viewport_type.h:23
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
void DrawViewport() const
Draw the viewport of this window.
Definition: viewport.cpp:1771
Draw only every second pixel, used for greying-out.
Definition: gfx_type.h:283
static void DrawStickyBox(const Rect &r, Colours colour, bool clicked)
Draw a sticky box.
Definition: widget.cpp:470
static int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
Definition: gfx_func.h:148
Top offset of shade sprite.
Definition: window_gui.h:85
Width of a standard sticky box widget.
Definition: window_gui.h:89
Bottom offset of scrollbar.
Definition: window_gui.h:51
Colours colour
Widget colour.
Definition: widget_type.h:866
void SetResize(uint resize_x, uint resize_y)
Set resize step of the widget.
Definition: widget.cpp:848
Functions related to companies.
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition: widget.cpp:1049
WidgetType
Window widget types, nested widget types, and nested widget part types.
Definition: widget_type.h:44
void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
Assign size and position to the widget.
Definition: widget.cpp:1198
void SetScrollbar(Scrollbar *sb)
Assign a scrollbar to this matrix.
Definition: widget.cpp:1526
virtual void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)=0
Assign size and position to the widget.
virtual NWidgetBase * GetWidgetOfType(WidgetType tp)
Retrieve a widget by its type.
Definition: widget.cpp:793
void ScrollbarClickHandler(Window *w, NWidgetCore *nw, int x, int y)
Special handling for the scrollbar widget type.
Definition: widget.cpp:136
Height of top bevel border.
Definition: window_gui.h:56
First zero-size plane.
Definition: widget_type.h:390
bool IsLowered() const
Return whether the widget is lowered.
Definition: widget_type.h:341
GUISettings gui
settings related to the GUI
void FillNestedArray(NWidgetBase **array, uint length) override
Fill the Window::nested_array array with pointers to nested widgets in the tree.
Definition: widget.cpp:1821
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
Data structure for viewport, display of a part of the world.
Definition: viewport_type.h:22
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
If set the frame is lowered and the background colour brighter (ie. buttons when pressed) ...
Definition: window_gui.h:29
Bottom offset of sticky sprite.
Definition: window_gui.h:93
static int MakeNWidget(const NWidgetPart *parts, int count, NWidgetBase **dest, bool *fill_dest, int *biggest_index)
Construct a single nested widget in *dest from its parts.
Definition: widget.cpp:2560
Offset of the caption text at the bottom.
Definition: window_gui.h:128
Bottom offset of debug sprite.
Definition: window_gui.h:100
static const byte _string_colourmap[17]
Colour mapping for TextColour.
NWidgetPartPaddings padding
Part with paddings.
Definition: widget_type.h:914
bool _window_highlight_colour
If false, highlight is white, otherwise the by the widget defined colour.
Definition: window.cpp:62
void UpdatePosition(int difference, ScrollbarStepping unit=SS_SMALL)
Updates the position of the first visible element by the given amount.
Definition: widget_type.h:712
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:48
Last Item. use WIDGETS_END to fill up padding!!
Definition: widget_type.h:70
void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override
Assign size and position to the widget.
Definition: widget.cpp:1023
uint8 spacing
Extra spacing around lines.
Definition: widget_type.h:892
Bit value of the &#39;scrollbar up&#39; or &#39;scrollbar down&#39; flag.
Definition: widget_type.h:274
Functions related to transparency.
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
Definition: window_gui.h:591
Sort ascending.
Definition: window_gui.h:224
uint TransparencyOptionBits
transparency option bits
Definition: transparency.h:36
Up-button is lowered bit.
Definition: widget_type.h:260
int index
Index of the nested widget in the widget array of the window (-1 means &#39;not used&#39;).
Definition: widget_type.h:302
Top offset of image in the button.
Definition: window_gui.h:40
NWidContainerFlags cont_flags
Part with container flags.
Definition: widget_type.h:918
NWidgetSpacer(int length, int height)
Generic spacer widget.
Definition: widget.cpp:1436
static Dimension defsizebox_dimension
Cached size of a defsizebox widget.
Definition: widget_type.h:785
Vertical container.
Definition: widget_type.h:75
static void DrawDefSizeBox(const Rect &r, Colours colour, bool clicked)
Draw a defsize box.
Definition: widget.cpp:481
static void DrawButtonDropdown(const Rect &r, Colours colour, bool clicked_button, bool clicked_dropdown, StringID str)
Draw a button with a dropdown (WWT_DROPDOWN and NWID_BUTTON_DROPDOWN).
Definition: widget.cpp:566
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
(Toggle) Button with diff text when clicked
Definition: widget_type.h:54
Functions related to zooming.
FontSize
Available font sizes.
Definition: gfx_type.h:201
int shown_plane
Plane being displayed (for NWID_SELECTION only).
Definition: widget_type.h:418
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:172
Right offset of string.
Definition: window_gui.h:45
Maximum number of companies.
Definition: company_type.h:23
Set if palette is actually a magic text recolour.
Definition: sprites.h:1509
NWidgetCore * GetWidgetFromPos(int x, int y) override
Retrieve a widget by its position.
Definition: widget.cpp:1868
Top offset of sticky sprite.
Definition: window_gui.h:92
void GetScrollOffsets(int &start_x, int &start_y, int &base_offs_x, int &base_offs_y)
Get the different offsets that are influenced by scrolling.
Definition: widget.cpp:1679
NWidgetContainer * MakeWindowNWidgetTree(const NWidgetPart *parts, int count, int *biggest_index, NWidgetStacked **shade_select)
Make a nested widget tree for a window from a parts array.
Definition: widget.cpp:2812
NWidgetBase * head
Pointer to first widget in container.
Definition: widget_type.h:380
Bottom offset of the dropdown widget string.
Definition: window_gui.h:135
Right offset of scrollbar.
Definition: window_gui.h:49
Coordinates of a point in 2D.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:770
void SetDisplayedPlane(int plane)
Select which plane to show (for NWID_SELECTION only).
Definition: widget.cpp:1082
NWidgetCore(WidgetType tp, Colours colour, uint fill_x, uint fill_y, uint32 widget_data, StringID tool_tip)
Initialization of a &#39;real&#39; widget.
Definition: widget.cpp:868
Colours _company_colours[MAX_COMPANIES]
NOSAVE: can be determined from company structs.
Definition: company_cmd.cpp:46
The colour translation of GRF&#39;s strings.
Drop down list.
Definition: widget_type.h:68
Normal push-button (no toggle button) with arrow caption.
Definition: widget_type.h:104
uint16 GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:620
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable...
Definition: window_gui.h:324
uint8 pip_pre
Amount of space before first widget.
Definition: widget_type.h:443
virtual void SetupSmallestSize(Window *w, bool init_array)=0
Compute smallest size needed by the widget.
void DrawCaption(const Rect &r, Colours colour, Owner owner, StringID str)
Draw a caption bar.
Definition: widget.cpp:538
Widget part for specifying minimal number of lines of text.
Definition: widget_type.h:87
Widget part to denote end of a container.
Definition: widget_type.h:92
Display plane with zero size horizontally, and filling and resizing vertically.
Definition: widget_type.h:386
Right offset of shade sprite.
Definition: window_gui.h:84
Width of a resize box widget.
Definition: window_gui.h:110
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:61
ZoomLevel zoom
The zoom level of the viewport.
Definition: viewport_type.h:33
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:64
void SetupSmallestSize(Window *w, bool init_array) override
Compute smallest size needed by the widget.
Definition: widget.cpp:1755
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:319
void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override
Assign size and position to the widget.
Definition: widget.cpp:1562
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
ZoomLevel
All zoom levels we know.
Definition: zoom_type.h:19
void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
Assign size and position to the widget.
Definition: widget.cpp:1286
Force the arrow to the right.
Definition: widget_type.h:38
void SetCapacityFromWidget(Window *w, int widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget. ...
Definition: widget.cpp:1971
Specification of a rectangle with absolute coordinates of all edges.
Vertical scrollbar.
Definition: widget_type.h:82
bool IsShaded() const
Is window shaded currently?
Definition: window_gui.h:524
Text is written right-to-left by default.
Definition: strings_type.h:24
Left offset of the dropdown widget string.
Definition: window_gui.h:132
int top
Screen coordinate top edge of the viewport.
Definition: viewport_type.h:24
Resize the nested widget tree.
Definition: widget_type.h:111
(Toggle) Button with image
Definition: widget_type.h:50
NWidgetDisplay disp_flags
Flags that affect display and interaction with the widget.
Definition: widget_type.h:300
Makes the background transparent if set.
Definition: window_gui.h:27
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:78
uint8 left
Paddings for all directions.
Definition: widget_type.h:875
ViewportData * viewport
Pointer to viewport data, if present.
Definition: window_gui.h:326
uint8 lines
Number of text lines.
Definition: widget_type.h:891
FontSize size
Font size of text lines.
Definition: widget_type.h:893
NWidgetHorizontalLTR(NWidContainerFlags flags=NC_NONE)
Horizontal left-to-right container widget.
Definition: widget.cpp:1281
void SetClicked(int clicked)
Sets the clicked widget in the matrix.
Definition: widget.cpp:1485
uint8 padding_right
Paddings added to the right of the widget. Managed by parent container widget. (parent container may ...
Definition: widget_type.h:182
const NWID * GetWidget(uint widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition: window_gui.h:842
Do not sort (with this button).
Definition: window_gui.h:223
virtual void SetDirty(const Window *w) const
Mark the widget as &#39;dirty&#39; (in need of repaint).
Definition: widget.cpp:773
Window white border counter bit mask.
Definition: window_gui.h:240
Left offset of the image in the button.
Definition: window_gui.h:38
Left offset of closebox string.
Definition: window_gui.h:118
uint fill_x
Horizontal fill stepsize (from initial size, 0 means not resizable).
Definition: widget_type.h:162
NWidgetBase * nested_root
Root of the nested tree.
Definition: window_gui.h:329
Dimensions (a width and height) of a rectangle in 2D.
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:427
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:60
This file contains all sprite-related enums and defines.
Nested widget with a child.
Definition: widget_type.h:543
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:62
static void DrawImageButtons(const Rect &r, WidgetType type, Colours colour, bool clicked, SpriteID img)
Draw an image button.
Definition: widget.cpp:216
void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
Assign size and position to the widget.
Definition: widget.cpp:854
Widget part for specifying minimal size.
Definition: widget_type.h:86
Horizontal container that doesn&#39;t change the order of the widgets for RTL languages.
Definition: widget_type.h:74
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:835
Right offset of the dropdown widget string.
Definition: window_gui.h:133
int pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:176
Top offset of the dropdown widget string.
Definition: window_gui.h:134
Offset of the caption text at the right.
Definition: window_gui.h:126
int mouse_capture_widget
Widgetindex of current mouse capture widget (e.g. dragged scrollbar). -1 if no widget has mouse captu...
Definition: window_gui.h:335
Top offset of closebox string.
Definition: window_gui.h:120
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:320
void SetupSmallestSize(Window *w, bool init_array)
Compute smallest size needed by the widget.
Definition: widget.cpp:1296
(Toggle) Button with text
Definition: widget_type.h:53
Top offset of string.
Definition: window_gui.h:46
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:629
Base class for a &#39;real&#39; widget.
Definition: widget_type.h:282
int width
Screen width of the viewport.
Definition: viewport_type.h:25