OpenTTD Source  13.2.1
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 
29  /* WWT_IMGBTN(_2) */
34 
35  /* WWT_INSET */
39 
44 
49 
50  /* Size of the pure frame bevel without any padding. */
55 
56  /* FrameRect widgets, all text buttons, panel, editbox */
61 
62  /* WWT_FRAME */
67 
68  /* WWT_MATRIX */
73 
74  /* WWT_SHADEBOX */
80 
81  /* WWT_STICKYBOX */
87 
88  /* WWT_DEBUGBOX */
94 
95  /* WWT_DEFSIZEBOX */
101 
102  /* WWT_RESIZEBOX */
108 
109  /* WWT_CLOSEBOX */
115 
116  /* WWT_CAPTION */
122 
123  /* Dropdown widget. */
129 
132 };
133 
152  {20, 10, 20, 10},
153  1,
156  2,
157  6,
158  10,
159 };
160 
162 
168 static inline RectPadding ScaleGUITrad(const RectPadding &r)
169 {
170  return {(uint8)ScaleGUITrad(r.left), (uint8)ScaleGUITrad(r.top), (uint8)ScaleGUITrad(r.right), (uint8)ScaleGUITrad(r.bottom)};
171 }
172 
178 static inline Dimension ScaleGUITrad(const Dimension &dim)
179 {
180  return {(uint)ScaleGUITrad(dim.width), (uint)ScaleGUITrad(dim.height)};
181 }
182 
188 {
189  Point offset;
190  Dimension d = GetSpriteSize(sprid, &offset, ZOOM_LVL_OUT_4X);
191  d.width -= offset.x;
192  d.height -= offset.y;
193  return ScaleGUITrad(d);
194 }
195 
200 {
207  } else {
209  }
223 
230 }
231 
239 static inline Point GetAlignedPosition(const Rect &r, const Dimension &d, StringAlignment align)
240 {
241  Point p;
242  /* In case we have a RTL language we swap the alignment. */
243  if (!(align & SA_FORCE) && _current_text_dir == TD_RTL && (align & SA_HOR_MASK) != SA_HOR_CENTER) align ^= SA_RIGHT;
244  switch (align & SA_HOR_MASK) {
245  case SA_LEFT: p.x = r.left; break;
246  case SA_HOR_CENTER: p.x = CenterBounds(r.left, r.right, d.width); break;
247  case SA_RIGHT: p.x = r.right + 1 - d.width; break;
248  default: NOT_REACHED();
249  }
250  switch (align & SA_VERT_MASK) {
251  case SA_TOP: p.y = r.top; break;
252  case SA_VERT_CENTER: p.y = CenterBounds(r.top, r.bottom, d.height); break;
253  case SA_BOTTOM: p.y = r.bottom + 1 - d.height; break;
254  default: NOT_REACHED();
255  }
256  return p;
257 }
258 
268 static Point HandleScrollbarHittest(const Scrollbar *sb, int top, int bottom, bool horizontal)
269 {
270  /* Base for reversion */
271  int rev_base = top + bottom;
272  int button_size;
273  if (horizontal) {
274  button_size = NWidgetScrollbar::GetHorizontalDimension().width;
275  } else {
276  button_size = NWidgetScrollbar::GetVerticalDimension().height;
277  }
278  top += button_size; // top points to just below the up-button
279  bottom -= button_size; // bottom points to top of the down-button
280 
281  int height = (bottom - top);
282  int pos = sb->GetPosition();
283  int count = sb->GetCount();
284  int cap = sb->GetCapacity();
285 
286  if (count != 0) top += height * pos / count;
287 
288  if (cap > count) cap = count;
289  if (count != 0) bottom -= (count - pos - cap) * height / count;
290 
291  Point pt;
292  if (horizontal && _current_text_dir == TD_RTL) {
293  pt.x = rev_base - bottom;
294  pt.y = rev_base - top;
295  } else {
296  pt.x = top;
297  pt.y = bottom;
298  }
299  return pt;
300 }
301 
311 static void ScrollbarClickPositioning(Window *w, NWidgetScrollbar *sb, int x, int y, int mi, int ma)
312 {
313  int pos;
314  int button_size;
315  bool rtl = false;
316  bool changed = false;
317 
318  if (sb->type == NWID_HSCROLLBAR) {
319  pos = x;
320  rtl = _current_text_dir == TD_RTL;
321  button_size = NWidgetScrollbar::GetHorizontalDimension().width;
322  } else {
323  pos = y;
324  button_size = NWidgetScrollbar::GetVerticalDimension().height;
325  }
326  if (pos < mi + button_size) {
327  /* Pressing the upper button? */
329  if (_scroller_click_timeout <= 1) {
330  _scroller_click_timeout = 3;
331  changed = sb->UpdatePosition(rtl ? 1 : -1);
332  }
333  w->mouse_capture_widget = sb->index;
334  } else if (pos >= ma - button_size) {
335  /* Pressing the lower button? */
337 
338  if (_scroller_click_timeout <= 1) {
339  _scroller_click_timeout = 3;
340  changed = sb->UpdatePosition(rtl ? -1 : 1);
341  }
342  w->mouse_capture_widget = sb->index;
343  } else {
344  Point pt = HandleScrollbarHittest(sb, mi, ma, sb->type == NWID_HSCROLLBAR);
345 
346  if (pos < pt.x) {
347  changed = sb->UpdatePosition(rtl ? 1 : -1, Scrollbar::SS_BIG);
348  } else if (pos > pt.y) {
349  changed = sb->UpdatePosition(rtl ? -1 : 1, Scrollbar::SS_BIG);
350  } else {
351  _scrollbar_start_pos = pt.x - mi - button_size;
352  _scrollbar_size = ma - mi - button_size * 2;
353  w->mouse_capture_widget = sb->index;
354  _cursorpos_drag_start = _cursor.pos;
355  }
356  }
357 
358  if (changed) {
359  /* Position changed so refresh the window */
360  w->SetDirty();
361  } else {
362  /* No change so only refresh this scrollbar */
363  sb->SetDirty(w);
364  }
365 }
366 
375 void ScrollbarClickHandler(Window *w, NWidgetCore *nw, int x, int y)
376 {
377  int mi, ma;
378 
379  if (nw->type == NWID_HSCROLLBAR) {
380  mi = nw->pos_x;
381  ma = nw->pos_x + nw->current_x;
382  } else {
383  mi = nw->pos_y;
384  ma = nw->pos_y + nw->current_y;
385  }
386  NWidgetScrollbar *scrollbar = dynamic_cast<NWidgetScrollbar*>(nw);
387  assert(scrollbar != nullptr);
388  ScrollbarClickPositioning(w, scrollbar, x, y, mi, ma);
389 }
390 
399 int GetWidgetFromPos(const Window *w, int x, int y)
400 {
401  NWidgetCore *nw = w->nested_root->GetWidgetFromPos(x, y);
402  return (nw != nullptr) ? nw->index : -1;
403 }
404 
414 void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
415 {
416  assert(colour < COLOUR_END);
417 
418  uint dark = _colour_gradient[colour][3];
419  uint medium_dark = _colour_gradient[colour][5];
420  uint medium_light = _colour_gradient[colour][6];
421  uint light = _colour_gradient[colour][7];
422 
423  if (flags & FR_TRANSPARENT) {
424  GfxFillRect(left, top, right, bottom, PALETTE_TO_TRANSPARENT, FILLRECT_RECOLOUR);
425  } else {
426  uint interior;
427 
428  Rect outer = {left, top, right, bottom}; // Outside rectangle
429  Rect inner = outer.Shrink(WidgetDimensions::scaled.bevel); // Inside rectangle
430 
431  if (flags & FR_LOWERED) {
432  GfxFillRect(outer.left, outer.top, inner.left - 1, outer.bottom, dark); // Left
433  GfxFillRect(inner.left, outer.top, outer.right, inner.top - 1, dark); // Top
434  GfxFillRect(inner.right + 1, inner.top, outer.right, inner.bottom, light); // Right
435  GfxFillRect(inner.left, inner.bottom + 1, outer.right, outer.bottom, light); // Bottom
436  interior = (flags & FR_DARKENED ? medium_dark : medium_light);
437  } else {
438  GfxFillRect(outer.left, outer.top, inner.left - 1, inner.bottom, light); // Left
439  GfxFillRect(inner.left, outer.top, inner.right, inner.top - 1, light); // Top
440  GfxFillRect(inner.right + 1, outer.top, outer.right, inner.bottom, dark); // Right
441  GfxFillRect(outer.left, inner.bottom + 1, outer.right, outer.bottom, dark); // Bottom
442  interior = medium_dark;
443  }
444  if (!(flags & FR_BORDERONLY)) {
445  GfxFillRect(inner.left, inner.top, inner.right, inner.bottom, interior); // Inner
446  }
447  }
448 }
449 
450 void DrawSpriteIgnorePadding(SpriteID img, PaletteID pal, const Rect &r, bool clicked, StringAlignment align)
451 {
452  Point offset;
453  Dimension d = GetSpriteSize(img, &offset);
454  d.width -= offset.x;
455  d.height -= offset.y;
456 
457  Point p = GetAlignedPosition(r, d, align);
458  int o = clicked ? WidgetDimensions::scaled.pressed : 0;
459  DrawSprite(img, pal, p.x + o - offset.x, p.y + o - offset.y);
460 }
461 
471 static inline void DrawImageButtons(const Rect &r, WidgetType type, Colours colour, bool clicked, SpriteID img, StringAlignment align)
472 {
473  assert(img != 0);
474  DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE);
475 
476  if ((type & WWT_MASK) == WWT_IMGBTN_2 && clicked) img++; // Show different image when clicked for #WWT_IMGBTN_2.
477  DrawSpriteIgnorePadding(img, PAL_NONE, r, clicked, align);
478 }
479 
489 static inline void DrawLabel(const Rect &r, WidgetType type, bool clicked, TextColour colour, StringID str, StringAlignment align)
490 {
491  if (str == STR_NULL) return;
492  if ((type & WWT_MASK) == WWT_TEXTBTN_2 && clicked) str++;
494  Point p = GetAlignedPosition(r, d, align);
495  int o = clicked ? WidgetDimensions::scaled.pressed : 0;
496  DrawString(r.left + o, r.right + o, p.y + o, str, colour, align);
497 }
498 
506 static inline void DrawText(const Rect &r, TextColour colour, StringID str, StringAlignment align)
507 {
509  Point p = GetAlignedPosition(r, d, align);
510  if (str != STR_NULL) DrawString(r.left, r.right, p.y, str, colour, align);
511 }
512 
521 static inline void DrawInset(const Rect &r, Colours colour, TextColour text_colour, StringID str, StringAlignment align)
522 {
523  DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, FR_LOWERED | FR_DARKENED);
524  if (str != STR_NULL) DrawString(r.Shrink(WidgetDimensions::scaled.inset), str, text_colour, align);
525 }
526 
536 static inline void DrawMatrix(const Rect &r, Colours colour, bool clicked, uint16 data, uint resize_x, uint resize_y)
537 {
538  DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE);
539 
540  int num_columns = GB(data, MAT_COL_START, MAT_COL_BITS); // Lower 8 bits of the widget data: Number of columns in the matrix.
541  int column_width; // Width of a single column in the matrix.
542  if (num_columns == 0) {
543  column_width = resize_x;
544  num_columns = r.Width() / column_width;
545  } else {
546  column_width = r.Width() / num_columns;
547  }
548 
549  int num_rows = GB(data, MAT_ROW_START, MAT_ROW_BITS); // Upper 8 bits of the widget data: Number of rows in the matrix.
550  int row_height; // Height of a single row in the matrix.
551  if (num_rows == 0) {
552  row_height = resize_y;
553  num_rows = r.Height() / row_height;
554  } else {
555  row_height = r.Height() / num_rows;
556  }
557 
558  int col = _colour_gradient[colour & 0xF][6];
559 
560  int x = r.left;
561  for (int ctr = num_columns; ctr > 1; ctr--) {
562  x += column_width;
563  GfxFillRect(x, r.top + WidgetDimensions::scaled.bevel.top, x + WidgetDimensions::scaled.bevel.left - 1, r.bottom - WidgetDimensions::scaled.bevel.bottom, col);
564  }
565 
566  x = r.top;
567  for (int ctr = num_rows; ctr > 1; ctr--) {
568  x += row_height;
569  GfxFillRect(r.left + WidgetDimensions::scaled.bevel.left, x, r.right - WidgetDimensions::scaled.bevel.right, x + WidgetDimensions::scaled.bevel.top - 1, col);
570  }
571 
572  col = _colour_gradient[colour & 0xF][4];
573 
574  x = r.left - 1;
575  for (int ctr = num_columns; ctr > 1; ctr--) {
576  x += column_width;
577  GfxFillRect(x - WidgetDimensions::scaled.bevel.right + 1, r.top + WidgetDimensions::scaled.bevel.top, x, r.bottom - WidgetDimensions::scaled.bevel.bottom, col);
578  }
579 
580  x = r.top - 1;
581  for (int ctr = num_rows; ctr > 1; ctr--) {
582  x += row_height;
583  GfxFillRect(r.left + WidgetDimensions::scaled.bevel.left, x - WidgetDimensions::scaled.bevel.bottom + 1, r.right - WidgetDimensions::scaled.bevel.right, x, col);
584  }
585 }
586 
596 static inline void DrawVerticalScrollbar(const Rect &r, Colours colour, bool up_clicked, bool bar_dragged, bool down_clicked, const Scrollbar *scrollbar)
597 {
598  int height = NWidgetScrollbar::GetVerticalDimension().height;
599 
600  /* draw up/down buttons */
601  DrawImageButtons(r.WithHeight(height, false), NWID_VSCROLLBAR, colour, up_clicked, SPR_ARROW_UP, SA_CENTER);
602  DrawImageButtons(r.WithHeight(height, true), NWID_VSCROLLBAR, colour, down_clicked, SPR_ARROW_DOWN, SA_CENTER);
603 
604  int c1 = _colour_gradient[colour & 0xF][3];
605  int c2 = _colour_gradient[colour & 0xF][7];
606 
607  /* draw "shaded" background */
608  GfxFillRect(r.left, r.top + height, r.right, r.bottom - height, c2);
609  GfxFillRect(r.left, r.top + height, r.right, r.bottom - height, c1, FILLRECT_CHECKER);
610 
611  /* track positions. These fractions are based on original 1x dimensions, but scale better. */
612  int left = r.left + r.Width() * 3 / 11; /* left track is positioned 3/11ths from the left */
613  int right = r.left + r.Width() * 8 / 11; /* right track is positioned 8/11ths from the left */
614  const uint8 bl = WidgetDimensions::scaled.bevel.left;
615  const uint8 br = WidgetDimensions::scaled.bevel.right;
616 
617  /* draw shaded lines */
618  GfxFillRect(left - bl, r.top + height, left - 1, r.bottom - height, c1);
619  GfxFillRect(left, r.top + height, left + br - 1, r.bottom - height, c2);
620  GfxFillRect(right - bl, r.top + height, right - 1, r.bottom - height, c1);
621  GfxFillRect(right, r.top + height, right + br - 1, r.bottom - height, c2);
622 
623  Point pt = HandleScrollbarHittest(scrollbar, r.top, r.bottom, false);
624  DrawFrameRect(r.left, pt.x, r.right, pt.y, colour, bar_dragged ? FR_LOWERED : FR_NONE);
625 }
626 
636 static inline void DrawHorizontalScrollbar(const Rect &r, Colours colour, bool left_clicked, bool bar_dragged, bool right_clicked, const Scrollbar *scrollbar)
637 {
638  int width = NWidgetScrollbar::GetHorizontalDimension().width;
639 
640  DrawImageButtons(r.WithWidth(width, false), NWID_HSCROLLBAR, colour, left_clicked, SPR_ARROW_LEFT, SA_CENTER);
641  DrawImageButtons(r.WithWidth(width, true), NWID_HSCROLLBAR, colour, right_clicked, SPR_ARROW_RIGHT, SA_CENTER);
642 
643  int c1 = _colour_gradient[colour & 0xF][3];
644  int c2 = _colour_gradient[colour & 0xF][7];
645 
646  /* draw "shaded" background */
647  GfxFillRect(r.left + width, r.top, r.right - width, r.bottom, c2);
648  GfxFillRect(r.left + width, r.top, r.right - width, r.bottom, c1, FILLRECT_CHECKER);
649 
650  /* track positions. These fractions are based on original 1x dimensions, but scale better. */
651  int top = r.top + r.Height() * 3 / 11; /* top track is positioned 3/11ths from the top */
652  int bottom = r.top + r.Height() * 8 / 11; /* bottom track is positioned 8/11ths from the top */
653  const uint8 bt = WidgetDimensions::scaled.bevel.top;
654  const uint8 bb = WidgetDimensions::scaled.bevel.bottom;
655 
656  /* draw shaded lines */
657  GfxFillRect(r.left + width, top - bt, r.right - width, top - 1, c1);
658  GfxFillRect(r.left + width, top, r.right - width, top + bb - 1, c2);
659  GfxFillRect(r.left + width, bottom - bt, r.right - width, bottom - 1, c1);
660  GfxFillRect(r.left + width, bottom, r.right - width, bottom + bb - 1, c2);
661 
662  /* draw actual scrollbar */
663  Point pt = HandleScrollbarHittest(scrollbar, r.left, r.right, true);
664  DrawFrameRect(pt.x, r.top, pt.y, r.bottom, colour, bar_dragged ? FR_LOWERED : FR_NONE);
665 }
666 
675 static inline void DrawFrame(const Rect &r, Colours colour, TextColour text_colour, StringID str, StringAlignment align)
676 {
677  int x2 = r.left; // by default the left side is the left side of the widget
678 
679  if (str != STR_NULL) x2 = DrawString(r.left + WidgetDimensions::scaled.frametext.left, r.right - WidgetDimensions::scaled.frametext.right, r.top, str, text_colour, align);
680 
681  int c1 = _colour_gradient[colour][3];
682  int c2 = _colour_gradient[colour][7];
683 
684  /* If the frame has text, adjust the top bar to fit half-way through */
685  Rect inner = r.Shrink(ScaleGUITrad(1));
686  if (str != STR_NULL) inner.top = r.top + FONT_HEIGHT_NORMAL / 2;
687 
688  Rect outer = inner.Expand(WidgetDimensions::scaled.bevel);
689  Rect inside = inner.Shrink(WidgetDimensions::scaled.bevel);
690 
691  if (_current_text_dir == TD_LTR) {
692  /* Line from upper left corner to start of text */
693  GfxFillRect(outer.left, outer.top, r.left + WidgetDimensions::scaled.frametext.left - WidgetDimensions::scaled.bevel.left - 1, inner.top - 1, c1);
694  GfxFillRect(inner.left, inner.top, r.left + WidgetDimensions::scaled.frametext.left - WidgetDimensions::scaled.bevel.left - 1, inside.top - 1, c2);
695 
696  /* Line from end of text to upper right corner */
697  GfxFillRect(x2 + WidgetDimensions::scaled.bevel.right, outer.top, inner.right, inner.top - 1, c1);
698  GfxFillRect(x2 + WidgetDimensions::scaled.bevel.right, inner.top, inside.right, inside.top - 1, c2);
699  } else {
700  /* Line from upper left corner to start of text */
701  GfxFillRect(outer.left, outer.top, x2 - WidgetDimensions::scaled.bevel.left - 1, inner.top - 1, c1);
702  GfxFillRect(inner.left, inner.top, x2 - WidgetDimensions::scaled.bevel.left - 1, inside.top - 1, c2);
703 
704  /* Line from end of text to upper right corner */
705  GfxFillRect(r.right - WidgetDimensions::scaled.frametext.right + WidgetDimensions::scaled.bevel.right, outer.top, inner.right, inner.top - 1, c1);
706  GfxFillRect(r.right - WidgetDimensions::scaled.frametext.right + WidgetDimensions::scaled.bevel.right, inner.top, inside.right, inside.top - 1, c2);
707  }
708 
709  /* Line from upper left corner to bottom left corner */
710  GfxFillRect(outer.left, inner.top, inner.left - 1, inner.bottom, c1);
711  GfxFillRect(inner.left, inside.top, inside.left - 1, inside.bottom, c2);
712 
713  /* Line from upper right corner to bottom right corner */
714  GfxFillRect(inside.right + 1, inner.top, inner.right, inside.bottom, c1);
715  GfxFillRect(inner.right + 1, outer.top, outer.right, inner.bottom, c2);
716 
717  /* Line from bottom left corner to bottom right corner */
718  GfxFillRect(inner.left, inside.bottom + 1, inner.right, inner.bottom, c1);
719  GfxFillRect(outer.left, inner.bottom + 1, outer.right, outer.bottom, c2);
720 }
721 
728 static inline void DrawShadeBox(const Rect &r, Colours colour, bool clicked)
729 {
730  DrawImageButtons(r, WWT_SHADEBOX, colour, clicked, clicked ? SPR_WINDOW_SHADE: SPR_WINDOW_UNSHADE, SA_CENTER);
731 }
732 
739 static inline void DrawStickyBox(const Rect &r, Colours colour, bool clicked)
740 {
741  DrawImageButtons(r, WWT_STICKYBOX, colour, clicked, clicked ? SPR_PIN_UP : SPR_PIN_DOWN, SA_CENTER);
742 }
743 
750 static inline void DrawDefSizeBox(const Rect &r, Colours colour, bool clicked)
751 {
752  DrawImageButtons(r, WWT_DEFSIZEBOX, colour, clicked, SPR_WINDOW_DEFSIZE, SA_CENTER);
753 }
754 
761 static inline void DrawDebugBox(const Rect &r, Colours colour, bool clicked)
762 {
763  DrawImageButtons(r, WWT_DEBUGBOX, colour, clicked, SPR_WINDOW_DEBUG, SA_CENTER);
764 }
765 
773 static inline void DrawResizeBox(const Rect &r, Colours colour, bool at_left, bool clicked)
774 {
775  DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE);
776  DrawSpriteIgnorePadding(at_left ? SPR_WINDOW_RESIZE_LEFT : SPR_WINDOW_RESIZE_RIGHT, PAL_NONE, r.Shrink(ScaleGUITrad(2)), clicked, at_left ? (SA_LEFT | SA_BOTTOM | SA_FORCE) : (SA_RIGHT | SA_BOTTOM | SA_FORCE));
777 }
778 
784 static inline void DrawCloseBox(const Rect &r, Colours colour)
785 {
786  if (colour != COLOUR_WHITE) DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, FR_NONE);
787  Point offset;
788  Dimension d = GetSpriteSize(SPR_CLOSEBOX, &offset);
789  d.width -= offset.x;
790  d.height -= offset.y;
791  int s = ScaleSpriteTrad(1); /* Offset to account for shadow of SPR_CLOSEBOX */
792  DrawSprite(SPR_CLOSEBOX, (colour != COLOUR_WHITE ? TC_BLACK : TC_SILVER) | (1U << PALETTE_TEXT_RECOLOUR), CenterBounds(r.left, r.right, d.width - s) - offset.x, CenterBounds(r.top, r.bottom, d.height - s) - offset.y);
793 }
794 
804 void DrawCaption(const Rect &r, Colours colour, Owner owner, TextColour text_colour, StringID str, StringAlignment align)
805 {
806  bool company_owned = owner < MAX_COMPANIES;
807 
808  DrawFrameRect(r, colour, FR_BORDERONLY);
809  Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
810  DrawFrameRect(ir, colour, company_owned ? FR_LOWERED | FR_DARKENED | FR_BORDERONLY : FR_LOWERED | FR_DARKENED);
811 
812  if (company_owned) {
814  }
815 
816  if (str != STR_NULL) {
818  Point p = GetAlignedPosition(r, d, align);
819  DrawString(r.left + WidgetDimensions::scaled.captiontext.left, r.right - WidgetDimensions::scaled.captiontext.left, p.y, str, text_colour, align);
820  }
821 }
822 
834 static inline void DrawButtonDropdown(const Rect &r, Colours colour, bool clicked_button, bool clicked_dropdown, StringID str, StringAlignment align)
835 {
836  int dd_width = NWidgetLeaf::dropdown_dimension.width;
837 
838  if (_current_text_dir == TD_LTR) {
839  DrawFrameRect(r.left, r.top, r.right - dd_width, r.bottom, colour, clicked_button ? FR_LOWERED : FR_NONE);
840  DrawImageButtons(r.WithWidth(dd_width, true), WWT_DROPDOWN, colour, clicked_dropdown, SPR_ARROW_DOWN, SA_CENTER);
841  if (str != STR_NULL) {
842  int o = clicked_button ? WidgetDimensions::scaled.pressed : 0;
843  DrawString(r.left + WidgetDimensions::scaled.dropdowntext.left + o, r.right - dd_width - WidgetDimensions::scaled.dropdowntext.right + o, CenterBounds(r.top, r.bottom, FONT_HEIGHT_NORMAL) + o, str, TC_BLACK, align);
844  }
845  } else {
846  DrawFrameRect(r.left + dd_width, r.top, r.right, r.bottom, colour, clicked_button ? FR_LOWERED : FR_NONE);
847  DrawImageButtons(r.WithWidth(dd_width, false), WWT_DROPDOWN, colour, clicked_dropdown, SPR_ARROW_DOWN, SA_CENTER);
848  if (str != STR_NULL) {
849  int o = clicked_button ? WidgetDimensions::scaled.pressed : 0;
850  DrawString(r.left + dd_width + WidgetDimensions::scaled.dropdowntext.left + o, r.right - WidgetDimensions::scaled.dropdowntext.right + o, CenterBounds(r.top, r.bottom, FONT_HEIGHT_NORMAL) + o, str, TC_BLACK, align);
851  }
852  }
853 }
854 
859 {
860  this->nested_root->Draw(this);
861 
862  if (this->flags & WF_WHITE_BORDER) {
863  DrawFrameRect(0, 0, this->width - 1, this->height - 1, COLOUR_WHITE, FR_BORDERONLY);
864  }
865 
866  if (this->flags & WF_HIGHLIGHTED) {
867  extern bool _window_highlight_colour;
868  for (uint i = 0; i < this->nested_array_size; i++) {
869  const NWidgetBase *widget = this->GetWidget<NWidgetBase>(i);
870  if (widget == nullptr || !widget->IsHighlighted()) continue;
871 
872  Rect outer = widget->GetCurrentRect();
873  Rect inner = outer.Shrink(WidgetDimensions::scaled.bevel).Expand(1);
874 
875  int colour = _string_colourmap[_window_highlight_colour ? widget->GetHighlightColour() : TC_WHITE];
876 
877  GfxFillRect(outer.left, outer.top, inner.left, inner.bottom, colour);
878  GfxFillRect(inner.left + 1, outer.top, inner.right - 1, inner.top, colour);
879  GfxFillRect(inner.right, outer.top, outer.right, inner.bottom, colour);
880  GfxFillRect(outer.left + 1, inner.bottom, outer.right - 1, outer.bottom, colour);
881  }
882  }
883 }
884 
890 void Window::DrawSortButtonState(int widget, SortButtonState state) const
891 {
892  if (state == SBS_OFF) return;
893 
894  assert(this->nested_array != nullptr);
895  Rect r = this->GetWidget<NWidgetBase>(widget)->GetCurrentRect();
896 
897  /* Sort button uses the same sprites as vertical scrollbar */
898  Dimension dim = NWidgetScrollbar::GetVerticalDimension();
899 
900  DrawSpriteIgnorePadding(state == SBS_DOWN ? SPR_ARROW_DOWN : SPR_ARROW_UP, PAL_NONE, r.WithWidth(dim.width, _current_text_dir == TD_LTR), this->IsWidgetLowered(widget), SA_CENTER);
901 }
902 
908 {
909  return NWidgetScrollbar::GetVerticalDimension().width + 1;
910 }
911 
912 
971 {
972  this->type = tp;
973 }
974 
975 /* ~NWidgetContainer() takes care of #next and #prev data members. */
976 
1024 void NWidgetBase::SetDirty(const Window *w) const
1025 {
1026  int abs_left = w->left + this->pos_x;
1027  int abs_top = w->top + this->pos_y;
1028  AddDirtyBlock(abs_left, abs_top, abs_left + this->current_x, abs_top + this->current_y);
1029 }
1030 
1045 {
1046  return (this->type == tp) ? this : nullptr;
1047 }
1048 
1049 void NWidgetBase::AdjustPaddingForZoom()
1050 {
1051  this->padding = ScaleGUITrad(this->uz_padding);
1052 }
1053 
1061 {
1062  this->fill_x = fill_x;
1063  this->fill_y = fill_y;
1064 }
1065 
1066 void NWidgetResizeBase::AdjustPaddingForZoom()
1067 {
1068  if (!this->absolute) {
1069  this->min_x = ScaleGUITrad(this->uz_min_x);
1070  this->min_y = std::max(ScaleGUITrad(this->uz_min_y), this->uz_text_lines * GetCharacterHeight(this->uz_text_size) + ScaleGUITrad(this->uz_text_spacing));
1071  }
1072  NWidgetBase::AdjustPaddingForZoom();
1073 }
1074 
1080 void NWidgetResizeBase::SetMinimalSize(uint min_x, uint min_y)
1081 {
1082  this->uz_min_x = std::max(this->uz_min_x, min_x);
1083  this->uz_min_y = std::max(this->uz_min_y, min_y);
1084  this->min_x = ScaleGUITrad(this->uz_min_x);
1085  this->min_y = std::max(ScaleGUITrad(this->uz_min_y), this->uz_text_lines * GetCharacterHeight(this->uz_text_size) + ScaleGUITrad(this->uz_text_spacing));
1086 }
1087 
1093 void NWidgetResizeBase::SetMinimalSizeAbsolute(uint min_x, uint min_y)
1094 {
1095  this->absolute = true;
1096  this->min_x = std::max(this->min_x, min_x);
1097  this->min_y = std::max(this->min_y, min_y);
1098 }
1099 
1106 void NWidgetResizeBase::SetMinimalTextLines(uint8 min_lines, uint8 spacing, FontSize size)
1107 {
1108  this->uz_text_lines = min_lines;
1109  this->uz_text_spacing = spacing;
1110  this->uz_text_size = size;
1111  this->min_y = std::max(ScaleGUITrad(this->uz_min_y), this->uz_text_lines * GetCharacterHeight(this->uz_text_size) + ScaleGUITrad(this->uz_text_spacing));
1112 }
1113 
1119 void NWidgetResizeBase::SetFill(uint fill_x, uint fill_y)
1120 {
1121  this->fill_x = fill_x;
1122  this->fill_y = fill_y;
1123 }
1124 
1130 void NWidgetResizeBase::SetResize(uint resize_x, uint resize_y)
1131 {
1132  this->resize_x = resize_x;
1133  this->resize_y = resize_y;
1134 }
1135 
1136 void NWidgetResizeBase::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
1137 {
1138  this->StoreSizePosition(sizing, x, y, given_width, given_height);
1139 }
1140 
1150 NWidgetCore::NWidgetCore(WidgetType tp, Colours colour, uint fill_x, uint fill_y, uint32 widget_data, StringID tool_tip) : NWidgetResizeBase(tp, fill_x, fill_y)
1151 {
1152  this->colour = colour;
1153  this->index = -1;
1154  this->widget_data = widget_data;
1155  this->tool_tip = tool_tip;
1156  this->scrollbar_index = -1;
1157  this->text_colour = TC_BLACK;
1158  this->align = SA_CENTER;
1159 }
1160 
1165 void NWidgetCore::SetIndex(int index)
1166 {
1167  assert(index >= 0);
1168  this->index = index;
1169 }
1170 
1176 void NWidgetCore::SetDataTip(uint32 widget_data, StringID tool_tip)
1177 {
1178  this->widget_data = widget_data;
1179  this->tool_tip = tool_tip;
1180 }
1181 
1187 {
1188  this->text_colour = colour;
1189 }
1190 
1196 {
1197  this->tool_tip = tool_tip;
1198 }
1199 
1205 {
1206  this->align = align;
1207 }
1208 
1209 void NWidgetCore::FillNestedArray(NWidgetBase **array, uint length)
1210 {
1211  if (this->index >= 0 && (uint)(this->index) < length) array[this->index] = this;
1212 }
1213 
1215 {
1216  return (IsInsideBS(x, this->pos_x, this->current_x) && IsInsideBS(y, this->pos_y, this->current_y)) ? this : nullptr;
1217 }
1218 
1224 {
1225  this->head = nullptr;
1226  this->tail = nullptr;
1227 }
1228 
1229 NWidgetContainer::~NWidgetContainer()
1230 {
1231  while (this->head != nullptr) {
1232  NWidgetBase *wid = this->head->next;
1233  delete this->head;
1234  this->head = wid;
1235  }
1236  this->tail = nullptr;
1237 }
1238 
1240 {
1241  if (this->type == tp) return this;
1242  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1243  NWidgetBase *nwid = child_wid->GetWidgetOfType(tp);
1244  if (nwid != nullptr) return nwid;
1245  }
1246  return nullptr;
1247 }
1248 
1249 void NWidgetContainer::AdjustPaddingForZoom()
1250 {
1251  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1252  child_wid->AdjustPaddingForZoom();
1253  }
1254  NWidgetBase::AdjustPaddingForZoom();
1255 }
1256 
1262 {
1263  assert(wid->next == nullptr && wid->prev == nullptr);
1264 
1265  if (this->head == nullptr) {
1266  this->head = wid;
1267  this->tail = wid;
1268  } else {
1269  assert(this->tail != nullptr);
1270  assert(this->tail->next == nullptr);
1271 
1272  this->tail->next = wid;
1273  wid->prev = this->tail;
1274  this->tail = wid;
1275  }
1276 }
1277 
1279 {
1280  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1281  child_wid->FillNestedArray(array, length);
1282  }
1283 }
1284 
1289 {
1290  this->index = -1;
1291 }
1292 
1293 void NWidgetStacked::SetIndex(int index)
1294 {
1295  this->index = index;
1296 }
1297 
1298 void NWidgetStacked::AdjustPaddingForZoom()
1299 {
1300  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1301  child_wid->AdjustPaddingForZoom();
1302  }
1303  NWidgetContainer::AdjustPaddingForZoom();
1304 }
1305 
1307 {
1308  if (this->index >= 0 && init_array) { // Fill w->nested_array[]
1309  assert(w->nested_array_size > (uint)this->index);
1310  w->nested_array[this->index] = this;
1311  }
1312 
1313  /* Zero size plane selected */
1314  if (this->shown_plane >= SZSP_BEGIN) {
1315  Dimension size = {0, 0};
1316  Dimension padding = {0, 0};
1317  Dimension fill = {(this->shown_plane == SZSP_HORIZONTAL), (this->shown_plane == SZSP_VERTICAL)};
1318  Dimension resize = {(this->shown_plane == SZSP_HORIZONTAL), (this->shown_plane == SZSP_VERTICAL)};
1319  /* Here we're primarily interested in the value of resize */
1320  if (this->index >= 0) w->UpdateWidgetSize(this->index, &size, padding, &fill, &resize);
1321 
1322  this->smallest_x = size.width;
1323  this->smallest_y = size.height;
1324  this->fill_x = fill.width;
1325  this->fill_y = fill.height;
1326  this->resize_x = resize.width;
1327  this->resize_y = resize.height;
1328  return;
1329  }
1330 
1331  /* First sweep, recurse down and compute minimal size and filling. */
1332  this->smallest_x = 0;
1333  this->smallest_y = 0;
1334  this->fill_x = (this->head != nullptr) ? 1 : 0;
1335  this->fill_y = (this->head != nullptr) ? 1 : 0;
1336  this->resize_x = (this->head != nullptr) ? 1 : 0;
1337  this->resize_y = (this->head != nullptr) ? 1 : 0;
1338  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1339  child_wid->SetupSmallestSize(w, init_array);
1340 
1341  this->smallest_x = std::max(this->smallest_x, child_wid->smallest_x + child_wid->padding.Horizontal());
1342  this->smallest_y = std::max(this->smallest_y, child_wid->smallest_y + child_wid->padding.Vertical());
1343  this->fill_x = LeastCommonMultiple(this->fill_x, child_wid->fill_x);
1344  this->fill_y = LeastCommonMultiple(this->fill_y, child_wid->fill_y);
1345  this->resize_x = LeastCommonMultiple(this->resize_x, child_wid->resize_x);
1346  this->resize_y = LeastCommonMultiple(this->resize_y, child_wid->resize_y);
1347  }
1348 }
1349 
1350 void NWidgetStacked::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
1351 {
1352  assert(given_width >= this->smallest_x && given_height >= this->smallest_y);
1353  this->StoreSizePosition(sizing, x, y, given_width, given_height);
1354 
1355  if (this->shown_plane >= SZSP_BEGIN) return;
1356 
1357  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1358  uint hor_step = (sizing == ST_SMALLEST) ? 1 : child_wid->GetHorizontalStepSize(sizing);
1359  uint child_width = ComputeMaxSize(child_wid->smallest_x, given_width - child_wid->padding.Horizontal(), hor_step);
1360  uint child_pos_x = (rtl ? child_wid->padding.right : child_wid->padding.left);
1361 
1362  uint vert_step = (sizing == ST_SMALLEST) ? 1 : child_wid->GetVerticalStepSize(sizing);
1363  uint child_height = ComputeMaxSize(child_wid->smallest_y, given_height - child_wid->padding.Vertical(), vert_step);
1364  uint child_pos_y = child_wid->padding.top;
1365 
1366  child_wid->AssignSizePosition(sizing, x + child_pos_x, y + child_pos_y, child_width, child_height, rtl);
1367  }
1368 }
1369 
1371 {
1372  if (this->index >= 0 && (uint)(this->index) < length) array[this->index] = this;
1373  NWidgetContainer::FillNestedArray(array, length);
1374 }
1375 
1377 {
1378  if (this->shown_plane >= SZSP_BEGIN) return;
1379 
1380  int plane = 0;
1381  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; plane++, child_wid = child_wid->next) {
1382  if (plane == this->shown_plane) {
1383  child_wid->Draw(w);
1384  return;
1385  }
1386  }
1387 
1388  NOT_REACHED();
1389 }
1390 
1392 {
1393  if (this->shown_plane >= SZSP_BEGIN) return nullptr;
1394 
1395  if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return nullptr;
1396  int plane = 0;
1397  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; plane++, child_wid = child_wid->next) {
1398  if (plane == this->shown_plane) {
1399  return child_wid->GetWidgetFromPos(x, y);
1400  }
1401  }
1402  return nullptr;
1403 }
1404 
1410 {
1411  this->shown_plane = plane;
1412 }
1413 
1414 NWidgetPIPContainer::NWidgetPIPContainer(WidgetType tp, NWidContainerFlags flags) : NWidgetContainer(tp)
1415 {
1416  this->flags = flags;
1417 }
1418 
1419 void NWidgetPIPContainer::AdjustPaddingForZoom()
1420 {
1421  this->pip_pre = ScaleGUITrad(this->uz_pip_pre);
1422  this->pip_inter = ScaleGUITrad(this->uz_pip_inter);
1423  this->pip_post = ScaleGUITrad(this->uz_pip_post);
1424  NWidgetContainer::AdjustPaddingForZoom();
1425 }
1426 
1436 void NWidgetPIPContainer::SetPIP(uint8 pip_pre, uint8 pip_inter, uint8 pip_post)
1437 {
1438  this->uz_pip_pre = pip_pre;
1439  this->uz_pip_inter = pip_inter;
1440  this->uz_pip_post = pip_post;
1441 
1442  this->pip_pre = ScaleGUITrad(this->uz_pip_pre);
1443  this->pip_inter = ScaleGUITrad(this->uz_pip_inter);
1444  this->pip_post = ScaleGUITrad(this->uz_pip_post);
1445 }
1446 
1448 {
1449  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1450  child_wid->Draw(w);
1451  }
1452 }
1453 
1455 {
1456  if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return nullptr;
1457 
1458  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1459  NWidgetCore *nwid = child_wid->GetWidgetFromPos(x, y);
1460  if (nwid != nullptr) return nwid;
1461  }
1462  return nullptr;
1463 }
1464 
1467 {
1468 }
1469 
1471 {
1472  this->smallest_x = 0; // Sum of minimal size of all children.
1473  this->smallest_y = 0; // Biggest child.
1474  this->fill_x = 0; // smallest non-zero child widget fill step.
1475  this->fill_y = 1; // smallest common child fill step.
1476  this->resize_x = 0; // smallest non-zero child widget resize step.
1477  this->resize_y = 1; // smallest common child resize step.
1478 
1479  /* 1a. Forward call, collect biggest nested array index, and longest/widest child length. */
1480  uint longest = 0; // Longest child found.
1481  uint max_vert_fill = 0; // Biggest vertical fill step.
1482  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1483  child_wid->SetupSmallestSize(w, init_array);
1484  longest = std::max(longest, child_wid->smallest_x);
1485  max_vert_fill = std::max(max_vert_fill, child_wid->GetVerticalStepSize(ST_SMALLEST));
1486  this->smallest_y = std::max(this->smallest_y, child_wid->smallest_y + child_wid->padding.Vertical());
1487  }
1488  /* 1b. Make the container higher if needed to accommodate all children nicely. */
1489  [[maybe_unused]] uint max_smallest = this->smallest_y + 3 * max_vert_fill; // Upper limit to computing smallest height.
1490  uint cur_height = this->smallest_y;
1491  for (;;) {
1492  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1493  uint step_size = child_wid->GetVerticalStepSize(ST_SMALLEST);
1494  uint child_height = child_wid->smallest_y + child_wid->padding.Vertical();
1495  if (step_size > 1 && child_height < cur_height) { // Small step sizes or already fitting children are not interesting.
1496  uint remainder = (cur_height - child_height) % step_size;
1497  if (remainder > 0) { // Child did not fit entirely, widen the container.
1498  cur_height += step_size - remainder;
1499  assert(cur_height < max_smallest); // Safeguard against infinite height expansion.
1500  /* Remaining children will adapt to the new cur_height, thus speeding up the computation. */
1501  }
1502  }
1503  }
1504  if (this->smallest_y == cur_height) break;
1505  this->smallest_y = cur_height; // Smallest height got changed, try again.
1506  }
1507  /* 2. For containers that must maintain equal width, extend child minimal size. */
1508  if (this->flags & NC_EQUALSIZE) {
1509  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1510  if (child_wid->fill_x == 1) child_wid->smallest_x = longest;
1511  }
1512  }
1513  /* 3. Move PIP space to the children, compute smallest, fill, and resize values of the container. */
1514  if (this->head != nullptr) this->head->padding.left += this->pip_pre;
1515  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1516  if (child_wid->next != nullptr) {
1517  child_wid->padding.right += this->pip_inter;
1518  } else {
1519  child_wid->padding.right += this->pip_post;
1520  }
1521 
1522  this->smallest_x += child_wid->smallest_x + child_wid->padding.Horizontal();
1523  if (child_wid->fill_x > 0) {
1524  if (this->fill_x == 0 || this->fill_x > child_wid->fill_x) this->fill_x = child_wid->fill_x;
1525  }
1526  this->fill_y = LeastCommonMultiple(this->fill_y, child_wid->fill_y);
1527 
1528  if (child_wid->resize_x > 0) {
1529  if (this->resize_x == 0 || this->resize_x > child_wid->resize_x) this->resize_x = child_wid->resize_x;
1530  }
1531  this->resize_y = LeastCommonMultiple(this->resize_y, child_wid->resize_y);
1532  }
1533  /* We need to zero the PIP settings so we can re-initialize the tree. */
1534  this->pip_pre = this->pip_inter = this->pip_post = 0;
1535 }
1536 
1537 void NWidgetHorizontal::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
1538 {
1539  assert(given_width >= this->smallest_x && given_height >= this->smallest_y);
1540 
1541  /* Compute additional width given to us. */
1542  uint additional_length = given_width;
1543  if (sizing == ST_SMALLEST && (this->flags & NC_EQUALSIZE)) {
1544  /* For EQUALSIZE containers this does not sum to smallest_x during initialisation */
1545  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1546  additional_length -= child_wid->smallest_x + child_wid->padding.Horizontal();
1547  }
1548  } else {
1549  additional_length -= this->smallest_x;
1550  }
1551 
1552  this->StoreSizePosition(sizing, x, y, given_width, given_height);
1553 
1554  /* In principle, the additional horizontal space is distributed evenly over the available resizable children. Due to step sizes, this may not always be feasible.
1555  * To make resizing work as good as possible, first children with biggest step sizes are done. These may get less due to rounding down.
1556  * 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
1557  * of the child with the smallest non-zero stepsize.
1558  *
1559  * 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
1560  * size and position, and directly call child->AssignSizePosition() with the computed values.
1561  * 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
1562  * then we call the child.
1563  */
1564 
1565  /* First loop: Find biggest stepsize, find number of children that want a piece of the pie, handle vertical size for all children,
1566  * handle horizontal size for non-resizing children.
1567  */
1568  int num_changing_childs = 0; // Number of children that can change size.
1569  uint biggest_stepsize = 0;
1570  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1571  uint hor_step = child_wid->GetHorizontalStepSize(sizing);
1572  if (hor_step > 0) {
1573  if (!(flags & NC_BIGFIRST)) num_changing_childs++;
1574  biggest_stepsize = std::max(biggest_stepsize, hor_step);
1575  } else {
1576  child_wid->current_x = child_wid->smallest_x;
1577  }
1578 
1579  uint vert_step = (sizing == ST_SMALLEST) ? 1 : child_wid->GetVerticalStepSize(sizing);
1580  child_wid->current_y = ComputeMaxSize(child_wid->smallest_y, given_height - child_wid->padding.Vertical(), vert_step);
1581  }
1582 
1583  /* First.5 loop: count how many children are of the biggest step size. */
1584  if ((flags & NC_BIGFIRST) && biggest_stepsize > 0) {
1585  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1586  uint hor_step = child_wid->GetHorizontalStepSize(sizing);
1587  if (hor_step == biggest_stepsize) {
1588  num_changing_childs++;
1589  }
1590  }
1591  }
1592 
1593  /* Second loop: Allocate the additional horizontal space over the resizing children, starting with the biggest resize steps. */
1594  while (biggest_stepsize > 0) {
1595  uint next_biggest_stepsize = 0;
1596  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1597  uint hor_step = child_wid->GetHorizontalStepSize(sizing);
1598  if (hor_step > biggest_stepsize) continue; // Already done
1599  if (hor_step == biggest_stepsize) {
1600  uint increment = additional_length / num_changing_childs;
1601  num_changing_childs--;
1602  if (hor_step > 1) increment -= increment % hor_step;
1603  child_wid->current_x = child_wid->smallest_x + increment;
1604  additional_length -= increment;
1605  continue;
1606  }
1607  next_biggest_stepsize = std::max(next_biggest_stepsize, hor_step);
1608  }
1609  biggest_stepsize = next_biggest_stepsize;
1610 
1611  if (num_changing_childs == 0 && (flags & NC_BIGFIRST) && biggest_stepsize > 0) {
1612  /* Second.5 loop: count how many children are of the updated biggest step size. */
1613  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1614  uint hor_step = child_wid->GetHorizontalStepSize(sizing);
1615  if (hor_step == biggest_stepsize) {
1616  num_changing_childs++;
1617  }
1618  }
1619  }
1620  }
1621  assert(num_changing_childs == 0);
1622 
1623  /* Third loop: Compute position and call the child. */
1624  uint position = rtl ? this->current_x : 0; // Place to put next child relative to origin of the container.
1625  NWidgetBase *child_wid = this->head;
1626  while (child_wid != nullptr) {
1627  uint child_width = child_wid->current_x;
1628  uint child_x = x + (rtl ? position - child_width - child_wid->padding.left : position + child_wid->padding.left);
1629  uint child_y = y + child_wid->padding.top;
1630 
1631  child_wid->AssignSizePosition(sizing, child_x, child_y, child_width, child_wid->current_y, rtl);
1632  uint padded_child_width = child_width + child_wid->padding.Horizontal();
1633  position = rtl ? position - padded_child_width : position + padded_child_width;
1634 
1635  child_wid = child_wid->next;
1636  }
1637 }
1638 
1641 {
1642  this->type = NWID_HORIZONTAL_LTR;
1643 }
1644 
1645 void NWidgetHorizontalLTR::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
1646 {
1647  NWidgetHorizontal::AssignSizePosition(sizing, x, y, given_width, given_height, false);
1648 }
1649 
1652 {
1653 }
1654 
1656 {
1657  this->smallest_x = 0; // Biggest child.
1658  this->smallest_y = 0; // Sum of minimal size of all children.
1659  this->fill_x = 1; // smallest common child fill step.
1660  this->fill_y = 0; // smallest non-zero child widget fill step.
1661  this->resize_x = 1; // smallest common child resize step.
1662  this->resize_y = 0; // smallest non-zero child widget resize step.
1663 
1664  /* 1a. Forward call, collect biggest nested array index, and longest/widest child length. */
1665  uint highest = 0; // Highest child found.
1666  uint max_hor_fill = 0; // Biggest horizontal fill step.
1667  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1668  child_wid->SetupSmallestSize(w, init_array);
1669  highest = std::max(highest, child_wid->smallest_y);
1670  max_hor_fill = std::max(max_hor_fill, child_wid->GetHorizontalStepSize(ST_SMALLEST));
1671  this->smallest_x = std::max(this->smallest_x, child_wid->smallest_x + child_wid->padding.Horizontal());
1672  }
1673  /* 1b. Make the container wider if needed to accommodate all children nicely. */
1674  [[maybe_unused]] uint max_smallest = this->smallest_x + 3 * max_hor_fill; // Upper limit to computing smallest height.
1675  uint cur_width = this->smallest_x;
1676  for (;;) {
1677  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1678  uint step_size = child_wid->GetHorizontalStepSize(ST_SMALLEST);
1679  uint child_width = child_wid->smallest_x + child_wid->padding.Horizontal();
1680  if (step_size > 1 && child_width < cur_width) { // Small step sizes or already fitting children are not interesting.
1681  uint remainder = (cur_width - child_width) % step_size;
1682  if (remainder > 0) { // Child did not fit entirely, widen the container.
1683  cur_width += step_size - remainder;
1684  assert(cur_width < max_smallest); // Safeguard against infinite width expansion.
1685  /* Remaining children will adapt to the new cur_width, thus speeding up the computation. */
1686  }
1687  }
1688  }
1689  if (this->smallest_x == cur_width) break;
1690  this->smallest_x = cur_width; // Smallest width got changed, try again.
1691  }
1692  /* 2. For containers that must maintain equal width, extend children minimal size. */
1693  if (this->flags & NC_EQUALSIZE) {
1694  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1695  if (child_wid->fill_y == 1) child_wid->smallest_y = highest;
1696  }
1697  }
1698  /* 3. Move PIP space to the child, compute smallest, fill, and resize values of the container. */
1699  if (this->head != nullptr) this->head->padding.top += this->pip_pre;
1700  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1701  if (child_wid->next != nullptr) {
1702  child_wid->padding.bottom += this->pip_inter;
1703  } else {
1704  child_wid->padding.bottom += this->pip_post;
1705  }
1706 
1707  this->smallest_y += child_wid->smallest_y + child_wid->padding.Vertical();
1708  if (child_wid->fill_y > 0) {
1709  if (this->fill_y == 0 || this->fill_y > child_wid->fill_y) this->fill_y = child_wid->fill_y;
1710  }
1711  this->fill_x = LeastCommonMultiple(this->fill_x, child_wid->fill_x);
1712 
1713  if (child_wid->resize_y > 0) {
1714  if (this->resize_y == 0 || this->resize_y > child_wid->resize_y) this->resize_y = child_wid->resize_y;
1715  }
1716  this->resize_x = LeastCommonMultiple(this->resize_x, child_wid->resize_x);
1717  }
1718  /* We need to zero the PIP settings so we can re-initialize the tree. */
1719  this->pip_pre = this->pip_inter = this->pip_post = 0;
1720 }
1721 
1722 void NWidgetVertical::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
1723 {
1724  assert(given_width >= this->smallest_x && given_height >= this->smallest_y);
1725 
1726  /* Compute additional height given to us. */
1727  uint additional_length = given_height;
1728  if (sizing == ST_SMALLEST && (this->flags & NC_EQUALSIZE)) {
1729  /* For EQUALSIZE containers this does not sum to smallest_y during initialisation */
1730  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1731  additional_length -= child_wid->smallest_y + child_wid->padding.Vertical();
1732  }
1733  } else {
1734  additional_length -= this->smallest_y;
1735  }
1736 
1737  this->StoreSizePosition(sizing, x, y, given_width, given_height);
1738 
1739  /* Like the horizontal container, the vertical container also distributes additional height evenly, starting with the children with the biggest resize steps.
1740  * It also stores computed widths and heights into current_x and current_y values of the child.
1741  */
1742 
1743  /* 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. */
1744  int num_changing_childs = 0; // Number of children that can change size.
1745  uint biggest_stepsize = 0;
1746  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1747  uint vert_step = child_wid->GetVerticalStepSize(sizing);
1748  if (vert_step > 0) {
1749  if (!(flags & NC_BIGFIRST)) num_changing_childs++;
1750  biggest_stepsize = std::max(biggest_stepsize, vert_step);
1751  } else {
1752  child_wid->current_y = child_wid->smallest_y;
1753  }
1754 
1755  uint hor_step = (sizing == ST_SMALLEST) ? 1 : child_wid->GetHorizontalStepSize(sizing);
1756  child_wid->current_x = ComputeMaxSize(child_wid->smallest_x, given_width - child_wid->padding.Horizontal(), hor_step);
1757  }
1758 
1759  /* First.5 loop: count how many children are of the biggest step size. */
1760  if ((this->flags & NC_BIGFIRST) && biggest_stepsize > 0) {
1761  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1762  uint vert_step = child_wid->GetVerticalStepSize(sizing);
1763  if (vert_step == biggest_stepsize) {
1764  num_changing_childs++;
1765  }
1766  }
1767  }
1768 
1769  /* Second loop: Allocate the additional vertical space over the resizing children, starting with the biggest resize steps. */
1770  while (biggest_stepsize > 0) {
1771  uint next_biggest_stepsize = 0;
1772  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1773  uint vert_step = child_wid->GetVerticalStepSize(sizing);
1774  if (vert_step > biggest_stepsize) continue; // Already done
1775  if (vert_step == biggest_stepsize) {
1776  uint increment = additional_length / num_changing_childs;
1777  num_changing_childs--;
1778  if (vert_step > 1) increment -= increment % vert_step;
1779  child_wid->current_y = child_wid->smallest_y + increment;
1780  additional_length -= increment;
1781  continue;
1782  }
1783  next_biggest_stepsize = std::max(next_biggest_stepsize, vert_step);
1784  }
1785  biggest_stepsize = next_biggest_stepsize;
1786 
1787  if (num_changing_childs == 0 && (flags & NC_BIGFIRST) && biggest_stepsize > 0) {
1788  /* Second.5 loop: count how many children are of the updated biggest step size. */
1789  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1790  uint vert_step = child_wid->GetVerticalStepSize(sizing);
1791  if (vert_step == biggest_stepsize) {
1792  num_changing_childs++;
1793  }
1794  }
1795  }
1796  }
1797  assert(num_changing_childs == 0);
1798 
1799  /* Third loop: Compute position and call the child. */
1800  uint position = 0; // Place to put next child relative to origin of the container.
1801  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1802  uint child_x = x + (rtl ? child_wid->padding.right : child_wid->padding.left);
1803  uint child_height = child_wid->current_y;
1804 
1805  child_wid->AssignSizePosition(sizing, child_x, y + position + child_wid->padding.top, child_wid->current_x, child_height, rtl);
1806  position += child_height + child_wid->padding.Vertical();
1807  }
1808 }
1809 
1816 {
1817  this->SetMinimalSize(width, height);
1818  this->SetResize(0, 0);
1819 }
1820 
1821 void NWidgetSpacer::SetupSmallestSize(Window *w, bool init_array)
1822 {
1823  this->smallest_x = this->min_x;
1824  this->smallest_y = this->min_y;
1825 }
1826 
1828 {
1829 }
1830 
1832 {
1833  /* Spacer widget is never visible. */
1834 }
1835 
1836 void NWidgetSpacer::SetDirty(const Window *w) const
1837 {
1838  /* Spacer widget never need repainting. */
1839 }
1840 
1842 {
1843  return nullptr;
1844 }
1845 
1846 NWidgetMatrix::NWidgetMatrix() : NWidgetPIPContainer(NWID_MATRIX, NC_EQUALSIZE), index(-1), clicked(-1), count(-1)
1847 {
1848 }
1849 
1850 void NWidgetMatrix::SetIndex(int index)
1851 {
1852  this->index = index;
1853 }
1854 
1855 void NWidgetMatrix::SetColour(Colours colour)
1856 {
1857  this->colour = colour;
1858 }
1859 
1864 void NWidgetMatrix::SetClicked(int clicked)
1865 {
1866  this->clicked = clicked;
1867  if (this->clicked >= 0 && this->sb != nullptr && this->widgets_x != 0) {
1868  int vpos = (this->clicked / this->widgets_x) * this->widget_h; // Vertical position of the top.
1869  /* Need to scroll down -> Scroll to the bottom.
1870  * However, last entry has no 'this->pip_inter' underneath, and we must stay below this->sb->GetCount() */
1871  if (this->sb->GetPosition() < vpos) vpos += this->widget_h - this->pip_inter - 1;
1872  this->sb->ScrollTowards(vpos);
1873  }
1874 }
1875 
1882 {
1883  this->count = count;
1884 
1885  if (this->sb == nullptr || this->widgets_x == 0) return;
1886 
1887  /* We need to get the number of pixels the matrix is high/wide.
1888  * So, determine the number of rows/columns based on the number of
1889  * columns/rows (one is constant/unscrollable).
1890  * Then multiply that by the height of a widget, and add the pre
1891  * and post spacing "offsets". */
1892  count = CeilDiv(count, this->sb->IsVertical() ? this->widgets_x : this->widgets_y);
1893  count *= (this->sb->IsVertical() ? this->head->smallest_y : this->head->smallest_x) + this->pip_inter;
1894  if (count > 0) count -= this->pip_inter; // We counted an inter too much in the multiplication above
1895  count += this->pip_pre + this->pip_post;
1896  this->sb->SetCount(count);
1897  this->sb->SetCapacity(this->sb->IsVertical() ? this->current_y : this->current_x);
1898  this->sb->SetStepSize(this->sb->IsVertical() ? this->widget_h : this->widget_w);
1899 }
1900 
1906 {
1907  this->sb = sb;
1908 }
1909 
1910 void NWidgetMatrix::SetupSmallestSize(Window *w, bool init_array)
1911 {
1912  assert(this->head != nullptr);
1913  assert(this->head->next == nullptr);
1914 
1915  if (this->index >= 0 && init_array) { // Fill w->nested_array[]
1916  assert(w->nested_array_size > (uint)this->index);
1917  w->nested_array[this->index] = this;
1918  }
1919 
1920  /* Reset the widget number. */
1921  NWidgetCore *nw = dynamic_cast<NWidgetCore *>(this->head);
1922  assert(nw != nullptr);
1923  SB(nw->index, 16, 16, 0);
1924  this->head->SetupSmallestSize(w, init_array);
1925 
1926  Dimension padding = { (uint)this->pip_pre + this->pip_post, (uint)this->pip_pre + this->pip_post};
1927  Dimension size = {this->head->smallest_x + padding.width, this->head->smallest_y + padding.height};
1928  Dimension fill = {0, 0};
1929  Dimension resize = {this->pip_inter + this->head->smallest_x, this->pip_inter + this->head->smallest_y};
1930 
1931  if (this->index >= 0) w->UpdateWidgetSize(this->index, &size, padding, &fill, &resize);
1932 
1933  this->smallest_x = size.width;
1934  this->smallest_y = size.height;
1935  this->fill_x = fill.width;
1936  this->fill_y = fill.height;
1937  this->resize_x = resize.width;
1938  this->resize_y = resize.height;
1939 }
1940 
1941 void NWidgetMatrix::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
1942 {
1943  assert(given_width >= this->smallest_x && given_height >= this->smallest_y);
1944 
1945  this->pos_x = x;
1946  this->pos_y = y;
1947  this->current_x = given_width;
1948  this->current_y = given_height;
1949 
1950  /* Determine the size of the widgets, and the number of visible widgets on each of the axis. */
1951  this->widget_w = this->head->smallest_x + this->pip_inter;
1952  this->widget_h = this->head->smallest_y + this->pip_inter;
1953 
1954  /* Account for the pip_inter is between widgets, so we need to account for that when
1955  * the division assumes pip_inter is used for all widgets. */
1956  this->widgets_x = CeilDiv(this->current_x - this->pip_pre - this->pip_post + this->pip_inter, this->widget_w);
1957  this->widgets_y = CeilDiv(this->current_y - this->pip_pre - this->pip_post + this->pip_inter, this->widget_h);
1958 
1959  /* When resizing, update the scrollbar's count. E.g. with a vertical
1960  * scrollbar becoming wider or narrower means the amount of rows in
1961  * the scrollbar becomes respectively smaller or higher. */
1962  this->SetCount(this->count);
1963 }
1964 
1966 {
1967  if (this->index >= 0 && (uint)(this->index) < length) array[this->index] = this;
1968  NWidgetContainer::FillNestedArray(array, length);
1969 }
1970 
1972 {
1973  /* Falls outside of the matrix widget. */
1974  if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return nullptr;
1975 
1976  int start_x, start_y, base_offs_x, base_offs_y;
1977  this->GetScrollOffsets(start_x, start_y, base_offs_x, base_offs_y);
1978 
1979  bool rtl = _current_text_dir == TD_RTL;
1980 
1981  int widget_col = (rtl ?
1982  -x + (int)this->pip_post + (int)this->pos_x + base_offs_x + (int)this->widget_w - 1 - (int)this->pip_inter :
1983  x - (int)this->pip_pre - (int)this->pos_x - base_offs_x
1984  ) / this->widget_w;
1985 
1986  int widget_row = (y - base_offs_y - (int)this->pip_pre - (int)this->pos_y) / this->widget_h;
1987 
1988  int sub_wid = (widget_row + start_y) * this->widgets_x + start_x + widget_col;
1989  if (sub_wid >= this->count) return nullptr;
1990 
1991  NWidgetCore *child = dynamic_cast<NWidgetCore *>(this->head);
1992  assert(child != nullptr);
1994  this->pos_x + (rtl ? this->pip_post - widget_col * this->widget_w : this->pip_pre + widget_col * this->widget_w) + base_offs_x,
1995  this->pos_y + this->pip_pre + widget_row * this->widget_h + base_offs_y,
1996  child->smallest_x, child->smallest_y, rtl);
1997 
1998  SB(child->index, 16, 16, sub_wid);
1999 
2000  return child->GetWidgetFromPos(x, y);
2001 }
2002 
2003 /* virtual */ void NWidgetMatrix::Draw(const Window *w)
2004 {
2005  /* Fill the background. */
2006  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]);
2007 
2008  /* Set up a clipping area for the previews. */
2009  bool rtl = _current_text_dir == TD_RTL;
2010  DrawPixelInfo tmp_dpi;
2011  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;
2012  DrawPixelInfo *old_dpi = _cur_dpi;
2013  _cur_dpi = &tmp_dpi;
2014 
2015  /* Get the appropriate offsets so we can draw the right widgets. */
2016  NWidgetCore *child = dynamic_cast<NWidgetCore *>(this->head);
2017  assert(child != nullptr);
2018  int start_x, start_y, base_offs_x, base_offs_y;
2019  this->GetScrollOffsets(start_x, start_y, base_offs_x, base_offs_y);
2020 
2021  int offs_y = base_offs_y;
2022  for (int y = start_y; y < start_y + this->widgets_y + 1; y++, offs_y += this->widget_h) {
2023  /* Are we within bounds? */
2024  if (offs_y + child->smallest_y <= 0) continue;
2025  if (offs_y >= (int)this->current_y) break;
2026 
2027  /* We've passed our amount of widgets. */
2028  if (y * this->widgets_x >= this->count) break;
2029 
2030  int offs_x = base_offs_x;
2031  for (int x = start_x; x < start_x + this->widgets_x + 1; x++, offs_x += rtl ? -this->widget_w : this->widget_w) {
2032  /* Are we within bounds? */
2033  if (offs_x + child->smallest_x <= 0) continue;
2034  if (offs_x >= (int)this->current_x) continue;
2035 
2036  /* Do we have this many widgets? */
2037  int sub_wid = y * this->widgets_x + x;
2038  if (sub_wid >= this->count) break;
2039 
2040  child->AssignSizePosition(ST_RESIZE, offs_x, offs_y, child->smallest_x, child->smallest_y, rtl);
2041  child->SetLowered(this->clicked == sub_wid);
2042  SB(child->index, 16, 16, sub_wid);
2043  child->Draw(w);
2044  }
2045  }
2046 
2047  /* Restore the clipping area. */
2048  _cur_dpi = old_dpi;
2049 }
2050 
2058 void NWidgetMatrix::GetScrollOffsets(int &start_x, int &start_y, int &base_offs_x, int &base_offs_y)
2059 {
2060  base_offs_x = _current_text_dir == TD_RTL ? this->widget_w * (this->widgets_x - 1) : 0;
2061  base_offs_y = 0;
2062  start_x = 0;
2063  start_y = 0;
2064  if (this->sb != nullptr) {
2065  if (this->sb->IsVertical()) {
2066  start_y = this->sb->GetPosition() / this->widget_h;
2067  base_offs_y += -this->sb->GetPosition() + start_y * this->widget_h;
2068  } else {
2069  start_x = this->sb->GetPosition() / this->widget_w;
2070  int sub_x = this->sb->GetPosition() - start_x * this->widget_w;
2071  if (_current_text_dir == TD_RTL) {
2072  base_offs_x += sub_x;
2073  } else {
2074  base_offs_x -= sub_x;
2075  }
2076  }
2077  }
2078 }
2079 
2089 NWidgetBackground::NWidgetBackground(WidgetType tp, Colours colour, int index, NWidgetPIPContainer *child) : NWidgetCore(tp, colour, 1, 1, 0x0, STR_NULL)
2090 {
2091  assert(tp == WWT_PANEL || tp == WWT_INSET || tp == WWT_FRAME);
2092  if (index >= 0) this->SetIndex(index);
2093  this->child = child;
2094  this->SetAlignment(SA_TOP | SA_LEFT);
2095 }
2096 
2097 NWidgetBackground::~NWidgetBackground()
2098 {
2099  if (this->child != nullptr) delete this->child;
2100 }
2101 
2110 {
2111  if (this->child == nullptr) {
2112  this->child = new NWidgetVertical();
2113  }
2114  this->child->Add(nwid);
2115 }
2116 
2127 void NWidgetBackground::SetPIP(uint8 pip_pre, uint8 pip_inter, uint8 pip_post)
2128 {
2129  if (this->child == nullptr) {
2130  this->child = new NWidgetVertical();
2131  }
2132  this->child->SetPIP(pip_pre, pip_inter, pip_post);
2133 }
2134 
2135 void NWidgetBackground::AdjustPaddingForZoom()
2136 {
2137  if (child != nullptr) child->AdjustPaddingForZoom();
2138  NWidgetCore::AdjustPaddingForZoom();
2139 }
2140 
2142 {
2143  if (init_array && this->index >= 0) {
2144  assert(w->nested_array_size > (uint)this->index);
2145  w->nested_array[this->index] = this;
2146  }
2147  if (this->child != nullptr) {
2148  this->child->SetupSmallestSize(w, init_array);
2149 
2150  this->smallest_x = this->child->smallest_x;
2151  this->smallest_y = this->child->smallest_y;
2152  this->fill_x = this->child->fill_x;
2153  this->fill_y = this->child->fill_y;
2154  this->resize_x = this->child->resize_x;
2155  this->resize_y = this->child->resize_y;
2156 
2157  /* Don't apply automatic padding if there is no child widget. */
2158  if (w == nullptr) return;
2159 
2160  if (this->type == WWT_FRAME) {
2161  /* Account for the size of the frame's text if that exists */
2162  this->child->padding = WidgetDimensions::scaled.frametext;
2163  this->child->padding.top = std::max<uint8>(WidgetDimensions::scaled.frametext.top, this->widget_data != STR_NULL ? FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.frametext.top / 2 : 0);
2164 
2165  this->smallest_x += this->child->padding.Horizontal();
2166  this->smallest_y += this->child->padding.Vertical();
2167 
2168  if (this->index >= 0) w->SetStringParameters(this->index);
2169  this->smallest_x = std::max(this->smallest_x, GetStringBoundingBox(this->widget_data).width + WidgetDimensions::scaled.frametext.Horizontal());
2170  } else if (this->type == WWT_INSET) {
2171  /* Apply automatic padding for bevel thickness. */
2172  this->child->padding = WidgetDimensions::scaled.bevel;
2173 
2174  this->smallest_x += this->child->padding.Horizontal();
2175  this->smallest_y += this->child->padding.Vertical();
2176  }
2177  } else {
2178  Dimension d = {this->min_x, this->min_y};
2179  Dimension fill = {this->fill_x, this->fill_y};
2180  Dimension resize = {this->resize_x, this->resize_y};
2181  if (w != nullptr) { // A non-nullptr window pointer acts as switch to turn dynamic widget size on.
2182  if (this->type == WWT_FRAME || this->type == WWT_INSET) {
2183  if (this->index >= 0) w->SetStringParameters(this->index);
2184  Dimension background = GetStringBoundingBox(this->widget_data);
2185  background.width += (this->type == WWT_FRAME) ? (WidgetDimensions::scaled.frametext.Horizontal()) : (WidgetDimensions::scaled.inset.Horizontal());
2186  d = maxdim(d, background);
2187  }
2188  if (this->index >= 0) {
2190  switch (this->type) {
2191  default: NOT_REACHED();
2195  }
2196  w->UpdateWidgetSize(this->index, &d, padding, &fill, &resize);
2197  }
2198  }
2199  this->smallest_x = d.width;
2200  this->smallest_y = d.height;
2201  this->fill_x = fill.width;
2202  this->fill_y = fill.height;
2203  this->resize_x = resize.width;
2204  this->resize_y = resize.height;
2205  }
2206 }
2207 
2208 void NWidgetBackground::AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
2209 {
2210  this->StoreSizePosition(sizing, x, y, given_width, given_height);
2211 
2212  if (this->child != nullptr) {
2213  uint x_offset = (rtl ? this->child->padding.right : this->child->padding.left);
2214  uint width = given_width - this->child->padding.Horizontal();
2215  uint height = given_height - this->child->padding.Vertical();
2216  this->child->AssignSizePosition(sizing, x + x_offset, y + this->child->padding.top, width, height, rtl);
2217  }
2218 }
2219 
2221 {
2222  if (this->index >= 0 && (uint)(this->index) < length) array[this->index] = this;
2223  if (this->child != nullptr) this->child->FillNestedArray(array, length);
2224 }
2225 
2227 {
2228  if (this->current_x == 0 || this->current_y == 0) return;
2229 
2230  Rect r = this->GetCurrentRect();
2231 
2232  const DrawPixelInfo *dpi = _cur_dpi;
2233  if (dpi->left > r.right || dpi->left + dpi->width <= r.left || dpi->top > r.bottom || dpi->top + dpi->height <= r.top) return;
2234 
2235  switch (this->type) {
2236  case WWT_PANEL:
2237  assert(this->widget_data == 0);
2238  DrawFrameRect(r.left, r.top, r.right, r.bottom, this->colour, this->IsLowered() ? FR_LOWERED : FR_NONE);
2239  break;
2240 
2241  case WWT_FRAME:
2242  if (this->index >= 0) w->SetStringParameters(this->index);
2243  DrawFrame(r, this->colour, this->text_colour, this->widget_data, this->align);
2244  break;
2245 
2246  case WWT_INSET:
2247  if (this->index >= 0) w->SetStringParameters(this->index);
2248  DrawInset(r, this->colour, this->text_colour, this->widget_data, this->align);
2249  break;
2250 
2251  default:
2252  NOT_REACHED();
2253  }
2254 
2255  if (this->index >= 0) w->DrawWidget(r, this->index);
2256  if (this->child != nullptr) this->child->Draw(w);
2257 
2258  if (this->IsDisabled()) {
2260  }
2261 }
2262 
2264 {
2265  NWidgetCore *nwid = nullptr;
2266  if (IsInsideBS(x, this->pos_x, this->current_x) && IsInsideBS(y, this->pos_y, this->current_y)) {
2267  if (this->child != nullptr) nwid = this->child->GetWidgetFromPos(x, y);
2268  if (nwid == nullptr) nwid = this;
2269  }
2270  return nwid;
2271 }
2272 
2274 {
2275  NWidgetBase *nwid = nullptr;
2276  if (this->child != nullptr) nwid = this->child->GetWidgetOfType(tp);
2277  if (nwid == nullptr && this->type == tp) nwid = this;
2278  return nwid;
2279 }
2280 
2281 NWidgetViewport::NWidgetViewport(int index) : NWidgetCore(NWID_VIEWPORT, INVALID_COLOUR, 1, 1, 0x0, STR_NULL)
2282 {
2283  this->SetIndex(index);
2284 }
2285 
2287 {
2288  if (init_array && this->index >= 0) {
2289  assert(w->nested_array_size > (uint)this->index);
2290  w->nested_array[this->index] = this;
2291  }
2292  this->smallest_x = this->min_x;
2293  this->smallest_y = this->min_y;
2294 }
2295 
2297 {
2298  if (this->current_x == 0 || this->current_y == 0) return;
2299 
2300  if (this->disp_flags & ND_NO_TRANSPARENCY) {
2302  _transparency_opt &= (1 << TO_SIGNS) | (1 << TO_LOADING); // Disable all transparency, except textual stuff
2303  w->DrawViewport();
2304  _transparency_opt = to_backup;
2305  } else {
2306  w->DrawViewport();
2307  }
2308 
2309  /* Optionally shade the viewport. */
2310  if (this->disp_flags & (ND_SHADE_GREY | ND_SHADE_DIMMED)) {
2311  GfxFillRect(this->pos_x, this->pos_y, this->pos_x + this->current_x - 1, this->pos_y + this->current_y - 1,
2313  }
2314 }
2315 
2322 void NWidgetViewport::InitializeViewport(Window *w, uint32 follow_flags, ZoomLevel zoom)
2323 {
2324  InitializeWindowViewport(w, this->pos_x, this->pos_y, this->current_x, this->current_y, follow_flags, zoom);
2325 }
2326 
2332 {
2333  Viewport *vp = w->viewport;
2334  if (vp != nullptr) {
2335  vp->left = w->left + this->pos_x;
2336  vp->top = w->top + this->pos_y;
2337  vp->width = this->current_x;
2338  vp->height = this->current_y;
2339 
2340  vp->virtual_width = ScaleByZoom(vp->width, vp->zoom);
2341  vp->virtual_height = ScaleByZoom(vp->height, vp->zoom);
2342  }
2343 }
2344 
2353 int Scrollbar::GetScrolledRowFromWidget(int clickpos, const Window * const w, int widget, int padding) const
2354 {
2355  uint pos = w->GetRowFromWidget(clickpos, widget, padding, -1);
2356  if (pos != INT_MAX) pos += this->GetPosition();
2357  return (pos >= this->GetCount()) ? INT_MAX : pos;
2358 }
2359 
2374 EventState Scrollbar::UpdateListPositionOnKeyPress(int &list_position, uint16 keycode) const
2375 {
2376  int new_pos = list_position;
2377  switch (keycode) {
2378  case WKC_UP:
2379  /* scroll up by one */
2380  new_pos--;
2381  break;
2382 
2383  case WKC_DOWN:
2384  /* scroll down by one */
2385  new_pos++;
2386  break;
2387 
2388  case WKC_PAGEUP:
2389  /* scroll up a page */
2390  new_pos -= this->GetCapacity();
2391  break;
2392 
2393  case WKC_PAGEDOWN:
2394  /* scroll down a page */
2395  new_pos += this->GetCapacity();
2396  break;
2397 
2398  case WKC_HOME:
2399  /* jump to beginning */
2400  new_pos = 0;
2401  break;
2402 
2403  case WKC_END:
2404  /* jump to end */
2405  new_pos = this->GetCount() - 1;
2406  break;
2407 
2408  default:
2409  return ES_NOT_HANDLED;
2410  }
2411 
2412  /* If there are no elements, there is nothing to scroll/update. */
2413  if (this->GetCount() != 0) {
2414  list_position = Clamp(new_pos, 0, this->GetCount() - 1);
2415  }
2416  return ES_HANDLED;
2417 }
2418 
2419 
2427 void Scrollbar::SetCapacityFromWidget(Window *w, int widget, int padding)
2428 {
2429  NWidgetBase *nwid = w->GetWidget<NWidgetBase>(widget);
2430  if (this->IsVertical()) {
2431  this->SetCapacity(((int)nwid->current_y - padding) / (int)nwid->resize_y);
2432  } else {
2433  this->SetCapacity(((int)nwid->current_x - padding) / (int)nwid->resize_x);
2434  }
2435 }
2436 
2443 NWidgetScrollbar::NWidgetScrollbar(WidgetType tp, Colours colour, int index) : NWidgetCore(tp, colour, 1, 1, 0x0, STR_NULL), Scrollbar(tp != NWID_HSCROLLBAR)
2444 {
2445  assert(tp == NWID_HSCROLLBAR || tp == NWID_VSCROLLBAR);
2446  this->SetIndex(index);
2447 
2448  switch (this->type) {
2449  case NWID_HSCROLLBAR:
2450  this->SetResize(1, 0);
2451  this->SetFill(1, 0);
2452  this->SetDataTip(0x0, STR_TOOLTIP_HSCROLL_BAR_SCROLLS_LIST);
2453  break;
2454 
2455  case NWID_VSCROLLBAR:
2456  this->SetResize(0, 1);
2457  this->SetFill(0, 1);
2458  this->SetDataTip(0x0, STR_TOOLTIP_VSCROLL_BAR_SCROLLS_LIST);
2459  break;
2460 
2461  default: NOT_REACHED();
2462  }
2463 }
2464 
2466 {
2467  if (init_array && this->index >= 0) {
2468  assert(w->nested_array_size > (uint)this->index);
2469  w->nested_array[this->index] = this;
2470  }
2471  this->min_x = 0;
2472  this->min_y = 0;
2473 
2474  switch (this->type) {
2475  case NWID_HSCROLLBAR:
2476  this->SetMinimalSizeAbsolute(NWidgetScrollbar::GetHorizontalDimension().width * 3, NWidgetScrollbar::GetHorizontalDimension().height);
2477  break;
2478 
2479  case NWID_VSCROLLBAR:
2480  this->SetMinimalSizeAbsolute(NWidgetScrollbar::GetVerticalDimension().width, NWidgetScrollbar::GetVerticalDimension().height * 3);
2481  break;
2482 
2483  default: NOT_REACHED();
2484  }
2485 
2486  this->smallest_x = this->min_x;
2487  this->smallest_y = this->min_y;
2488 }
2489 
2491 {
2492  if (this->current_x == 0 || this->current_y == 0) return;
2493 
2494  Rect r = this->GetCurrentRect();
2495 
2496  const DrawPixelInfo *dpi = _cur_dpi;
2497  if (dpi->left > r.right || dpi->left + dpi->width <= r.left || dpi->top > r.bottom || dpi->top + dpi->height <= r.top) return;
2498 
2499  bool up_lowered = HasBit(this->disp_flags, NDB_SCROLLBAR_UP);
2500  bool down_lowered = HasBit(this->disp_flags, NDB_SCROLLBAR_DOWN);
2501  bool middle_lowered = !(this->disp_flags & ND_SCROLLBAR_BTN) && w->mouse_capture_widget == this->index;
2502 
2503  if (this->type == NWID_HSCROLLBAR) {
2504  DrawHorizontalScrollbar(r, this->colour, up_lowered, middle_lowered, down_lowered, this);
2505  } else {
2506  DrawVerticalScrollbar(r, this->colour, up_lowered, middle_lowered, down_lowered, this);
2507  }
2508 
2509  if (this->IsDisabled()) {
2511  }
2512 }
2513 
2514 /* static */ void NWidgetScrollbar::InvalidateDimensionCache()
2515 {
2516  vertical_dimension.width = vertical_dimension.height = 0;
2517  horizontal_dimension.width = horizontal_dimension.height = 0;
2518 }
2519 
2520 /* static */ Dimension NWidgetScrollbar::GetVerticalDimension()
2521 {
2522  if (vertical_dimension.width == 0) {
2523  vertical_dimension = maxdim(GetScaledSpriteSize(SPR_ARROW_UP), GetScaledSpriteSize(SPR_ARROW_DOWN));
2525  vertical_dimension.height += WidgetDimensions::scaled.vscrollbar.Vertical();
2526  }
2527  return vertical_dimension;
2528 }
2529 
2530 /* static */ Dimension NWidgetScrollbar::GetHorizontalDimension()
2531 {
2532  if (horizontal_dimension.width == 0) {
2533  horizontal_dimension = maxdim(GetScaledSpriteSize(SPR_ARROW_LEFT), GetScaledSpriteSize(SPR_ARROW_RIGHT));
2536  }
2537  return horizontal_dimension;
2538 }
2539 
2542 
2545 {
2546  shadebox_dimension.width = shadebox_dimension.height = 0;
2547  debugbox_dimension.width = debugbox_dimension.height = 0;
2548  defsizebox_dimension.width = defsizebox_dimension.height = 0;
2549  stickybox_dimension.width = stickybox_dimension.height = 0;
2550  resizebox_dimension.width = resizebox_dimension.height = 0;
2551  closebox_dimension.width = closebox_dimension.height = 0;
2552  dropdown_dimension.width = dropdown_dimension.height = 0;
2553 }
2554 
2562 
2571 NWidgetLeaf::NWidgetLeaf(WidgetType tp, Colours colour, int index, uint32 data, StringID tip) : NWidgetCore(tp, colour, 1, 1, data, tip)
2572 {
2573  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);
2574  if (index >= 0) this->SetIndex(index);
2575  this->min_x = 0;
2576  this->min_y = 0;
2577  this->SetResize(0, 0);
2578 
2579  switch (tp) {
2580  case WWT_EMPTY:
2581  break;
2582 
2583  case WWT_TEXT:
2584  this->SetFill(0, 0);
2586  break;
2587 
2588  case WWT_PUSHBTN:
2589  case WWT_IMGBTN:
2590  case WWT_PUSHIMGBTN:
2591  case WWT_IMGBTN_2:
2592  case WWT_TEXTBTN:
2593  case WWT_PUSHTXTBTN:
2594  case WWT_TEXTBTN_2:
2595  case WWT_LABEL:
2596  case WWT_MATRIX:
2597  case NWID_BUTTON_DROPDOWN:
2598  case NWID_PUSHBUTTON_DROPDOWN:
2599  case WWT_ARROWBTN:
2600  case WWT_PUSHARROWBTN:
2601  this->SetFill(0, 0);
2602  break;
2603 
2604  case WWT_EDITBOX:
2605  this->SetFill(0, 0);
2606  break;
2607 
2608  case WWT_CAPTION:
2609  this->SetFill(1, 0);
2610  this->SetResize(1, 0);
2612  this->SetMinimalTextLines(1, WidgetDimensions::unscaled.framerect.Vertical(), FS_NORMAL);
2613  this->SetDataTip(data, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS);
2614  break;
2615 
2616  case WWT_STICKYBOX:
2617  this->SetFill(0, 0);
2619  this->SetDataTip(STR_NULL, STR_TOOLTIP_STICKY);
2620  break;
2621 
2622  case WWT_SHADEBOX:
2623  this->SetFill(0, 0);
2625  this->SetDataTip(STR_NULL, STR_TOOLTIP_SHADE);
2626  break;
2627 
2628  case WWT_DEBUGBOX:
2629  this->SetFill(0, 0);
2631  this->SetDataTip(STR_NULL, STR_TOOLTIP_DEBUG);
2632  break;
2633 
2634  case WWT_DEFSIZEBOX:
2635  this->SetFill(0, 0);
2637  this->SetDataTip(STR_NULL, STR_TOOLTIP_DEFSIZE);
2638  break;
2639 
2640  case WWT_RESIZEBOX:
2641  this->SetFill(0, 0);
2643  this->SetDataTip(STR_NULL, STR_TOOLTIP_RESIZE);
2644  break;
2645 
2646  case WWT_CLOSEBOX:
2647  this->SetFill(0, 0);
2649  this->SetDataTip(STR_NULL, STR_TOOLTIP_CLOSE_WINDOW);
2650  break;
2651 
2652  case WWT_DROPDOWN:
2653  this->SetFill(0, 0);
2655  this->SetAlignment(SA_TOP | SA_LEFT);
2656  break;
2657 
2658  default:
2659  NOT_REACHED();
2660  }
2661 }
2662 
2663 void NWidgetLeaf::SetupSmallestSize(Window *w, bool init_array)
2664 {
2665  if (this->index >= 0 && init_array) { // Fill w->nested_array[]
2666  assert(w->nested_array_size > (uint)this->index);
2667  w->nested_array[this->index] = this;
2668  }
2669 
2670  Dimension padding = {0, 0};
2671  Dimension size = {this->min_x, this->min_y};
2672  Dimension fill = {this->fill_x, this->fill_y};
2673  Dimension resize = {this->resize_x, this->resize_y};
2674  switch (this->type) {
2675  case WWT_EMPTY: {
2676  break;
2677  }
2678  case WWT_MATRIX: {
2680  break;
2681  }
2682  case WWT_SHADEBOX: {
2684  if (NWidgetLeaf::shadebox_dimension.width == 0) {
2685  NWidgetLeaf::shadebox_dimension = maxdim(GetScaledSpriteSize(SPR_WINDOW_SHADE), GetScaledSpriteSize(SPR_WINDOW_UNSHADE));
2687  NWidgetLeaf::shadebox_dimension.height += padding.height;
2688  }
2690  break;
2691  }
2692  case WWT_DEBUGBOX:
2695  if (NWidgetLeaf::debugbox_dimension.width == 0) {
2698  NWidgetLeaf::debugbox_dimension.height += padding.height;
2699  }
2701  } else {
2702  /* If the setting is disabled we don't want to see it! */
2703  size.width = 0;
2704  fill.width = 0;
2705  resize.width = 0;
2706  }
2707  break;
2708 
2709  case WWT_STICKYBOX: {
2711  if (NWidgetLeaf::stickybox_dimension.width == 0) {
2714  NWidgetLeaf::stickybox_dimension.height += padding.height;
2715  }
2717  break;
2718  }
2719 
2720  case WWT_DEFSIZEBOX: {
2722  if (NWidgetLeaf::defsizebox_dimension.width == 0) {
2725  NWidgetLeaf::defsizebox_dimension.height += padding.height;
2726  }
2728  break;
2729  }
2730 
2731  case WWT_RESIZEBOX: {
2733  if (NWidgetLeaf::resizebox_dimension.width == 0) {
2734  NWidgetLeaf::resizebox_dimension = maxdim(GetScaledSpriteSize(SPR_WINDOW_RESIZE_LEFT), GetScaledSpriteSize(SPR_WINDOW_RESIZE_RIGHT));
2736  NWidgetLeaf::resizebox_dimension.height += padding.height;
2737  }
2739  break;
2740  }
2741  case WWT_EDITBOX: {
2742  Dimension sprite_size = GetScaledSpriteSize(_current_text_dir == TD_RTL ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT);
2743  size.width = std::max(size.width, ScaleGUITrad(30) + sprite_size.width);
2744  size.height = std::max(sprite_size.height, GetStringBoundingBox("_").height + WidgetDimensions::scaled.framerect.Vertical());
2745  }
2746  FALLTHROUGH;
2747  case WWT_PUSHBTN: {
2749  break;
2750  }
2751  case WWT_IMGBTN:
2752  case WWT_IMGBTN_2:
2753  case WWT_PUSHIMGBTN: {
2756  if (this->type == WWT_IMGBTN_2) d2 = maxdim(d2, GetScaledSpriteSize(this->widget_data + 1));
2757  d2.width += padding.width;
2758  d2.height += padding.height;
2759  size = maxdim(size, d2);
2760  break;
2761  }
2762  case WWT_ARROWBTN:
2763  case WWT_PUSHARROWBTN: {
2765  Dimension d2 = maxdim(GetScaledSpriteSize(SPR_ARROW_LEFT), GetScaledSpriteSize(SPR_ARROW_RIGHT));
2766  d2.width += padding.width;
2767  d2.height += padding.height;
2768  size = maxdim(size, d2);
2769  break;
2770  }
2771 
2772  case WWT_CLOSEBOX: {
2774  if (NWidgetLeaf::closebox_dimension.width == 0) {
2777  NWidgetLeaf::closebox_dimension.height += padding.height;
2778  }
2780  break;
2781  }
2782  case WWT_TEXTBTN:
2783  case WWT_PUSHTXTBTN:
2784  case WWT_TEXTBTN_2: {
2786  if (this->index >= 0) w->SetStringParameters(this->index);
2788  d2.width += padding.width;
2789  d2.height += padding.height;
2790  size = maxdim(size, d2);
2791  break;
2792  }
2793  case WWT_LABEL:
2794  case WWT_TEXT: {
2795  if (this->index >= 0) w->SetStringParameters(this->index);
2796  size = maxdim(size, GetStringBoundingBox(this->widget_data));
2797  break;
2798  }
2799  case WWT_CAPTION: {
2801  if (this->index >= 0) w->SetStringParameters(this->index);
2803  d2.width += padding.width;
2804  d2.height += padding.height;
2805  size = maxdim(size, d2);
2806  break;
2807  }
2808  case WWT_DROPDOWN:
2809  case NWID_BUTTON_DROPDOWN:
2810  case NWID_PUSHBUTTON_DROPDOWN: {
2811  if (NWidgetLeaf::dropdown_dimension.width == 0) {
2815  }
2817  if (this->index >= 0) w->SetStringParameters(this->index);
2819  d2.width += padding.width;
2820  d2.height = std::max(d2.height + padding.height, NWidgetLeaf::dropdown_dimension.height);
2821  size = maxdim(size, d2);
2822  break;
2823  }
2824  default:
2825  NOT_REACHED();
2826  }
2827 
2828  if (this->index >= 0) w->UpdateWidgetSize(this->index, &size, padding, &fill, &resize);
2829 
2830  this->smallest_x = size.width;
2831  this->smallest_y = size.height;
2832  this->fill_x = fill.width;
2833  this->fill_y = fill.height;
2834  this->resize_x = resize.width;
2835  this->resize_y = resize.height;
2836 }
2837 
2839 {
2840  if (this->current_x == 0 || this->current_y == 0) return;
2841 
2842  /* Setup a clipping rectangle... for WWT_EMPTY or WWT_TEXT, an extra scaled pixel is allowed vertically in case text shadow encroaches. */
2843  int extra_y = (this->type == WWT_EMPTY || this->type == WWT_TEXT) ? ScaleGUITrad(1) : 0;
2844  DrawPixelInfo new_dpi;
2845  if (!FillDrawPixelInfo(&new_dpi, this->pos_x, this->pos_y, this->current_x, this->current_y + extra_y)) return;
2846  /* ...but keep coordinates relative to the window. */
2847  new_dpi.left += this->pos_x;
2848  new_dpi.top += this->pos_y;
2849 
2850  DrawPixelInfo *old_dpi = _cur_dpi;
2851  _cur_dpi = &new_dpi;
2852 
2853  Rect r = this->GetCurrentRect();
2854 
2855  bool clicked = this->IsLowered();
2856  switch (this->type) {
2857  case WWT_EMPTY:
2858  break;
2859 
2860  case WWT_PUSHBTN:
2861  assert(this->widget_data == 0);
2862  DrawFrameRect(r.left, r.top, r.right, r.bottom, this->colour, (clicked) ? FR_LOWERED : FR_NONE);
2863  break;
2864 
2865  case WWT_IMGBTN:
2866  case WWT_PUSHIMGBTN:
2867  case WWT_IMGBTN_2:
2868  DrawImageButtons(r, this->type, this->colour, clicked, this->widget_data, this->align);
2869  break;
2870 
2871  case WWT_TEXTBTN:
2872  case WWT_PUSHTXTBTN:
2873  case WWT_TEXTBTN_2:
2874  if (this->index >= 0) w->SetStringParameters(this->index);
2875  DrawFrameRect(r.left, r.top, r.right, r.bottom, this->colour, (clicked) ? FR_LOWERED : FR_NONE);
2876  DrawLabel(r, this->type, clicked, this->text_colour, this->widget_data, this->align);
2877  break;
2878 
2879  case WWT_ARROWBTN:
2880  case WWT_PUSHARROWBTN: {
2881  SpriteID sprite;
2882  switch (this->widget_data) {
2883  case AWV_DECREASE: sprite = _current_text_dir != TD_RTL ? SPR_ARROW_LEFT : SPR_ARROW_RIGHT; break;
2884  case AWV_INCREASE: sprite = _current_text_dir == TD_RTL ? SPR_ARROW_LEFT : SPR_ARROW_RIGHT; break;
2885  case AWV_LEFT: sprite = SPR_ARROW_LEFT; break;
2886  case AWV_RIGHT: sprite = SPR_ARROW_RIGHT; break;
2887  default: NOT_REACHED();
2888  }
2889  DrawImageButtons(r, WWT_PUSHIMGBTN, this->colour, clicked, sprite, this->align);
2890  break;
2891  }
2892 
2893  case WWT_LABEL:
2894  if (this->index >= 0) w->SetStringParameters(this->index);
2895  DrawLabel(r, this->type, clicked, this->text_colour, this->widget_data, this->align);
2896  break;
2897 
2898  case WWT_TEXT:
2899  if (this->index >= 0) w->SetStringParameters(this->index);
2900  DrawText(r, this->text_colour, this->widget_data, this->align);
2901  break;
2902 
2903  case WWT_MATRIX:
2904  DrawMatrix(r, this->colour, clicked, this->widget_data, this->resize_x, this->resize_y);
2905  break;
2906 
2907  case WWT_EDITBOX: {
2908  const QueryString *query = w->GetQueryString(this->index);
2909  if (query != nullptr) query->DrawEditBox(w, this->index);
2910  break;
2911  }
2912 
2913  case WWT_CAPTION:
2914  if (this->index >= 0) w->SetStringParameters(this->index);
2915  DrawCaption(r, this->colour, w->owner, this->text_colour, this->widget_data, this->align);
2916  break;
2917 
2918  case WWT_SHADEBOX:
2919  assert(this->widget_data == 0);
2920  DrawShadeBox(r, this->colour, w->IsShaded());
2921  break;
2922 
2923  case WWT_DEBUGBOX:
2924  DrawDebugBox(r, this->colour, clicked);
2925  break;
2926 
2927  case WWT_STICKYBOX:
2928  assert(this->widget_data == 0);
2929  DrawStickyBox(r, this->colour, !!(w->flags & WF_STICKY));
2930  break;
2931 
2932  case WWT_DEFSIZEBOX:
2933  assert(this->widget_data == 0);
2934  DrawDefSizeBox(r, this->colour, clicked);
2935  break;
2936 
2937  case WWT_RESIZEBOX:
2938  assert(this->widget_data == 0);
2939  DrawResizeBox(r, this->colour, this->pos_x < (w->width / 2), !!(w->flags & WF_SIZING));
2940  break;
2941 
2942  case WWT_CLOSEBOX:
2943  DrawCloseBox(r, this->colour);
2944  break;
2945 
2946  case WWT_DROPDOWN:
2947  if (this->index >= 0) w->SetStringParameters(this->index);
2948  DrawButtonDropdown(r, this->colour, false, clicked, this->widget_data, this->align);
2949  break;
2950 
2951  case NWID_BUTTON_DROPDOWN:
2952  case NWID_PUSHBUTTON_DROPDOWN:
2953  if (this->index >= 0) w->SetStringParameters(this->index);
2954  DrawButtonDropdown(r, this->colour, clicked, (this->disp_flags & ND_DROPDOWN_ACTIVE) != 0, this->widget_data, this->align);
2955  break;
2956 
2957  default:
2958  NOT_REACHED();
2959  }
2960  if (this->index >= 0) w->DrawWidget(r, this->index);
2961 
2962  if (this->IsDisabled()) {
2964  }
2965 
2966  _cur_dpi = old_dpi;
2967 }
2968 
2977 {
2978  if (_current_text_dir == TD_LTR) {
2979  int button_width = this->pos_x + this->current_x - NWidgetLeaf::dropdown_dimension.width;
2980  return pt.x < button_width;
2981  } else {
2982  int button_left = this->pos_x + NWidgetLeaf::dropdown_dimension.width;
2983  return pt.x >= button_left;
2984  }
2985 }
2986 
2987 /* == Conversion code from NWidgetPart array to NWidgetBase* tree == */
2988 
3004 static int MakeNWidget(const NWidgetPart *parts, int count, NWidgetBase **dest, bool *fill_dest, int *biggest_index)
3005 {
3006  int num_used = 0;
3007 
3008  *dest = nullptr;
3009  *fill_dest = false;
3010 
3011  while (count > num_used) {
3012  switch (parts->type) {
3013  case NWID_SPACER:
3014  if (*dest != nullptr) return num_used;
3015  *dest = new NWidgetSpacer(0, 0);
3016  break;
3017 
3018  case NWID_HORIZONTAL:
3019  if (*dest != nullptr) return num_used;
3020  *dest = new NWidgetHorizontal(parts->u.cont_flags);
3021  *fill_dest = true;
3022  break;
3023 
3024  case NWID_HORIZONTAL_LTR:
3025  if (*dest != nullptr) return num_used;
3026  *dest = new NWidgetHorizontalLTR(parts->u.cont_flags);
3027  *fill_dest = true;
3028  break;
3029 
3030  case WWT_PANEL:
3031  case WWT_INSET:
3032  case WWT_FRAME:
3033  if (*dest != nullptr) return num_used;
3034  *dest = new NWidgetBackground(parts->type, parts->u.widget.colour, parts->u.widget.index);
3035  *biggest_index = std::max(*biggest_index, (int)parts->u.widget.index);
3036  *fill_dest = true;
3037  break;
3038 
3039  case NWID_VERTICAL:
3040  if (*dest != nullptr) return num_used;
3041  *dest = new NWidgetVertical(parts->u.cont_flags);
3042  *fill_dest = true;
3043  break;
3044 
3045  case NWID_MATRIX: {
3046  if (*dest != nullptr) return num_used;
3047  NWidgetMatrix *nwm = new NWidgetMatrix();
3048  *dest = nwm;
3049  *fill_dest = true;
3050  nwm->SetIndex(parts->u.widget.index);
3051  nwm->SetColour(parts->u.widget.colour);
3052  *biggest_index = std::max(*biggest_index, (int)parts->u.widget.index);
3053  break;
3054  }
3055 
3056  case WPT_FUNCTION: {
3057  if (*dest != nullptr) return num_used;
3058  /* Ensure proper functioning even when the called code simply writes its largest index. */
3059  int biggest = -1;
3060  *dest = parts->u.func_ptr(&biggest);
3061  *biggest_index = std::max(*biggest_index, biggest);
3062  *fill_dest = false;
3063  break;
3064  }
3065 
3066  case WPT_RESIZE: {
3067  NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest);
3068  if (nwrb != nullptr) {
3069  assert(parts->u.xy.x >= 0 && parts->u.xy.y >= 0);
3070  nwrb->SetResize(parts->u.xy.x, parts->u.xy.y);
3071  }
3072  break;
3073  }
3074 
3075  case WPT_MINSIZE: {
3076  NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest);
3077  if (nwrb != nullptr) {
3078  assert(parts->u.xy.x >= 0 && parts->u.xy.y >= 0);
3079  nwrb->SetMinimalSize(parts->u.xy.x, parts->u.xy.y);
3080  }
3081  break;
3082  }
3083 
3084  case WPT_MINTEXTLINES: {
3085  NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest);
3086  if (nwrb != nullptr) {
3087  assert(parts->u.text_lines.size >= FS_BEGIN && parts->u.text_lines.size < FS_END);
3088  nwrb->SetMinimalTextLines(parts->u.text_lines.lines, parts->u.text_lines.spacing, parts->u.text_lines.size);
3089  }
3090  break;
3091  }
3092 
3093  case WPT_TEXTCOLOUR: {
3094  NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(*dest);
3095  if (nwc != nullptr) {
3096  nwc->SetTextColour(parts->u.colour.colour);
3097  }
3098  break;
3099  }
3100 
3101  case WPT_ALIGNMENT: {
3102  NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(*dest);
3103  if (nwc != nullptr) {
3104  nwc->SetAlignment(parts->u.align.align);
3105  }
3106  break;
3107  }
3108 
3109  case WPT_FILL: {
3110  NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(*dest);
3111  if (nwrb != nullptr) nwrb->SetFill(parts->u.xy.x, parts->u.xy.y);
3112  break;
3113  }
3114 
3115  case WPT_DATATIP: {
3116  NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(*dest);
3117  if (nwc != nullptr) {
3118  nwc->widget_data = parts->u.data_tip.data;
3119  nwc->tool_tip = parts->u.data_tip.tooltip;
3120  }
3121  break;
3122  }
3123 
3124  case WPT_PADDING:
3125  if (*dest != nullptr) (*dest)->SetPadding(parts->u.padding);
3126  break;
3127 
3128  case WPT_PIPSPACE: {
3129  NWidgetPIPContainer *nwc = dynamic_cast<NWidgetPIPContainer *>(*dest);
3130  if (nwc != nullptr) nwc->SetPIP(parts->u.pip.pre, parts->u.pip.inter, parts->u.pip.post);
3131 
3132  NWidgetBackground *nwb = dynamic_cast<NWidgetBackground *>(*dest);
3133  if (nwb != nullptr) nwb->SetPIP(parts->u.pip.pre, parts->u.pip.inter, parts->u.pip.post);
3134  break;
3135  }
3136 
3137  case WPT_SCROLLBAR: {
3138  NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(*dest);
3139  if (nwc != nullptr) {
3140  nwc->scrollbar_index = parts->u.widget.index;
3141  }
3142  break;
3143  }
3144 
3145  case WPT_ENDCONTAINER:
3146  return num_used;
3147 
3148  case NWID_VIEWPORT:
3149  if (*dest != nullptr) return num_used;
3150  *dest = new NWidgetViewport(parts->u.widget.index);
3151  *biggest_index = std::max(*biggest_index, (int)parts->u.widget.index);
3152  break;
3153 
3154  case NWID_HSCROLLBAR:
3155  case NWID_VSCROLLBAR:
3156  if (*dest != nullptr) return num_used;
3157  *dest = new NWidgetScrollbar(parts->type, parts->u.widget.colour, parts->u.widget.index);
3158  *biggest_index = std::max(*biggest_index, (int)parts->u.widget.index);
3159  break;
3160 
3161  case NWID_SELECTION: {
3162  if (*dest != nullptr) return num_used;
3163  NWidgetStacked *nws = new NWidgetStacked();
3164  *dest = nws;
3165  *fill_dest = true;
3166  nws->SetIndex(parts->u.widget.index);
3167  *biggest_index = std::max(*biggest_index, (int)parts->u.widget.index);
3168  break;
3169  }
3170 
3171  default:
3172  if (*dest != nullptr) return num_used;
3173  assert((parts->type & WWT_MASK) < WWT_LAST || (parts->type & WWT_MASK) == NWID_BUTTON_DROPDOWN);
3174  *dest = new NWidgetLeaf(parts->type, parts->u.widget.colour, parts->u.widget.index, 0x0, STR_NULL);
3175  *biggest_index = std::max(*biggest_index, (int)parts->u.widget.index);
3176  break;
3177  }
3178  num_used++;
3179  parts++;
3180  }
3181 
3182  return num_used;
3183 }
3184 
3194 static int MakeWidgetTree(const NWidgetPart *parts, int count, NWidgetBase **parent, int *biggest_index)
3195 {
3196  /* If *parent == nullptr, only the first widget is read and returned. Otherwise, *parent must point to either
3197  * a #NWidgetContainer or a #NWidgetBackground object, and parts are added as much as possible. */
3198  NWidgetContainer *nwid_cont = dynamic_cast<NWidgetContainer *>(*parent);
3199  NWidgetBackground *nwid_parent = dynamic_cast<NWidgetBackground *>(*parent);
3200  assert(*parent == nullptr || (nwid_cont != nullptr && nwid_parent == nullptr) || (nwid_cont == nullptr && nwid_parent != nullptr));
3201 
3202  int total_used = 0;
3203  for (;;) {
3204  NWidgetBase *sub_widget = nullptr;
3205  bool fill_sub = false;
3206  int num_used = MakeNWidget(parts, count - total_used, &sub_widget, &fill_sub, biggest_index);
3207  parts += num_used;
3208  total_used += num_used;
3209 
3210  /* Break out of loop when end reached */
3211  if (sub_widget == nullptr) break;
3212 
3213  /* If sub-widget is a container, recursively fill that container. */
3214  WidgetType tp = sub_widget->type;
3215  if (fill_sub && (tp == NWID_HORIZONTAL || tp == NWID_HORIZONTAL_LTR || tp == NWID_VERTICAL || tp == NWID_MATRIX
3216  || tp == WWT_PANEL || tp == WWT_FRAME || tp == WWT_INSET || tp == NWID_SELECTION)) {
3217  NWidgetBase *sub_ptr = sub_widget;
3218  int num_used = MakeWidgetTree(parts, count - total_used, &sub_ptr, biggest_index);
3219  parts += num_used;
3220  total_used += num_used;
3221  }
3222 
3223  /* Add sub_widget to parent container if available, otherwise return the widget to the caller. */
3224  if (nwid_cont != nullptr) nwid_cont->Add(sub_widget);
3225  if (nwid_parent != nullptr) nwid_parent->Add(sub_widget);
3226  if (nwid_cont == nullptr && nwid_parent == nullptr) {
3227  *parent = sub_widget;
3228  return total_used;
3229  }
3230  }
3231 
3232  if (count == total_used) return total_used; // Reached the end of the array of parts?
3233 
3234  assert(total_used < count);
3235  assert(parts->type == WPT_ENDCONTAINER);
3236  return total_used + 1; // *parts is also 'used'
3237 }
3238 
3250 NWidgetContainer *MakeNWidgets(const NWidgetPart *parts, int count, int *biggest_index, NWidgetContainer *container)
3251 {
3252  *biggest_index = -1;
3253  if (container == nullptr) container = new NWidgetVertical();
3254  NWidgetBase *cont_ptr = container;
3255  MakeWidgetTree(parts, count, &cont_ptr, biggest_index);
3256  return container;
3257 }
3258 
3272 NWidgetContainer *MakeWindowNWidgetTree(const NWidgetPart *parts, int count, int *biggest_index, NWidgetStacked **shade_select)
3273 {
3274  *biggest_index = -1;
3275 
3276  /* Read the first widget recursively from the array. */
3277  NWidgetBase *nwid = nullptr;
3278  int num_used = MakeWidgetTree(parts, count, &nwid, biggest_index);
3279  assert(nwid != nullptr);
3280  parts += num_used;
3281  count -= num_used;
3282 
3283  NWidgetContainer *root = new NWidgetVertical;
3284  root->Add(nwid);
3285  if (count == 0) { // There is no body at all.
3286  *shade_select = nullptr;
3287  return root;
3288  }
3289 
3290  /* If the first widget looks like a titlebar, treat it as such.
3291  * If it has a shading box, silently add a shade selection widget in the tree. */
3292  NWidgetHorizontal *hor_cont = dynamic_cast<NWidgetHorizontal *>(nwid);
3293  NWidgetContainer *body;
3294  if (hor_cont != nullptr && hor_cont->GetWidgetOfType(WWT_CAPTION) != nullptr && hor_cont->GetWidgetOfType(WWT_SHADEBOX) != nullptr) {
3295  *shade_select = new NWidgetStacked;
3296  root->Add(*shade_select);
3297  body = new NWidgetVertical;
3298  (*shade_select)->Add(body);
3299  } else {
3300  *shade_select = nullptr;
3301  body = root;
3302  }
3303 
3304  /* Load the remaining parts into 'body'. */
3305  int biggest2 = -1;
3306  MakeNWidgets(parts, count, &biggest2, body);
3307 
3308  *biggest_index = std::max(*biggest_index, biggest2);
3309  return root;
3310 }
3311 
3323 NWidgetBase *MakeCompanyButtonRows(int *biggest_index, int widget_first, int widget_last, Colours button_colour, int max_length, StringID button_tooltip)
3324 {
3325  assert(max_length >= 1);
3326  NWidgetVertical *vert = nullptr; // Storage for all rows.
3327  NWidgetHorizontal *hor = nullptr; // Storage for buttons in one row.
3328  int hor_length = 0;
3329 
3330  Dimension sprite_size = GetSpriteSize(SPR_COMPANY_ICON, nullptr, ZOOM_LVL_OUT_4X);
3331  sprite_size.width += WidgetDimensions::unscaled.matrix.Horizontal();
3332  sprite_size.height += WidgetDimensions::unscaled.matrix.Vertical() + 1; // 1 for the 'offset' of being pressed
3333 
3334  for (int widnum = widget_first; widnum <= widget_last; widnum++) {
3335  /* Ensure there is room in 'hor' for another button. */
3336  if (hor_length == max_length) {
3337  if (vert == nullptr) vert = new NWidgetVertical();
3338  vert->Add(hor);
3339  hor = nullptr;
3340  hor_length = 0;
3341  }
3342  if (hor == nullptr) {
3343  hor = new NWidgetHorizontal();
3344  hor_length = 0;
3345  }
3346 
3347  NWidgetBackground *panel = new NWidgetBackground(WWT_PANEL, button_colour, widnum);
3348  panel->SetMinimalSize(sprite_size.width, sprite_size.height);
3349  panel->SetFill(1, 1);
3350  panel->SetResize(1, 0);
3351  panel->SetDataTip(0x0, button_tooltip);
3352  hor->Add(panel);
3353  hor_length++;
3354  }
3355  *biggest_index = widget_last;
3356  if (vert == nullptr) return hor; // All buttons fit in a single row.
3357 
3358  if (hor_length > 0 && hor_length < max_length) {
3359  /* Last row is partial, add a spacer at the end to force all buttons to the left. */
3360  NWidgetSpacer *spc = new NWidgetSpacer(sprite_size.width, sprite_size.height);
3361  spc->SetFill(1, 1);
3362  spc->SetResize(1, 0);
3363  hor->Add(spc);
3364  }
3365  if (hor != nullptr) vert->Add(hor);
3366  return vert;
3367 }
ES_HANDLED
@ ES_HANDLED
The passed event is handled.
Definition: window_type.h:720
NWidgetBackground::SetupSmallestSize
void SetupSmallestSize(Window *w, bool init_array) override
Definition: widget.cpp:2141
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:3323
NWidgetSpacer::NWidgetSpacer
NWidgetSpacer(int width, int height)
Generic spacer widget.
Definition: widget.cpp:1815
NWidgetResizeBase
Base class for a resizable nested widget.
Definition: widget_type.h:255
NWidgetPartTextLines::lines
uint8 lines
Number of text lines.
Definition: widget_type.h:942
NWidgetMatrix::clicked
int clicked
The currently clicked widget.
Definition: widget_type.h:558
ScrollbarClickHandler
void ScrollbarClickHandler(Window *w, NWidgetCore *nw, int x, int y)
Special handling for the scrollbar widget type.
Definition: widget.cpp:375
NWidgetScrollbar::SetupSmallestSize
void SetupSmallestSize(Window *w, bool init_array) override
Definition: widget.cpp:2465
WD_SHADEBOX_WIDTH
@ WD_SHADEBOX_WIDTH
Width of a standard shade box widget.
Definition: widget.cpp:75
NWidgetStacked::AssignSizePosition
void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override
Definition: widget.cpp:1350
NWidgetMatrix::widgets_y
int widgets_y
The number of visible widgets in vertical direction.
Definition: widget_type.h:565
NWidgetStacked::NWidgetStacked
NWidgetStacked()
Widgets stacked on top of each other.
Definition: widget.cpp:1288
NWidgetResizeBase::uz_min_x
uint uz_min_x
Unscaled Minimal horizontal size of only this widget.
Definition: widget_type.h:272
WD_RESIZEBOX_BOTTOM
@ WD_RESIZEBOX_BOTTOM
Bottom offset of resize sprite.
Definition: widget.cpp:107
NWidgetPart::colour
NWidgetPartTextColour colour
Part with text colour data.
Definition: widget_type.h:984
NWidgetCore::IsDisabled
bool IsDisabled() const
Return whether the widget is disabled.
Definition: widget_type.h:395
WWT_IMGBTN_2
@ WWT_IMGBTN_2
(Toggle) Button with diff image when clicked
Definition: widget_type.h:51
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:848
DrawText
static void DrawText(const Rect &r, TextColour colour, StringID str, StringAlignment align)
Draw text.
Definition: widget.cpp:506
Rect::Height
int Height() const
Get height of Rect.
Definition: geometry_type.hpp:85
WD_FRAMETEXT_LEFT
@ WD_FRAMETEXT_LEFT
Left offset of the text of the frame.
Definition: widget.cpp:63
WidgetDrawDistances
WidgetDrawDistances
Distances used in drawing widgets.
Definition: widget.cpp:28
SA_HOR_MASK
@ SA_HOR_MASK
Mask for horizontal alignment.
Definition: gfx_type.h:337
NWidgetPart::pip
NWidgetPartPIP pip
Part with pre/inter/post spaces.
Definition: widget_type.h:982
WD_IMGBTN_BOTTOM
@ WD_IMGBTN_BOTTOM
Bottom offset of image in the button.
Definition: widget.cpp:33
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:1724
WF_SIZING
@ WF_SIZING
Window is being resized.
Definition: window_gui.h:173
NWidgetSpacer::GetWidgetFromPos
NWidgetCore * GetWidgetFromPos(int x, int y) override
Definition: widget.cpp:1841
querystring_gui.h
NWidgetPartPIP::post
uint8 post
Amount of space before/between/after child widgets.
Definition: widget_type.h:934
SortButtonState
SortButtonState
State of a sort direction button.
Definition: window_gui.h:158
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:1150
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:489
GUISettings::newgrf_developer_tools
bool newgrf_developer_tools
activate NewGRF developer tools and allow modifying NewGRFs in an existing game
Definition: settings_type.h:192
WD_SHADEBOX_LEFT
@ WD_SHADEBOX_LEFT
Left offset of shade sprite.
Definition: widget.cpp:76
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:311
PALETTE_TEXT_RECOLOUR
@ PALETTE_TEXT_RECOLOUR
Set if palette is actually a magic text recolour.
Definition: sprites.h:1520
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
WD_CLOSEBOX_TOP
@ WD_CLOSEBOX_TOP
Top offset of closebox string.
Definition: widget.cpp:113
NWidgetPIPContainer::pip_inter
uint8 pip_inter
Amount of space between widgets.
Definition: widget_type.h:488
WD_CAPTIONTEXT_LEFT
@ WD_CAPTIONTEXT_LEFT
Offset of the caption text at the left.
Definition: widget.cpp:118
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:985
Scrollbar::GetCapacity
uint16 GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:669
NWidgetStacked::index
int index
If non-negative, index in the Window::nested_array.
Definition: widget_type.h:460
WD_RESIZEBOX_TOP
@ WD_RESIZEBOX_TOP
Top offset of resize sprite.
Definition: widget.cpp:106
Window::DrawSortButtonState
void DrawSortButtonState(int widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
Definition: widget.cpp:890
Window::nested_root
NWidgetBase * nested_root
Root of the nested tree.
Definition: window_gui.h:258
NWidgetLeaf::resizebox_dimension
static Dimension resizebox_dimension
Cached size of a resizebox widget.
Definition: widget_type.h:832
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:64
DrawCloseBox
static void DrawCloseBox(const Rect &r, Colours colour)
Draw a close box.
Definition: widget.cpp:784
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:92
_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:430
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:1436
Window::DrawWidget
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
Definition: window_gui.h:500
WD_STICKYBOX_WIDTH
@ WD_STICKYBOX_WIDTH
Width of a standard sticky box widget.
Definition: widget.cpp:82
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition: window_gui.h:67
NWidgetContainer::Add
void Add(NWidgetBase *wid)
Append widget wid to container.
Definition: widget.cpp:1261
NWID_HSCROLLBAR
@ NWID_HSCROLLBAR
Horizontal scrollbar.
Definition: widget_type.h:81
WD_DROPDOWNTEXT_BOTTOM
@ WD_DROPDOWNTEXT_BOTTOM
Bottom offset of the dropdown widget string.
Definition: widget.cpp:128
FS_BEGIN
@ FS_BEGIN
First font.
Definition: gfx_type.h:209
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:622
WidgetDimensions::pressed
int pressed
Offset for contents of depressed widget.
Definition: window_gui.h:60
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:780
Scrollbar::pos
uint16 pos
Index of first visible item of the list.
Definition: widget_type.h:641
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:739
WD_DEBUGBOX_BOTTOM
@ WD_DEBUGBOX_BOTTOM
Bottom offset of debug sprite.
Definition: widget.cpp:93
NWidgetMatrix
Matrix container with implicitly equal sized (virtual) sub-widgets.
Definition: widget_type.h:539
WD_DROPDOWNTEXT_TOP
@ WD_DROPDOWNTEXT_TOP
Top offset of the dropdown widget string.
Definition: widget.cpp:127
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:255
NWidgetPIPContainer::uz_pip_post
uint8 uz_pip_post
Unscaled space after last widget.
Definition: widget_type.h:493
ND_SHADE_DIMMED
@ ND_SHADE_DIMMED
Bit value of the 'dimmed colours' flag.
Definition: widget_type.h:303
WD_CAPTIONTEXT_BOTTOM
@ WD_CAPTIONTEXT_BOTTOM
Offset of the caption text at the bottom.
Definition: widget.cpp:121
WD_HSCROLLBAR_BOTTOM
@ WD_HSCROLLBAR_BOTTOM
Bottom offset of horizontal scrollbar.
Definition: widget.cpp:48
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:1165
NWidgetBase::uz_padding
RectPadding uz_padding
Unscaled padding, for resize calculation.
Definition: widget_type.h:206
FILLRECT_RECOLOUR
@ FILLRECT_RECOLOUR
Apply a recolour sprite to the screen content.
Definition: gfx_type.h:295
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:1106
FrameFlags
FrameFlags
Flags to describe the look of the frame.
Definition: window_gui.h:30
NWidgetStacked::Draw
void Draw(const Window *w) override
Definition: widget.cpp:1376
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
NWidgetMatrix::Draw
void Draw(const Window *w) override
Definition: widget.cpp:2003
WD_DEBUGBOX_TOP
@ WD_DEBUGBOX_TOP
Top offset of debug sprite.
Definition: widget.cpp:92
NWidgetLeaf::stickybox_dimension
static Dimension stickybox_dimension
Cached size of a stickybox widget.
Definition: widget_type.h:838
WD_RESIZEBOX_RIGHT
@ WD_RESIZEBOX_RIGHT
Right offset of resize sprite.
Definition: widget.cpp:105
NDB_SCROLLBAR_DOWN
@ NDB_SCROLLBAR_DOWN
Down-button is lowered bit.
Definition: widget_type.h:293
WD_VSCROLLBAR_LEFT
@ WD_VSCROLLBAR_LEFT
Left offset of vertical scrollbar.
Definition: widget.cpp:40
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:834
Window::IsNewGRFInspectable
virtual bool IsNewGRFInspectable() const
Is the data related to this window NewGRF inspectable?
Definition: window_gui.h:743
WF_STICKY
@ WF_STICKY
Window is made sticky by user.
Definition: window_gui.h:174
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:22
WD_MATRIX_LEFT
@ WD_MATRIX_LEFT
Offset at left of a matrix cell.
Definition: widget.cpp:69
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:575
PALETTE_TO_TRANSPARENT
static const PaletteID PALETTE_TO_TRANSPARENT
This sets the sprite to transparent.
Definition: sprites.h:1595
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:970
NWidgetResizeBase::uz_min_y
uint uz_min_y
Unscaled Minimal vertical size of only this widget.
Definition: widget_type.h:273
WD_SHADEBOX_RIGHT
@ WD_SHADEBOX_RIGHT
Right offset of shade sprite.
Definition: widget.cpp:77
Scrollbar::SetCount
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:717
WD_SHADEBOX_TOP
@ WD_SHADEBOX_TOP
Top offset of shade sprite.
Definition: widget.cpp:78
WD_CAPTION_HEIGHT
@ WD_CAPTION_HEIGHT
Height of a title bar.
Definition: widget.cpp:117
FILLRECT_CHECKER
@ FILLRECT_CHECKER
Draw only every second pixel, used for greying-out.
Definition: gfx_type.h:294
MAT_ROW_START
@ MAT_ROW_START
Lowest bit of the number of rows.
Definition: widget_type.h:29
WD_RESIZEBOX_LEFT
@ WD_RESIZEBOX_LEFT
Left offset of resize sprite.
Definition: widget.cpp:104
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:253
zoom_func.h
NWidgetLeaf
Leaf widget.
Definition: widget_type.h:820
ZoomLevel
ZoomLevel
All zoom levels we know.
Definition: zoom_type.h:19
SA_BOTTOM
@ SA_BOTTOM
Bottom align the text.
Definition: gfx_type.h:341
NWidgetMatrix::SetScrollbar
void SetScrollbar(Scrollbar *sb)
Assign a scrollbar to this matrix.
Definition: widget.cpp:1905
StringAlignment
StringAlignment
How to align the to-be drawn text.
Definition: gfx_type.h:333
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:53
NWidgetMatrix::count
int count
Amount of valid widgets.
Definition: widget_type.h:559
DrawString
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:644
WD_HSCROLLBAR_RIGHT
@ WD_HSCROLLBAR_RIGHT
Right offset of horizontal scrollbar.
Definition: widget.cpp:46
NWidgetPart::xy
Point xy
Part with an x/y size.
Definition: widget_type.h:978
NWidgetSpacer::FillNestedArray
void FillNestedArray(NWidgetBase **array, uint length) override
Definition: widget.cpp:1827
SZSP_HORIZONTAL
@ SZSP_HORIZONTAL
Display plane with zero size vertically, and filling and resizing horizontally.
Definition: widget_type.h:427
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:253
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:34
NWidgetCore::tool_tip
StringID tool_tip
Tooltip of the widget.
Definition: widget_type.h:341
NWidgetContainer::GetWidgetOfType
NWidgetBase * GetWidgetOfType(WidgetType tp) override
Retrieve a widget by its type.
Definition: widget.cpp:1239
Rect::Expand
Rect Expand(int s) const
Copy and expand Rect by s pixels.
Definition: geometry_type.hpp:147
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition: gfx_type.h:336
SA_VERT_CENTER
@ SA_VERT_CENTER
Vertically center the text.
Definition: gfx_type.h:340
NWidgetCore::SetLowered
void SetLowered(bool lowered)
Lower or raise the widget.
Definition: widget_type.h:374
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:2353
NWidgetLeaf::shadebox_dimension
static Dimension shadebox_dimension
Cached size of a shadebox widget.
Definition: widget_type.h:835
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:194
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:636
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:3250
NWidgetMatrix::SetupSmallestSize
void SetupSmallestSize(Window *w, bool init_array) override
Definition: widget.cpp:1910
FR_TRANSPARENT
@ FR_TRANSPARENT
Makes the background transparent if set.
Definition: window_gui.h:32
_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
Rect::WithHeight
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Definition: geometry_type.hpp:205
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:975
NWidgetVertical::SetupSmallestSize
void SetupSmallestSize(Window *w, bool init_array) override
Definition: widget.cpp:1655
DrawDefSizeBox
static void DrawDefSizeBox(const Rect &r, Colours colour, bool clicked)
Draw a defsize box.
Definition: widget.cpp:750
WidgetDimensions::modalpopup
RectPadding modalpopup
Padding for a modal popup.
Definition: window_gui.h:58
NWidgetPIPContainer::uz_pip_inter
uint8 uz_pip_inter
Unscaled space between widgets.
Definition: widget_type.h:492
WD_DEBUGBOX_LEFT
@ WD_DEBUGBOX_LEFT
Left offset of debug sprite.
Definition: widget.cpp:90
NWidgetMatrix::sb
Scrollbar * sb
The scrollbar we're associated with.
Definition: widget_type.h:560
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:340
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:890
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:1881
NWidgetBase::prev
NWidgetBase * prev
Pointer to previous widget in container. Managed by parent container widget.
Definition: widget_type.h:203
WD_DROPDOWNTEXT_RIGHT
@ WD_DROPDOWNTEXT_RIGHT
Right offset of the dropdown widget string.
Definition: widget.cpp:126
WD_IMGBTN_TOP
@ WD_IMGBTN_TOP
Top offset of image in the button.
Definition: widget.cpp:32
Window::SetStringParameters
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
Definition: window_gui.h:522
window_gui.h
NWidgetStacked::FillNestedArray
void FillNestedArray(NWidgetBase **array, uint length) override
Definition: widget.cpp:1370
NWidgetLeaf::InvalidateDimensionCache
static void InvalidateDimensionCache()
Reset the cached dimensions.
Definition: widget.cpp:2544
NWidgetResizeBase::NWidgetResizeBase
NWidgetResizeBase(WidgetType tp, uint fill_x, uint fill_y)
Constructor for resizable nested widgets.
Definition: widget.cpp:1060
RectPadding
Padding dimensions to apply to each side of a Rect.
Definition: geometry_type.hpp:47
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:469
Window::GetWidget
const NWID * GetWidget(uint widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition: window_gui.h:865
ND_DROPDOWN_ACTIVE
@ ND_DROPDOWN_ACTIVE
Bit value of the 'dropdown active' flag.
Definition: widget_type.h:304
Scrollbar::UpdatePosition
bool UpdatePosition(int difference, ScrollbarStepping unit=SS_SMALL)
Updates the position of the first visible element by the given amount.
Definition: widget_type.h:763
_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:1136
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
NWidgetLeaf::NWidgetLeaf
NWidgetLeaf(WidgetType tp, Colours colour, int index, uint32 data, StringID tip)
Nested leaf widget.
Definition: widget.cpp:2571
WD_BEVEL_BOTTOM
@ WD_BEVEL_BOTTOM
Height of bottom bevel border.
Definition: widget.cpp:54
NWidgetBackground::AssignSizePosition
void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override
Definition: widget.cpp:2208
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:596
NWidgetLeaf::dropdown_dimension
static Dimension dropdown_dimension
Cached size of a dropdown widget.
Definition: widget_type.h:831
ST_SMALLEST
@ ST_SMALLEST
Initialize nested widget tree to smallest size. Also updates current_x and current_y.
Definition: widget_type.h:112
DrawShadeBox
static void DrawShadeBox(const Rect &r, Colours colour, bool clicked)
Draw a shade box.
Definition: widget.cpp:728
NWidgetViewport::UpdateViewportCoordinates
void UpdateViewportCoordinates(Window *w)
Update the position and size of the viewport (after eg a resize).
Definition: widget.cpp:2331
Scrollbar::GetCount
uint16 GetCount() const
Gets the number of elements in the list.
Definition: widget_type.h:660
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:203
NWidgetContainer::tail
NWidgetBase * tail
Pointer to last widget in container.
Definition: widget_type.h:421
SA_TOP
@ SA_TOP
Top align the text.
Definition: gfx_type.h:339
WidgetDimensions::hsep_normal
int hsep_normal
Normal horizontal spacing.
Definition: window_gui.h:63
NWidgetPIPContainer::Draw
void Draw(const Window *w) override
Definition: widget.cpp:1447
NWID_VIEWPORT
@ NWID_VIEWPORT
Nested widget containing a viewport.
Definition: widget_type.h:79
NWidgetViewport::SetupSmallestSize
void SetupSmallestSize(Window *w, bool init_array) override
Definition: widget.cpp:2286
WD_VSCROLLBAR_BOTTOM
@ WD_VSCROLLBAR_BOTTOM
Bottom offset of vertical scrollbar.
Definition: widget.cpp:43
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:185
NWidgetPIPContainer::GetWidgetFromPos
NWidgetCore * GetWidgetFromPos(int x, int y) override
Definition: widget.cpp:1454
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:249
WD_STICKYBOX_LEFT
@ WD_STICKYBOX_LEFT
Left offset of sticky sprite.
Definition: widget.cpp:83
WD_BEVEL_RIGHT
@ WD_BEVEL_RIGHT
Width of right bevel border.
Definition: widget.cpp:52
WF_WHITE_BORDER
@ WF_WHITE_BORDER
Window white border counter bit mask.
Definition: window_gui.h:176
WD_VSCROLLBAR_RIGHT
@ WD_VSCROLLBAR_RIGHT
Right offset of vertical scrollbar.
Definition: widget.cpp:41
NWidgetResizeBase::SetResize
void SetResize(uint resize_x, uint resize_y)
Set resize step of the widget.
Definition: widget.cpp:1130
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:1008
WD_VSCROLLBAR_TOP
@ WD_VSCROLLBAR_TOP
Top offset of vertical scrollbar.
Definition: widget.cpp:42
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:193
WD_STICKYBOX_RIGHT
@ WD_STICKYBOX_RIGHT
Right offset of sticky sprite.
Definition: widget.cpp:84
WD_PAR_VSEP_NORMAL
@ WD_PAR_VSEP_NORMAL
Normal amount of vertical space between two paragraphs of text.
Definition: widget.cpp:130
WidgetDimensions::matrix
RectPadding matrix
Offsets within a matrix cell.
Definition: window_gui.h:49
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:836
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:214
RectPadding::Horizontal
uint Horizontal() const
Get total horizontal padding of RectPadding.
Definition: geometry_type.hpp:59
WD_CAPTIONTEXT_RIGHT
@ WD_CAPTIONTEXT_RIGHT
Offset of the caption text at the right.
Definition: widget.cpp:119
NWidgetBase::GetWidgetOfType
virtual NWidgetBase * GetWidgetOfType(WidgetType tp)
Retrieve a widget by its type.
Definition: widget.cpp:1044
WPT_PIPSPACE
@ WPT_PIPSPACE
Widget part for specifying pre/inter/post space for containers.
Definition: widget_type.h:91
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:721
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:104
WD_DEFSIZEBOX_TOP
@ WD_DEFSIZEBOX_TOP
Top offset of defsize sprite.
Definition: widget.cpp:99
NWidgetCore::SetToolTip
void SetToolTip(StringID tool_tip)
Set the tool tip of the nested widget.
Definition: widget.cpp:1195
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:2273
Scrollbar::IsVertical
bool IsVertical() const
Is the scrollbar vertical or not?
Definition: widget_type.h:697
WidgetDimensions::hsep_wide
int hsep_wide
Wide horizontal spacing.
Definition: window_gui.h:64
NWidgetMatrix::GetWidgetFromPos
NWidgetCore * GetWidgetFromPos(int x, int y) override
Definition: widget.cpp:1971
WD_PAR_VSEP_WIDE
@ WD_PAR_VSEP_WIDE
Large amount of vertical space between two paragraphs of text.
Definition: widget.cpp:131
WD_FRAMERECT_BOTTOM
@ WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
Definition: widget.cpp:60
PALETTE_NEWSPAPER
static const PaletteID PALETTE_NEWSPAPER
Recolour sprite for newspaper-greying.
Definition: sprites.h:1597
GetWidgetFromPos
int GetWidgetFromPos(const Window *w, int x, int y)
Returns the index for the widget located at the given position relative to the window.
Definition: widget.cpp:399
ScaleSpriteTrad
static int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
Definition: zoom_func.h:107
WD_FRAMETEXT_BOTTOM
@ WD_FRAMETEXT_BOTTOM
Bottom offset of the text of the frame.
Definition: widget.cpp:66
DrawDebugBox
static void DrawDebugBox(const Rect &r, Colours colour, bool clicked)
Draw a NewGRF debug box.
Definition: widget.cpp:761
WD_CLOSEBOX_BOTTOM
@ WD_CLOSEBOX_BOTTOM
Bottom offset of closebox string.
Definition: widget.cpp:114
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:2374
_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:339
SA_FORCE
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
Definition: gfx_type.h:346
NWidgetPart::widget
NWidgetPartWidget widget
Part with a start of a widget.
Definition: widget_type.h:980
NWidgetPartWidget::index
int16 index
Widget index in the widget array.
Definition: widget_type.h:919
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
WD_BEVEL_LEFT
@ WD_BEVEL_LEFT
Width of left bevel border.
Definition: widget.cpp:51
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:487
TransparencyOptionBits
uint TransparencyOptionBits
transparency option bits
Definition: transparency.h:36
NWidgetResizeBase::uz_text_size
FontSize uz_text_size
'Unscaled' font size, stored for resize calculation.
Definition: widget_type.h:277
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:2127
safeguards.h
NWidgetCore::SetAlignment
void SetAlignment(StringAlignment align)
Set the text/image alignment of the nested widget.
Definition: widget.cpp:1204
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:536
NWidgetCore::SetTextColour
void SetTextColour(TextColour colour)
Set the text colour of the nested widget.
Definition: widget.cpp:1186
Window::left
int left
x position of left edge of the window
Definition: window_gui.h:246
NWidgetLeaf::defsizebox_dimension
static Dimension defsizebox_dimension
Cached size of a defsizebox widget.
Definition: widget_type.h:837
Window::flags
WindowFlags flags
Window flags.
Definition: window_gui.h:239
WD_DROPDOWNTEXT_LEFT
@ WD_DROPDOWNTEXT_LEFT
Left offset of the dropdown widget string.
Definition: widget.cpp:125
WD_DEFSIZEBOX_WIDTH
@ WD_DEFSIZEBOX_WIDTH
Width of a standard defsize box widget.
Definition: widget.cpp:96
WidgetDimensions::captiontext
RectPadding captiontext
Offsets of text within a caption.
Definition: window_gui.h:56
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:1223
WidgetDimensions::dropdowntext
RectPadding dropdowntext
Offsets of text within a dropdown widget.
Definition: window_gui.h:57
Rect::WithWidth
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Definition: geometry_type.hpp:179
NWidgetPart::func_ptr
NWidgetFunctionType * func_ptr
Part with a function call.
Definition: widget_type.h:986
NDB_SCROLLBAR_UP
@ NDB_SCROLLBAR_UP
Up-button is lowered bit.
Definition: widget_type.h:292
DrawSprite
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Definition: gfx.cpp:1058
NWidgetPart::padding
NWidgetPartPaddings padding
Part with paddings.
Definition: widget_type.h:981
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:177
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:380
WD_FRAMETEXT_RIGHT
@ WD_FRAMETEXT_RIGHT
Right offset of the text of the frame.
Definition: widget.cpp:64
NWidgetHorizontal::SetupSmallestSize
void SetupSmallestSize(Window *w, bool init_array) override
Definition: widget.cpp:1470
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:636
NWidgetPartTextLines::spacing
uint8 spacing
Extra spacing around lines.
Definition: widget_type.h:943
WWT_FRAME
@ WWT_FRAME
Frame.
Definition: widget_type.h:58
NWidgetStacked::GetWidgetFromPos
NWidgetCore * GetWidgetFromPos(int x, int y) override
Definition: widget.cpp:1391
NWidgetContainer::head
NWidgetBase * head
Pointer to first widget in container.
Definition: widget_type.h:420
NWidgetMatrix::index
int index
If non-negative, index in the Window::nested_array.
Definition: widget_type.h:556
stdafx.h
WD_SHADEBOX_BOTTOM
@ WD_SHADEBOX_BOTTOM
Bottom offset of shade sprite.
Definition: widget.cpp:79
WD_INSET_LEFT
@ WD_INSET_LEFT
Left offset of string.
Definition: widget.cpp:36
GetScaledSpriteSize
Dimension GetScaledSpriteSize(SpriteID sprid)
Scale sprite size for GUI.
Definition: widget.cpp:187
GfxFillRect
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition: gfx.cpp:116
RectPadding::Vertical
uint Vertical() const
Get total vertical padding of RectPadding.
Definition: geometry_type.hpp:65
WD_CLOSEBOX_WIDTH
@ WD_CLOSEBOX_WIDTH
Width of a close box widget.
Definition: widget.cpp:110
NWidgetHorizontal::AssignSizePosition
void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override
Definition: widget.cpp:1537
NWidgetStacked::SetDisplayedPlane
void SetDisplayedPlane(int plane)
Select which plane to show (for NWID_SELECTION only).
Definition: widget.cpp:1409
NWidgetPIPContainer::uz_pip_pre
uint8 uz_pip_pre
Unscaled space before first widget.
Definition: widget_type.h:491
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:264
NWidgetBase::current_y
uint current_y
Current vertical size (after resizing).
Definition: widget_type.h:197
NWidgetStacked
Stacked widgets, widgets all occupying the same space in the window.
Definition: widget_type.h:443
NWidgetScrollbar::vertical_dimension
static Dimension vertical_dimension
Cached size of vertical scrollbar button.
Definition: widget_type.h:812
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_type.h:335
NWidgetBase::next
NWidgetBase * next
Pointer to next widget in container. Managed by parent container widget.
Definition: widget_type.h:202
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:259
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:1119
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:1786
WD_DEBUGBOX_RIGHT
@ WD_DEBUGBOX_RIGHT
Right offset of debug sprite.
Definition: widget.cpp:91
WWT_TEXTBTN_2
@ WWT_TEXTBTN_2
(Toggle) Button with diff text when clicked
Definition: widget_type.h:54
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:993
DrawResizeBox
static void DrawResizeBox(const Rect &r, Colours colour, bool at_left, bool clicked)
Draw a resize box.
Definition: widget.cpp:773
NWidgetSpacer::SetDirty
void SetDirty(const Window *w) const override
Mark the widget as 'dirty' (in need of repaint).
Definition: widget.cpp:1836
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
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_INSET_TOP
@ WD_INSET_TOP
Top offset of string.
Definition: widget.cpp:38
Scrollbar::SetCapacity
void SetCapacity(int capacity)
Set the capacity of visible elements.
Definition: widget_type.h:733
NWidgetSpacer::SetupSmallestSize
void SetupSmallestSize(Window *w, bool init_array) override
Definition: widget.cpp:1821
DrawFrame
static void DrawFrame(const Rect &r, Colours colour, TextColour text_colour, StringID str, StringAlignment align)
Draw a frame widget.
Definition: widget.cpp:675
NWidgetBackground::GetWidgetFromPos
NWidgetCore * GetWidgetFromPos(int x, int y) override
Definition: widget.cpp:2263
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:2058
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:1831
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:187
NWidgetPart::cont_flags
NWidContainerFlags cont_flags
Part with container flags.
Definition: widget_type.h:987
SBS_DOWN
@ SBS_DOWN
Sort ascending.
Definition: window_gui.h:160
WidgetDimensions
Definition: window_gui.h:40
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
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:342
NWidgetCore::disp_flags
NWidgetDisplay disp_flags
Flags that affect display and interaction with the widget.
Definition: widget_type.h:337
NWidgetCore::SetDataTip
void SetDataTip(uint32 widget_data, StringID tool_tip)
Set data and tool tip of the nested widget.
Definition: widget.cpp:1176
WD_FRAMETEXT_TOP
@ WD_FRAMETEXT_TOP
Top offset of the text of the frame.
Definition: widget.cpp:65
Window::IsShaded
bool IsShaded() const
Is window shaded currently?
Definition: window_gui.h:455
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:268
NWidgetBase::pos_x
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:199
NWidgetHorizontal
Horizontal container.
Definition: widget_type.h:500
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:2089
NWidgetMatrix::FillNestedArray
void FillNestedArray(NWidgetBase **array, uint length) override
Definition: widget.cpp:1965
NWidgetResizeBase::uz_text_spacing
uint8 uz_text_spacing
'Unscaled' text padding, stored for resize calculation.
Definition: widget_type.h:276
WWT_TEXT
@ WWT_TEXT
Pure simple text.
Definition: widget_type.h:56
NWidgetPIPContainer
Container with pre/inter/post child space.
Definition: widget_type.h:475
WidgetDimensions::hsep_indent
int hsep_indent
Width of identation for tree layouts.
Definition: window_gui.h:65
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:206
NWidgetBase::fill_x
uint fill_x
Horizontal fill stepsize (from initial size, 0 means not resizable).
Definition: widget_type.h:186
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:3194
WD_FRAMERECT_TOP
@ WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
Definition: widget.cpp:59
NWidgetScrollbar
Nested widget to display and control a scrollbar in a window.
Definition: widget_type.h:800
WidgetDimensions::fullbevel
RectPadding fullbevel
Always-scaled bevel border.
Definition: window_gui.h:46
geometry_func.hpp
PaletteID
uint32 PaletteID
The number of the palette.
Definition: gfx_type.h:18
NWidgetBackground::Draw
void Draw(const Window *w) override
Definition: widget.cpp:2226
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:2322
NWidgetPIPContainer::flags
NWidContainerFlags flags
Flags of the container.
Definition: widget_type.h:486
transparency.h
NWidgetPartTextColour::colour
TextColour colour
TextColour for DrawString.
Definition: widget_type.h:952
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:74
NWidgetPIPContainer::pip_post
uint8 pip_post
Amount of space after last widget.
Definition: widget_type.h:489
NWidgetStacked::SetupSmallestSize
void SetupSmallestSize(Window *w, bool init_array) override
Definition: widget.cpp:1306
WD_MATRIX_BOTTOM
@ WD_MATRIX_BOTTOM
Offset at bottom of a matrix cell.
Definition: widget.cpp:72
NWidgetBase::resize_y
uint resize_y
Vertical resize step (0 means not resizable).
Definition: widget_type.h:189
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:238
EventState
EventState
State of handling an event.
Definition: window_type.h:719
WD_STICKYBOX_BOTTOM
@ WD_STICKYBOX_BOTTOM
Bottom offset of sticky sprite.
Definition: widget.cpp:86
NWidgetVertical
Vertical container.
Definition: widget_type.h:523
NWidgetBackground::child
NWidgetPIPContainer * child
Child widget.
Definition: widget_type.h:610
Scrollbar::GetPosition
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:678
NWidgetPart::data_tip
NWidgetPartDataTip data_tip
Part with a data/tooltip.
Definition: widget_type.h:979
NWidgetContainer::FillNestedArray
void FillNestedArray(NWidgetBase **array, uint length) override
Definition: widget.cpp:1278
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:514
WidgetDimensions::bevel
RectPadding bevel
Widths of bevel border.
Definition: window_gui.h:45
NWidgetCore::colour
Colours colour
Colour of this widget.
Definition: widget_type.h:338
NWidgetMatrix::widget_h
int widget_h
The height of the child widget including inter spacing.
Definition: widget_type.h:563
NWidgetResizeBase::uz_text_lines
uint8 uz_text_lines
'Unscaled' text lines, stored for resize calculation.
Definition: widget_type.h:275
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:405
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:247
WD_DEFSIZEBOX_RIGHT
@ WD_DEFSIZEBOX_RIGHT
Right offset of defsize sprite.
Definition: widget.cpp:98
Window::DrawViewport
void DrawViewport() const
Draw the viewport of this window.
Definition: viewport.cpp:1825
WidgetDimensions::framerect
RectPadding framerect
Offsets within frame area.
Definition: window_gui.h:47
NWidgetCore::scrollbar_index
int scrollbar_index
Index of an attached scrollbar.
Definition: widget_type.h:342
SA_LEFT
@ SA_LEFT
Left align the text.
Definition: gfx_type.h:334
DrawFrameRect
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition: widget.cpp:414
NWidgetBase::SetDirty
virtual void SetDirty(const Window *w) const
Mark the widget as 'dirty' (in need of repaint).
Definition: widget.cpp:1024
WD_HSCROLLBAR_LEFT
@ WD_HSCROLLBAR_LEFT
Left offset of horizontal scrollbar.
Definition: widget.cpp:45
CenterBounds
static int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
Definition: gfx_func.h:178
SA_CENTER
@ SA_CENTER
Center both horizontally and vertically.
Definition: gfx_type.h:344
WD_DROPDOWN_HEIGHT
@ WD_DROPDOWN_HEIGHT
Height of a drop down widget.
Definition: widget.cpp:124
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition: fontcache.cpp:62
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:248
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:239
WD_MATRIX_RIGHT
@ WD_MATRIX_RIGHT
Offset at right of a matrix cell.
Definition: widget.cpp:70
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:2427
Window::SortButtonWidth
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition: widget.cpp:907
NWidgetHorizontalLTR::NWidgetHorizontalLTR
NWidgetHorizontalLTR(NWidContainerFlags flags=NC_NONE)
Horizontal left-to-right container widget.
Definition: widget.cpp:1640
NWidgetHorizontalLTR::AssignSizePosition
void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override
Definition: widget.cpp:1645
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:35
NWidgetResizeBase::min_x
uint min_x
Minimal horizontal size of only this widget.
Definition: widget_type.h:268
NWidgetBase::pos_y
int pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:200
NWidgetCore::align
StringAlignment align
Alignment of text/image within widget.
Definition: widget_type.h:345
Scrollbar::SS_BIG
@ SS_BIG
Step in cap units.
Definition: widget_type.h:649
WD_FRAMERECT_RIGHT
@ WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
Definition: widget.cpp:58
Scrollbar::SetStepSize
void SetStepSize(uint16 stepsize)
Set the distance to scroll when using the buttons or the wheel.
Definition: widget_type.h:706
NWidgetScrollbar::NWidgetScrollbar
NWidgetScrollbar(WidgetType tp, Colours colour, int index)
Scrollbar widget.
Definition: widget.cpp:2443
ND_SHADE_GREY
@ ND_SHADE_GREY
Bit value of the 'shade to grey' flag.
Definition: widget_type.h:302
WD_IMGBTN_RIGHT
@ WD_IMGBTN_RIGHT
Right offset of the image in the button.
Definition: widget.cpp:31
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:344
NWidgetPart::type
WidgetType type
Type of the part.
Definition: widget_type.h:976
WD_CLOSEBOX_LEFT
@ WD_CLOSEBOX_LEFT
Left offset of closebox string.
Definition: widget.cpp:111
NWidgetResizeBase::min_y
uint min_y
Minimal vertical size of only this widget.
Definition: widget_type.h:269
NWidgetHorizontalLTR
Horizontal container that doesn't change the direction of the widgets for RTL languages.
Definition: widget_type.h:512
DrawCaption
void DrawCaption(const Rect &r, Colours colour, Owner owner, TextColour text_colour, StringID str, StringAlignment align)
Draw a caption bar.
Definition: widget.cpp:804
CeilDiv
static uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
Definition: math_func.hpp:280
WD_DEFSIZEBOX_LEFT
@ WD_DEFSIZEBOX_LEFT
Left offset of defsize sprite.
Definition: widget.cpp:97
FontSize
FontSize
Available font sizes.
Definition: gfx_type.h:202
WD_DEFSIZEBOX_BOTTOM
@ WD_DEFSIZEBOX_BOTTOM
Bottom offset of defsize sprite.
Definition: widget.cpp:100
NWidgetMatrix::widget_w
int widget_w
The width of the child widget including inter spacing.
Definition: widget_type.h:562
NWidgetBackground::Add
void Add(NWidgetBase *nwid)
Add a child to the parent.
Definition: widget.cpp:2109
MAT_ROW_BITS
@ MAT_ROW_BITS
Number of bits for the number of rows in the matrix.
Definition: widget_type.h:30
WD_MATRIX_TOP
@ WD_MATRIX_TOP
Offset at top of a matrix cell.
Definition: widget.cpp:71
Window
Data structure for an opened window.
Definition: window_gui.h:213
SizingType
SizingType
Different forms of sizing nested widgets, using NWidgetBase::AssignSizePosition()
Definition: widget_type.h:111
NWidContainerFlags
NWidContainerFlags
Nested widget container flags,.
Definition: widget_type.h:464
SZSP_VERTICAL
@ SZSP_VERTICAL
Display plane with zero size horizontally, and filling and resizing vertically.
Definition: widget_type.h:426
WD_BEVEL_TOP
@ WD_BEVEL_TOP
Height of top bevel border.
Definition: widget.cpp:53
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:858
NWidgetResizeBase::absolute
bool absolute
Set if minimum size is fixed and should not be resized.
Definition: widget_type.h:271
ZOOM_LVL_OUT_4X
@ ZOOM_LVL_OUT_4X
Zoomed 4 times out.
Definition: zoom_type.h:24
NWidgetBackground
Nested widget with a child.
Definition: widget_type.h:591
Viewport::virtual_height
int virtual_height
height << zoom
Definition: viewport_type.h:31
WidgetDimensions::frametext
RectPadding frametext
Offsets within a text frame area.
Definition: window_gui.h:48
NWidgetVertical::NWidgetVertical
NWidgetVertical(NWidContainerFlags flags=NC_NONE)
Vertical container widget.
Definition: widget.cpp:1651
DrawImageButtons
static void DrawImageButtons(const Rect &r, WidgetType type, Colours colour, bool clicked, SpriteID img, StringAlignment align)
Draw an image button.
Definition: widget.cpp:471
NWidgetViewport::Draw
void Draw(const Window *w) override
Definition: widget.cpp:2296
Rect::Width
int Width() const
Get width of Rect.
Definition: geometry_type.hpp:79
SBS_OFF
@ SBS_OFF
Do not sort (with this button).
Definition: window_gui.h:159
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
WD_DEBUGBOX_WIDTH
@ WD_DEBUGBOX_WIDTH
Width of a standard debug box widget.
Definition: widget.cpp:89
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:260
GUISettings::scale_bevels
bool scale_bevels
bevels are scaled with GUI scale.
Definition: settings_type.h:199
NWidgetCore::index
int index
Index of the nested widget in the widget array of the window (-1 means 'not used').
Definition: widget_type.h:339
NWidgetMatrix::colour
Colours colour
Colour of this widget.
Definition: widget_type.h:557
NWidgetCore
Base class for a 'real' widget.
Definition: widget_type.h:316
WD_HSCROLLBAR_TOP
@ WD_HSCROLLBAR_TOP
Top offset of horizontal scrollbar.
Definition: widget.cpp:47
NWidgetLeaf::closebox_dimension
static Dimension closebox_dimension
Cached size of a closebox widget.
Definition: widget_type.h:833
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
WD_IMGBTN_LEFT
@ WD_IMGBTN_LEFT
Left offset of the image in the button.
Definition: widget.cpp:30
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:69
CursorVars::pos
Point pos
logical mouse position
Definition: gfx_type.h:117
NWidgetPartDataTip::tooltip
StringID tooltip
Tooltip of the widget.
Definition: widget_type.h:910
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:2838
NWidgetVertical::AssignSizePosition
void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override
Definition: widget.cpp:1722
NWidgetBase::resize_x
uint resize_x
Horizontal resize step (0 means not resizable).
Definition: widget_type.h:188
WD_CAPTIONTEXT_TOP
@ WD_CAPTIONTEXT_TOP
Offset of the caption text at the top.
Definition: widget.cpp:120
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:918
WidgetDimensions::vsep_wide
int vsep_wide
Wide vertical spacing.
Definition: window_gui.h:62
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:211
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:224
NWidgetPartTextLines::size
FontSize size
Font size of text lines.
Definition: widget_type.h:944
NWidgetBase::current_x
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:196
WD_FRAMERECT_LEFT
@ WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
Definition: widget.cpp:57
NWidgetStacked::shown_plane
int shown_plane
Plane being displayed (for NWID_SELECTION only).
Definition: widget_type.h:459
NWidgetMatrix::AssignSizePosition
void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override
Definition: widget.cpp:1941
WD_CLOSEBOX_RIGHT
@ WD_CLOSEBOX_RIGHT
Right offset of closebox string.
Definition: widget.cpp:112
WD_RESIZEBOX_WIDTH
@ WD_RESIZEBOX_WIDTH
Width of a resize box widget.
Definition: widget.cpp:103
NWidgetResizeBase::SetMinimalSize
void SetMinimalSize(uint min_x, uint min_y)
Set minimal size of the widget.
Definition: widget.cpp:1080
NWidgetScrollbar::horizontal_dimension
static Dimension horizontal_dimension
Cached size of horizontal scrollbar button.
Definition: widget_type.h:813
NWidgetLeaf::SetupSmallestSize
void SetupSmallestSize(Window *w, bool init_array) override
Definition: widget.cpp:2663
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:3004
NWidgetResizeBase::SetMinimalSizeAbsolute
void SetMinimalSizeAbsolute(uint min_x, uint min_y)
Set absolute (post-scaling) minimal size of the widget.
Definition: widget.cpp:1093
NWidgetScrollbar::Draw
void Draw(const Window *w) override
Definition: widget.cpp:2490
NWidgetCore::GetWidgetFromPos
NWidgetCore * GetWidgetFromPos(int x, int y) override
Definition: widget.cpp:1214
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:49
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:2976
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:3272
NWidgetCore::FillNestedArray
void FillNestedArray(NWidgetBase **array, uint length) override
Definition: widget.cpp:1209
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:1466
NWidgetBackground::FillNestedArray
void FillNestedArray(NWidgetBase **array, uint length) override
Definition: widget.cpp:2220
WD_STICKYBOX_TOP
@ WD_STICKYBOX_TOP
Top offset of sticky sprite.
Definition: widget.cpp:85
SetupWidgetDimensions
void SetupWidgetDimensions()
Set up pre-scaled versions of Widget Dimensions.
Definition: widget.cpp:199
WD_INSET_RIGHT
@ WD_INSET_RIGHT
Right offset of string.
Definition: widget.cpp:37
DrawInset
static void DrawInset(const Rect &r, Colours colour, TextColour text_colour, StringID str, StringAlignment align)
Draw an inset widget.
Definition: widget.cpp:521
NWidgetBase::padding
RectPadding padding
Padding added to the widget. Managed by parent container widget. (parent container may swap left and ...
Definition: widget_type.h:205
ND_SCROLLBAR_BTN
@ ND_SCROLLBAR_BTN
Bit value of the 'scrollbar up' or 'scrollbar down' flag.
Definition: widget_type.h:307
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:604
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:33
NWidgetPartDataTip::data
uint32 data
Data value of the widget.
Definition: widget_type.h:909
NWidgetMatrix::widgets_x
int widgets_x
The number of visible widgets in horizontal direction.
Definition: widget_type.h:564
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:301
DrawPixelInfo
Data about how and where to blit pixels.
Definition: gfx_type.h:151
NC_BIGFIRST
@ NC_BIGFIRST
Value of the NCB_BIGFIRST flag.
Definition: widget_type.h:470
NWidgetPart::text_lines
NWidgetPartTextLines text_lines
Part with text line data.
Definition: widget_type.h:983
NWidgetPartAlignment::align
StringAlignment align
Alignment of text/image.
Definition: widget_type.h:960
ScaleGUITrad
static RectPadding ScaleGUITrad(const RectPadding &r)
Scale a RectPadding to GUI zoom level.
Definition: widget.cpp:168
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:1864
WPT_ENDCONTAINER
@ WPT_ENDCONTAINER
Widget part to denote end of a container.
Definition: widget_type.h:94
WidgetDimensions::vsep_normal
int vsep_normal
Normal vertical spacing.
Definition: window_gui.h:61