OpenTTD Source  13.0-beta1
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 
34 static inline Point GetAlignedPosition(const Rect &r, const Dimension &d, StringAlignment align)
35 {
36  Point p;
37  /* In case we have a RTL language we swap the alignment. */
38  if (!(align & SA_FORCE) && _current_text_dir == TD_RTL && (align & SA_HOR_MASK) != SA_HOR_CENTER) align ^= SA_RIGHT;
39  switch (align & SA_HOR_MASK) {
40  case SA_LEFT: p.x = r.left; break;
41  case SA_HOR_CENTER: p.x = CenterBounds(r.left, r.right, d.width); break;
42  case SA_RIGHT: p.x = r.right - d.width; break;
43  default: NOT_REACHED();
44  }
45  switch (align & SA_VERT_MASK) {
46  case SA_TOP: p.y = r.top; break;
47  case SA_VERT_CENTER: p.y = CenterBounds(r.top, r.bottom, d.height); break;
48  case SA_BOTTOM: p.y = r.bottom - d.height; break;
49  default: NOT_REACHED();
50  }
51  return p;
52 }
53 
63 static Point HandleScrollbarHittest(const Scrollbar *sb, int top, int bottom, bool horizontal)
64 {
65  /* Base for reversion */
66  int rev_base = top + bottom;
67  int button_size;
68  if (horizontal) {
69  button_size = NWidgetScrollbar::GetHorizontalDimension().width;
70  } else {
71  button_size = NWidgetScrollbar::GetVerticalDimension().height;
72  }
73  top += button_size; // top points to just below the up-button
74  bottom -= button_size; // bottom points to top of the down-button
75 
76  int height = (bottom - top);
77  int pos = sb->GetPosition();
78  int count = sb->GetCount();
79  int cap = sb->GetCapacity();
80 
81  if (count != 0) top += height * pos / count;
82 
83  if (cap > count) cap = count;
84  if (count != 0) bottom -= (count - pos - cap) * height / count;
85 
86  Point pt;
87  if (horizontal && _current_text_dir == TD_RTL) {
88  pt.x = rev_base - bottom;
89  pt.y = rev_base - top;
90  } else {
91  pt.x = top;
92  pt.y = bottom;
93  }
94  return pt;
95 }
96 
106 static void ScrollbarClickPositioning(Window *w, NWidgetScrollbar *sb, int x, int y, int mi, int ma)
107 {
108  int pos;
109  int button_size;
110  bool rtl = false;
111  bool changed = false;
112 
113  if (sb->type == NWID_HSCROLLBAR) {
114  pos = x;
115  rtl = _current_text_dir == TD_RTL;
116  button_size = NWidgetScrollbar::GetHorizontalDimension().width;
117  } else {
118  pos = y;
119  button_size = NWidgetScrollbar::GetVerticalDimension().height;
120  }
121  if (pos < mi + button_size) {
122  /* Pressing the upper button? */
124  if (_scroller_click_timeout <= 1) {
125  _scroller_click_timeout = 3;
126  changed = sb->UpdatePosition(rtl ? 1 : -1);
127  }
128  w->mouse_capture_widget = sb->index;
129  } else if (pos >= ma - button_size) {
130  /* Pressing the lower button? */
132 
133  if (_scroller_click_timeout <= 1) {
134  _scroller_click_timeout = 3;
135  changed = sb->UpdatePosition(rtl ? -1 : 1);
136  }
137  w->mouse_capture_widget = sb->index;
138  } else {
139  Point pt = HandleScrollbarHittest(sb, mi, ma, sb->type == NWID_HSCROLLBAR);
140 
141  if (pos < pt.x) {
142  changed = sb->UpdatePosition(rtl ? 1 : -1, Scrollbar::SS_BIG);
143  } else if (pos > pt.y) {
144  changed = sb->UpdatePosition(rtl ? -1 : 1, Scrollbar::SS_BIG);
145  } else {
146  _scrollbar_start_pos = pt.x - mi - button_size;
147  _scrollbar_size = ma - mi - button_size * 2;
148  w->mouse_capture_widget = sb->index;
149  _cursorpos_drag_start = _cursor.pos;
150  }
151  }
152 
153  if (changed) {
154  /* Position changed so refresh the window */
155  w->SetDirty();
156  } else {
157  /* No change so only refresh this scrollbar */
158  sb->SetDirty(w);
159  }
160 }
161 
170 void ScrollbarClickHandler(Window *w, NWidgetCore *nw, int x, int y)
171 {
172  int mi, ma;
173 
174  if (nw->type == NWID_HSCROLLBAR) {
175  mi = nw->pos_x;
176  ma = nw->pos_x + nw->current_x;
177  } else {
178  mi = nw->pos_y;
179  ma = nw->pos_y + nw->current_y;
180  }
181  NWidgetScrollbar *scrollbar = dynamic_cast<NWidgetScrollbar*>(nw);
182  assert(scrollbar != nullptr);
183  ScrollbarClickPositioning(w, scrollbar, x, y, mi, ma);
184 }
185 
194 int GetWidgetFromPos(const Window *w, int x, int y)
195 {
196  NWidgetCore *nw = w->nested_root->GetWidgetFromPos(x, y);
197  return (nw != nullptr) ? nw->index : -1;
198 }
199 
209 void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
210 {
211  assert(colour < COLOUR_END);
212 
213  uint dark = _colour_gradient[colour][3];
214  uint medium_dark = _colour_gradient[colour][5];
215  uint medium_light = _colour_gradient[colour][6];
216  uint light = _colour_gradient[colour][7];
217 
218  if (flags & FR_TRANSPARENT) {
219  GfxFillRect(left, top, right, bottom, PALETTE_TO_TRANSPARENT, FILLRECT_RECOLOUR);
220  } else {
221  uint interior;
222 
223  if (flags & FR_LOWERED) {
224  GfxFillRect(left, top, left, bottom, dark);
225  GfxFillRect(left + WD_BEVEL_LEFT, top, right, top, dark);
226  GfxFillRect(right, top + WD_BEVEL_TOP, right, bottom - WD_BEVEL_BOTTOM, light);
227  GfxFillRect(left + WD_BEVEL_LEFT, bottom, right, bottom, light);
228  interior = (flags & FR_DARKENED ? medium_dark : medium_light);
229  } else {
230  GfxFillRect(left, top, left, bottom - WD_BEVEL_BOTTOM, light);
231  GfxFillRect(left + WD_BEVEL_LEFT, top, right - WD_BEVEL_RIGHT, top, light);
232  GfxFillRect(right, top, right, bottom - WD_BEVEL_BOTTOM, dark);
233  GfxFillRect(left, bottom, right, bottom, dark);
234  interior = medium_dark;
235  }
236  if (!(flags & FR_BORDERONLY)) {
237  GfxFillRect(left + WD_BEVEL_LEFT, top + WD_BEVEL_TOP, right - WD_BEVEL_RIGHT, bottom - WD_BEVEL_BOTTOM, interior);
238  }
239  }
240 }
241 
251 static inline void DrawImageButtons(const Rect &r, WidgetType type, Colours colour, bool clicked, SpriteID img, StringAlignment align)
252 {
253  assert(img != 0);
254  DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE);
255 
256  if ((type & WWT_MASK) == WWT_IMGBTN_2 && clicked) img++; // Show different image when clicked for #WWT_IMGBTN_2.
257  Dimension d = GetSpriteSize(img);
258  Point p = GetAlignedPosition(r, d, align);
259  DrawSprite(img, PAL_NONE, p.x + clicked, p.y + clicked);
260 }
261 
271 static inline void DrawLabel(const Rect &r, WidgetType type, bool clicked, TextColour colour, StringID str, StringAlignment align)
272 {
273  if (str == STR_NULL) return;
274  if ((type & WWT_MASK) == WWT_TEXTBTN_2 && clicked) str++;
276  Point p = GetAlignedPosition(r, d, align);
277  DrawString(r.left + clicked, r.right + clicked, p.y + clicked, str, colour, align);
278 }
279 
287 static inline void DrawText(const Rect &r, TextColour colour, StringID str, StringAlignment align)
288 {
290  Point p = GetAlignedPosition(r, d, align);
291  if (str != STR_NULL) DrawString(r.left, r.right, p.y, str, colour, align);
292 }
293 
302 static inline void DrawInset(const Rect &r, Colours colour, TextColour text_colour, StringID str, StringAlignment align)
303 {
304  DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, FR_LOWERED | FR_DARKENED);
305  if (str != STR_NULL) DrawString(r.left + WD_INSET_LEFT, r.right - WD_INSET_RIGHT, r.top + WD_INSET_TOP, str, text_colour, align);
306 }
307 
317 static inline void DrawMatrix(const Rect &r, Colours colour, bool clicked, uint16 data, uint resize_x, uint resize_y)
318 {
319  DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE);
320 
321  int num_columns = GB(data, MAT_COL_START, MAT_COL_BITS); // Lower 8 bits of the widget data: Number of columns in the matrix.
322  int column_width; // Width of a single column in the matrix.
323  if (num_columns == 0) {
324  column_width = resize_x;
325  num_columns = (r.right - r.left + 1) / column_width;
326  } else {
327  column_width = (r.right - r.left + 1) / num_columns;
328  }
329 
330  int num_rows = GB(data, MAT_ROW_START, MAT_ROW_BITS); // Upper 8 bits of the widget data: Number of rows in the matrix.
331  int row_height; // Height of a single row in the matrix.
332  if (num_rows == 0) {
333  row_height = resize_y;
334  num_rows = (r.bottom - r.top + 1) / row_height;
335  } else {
336  row_height = (r.bottom - r.top + 1) / num_rows;
337  }
338 
339  int col = _colour_gradient[colour & 0xF][6];
340 
341  int x = r.left;
342  for (int ctr = num_columns; ctr > 1; ctr--) {
343  x += column_width;
344  GfxFillRect(x, r.top + 1, x, r.bottom - 1, col);
345  }
346 
347  x = r.top;
348  for (int ctr = num_rows; ctr > 1; ctr--) {
349  x += row_height;
350  GfxFillRect(r.left + 1, x, r.right - 1, x, col);
351  }
352 
353  col = _colour_gradient[colour & 0xF][4];
354 
355  x = r.left - 1;
356  for (int ctr = num_columns; ctr > 1; ctr--) {
357  x += column_width;
358  GfxFillRect(x, r.top + 1, x, r.bottom - 1, col);
359  }
360 
361  x = r.top - 1;
362  for (int ctr = num_rows; ctr > 1; ctr--) {
363  x += row_height;
364  GfxFillRect(r.left + 1, x, r.right - 1, x, col);
365  }
366 }
367 
377 static inline void DrawVerticalScrollbar(const Rect &r, Colours colour, bool up_clicked, bool bar_dragged, bool down_clicked, const Scrollbar *scrollbar)
378 {
379  int centre = (r.right - r.left) / 2;
380  int height = NWidgetScrollbar::GetVerticalDimension().height;
381 
382  /* draw up/down buttons */
383  DrawFrameRect(r.left, r.top, r.right, r.top + height - 1, colour, (up_clicked) ? FR_LOWERED : FR_NONE);
384  DrawSprite(SPR_ARROW_UP, PAL_NONE, r.left + 1 + up_clicked, r.top + 1 + up_clicked);
385 
386  DrawFrameRect(r.left, r.bottom - (height - 1), r.right, r.bottom, colour, (down_clicked) ? FR_LOWERED : FR_NONE);
387  DrawSprite(SPR_ARROW_DOWN, PAL_NONE, r.left + 1 + down_clicked, r.bottom - (height - 2) + down_clicked);
388 
389  int c1 = _colour_gradient[colour & 0xF][3];
390  int c2 = _colour_gradient[colour & 0xF][7];
391 
392  /* draw "shaded" background */
393  GfxFillRect(r.left, r.top + height, r.right, r.bottom - height, c2);
394  GfxFillRect(r.left, r.top + height, r.right, r.bottom - height, c1, FILLRECT_CHECKER);
395 
396  /* draw shaded lines */
397  GfxFillRect(r.left + centre - 3, r.top + height, r.left + centre - 3, r.bottom - height, c1);
398  GfxFillRect(r.left + centre - 2, r.top + height, r.left + centre - 2, r.bottom - height, c2);
399  GfxFillRect(r.left + centre + 2, r.top + height, r.left + centre + 2, r.bottom - height, c1);
400  GfxFillRect(r.left + centre + 3, r.top + height, r.left + centre + 3, r.bottom - height, c2);
401 
402  Point pt = HandleScrollbarHittest(scrollbar, r.top, r.bottom, false);
403  DrawFrameRect(r.left, pt.x, r.right, pt.y, colour, bar_dragged ? FR_LOWERED : FR_NONE);
404 }
405 
415 static inline void DrawHorizontalScrollbar(const Rect &r, Colours colour, bool left_clicked, bool bar_dragged, bool right_clicked, const Scrollbar *scrollbar)
416 {
417  int centre = (r.bottom - r.top) / 2;
418  int width = NWidgetScrollbar::GetHorizontalDimension().width;
419 
420  DrawFrameRect(r.left, r.top, r.left + width - 1, r.bottom, colour, left_clicked ? FR_LOWERED : FR_NONE);
421  DrawSprite(SPR_ARROW_LEFT, PAL_NONE, r.left + 1 + left_clicked, r.top + 1 + left_clicked);
422 
423  DrawFrameRect(r.right - (width - 1), r.top, r.right, r.bottom, colour, right_clicked ? FR_LOWERED : FR_NONE);
424  DrawSprite(SPR_ARROW_RIGHT, PAL_NONE, r.right - (width - 2) + right_clicked, r.top + 1 + right_clicked);
425 
426  int c1 = _colour_gradient[colour & 0xF][3];
427  int c2 = _colour_gradient[colour & 0xF][7];
428 
429  /* draw "shaded" background */
430  GfxFillRect(r.left + width, r.top, r.right - width, r.bottom, c2);
431  GfxFillRect(r.left + width, r.top, r.right - width, r.bottom, c1, FILLRECT_CHECKER);
432 
433  /* draw shaded lines */
434  GfxFillRect(r.left + width, r.top + centre - 3, r.right - width, r.top + centre - 3, c1);
435  GfxFillRect(r.left + width, r.top + centre - 2, r.right - width, r.top + centre - 2, c2);
436  GfxFillRect(r.left + width, r.top + centre + 2, r.right - width, r.top + centre + 2, c1);
437  GfxFillRect(r.left + width, r.top + centre + 3, r.right - width, r.top + centre + 3, c2);
438 
439  /* draw actual scrollbar */
440  Point pt = HandleScrollbarHittest(scrollbar, r.left, r.right, true);
441  DrawFrameRect(pt.x, r.top, pt.y, r.bottom, colour, bar_dragged ? FR_LOWERED : FR_NONE);
442 }
443 
452 static inline void DrawFrame(const Rect &r, Colours colour, TextColour text_colour, StringID str, StringAlignment align)
453 {
454  int x2 = r.left; // by default the left side is the left side of the widget
455 
456  if (str != STR_NULL) x2 = DrawString(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, r.top, str, text_colour, align);
457 
458  int c1 = _colour_gradient[colour][3];
459  int c2 = _colour_gradient[colour][7];
460 
461  /* If the frame has text, adjust the top bar to fit half-way through */
462  int dy1 = 4;
463  if (str != STR_NULL) dy1 = FONT_HEIGHT_NORMAL / 2 - 1;
464  int dy2 = dy1 + 1;
465 
466  if (_current_text_dir == TD_LTR) {
467  /* Line from upper left corner to start of text */
468  GfxFillRect(r.left, r.top + dy1, r.left + 4, r.top + dy1, c1);
469  GfxFillRect(r.left + 1, r.top + dy2, r.left + 4, r.top + dy2, c2);
470 
471  /* Line from end of text to upper right corner */
472  GfxFillRect(x2, r.top + dy1, r.right - 1, r.top + dy1, c1);
473  GfxFillRect(x2, r.top + dy2, r.right - 2, r.top + dy2, c2);
474  } else {
475  /* Line from upper left corner to start of text */
476  GfxFillRect(r.left, r.top + dy1, x2 - 2, r.top + dy1, c1);
477  GfxFillRect(r.left + 1, r.top + dy2, x2 - 2, r.top + dy2, c2);
478 
479  /* Line from end of text to upper right corner */
480  GfxFillRect(r.right - 5, r.top + dy1, r.right - 1, r.top + dy1, c1);
481  GfxFillRect(r.right - 5, r.top + dy2, r.right - 2, r.top + dy2, c2);
482  }
483 
484  /* Line from upper left corner to bottom left corner */
485  GfxFillRect(r.left, r.top + dy2, r.left, r.bottom - 1, c1);
486  GfxFillRect(r.left + 1, r.top + dy2 + 1, r.left + 1, r.bottom - 2, c2);
487 
488  /* Line from upper right corner to bottom right corner */
489  GfxFillRect(r.right - 1, r.top + dy2, r.right - 1, r.bottom - 2, c1);
490  GfxFillRect(r.right, r.top + dy1, r.right, r.bottom - 1, c2);
491 
492  GfxFillRect(r.left + 1, r.bottom - 1, r.right - 1, r.bottom - 1, c1);
493  GfxFillRect(r.left, r.bottom, r.right, r.bottom, c2);
494 }
495 
502 static inline void DrawShadeBox(const Rect &r, Colours colour, bool clicked)
503 {
504  DrawImageButtons(r, WWT_SHADEBOX, colour, clicked, clicked ? SPR_WINDOW_SHADE: SPR_WINDOW_UNSHADE, SA_CENTER);
505 }
506 
513 static inline void DrawStickyBox(const Rect &r, Colours colour, bool clicked)
514 {
515  DrawImageButtons(r, WWT_STICKYBOX, colour, clicked, clicked ? SPR_PIN_UP : SPR_PIN_DOWN, SA_CENTER);
516 }
517 
524 static inline void DrawDefSizeBox(const Rect &r, Colours colour, bool clicked)
525 {
526  DrawImageButtons(r, WWT_DEFSIZEBOX, colour, clicked, SPR_WINDOW_DEFSIZE, SA_CENTER);
527 }
528 
535 static inline void DrawDebugBox(const Rect &r, Colours colour, bool clicked)
536 {
537  DrawImageButtons(r, WWT_DEBUGBOX, colour, clicked, SPR_WINDOW_DEBUG, SA_CENTER);
538 }
539 
547 static inline void DrawResizeBox(const Rect &r, Colours colour, bool at_left, bool clicked)
548 {
549  DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE);
550  if (at_left) {
551  Dimension d = GetSpriteSize(SPR_WINDOW_RESIZE_LEFT);
552  DrawSprite(SPR_WINDOW_RESIZE_LEFT, PAL_NONE, r.left + WD_RESIZEBOX_RIGHT + clicked,
553  r.bottom + 1 - WD_RESIZEBOX_BOTTOM - d.height + clicked);
554  } else {
555  Dimension d = GetSpriteSize(SPR_WINDOW_RESIZE_RIGHT);
556  DrawSprite(SPR_WINDOW_RESIZE_RIGHT, PAL_NONE, r.right + 1 - WD_RESIZEBOX_RIGHT - d.width + clicked,
557  r.bottom + 1 - WD_RESIZEBOX_BOTTOM - d.height + clicked);
558  }
559 }
560 
566 static inline void DrawCloseBox(const Rect &r, Colours colour)
567 {
568  if (colour != COLOUR_WHITE) DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, FR_NONE);
569  Dimension d = GetSpriteSize(SPR_CLOSEBOX);
570  int s = UnScaleGUI(1); /* Offset to account for shadow of SPR_CLOSEBOX */
571  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));
572 }
573 
583 void DrawCaption(const Rect &r, Colours colour, Owner owner, TextColour text_colour, StringID str, StringAlignment align)
584 {
585  bool company_owned = owner < MAX_COMPANIES;
586 
587  DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, FR_BORDERONLY);
588  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);
589 
590  if (company_owned) {
591  GfxFillRect(r.left + 2, r.top + 2, r.right - 2, r.bottom - 2, _colour_gradient[_company_colours[owner]][4]);
592  }
593 
594  if (str != STR_NULL) {
596  Point p = GetAlignedPosition(r, d, align);
597  DrawString(r.left + WD_CAPTIONTEXT_LEFT, r.right - WD_CAPTIONTEXT_RIGHT, p.y, str, text_colour, align);
598  }
599 }
600 
612 static inline void DrawButtonDropdown(const Rect &r, Colours colour, bool clicked_button, bool clicked_dropdown, StringID str, StringAlignment align)
613 {
614  int text_offset = std::max(0, ((int)(r.bottom - r.top + 1) - FONT_HEIGHT_NORMAL) / 2); // Offset for rendering the text vertically centered
615 
616  int dd_width = NWidgetLeaf::dropdown_dimension.width;
617  int dd_height = NWidgetLeaf::dropdown_dimension.height;
618  int image_offset = std::max(0, ((int)(r.bottom - r.top + 1) - dd_height) / 2);
619 
620  if (_current_text_dir == TD_LTR) {
621  DrawFrameRect(r.left, r.top, r.right - dd_width, r.bottom, colour, clicked_button ? FR_LOWERED : FR_NONE);
622  DrawFrameRect(r.right + 1 - dd_width, r.top, r.right, r.bottom, colour, clicked_dropdown ? FR_LOWERED : FR_NONE);
623  DrawSprite(SPR_ARROW_DOWN, PAL_NONE, r.right - (dd_width - 2) + clicked_dropdown, r.top + image_offset + clicked_dropdown);
624  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, align);
625  } else {
626  DrawFrameRect(r.left + dd_width, r.top, r.right, r.bottom, colour, clicked_button ? FR_LOWERED : FR_NONE);
627  DrawFrameRect(r.left, r.top, r.left + dd_width - 1, r.bottom, colour, clicked_dropdown ? FR_LOWERED : FR_NONE);
628  DrawSprite(SPR_ARROW_DOWN, PAL_NONE, r.left + 1 + clicked_dropdown, r.top + image_offset + clicked_dropdown);
629  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, align);
630  }
631 }
632 
637 {
638  this->nested_root->Draw(this);
639 
640  if (this->flags & WF_WHITE_BORDER) {
641  DrawFrameRect(0, 0, this->width - 1, this->height - 1, COLOUR_WHITE, FR_BORDERONLY);
642  }
643 
644  if (this->flags & WF_HIGHLIGHTED) {
645  extern bool _window_highlight_colour;
646  for (uint i = 0; i < this->nested_array_size; i++) {
647  const NWidgetBase *widget = this->GetWidget<NWidgetBase>(i);
648  if (widget == nullptr || !widget->IsHighlighted()) continue;
649 
650  int left = widget->pos_x;
651  int top = widget->pos_y;
652  int right = left + widget->current_x - 1;
653  int bottom = top + widget->current_y - 1;
654 
655  int colour = _string_colourmap[_window_highlight_colour ? widget->GetHighlightColour() : TC_WHITE];
656 
657  GfxFillRect(left, top, left, bottom - WD_BEVEL_BOTTOM, colour);
658  GfxFillRect(left + WD_BEVEL_LEFT, top, right - WD_BEVEL_RIGHT, top, colour);
659  GfxFillRect(right, top, right, bottom - WD_BEVEL_BOTTOM, colour);
660  GfxFillRect(left, bottom, right, bottom, colour);
661  }
662  }
663 }
664 
670 void Window::DrawSortButtonState(int widget, SortButtonState state) const
671 {
672  if (state == SBS_OFF) return;
673 
674  assert(this->nested_array != nullptr);
675  const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(widget);
676 
677  /* Sort button uses the same sprites as vertical scrollbar */
678  Dimension dim = NWidgetScrollbar::GetVerticalDimension();
679  int offset = this->IsWidgetLowered(widget) ? 1 : 0;
680  int x = offset + nwid->pos_x + (_current_text_dir == TD_LTR ? nwid->current_x - dim.width : 0);
681  int y = offset + nwid->pos_y + (nwid->current_y - dim.height) / 2;
682 
683  DrawSprite(state == SBS_DOWN ? SPR_ARROW_DOWN : SPR_ARROW_UP, PAL_NONE, x, y);
684 }
685 
691 {
692  return NWidgetScrollbar::GetVerticalDimension().width + 1;
693 }
694 
695 
754 {
755  this->type = tp;
756 }
757 
758 /* ~NWidgetContainer() takes care of #next and #prev data members. */
759 
807 void NWidgetBase::SetDirty(const Window *w) const
808 {
809  int abs_left = w->left + this->pos_x;
810  int abs_top = w->top + this->pos_y;
811  AddDirtyBlock(abs_left, abs_top, abs_left + this->current_x, abs_top + this->current_y);
812 }
813 
828 {
829  return (this->type == tp) ? this : nullptr;
830 }
831 
832 void NWidgetBase::AdjustPaddingForZoom()
833 {
834  this->padding_top = ScaleGUITrad(this->uz_padding_top);
838 }
839 
847 {
848  this->fill_x = fill_x;
849  this->fill_y = fill_y;
850 }
851 
852 void NWidgetResizeBase::AdjustPaddingForZoom()
853 {
854  if (!this->absolute) {
855  this->min_x = ScaleGUITrad(this->uz_min_x);
856  this->min_y = std::max(ScaleGUITrad(this->uz_min_y), this->uz_text_lines * GetCharacterHeight(this->uz_text_size) + ScaleGUITrad(this->uz_text_spacing));
857  }
858  NWidgetBase::AdjustPaddingForZoom();
859 }
860 
866 void NWidgetResizeBase::SetMinimalSize(uint min_x, uint min_y)
867 {
868  this->uz_min_x = std::max(this->uz_min_x, min_x);
869  this->uz_min_y = std::max(this->uz_min_y, min_y);
870  this->min_x = ScaleGUITrad(this->uz_min_x);
871  this->min_y = std::max(ScaleGUITrad(this->uz_min_y), this->uz_text_lines * GetCharacterHeight(this->uz_text_size) + ScaleGUITrad(this->uz_text_spacing));
872 }
873 
879 void NWidgetResizeBase::SetMinimalSizeAbsolute(uint min_x, uint min_y)
880 {
881  this->absolute = true;
882  this->min_x = std::max(this->min_x, min_x);
883  this->min_y = std::max(this->min_y, min_y);
884 }
885 
892 void NWidgetResizeBase::SetMinimalTextLines(uint8 min_lines, uint8 spacing, FontSize size)
893 {
894  this->uz_text_lines = min_lines;
895  this->uz_text_spacing = spacing;
896  this->uz_text_size = size;
897  this->min_y = std::max(ScaleGUITrad(this->uz_min_y), this->uz_text_lines * GetCharacterHeight(this->uz_text_size) + ScaleGUITrad(this->uz_text_spacing));
898 }
899 
905 void NWidgetResizeBase::SetFill(uint fill_x, uint fill_y)
906 {
907  this->fill_x = fill_x;
908  this->fill_y = fill_y;
909 }
910 
916 void NWidgetResizeBase::SetResize(uint resize_x, uint resize_y)
917 {
918  this->resize_x = resize_x;
919  this->resize_y = resize_y;
920 }
921 
922 void NWidgetResizeBase::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
923 {
924  this->StoreSizePosition(sizing, x, y, given_width, given_height);
925 }
926 
936 NWidgetCore::NWidgetCore(WidgetType tp, Colours colour, uint fill_x, uint fill_y, uint32 widget_data, StringID tool_tip) : NWidgetResizeBase(tp, fill_x, fill_y)
937 {
938  this->colour = colour;
939  this->index = -1;
940  this->widget_data = widget_data;
941  this->tool_tip = tool_tip;
942  this->scrollbar_index = -1;
943  this->text_colour = TC_BLACK;
944  this->align = SA_CENTER;
945 }
946 
951 void NWidgetCore::SetIndex(int index)
952 {
953  assert(index >= 0);
954  this->index = index;
955 }
956 
962 void NWidgetCore::SetDataTip(uint32 widget_data, StringID tool_tip)
963 {
964  this->widget_data = widget_data;
965  this->tool_tip = tool_tip;
966 }
967 
973 {
974  this->text_colour = colour;
975 }
976 
982 {
983  this->tool_tip = tool_tip;
984 }
985 
991 {
992  this->align = align;
993 }
994 
995 void NWidgetCore::FillNestedArray(NWidgetBase **array, uint length)
996 {
997  if (this->index >= 0 && (uint)(this->index) < length) array[this->index] = this;
998 }
999 
1001 {
1002  return (IsInsideBS(x, this->pos_x, this->current_x) && IsInsideBS(y, this->pos_y, this->current_y)) ? this : nullptr;
1003 }
1004 
1010 {
1011  this->head = nullptr;
1012  this->tail = nullptr;
1013 }
1014 
1015 NWidgetContainer::~NWidgetContainer()
1016 {
1017  while (this->head != nullptr) {
1018  NWidgetBase *wid = this->head->next;
1019  delete this->head;
1020  this->head = wid;
1021  }
1022  this->tail = nullptr;
1023 }
1024 
1026 {
1027  if (this->type == tp) return this;
1028  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1029  NWidgetBase *nwid = child_wid->GetWidgetOfType(tp);
1030  if (nwid != nullptr) return nwid;
1031  }
1032  return nullptr;
1033 }
1034 
1035 void NWidgetContainer::AdjustPaddingForZoom()
1036 {
1037  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1038  child_wid->AdjustPaddingForZoom();
1039  }
1040  NWidgetBase::AdjustPaddingForZoom();
1041 }
1042 
1048 {
1049  assert(wid->next == nullptr && wid->prev == nullptr);
1050 
1051  if (this->head == nullptr) {
1052  this->head = wid;
1053  this->tail = wid;
1054  } else {
1055  assert(this->tail != nullptr);
1056  assert(this->tail->next == nullptr);
1057 
1058  this->tail->next = wid;
1059  wid->prev = this->tail;
1060  this->tail = wid;
1061  }
1062 }
1063 
1065 {
1066  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1067  child_wid->FillNestedArray(array, length);
1068  }
1069 }
1070 
1075 {
1076  this->index = -1;
1077 }
1078 
1079 void NWidgetStacked::SetIndex(int index)
1080 {
1081  this->index = index;
1082 }
1083 
1084 void NWidgetStacked::AdjustPaddingForZoom()
1085 {
1086  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1087  child_wid->AdjustPaddingForZoom();
1088  }
1089  NWidgetContainer::AdjustPaddingForZoom();
1090 }
1091 
1093 {
1094  if (this->index >= 0 && init_array) { // Fill w->nested_array[]
1095  assert(w->nested_array_size > (uint)this->index);
1096  w->nested_array[this->index] = this;
1097  }
1098 
1099  /* Zero size plane selected */
1100  if (this->shown_plane >= SZSP_BEGIN) {
1101  Dimension size = {0, 0};
1102  Dimension padding = {0, 0};
1103  Dimension fill = {(this->shown_plane == SZSP_HORIZONTAL), (this->shown_plane == SZSP_VERTICAL)};
1104  Dimension resize = {(this->shown_plane == SZSP_HORIZONTAL), (this->shown_plane == SZSP_VERTICAL)};
1105  /* Here we're primarily interested in the value of resize */
1106  if (this->index >= 0) w->UpdateWidgetSize(this->index, &size, padding, &fill, &resize);
1107 
1108  this->smallest_x = size.width;
1109  this->smallest_y = size.height;
1110  this->fill_x = fill.width;
1111  this->fill_y = fill.height;
1112  this->resize_x = resize.width;
1113  this->resize_y = resize.height;
1114  return;
1115  }
1116 
1117  /* First sweep, recurse down and compute minimal size and filling. */
1118  this->smallest_x = 0;
1119  this->smallest_y = 0;
1120  this->fill_x = (this->head != nullptr) ? 1 : 0;
1121  this->fill_y = (this->head != nullptr) ? 1 : 0;
1122  this->resize_x = (this->head != nullptr) ? 1 : 0;
1123  this->resize_y = (this->head != nullptr) ? 1 : 0;
1124  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1125  child_wid->SetupSmallestSize(w, init_array);
1126 
1127  this->smallest_x = std::max(this->smallest_x, child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right);
1128  this->smallest_y = std::max(this->smallest_y, child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom);
1129  this->fill_x = LeastCommonMultiple(this->fill_x, child_wid->fill_x);
1130  this->fill_y = LeastCommonMultiple(this->fill_y, child_wid->fill_y);
1131  this->resize_x = LeastCommonMultiple(this->resize_x, child_wid->resize_x);
1132  this->resize_y = LeastCommonMultiple(this->resize_y, child_wid->resize_y);
1133  }
1134 }
1135 
1136 void NWidgetStacked::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
1137 {
1138  assert(given_width >= this->smallest_x && given_height >= this->smallest_y);
1139  this->StoreSizePosition(sizing, x, y, given_width, given_height);
1140 
1141  if (this->shown_plane >= SZSP_BEGIN) return;
1142 
1143  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1144  uint hor_step = (sizing == ST_SMALLEST) ? 1 : child_wid->GetHorizontalStepSize(sizing);
1145  uint child_width = ComputeMaxSize(child_wid->smallest_x, given_width - child_wid->padding_left - child_wid->padding_right, hor_step);
1146  uint child_pos_x = (rtl ? child_wid->padding_right : child_wid->padding_left);
1147 
1148  uint vert_step = (sizing == ST_SMALLEST) ? 1 : child_wid->GetVerticalStepSize(sizing);
1149  uint child_height = ComputeMaxSize(child_wid->smallest_y, given_height - child_wid->padding_top - child_wid->padding_bottom, vert_step);
1150  uint child_pos_y = child_wid->padding_top;
1151 
1152  child_wid->AssignSizePosition(sizing, x + child_pos_x, y + child_pos_y, child_width, child_height, rtl);
1153  }
1154 }
1155 
1157 {
1158  if (this->index >= 0 && (uint)(this->index) < length) array[this->index] = this;
1159  NWidgetContainer::FillNestedArray(array, length);
1160 }
1161 
1163 {
1164  if (this->shown_plane >= SZSP_BEGIN) return;
1165 
1166  int plane = 0;
1167  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; plane++, child_wid = child_wid->next) {
1168  if (plane == this->shown_plane) {
1169  child_wid->Draw(w);
1170  return;
1171  }
1172  }
1173 
1174  NOT_REACHED();
1175 }
1176 
1178 {
1179  if (this->shown_plane >= SZSP_BEGIN) return nullptr;
1180 
1181  if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return nullptr;
1182  int plane = 0;
1183  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; plane++, child_wid = child_wid->next) {
1184  if (plane == this->shown_plane) {
1185  return child_wid->GetWidgetFromPos(x, y);
1186  }
1187  }
1188  return nullptr;
1189 }
1190 
1196 {
1197  this->shown_plane = plane;
1198 }
1199 
1200 NWidgetPIPContainer::NWidgetPIPContainer(WidgetType tp, NWidContainerFlags flags) : NWidgetContainer(tp)
1201 {
1202  this->flags = flags;
1203 }
1204 
1205 void NWidgetPIPContainer::AdjustPaddingForZoom()
1206 {
1207  this->pip_pre = ScaleGUITrad(this->uz_pip_pre);
1208  this->pip_inter = ScaleGUITrad(this->uz_pip_inter);
1209  this->pip_post = ScaleGUITrad(this->uz_pip_post);
1210  NWidgetContainer::AdjustPaddingForZoom();
1211 }
1212 
1222 void NWidgetPIPContainer::SetPIP(uint8 pip_pre, uint8 pip_inter, uint8 pip_post)
1223 {
1224  this->uz_pip_pre = pip_pre;
1225  this->uz_pip_inter = pip_inter;
1226  this->uz_pip_post = pip_post;
1227 
1228  this->pip_pre = ScaleGUITrad(this->uz_pip_pre);
1229  this->pip_inter = ScaleGUITrad(this->uz_pip_inter);
1230  this->pip_post = ScaleGUITrad(this->uz_pip_post);
1231 }
1232 
1234 {
1235  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1236  child_wid->Draw(w);
1237  }
1238 }
1239 
1241 {
1242  if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return nullptr;
1243 
1244  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1245  NWidgetCore *nwid = child_wid->GetWidgetFromPos(x, y);
1246  if (nwid != nullptr) return nwid;
1247  }
1248  return nullptr;
1249 }
1250 
1253 {
1254 }
1255 
1257 {
1258  this->smallest_x = 0; // Sum of minimal size of all children.
1259  this->smallest_y = 0; // Biggest child.
1260  this->fill_x = 0; // smallest non-zero child widget fill step.
1261  this->fill_y = 1; // smallest common child fill step.
1262  this->resize_x = 0; // smallest non-zero child widget resize step.
1263  this->resize_y = 1; // smallest common child resize step.
1264 
1265  /* 1a. Forward call, collect biggest nested array index, and longest/widest child length. */
1266  uint longest = 0; // Longest child found.
1267  uint max_vert_fill = 0; // Biggest vertical fill step.
1268  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1269  child_wid->SetupSmallestSize(w, init_array);
1270  longest = std::max(longest, child_wid->smallest_x);
1271  max_vert_fill = std::max(max_vert_fill, child_wid->GetVerticalStepSize(ST_SMALLEST));
1272  this->smallest_y = std::max(this->smallest_y, child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom);
1273  }
1274  /* 1b. Make the container higher if needed to accommodate all children nicely. */
1275  [[maybe_unused]] uint max_smallest = this->smallest_y + 3 * max_vert_fill; // Upper limit to computing smallest height.
1276  uint cur_height = this->smallest_y;
1277  for (;;) {
1278  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1279  uint step_size = child_wid->GetVerticalStepSize(ST_SMALLEST);
1280  uint child_height = child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom;
1281  if (step_size > 1 && child_height < cur_height) { // Small step sizes or already fitting children are not interesting.
1282  uint remainder = (cur_height - child_height) % step_size;
1283  if (remainder > 0) { // Child did not fit entirely, widen the container.
1284  cur_height += step_size - remainder;
1285  assert(cur_height < max_smallest); // Safeguard against infinite height expansion.
1286  /* Remaining children will adapt to the new cur_height, thus speeding up the computation. */
1287  }
1288  }
1289  }
1290  if (this->smallest_y == cur_height) break;
1291  this->smallest_y = cur_height; // Smallest height got changed, try again.
1292  }
1293  /* 2. For containers that must maintain equal width, extend child minimal size. */
1294  if (this->flags & NC_EQUALSIZE) {
1295  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1296  if (child_wid->fill_x == 1) child_wid->smallest_x = longest;
1297  }
1298  }
1299  /* 3. Move PIP space to the children, compute smallest, fill, and resize values of the container. */
1300  if (this->head != nullptr) this->head->padding_left += this->pip_pre;
1301  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1302  if (child_wid->next != nullptr) {
1303  child_wid->padding_right += this->pip_inter;
1304  } else {
1305  child_wid->padding_right += this->pip_post;
1306  }
1307 
1308  this->smallest_x += child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right;
1309  if (child_wid->fill_x > 0) {
1310  if (this->fill_x == 0 || this->fill_x > child_wid->fill_x) this->fill_x = child_wid->fill_x;
1311  }
1312  this->fill_y = LeastCommonMultiple(this->fill_y, child_wid->fill_y);
1313 
1314  if (child_wid->resize_x > 0) {
1315  if (this->resize_x == 0 || this->resize_x > child_wid->resize_x) this->resize_x = child_wid->resize_x;
1316  }
1317  this->resize_y = LeastCommonMultiple(this->resize_y, child_wid->resize_y);
1318  }
1319  /* We need to zero the PIP settings so we can re-initialize the tree. */
1320  this->pip_pre = this->pip_inter = this->pip_post = 0;
1321 }
1322 
1323 void NWidgetHorizontal::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
1324 {
1325  assert(given_width >= this->smallest_x && given_height >= this->smallest_y);
1326 
1327  /* Compute additional width given to us. */
1328  uint additional_length = given_width;
1329  if (sizing == ST_SMALLEST && (this->flags & NC_EQUALSIZE)) {
1330  /* For EQUALSIZE containers this does not sum to smallest_x during initialisation */
1331  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1332  additional_length -= child_wid->smallest_x + child_wid->padding_right + child_wid->padding_left;
1333  }
1334  } else {
1335  additional_length -= this->smallest_x;
1336  }
1337 
1338  this->StoreSizePosition(sizing, x, y, given_width, given_height);
1339 
1340  /* In principle, the additional horizontal space is distributed evenly over the available resizable children. Due to step sizes, this may not always be feasible.
1341  * To make resizing work as good as possible, first children with biggest step sizes are done. These may get less due to rounding down.
1342  * 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
1343  * of the child with the smallest non-zero stepsize.
1344  *
1345  * 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
1346  * size and position, and directly call child->AssignSizePosition() with the computed values.
1347  * 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
1348  * then we call the child.
1349  */
1350 
1351  /* First loop: Find biggest stepsize, find number of children that want a piece of the pie, handle vertical size for all children,
1352  * handle horizontal size for non-resizing children.
1353  */
1354  int num_changing_childs = 0; // Number of children that can change size.
1355  uint biggest_stepsize = 0;
1356  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1357  uint hor_step = child_wid->GetHorizontalStepSize(sizing);
1358  if (hor_step > 0) {
1359  if (!(flags & NC_BIGFIRST)) num_changing_childs++;
1360  biggest_stepsize = std::max(biggest_stepsize, hor_step);
1361  } else {
1362  child_wid->current_x = child_wid->smallest_x;
1363  }
1364 
1365  uint vert_step = (sizing == ST_SMALLEST) ? 1 : child_wid->GetVerticalStepSize(sizing);
1366  child_wid->current_y = ComputeMaxSize(child_wid->smallest_y, given_height - child_wid->padding_top - child_wid->padding_bottom, vert_step);
1367  }
1368 
1369  /* First.5 loop: count how many children are of the biggest step size. */
1370  if ((flags & NC_BIGFIRST) && biggest_stepsize > 0) {
1371  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1372  uint hor_step = child_wid->GetHorizontalStepSize(sizing);
1373  if (hor_step == biggest_stepsize) {
1374  num_changing_childs++;
1375  }
1376  }
1377  }
1378 
1379  /* Second loop: Allocate the additional horizontal space over the resizing children, starting with the biggest resize steps. */
1380  while (biggest_stepsize > 0) {
1381  uint next_biggest_stepsize = 0;
1382  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1383  uint hor_step = child_wid->GetHorizontalStepSize(sizing);
1384  if (hor_step > biggest_stepsize) continue; // Already done
1385  if (hor_step == biggest_stepsize) {
1386  uint increment = additional_length / num_changing_childs;
1387  num_changing_childs--;
1388  if (hor_step > 1) increment -= increment % hor_step;
1389  child_wid->current_x = child_wid->smallest_x + increment;
1390  additional_length -= increment;
1391  continue;
1392  }
1393  next_biggest_stepsize = std::max(next_biggest_stepsize, hor_step);
1394  }
1395  biggest_stepsize = next_biggest_stepsize;
1396 
1397  if (num_changing_childs == 0 && (flags & NC_BIGFIRST) && biggest_stepsize > 0) {
1398  /* Second.5 loop: count how many children are of the updated biggest step size. */
1399  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1400  uint hor_step = child_wid->GetHorizontalStepSize(sizing);
1401  if (hor_step == biggest_stepsize) {
1402  num_changing_childs++;
1403  }
1404  }
1405  }
1406  }
1407  assert(num_changing_childs == 0);
1408 
1409  /* Third loop: Compute position and call the child. */
1410  uint position = rtl ? this->current_x : 0; // Place to put next child relative to origin of the container.
1411  NWidgetBase *child_wid = this->head;
1412  while (child_wid != nullptr) {
1413  uint child_width = child_wid->current_x;
1414  uint child_x = x + (rtl ? position - child_width - child_wid->padding_left : position + child_wid->padding_left);
1415  uint child_y = y + child_wid->padding_top;
1416 
1417  child_wid->AssignSizePosition(sizing, child_x, child_y, child_width, child_wid->current_y, rtl);
1418  uint padded_child_width = child_width + child_wid->padding_right + child_wid->padding_left;
1419  position = rtl ? position - padded_child_width : position + padded_child_width;
1420 
1421  child_wid = child_wid->next;
1422  }
1423 }
1424 
1427 {
1428  this->type = NWID_HORIZONTAL_LTR;
1429 }
1430 
1431 void NWidgetHorizontalLTR::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
1432 {
1433  NWidgetHorizontal::AssignSizePosition(sizing, x, y, given_width, given_height, false);
1434 }
1435 
1438 {
1439 }
1440 
1442 {
1443  this->smallest_x = 0; // Biggest child.
1444  this->smallest_y = 0; // Sum of minimal size of all children.
1445  this->fill_x = 1; // smallest common child fill step.
1446  this->fill_y = 0; // smallest non-zero child widget fill step.
1447  this->resize_x = 1; // smallest common child resize step.
1448  this->resize_y = 0; // smallest non-zero child widget resize step.
1449 
1450  /* 1a. Forward call, collect biggest nested array index, and longest/widest child length. */
1451  uint highest = 0; // Highest child found.
1452  uint max_hor_fill = 0; // Biggest horizontal fill step.
1453  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1454  child_wid->SetupSmallestSize(w, init_array);
1455  highest = std::max(highest, child_wid->smallest_y);
1456  max_hor_fill = std::max(max_hor_fill, child_wid->GetHorizontalStepSize(ST_SMALLEST));
1457  this->smallest_x = std::max(this->smallest_x, child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right);
1458  }
1459  /* 1b. Make the container wider if needed to accommodate all children nicely. */
1460  [[maybe_unused]] uint max_smallest = this->smallest_x + 3 * max_hor_fill; // Upper limit to computing smallest height.
1461  uint cur_width = this->smallest_x;
1462  for (;;) {
1463  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1464  uint step_size = child_wid->GetHorizontalStepSize(ST_SMALLEST);
1465  uint child_width = child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right;
1466  if (step_size > 1 && child_width < cur_width) { // Small step sizes or already fitting children are not interesting.
1467  uint remainder = (cur_width - child_width) % step_size;
1468  if (remainder > 0) { // Child did not fit entirely, widen the container.
1469  cur_width += step_size - remainder;
1470  assert(cur_width < max_smallest); // Safeguard against infinite width expansion.
1471  /* Remaining children will adapt to the new cur_width, thus speeding up the computation. */
1472  }
1473  }
1474  }
1475  if (this->smallest_x == cur_width) break;
1476  this->smallest_x = cur_width; // Smallest width got changed, try again.
1477  }
1478  /* 2. For containers that must maintain equal width, extend children minimal size. */
1479  if (this->flags & NC_EQUALSIZE) {
1480  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1481  if (child_wid->fill_y == 1) child_wid->smallest_y = highest;
1482  }
1483  }
1484  /* 3. Move PIP space to the child, compute smallest, fill, and resize values of the container. */
1485  if (this->head != nullptr) this->head->padding_top += this->pip_pre;
1486  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1487  if (child_wid->next != nullptr) {
1488  child_wid->padding_bottom += this->pip_inter;
1489  } else {
1490  child_wid->padding_bottom += this->pip_post;
1491  }
1492 
1493  this->smallest_y += child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom;
1494  if (child_wid->fill_y > 0) {
1495  if (this->fill_y == 0 || this->fill_y > child_wid->fill_y) this->fill_y = child_wid->fill_y;
1496  }
1497  this->fill_x = LeastCommonMultiple(this->fill_x, child_wid->fill_x);
1498 
1499  if (child_wid->resize_y > 0) {
1500  if (this->resize_y == 0 || this->resize_y > child_wid->resize_y) this->resize_y = child_wid->resize_y;
1501  }
1502  this->resize_x = LeastCommonMultiple(this->resize_x, child_wid->resize_x);
1503  }
1504  /* We need to zero the PIP settings so we can re-initialize the tree. */
1505  this->pip_pre = this->pip_inter = this->pip_post = 0;
1506 }
1507 
1508 void NWidgetVertical::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
1509 {
1510  assert(given_width >= this->smallest_x && given_height >= this->smallest_y);
1511 
1512  /* Compute additional height given to us. */
1513  uint additional_length = given_height;
1514  if (sizing == ST_SMALLEST && (this->flags & NC_EQUALSIZE)) {
1515  /* For EQUALSIZE containers this does not sum to smallest_y during initialisation */
1516  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1517  additional_length -= child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom;
1518  }
1519  } else {
1520  additional_length -= this->smallest_y;
1521  }
1522 
1523  this->StoreSizePosition(sizing, x, y, given_width, given_height);
1524 
1525  /* Like the horizontal container, the vertical container also distributes additional height evenly, starting with the children with the biggest resize steps.
1526  * It also stores computed widths and heights into current_x and current_y values of the child.
1527  */
1528 
1529  /* 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. */
1530  int num_changing_childs = 0; // Number of children that can change size.
1531  uint biggest_stepsize = 0;
1532  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1533  uint vert_step = child_wid->GetVerticalStepSize(sizing);
1534  if (vert_step > 0) {
1535  if (!(flags & NC_BIGFIRST)) num_changing_childs++;
1536  biggest_stepsize = std::max(biggest_stepsize, vert_step);
1537  } else {
1538  child_wid->current_y = child_wid->smallest_y;
1539  }
1540 
1541  uint hor_step = (sizing == ST_SMALLEST) ? 1 : child_wid->GetHorizontalStepSize(sizing);
1542  child_wid->current_x = ComputeMaxSize(child_wid->smallest_x, given_width - child_wid->padding_left - child_wid->padding_right, hor_step);
1543  }
1544 
1545  /* First.5 loop: count how many children are of the biggest step size. */
1546  if ((this->flags & NC_BIGFIRST) && biggest_stepsize > 0) {
1547  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1548  uint vert_step = child_wid->GetVerticalStepSize(sizing);
1549  if (vert_step == biggest_stepsize) {
1550  num_changing_childs++;
1551  }
1552  }
1553  }
1554 
1555  /* Second loop: Allocate the additional vertical space over the resizing children, starting with the biggest resize steps. */
1556  while (biggest_stepsize > 0) {
1557  uint next_biggest_stepsize = 0;
1558  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1559  uint vert_step = child_wid->GetVerticalStepSize(sizing);
1560  if (vert_step > biggest_stepsize) continue; // Already done
1561  if (vert_step == biggest_stepsize) {
1562  uint increment = additional_length / num_changing_childs;
1563  num_changing_childs--;
1564  if (vert_step > 1) increment -= increment % vert_step;
1565  child_wid->current_y = child_wid->smallest_y + increment;
1566  additional_length -= increment;
1567  continue;
1568  }
1569  next_biggest_stepsize = std::max(next_biggest_stepsize, vert_step);
1570  }
1571  biggest_stepsize = next_biggest_stepsize;
1572 
1573  if (num_changing_childs == 0 && (flags & NC_BIGFIRST) && biggest_stepsize > 0) {
1574  /* Second.5 loop: count how many children are of the updated biggest step size. */
1575  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1576  uint vert_step = child_wid->GetVerticalStepSize(sizing);
1577  if (vert_step == biggest_stepsize) {
1578  num_changing_childs++;
1579  }
1580  }
1581  }
1582  }
1583  assert(num_changing_childs == 0);
1584 
1585  /* Third loop: Compute position and call the child. */
1586  uint position = 0; // Place to put next child relative to origin of the container.
1587  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1588  uint child_x = x + (rtl ? child_wid->padding_right : child_wid->padding_left);
1589  uint child_height = child_wid->current_y;
1590 
1591  child_wid->AssignSizePosition(sizing, child_x, y + position + child_wid->padding_top, child_wid->current_x, child_height, rtl);
1592  position += child_height + child_wid->padding_top + child_wid->padding_bottom;
1593  }
1594 }
1595 
1602 {
1603  this->SetMinimalSize(width, height);
1604  this->SetResize(0, 0);
1605 }
1606 
1607 void NWidgetSpacer::SetupSmallestSize(Window *w, bool init_array)
1608 {
1609  this->smallest_x = this->min_x;
1610  this->smallest_y = this->min_y;
1611 }
1612 
1614 {
1615 }
1616 
1618 {
1619  /* Spacer widget is never visible. */
1620 }
1621 
1622 void NWidgetSpacer::SetDirty(const Window *w) const
1623 {
1624  /* Spacer widget never need repainting. */
1625 }
1626 
1628 {
1629  return nullptr;
1630 }
1631 
1632 NWidgetMatrix::NWidgetMatrix() : NWidgetPIPContainer(NWID_MATRIX, NC_EQUALSIZE), index(-1), clicked(-1), count(-1)
1633 {
1634 }
1635 
1636 void NWidgetMatrix::SetIndex(int index)
1637 {
1638  this->index = index;
1639 }
1640 
1641 void NWidgetMatrix::SetColour(Colours colour)
1642 {
1643  this->colour = colour;
1644 }
1645 
1650 void NWidgetMatrix::SetClicked(int clicked)
1651 {
1652  this->clicked = clicked;
1653  if (this->clicked >= 0 && this->sb != nullptr && this->widgets_x != 0) {
1654  int vpos = (this->clicked / this->widgets_x) * this->widget_h; // Vertical position of the top.
1655  /* Need to scroll down -> Scroll to the bottom.
1656  * However, last entry has no 'this->pip_inter' underneath, and we must stay below this->sb->GetCount() */
1657  if (this->sb->GetPosition() < vpos) vpos += this->widget_h - this->pip_inter - 1;
1658  this->sb->ScrollTowards(vpos);
1659  }
1660 }
1661 
1668 {
1669  this->count = count;
1670 
1671  if (this->sb == nullptr || this->widgets_x == 0) return;
1672 
1673  /* We need to get the number of pixels the matrix is high/wide.
1674  * So, determine the number of rows/columns based on the number of
1675  * columns/rows (one is constant/unscrollable).
1676  * Then multiply that by the height of a widget, and add the pre
1677  * and post spacing "offsets". */
1678  count = CeilDiv(count, this->sb->IsVertical() ? this->widgets_x : this->widgets_y);
1679  count *= (this->sb->IsVertical() ? this->head->smallest_y : this->head->smallest_x) + this->pip_inter;
1680  if (count > 0) count -= this->pip_inter; // We counted an inter too much in the multiplication above
1681  count += this->pip_pre + this->pip_post;
1682  this->sb->SetCount(count);
1683  this->sb->SetCapacity(this->sb->IsVertical() ? this->current_y : this->current_x);
1684  this->sb->SetStepSize(this->sb->IsVertical() ? this->widget_h : this->widget_w);
1685 }
1686 
1692 {
1693  this->sb = sb;
1694 }
1695 
1696 void NWidgetMatrix::SetupSmallestSize(Window *w, bool init_array)
1697 {
1698  assert(this->head != nullptr);
1699  assert(this->head->next == nullptr);
1700 
1701  if (this->index >= 0 && init_array) { // Fill w->nested_array[]
1702  assert(w->nested_array_size > (uint)this->index);
1703  w->nested_array[this->index] = this;
1704  }
1705 
1706  /* Reset the widget number. */
1707  NWidgetCore *nw = dynamic_cast<NWidgetCore *>(this->head);
1708  assert(nw != nullptr);
1709  SB(nw->index, 16, 16, 0);
1710  this->head->SetupSmallestSize(w, init_array);
1711 
1712  Dimension padding = { (uint)this->pip_pre + this->pip_post, (uint)this->pip_pre + this->pip_post};
1713  Dimension size = {this->head->smallest_x + padding.width, this->head->smallest_y + padding.height};
1714  Dimension fill = {0, 0};
1715  Dimension resize = {this->pip_inter + this->head->smallest_x, this->pip_inter + this->head->smallest_y};
1716 
1717  if (this->index >= 0) w->UpdateWidgetSize(this->index, &size, padding, &fill, &resize);
1718 
1719  this->smallest_x = size.width;
1720  this->smallest_y = size.height;
1721  this->fill_x = fill.width;
1722  this->fill_y = fill.height;
1723  this->resize_x = resize.width;
1724  this->resize_y = resize.height;
1725 }
1726 
1727 void NWidgetMatrix::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
1728 {
1729  assert(given_width >= this->smallest_x && given_height >= this->smallest_y);
1730 
1731  this->pos_x = x;
1732  this->pos_y = y;
1733  this->current_x = given_width;
1734  this->current_y = given_height;
1735 
1736  /* Determine the size of the widgets, and the number of visible widgets on each of the axis. */
1737  this->widget_w = this->head->smallest_x + this->pip_inter;
1738  this->widget_h = this->head->smallest_y + this->pip_inter;
1739 
1740  /* Account for the pip_inter is between widgets, so we need to account for that when
1741  * the division assumes pip_inter is used for all widgets. */
1742  this->widgets_x = CeilDiv(this->current_x - this->pip_pre - this->pip_post + this->pip_inter, this->widget_w);
1743  this->widgets_y = CeilDiv(this->current_y - this->pip_pre - this->pip_post + this->pip_inter, this->widget_h);
1744 
1745  /* When resizing, update the scrollbar's count. E.g. with a vertical
1746  * scrollbar becoming wider or narrower means the amount of rows in
1747  * the scrollbar becomes respectively smaller or higher. */
1748  this->SetCount(this->count);
1749 }
1750 
1752 {
1753  if (this->index >= 0 && (uint)(this->index) < length) array[this->index] = this;
1754  NWidgetContainer::FillNestedArray(array, length);
1755 }
1756 
1758 {
1759  /* Falls outside of the matrix widget. */
1760  if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return nullptr;
1761 
1762  int start_x, start_y, base_offs_x, base_offs_y;
1763  this->GetScrollOffsets(start_x, start_y, base_offs_x, base_offs_y);
1764 
1765  bool rtl = _current_text_dir == TD_RTL;
1766 
1767  int widget_col = (rtl ?
1768  -x + (int)this->pip_post + (int)this->pos_x + base_offs_x + (int)this->widget_w - 1 - (int)this->pip_inter :
1769  x - (int)this->pip_pre - (int)this->pos_x - base_offs_x
1770  ) / this->widget_w;
1771 
1772  int widget_row = (y - base_offs_y - (int)this->pip_pre - (int)this->pos_y) / this->widget_h;
1773 
1774  int sub_wid = (widget_row + start_y) * this->widgets_x + start_x + widget_col;
1775  if (sub_wid >= this->count) return nullptr;
1776 
1777  NWidgetCore *child = dynamic_cast<NWidgetCore *>(this->head);
1778  assert(child != nullptr);
1780  this->pos_x + (rtl ? this->pip_post - widget_col * this->widget_w : this->pip_pre + widget_col * this->widget_w) + base_offs_x,
1781  this->pos_y + this->pip_pre + widget_row * this->widget_h + base_offs_y,
1782  child->smallest_x, child->smallest_y, rtl);
1783 
1784  SB(child->index, 16, 16, sub_wid);
1785 
1786  return child->GetWidgetFromPos(x, y);
1787 }
1788 
1789 /* virtual */ void NWidgetMatrix::Draw(const Window *w)
1790 {
1791  /* Fill the background. */
1792  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]);
1793 
1794  /* Set up a clipping area for the previews. */
1795  bool rtl = _current_text_dir == TD_RTL;
1796  DrawPixelInfo tmp_dpi;
1797  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;
1798  DrawPixelInfo *old_dpi = _cur_dpi;
1799  _cur_dpi = &tmp_dpi;
1800 
1801  /* Get the appropriate offsets so we can draw the right widgets. */
1802  NWidgetCore *child = dynamic_cast<NWidgetCore *>(this->head);
1803  assert(child != nullptr);
1804  int start_x, start_y, base_offs_x, base_offs_y;
1805  this->GetScrollOffsets(start_x, start_y, base_offs_x, base_offs_y);
1806 
1807  int offs_y = base_offs_y;
1808  for (int y = start_y; y < start_y + this->widgets_y + 1; y++, offs_y += this->widget_h) {
1809  /* Are we within bounds? */
1810  if (offs_y + child->smallest_y <= 0) continue;
1811  if (offs_y >= (int)this->current_y) break;
1812 
1813  /* We've passed our amount of widgets. */
1814  if (y * this->widgets_x >= this->count) break;
1815 
1816  int offs_x = base_offs_x;
1817  for (int x = start_x; x < start_x + this->widgets_x + 1; x++, offs_x += rtl ? -this->widget_w : this->widget_w) {
1818  /* Are we within bounds? */
1819  if (offs_x + child->smallest_x <= 0) continue;
1820  if (offs_x >= (int)this->current_x) continue;
1821 
1822  /* Do we have this many widgets? */
1823  int sub_wid = y * this->widgets_x + x;
1824  if (sub_wid >= this->count) break;
1825 
1826  child->AssignSizePosition(ST_RESIZE, offs_x, offs_y, child->smallest_x, child->smallest_y, rtl);
1827  child->SetLowered(this->clicked == sub_wid);
1828  SB(child->index, 16, 16, sub_wid);
1829  child->Draw(w);
1830  }
1831  }
1832 
1833  /* Restore the clipping area. */
1834  _cur_dpi = old_dpi;
1835 }
1836 
1844 void NWidgetMatrix::GetScrollOffsets(int &start_x, int &start_y, int &base_offs_x, int &base_offs_y)
1845 {
1846  base_offs_x = _current_text_dir == TD_RTL ? this->widget_w * (this->widgets_x - 1) : 0;
1847  base_offs_y = 0;
1848  start_x = 0;
1849  start_y = 0;
1850  if (this->sb != nullptr) {
1851  if (this->sb->IsVertical()) {
1852  start_y = this->sb->GetPosition() / this->widget_h;
1853  base_offs_y += -this->sb->GetPosition() + start_y * this->widget_h;
1854  } else {
1855  start_x = this->sb->GetPosition() / this->widget_w;
1856  int sub_x = this->sb->GetPosition() - start_x * this->widget_w;
1857  if (_current_text_dir == TD_RTL) {
1858  base_offs_x += sub_x;
1859  } else {
1860  base_offs_x -= sub_x;
1861  }
1862  }
1863  }
1864 }
1865 
1875 NWidgetBackground::NWidgetBackground(WidgetType tp, Colours colour, int index, NWidgetPIPContainer *child) : NWidgetCore(tp, colour, 1, 1, 0x0, STR_NULL)
1876 {
1877  assert(tp == WWT_PANEL || tp == WWT_INSET || tp == WWT_FRAME);
1878  if (index >= 0) this->SetIndex(index);
1879  this->child = child;
1880  this->SetAlignment(SA_TOP | SA_LEFT);
1881 }
1882 
1883 NWidgetBackground::~NWidgetBackground()
1884 {
1885  if (this->child != nullptr) delete this->child;
1886 }
1887 
1896 {
1897  if (this->child == nullptr) {
1898  this->child = new NWidgetVertical();
1899  }
1900  this->child->Add(nwid);
1901 }
1902 
1913 void NWidgetBackground::SetPIP(uint8 pip_pre, uint8 pip_inter, uint8 pip_post)
1914 {
1915  if (this->child == nullptr) {
1916  this->child = new NWidgetVertical();
1917  }
1918  this->child->SetPIP(pip_pre, pip_inter, pip_post);
1919 }
1920 
1921 void NWidgetBackground::AdjustPaddingForZoom()
1922 {
1923  if (child != nullptr) child->AdjustPaddingForZoom();
1924  NWidgetCore::AdjustPaddingForZoom();
1925 }
1926 
1928 {
1929  if (init_array && this->index >= 0) {
1930  assert(w->nested_array_size > (uint)this->index);
1931  w->nested_array[this->index] = this;
1932  }
1933  if (this->child != nullptr) {
1934  this->child->SetupSmallestSize(w, init_array);
1935 
1936  this->smallest_x = this->child->smallest_x;
1937  this->smallest_y = this->child->smallest_y;
1938  this->fill_x = this->child->fill_x;
1939  this->fill_y = this->child->fill_y;
1940  this->resize_x = this->child->resize_x;
1941  this->resize_y = this->child->resize_y;
1942 
1943  /* Don't apply automatic padding if there is no child widget. */
1944  if (w == nullptr) return;
1945 
1946  if (this->type == WWT_FRAME) {
1947  /* Account for the size of the frame's text if that exists */
1950  this->child->padding_top = std::max((int)WD_FRAMETEXT_TOP, this->widget_data != STR_NULL ? FONT_HEIGHT_NORMAL + WD_FRAMETEXT_TOP / 2 : 0);
1952 
1953  this->smallest_x += this->child->padding_left + this->child->padding_right;
1954  this->smallest_y += this->child->padding_top + this->child->padding_bottom;
1955 
1956  if (this->index >= 0) w->SetStringParameters(this->index);
1958  } else if (this->type == WWT_INSET) {
1959  /* Apply automatic padding for bevel thickness. */
1960  this->child->padding_left = WD_BEVEL_LEFT;
1962  this->child->padding_top = WD_BEVEL_TOP;
1964 
1965  this->smallest_x += this->child->padding_left + this->child->padding_right;
1966  this->smallest_y += this->child->padding_top + this->child->padding_bottom;
1967  }
1968  } else {
1969  Dimension d = {this->min_x, this->min_y};
1970  Dimension fill = {this->fill_x, this->fill_y};
1971  Dimension resize = {this->resize_x, this->resize_y};
1972  if (w != nullptr) { // A non-nullptr window pointer acts as switch to turn dynamic widget size on.
1973  if (this->type == WWT_FRAME || this->type == WWT_INSET) {
1974  if (this->index >= 0) w->SetStringParameters(this->index);
1975  Dimension background = GetStringBoundingBox(this->widget_data);
1976  background.width += (this->type == WWT_FRAME) ? (WD_FRAMETEXT_LEFT + WD_FRAMERECT_RIGHT) : (WD_INSET_LEFT + WD_INSET_RIGHT);
1977  d = maxdim(d, background);
1978  }
1979  if (this->index >= 0) {
1980  static const Dimension padding = {0, 0};
1981  w->UpdateWidgetSize(this->index, &d, padding, &fill, &resize);
1982  }
1983  }
1984  this->smallest_x = d.width;
1985  this->smallest_y = d.height;
1986  this->fill_x = fill.width;
1987  this->fill_y = fill.height;
1988  this->resize_x = resize.width;
1989  this->resize_y = resize.height;
1990  }
1991 }
1992 
1993 void NWidgetBackground::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
1994 {
1995  this->StoreSizePosition(sizing, x, y, given_width, given_height);
1996 
1997  if (this->child != nullptr) {
1998  uint x_offset = (rtl ? this->child->padding_right : this->child->padding_left);
1999  uint width = given_width - this->child->padding_right - this->child->padding_left;
2000  uint height = given_height - this->child->padding_top - this->child->padding_bottom;
2001  this->child->AssignSizePosition(sizing, x + x_offset, y + this->child->padding_top, width, height, rtl);
2002  }
2003 }
2004 
2006 {
2007  if (this->index >= 0 && (uint)(this->index) < length) array[this->index] = this;
2008  if (this->child != nullptr) this->child->FillNestedArray(array, length);
2009 }
2010 
2012 {
2013  if (this->current_x == 0 || this->current_y == 0) return;
2014 
2015  Rect r = this->GetCurrentRect();
2016 
2017  const DrawPixelInfo *dpi = _cur_dpi;
2018  if (dpi->left > r.right || dpi->left + dpi->width <= r.left || dpi->top > r.bottom || dpi->top + dpi->height <= r.top) return;
2019 
2020  switch (this->type) {
2021  case WWT_PANEL:
2022  assert(this->widget_data == 0);
2023  DrawFrameRect(r.left, r.top, r.right, r.bottom, this->colour, this->IsLowered() ? FR_LOWERED : FR_NONE);
2024  break;
2025 
2026  case WWT_FRAME:
2027  if (this->index >= 0) w->SetStringParameters(this->index);
2028  DrawFrame(r, this->colour, this->text_colour, this->widget_data, this->align);
2029  break;
2030 
2031  case WWT_INSET:
2032  if (this->index >= 0) w->SetStringParameters(this->index);
2033  DrawInset(r, this->colour, this->text_colour, this->widget_data, this->align);
2034  break;
2035 
2036  default:
2037  NOT_REACHED();
2038  }
2039 
2040  if (this->index >= 0) w->DrawWidget(r, this->index);
2041  if (this->child != nullptr) this->child->Draw(w);
2042 
2043  if (this->IsDisabled()) {
2044  GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, _colour_gradient[this->colour & 0xF][2], FILLRECT_CHECKER);
2045  }
2046 }
2047 
2049 {
2050  NWidgetCore *nwid = nullptr;
2051  if (IsInsideBS(x, this->pos_x, this->current_x) && IsInsideBS(y, this->pos_y, this->current_y)) {
2052  if (this->child != nullptr) nwid = this->child->GetWidgetFromPos(x, y);
2053  if (nwid == nullptr) nwid = this;
2054  }
2055  return nwid;
2056 }
2057 
2059 {
2060  NWidgetBase *nwid = nullptr;
2061  if (this->child != nullptr) nwid = this->child->GetWidgetOfType(tp);
2062  if (nwid == nullptr && this->type == tp) nwid = this;
2063  return nwid;
2064 }
2065 
2066 NWidgetViewport::NWidgetViewport(int index) : NWidgetCore(NWID_VIEWPORT, INVALID_COLOUR, 1, 1, 0x0, STR_NULL)
2067 {
2068  this->SetIndex(index);
2069 }
2070 
2072 {
2073  if (init_array && this->index >= 0) {
2074  assert(w->nested_array_size > (uint)this->index);
2075  w->nested_array[this->index] = this;
2076  }
2077  this->smallest_x = this->min_x;
2078  this->smallest_y = this->min_y;
2079 }
2080 
2082 {
2083  if (this->current_x == 0 || this->current_y == 0) return;
2084 
2085  if (this->disp_flags & ND_NO_TRANSPARENCY) {
2087  _transparency_opt &= (1 << TO_SIGNS) | (1 << TO_LOADING); // Disable all transparency, except textual stuff
2088  w->DrawViewport();
2089  _transparency_opt = to_backup;
2090  } else {
2091  w->DrawViewport();
2092  }
2093 
2094  /* Optionally shade the viewport. */
2095  if (this->disp_flags & (ND_SHADE_GREY | ND_SHADE_DIMMED)) {
2096  GfxFillRect(this->pos_x, this->pos_y, this->pos_x + this->current_x - 1, this->pos_y + this->current_y - 1,
2098  }
2099 }
2100 
2107 void NWidgetViewport::InitializeViewport(Window *w, uint32 follow_flags, ZoomLevel zoom)
2108 {
2109  InitializeWindowViewport(w, this->pos_x, this->pos_y, this->current_x, this->current_y, follow_flags, zoom);
2110 }
2111 
2117 {
2118  Viewport *vp = w->viewport;
2119  if (vp != nullptr) {
2120  vp->left = w->left + this->pos_x;
2121  vp->top = w->top + this->pos_y;
2122  vp->width = this->current_x;
2123  vp->height = this->current_y;
2124 
2125  vp->virtual_width = ScaleByZoom(vp->width, vp->zoom);
2126  vp->virtual_height = ScaleByZoom(vp->height, vp->zoom);
2127  }
2128 }
2129 
2138 int Scrollbar::GetScrolledRowFromWidget(int clickpos, const Window * const w, int widget, int padding) const
2139 {
2140  uint pos = w->GetRowFromWidget(clickpos, widget, padding, -1);
2141  if (pos != INT_MAX) pos += this->GetPosition();
2142  return (pos >= this->GetCount()) ? INT_MAX : pos;
2143 }
2144 
2159 EventState Scrollbar::UpdateListPositionOnKeyPress(int &list_position, uint16 keycode) const
2160 {
2161  int new_pos = list_position;
2162  switch (keycode) {
2163  case WKC_UP:
2164  /* scroll up by one */
2165  new_pos--;
2166  break;
2167 
2168  case WKC_DOWN:
2169  /* scroll down by one */
2170  new_pos++;
2171  break;
2172 
2173  case WKC_PAGEUP:
2174  /* scroll up a page */
2175  new_pos -= this->GetCapacity();
2176  break;
2177 
2178  case WKC_PAGEDOWN:
2179  /* scroll down a page */
2180  new_pos += this->GetCapacity();
2181  break;
2182 
2183  case WKC_HOME:
2184  /* jump to beginning */
2185  new_pos = 0;
2186  break;
2187 
2188  case WKC_END:
2189  /* jump to end */
2190  new_pos = this->GetCount() - 1;
2191  break;
2192 
2193  default:
2194  return ES_NOT_HANDLED;
2195  }
2196 
2197  /* If there are no elements, there is nothing to scroll/update. */
2198  if (this->GetCount() != 0) {
2199  list_position = Clamp(new_pos, 0, this->GetCount() - 1);
2200  }
2201  return ES_HANDLED;
2202 }
2203 
2204 
2212 void Scrollbar::SetCapacityFromWidget(Window *w, int widget, int padding)
2213 {
2214  NWidgetBase *nwid = w->GetWidget<NWidgetBase>(widget);
2215  if (this->IsVertical()) {
2216  this->SetCapacity(((int)nwid->current_y - padding) / (int)nwid->resize_y);
2217  } else {
2218  this->SetCapacity(((int)nwid->current_x - padding) / (int)nwid->resize_x);
2219  }
2220 }
2221 
2228 NWidgetScrollbar::NWidgetScrollbar(WidgetType tp, Colours colour, int index) : NWidgetCore(tp, colour, 1, 1, 0x0, STR_NULL), Scrollbar(tp != NWID_HSCROLLBAR)
2229 {
2230  assert(tp == NWID_HSCROLLBAR || tp == NWID_VSCROLLBAR);
2231  this->SetIndex(index);
2232 
2233  switch (this->type) {
2234  case NWID_HSCROLLBAR:
2235  this->SetResize(1, 0);
2236  this->SetFill(1, 0);
2237  this->SetDataTip(0x0, STR_TOOLTIP_HSCROLL_BAR_SCROLLS_LIST);
2238  break;
2239 
2240  case NWID_VSCROLLBAR:
2241  this->SetResize(0, 1);
2242  this->SetFill(0, 1);
2243  this->SetDataTip(0x0, STR_TOOLTIP_VSCROLL_BAR_SCROLLS_LIST);
2244  break;
2245 
2246  default: NOT_REACHED();
2247  }
2248 }
2249 
2251 {
2252  if (init_array && this->index >= 0) {
2253  assert(w->nested_array_size > (uint)this->index);
2254  w->nested_array[this->index] = this;
2255  }
2256  this->min_x = 0;
2257  this->min_y = 0;
2258 
2259  switch (this->type) {
2260  case NWID_HSCROLLBAR:
2261  this->SetMinimalSizeAbsolute(NWidgetScrollbar::GetHorizontalDimension().width * 3, NWidgetScrollbar::GetHorizontalDimension().height);
2262  break;
2263 
2264  case NWID_VSCROLLBAR:
2265  this->SetMinimalSizeAbsolute(NWidgetScrollbar::GetVerticalDimension().width, NWidgetScrollbar::GetVerticalDimension().height * 3);
2266  break;
2267 
2268  default: NOT_REACHED();
2269  }
2270 
2271  this->smallest_x = this->min_x;
2272  this->smallest_y = this->min_y;
2273 }
2274 
2276 {
2277  if (this->current_x == 0 || this->current_y == 0) return;
2278 
2279  Rect r = this->GetCurrentRect();
2280 
2281  const DrawPixelInfo *dpi = _cur_dpi;
2282  if (dpi->left > r.right || dpi->left + dpi->width <= r.left || dpi->top > r.bottom || dpi->top + dpi->height <= r.top) return;
2283 
2284  bool up_lowered = HasBit(this->disp_flags, NDB_SCROLLBAR_UP);
2285  bool down_lowered = HasBit(this->disp_flags, NDB_SCROLLBAR_DOWN);
2286  bool middle_lowered = !(this->disp_flags & ND_SCROLLBAR_BTN) && w->mouse_capture_widget == this->index;
2287 
2288  if (this->type == NWID_HSCROLLBAR) {
2289  DrawHorizontalScrollbar(r, this->colour, up_lowered, middle_lowered, down_lowered, this);
2290  } else {
2291  DrawVerticalScrollbar(r, this->colour, up_lowered, middle_lowered, down_lowered, this);
2292  }
2293 
2294  if (this->IsDisabled()) {
2295  GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, _colour_gradient[this->colour & 0xF][2], FILLRECT_CHECKER);
2296  }
2297 }
2298 
2299 /* static */ void NWidgetScrollbar::InvalidateDimensionCache()
2300 {
2301  vertical_dimension.width = vertical_dimension.height = 0;
2302  horizontal_dimension.width = horizontal_dimension.height = 0;
2303 }
2304 
2305 /* static */ Dimension NWidgetScrollbar::GetVerticalDimension()
2306 {
2308  if (vertical_dimension.width == 0) {
2309  vertical_dimension = maxdim(GetSpriteSize(SPR_ARROW_UP), GetSpriteSize(SPR_ARROW_DOWN));
2310  vertical_dimension.width += extra.width;
2311  vertical_dimension.height += extra.height;
2312  }
2313  return vertical_dimension;
2314 }
2315 
2316 /* static */ Dimension NWidgetScrollbar::GetHorizontalDimension()
2317 {
2319  if (horizontal_dimension.width == 0) {
2320  horizontal_dimension = maxdim(GetSpriteSize(SPR_ARROW_LEFT), GetSpriteSize(SPR_ARROW_RIGHT));
2321  horizontal_dimension.width += extra.width;
2322  horizontal_dimension.height += extra.height;
2323  }
2324  return horizontal_dimension;
2325 }
2326 
2329 
2332 {
2333  shadebox_dimension.width = shadebox_dimension.height = 0;
2334  debugbox_dimension.width = debugbox_dimension.height = 0;
2335  defsizebox_dimension.width = defsizebox_dimension.height = 0;
2336  stickybox_dimension.width = stickybox_dimension.height = 0;
2337  resizebox_dimension.width = resizebox_dimension.height = 0;
2338  closebox_dimension.width = closebox_dimension.height = 0;
2339  dropdown_dimension.width = dropdown_dimension.height = 0;
2340 }
2341 
2349 
2358 NWidgetLeaf::NWidgetLeaf(WidgetType tp, Colours colour, int index, uint32 data, StringID tip) : NWidgetCore(tp, colour, 1, 1, data, tip)
2359 {
2360  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);
2361  if (index >= 0) this->SetIndex(index);
2362  this->min_x = 0;
2363  this->min_y = 0;
2364  this->SetResize(0, 0);
2365 
2366  switch (tp) {
2367  case WWT_EMPTY:
2368  break;
2369 
2370  case WWT_TEXT:
2371  this->SetFill(0, 0);
2373  break;
2374 
2375  case WWT_PUSHBTN:
2376  case WWT_IMGBTN:
2377  case WWT_PUSHIMGBTN:
2378  case WWT_IMGBTN_2:
2379  case WWT_TEXTBTN:
2380  case WWT_PUSHTXTBTN:
2381  case WWT_TEXTBTN_2:
2382  case WWT_LABEL:
2383  case WWT_MATRIX:
2384  case NWID_BUTTON_DROPDOWN:
2385  case NWID_PUSHBUTTON_DROPDOWN:
2386  case WWT_ARROWBTN:
2387  case WWT_PUSHARROWBTN:
2388  this->SetFill(0, 0);
2389  break;
2390 
2391  case WWT_EDITBOX:
2392  this->SetFill(0, 0);
2393  break;
2394 
2395  case WWT_CAPTION:
2396  this->SetFill(1, 0);
2397  this->SetResize(1, 0);
2400  this->SetDataTip(data, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS);
2401  break;
2402 
2403  case WWT_STICKYBOX:
2404  this->SetFill(0, 0);
2406  this->SetDataTip(STR_NULL, STR_TOOLTIP_STICKY);
2407  break;
2408 
2409  case WWT_SHADEBOX:
2410  this->SetFill(0, 0);
2412  this->SetDataTip(STR_NULL, STR_TOOLTIP_SHADE);
2413  break;
2414 
2415  case WWT_DEBUGBOX:
2416  this->SetFill(0, 0);
2418  this->SetDataTip(STR_NULL, STR_TOOLTIP_DEBUG);
2419  break;
2420 
2421  case WWT_DEFSIZEBOX:
2422  this->SetFill(0, 0);
2424  this->SetDataTip(STR_NULL, STR_TOOLTIP_DEFSIZE);
2425  break;
2426 
2427  case WWT_RESIZEBOX:
2428  this->SetFill(0, 0);
2430  this->SetDataTip(STR_NULL, STR_TOOLTIP_RESIZE);
2431  break;
2432 
2433  case WWT_CLOSEBOX:
2434  this->SetFill(0, 0);
2436  this->SetDataTip(STR_NULL, STR_TOOLTIP_CLOSE_WINDOW);
2437  break;
2438 
2439  case WWT_DROPDOWN:
2440  this->SetFill(0, 0);
2442  this->SetAlignment(SA_TOP | SA_LEFT);
2443  break;
2444 
2445  default:
2446  NOT_REACHED();
2447  }
2448 }
2449 
2450 void NWidgetLeaf::SetupSmallestSize(Window *w, bool init_array)
2451 {
2452  if (this->index >= 0 && init_array) { // Fill w->nested_array[]
2453  assert(w->nested_array_size > (uint)this->index);
2454  w->nested_array[this->index] = this;
2455  }
2456 
2457  Dimension size = {this->min_x, this->min_y};
2458  Dimension fill = {this->fill_x, this->fill_y};
2459  Dimension resize = {this->resize_x, this->resize_y};
2460  /* Get padding, and update size with the real content size if appropriate. */
2461  const Dimension *padding = nullptr;
2462  switch (this->type) {
2463  case WWT_EMPTY: {
2464  static const Dimension extra = {0, 0};
2465  padding = &extra;
2466  break;
2467  }
2468  case WWT_MATRIX: {
2470  padding = &extra;
2471  break;
2472  }
2473  case WWT_SHADEBOX: {
2475  padding = &extra;
2476  if (NWidgetLeaf::shadebox_dimension.width == 0) {
2477  NWidgetLeaf::shadebox_dimension = maxdim(GetSpriteSize(SPR_WINDOW_SHADE), GetSpriteSize(SPR_WINDOW_UNSHADE));
2478  NWidgetLeaf::shadebox_dimension.width += extra.width;
2479  NWidgetLeaf::shadebox_dimension.height += extra.height;
2480  }
2482  break;
2483  }
2484  case WWT_DEBUGBOX:
2487  padding = &extra;
2488  if (NWidgetLeaf::debugbox_dimension.width == 0) {
2489  NWidgetLeaf::debugbox_dimension = GetSpriteSize(SPR_WINDOW_DEBUG);
2490  NWidgetLeaf::debugbox_dimension.width += extra.width;
2491  NWidgetLeaf::debugbox_dimension.height += extra.height;
2492  }
2494  } else {
2495  /* If the setting is disabled we don't want to see it! */
2496  size.width = 0;
2497  fill.width = 0;
2498  resize.width = 0;
2499  }
2500  break;
2501 
2502  case WWT_STICKYBOX: {
2504  padding = &extra;
2505  if (NWidgetLeaf::stickybox_dimension.width == 0) {
2507  NWidgetLeaf::stickybox_dimension.width += extra.width;
2508  NWidgetLeaf::stickybox_dimension.height += extra.height;
2509  }
2511  break;
2512  }
2513 
2514  case WWT_DEFSIZEBOX: {
2516  padding = &extra;
2517  if (NWidgetLeaf::defsizebox_dimension.width == 0) {
2518  NWidgetLeaf::defsizebox_dimension = GetSpriteSize(SPR_WINDOW_DEFSIZE);
2519  NWidgetLeaf::defsizebox_dimension.width += extra.width;
2520  NWidgetLeaf::defsizebox_dimension.height += extra.height;
2521  }
2523  break;
2524  }
2525 
2526  case WWT_RESIZEBOX: {
2528  padding = &extra;
2529  if (NWidgetLeaf::resizebox_dimension.width == 0) {
2530  NWidgetLeaf::resizebox_dimension = maxdim(GetSpriteSize(SPR_WINDOW_RESIZE_LEFT), GetSpriteSize(SPR_WINDOW_RESIZE_RIGHT));
2531  NWidgetLeaf::resizebox_dimension.width += extra.width;
2532  NWidgetLeaf::resizebox_dimension.height += extra.height;
2533  }
2535  break;
2536  }
2537  case WWT_EDITBOX: {
2538  Dimension sprite_size = GetSpriteSize(_current_text_dir == TD_RTL ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT);
2539  size.width = std::max(size.width, 30 + sprite_size.width);
2540  size.height = std::max(sprite_size.height, GetStringBoundingBox("_").height + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM);
2541  }
2542  FALLTHROUGH;
2543  case WWT_PUSHBTN: {
2545  padding = &extra;
2546  break;
2547  }
2548  case WWT_IMGBTN:
2549  case WWT_IMGBTN_2:
2550  case WWT_PUSHIMGBTN: {
2552  padding = &extra;
2553  Dimension d2 = GetSpriteSize(this->widget_data);
2554  if (this->type == WWT_IMGBTN_2) d2 = maxdim(d2, GetSpriteSize(this->widget_data + 1));
2555  d2.width += extra.width;
2556  d2.height += extra.height;
2557  size = maxdim(size, d2);
2558  break;
2559  }
2560  case WWT_ARROWBTN:
2561  case WWT_PUSHARROWBTN: {
2563  padding = &extra;
2564  Dimension d2 = maxdim(GetSpriteSize(SPR_ARROW_LEFT), GetSpriteSize(SPR_ARROW_RIGHT));
2565  d2.width += extra.width;
2566  d2.height += extra.height;
2567  size = maxdim(size, d2);
2568  break;
2569  }
2570 
2571  case WWT_CLOSEBOX: {
2573  padding = &extra;
2574  if (NWidgetLeaf::closebox_dimension.width == 0) {
2576  NWidgetLeaf::closebox_dimension.width += extra.width;
2577  NWidgetLeaf::closebox_dimension.height += extra.height;
2578  }
2580  break;
2581  }
2582  case WWT_TEXTBTN:
2583  case WWT_PUSHTXTBTN:
2584  case WWT_TEXTBTN_2: {
2586  padding = &extra;
2587  if (this->index >= 0) w->SetStringParameters(this->index);
2589  d2.width += extra.width;
2590  d2.height += extra.height;
2591  size = maxdim(size, d2);
2592  break;
2593  }
2594  case WWT_LABEL:
2595  case WWT_TEXT: {
2596  static const Dimension extra = {0, 0};
2597  padding = &extra;
2598  if (this->index >= 0) w->SetStringParameters(this->index);
2599  size = maxdim(size, GetStringBoundingBox(this->widget_data));
2600  break;
2601  }
2602  case WWT_CAPTION: {
2604  padding = &extra;
2605  if (this->index >= 0) w->SetStringParameters(this->index);
2607  d2.width += extra.width;
2608  d2.height += extra.height;
2609  size = maxdim(size, d2);
2610  break;
2611  }
2612  case WWT_DROPDOWN:
2613  case NWID_BUTTON_DROPDOWN:
2614  case NWID_PUSHBUTTON_DROPDOWN: {
2616  padding = &extra;
2617  if (NWidgetLeaf::dropdown_dimension.width == 0) {
2622  }
2623  if (this->index >= 0) w->SetStringParameters(this->index);
2625  d2.width += extra.width;
2626  d2.height = std::max(d2.height, NWidgetLeaf::dropdown_dimension.height) + extra.height;
2627  size = maxdim(size, d2);
2628  break;
2629  }
2630  default:
2631  NOT_REACHED();
2632  }
2633 
2634  if (this->index >= 0) w->UpdateWidgetSize(this->index, &size, *padding, &fill, &resize);
2635 
2636  this->smallest_x = size.width;
2637  this->smallest_y = size.height;
2638  this->fill_x = fill.width;
2639  this->fill_y = fill.height;
2640  this->resize_x = resize.width;
2641  this->resize_y = resize.height;
2642 }
2643 
2645 {
2646  if (this->current_x == 0 || this->current_y == 0) return;
2647 
2648  /* Setup a clipping rectangle... */
2649  DrawPixelInfo new_dpi;
2650  if (!FillDrawPixelInfo(&new_dpi, this->pos_x, this->pos_y, this->current_x, this->current_y)) return;
2651  /* ...but keep coordinates relative to the window. */
2652  new_dpi.left += this->pos_x;
2653  new_dpi.top += this->pos_y;
2654 
2655  DrawPixelInfo *old_dpi = _cur_dpi;
2656  _cur_dpi = &new_dpi;
2657 
2658  Rect r = this->GetCurrentRect();
2659 
2660  bool clicked = this->IsLowered();
2661  switch (this->type) {
2662  case WWT_EMPTY:
2663  break;
2664 
2665  case WWT_PUSHBTN:
2666  assert(this->widget_data == 0);
2667  DrawFrameRect(r.left, r.top, r.right, r.bottom, this->colour, (clicked) ? FR_LOWERED : FR_NONE);
2668  break;
2669 
2670  case WWT_IMGBTN:
2671  case WWT_PUSHIMGBTN:
2672  case WWT_IMGBTN_2:
2673  DrawImageButtons(r, this->type, this->colour, clicked, this->widget_data, this->align);
2674  break;
2675 
2676  case WWT_TEXTBTN:
2677  case WWT_PUSHTXTBTN:
2678  case WWT_TEXTBTN_2:
2679  if (this->index >= 0) w->SetStringParameters(this->index);
2680  DrawFrameRect(r.left, r.top, r.right, r.bottom, this->colour, (clicked) ? FR_LOWERED : FR_NONE);
2681  DrawLabel(r, this->type, clicked, this->text_colour, this->widget_data, this->align);
2682  break;
2683 
2684  case WWT_ARROWBTN:
2685  case WWT_PUSHARROWBTN: {
2686  SpriteID sprite;
2687  switch (this->widget_data) {
2688  case AWV_DECREASE: sprite = _current_text_dir != TD_RTL ? SPR_ARROW_LEFT : SPR_ARROW_RIGHT; break;
2689  case AWV_INCREASE: sprite = _current_text_dir == TD_RTL ? SPR_ARROW_LEFT : SPR_ARROW_RIGHT; break;
2690  case AWV_LEFT: sprite = SPR_ARROW_LEFT; break;
2691  case AWV_RIGHT: sprite = SPR_ARROW_RIGHT; break;
2692  default: NOT_REACHED();
2693  }
2694  DrawImageButtons(r, WWT_PUSHIMGBTN, this->colour, clicked, sprite, this->align);
2695  break;
2696  }
2697 
2698  case WWT_LABEL:
2699  if (this->index >= 0) w->SetStringParameters(this->index);
2700  DrawLabel(r, this->type, clicked, this->text_colour, this->widget_data, this->align);
2701  break;
2702 
2703  case WWT_TEXT:
2704  if (this->index >= 0) w->SetStringParameters(this->index);
2705  DrawText(r, this->text_colour, this->widget_data, this->align);
2706  break;
2707 
2708  case WWT_MATRIX:
2709  DrawMatrix(r, this->colour, clicked, this->widget_data, this->resize_x, this->resize_y);
2710  break;
2711 
2712  case WWT_EDITBOX: {
2713  const QueryString *query = w->GetQueryString(this->index);
2714  if (query != nullptr) query->DrawEditBox(w, this->index);
2715  break;
2716  }
2717 
2718  case WWT_CAPTION:
2719  if (this->index >= 0) w->SetStringParameters(this->index);
2720  DrawCaption(r, this->colour, w->owner, this->text_colour, this->widget_data, this->align);
2721  break;
2722 
2723  case WWT_SHADEBOX:
2724  assert(this->widget_data == 0);
2725  DrawShadeBox(r, this->colour, w->IsShaded());
2726  break;
2727 
2728  case WWT_DEBUGBOX:
2729  DrawDebugBox(r, this->colour, clicked);
2730  break;
2731 
2732  case WWT_STICKYBOX:
2733  assert(this->widget_data == 0);
2734  DrawStickyBox(r, this->colour, !!(w->flags & WF_STICKY));
2735  break;
2736 
2737  case WWT_DEFSIZEBOX:
2738  assert(this->widget_data == 0);
2739  DrawDefSizeBox(r, this->colour, clicked);
2740  break;
2741 
2742  case WWT_RESIZEBOX:
2743  assert(this->widget_data == 0);
2744  DrawResizeBox(r, this->colour, this->pos_x < (w->width / 2), !!(w->flags & WF_SIZING));
2745  break;
2746 
2747  case WWT_CLOSEBOX:
2748  DrawCloseBox(r, this->colour);
2749  break;
2750 
2751  case WWT_DROPDOWN:
2752  if (this->index >= 0) w->SetStringParameters(this->index);
2753  DrawButtonDropdown(r, this->colour, false, clicked, this->widget_data, this->align);
2754  break;
2755 
2756  case NWID_BUTTON_DROPDOWN:
2757  case NWID_PUSHBUTTON_DROPDOWN:
2758  if (this->index >= 0) w->SetStringParameters(this->index);
2759  DrawButtonDropdown(r, this->colour, clicked, (this->disp_flags & ND_DROPDOWN_ACTIVE) != 0, this->widget_data, this->align);
2760  break;
2761 
2762  default:
2763  NOT_REACHED();
2764  }
2765  if (this->index >= 0) w->DrawWidget(r, this->index);
2766 
2767  if (this->IsDisabled()) {
2768  GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, _colour_gradient[this->colour & 0xF][2], FILLRECT_CHECKER);
2769  }
2770 
2771  _cur_dpi = old_dpi;
2772 }
2773 
2782 {
2783  if (_current_text_dir == TD_LTR) {
2784  int button_width = this->pos_x + this->current_x - NWidgetLeaf::dropdown_dimension.width;
2785  return pt.x < button_width;
2786  } else {
2787  int button_left = this->pos_x + NWidgetLeaf::dropdown_dimension.width;
2788  return pt.x >= button_left;
2789  }
2790 }
2791 
2792 /* == Conversion code from NWidgetPart array to NWidgetBase* tree == */
2793 
2809 static int MakeNWidget(const NWidgetPart *parts, int count, NWidgetBase **dest, bool *fill_dest, int *biggest_index)
2810 {
2811  int num_used = 0;
2812 
2813  *dest = nullptr;
2814  *fill_dest = false;
2815 
2816  while (count > num_used) {
2817  switch (parts->type) {
2818  case NWID_SPACER:
2819  if (*dest != nullptr) return num_used;
2820  *dest = new NWidgetSpacer(0, 0);
2821  break;
2822 
2823  case NWID_HORIZONTAL:
2824  if (*dest != nullptr) return num_used;
2825  *dest = new NWidgetHorizontal(parts->u.cont_flags);
2826  *fill_dest = true;
2827  break;
2828 
2829  case NWID_HORIZONTAL_LTR:
2830  if (*dest != nullptr) return num_used;
2831  *dest = new NWidgetHorizontalLTR(parts->u.cont_flags);
2832  *fill_dest = true;
2833  break;
2834 
2835  case WWT_PANEL:
2836  case WWT_INSET:
2837  case WWT_FRAME:
2838  if (*dest != nullptr) return num_used;
2839  *dest = new NWidgetBackground(parts->type, parts->u.widget.colour, parts->u.widget.index);
2840  *biggest_index = std::max(*biggest_index, (int)parts->u.widget.index);
2841  *fill_dest = true;
2842  break;
2843 
2844  case NWID_VERTICAL:
2845  if (*dest != nullptr) return num_used;
2846  *dest = new NWidgetVertical(parts->u.cont_flags);
2847  *fill_dest = true;
2848  break;
2849 
2850  case NWID_MATRIX: {
2851  if (*dest != nullptr) return num_used;
2852  NWidgetMatrix *nwm = new NWidgetMatrix();
2853  *dest = nwm;
2854  *fill_dest = true;
2855  nwm->SetIndex(parts->u.widget.index);
2856  nwm->SetColour(parts->u.widget.colour);
2857  *biggest_index = std::max(*biggest_index, (int)parts->u.widget.index);
2858  break;
2859  }
2860 
2861  case WPT_FUNCTION: {
2862  if (*dest != nullptr) return num_used;
2863  /* Ensure proper functioning even when the called code simply writes its largest index. */
2864  int biggest = -1;
2865  *dest = parts->u.func_ptr(&biggest);
2866  *biggest_index = std::max(*biggest_index, biggest);
2867  *fill_dest = false;
2868  break;
2869  }
2870 
2871  case WPT_RESIZE: {
2872  NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest);
2873  if (nwrb != nullptr) {
2874  assert(parts->u.xy.x >= 0 && parts->u.xy.y >= 0);
2875  nwrb->SetResize(parts->u.xy.x, parts->u.xy.y);
2876  }
2877  break;
2878  }
2879 
2880  case WPT_MINSIZE: {
2881  NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest);
2882  if (nwrb != nullptr) {
2883  assert(parts->u.xy.x >= 0 && parts->u.xy.y >= 0);
2884  nwrb->SetMinimalSize(parts->u.xy.x, parts->u.xy.y);
2885  }
2886  break;
2887  }
2888 
2889  case WPT_MINTEXTLINES: {
2890  NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest);
2891  if (nwrb != nullptr) {
2892  assert(parts->u.text_lines.size >= FS_BEGIN && parts->u.text_lines.size < FS_END);
2893  nwrb->SetMinimalTextLines(parts->u.text_lines.lines, parts->u.text_lines.spacing, parts->u.text_lines.size);
2894  }
2895  break;
2896  }
2897 
2898  case WPT_TEXTCOLOUR: {
2899  NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(*dest);
2900  if (nwc != nullptr) {
2901  nwc->SetTextColour(parts->u.colour.colour);
2902  }
2903  break;
2904  }
2905 
2906  case WPT_ALIGNMENT: {
2907  NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(*dest);
2908  if (nwc != nullptr) {
2909  nwc->SetAlignment(parts->u.align.align);
2910  }
2911  break;
2912  }
2913 
2914  case WPT_FILL: {
2915  NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest);
2916  if (nwrb != nullptr) nwrb->SetFill(parts->u.xy.x, parts->u.xy.y);
2917  break;
2918  }
2919 
2920  case WPT_DATATIP: {
2921  NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(*dest);
2922  if (nwc != nullptr) {
2923  nwc->widget_data = parts->u.data_tip.data;
2924  nwc->tool_tip = parts->u.data_tip.tooltip;
2925  }
2926  break;
2927  }
2928 
2929  case WPT_PADDING:
2930  if (*dest != nullptr) (*dest)->SetPadding(parts->u.padding.top, parts->u.padding.right, parts->u.padding.bottom, parts->u.padding.left);
2931  break;
2932 
2933  case WPT_PIPSPACE: {
2934  NWidgetPIPContainer *nwc = dynamic_cast<NWidgetPIPContainer *>(*dest);
2935  if (nwc != nullptr) nwc->SetPIP(parts->u.pip.pre, parts->u.pip.inter, parts->u.pip.post);
2936 
2937  NWidgetBackground *nwb = dynamic_cast<NWidgetBackground *>(*dest);
2938  if (nwb != nullptr) nwb->SetPIP(parts->u.pip.pre, parts->u.pip.inter, parts->u.pip.post);
2939  break;
2940  }
2941 
2942  case WPT_SCROLLBAR: {
2943  NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(*dest);
2944  if (nwc != nullptr) {
2945  nwc->scrollbar_index = parts->u.widget.index;
2946  }
2947  break;
2948  }
2949 
2950  case WPT_ENDCONTAINER:
2951  return num_used;
2952 
2953  case NWID_VIEWPORT:
2954  if (*dest != nullptr) return num_used;
2955  *dest = new NWidgetViewport(parts->u.widget.index);
2956  *biggest_index = std::max(*biggest_index, (int)parts->u.widget.index);
2957  break;
2958 
2959  case NWID_HSCROLLBAR:
2960  case NWID_VSCROLLBAR:
2961  if (*dest != nullptr) return num_used;
2962  *dest = new NWidgetScrollbar(parts->type, parts->u.widget.colour, parts->u.widget.index);
2963  *biggest_index = std::max(*biggest_index, (int)parts->u.widget.index);
2964  break;
2965 
2966  case NWID_SELECTION: {
2967  if (*dest != nullptr) return num_used;
2968  NWidgetStacked *nws = new NWidgetStacked();
2969  *dest = nws;
2970  *fill_dest = true;
2971  nws->SetIndex(parts->u.widget.index);
2972  *biggest_index = std::max(*biggest_index, (int)parts->u.widget.index);
2973  break;
2974  }
2975 
2976  default:
2977  if (*dest != nullptr) return num_used;
2978  assert((parts->type & WWT_MASK) < WWT_LAST || (parts->type & WWT_MASK) == NWID_BUTTON_DROPDOWN);
2979  *dest = new NWidgetLeaf(parts->type, parts->u.widget.colour, parts->u.widget.index, 0x0, STR_NULL);
2980  *biggest_index = std::max(*biggest_index, (int)parts->u.widget.index);
2981  break;
2982  }
2983  num_used++;
2984  parts++;
2985  }
2986 
2987  return num_used;
2988 }
2989 
2999 static int MakeWidgetTree(const NWidgetPart *parts, int count, NWidgetBase **parent, int *biggest_index)
3000 {
3001  /* If *parent == nullptr, only the first widget is read and returned. Otherwise, *parent must point to either
3002  * a #NWidgetContainer or a #NWidgetBackground object, and parts are added as much as possible. */
3003  NWidgetContainer *nwid_cont = dynamic_cast<NWidgetContainer *>(*parent);
3004  NWidgetBackground *nwid_parent = dynamic_cast<NWidgetBackground *>(*parent);
3005  assert(*parent == nullptr || (nwid_cont != nullptr && nwid_parent == nullptr) || (nwid_cont == nullptr && nwid_parent != nullptr));
3006 
3007  int total_used = 0;
3008  for (;;) {
3009  NWidgetBase *sub_widget = nullptr;
3010  bool fill_sub = false;
3011  int num_used = MakeNWidget(parts, count - total_used, &sub_widget, &fill_sub, biggest_index);
3012  parts += num_used;
3013  total_used += num_used;
3014 
3015  /* Break out of loop when end reached */
3016  if (sub_widget == nullptr) break;
3017 
3018  /* If sub-widget is a container, recursively fill that container. */
3019  WidgetType tp = sub_widget->type;
3020  if (fill_sub && (tp == NWID_HORIZONTAL || tp == NWID_HORIZONTAL_LTR || tp == NWID_VERTICAL || tp == NWID_MATRIX
3021  || tp == WWT_PANEL || tp == WWT_FRAME || tp == WWT_INSET || tp == NWID_SELECTION)) {
3022  NWidgetBase *sub_ptr = sub_widget;
3023  int num_used = MakeWidgetTree(parts, count - total_used, &sub_ptr, biggest_index);
3024  parts += num_used;
3025  total_used += num_used;
3026  }
3027 
3028  /* Add sub_widget to parent container if available, otherwise return the widget to the caller. */
3029  if (nwid_cont != nullptr) nwid_cont->Add(sub_widget);
3030  if (nwid_parent != nullptr) nwid_parent->Add(sub_widget);
3031  if (nwid_cont == nullptr && nwid_parent == nullptr) {
3032  *parent = sub_widget;
3033  return total_used;
3034  }
3035  }
3036 
3037  if (count == total_used) return total_used; // Reached the end of the array of parts?
3038 
3039  assert(total_used < count);
3040  assert(parts->type == WPT_ENDCONTAINER);
3041  return total_used + 1; // *parts is also 'used'
3042 }
3043 
3055 NWidgetContainer *MakeNWidgets(const NWidgetPart *parts, int count, int *biggest_index, NWidgetContainer *container)
3056 {
3057  *biggest_index = -1;
3058  if (container == nullptr) container = new NWidgetVertical();
3059  NWidgetBase *cont_ptr = container;
3060  MakeWidgetTree(parts, count, &cont_ptr, biggest_index);
3061  return container;
3062 }
3063 
3077 NWidgetContainer *MakeWindowNWidgetTree(const NWidgetPart *parts, int count, int *biggest_index, NWidgetStacked **shade_select)
3078 {
3079  *biggest_index = -1;
3080 
3081  /* Read the first widget recursively from the array. */
3082  NWidgetBase *nwid = nullptr;
3083  int num_used = MakeWidgetTree(parts, count, &nwid, biggest_index);
3084  assert(nwid != nullptr);
3085  parts += num_used;
3086  count -= num_used;
3087 
3088  NWidgetContainer *root = new NWidgetVertical;
3089  root->Add(nwid);
3090  if (count == 0) { // There is no body at all.
3091  *shade_select = nullptr;
3092  return root;
3093  }
3094 
3095  /* If the first widget looks like a titlebar, treat it as such.
3096  * If it has a shading box, silently add a shade selection widget in the tree. */
3097  NWidgetHorizontal *hor_cont = dynamic_cast<NWidgetHorizontal *>(nwid);
3098  NWidgetContainer *body;
3099  if (hor_cont != nullptr && hor_cont->GetWidgetOfType(WWT_CAPTION) != nullptr && hor_cont->GetWidgetOfType(WWT_SHADEBOX) != nullptr) {
3100  *shade_select = new NWidgetStacked;
3101  root->Add(*shade_select);
3102  body = new NWidgetVertical;
3103  (*shade_select)->Add(body);
3104  } else {
3105  *shade_select = nullptr;
3106  body = root;
3107  }
3108 
3109  /* Load the remaining parts into 'body'. */
3110  int biggest2 = -1;
3111  MakeNWidgets(parts, count, &biggest2, body);
3112 
3113  *biggest_index = std::max(*biggest_index, biggest2);
3114  return root;
3115 }
3116 
3128 NWidgetBase *MakeCompanyButtonRows(int *biggest_index, int widget_first, int widget_last, Colours button_colour, int max_length, StringID button_tooltip)
3129 {
3130  assert(max_length >= 1);
3131  NWidgetVertical *vert = nullptr; // Storage for all rows.
3132  NWidgetHorizontal *hor = nullptr; // Storage for buttons in one row.
3133  int hor_length = 0;
3134 
3135  Dimension sprite_size = GetSpriteSize(SPR_COMPANY_ICON, nullptr, ZOOM_LVL_OUT_4X);
3136  sprite_size.width += WD_MATRIX_LEFT + WD_MATRIX_RIGHT;
3137  sprite_size.height += WD_MATRIX_TOP + WD_MATRIX_BOTTOM + 1; // 1 for the 'offset' of being pressed
3138 
3139  for (int widnum = widget_first; widnum <= widget_last; widnum++) {
3140  /* Ensure there is room in 'hor' for another button. */
3141  if (hor_length == max_length) {
3142  if (vert == nullptr) vert = new NWidgetVertical();
3143  vert->Add(hor);
3144  hor = nullptr;
3145  hor_length = 0;
3146  }
3147  if (hor == nullptr) {
3148  hor = new NWidgetHorizontal();
3149  hor_length = 0;
3150  }
3151 
3152  NWidgetBackground *panel = new NWidgetBackground(WWT_PANEL, button_colour, widnum);
3153  panel->SetMinimalSize(sprite_size.width, sprite_size.height);
3154  panel->SetFill(1, 1);
3155  panel->SetResize(1, 0);
3156  panel->SetDataTip(0x0, button_tooltip);
3157  hor->Add(panel);
3158  hor_length++;
3159  }
3160  *biggest_index = widget_last;
3161  if (vert == nullptr) return hor; // All buttons fit in a single row.
3162 
3163  if (hor_length > 0 && hor_length < max_length) {
3164  /* Last row is partial, add a spacer at the end to force all buttons to the left. */
3165  NWidgetSpacer *spc = new NWidgetSpacer(sprite_size.width, sprite_size.height);
3166  spc->SetFill(1, 1);
3167  spc->SetResize(1, 0);
3168  hor->Add(spc);
3169  }
3170  if (hor != nullptr) vert->Add(hor);
3171  return vert;
3172 }
ES_HANDLED
@ ES_HANDLED
The passed event is handled.
Definition: window_type.h:718
NWidgetBackground::SetupSmallestSize
void SetupSmallestSize(Window *w, bool init_array) override
Definition: widget.cpp:1927
MakeCompanyButtonRows
NWidgetBase * MakeCompanyButtonRows(int *biggest_index, int widget_first, int widget_last, Colours button_colour, int max_length, StringID button_tooltip)
Make a number of rows with button-like graphics, for enabling/disabling each company.
Definition: widget.cpp:3128
NWidgetSpacer::NWidgetSpacer
NWidgetSpacer(int width, int height)
Generic spacer widget.
Definition: widget.cpp:1601
NWidgetResizeBase
Base class for a resizable nested widget.
Definition: widget_type.h:252
NWidgetPartTextLines::lines
uint8 lines
Number of text lines.
Definition: widget_type.h:940
NWidgetMatrix::clicked
int clicked
The currently clicked widget.
Definition: widget_type.h:553
ScrollbarClickHandler
void ScrollbarClickHandler(Window *w, NWidgetCore *nw, int x, int y)
Special handling for the scrollbar widget type.
Definition: widget.cpp:170
NWidgetScrollbar::SetupSmallestSize
void SetupSmallestSize(Window *w, bool init_array) override
Definition: widget.cpp:2250
NWidgetStacked::AssignSizePosition
void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override
Definition: widget.cpp:1136
NWidgetMatrix::widgets_y
int widgets_y
The number of visible widgets in vertical direction.
Definition: widget_type.h:560
WD_FRAMERECT_TOP
@ WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
Definition: window_gui.h:64
WD_DEFSIZEBOX_LEFT
@ WD_DEFSIZEBOX_LEFT
Left offset of defsize sprite.
Definition: window_gui.h:106
NWidgetStacked::NWidgetStacked
NWidgetStacked()
Widgets stacked on top of each other.
Definition: widget.cpp:1074
NWidgetResizeBase::uz_min_x
uint uz_min_x
Unscaled Minimal horizontal size of only this widget.
Definition: widget_type.h:269
NWidgetPart::colour
NWidgetPartTextColour colour
Part with text colour data.
Definition: widget_type.h:982
NWidgetCore::IsDisabled
bool IsDisabled() const
Return whether the widget is disabled.
Definition: widget_type.h:390
WWT_IMGBTN_2
@ WWT_IMGBTN_2
(Toggle) Button with diff image when clicked
Definition: widget_type.h:51
WD_RESIZEBOX_BOTTOM
@ WD_RESIZEBOX_BOTTOM
Bottom offset of resize sprite.
Definition: window_gui.h:116
WPT_DATATIP
@ WPT_DATATIP
Widget part for specifying data and tooltip.
Definition: widget_type.h:89
ComputeMaxSize
static uint ComputeMaxSize(uint base, uint max_space, uint step)
Return the biggest possible size of a nested widget.
Definition: widget_type.h:845
DrawText
static void DrawText(const Rect &r, TextColour colour, StringID str, StringAlignment align)
Draw text.
Definition: widget.cpp:287
SA_HOR_MASK
@ SA_HOR_MASK
Mask for horizontal alignment.
Definition: gfx_type.h:331
NWidgetPart::pip
NWidgetPartPIP pip
Part with pre/inter/post spaces.
Definition: widget_type.h:980
WD_MATRIX_RIGHT
@ WD_MATRIX_RIGHT
Offset at right of a matrix cell.
Definition: window_gui.h:79
AddDirtyBlock
void AddDirtyBlock(int left, int top, int right, int bottom)
Extend the internal _invalid_rect rectangle to contain the rectangle defined by the given parameters.
Definition: gfx.cpp:1710
WF_SIZING
@ WF_SIZING
Window is being resized.
Definition: window_gui.h:239
NWidgetSpacer::GetWidgetFromPos
NWidgetCore * GetWidgetFromPos(int x, int y) override
Definition: widget.cpp:1627
querystring_gui.h
NWidgetPartPIP::post
uint8 post
Amount of space before/between/after child widgets.
Definition: widget_type.h:932
SortButtonState
SortButtonState
State of a sort direction button.
Definition: window_gui.h:224
NWidgetCore::NWidgetCore
NWidgetCore(WidgetType tp, Colours colour, uint fill_x, uint fill_y, uint32 widget_data, StringID tool_tip)
Initialization of a 'real' widget.
Definition: widget.cpp:936
DrawLabel
static void DrawLabel(const Rect &r, WidgetType type, bool clicked, TextColour colour, StringID str, StringAlignment align)
Draw the label-part of a widget.
Definition: widget.cpp:271
WD_STICKYBOX_WIDTH
@ WD_STICKYBOX_WIDTH
Width of a standard sticky box widget.
Definition: window_gui.h:91
GUISettings::newgrf_developer_tools
bool newgrf_developer_tools
activate NewGRF developer tools and allow modifying NewGRFs in an existing game
Definition: settings_type.h:189
ScrollbarClickPositioning
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:106
PALETTE_TEXT_RECOLOUR
@ PALETTE_TEXT_RECOLOUR
Set if palette is actually a magic text recolour.
Definition: sprites.h:1518
GB
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
NWidgetPIPContainer::pip_inter
uint8 pip_inter
Amount of space between widgets.
Definition: widget_type.h:483
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:27
NWidgetPart::align
NWidgetPartAlignment align
Part with internal alignment.
Definition: widget_type.h:983
Scrollbar::GetCapacity
uint16 GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:664
NWidgetStacked::index
int index
If non-negative, index in the Window::nested_array.
Definition: widget_type.h:455
Window::DrawSortButtonState
void DrawSortButtonState(int widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
Definition: widget.cpp:670
Window::nested_root
NWidgetBase * nested_root
Root of the nested tree.
Definition: window_gui.h:324
NWidgetLeaf::resizebox_dimension
static Dimension resizebox_dimension
Cached size of a resizebox widget.
Definition: widget_type.h:829
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:64
WD_SHADEBOX_BOTTOM
@ WD_SHADEBOX_BOTTOM
Bottom offset of shade sprite.
Definition: window_gui.h:88
DrawCloseBox
static void DrawCloseBox(const Rect &r, Colours colour)
Draw a close box.
Definition: widget.cpp:566
_transparency_opt
TransparencyOptionBits _transparency_opt
The bits that should be transparent.
Definition: transparency_gui.cpp:23
SZSP_BEGIN
@ SZSP_BEGIN
First zero-size plane.
Definition: widget_type.h:425
NWidgetPIPContainer::SetPIP
void SetPIP(uint8 pip_pre, uint8 pip_inter, uint8 pip_post)
Set additional pre/inter/post space for the container.
Definition: widget.cpp:1222
Window::DrawWidget
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
Definition: window_gui.h:565
NWidgetContainer::Add
void Add(NWidgetBase *wid)
Append widget wid to container.
Definition: widget.cpp:1047
NWID_HSCROLLBAR
@ NWID_HSCROLLBAR
Horizontal scrollbar.
Definition: widget_type.h:81
FS_BEGIN
@ FS_BEGIN
First font.
Definition: gfx_type.h:213
WD_MATRIX_TOP
@ WD_MATRIX_TOP
Offset at top of a matrix cell.
Definition: window_gui.h:80
TD_LTR
@ TD_LTR
Text is written left-to-right by default.
Definition: strings_type.h:23
NWidgetViewport
Nested widget to display a viewport in a window.
Definition: widget_type.h:617
TO_LOADING
@ TO_LOADING
loading indicators
Definition: transparency.h:31
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
Scrollbar::ScrollTowards
void ScrollTowards(int position)
Scroll towards the given position; if the item is visible nothing happens, otherwise it will be shown...
Definition: widget_type.h:777
Scrollbar::pos
uint16 pos
Index of first visible item of the list.
Definition: widget_type.h:636
Viewport::width
int width
Screen width of the viewport.
Definition: viewport_type.h:25
DrawStickyBox
static void DrawStickyBox(const Rect &r, Colours colour, bool clicked)
Draw a sticky box.
Definition: widget.cpp:513
NWidgetMatrix
Matrix container with implicitly equal sized (virtual) sub-widgets.
Definition: widget_type.h:534
WWT_IMGBTN
@ WWT_IMGBTN
(Toggle) Button with image
Definition: widget_type.h:50
Window::viewport
ViewportData * viewport
Pointer to viewport data, if present.
Definition: window_gui.h:321
NWidgetPIPContainer::uz_pip_post
uint8 uz_pip_post
Unscaled space after last widget.
Definition: widget_type.h:488
ND_SHADE_DIMMED
@ ND_SHADE_DIMMED
Bit value of the 'dimmed colours' flag.
Definition: widget_type.h:299
WD_STICKYBOX_TOP
@ WD_STICKYBOX_TOP
Top offset of sticky sprite.
Definition: window_gui.h:94
WWT_LABEL
@ WWT_LABEL
Centered label.
Definition: widget_type.h:55
Viewport::height
int height
Screen height of the viewport.
Definition: viewport_type.h:26
NWidgetCore::SetIndex
void SetIndex(int index)
Set index of the nested widget in the widget array.
Definition: widget.cpp:951
FILLRECT_RECOLOUR
@ FILLRECT_RECOLOUR
Apply a recolour sprite to the screen content.
Definition: gfx_type.h:289
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:63
NWidgetResizeBase::SetMinimalTextLines
void SetMinimalTextLines(uint8 min_lines, uint8 spacing, FontSize size)
Set minimal text lines for the widget.
Definition: widget.cpp:892
FrameFlags
FrameFlags
Flags to describe the look of the frame.
Definition: window_gui.h:27
NWidgetStacked::Draw
void Draw(const Window *w) override
Definition: widget.cpp:1162
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
NWidgetMatrix::Draw
void Draw(const Window *w) override
Definition: widget.cpp:1789
NWidgetLeaf::stickybox_dimension
static Dimension stickybox_dimension
Cached size of a stickybox widget.
Definition: widget_type.h:835
NDB_SCROLLBAR_DOWN
@ NDB_SCROLLBAR_DOWN
Down-button is lowered bit.
Definition: widget_type.h:290
WD_CLOSEBOX_RIGHT
@ WD_CLOSEBOX_RIGHT
Right offset of closebox string.
Definition: window_gui.h:121
Viewport::top
int top
Screen coordinate top edge of the viewport.
Definition: viewport_type.h:24
DrawButtonDropdown
static void DrawButtonDropdown(const Rect &r, Colours colour, bool clicked_button, bool clicked_dropdown, StringID str, StringAlignment align)
Draw a button with a dropdown (WWT_DROPDOWN and NWID_BUTTON_DROPDOWN).
Definition: widget.cpp:612
Window::IsNewGRFInspectable
virtual bool IsNewGRFInspectable() const
Is the data related to this window NewGRF inspectable?
Definition: window_gui.h:799
WF_STICKY
@ WF_STICKY
Window is made sticky by user.
Definition: window_gui.h:240
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:22
WWT_MATRIX
@ WWT_MATRIX
Grid of rows and columns.
Definition: widget_type.h:57
NWID_HORIZONTAL_LTR
@ NWID_HORIZONTAL_LTR
Horizontal container that doesn't change the order of the widgets for RTL languages.
Definition: widget_type.h:74
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
NWidgetSpacer
Spacer widget.
Definition: widget_type.h:570
UnScaleGUI
static int UnScaleGUI(int value)
Short-hand to apply GUI zoom level.
Definition: zoom_func.h:77
PALETTE_TO_TRANSPARENT
static const PaletteID PALETTE_TO_TRANSPARENT
This sets the sprite to transparent.
Definition: sprites.h:1593
WWT_ARROWBTN
@ WWT_ARROWBTN
(Toggle) Button with an arrow
Definition: widget_type.h:52
NWidgetBase::NWidgetBase
NWidgetBase(WidgetType tp)
Base class constructor.
Definition: widget.cpp:753
NWidgetResizeBase::uz_min_y
uint uz_min_y
Unscaled Minimal vertical size of only this widget.
Definition: widget_type.h:270
Scrollbar::SetCount
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:712
FILLRECT_CHECKER
@ FILLRECT_CHECKER
Draw only every second pixel, used for greying-out.
Definition: gfx_type.h:288
MAT_ROW_START
@ MAT_ROW_START
Lowest bit of the number of rows.
Definition: widget_type.h:29
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:250
zoom_func.h
NWidgetLeaf
Leaf widget.
Definition: widget_type.h:817
WD_FRAMETEXT_TOP
@ WD_FRAMETEXT_TOP
Top offset of the text of the frame.
Definition: window_gui.h:74
WD_SCROLLBAR_RIGHT
@ WD_SCROLLBAR_RIGHT
Right offset of scrollbar.
Definition: window_gui.h:51
ZoomLevel
ZoomLevel
All zoom levels we know.
Definition: zoom_type.h:21
SA_BOTTOM
@ SA_BOTTOM
Bottom align the text.
Definition: gfx_type.h:335
NWidgetMatrix::SetScrollbar
void SetScrollbar(Scrollbar *sb)
Assign a scrollbar to this matrix.
Definition: widget.cpp:1691
StringAlignment
StringAlignment
How to align the to-be drawn text.
Definition: gfx_type.h:327
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:53
WD_DEFSIZEBOX_BOTTOM
@ WD_DEFSIZEBOX_BOTTOM
Bottom offset of defsize sprite.
Definition: window_gui.h:109
NWidgetMatrix::count
int count
Amount of valid widgets.
Definition: widget_type.h:554
DrawString
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:645
NWidgetPart::xy
Point xy
Part with an x/y size.
Definition: widget_type.h:976
NWidgetSpacer::FillNestedArray
void FillNestedArray(NWidgetBase **array, uint length) override
Definition: widget.cpp:1613
SZSP_HORIZONTAL
@ SZSP_HORIZONTAL
Display plane with zero size vertically, and filling and resizing horizontally.
Definition: widget_type.h:422
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget array.
Definition: widget_type.h:46
Window::owner
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Definition: window_gui.h:319
WWT_PUSHARROWBTN
@ WWT_PUSHARROWBTN
Normal push-button (no toggle button) with arrow caption.
Definition: widget_type.h:106
FR_LOWERED
@ FR_LOWERED
If set the frame is lowered and the background colour brighter (ie. buttons when pressed)
Definition: window_gui.h:31
NWidgetCore::tool_tip
StringID tool_tip
Tooltip of the widget.
Definition: widget_type.h:336
NWidgetContainer::GetWidgetOfType
NWidgetBase * GetWidgetOfType(WidgetType tp) override
Retrieve a widget by its type.
Definition: widget.cpp:1025
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition: gfx_type.h:330
SA_VERT_CENTER
@ SA_VERT_CENTER
Vertically center the text.
Definition: gfx_type.h:334
NWidgetCore::SetLowered
void SetLowered(bool lowered)
Lower or raise the widget.
Definition: widget_type.h:369
WD_DEBUGBOX_LEFT
@ WD_DEBUGBOX_LEFT
Left offset of debug sprite.
Definition: window_gui.h:99
Scrollbar::GetScrolledRowFromWidget
int GetScrolledRowFromWidget(int clickpos, const Window *const w, int widget, int padding=0) const
Compute the row of a scrolled widget that a user clicked in.
Definition: widget.cpp:2138
NWidgetLeaf::shadebox_dimension
static Dimension shadebox_dimension
Cached size of a shadebox widget.
Definition: widget_type.h:832
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
NWID_MATRIX
@ NWID_MATRIX
Matrix container.
Definition: widget_type.h:76
NWidgetBase::smallest_y
uint smallest_y
Smallest vertical size of the widget in a filled window.
Definition: widget_type.h:184
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:631
MakeNWidgets
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:3055
NWidgetBase::padding_top
uint8 padding_top
Paddings added to the top of the widget. Managed by parent container widget.
Definition: widget_type.h:195
NWidgetMatrix::SetupSmallestSize
void SetupSmallestSize(Window *w, bool init_array) override
Definition: widget.cpp:1696
WD_FRAMETEXT_LEFT
@ WD_FRAMETEXT_LEFT
Left offset of the text of the frame.
Definition: window_gui.h:72
FR_TRANSPARENT
@ FR_TRANSPARENT
Makes the background transparent if set.
Definition: window_gui.h:29
_colour_gradient
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: gfx.cpp:55
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:973
NWidgetVertical::SetupSmallestSize
void SetupSmallestSize(Window *w, bool init_array) override
Definition: widget.cpp:1441
DrawDefSizeBox
static void DrawDefSizeBox(const Rect &r, Colours colour, bool clicked)
Draw a defsize box.
Definition: widget.cpp:524
NWidgetPIPContainer::uz_pip_inter
uint8 uz_pip_inter
Unscaled space between widgets.
Definition: widget_type.h:487
NWidgetMatrix::sb
Scrollbar * sb
The scrollbar we're associated with.
Definition: widget_type.h:555
QueryString
Data stored about a string that can be modified in the GUI.
Definition: querystring_gui.h:20
MAT_COL_START
@ MAT_COL_START
Lowest bit of the number of columns.
Definition: widget_type.h:25
NWidgetCore::widget_data
uint32 widget_data
Data of the widget.
Definition: widget_type.h:335
WD_IMGBTN_BOTTOM
@ WD_IMGBTN_BOTTOM
Bottom offset of image in the button.
Definition: window_gui.h:43
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:891
WD_INSET_TOP
@ WD_INSET_TOP
Top offset of string.
Definition: window_gui.h:48
SpriteID
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
NWidgetBase::Draw
virtual void Draw(const Window *w)=0
NWidgetMatrix::SetCount
void SetCount(int count)
Set the number of elements in this matrix.
Definition: widget.cpp:1667
NWidgetBase::prev
NWidgetBase * prev
Pointer to previous widget in container. Managed by parent container widget.
Definition: widget_type.h:193
Window::SetStringParameters
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
Definition: window_gui.h:587
window_gui.h
NWidgetStacked::FillNestedArray
void FillNestedArray(NWidgetBase **array, uint length) override
Definition: widget.cpp:1156
NWidgetLeaf::InvalidateDimensionCache
static void InvalidateDimensionCache()
Reset the cached dimensions.
Definition: widget.cpp:2331
NWidgetResizeBase::NWidgetResizeBase
NWidgetResizeBase(WidgetType tp, uint fill_x, uint fill_y)
Constructor for resizable nested widgets.
Definition: widget.cpp:846
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:464
Window::GetWidget
const NWID * GetWidget(uint widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition: window_gui.h:908
ND_DROPDOWN_ACTIVE
@ ND_DROPDOWN_ACTIVE
Bit value of the 'dropdown active' flag.
Definition: widget_type.h:300
Scrollbar::UpdatePosition
bool UpdatePosition(int difference, ScrollbarStepping unit=SS_SMALL)
Updates the position of the first visible element by the given amount.
Definition: widget_type.h:760
_company_colours
Colours _company_colours[MAX_COMPANIES]
NOSAVE: can be determined from company structs.
Definition: company_cmd.cpp:48
AWV_LEFT
@ AWV_LEFT
Force the arrow to the left.
Definition: widget_type.h:37
NWidgetResizeBase::AssignSizePosition
void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override
Definition: widget.cpp:922
Viewport
Data structure for viewport, display of a part of the world.
Definition: viewport_type.h:22
WPT_FILL
@ WPT_FILL
Widget part for specifying fill.
Definition: widget_type.h:88
NWidgetBase::padding_left
uint8 padding_left
Paddings added to the left of the widget. Managed by parent container widget. (parent container may s...
Definition: widget_type.h:198
NWidgetLeaf::NWidgetLeaf
NWidgetLeaf(WidgetType tp, Colours colour, int index, uint32 data, StringID tip)
Nested leaf widget.
Definition: widget.cpp:2358
NWidgetBackground::AssignSizePosition
void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override
Definition: widget.cpp:1993
WD_RESIZEBOX_RIGHT
@ WD_RESIZEBOX_RIGHT
Right offset of resize sprite.
Definition: window_gui.h:114
WWT_PUSHBTN
@ WWT_PUSHBTN
Normal push-button (no toggle button) with custom drawing.
Definition: widget_type.h:103
DrawVerticalScrollbar
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:377
NWidgetLeaf::dropdown_dimension
static Dimension dropdown_dimension
Cached size of a dropdown widget.
Definition: widget_type.h:828
ST_SMALLEST
@ ST_SMALLEST
Initialize nested widget tree to smallest size. Also updates current_x and current_y.
Definition: widget_type.h:112
NWidgetBase::uz_padding_bottom
uint8 uz_padding_bottom
Unscaled bottom padding, for resize calculation.
Definition: widget_type.h:202
DrawShadeBox
static void DrawShadeBox(const Rect &r, Colours colour, bool clicked)
Draw a shade box.
Definition: widget.cpp:502
NWidgetViewport::UpdateViewportCoordinates
void UpdateViewportCoordinates(Window *w)
Update the position and size of the viewport (after eg a resize).
Definition: widget.cpp:2116
WD_SHADEBOX_RIGHT
@ WD_SHADEBOX_RIGHT
Right offset of shade sprite.
Definition: window_gui.h:86
Scrollbar::GetCount
uint16 GetCount() const
Gets the number of elements in the list.
Definition: widget_type.h:655
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:207
NWidgetContainer::tail
NWidgetBase * tail
Pointer to last widget in container.
Definition: widget_type.h:416
SA_TOP
@ SA_TOP
Top align the text.
Definition: gfx_type.h:333
NWidgetPIPContainer::Draw
void Draw(const Window *w) override
Definition: widget.cpp:1233
NWID_VIEWPORT
@ NWID_VIEWPORT
Nested widget containing a viewport.
Definition: widget_type.h:79
WD_CLOSEBOX_TOP
@ WD_CLOSEBOX_TOP
Top offset of closebox string.
Definition: window_gui.h:122
NWidgetViewport::SetupSmallestSize
void SetupSmallestSize(Window *w, bool init_array) override
Definition: widget.cpp:2071
WWT_EDITBOX
@ WWT_EDITBOX
a textbox for typing
Definition: widget_type.h:69
NWidgetBase::type
WidgetType type
Type of the widget / nested widget.
Definition: widget_type.h:175
NWidgetPIPContainer::GetWidgetFromPos
NWidgetCore * GetWidgetFromPos(int x, int y) override
Definition: widget.cpp:1240
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:315
WF_WHITE_BORDER
@ WF_WHITE_BORDER
Window white border counter bit mask.
Definition: window_gui.h:242
WD_INSET_RIGHT
@ WD_INSET_RIGHT
Right offset of string.
Definition: window_gui.h:47
NWidgetResizeBase::SetResize
void SetResize(uint resize_x, uint resize_y)
Set resize step of the widget.
Definition: widget.cpp:916
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:993
Viewport::left
int left
Screen coordinate left edge of the viewport.
Definition: viewport_type.h:23
NWidgetBase::smallest_x
uint smallest_x
Smallest horizontal size of the widget in a filled window.
Definition: widget_type.h:183
WD_FRAMERECT_LEFT
@ WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:62
NWidgetBase::AssignSizePosition
virtual void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)=0
SB
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.
Definition: bitmath_func.hpp:58
NWidgetLeaf::debugbox_dimension
static Dimension debugbox_dimension
Cached size of a debugbox widget.
Definition: widget_type.h:833
IsInsideBS
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:188
NWidgetBase::GetWidgetOfType
virtual NWidgetBase * GetWidgetOfType(WidgetType tp)
Retrieve a widget by its type.
Definition: widget.cpp:827
WPT_PIPSPACE
@ WPT_PIPSPACE
Widget part for specifying pre/inter/post space for containers.
Definition: widget_type.h:91
WD_FRAMERECT_RIGHT
@ WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:63
ZeroedMemoryAllocator
Base class that provides memory initialization on dynamically created objects.
Definition: alloc_type.hpp:85
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition: window_type.h:719
WD_FRAMERECT_BOTTOM
@ WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
Definition: window_gui.h:65
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:104
WD_DEFSIZEBOX_RIGHT
@ WD_DEFSIZEBOX_RIGHT
Right offset of defsize sprite.
Definition: window_gui.h:107
NWidgetCore::SetToolTip
void SetToolTip(StringID tool_tip)
Set the tool tip of the nested widget.
Definition: widget.cpp:981
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:126
NWidgetBackground::GetWidgetOfType
NWidgetBase * GetWidgetOfType(WidgetType tp) override
Retrieve a widget by its type.
Definition: widget.cpp:2058
WD_FRAMETEXT_BOTTOM
@ WD_FRAMETEXT_BOTTOM
Bottom offset of the text of the frame.
Definition: window_gui.h:75
Scrollbar::IsVertical
bool IsVertical() const
Is the scrollbar vertical or not?
Definition: widget_type.h:692
NWidgetMatrix::GetWidgetFromPos
NWidgetCore * GetWidgetFromPos(int x, int y) override
Definition: widget.cpp:1757
PALETTE_NEWSPAPER
static const PaletteID PALETTE_NEWSPAPER
Recolour sprite for newspaper-greying.
Definition: sprites.h:1595
GetWidgetFromPos
int GetWidgetFromPos(const Window *w, int x, int y)
Returns the index for the widget located at the given position relative to the window.
Definition: widget.cpp:194
DrawDebugBox
static void DrawDebugBox(const Rect &r, Colours colour, bool clicked)
Draw a NewGRF debug box.
Definition: widget.cpp:535
Scrollbar::UpdateListPositionOnKeyPress
EventState UpdateListPositionOnKeyPress(int &list_position, uint16 keycode) const
Update the given list position as if it were on this scroll bar when the given keycode was pressed.
Definition: widget.cpp:2159
_string_colourmap
static const byte _string_colourmap[17]
Colour mapping for TextColour.
Definition: string_colours.h:11
Window::GetQueryString
const QueryString * GetQueryString(uint widnum) const
Return the querystring associated to a editbox.
Definition: window.cpp:340
SA_FORCE
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
Definition: gfx_type.h:340
NWidgetPart::widget
NWidgetPartWidget widget
Part with a start of a widget.
Definition: widget_type.h:978
NWidgetPartWidget::index
int16 index
Widget index in the widget array.
Definition: widget_type.h:916
WPT_SCROLLBAR
@ WPT_SCROLLBAR
Widget part for attaching a scrollbar.
Definition: widget_type.h:96
MAT_COL_BITS
@ MAT_COL_BITS
Number of bits for the number of columns in the matrix.
Definition: widget_type.h:26
MAX_COMPANIES
@ MAX_COMPANIES
Maximum number of companies.
Definition: company_type.h:23
NWidgetPIPContainer::pip_pre
uint8 pip_pre
Amount of space before first widget.
Definition: widget_type.h:482
TransparencyOptionBits
uint TransparencyOptionBits
transparency option bits
Definition: transparency.h:36
WD_STICKYBOX_RIGHT
@ WD_STICKYBOX_RIGHT
Right offset of sticky sprite.
Definition: window_gui.h:93
NWidgetResizeBase::uz_text_size
FontSize uz_text_size
'Unscaled' font size, stored for resize calculation.
Definition: widget_type.h:274
NWidgetBackground::SetPIP
void SetPIP(uint8 pip_pre, uint8 pip_inter, uint8 pip_post)
Set additional pre/inter/post space for the background widget.
Definition: widget.cpp:1913
safeguards.h
NWidgetCore::SetAlignment
void SetAlignment(StringAlignment align)
Set the text/image alignment of the nested widget.
Definition: widget.cpp:990
DrawMatrix
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:317
NWidgetCore::SetTextColour
void SetTextColour(TextColour colour)
Set the text colour of the nested widget.
Definition: widget.cpp:972
Window::left
int left
x position of left edge of the window
Definition: window_gui.h:312
NWidgetLeaf::defsizebox_dimension
static Dimension defsizebox_dimension
Cached size of a defsizebox widget.
Definition: widget_type.h:834
Window::flags
WindowFlags flags
Window flags.
Definition: window_gui.h:305
WD_INSET_LEFT
@ WD_INSET_LEFT
Left offset of string.
Definition: window_gui.h:46
WWT_LAST
@ WWT_LAST
Last Item. use WIDGETS_END to fill up padding!!
Definition: widget_type.h:70
WPT_ALIGNMENT
@ WPT_ALIGNMENT
Widget part for specifying text/image alignment.
Definition: widget_type.h:93
NWidgetContainer::NWidgetContainer
NWidgetContainer(WidgetType tp)
Constructor container baseclass.
Definition: widget.cpp:1009
WD_DEBUGBOX_RIGHT
@ WD_DEBUGBOX_RIGHT
Right offset of debug sprite.
Definition: window_gui.h:100
NWidgetPart::func_ptr
NWidgetFunctionType * func_ptr
Part with a function call.
Definition: widget_type.h:984
NDB_SCROLLBAR_UP
@ NDB_SCROLLBAR_UP
Up-button is lowered bit.
Definition: widget_type.h:289
DrawSprite
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Definition: gfx.cpp:1044
NWidgetPart::padding
NWidgetPartPaddings padding
Part with paddings.
Definition: widget_type.h:979
settings_type.h
sprites.h
Viewport::virtual_width
int virtual_width
width << zoom
Definition: viewport_type.h:30
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
WF_HIGHLIGHTED
@ WF_HIGHLIGHTED
Window has a widget that has a highlight.
Definition: window_gui.h:243
WPT_MINSIZE
@ WPT_MINSIZE
Widget part for specifying minimal size.
Definition: widget_type.h:86
NWidgetCore::IsLowered
bool IsLowered() const
Return whether the widget is lowered.
Definition: widget_type.h:375
NWidgetHorizontal::SetupSmallestSize
void SetupSmallestSize(Window *w, bool init_array) override
Definition: widget.cpp:1256
DrawHorizontalScrollbar
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:415
NWidgetPartTextLines::spacing
uint8 spacing
Extra spacing around lines.
Definition: widget_type.h:941
WWT_FRAME
@ WWT_FRAME
Frame.
Definition: widget_type.h:58
NWidgetStacked::GetWidgetFromPos
NWidgetCore * GetWidgetFromPos(int x, int y) override
Definition: widget.cpp:1177
NWidgetContainer::head
NWidgetBase * head
Pointer to first widget in container.
Definition: widget_type.h:415
NWidgetMatrix::index
int index
If non-negative, index in the Window::nested_array.
Definition: widget_type.h:551
WD_FRAMETEXT_RIGHT
@ WD_FRAMETEXT_RIGHT
Right offset of the text of the frame.
Definition: window_gui.h:73
stdafx.h
GfxFillRect
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition: gfx.cpp:119
WD_DROPDOWNTEXT_RIGHT
@ WD_DROPDOWNTEXT_RIGHT
Right offset of the dropdown widget string.
Definition: window_gui.h:135
WD_SCROLLBAR_LEFT
@ WD_SCROLLBAR_LEFT
Left offset of scrollbar.
Definition: window_gui.h:50
NWidgetHorizontal::AssignSizePosition
void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override
Definition: widget.cpp:1323
NWidgetStacked::SetDisplayedPlane
void SetDisplayedPlane(int plane)
Select which plane to show (for NWID_SELECTION only).
Definition: widget.cpp:1195
NWidgetPIPContainer::uz_pip_pre
uint8 uz_pip_pre
Unscaled space before first widget.
Definition: widget_type.h:486
viewport_func.h
Window::mouse_capture_widget
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:330
NWidgetBase::current_y
uint current_y
Current vertical size (after resizing).
Definition: widget_type.h:187
NWidgetStacked
Stacked widgets, widgets all occupying the same space in the window.
Definition: widget_type.h:438
NWidgetScrollbar::vertical_dimension
static Dimension vertical_dimension
Cached size of vertical scrollbar button.
Definition: widget_type.h:809
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_type.h:329
NWidgetBase::next
NWidgetBase * next
Pointer to next widget in container. Managed by parent container widget.
Definition: widget_type.h:192
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:75
Window::nested_array
NWidgetBase ** nested_array
Array of pointers into the tree. Do not access directly, use Window::GetWidget() instead.
Definition: window_gui.h:325
WidgetType
WidgetType
Window widget types, nested widget types, and nested widget part types.
Definition: widget_type.h:44
NWidgetResizeBase::SetFill
void SetFill(uint fill_x, uint fill_y)
Set the filling of the widget from initial size.
Definition: widget.cpp:905
string_colours.h
FillDrawPixelInfo
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:1772
WWT_TEXTBTN_2
@ WWT_TEXTBTN_2
(Toggle) Button with diff text when clicked
Definition: widget_type.h:54
WD_SHADEBOX_TOP
@ WD_SHADEBOX_TOP
Top offset of shade sprite.
Definition: window_gui.h:87
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:979
DrawResizeBox
static void DrawResizeBox(const Rect &r, Colours colour, bool at_left, bool clicked)
Draw a resize box.
Definition: widget.cpp:547
NWidgetSpacer::SetDirty
void SetDirty(const Window *w) const override
Mark the widget as 'dirty' (in need of repaint).
Definition: widget.cpp:1622
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:67
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:66
WD_SCROLLBAR_BOTTOM
@ WD_SCROLLBAR_BOTTOM
Bottom offset of scrollbar.
Definition: window_gui.h:53
WPT_MINTEXTLINES
@ WPT_MINTEXTLINES
Widget part for specifying minimal number of lines of text.
Definition: widget_type.h:87
NWidgetBase::GetWidgetFromPos
virtual NWidgetCore * GetWidgetFromPos(int x, int y)=0
WD_DROPDOWNTEXT_TOP
@ WD_DROPDOWNTEXT_TOP
Top offset of the dropdown widget string.
Definition: window_gui.h:136
Scrollbar::SetCapacity
void SetCapacity(int capacity)
Set the capacity of visible elements.
Definition: widget_type.h:728
NWidgetSpacer::SetupSmallestSize
void SetupSmallestSize(Window *w, bool init_array) override
Definition: widget.cpp:1607
WD_SHADEBOX_LEFT
@ WD_SHADEBOX_LEFT
Left offset of shade sprite.
Definition: window_gui.h:85
DrawFrame
static void DrawFrame(const Rect &r, Colours colour, TextColour text_colour, StringID str, StringAlignment align)
Draw a frame widget.
Definition: widget.cpp:452
NWidgetBackground::GetWidgetFromPos
NWidgetCore * GetWidgetFromPos(int x, int y) override
Definition: widget.cpp:2048
NWidgetMatrix::GetScrollOffsets
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:1844
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
NWidgetSpacer::Draw
void Draw(const Window *w) override
Definition: widget.cpp:1617
WWT_PUSHIMGBTN
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
Definition: widget_type.h:105
NWidgetBase::fill_y
uint fill_y
Vertical fill stepsize (from initial size, 0 means not resizable).
Definition: widget_type.h:177
NWidgetPart::cont_flags
NWidContainerFlags cont_flags
Part with container flags.
Definition: widget_type.h:985
SBS_DOWN
@ SBS_DOWN
Sort ascending.
Definition: window_gui.h:226
Clamp
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:77
strings_func.h
WD_DROPDOWN_HEIGHT
@ WD_DROPDOWN_HEIGHT
Height of a drop down widget.
Definition: window_gui.h:133
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:82
ScaleByZoom
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
SA_VERT_MASK
@ SA_VERT_MASK
Mask for vertical alignment.
Definition: gfx_type.h:336
NWidgetCore::disp_flags
NWidgetDisplay disp_flags
Flags that affect display and interaction with the widget.
Definition: widget_type.h:332
NWidgetCore::SetDataTip
void SetDataTip(uint32 widget_data, StringID tool_tip)
Set data and tool tip of the nested widget.
Definition: widget.cpp:962
Window::IsShaded
bool IsShaded() const
Is window shaded currently?
Definition: window_gui.h:520
HandleScrollbarHittest
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:63
NWidgetBase::pos_x
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:189
NWidgetHorizontal
Horizontal container.
Definition: widget_type.h:495
ST_RESIZE
@ ST_RESIZE
Resize the nested widget tree.
Definition: widget_type.h:113
NWidgetBackground::NWidgetBackground
NWidgetBackground(WidgetType tp, Colours colour, int index, NWidgetPIPContainer *child=nullptr)
Constructor parent nested widgets.
Definition: widget.cpp:1875
NWidgetBase::uz_padding_right
uint8 uz_padding_right
Unscaled right padding, for resize calculation.
Definition: widget_type.h:201
WD_CLOSEBOX_WIDTH
@ WD_CLOSEBOX_WIDTH
Width of a close box widget.
Definition: window_gui.h:119
NWidgetMatrix::FillNestedArray
void FillNestedArray(NWidgetBase **array, uint length) override
Definition: widget.cpp:1751
NWidgetResizeBase::uz_text_spacing
uint8 uz_text_spacing
'Unscaled' text padding, stored for resize calculation.
Definition: widget_type.h:273
WWT_TEXT
@ WWT_TEXT
Pure simple text.
Definition: widget_type.h:56
WD_BEVEL_RIGHT
@ WD_BEVEL_RIGHT
Width of right bevel border.
Definition: window_gui.h:57
NWidgetPIPContainer
Container with pre/inter/post child space.
Definition: widget_type.h:470
WD_CAPTIONTEXT_TOP
@ WD_CAPTIONTEXT_TOP
Offset of the caption text at the top.
Definition: window_gui.h:129
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:168
WD_DEFSIZEBOX_WIDTH
@ WD_DEFSIZEBOX_WIDTH
Width of a standard defsize box widget.
Definition: window_gui.h:105
WD_SHADEBOX_WIDTH
@ WD_SHADEBOX_WIDTH
Width of a standard shade box widget.
Definition: window_gui.h:84
ScaleGUITrad
static int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Definition: zoom_func.h:107
NWidgetBase::fill_x
uint fill_x
Horizontal fill stepsize (from initial size, 0 means not resizable).
Definition: widget_type.h:176
MakeWidgetTree
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:2999
NWidgetScrollbar
Nested widget to display and control a scrollbar in a window.
Definition: widget_type.h:797
geometry_func.hpp
WD_DEBUGBOX_WIDTH
@ WD_DEBUGBOX_WIDTH
Width of a standard debug box widget.
Definition: window_gui.h:98
NWidgetBackground::Draw
void Draw(const Window *w) override
Definition: widget.cpp:2011
WPT_RESIZE
@ WPT_RESIZE
Widget part for specifying resizing.
Definition: widget_type.h:85
NWidgetViewport::InitializeViewport
void InitializeViewport(Window *w, uint32 follow_flags, ZoomLevel zoom)
Initialize the viewport of the window.
Definition: widget.cpp:2107
NWidgetPIPContainer::flags
NWidContainerFlags flags
Flags of the container.
Definition: widget_type.h:481
transparency.h
WD_DEBUGBOX_BOTTOM
@ WD_DEBUGBOX_BOTTOM
Bottom offset of debug sprite.
Definition: window_gui.h:102
WD_SCROLLBAR_TOP
@ WD_SCROLLBAR_TOP
Top offset of scrollbar.
Definition: window_gui.h:52
NWidgetPartTextColour::colour
TextColour colour
TextColour for DrawString.
Definition: widget_type.h:950
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:48
_window_highlight_colour
bool _window_highlight_colour
If false, highlight is white, otherwise the by the widget defined colour.
Definition: window.cpp:75
NWidgetPIPContainer::pip_post
uint8 pip_post
Amount of space after last widget.
Definition: widget_type.h:484
NWidgetStacked::SetupSmallestSize
void SetupSmallestSize(Window *w, bool init_array) override
Definition: widget.cpp:1092
NWidgetBase::resize_y
uint resize_y
Vertical resize step (0 means not resizable).
Definition: widget_type.h:179
WPT_TEXTCOLOUR
@ WPT_TEXTCOLOUR
Widget part for specifying text colour.
Definition: widget_type.h:92
NWidgetBase::StoreSizePosition
void StoreSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height)
Store size and position.
Definition: widget_type.h:235
Window::IsWidgetLowered
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
Definition: window_gui.h:487
EventState
EventState
State of handling an event.
Definition: window_type.h:717
NWidgetVertical
Vertical container.
Definition: widget_type.h:518
NWidgetBackground::child
NWidgetPIPContainer * child
Child widget.
Definition: widget_type.h:605
Scrollbar::GetPosition
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:673
NWidgetPart::data_tip
NWidgetPartDataTip data_tip
Part with a data/tooltip.
Definition: widget_type.h:977
NWidgetContainer::FillNestedArray
void FillNestedArray(NWidgetBase **array, uint length) override
Definition: widget.cpp:1064
Window::UpdateWidgetSize
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:579
WD_IMGBTN_TOP
@ WD_IMGBTN_TOP
Top offset of image in the button.
Definition: window_gui.h:42
WD_RESIZEBOX_WIDTH
@ WD_RESIZEBOX_WIDTH
Width of a resize box widget.
Definition: window_gui.h:112
NWidgetCore::colour
Colours colour
Colour of this widget.
Definition: widget_type.h:333
NWidgetMatrix::widget_h
int widget_h
The height of the child widget including inter spacing.
Definition: widget_type.h:558
WD_STICKYBOX_BOTTOM
@ WD_STICKYBOX_BOTTOM
Bottom offset of sticky sprite.
Definition: window_gui.h:95
NWidgetResizeBase::uz_text_lines
uint8 uz_text_lines
'Unscaled' text lines, stored for resize calculation.
Definition: widget_type.h:272
NWID_SPACER
@ NWID_SPACER
Invisible widget that takes some space.
Definition: widget_type.h:77
company_func.h
WWT_INSET
@ WWT_INSET
Pressed (inset) panel, most commonly used as combo box text area.
Definition: widget_type.h:49
NWidgetContainer
Baseclass for container widgets.
Definition: widget_type.h:400
TO_SIGNS
@ TO_SIGNS
signs
Definition: transparency.h:23
Window::top
int top
y position of top edge of the window
Definition: window_gui.h:313
NWidgetBase::padding_right
uint8 padding_right
Paddings added to the right of the widget. Managed by parent container widget. (parent container may ...
Definition: widget_type.h:196
Window::DrawViewport
void DrawViewport() const
Draw the viewport of this window.
Definition: viewport.cpp:1815
NWidgetCore::scrollbar_index
int scrollbar_index
Index of an attached scrollbar.
Definition: widget_type.h:337
SA_LEFT
@ SA_LEFT
Left align the text.
Definition: gfx_type.h:328
DrawFrameRect
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition: widget.cpp:209
NWidgetBase::SetDirty
virtual void SetDirty(const Window *w) const
Mark the widget as 'dirty' (in need of repaint).
Definition: widget.cpp:807
NWidgetBase::uz_padding_top
uint8 uz_padding_top
Unscaled top padding, for resize calculation.
Definition: widget_type.h:200
WD_BEVEL_TOP
@ WD_BEVEL_TOP
Height of top bevel border.
Definition: window_gui.h:58
WD_BEVEL_LEFT
@ WD_BEVEL_LEFT
Width of left bevel border.
Definition: window_gui.h:56
WD_MATRIX_BOTTOM
@ WD_MATRIX_BOTTOM
Offset at bottom of a matrix cell.
Definition: window_gui.h:81
CenterBounds
static int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
Definition: gfx_func.h:140
SA_CENTER
@ SA_CENTER
Center both horizontally and vertically.
Definition: gfx_type.h:338
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition: fontcache.cpp:57
SetBit
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:314
GetAlignedPosition
static Point GetAlignedPosition(const Rect &r, const Dimension &d, StringAlignment align)
Calculate x and y coordinates for an aligned object within a window.
Definition: widget.cpp:34
Viewport::zoom
ZoomLevel zoom
The zoom level of the viewport.
Definition: viewport_type.h:33
Scrollbar::SetCapacityFromWidget
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:2212
WD_CAPTIONTEXT_BOTTOM
@ WD_CAPTIONTEXT_BOTTOM
Offset of the caption text at the bottom.
Definition: window_gui.h:130
Window::SortButtonWidth
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition: widget.cpp:690
NWidgetHorizontalLTR::NWidgetHorizontalLTR
NWidgetHorizontalLTR(NWidContainerFlags flags=NC_NONE)
Horizontal left-to-right container widget.
Definition: widget.cpp:1426
NWidgetHorizontalLTR::AssignSizePosition
void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override
Definition: widget.cpp:1431
FR_DARKENED
@ FR_DARKENED
If set the background is darker, allows for lowered frames with normal background colour when used wi...
Definition: window_gui.h:32
NWidgetResizeBase::min_x
uint min_x
Minimal horizontal size of only this widget.
Definition: widget_type.h:265
NWidgetBase::pos_y
int pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:190
WD_RESIZEBOX_TOP
@ WD_RESIZEBOX_TOP
Top offset of resize sprite.
Definition: window_gui.h:115
NWidgetCore::align
StringAlignment align
Alignment of text/image within widget.
Definition: widget_type.h:340
Scrollbar::SS_BIG
@ SS_BIG
Step in cap units.
Definition: widget_type.h:644
Scrollbar::SetStepSize
void SetStepSize(uint16 stepsize)
Set the distance to scroll when using the buttons or the wheel.
Definition: widget_type.h:701
NWidgetScrollbar::NWidgetScrollbar
NWidgetScrollbar(WidgetType tp, Colours colour, int index)
Scrollbar widget.
Definition: widget.cpp:2228
ND_SHADE_GREY
@ ND_SHADE_GREY
Bit value of the 'shade to grey' flag.
Definition: widget_type.h:298
WPT_PADDING
@ WPT_PADDING
Widget part for specifying a padding.
Definition: widget_type.h:90
NWidgetCore::text_colour
TextColour text_colour
Colour of text within widget.
Definition: widget_type.h:339
NWidgetPart::type
WidgetType type
Type of the part.
Definition: widget_type.h:974
NWidgetResizeBase::min_y
uint min_y
Minimal vertical size of only this widget.
Definition: widget_type.h:266
NWidgetHorizontalLTR
Horizontal container that doesn't change the direction of the widgets for RTL languages.
Definition: widget_type.h:507
DrawCaption
void DrawCaption(const Rect &r, Colours colour, Owner owner, TextColour text_colour, StringID str, StringAlignment align)
Draw a caption bar.
Definition: widget.cpp:583
WD_DEBUGBOX_TOP
@ WD_DEBUGBOX_TOP
Top offset of debug sprite.
Definition: window_gui.h:101
WD_CAPTION_HEIGHT
@ WD_CAPTION_HEIGHT
Height of a title bar.
Definition: window_gui.h:126
CeilDiv
static uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
Definition: math_func.hpp:254
WD_DROPDOWNTEXT_BOTTOM
@ WD_DROPDOWNTEXT_BOTTOM
Bottom offset of the dropdown widget string.
Definition: window_gui.h:137
FontSize
FontSize
Available font sizes.
Definition: gfx_type.h:206
NWidgetMatrix::widget_w
int widget_w
The width of the child widget including inter spacing.
Definition: widget_type.h:557
NWidgetBase::padding_bottom
uint8 padding_bottom
Paddings added to the bottom of the widget. Managed by parent container widget.
Definition: widget_type.h:197
NWidgetBackground::Add
void Add(NWidgetBase *nwid)
Add a child to the parent.
Definition: widget.cpp:1895
MAT_ROW_BITS
@ MAT_ROW_BITS
Number of bits for the number of rows in the matrix.
Definition: widget_type.h:30
Window
Data structure for an opened window.
Definition: window_gui.h:279
SizingType
SizingType
Different forms of sizing nested widgets, using NWidgetBase::AssignSizePosition()
Definition: widget_type.h:111
WD_CAPTIONTEXT_LEFT
@ WD_CAPTIONTEXT_LEFT
Offset of the caption text at the left.
Definition: window_gui.h:127
NWidContainerFlags
NWidContainerFlags
Nested widget container flags,.
Definition: widget_type.h:459
SZSP_VERTICAL
@ SZSP_VERTICAL
Display plane with zero size horizontally, and filling and resizing vertically.
Definition: widget_type.h:421
WD_MATRIX_LEFT
@ WD_MATRIX_LEFT
Offset at left of a matrix cell.
Definition: window_gui.h:78
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:636
NWidgetResizeBase::absolute
bool absolute
Set if minimum size is fixed and should not be resized.
Definition: widget_type.h:268
ZOOM_LVL_OUT_4X
@ ZOOM_LVL_OUT_4X
Zoomed 4 times out.
Definition: zoom_type.h:26
NWidgetBackground
Nested widget with a child.
Definition: widget_type.h:586
Viewport::virtual_height
int virtual_height
height << zoom
Definition: viewport_type.h:31
NWidgetVertical::NWidgetVertical
NWidgetVertical(NWidContainerFlags flags=NC_NONE)
Vertical container widget.
Definition: widget.cpp:1437
WD_DROPDOWNTEXT_LEFT
@ WD_DROPDOWNTEXT_LEFT
Left offset of the dropdown widget string.
Definition: window_gui.h:134
DrawImageButtons
static void DrawImageButtons(const Rect &r, WidgetType type, Colours colour, bool clicked, SpriteID img, StringAlignment align)
Draw an image button.
Definition: widget.cpp:251
NWidgetViewport::Draw
void Draw(const Window *w) override
Definition: widget.cpp:2081
WD_IMGBTN_LEFT
@ WD_IMGBTN_LEFT
Left offset of the image in the button.
Definition: window_gui.h:40
SBS_OFF
@ SBS_OFF
Do not sort (with this button).
Definition: window_gui.h:225
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:78
Window::nested_array_size
uint nested_array_size
Size of the nested array.
Definition: window_gui.h:326
NWidgetCore::index
int index
Index of the nested widget in the widget array of the window (-1 means 'not used').
Definition: widget_type.h:334
NWidgetMatrix::colour
Colours colour
Colour of this widget.
Definition: widget_type.h:552
NWidgetCore
Base class for a 'real' widget.
Definition: widget_type.h:311
NWidgetLeaf::closebox_dimension
static Dimension closebox_dimension
Cached size of a closebox widget.
Definition: widget_type.h:830
AWV_RIGHT
@ AWV_RIGHT
Force the arrow to the right.
Definition: widget_type.h:38
WWT_DEBUGBOX
@ WWT_DEBUGBOX
NewGRF debug box (at top-right of a window, between WWT_CAPTION and WWT_SHADEBOX)
Definition: widget_type.h:61
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:47
CursorVars::pos
Point pos
logical mouse position
Definition: gfx_type.h:117
NWidgetPartDataTip::tooltip
StringID tooltip
Tooltip of the widget.
Definition: widget_type.h:907
WD_CLOSEBOX_BOTTOM
@ WD_CLOSEBOX_BOTTOM
Bottom offset of closebox string.
Definition: window_gui.h:123
WPT_FUNCTION
@ WPT_FUNCTION
Widget part for calling a user function.
Definition: widget_type.h:95
NWidgetLeaf::Draw
void Draw(const Window *w) override
Definition: widget.cpp:2644
NWidgetVertical::AssignSizePosition
void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override
Definition: widget.cpp:1508
NWidgetBase::resize_x
uint resize_x
Horizontal resize step (0 means not resizable).
Definition: widget_type.h:178
AWV_INCREASE
@ AWV_INCREASE
Arrow to the right or in case of RTL to the left.
Definition: widget_type.h:36
NWidgetPartWidget::colour
Colours colour
Widget colour.
Definition: widget_type.h:915
NWidgetPartPaddings::left
uint8 left
Paddings for all directions.
Definition: widget_type.h:924
Window::GetRowFromWidget
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:212
InitializeWindowViewport
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:223
NWidgetPartTextLines::size
FontSize size
Font size of text lines.
Definition: widget_type.h:942
NWidgetBase::current_x
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:186
WD_BEVEL_BOTTOM
@ WD_BEVEL_BOTTOM
Height of bottom bevel border.
Definition: window_gui.h:59
NWidgetStacked::shown_plane
int shown_plane
Plane being displayed (for NWID_SELECTION only).
Definition: widget_type.h:454
NWidgetMatrix::AssignSizePosition
void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override
Definition: widget.cpp:1727
NWidgetResizeBase::SetMinimalSize
void SetMinimalSize(uint min_x, uint min_y)
Set minimal size of the widget.
Definition: widget.cpp:866
NWidgetScrollbar::horizontal_dimension
static Dimension horizontal_dimension
Cached size of horizontal scrollbar button.
Definition: widget_type.h:810
WD_IMGBTN_RIGHT
@ WD_IMGBTN_RIGHT
Right offset of the image in the button.
Definition: window_gui.h:41
NWidgetLeaf::SetupSmallestSize
void SetupSmallestSize(Window *w, bool init_array) override
Definition: widget.cpp:2450
MakeNWidget
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:2809
NWidgetResizeBase::SetMinimalSizeAbsolute
void SetMinimalSizeAbsolute(uint min_x, uint min_y)
Set absolute (post-scaling) minimal size of the widget.
Definition: widget.cpp:879
NWidgetScrollbar::Draw
void Draw(const Window *w) override
Definition: widget.cpp:2275
NWidgetCore::GetWidgetFromPos
NWidgetCore * GetWidgetFromPos(int x, int y) override
Definition: widget.cpp:1000
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
WD_CLOSEBOX_LEFT
@ WD_CLOSEBOX_LEFT
Left offset of closebox string.
Definition: window_gui.h:120
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:48
NWidgetLeaf::ButtonHit
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:2781
MakeWindowNWidgetTree
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:3077
NWidgetCore::FillNestedArray
void FillNestedArray(NWidgetBase **array, uint length) override
Definition: widget.cpp:995
LeastCommonMultiple
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
NWidgetHorizontal::NWidgetHorizontal
NWidgetHorizontal(NWidContainerFlags flags=NC_NONE)
Horizontal container widget.
Definition: widget.cpp:1252
NWidgetBackground::FillNestedArray
void FillNestedArray(NWidgetBase **array, uint length) override
Definition: widget.cpp:2005
DrawInset
static void DrawInset(const Rect &r, Colours colour, TextColour text_colour, StringID str, StringAlignment align)
Draw an inset widget.
Definition: widget.cpp:302
WD_RESIZEBOX_LEFT
@ WD_RESIZEBOX_LEFT
Left offset of resize sprite.
Definition: window_gui.h:113
ND_SCROLLBAR_BTN
@ ND_SCROLLBAR_BTN
Bit value of the 'scrollbar up' or 'scrollbar down' flag.
Definition: widget_type.h:303
WD_STICKYBOX_LEFT
@ WD_STICKYBOX_LEFT
Left offset of sticky sprite.
Definition: window_gui.h:92
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:53
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:598
NWID_BUTTON_DROPDOWN
@ NWID_BUTTON_DROPDOWN
Button with a drop-down.
Definition: widget_type.h:80
FR_BORDERONLY
@ FR_BORDERONLY
Draw border only, no background.
Definition: window_gui.h:30
NWidgetPartDataTip::data
uint32 data
Data value of the widget.
Definition: widget_type.h:906
NWidgetMatrix::widgets_x
int widgets_x
The number of visible widgets in horizontal direction.
Definition: widget_type.h:559
AWV_DECREASE
@ AWV_DECREASE
Arrow to the left or in case of RTL to the right.
Definition: widget_type.h:35
WWT_DROPDOWN
@ WWT_DROPDOWN
Drop down list.
Definition: widget_type.h:68
ND_NO_TRANSPARENCY
@ ND_NO_TRANSPARENCY
Bit value of the 'no transparency' flag.
Definition: widget_type.h:297
DrawPixelInfo
Data about how and where to blit pixels.
Definition: gfx_type.h:155
NC_BIGFIRST
@ NC_BIGFIRST
Value of the NCB_BIGFIRST flag.
Definition: widget_type.h:465
NWidgetPart::text_lines
NWidgetPartTextLines text_lines
Part with text line data.
Definition: widget_type.h:981
WD_CAPTIONTEXT_RIGHT
@ WD_CAPTIONTEXT_RIGHT
Offset of the caption text at the right.
Definition: window_gui.h:128
NWidgetPartAlignment::align
StringAlignment align
Alignment of text/image.
Definition: widget_type.h:958
WD_DEFSIZEBOX_TOP
@ WD_DEFSIZEBOX_TOP
Top offset of defsize sprite.
Definition: window_gui.h:108
NWidgetBase::uz_padding_left
uint8 uz_padding_left
Unscaled left padding, for resize calculation.
Definition: widget_type.h:203
NWidgetBase::SetupSmallestSize
virtual void SetupSmallestSize(Window *w, bool init_array)=0
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:62
NWidgetMatrix::SetClicked
void SetClicked(int clicked)
Sets the clicked widget in the matrix.
Definition: widget.cpp:1650
WPT_ENDCONTAINER
@ WPT_ENDCONTAINER
Widget part to denote end of a container.
Definition: widget_type.h:94