OpenTTD Source: src/widget.cpp Source File

OpenTTD Source 14.0-beta1

widget.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #include "stdafx.h"
11 #include "core/backup_type.hpp"
12 #include "company_func.h"
13 #include "window_gui.h"
14 #include "viewport_func.h"
15 #include "zoom_func.h"
16 #include "strings_func.h"
17 #include "transparency.h"
18 #include "core/geometry_func.hpp"
19 #include "settings_type.h"
20 #include "querystring_gui.h"
21
22 #include "table/sprites.h"
23 #include "table/strings.h"
24 #include "table/string_colours.h"
25
26 #include "safeguards.h"
27
28 WidgetDimensions WidgetDimensions::scaled = {};
29
35 static inline RectPadding ScaleGUITrad(const RectPadding &r)
36 {
37 return {(uint8_t)ScaleGUITrad(r.left), (uint8_t)ScaleGUITrad(r.top), (uint8_t)ScaleGUITrad(r.right), (uint8_t)ScaleGUITrad(r.bottom)};
38 }
39
45 static inline Dimension ScaleGUITrad(const Dimension &dim)
46 {
47 return {(uint)ScaleGUITrad(dim.width), (uint)ScaleGUITrad(dim.height)};
48 }
49
54 Dimension GetScaledSpriteSize(SpriteID sprid)
55 {
56 Point offset;
57 Dimension d = GetSpriteSize(sprid, &offset, ZOOM_LVL_OUT_4X);
58 d.width -= offset.x;
59 d.height -= offset.y;
60 return ScaleGUITrad(d);
61 }
62
66 void SetupWidgetDimensions()
67 {
68 WidgetDimensions::scaled.imgbtn = ScaleGUITrad(WidgetDimensions::unscaled.imgbtn);
69 WidgetDimensions::scaled.inset = ScaleGUITrad(WidgetDimensions::unscaled.inset);
70 WidgetDimensions::scaled.vscrollbar = ScaleGUITrad(WidgetDimensions::unscaled.vscrollbar);
71 WidgetDimensions::scaled.hscrollbar = ScaleGUITrad(WidgetDimensions::unscaled.hscrollbar);
72 if (_settings_client.gui.scale_bevels) {
73 WidgetDimensions::scaled.bevel = ScaleGUITrad(WidgetDimensions::unscaled.bevel);
74 } else {
75 WidgetDimensions::scaled.bevel = WidgetDimensions::unscaled.bevel;
76 }
77 WidgetDimensions::scaled.fullbevel = ScaleGUITrad(WidgetDimensions::unscaled.fullbevel);
78 WidgetDimensions::scaled.framerect = ScaleGUITrad(WidgetDimensions::unscaled.framerect);
79 WidgetDimensions::scaled.frametext = ScaleGUITrad(WidgetDimensions::unscaled.frametext);
80 WidgetDimensions::scaled.matrix = ScaleGUITrad(WidgetDimensions::unscaled.matrix);
81 WidgetDimensions::scaled.shadebox = ScaleGUITrad(WidgetDimensions::unscaled.shadebox);
82 WidgetDimensions::scaled.stickybox = ScaleGUITrad(WidgetDimensions::unscaled.stickybox);
83 WidgetDimensions::scaled.debugbox = ScaleGUITrad(WidgetDimensions::unscaled.debugbox);
84 WidgetDimensions::scaled.defsizebox = ScaleGUITrad(WidgetDimensions::unscaled.defsizebox);
85 WidgetDimensions::scaled.resizebox = ScaleGUITrad(WidgetDimensions::unscaled.resizebox);
86 WidgetDimensions::scaled.closebox = ScaleGUITrad(WidgetDimensions::unscaled.closebox);
87 WidgetDimensions::scaled.captiontext = ScaleGUITrad(WidgetDimensions::unscaled.captiontext);
88 WidgetDimensions::scaled.dropdowntext = ScaleGUITrad(WidgetDimensions::unscaled.dropdowntext);
89 WidgetDimensions::scaled.dropdownlist = ScaleGUITrad(WidgetDimensions::unscaled.dropdownlist);
90 WidgetDimensions::scaled.modalpopup = ScaleGUITrad(WidgetDimensions::unscaled.modalpopup);
91
92 WidgetDimensions::scaled.vsep_normal = ScaleGUITrad(WidgetDimensions::unscaled.vsep_normal);
93 WidgetDimensions::scaled.vsep_wide = ScaleGUITrad(WidgetDimensions::unscaled.vsep_wide);
94 WidgetDimensions::scaled.hsep_normal = ScaleGUITrad(WidgetDimensions::unscaled.hsep_normal);
95 WidgetDimensions::scaled.hsep_wide = ScaleGUITrad(WidgetDimensions::unscaled.hsep_wide);
96 WidgetDimensions::scaled.hsep_indent = ScaleGUITrad(WidgetDimensions::unscaled.hsep_indent);
97 }
98
106 static inline Point GetAlignedPosition(const Rect &r, const Dimension &d, StringAlignment align)
107 {
108 Point p;
109 /* In case we have a RTL language we swap the alignment. */
110 if (!(align & SA_FORCE) && _current_text_dir == TD_RTL && (align & SA_HOR_MASK) != SA_HOR_CENTER) align ^= SA_RIGHT;
111 switch (align & SA_HOR_MASK) {
112 case SA_LEFT: p.x = r.left; break;
113 case SA_HOR_CENTER: p.x = CenterBounds(r.left, r.right, d.width); break;
114 case SA_RIGHT: p.x = r.right + 1 - d.width; break;
115 default: NOT_REACHED();
116 }
117 switch (align & SA_VERT_MASK) {
118 case SA_TOP: p.y = r.top; break;
119 case SA_VERT_CENTER: p.y = CenterBounds(r.top, r.bottom, d.height); break;
120 case SA_BOTTOM: p.y = r.bottom + 1 - d.height; break;
121 default: NOT_REACHED();
122 }
123 return p;
124 }
125
135 static Point HandleScrollbarHittest(const Scrollbar *sb, int top, int bottom, bool horizontal)
136 {
137 /* Base for reversion */
138 int rev_base = top + bottom;
139 int button_size;
140 if (horizontal) {
141 button_size = NWidgetScrollbar::GetHorizontalDimension().width;
142 } else {
143 button_size = NWidgetScrollbar::GetVerticalDimension().height;
144 }
145 top += button_size; // top points to just below the up-button
146 bottom -= button_size; // bottom points to top of the down-button
147
148 int height = (bottom - top);
149 int pos = sb->GetPosition();
150 int count = sb->GetCount();
151 int cap = sb->GetCapacity();
152
153 if (count != 0) top += height * pos / count;
154
155 if (cap > count) cap = count;
156 if (count != 0) bottom -= (count - pos - cap) * height / count;
157
158 Point pt;
159 if (horizontal && _current_text_dir == TD_RTL) {
160 pt.x = rev_base - bottom;
161 pt.y = rev_base - top;
162 } else {
163 pt.x = top;
164 pt.y = bottom;
165 }
166 return pt;
167 }
168
178 static void ScrollbarClickPositioning(Window *w, NWidgetScrollbar *sb, int x, int y, int mi, int ma)
179 {
180 int pos;
181 int button_size;
182 bool rtl = false;
183 bool changed = false;
184
185 if (sb->type == NWID_HSCROLLBAR) {
186 pos = x;
187 rtl = _current_text_dir == TD_RTL;
188 button_size = NWidgetScrollbar::GetHorizontalDimension().width;
189 } else {
190 pos = y;
191 button_size = NWidgetScrollbar::GetVerticalDimension().height;
192 }
193 if (pos < mi + button_size) {
194 /* Pressing the upper button? */
195 SetBit(sb->disp_flags, NDB_SCROLLBAR_UP);
196 if (_scroller_click_timeout <= 1) {
197 _scroller_click_timeout = 3;
198 changed = sb->UpdatePosition(rtl ? 1 : -1);
199 }
200 w->mouse_capture_widget = sb->index;
201 } else if (pos >= ma - button_size) {
202 /* Pressing the lower button? */
203 SetBit(sb->disp_flags, NDB_SCROLLBAR_DOWN);
204
205 if (_scroller_click_timeout <= 1) {
206 _scroller_click_timeout = 3;
207 changed = sb->UpdatePosition(rtl ? -1 : 1);
208 }
209 w->mouse_capture_widget = sb->index;
210 } else {
211 Point pt = HandleScrollbarHittest(sb, mi, ma, sb->type == NWID_HSCROLLBAR);
212
213 if (pos < pt.x) {
214 changed = sb->UpdatePosition(rtl ? 1 : -1, Scrollbar::SS_BIG);
215 } else if (pos > pt.y) {
216 changed = sb->UpdatePosition(rtl ? -1 : 1, Scrollbar::SS_BIG);
217 } else {
218 _scrollbar_start_pos = pt.x - mi - button_size;
219 _scrollbar_size = ma - mi - button_size * 2;
220 w->mouse_capture_widget = sb->index;
221 _cursorpos_drag_start = _cursor.pos;
222 }
223 }
224
225 if (changed) {
226 /* Position changed so refresh the window */
227 w->SetDirty();
228 } else {
229 /* No change so only refresh this scrollbar */
230 sb->SetDirty(w);
231 }
232 }
233
242 void ScrollbarClickHandler(Window *w, NWidgetCore *nw, int x, int y)
243 {
244 int mi, ma;
245
246 if (nw->type == NWID_HSCROLLBAR) {
247 mi = nw->pos_x;
248 ma = nw->pos_x + nw->current_x;
249 } else {
250 mi = nw->pos_y;
251 ma = nw->pos_y + nw->current_y;
252 }
253 NWidgetScrollbar *scrollbar = dynamic_cast<NWidgetScrollbar*>(nw);
254 assert(scrollbar != nullptr);
255 ScrollbarClickPositioning(w, scrollbar, x, y, mi, ma);
256 }
257
266 WidgetID GetWidgetFromPos(const Window *w, int x, int y)
267 {
268 NWidgetCore *nw = w->nested_root->GetWidgetFromPos(x, y);
269 return (nw != nullptr) ? nw->index : -1;
270 }
271
281 void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
282 {
283 assert(colour < COLOUR_END);
284
285 uint dark = _colour_gradient[colour][3];
286 uint medium_dark = _colour_gradient[colour][5];
287 uint medium_light = _colour_gradient[colour][6];
288 uint light = _colour_gradient[colour][7];
289
290 if (flags & FR_TRANSPARENT) {
291 GfxFillRect(left, top, right, bottom, PALETTE_TO_TRANSPARENT, FILLRECT_RECOLOUR);
292 } else {
293 uint interior;
294
295 Rect outer = {left, top, right, bottom}; // Outside rectangle
296 Rect inner = outer.Shrink(WidgetDimensions::scaled.bevel); // Inside rectangle
297
298 if (flags & FR_LOWERED) {
299 GfxFillRect(outer.left, outer.top, inner.left - 1, outer.bottom, dark); // Left
300 GfxFillRect(inner.left, outer.top, outer.right, inner.top - 1, dark); // Top
301 GfxFillRect(inner.right + 1, inner.top, outer.right, inner.bottom, light); // Right
302 GfxFillRect(inner.left, inner.bottom + 1, outer.right, outer.bottom, light); // Bottom
303 interior = (flags & FR_DARKENED ? medium_dark : medium_light);
304 } else {
305 GfxFillRect(outer.left, outer.top, inner.left - 1, inner.bottom, light); // Left
306 GfxFillRect(inner.left, outer.top, inner.right, inner.top - 1, light); // Top
307 GfxFillRect(inner.right + 1, outer.top, outer.right, inner.bottom, dark); // Right
308 GfxFillRect(outer.left, inner.bottom + 1, outer.right, outer.bottom, dark); // Bottom
309 interior = medium_dark;
310 }
311 if (!(flags & FR_BORDERONLY)) {
312 GfxFillRect(inner.left, inner.top, inner.right, inner.bottom, interior); // Inner
313 }
314 }
315 }
316
317 void DrawSpriteIgnorePadding(SpriteID img, PaletteID pal, const Rect &r, StringAlignment align)
318 {
319 Point offset;
320 Dimension d = GetSpriteSize(img, &offset);
321 d.width -= offset.x;
322 d.height -= offset.y;
323
324 Point p = GetAlignedPosition(r, d, align);
325 DrawSprite(img, pal, p.x - offset.x, p.y - offset.y);
326 }
327
337 static inline void DrawImageButtons(const Rect &r, WidgetType type, Colours colour, bool clicked, SpriteID img, StringAlignment align)
338 {
339 assert(img != 0);
340 DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE);
341
342 if ((type & WWT_MASK) == WWT_IMGBTN_2 && clicked) img++; // Show different image when clicked for #WWT_IMGBTN_2.
343 DrawSpriteIgnorePadding(img, PAL_NONE, r, align);
344 }
345
356 static inline void DrawLabel(const Rect &r, WidgetType type, bool clicked, TextColour colour, StringID str, StringAlignment align, FontSize fs)
357 {
358 if (str == STR_NULL) return;
359 if ((type & WWT_MASK) == WWT_TEXTBTN_2 && clicked) str++;
360 Dimension d = GetStringBoundingBox(str, fs);
361 Point p = GetAlignedPosition(r, d, align);
362 DrawString(r.left, r.right, p.y, str, colour, align, false, fs);
363 }
364
373 static inline void DrawText(const Rect &r, TextColour colour, StringID str, StringAlignment align, FontSize fs)
374 {
375 Dimension d = GetStringBoundingBox(str, fs);
376 Point p = GetAlignedPosition(r, d, align);
377 if (str != STR_NULL) DrawString(r.left, r.right, p.y, str, colour, align, false, fs);
378 }
379
389 static inline void DrawInset(const Rect &r, Colours colour, TextColour text_colour, StringID str, StringAlignment align, FontSize fs)
390 {
391 DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, FR_LOWERED | FR_DARKENED);
392 if (str != STR_NULL) DrawString(r.Shrink(WidgetDimensions::scaled.inset), str, text_colour, align, false, fs);
393 }
394
404 static inline void DrawMatrix(const Rect &r, Colours colour, bool clicked, uint16_t data, uint resize_x, uint resize_y)
405 {
406 DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE);
407
408 int num_columns = GB(data, MAT_COL_START, MAT_COL_BITS); // Lower 8 bits of the widget data: Number of columns in the matrix.
409 int column_width; // Width of a single column in the matrix.
410 if (num_columns == 0) {
411 column_width = resize_x;
412 num_columns = r.Width() / column_width;
413 } else {
414 column_width = r.Width() / num_columns;
415 }
416
417 int num_rows = GB(data, MAT_ROW_START, MAT_ROW_BITS); // Upper 8 bits of the widget data: Number of rows in the matrix.
418 int row_height; // Height of a single row in the matrix.
419 if (num_rows == 0) {
420 row_height = resize_y;
421 num_rows = r.Height() / row_height;
422 } else {
423 row_height = r.Height() / num_rows;
424 }
425
426 int col = _colour_gradient[colour & 0xF][6];
427
428 int x = r.left;
429 for (int ctr = num_columns; ctr > 1; ctr--) {
430 x += column_width;
431 GfxFillRect(x, r.top + WidgetDimensions::scaled.bevel.top, x + WidgetDimensions::scaled.bevel.left - 1, r.bottom - WidgetDimensions::scaled.bevel.bottom, col);
432 }
433
434 x = r.top;
435 for (int ctr = num_rows; ctr > 1; ctr--) {
436 x += row_height;
437 GfxFillRect(r.left + WidgetDimensions::scaled.bevel.left, x, r.right - WidgetDimensions::scaled.bevel.right, x + WidgetDimensions::scaled.bevel.top - 1, col);
438 }
439
440 col = _colour_gradient[colour & 0xF][4];
441
442 x = r.left - 1;
443 for (int ctr = num_columns; ctr > 1; ctr--) {
444 x += column_width;
445 GfxFillRect(x - WidgetDimensions::scaled.bevel.right + 1, r.top + WidgetDimensions::scaled.bevel.top, x, r.bottom - WidgetDimensions::scaled.bevel.bottom, col);
446 }
447
448 x = r.top - 1;
449 for (int ctr = num_rows; ctr > 1; ctr--) {
450 x += row_height;
451 GfxFillRect(r.left + WidgetDimensions::scaled.bevel.left, x - WidgetDimensions::scaled.bevel.bottom + 1, r.right - WidgetDimensions::scaled.bevel.right, x, col);
452 }
453 }
454
464 static inline void DrawVerticalScrollbar(const Rect &r, Colours colour, bool up_clicked, bool bar_dragged, bool down_clicked, const Scrollbar *scrollbar)
465 {
466 int height = NWidgetScrollbar::GetVerticalDimension().height;
467
468 /* draw up/down buttons */
469 DrawImageButtons(r.WithHeight(height, false), NWID_VSCROLLBAR, colour, up_clicked, SPR_ARROW_UP, SA_CENTER);
470 DrawImageButtons(r.WithHeight(height, true), NWID_VSCROLLBAR, colour, down_clicked, SPR_ARROW_DOWN, SA_CENTER);
471
472 int c1 = _colour_gradient[colour & 0xF][3];
473 int c2 = _colour_gradient[colour & 0xF][7];
474
475 /* draw "shaded" background */
476 GfxFillRect(r.left, r.top + height, r.right, r.bottom - height, c2);
477 GfxFillRect(r.left, r.top + height, r.right, r.bottom - height, c1, FILLRECT_CHECKER);
478
479 /* track positions. These fractions are based on original 1x dimensions, but scale better. */
480 int left = r.left + r.Width() * 3 / 11; /* left track is positioned 3/11ths from the left */
481 int right = r.left + r.Width() * 8 / 11; /* right track is positioned 8/11ths from the left */
482 const uint8_t bl = WidgetDimensions::scaled.bevel.left;
483 const uint8_t br = WidgetDimensions::scaled.bevel.right;
484
485 /* draw shaded lines */
486 GfxFillRect(left - bl, r.top + height, left - 1, r.bottom - height, c1);
487 GfxFillRect(left, r.top + height, left + br - 1, r.bottom - height, c2);
488 GfxFillRect(right - bl, r.top + height, right - 1, r.bottom - height, c1);
489 GfxFillRect(right, r.top + height, right + br - 1, r.bottom - height, c2);
490
491 Point pt = HandleScrollbarHittest(scrollbar, r.top, r.bottom, false);
492 DrawFrameRect(r.left, pt.x, r.right, pt.y, colour, bar_dragged ? FR_LOWERED : FR_NONE);
493 }
494
504 static inline void DrawHorizontalScrollbar(const Rect &r, Colours colour, bool left_clicked, bool bar_dragged, bool right_clicked, const Scrollbar *scrollbar)
505 {
506 int width = NWidgetScrollbar::GetHorizontalDimension().width;
507
508 DrawImageButtons(r.WithWidth(width, false), NWID_HSCROLLBAR, colour, left_clicked, SPR_ARROW_LEFT, SA_CENTER);
509 DrawImageButtons(r.WithWidth(width, true), NWID_HSCROLLBAR, colour, right_clicked, SPR_ARROW_RIGHT, SA_CENTER);
510
511 int c1 = _colour_gradient[colour & 0xF][3];
512 int c2 = _colour_gradient[colour & 0xF][7];
513
514 /* draw "shaded" background */
515 GfxFillRect(r.left + width, r.top, r.right - width, r.bottom, c2);
516 GfxFillRect(r.left + width, r.top, r.right - width, r.bottom, c1, FILLRECT_CHECKER);
517
518 /* track positions. These fractions are based on original 1x dimensions, but scale better. */
519 int top = r.top + r.Height() * 3 / 11; /* top track is positioned 3/11ths from the top */
520 int bottom = r.top + r.Height() * 8 / 11; /* bottom track is positioned 8/11ths from the top */
521 const uint8_t bt = WidgetDimensions::scaled.bevel.top;
522 const uint8_t bb = WidgetDimensions::scaled.bevel.bottom;
523
524 /* draw shaded lines */
525 GfxFillRect(r.left + width, top - bt, r.right - width, top - 1, c1);
526 GfxFillRect(r.left + width, top, r.right - width, top + bb - 1, c2);
527 GfxFillRect(r.left + width, bottom - bt, r.right - width, bottom - 1, c1);
528 GfxFillRect(r.left + width, bottom, r.right - width, bottom + bb - 1, c2);
529
530 /* draw actual scrollbar */
531 Point pt = HandleScrollbarHittest(scrollbar, r.left, r.right, true);
532 DrawFrameRect(pt.x, r.top, pt.y, r.bottom, colour, bar_dragged ? FR_LOWERED : FR_NONE);
533 }
534
544 static inline void DrawFrame(const Rect &r, Colours colour, TextColour text_colour, StringID str, StringAlignment align, FontSize fs)
545 {
546 int x2 = r.left; // by default the left side is the left side of the widget
547
548 if (str != STR_NULL) x2 = DrawString(r.left + WidgetDimensions::scaled.frametext.left, r.right - WidgetDimensions::scaled.frametext.right, r.top, str, text_colour, align, false, fs);
549
550 int c1 = _colour_gradient[colour][3];
551 int c2 = _colour_gradient[colour][7];
552
553 /* If the frame has text, adjust the top bar to fit half-way through */
554 Rect inner = r.Shrink(ScaleGUITrad(1));
555 if (str != STR_NULL) inner.top = r.top + GetCharacterHeight(FS_NORMAL) / 2;
556
557 Rect outer = inner.Expand(WidgetDimensions::scaled.bevel);
558 Rect inside = inner.Shrink(WidgetDimensions::scaled.bevel);
559
560 if (_current_text_dir == TD_LTR) {
561 /* Line from upper left corner to start of text */
562 GfxFillRect(outer.left, outer.top, r.left + WidgetDimensions::scaled.frametext.left - WidgetDimensions::scaled.bevel.left - 1, inner.top - 1, c1);
563 GfxFillRect(inner.left, inner.top, r.left + WidgetDimensions::scaled.frametext.left - WidgetDimensions::scaled.bevel.left - 1, inside.top - 1, c2);
564
565 /* Line from end of text to upper right corner */
566 GfxFillRect(x2 + WidgetDimensions::scaled.bevel.right, outer.top, inner.right, inner.top - 1, c1);
567 GfxFillRect(x2 + WidgetDimensions::scaled.bevel.right, inner.top, inside.right, inside.top - 1, c2);
568 } else {
569 /* Line from upper left corner to start of text */
570 GfxFillRect(outer.left, outer.top, x2 - WidgetDimensions::scaled.bevel.left - 1, inner.top - 1, c1);
571 GfxFillRect(inner.left, inner.top, x2 - WidgetDimensions::scaled.bevel.left - 1, inside.top - 1, c2);
572
573 /* Line from end of text to upper right corner */
574 GfxFillRect(r.right - WidgetDimensions::scaled.frametext.right + WidgetDimensions::scaled.bevel.right, outer.top, inner.right, inner.top - 1, c1);
575 GfxFillRect(r.right - WidgetDimensions::scaled.frametext.right + WidgetDimensions::scaled.bevel.right, inner.top, inside.right, inside.top - 1, c2);
576 }
577
578 /* Line from upper left corner to bottom left corner */
579 GfxFillRect(outer.left, inner.top, inner.left - 1, inner.bottom, c1);
580 GfxFillRect(inner.left, inside.top, inside.left - 1, inside.bottom, c2);
581
582 /* Line from upper right corner to bottom right corner */
583 GfxFillRect(inside.right + 1, inner.top, inner.right, inside.bottom, c1);
584 GfxFillRect(inner.right + 1, outer.top, outer.right, inner.bottom, c2);
585
586 /* Line from bottom left corner to bottom right corner */
587 GfxFillRect(inner.left, inside.bottom + 1, inner.right, inner.bottom, c1);
588 GfxFillRect(outer.left, inner.bottom + 1, outer.right, outer.bottom, c2);
589 }
590
597 static inline void DrawShadeBox(const Rect &r, Colours colour, bool clicked)
598 {
599 DrawImageButtons(r, WWT_SHADEBOX, colour, clicked, clicked ? SPR_WINDOW_SHADE: SPR_WINDOW_UNSHADE, SA_CENTER);
600 }
601
608 static inline void DrawStickyBox(const Rect &r, Colours colour, bool clicked)
609 {
610 DrawImageButtons(r, WWT_STICKYBOX, colour, clicked, clicked ? SPR_PIN_UP : SPR_PIN_DOWN, SA_CENTER);
611 }
612
619 static inline void DrawDefSizeBox(const Rect &r, Colours colour, bool clicked)
620 {
621 DrawImageButtons(r, WWT_DEFSIZEBOX, colour, clicked, SPR_WINDOW_DEFSIZE, SA_CENTER);
622 }
623
630 static inline void DrawDebugBox(const Rect &r, Colours colour, bool clicked)
631 {
632 DrawImageButtons(r, WWT_DEBUGBOX, colour, clicked, SPR_WINDOW_DEBUG, SA_CENTER);
633 }
634
643 static inline void DrawResizeBox(const Rect &r, Colours colour, bool at_left, bool clicked, bool bevel)
644 {
645 if (bevel) {
646 DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE);
647 } else if (clicked) {
648 GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), _colour_gradient[colour][6]);
649 }
650 DrawSpriteIgnorePadding(at_left ? SPR_WINDOW_RESIZE_LEFT : SPR_WINDOW_RESIZE_RIGHT, PAL_NONE, r.Shrink(ScaleGUITrad(2)), at_left ? (SA_LEFT | SA_BOTTOM | SA_FORCE) : (SA_RIGHT | SA_BOTTOM | SA_FORCE));
651 }
652
658 static inline void DrawCloseBox(const Rect &r, Colours colour)
659 {
660 if (colour != COLOUR_WHITE) DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, FR_NONE);
661 Point offset;
662 Dimension d = GetSpriteSize(SPR_CLOSEBOX, &offset);
663 d.width -= offset.x;
664 d.height -= offset.y;
665 int s = ScaleSpriteTrad(1); /* Offset to account for shadow of SPR_CLOSEBOX */
666 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);
667 }
668
679 void DrawCaption(const Rect &r, Colours colour, Owner owner, TextColour text_colour, StringID str, StringAlignment align, FontSize fs)
680 {
681 bool company_owned = owner < MAX_COMPANIES;
682
683 DrawFrameRect(r, colour, FR_BORDERONLY);
684 Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
685 DrawFrameRect(ir, colour, company_owned ? FR_LOWERED | FR_DARKENED | FR_BORDERONLY : FR_LOWERED | FR_DARKENED);
686
687 if (company_owned) {
688 GfxFillRect(ir.Shrink(WidgetDimensions::scaled.bevel), _colour_gradient[_company_colours[owner]][4]);
689 }
690
691 if (str != STR_NULL) {
692 Dimension d = GetStringBoundingBox(str);
693 Point p = GetAlignedPosition(r, d, align);
694 DrawString(r.left + WidgetDimensions::scaled.captiontext.left, r.right - WidgetDimensions::scaled.captiontext.left, p.y, str, text_colour, align, false, fs);
695 }
696 }
697
709 static inline void DrawButtonDropdown(const Rect &r, Colours colour, bool clicked_button, bool clicked_dropdown, StringID str, StringAlignment align)
710 {
711 int dd_width = NWidgetLeaf::dropdown_dimension.width;
712
713 if (_current_text_dir == TD_LTR) {
714 DrawFrameRect(r.left, r.top, r.right - dd_width, r.bottom, colour, clicked_button ? FR_LOWERED : FR_NONE);
715 DrawImageButtons(r.WithWidth(dd_width, true), WWT_DROPDOWN, colour, clicked_dropdown, SPR_ARROW_DOWN, SA_CENTER);
716 if (str != STR_NULL) {
717 DrawString(r.left + WidgetDimensions::scaled.dropdowntext.left, r.right - dd_width - WidgetDimensions::scaled.dropdowntext.right, CenterBounds(r.top, r.bottom, GetCharacterHeight(FS_NORMAL)), str, TC_BLACK, align);
718 }
719 } else {
720 DrawFrameRect(r.left + dd_width, r.top, r.right, r.bottom, colour, clicked_button ? FR_LOWERED : FR_NONE);
721 DrawImageButtons(r.WithWidth(dd_width, false), WWT_DROPDOWN, colour, clicked_dropdown, SPR_ARROW_DOWN, SA_CENTER);
722 if (str != STR_NULL) {
723 DrawString(r.left + dd_width + WidgetDimensions::scaled.dropdowntext.left, r.right - WidgetDimensions::scaled.dropdowntext.right, CenterBounds(r.top, r.bottom, GetCharacterHeight(FS_NORMAL)), str, TC_BLACK, align);
724 }
725 }
726 }
727
731 void Window::DrawWidgets() const
732 {
733 this->nested_root->Draw(this);
734
735 if (this->flags & WF_WHITE_BORDER) {
736 DrawFrameRect(0, 0, this->width - 1, this->height - 1, COLOUR_WHITE, FR_BORDERONLY);
737 }
738
739 if (this->flags & WF_HIGHLIGHTED) {
740 extern bool _window_highlight_colour;
741 for (const auto &pair : this->widget_lookup) {
742 const NWidgetBase *widget = pair.second;
743 if (!widget->IsHighlighted()) continue;
744
745 Rect outer = widget->GetCurrentRect();
746 Rect inner = outer.Shrink(WidgetDimensions::scaled.bevel).Expand(1);
747
748 int colour = _string_colourmap[_window_highlight_colour ? widget->GetHighlightColour() : TC_WHITE];
749
750 GfxFillRect(outer.left, outer.top, inner.left, inner.bottom, colour);
751 GfxFillRect(inner.left + 1, outer.top, inner.right - 1, inner.top, colour);
752 GfxFillRect(inner.right, outer.top, outer.right, inner.bottom, colour);
753 GfxFillRect(outer.left + 1, inner.bottom, outer.right - 1, outer.bottom, colour);
754 }
755 }
756 }
757
763 void Window::DrawSortButtonState(WidgetID widget, SortButtonState state) const
764 {
765 if (state == SBS_OFF) return;
766
767 assert(!this->widget_lookup.empty());
768 Rect r = this->GetWidget<NWidgetBase>(widget)->GetCurrentRect();
769
770 /* Sort button uses the same sprites as vertical scrollbar */
771 Dimension dim = NWidgetScrollbar::GetVerticalDimension();
772
773 DrawSpriteIgnorePadding(state == SBS_DOWN ? SPR_ARROW_DOWN : SPR_ARROW_UP, PAL_NONE, r.WithWidth(dim.width, _current_text_dir == TD_LTR), SA_CENTER);
774 }
775
780 int Window::SortButtonWidth()
781 {
782 return NWidgetScrollbar::GetVerticalDimension().width + 1;
783 }
784
785 bool _draw_widget_outlines;
786
787 static void DrawOutline(const Window *, const NWidgetBase *wid)
788 {
789 if (!_draw_widget_outlines || wid->current_x == 0 || wid->current_y == 0) return;
790
791 DrawRectOutline(wid->GetCurrentRect(), PC_WHITE, 1, 4);
792 }
793
851 NWidgetBase::NWidgetBase(WidgetType tp) : ZeroedMemoryAllocator()
852 {
853 this->type = tp;
854 }
855
856 /* ~NWidgetContainer() takes care of #next and #prev data members. */
857
903 void NWidgetBase::SetDirty(const Window *w) const
904 {
905 int abs_left = w->left + this->pos_x;
906 int abs_top = w->top + this->pos_y;
907 AddDirtyBlock(abs_left, abs_top, abs_left + this->current_x, abs_top + this->current_y);
908 }
909
923 NWidgetBase *NWidgetBase::GetWidgetOfType(WidgetType tp)
924 {
925 return (this->type == tp) ? this : nullptr;
926 }
927
928 void NWidgetBase::AdjustPaddingForZoom()
929 {
930 this->padding = ScaleGUITrad(this->uz_padding);
931 }
932
939 NWidgetResizeBase::NWidgetResizeBase(WidgetType tp, uint fill_x, uint fill_y) : NWidgetBase(tp)
940 {
941 this->fill_x = fill_x;
942 this->fill_y = fill_y;
943 }
944
945 void NWidgetResizeBase::AdjustPaddingForZoom()
946 {
947 if (!this->absolute) {
948 this->min_x = ScaleGUITrad(this->uz_min_x);
949 this->min_y = std::max(ScaleGUITrad(this->uz_min_y), this->uz_text_lines * GetCharacterHeight(this->uz_text_size) + ScaleGUITrad(this->uz_text_spacing));
950 }
951 NWidgetBase::AdjustPaddingForZoom();
952 }
953
959 void NWidgetResizeBase::SetMinimalSize(uint min_x, uint min_y)
960 {
961 this->uz_min_x = std::max(this->uz_min_x, min_x);
962 this->uz_min_y = std::max(this->uz_min_y, min_y);
963 this->min_x = ScaleGUITrad(this->uz_min_x);
964 this->min_y = std::max(ScaleGUITrad(this->uz_min_y), this->uz_text_lines * GetCharacterHeight(this->uz_text_size) + ScaleGUITrad(this->uz_text_spacing));
965 }
966
972 void NWidgetResizeBase::SetMinimalSizeAbsolute(uint min_x, uint min_y)
973 {
974 this->absolute = true;
975 this->min_x = std::max(this->min_x, min_x);
976 this->min_y = std::max(this->min_y, min_y);
977 }
978
985 void NWidgetResizeBase::SetMinimalTextLines(uint8_t min_lines, uint8_t spacing, FontSize size)
986 {
987 this->uz_text_lines = min_lines;
988 this->uz_text_spacing = spacing;
989 this->uz_text_size = size;
990 this->min_y = std::max(ScaleGUITrad(this->uz_min_y), this->uz_text_lines * GetCharacterHeight(this->uz_text_size) + ScaleGUITrad(this->uz_text_spacing));
991 }
992
998 void NWidgetResizeBase::SetFill(uint fill_x, uint fill_y)
999 {
1000 this->fill_x = fill_x;
1001 this->fill_y = fill_y;
1002 }
1003
1009 void NWidgetResizeBase::SetResize(uint resize_x, uint resize_y)
1010 {
1011 this->resize_x = resize_x;
1012 this->resize_y = resize_y;
1013 }
1014
1022 bool NWidgetResizeBase::UpdateMultilineWidgetSize(const std::string &str, int max_lines)
1023 {
1024 int y = GetStringHeight(str, this->current_x);
1025 if (y > max_lines * GetCharacterHeight(FS_NORMAL)) {
1026 /* Text at the current width is too tall, so try to guess a better width. */
1027 Dimension d = GetStringBoundingBox(str);
1028 d.height *= max_lines;
1029 d.width /= 2;
1030 return this->UpdateSize(d.width, d.height);
1031 }
1032 return this->UpdateVerticalSize(y);
1033 }
1034
1042 bool NWidgetResizeBase::UpdateSize(uint min_x, uint min_y)
1043 {
1044 if (min_x == this->min_x && min_y == this->min_y) return false;
1045 this->min_x = min_x;
1046 this->min_y = min_y;
1047 return true;
1048 }
1049
1056 bool NWidgetResizeBase::UpdateVerticalSize(uint min_y)
1057 {
1058 if (min_y == this->min_y) return false;
1059 this->min_y = min_y;
1060 return true;
1061 }
1062
1063 void NWidgetResizeBase::AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool)
1064 {
1065 this->StoreSizePosition(sizing, x, y, given_width, given_height);
1066 }
1067
1078 NWidgetCore::NWidgetCore(WidgetType tp, Colours colour, WidgetID index, uint fill_x, uint fill_y, uint32_t widget_data, StringID tool_tip) : NWidgetResizeBase(tp, fill_x, fill_y), index(index)
1079 {
1080 this->colour = colour;
1081 this->widget_data = widget_data;
1082 this->tool_tip = tool_tip;
1083 this->scrollbar_index = -1;
1084 this->text_colour = tp == WWT_CAPTION ? TC_WHITE : TC_BLACK;
1085 this->text_size = FS_NORMAL;
1086 this->align = SA_CENTER;
1087 }
1088
1094 void NWidgetCore::SetDataTip(uint32_t widget_data, StringID tool_tip)
1095 {
1096 this->widget_data = widget_data;
1097 this->tool_tip = tool_tip;
1098 }
1099
1105 void NWidgetCore::SetTextStyle(TextColour colour, FontSize size)
1106 {
1107 this->text_colour = colour;
1108 this->text_size = size;
1109 }
1110
1115 void NWidgetCore::SetToolTip(StringID tool_tip)
1116 {
1117 this->tool_tip = tool_tip;
1118 }
1119
1124 void NWidgetCore::SetAlignment(StringAlignment align)
1125 {
1126 this->align = align;
1127 }
1128
1129 void NWidgetCore::FillWidgetLookup(WidgetLookup &widget_lookup)
1130 {
1131 if (this->index >= 0) widget_lookup[this->index] = this;
1132 }
1133
1134 NWidgetCore *NWidgetCore::GetWidgetFromPos(int x, int y)
1135 {
1136 return (IsInsideBS(x, this->pos_x, this->current_x) && IsInsideBS(y, this->pos_y, this->current_y)) ? this : nullptr;
1137 }
1138
1139 NWidgetBase *NWidgetContainer::GetWidgetOfType(WidgetType tp)
1140 {
1141 if (this->type == tp) return this;
1142 for (const auto &child_wid : this->children) {
1143 NWidgetBase *nwid = child_wid->GetWidgetOfType(tp);
1144 if (nwid != nullptr) return nwid;
1145 }
1146 return nullptr;
1147 }
1148
1149 void NWidgetContainer::AdjustPaddingForZoom()
1150 {
1151 for (const auto &child_wid : this->children) {
1152 child_wid->AdjustPaddingForZoom();
1153 }
1154 NWidgetBase::AdjustPaddingForZoom();
1155 }
1156
1161 void NWidgetContainer::Add(std::unique_ptr<NWidgetBase> &&wid)
1162 {
1163 assert(wid != nullptr);
1164 wid->parent = this;
1165 this->children.push_back(std::move(wid));
1166 }
1167
1168 void NWidgetContainer::FillWidgetLookup(WidgetLookup &widget_lookup)
1169 {
1170 for (const auto &child_wid : this->children) {
1171 child_wid->FillWidgetLookup(widget_lookup);
1172 }
1173 }
1174
1175 void NWidgetContainer::Draw(const Window *w)
1176 {
1177 for (const auto &child_wid : this->children) {
1178 child_wid->Draw(w);
1179 }
1180
1181 DrawOutline(w, this);
1182 }
1183
1184 NWidgetCore *NWidgetContainer::GetWidgetFromPos(int x, int y)
1185 {
1186 if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return nullptr;
1187
1188 for (const auto &child_wid : this->children) {
1189 NWidgetCore *nwid = child_wid->GetWidgetFromPos(x, y);
1190 if (nwid != nullptr) return nwid;
1191 }
1192 return nullptr;
1193 }
1194
1198 NWidgetStacked::NWidgetStacked(WidgetID index) : NWidgetContainer(NWID_SELECTION), index(index)
1199 {
1200 }
1201
1202 void NWidgetStacked::AdjustPaddingForZoom()
1203 {
1204 for (const auto &child_wid : this->children) {
1205 child_wid->AdjustPaddingForZoom();
1206 }
1207 NWidgetContainer::AdjustPaddingForZoom();
1208 }
1209
1210 void NWidgetStacked::SetupSmallestSize(Window *w)
1211 {
1212 /* Zero size plane selected */
1213 if (this->shown_plane >= SZSP_BEGIN) {
1214 Dimension size = {0, 0};
1215 Dimension padding = {0, 0};
1216 Dimension fill = {(this->shown_plane == SZSP_HORIZONTAL), (this->shown_plane == SZSP_VERTICAL)};
1217 Dimension resize = {(this->shown_plane == SZSP_HORIZONTAL), (this->shown_plane == SZSP_VERTICAL)};
1218 /* Here we're primarily interested in the value of resize */
1219 if (this->index >= 0) w->UpdateWidgetSize(this->index, &size, padding, &fill, &resize);
1220
1221 this->smallest_x = size.width;
1222 this->smallest_y = size.height;
1223 this->fill_x = fill.width;
1224 this->fill_y = fill.height;
1225 this->resize_x = resize.width;
1226 this->resize_y = resize.height;
1227 return;
1228 }
1229
1230 /* First sweep, recurse down and compute minimal size and filling. */
1231 this->smallest_x = 0;
1232 this->smallest_y = 0;
1233 this->fill_x = this->IsEmpty() ? 0 : 1;
1234 this->fill_y = this->IsEmpty() ? 0 : 1;
1235 this->resize_x = this->IsEmpty() ? 0 : 1;
1236 this->resize_y = this->IsEmpty() ? 0 : 1;
1237 for (const auto &child_wid : this->children) {
1238 child_wid->SetupSmallestSize(w);
1239
1240 this->smallest_x = std::max(this->smallest_x, child_wid->smallest_x + child_wid->padding.Horizontal());
1241 this->smallest_y = std::max(this->smallest_y, child_wid->smallest_y + child_wid->padding.Vertical());
1242 this->fill_x = std::lcm(this->fill_x, child_wid->fill_x);
1243 this->fill_y = std::lcm(this->fill_y, child_wid->fill_y);
1244 this->resize_x = std::lcm(this->resize_x, child_wid->resize_x);
1245 this->resize_y = std::lcm(this->resize_y, child_wid->resize_y);
1246 }
1247 }
1248
1249 void NWidgetStacked::AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl)
1250 {
1251 assert(given_width >= this->smallest_x && given_height >= this->smallest_y);
1252 this->StoreSizePosition(sizing, x, y, given_width, given_height);
1253
1254 if (this->shown_plane >= SZSP_BEGIN) return;
1255
1256 for (const auto &child_wid : this->children) {
1257 uint hor_step = (sizing == ST_SMALLEST) ? 1 : child_wid->GetHorizontalStepSize(sizing);
1258 uint child_width = ComputeMaxSize(child_wid->smallest_x, given_width - child_wid->padding.Horizontal(), hor_step);
1259 uint child_pos_x = (rtl ? child_wid->padding.right : child_wid->padding.left);
1260
1261 uint vert_step = (sizing == ST_SMALLEST) ? 1 : child_wid->GetVerticalStepSize(sizing);
1262 uint child_height = ComputeMaxSize(child_wid->smallest_y, given_height - child_wid->padding.Vertical(), vert_step);
1263 uint child_pos_y = child_wid->padding.top;
1264
1265 child_wid->AssignSizePosition(sizing, x + child_pos_x, y + child_pos_y, child_width, child_height, rtl);
1266 }
1267 }
1268
1269 void NWidgetStacked::FillWidgetLookup(WidgetLookup &widget_lookup)
1270 {
1271 if (this->index >= 0) widget_lookup[this->index] = this;
1272 NWidgetContainer::FillWidgetLookup(widget_lookup);
1273 }
1274
1275 void NWidgetStacked::Draw(const Window *w)
1276 {
1277 if (this->shown_plane >= SZSP_BEGIN) return;
1278
1279 assert(static_cast<size_t>(this->shown_plane) < this->children.size());
1280 this->children[shown_plane]->Draw(w);
1281 DrawOutline(w, this);
1282 }
1283
1284 NWidgetCore *NWidgetStacked::GetWidgetFromPos(int x, int y)
1285 {
1286 if (this->shown_plane >= SZSP_BEGIN) return nullptr;
1287
1288 if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return nullptr;
1289
1290 if (static_cast<size_t>(this->shown_plane) >= this->children.size()) return nullptr;
1291 return this->children[shown_plane]->GetWidgetFromPos(x, y);
1292 }
1293
1299 bool NWidgetStacked::SetDisplayedPlane(int plane)
1300 {
1301 if (this->shown_plane == plane) return false;
1302 this->shown_plane = plane;
1303 return true;
1304 }
1305
1306 NWidgetPIPContainer::NWidgetPIPContainer(WidgetType tp, NWidContainerFlags flags) : NWidgetContainer(tp)
1307 {
1308 this->flags = flags;
1309 }
1310
1311 void NWidgetPIPContainer::AdjustPaddingForZoom()
1312 {
1313 this->pip_pre = ScaleGUITrad(this->uz_pip_pre);
1314 this->pip_inter = ScaleGUITrad(this->uz_pip_inter);
1315 this->pip_post = ScaleGUITrad(this->uz_pip_post);
1316 NWidgetContainer::AdjustPaddingForZoom();
1317 }
1318
1328 void NWidgetPIPContainer::SetPIP(uint8_t pip_pre, uint8_t pip_inter, uint8_t pip_post)
1329 {
1330 this->uz_pip_pre = pip_pre;
1331 this->uz_pip_inter = pip_inter;
1332 this->uz_pip_post = pip_post;
1333
1334 this->pip_pre = ScaleGUITrad(this->uz_pip_pre);
1335 this->pip_inter = ScaleGUITrad(this->uz_pip_inter);
1336 this->pip_post = ScaleGUITrad(this->uz_pip_post);
1337 }
1338
1348 void NWidgetPIPContainer::SetPIPRatio(uint8_t pip_ratio_pre, uint8_t pip_ratio_inter, uint8_t pip_ratio_post)
1349 {
1350 this->pip_ratio_pre = pip_ratio_pre;
1351 this->pip_ratio_inter = pip_ratio_inter;
1352 this->pip_ratio_post = pip_ratio_post;
1353 }
1354
1356 NWidgetHorizontal::NWidgetHorizontal(NWidContainerFlags flags) : NWidgetPIPContainer(NWID_HORIZONTAL, flags)
1357 {
1358 }
1359
1360 void NWidgetHorizontal::SetupSmallestSize(Window *w)
1361 {
1362 this->smallest_x = 0; // Sum of minimal size of all children.
1363 this->smallest_y = 0; // Biggest child.
1364 this->fill_x = 0; // smallest non-zero child widget fill step.
1365 this->fill_y = 1; // smallest common child fill step.
1366 this->resize_x = 0; // smallest non-zero child widget resize step.
1367 this->resize_y = 1; // smallest common child resize step.
1368 this->gaps = 0;
1369
1370 /* 1a. Forward call, collect longest/widest child length. */
1371 uint longest = 0; // Longest child found.
1372 uint max_vert_fill = 0; // Biggest vertical fill step.
1373 for (const auto &child_wid : this->children) {
1374 child_wid->SetupSmallestSize(w);
1375 longest = std::max(longest, child_wid->smallest_x);
1376 max_vert_fill = std::max(max_vert_fill, child_wid->GetVerticalStepSize(ST_SMALLEST));
1377 this->smallest_y = std::max(this->smallest_y, child_wid->smallest_y + child_wid->padding.Vertical());
1378 if (child_wid->smallest_x != 0 || child_wid->fill_x != 0) this->gaps++;
1379 }
1380 if (this->gaps > 0) this->gaps--; // Number of gaps is number of widgets less one.
1381 /* 1b. Make the container higher if needed to accommodate all children nicely. */
1382 [[maybe_unused]] uint max_smallest = this->smallest_y + 3 * max_vert_fill; // Upper limit to computing smallest height.
1383 uint cur_height = this->smallest_y;
1384 for (;;) {
1385 for (const auto &child_wid : this->children) {
1386 uint step_size = child_wid->GetVerticalStepSize(ST_SMALLEST);
1387 uint child_height = child_wid->smallest_y + child_wid->padding.Vertical();
1388 if (step_size > 1 && child_height < cur_height) { // Small step sizes or already fitting children are not interesting.
1389 uint remainder = (cur_height - child_height) % step_size;
1390 if (remainder > 0) { // Child did not fit entirely, widen the container.
1391 cur_height += step_size - remainder;
1392 assert(cur_height < max_smallest); // Safeguard against infinite height expansion.
1393 /* Remaining children will adapt to the new cur_height, thus speeding up the computation. */
1394 }
1395 }
1396 }
1397 if (this->smallest_y == cur_height) break;
1398 this->smallest_y = cur_height; // Smallest height got changed, try again.
1399 }
1400 /* 2. For containers that must maintain equal width, extend child minimal size. */
1401 if (this->flags & NC_EQUALSIZE) {
1402 for (const auto &child_wid : this->children) {
1403 if (child_wid->fill_x == 1) child_wid->smallest_x = longest;
1404 }
1405 }
1406 /* 3. Compute smallest, fill, and resize values of the container. */
1407 for (const auto &child_wid : this->children) {
1408 this->smallest_x += child_wid->smallest_x + child_wid->padding.Horizontal();
1409 if (child_wid->fill_x > 0) {
1410 if (this->fill_x == 0 || this->fill_x > child_wid->fill_x) this->fill_x = child_wid->fill_x;
1411 }
1412 this->fill_y = std::lcm(this->fill_y, child_wid->fill_y);
1413
1414 if (child_wid->resize_x > 0) {
1415 if (this->resize_x == 0 || this->resize_x > child_wid->resize_x) this->resize_x = child_wid->resize_x;
1416 }
1417 this->resize_y = std::lcm(this->resize_y, child_wid->resize_y);
1418 }
1419 if (this->fill_x == 0 && this->pip_ratio_pre + this->pip_ratio_inter + this->pip_ratio_post > 0) this->fill_x = 1;
1420 /* 4. Increase by required PIP space. */
1421 this->smallest_x += this->pip_pre + this->gaps * this->pip_inter + this->pip_post;
1422 }
1423
1424 void NWidgetHorizontal::AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl)
1425 {
1426 assert(given_width >= this->smallest_x && given_height >= this->smallest_y);
1427
1428 /* Compute additional width given to us. */
1429 uint additional_length = given_width - (this->pip_pre + this->gaps * this->pip_inter + this->pip_post);
1430 for (const auto &child_wid : this->children) {
1431 if (child_wid->smallest_x != 0 || child_wid->fill_x != 0) additional_length -= child_wid->smallest_x + child_wid->padding.Horizontal();
1432 }
1433
1434 this->StoreSizePosition(sizing, x, y, given_width, given_height);
1435
1436 /* In principle, the additional horizontal space is distributed evenly over the available resizable children. Due to step sizes, this may not always be feasible.
1437 * To make resizing work as good as possible, first children with biggest step sizes are done. These may get less due to rounding down.
1438 * 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
1439 * of the child with the smallest non-zero stepsize.
1440 *
1441 * 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
1442 * size and position, and directly call child->AssignSizePosition() with the computed values.
1443 * 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
1444 * then we call the child.
1445 */
1446
1447 /* First loop: Find biggest stepsize, find number of children that want a piece of the pie, handle vertical size for all children,
1448 * handle horizontal size for non-resizing children.
1449 */
1450 int num_changing_childs = 0; // Number of children that can change size.
1451 uint biggest_stepsize = 0;
1452 for (const auto &child_wid : this->children) {
1453 uint hor_step = child_wid->GetHorizontalStepSize(sizing);
1454 if (hor_step > 0) {
1455 if (!(flags & NC_BIGFIRST)) num_changing_childs++;
1456 biggest_stepsize = std::max(biggest_stepsize, hor_step);
1457 } else {
1458 child_wid->current_x = child_wid->smallest_x;
1459 }
1460
1461 uint vert_step = (sizing == ST_SMALLEST) ? 1 : child_wid->GetVerticalStepSize(sizing);
1462 child_wid->current_y = ComputeMaxSize(child_wid->smallest_y, given_height - child_wid->padding.Vertical(), vert_step);
1463 }
1464
1465 /* First.5 loop: count how many children are of the biggest step size. */
1466 if ((flags & NC_BIGFIRST) && biggest_stepsize > 0) {
1467 for (const auto &child_wid : this->children) {
1468 uint hor_step = child_wid->GetHorizontalStepSize(sizing);
1469 if (hor_step == biggest_stepsize) {
1470 num_changing_childs++;
1471 }
1472 }
1473 }
1474
1475 /* Second loop: Allocate the additional horizontal space over the resizing children, starting with the biggest resize steps. */
1476 while (biggest_stepsize > 0) {
1477 uint next_biggest_stepsize = 0;
1478 for (const auto &child_wid : this->children) {
1479 uint hor_step = child_wid->GetHorizontalStepSize(sizing);
1480 if (hor_step > biggest_stepsize) continue; // Already done
1481 if (hor_step == biggest_stepsize) {
1482 uint increment = additional_length / num_changing_childs;
1483 num_changing_childs--;
1484 if (hor_step > 1) increment -= increment % hor_step;
1485 child_wid->current_x = child_wid->smallest_x + increment;
1486 additional_length -= increment;
1487 continue;
1488 }
1489 next_biggest_stepsize = std::max(next_biggest_stepsize, hor_step);
1490 }
1491 biggest_stepsize = next_biggest_stepsize;
1492
1493 if (num_changing_childs == 0 && (flags & NC_BIGFIRST) && biggest_stepsize > 0) {
1494 /* Second.5 loop: count how many children are of the updated biggest step size. */
1495 for (const auto &child_wid : this->children) {
1496 uint hor_step = child_wid->GetHorizontalStepSize(sizing);
1497 if (hor_step == biggest_stepsize) {
1498 num_changing_childs++;
1499 }
1500 }
1501 }
1502 }
1503 assert(num_changing_childs == 0);
1504
1505 uint pre = this->pip_pre;
1506 uint inter = this->pip_inter;
1507
1508 if (additional_length > 0) {
1509 /* Allocate remaining space by pip ratios. If this doesn't round exactly, the unused space will fall into pip_post
1510 * which is never explicitly needed. */
1511 int r = this->pip_ratio_pre + this->gaps * this->pip_ratio_inter + this->pip_ratio_post;
1512 if (r > 0) {
1513 pre += this->pip_ratio_pre * additional_length / r;
1514 if (this->gaps > 0) inter += this->pip_ratio_inter * additional_length / r;
1515 }
1516 }
1517
1518 /* Third loop: Compute position and call the child. */
1519 uint position = rtl ? this->current_x - pre : pre; // Place to put next child relative to origin of the container.
1520 for (const auto &child_wid : this->children) {
1521 uint child_width = child_wid->current_x;
1522 uint child_x = x + (rtl ? position - child_width - child_wid->padding.left : position + child_wid->padding.left);
1523 uint child_y = y + child_wid->padding.top;
1524
1525 child_wid->AssignSizePosition(sizing, child_x, child_y, child_width, child_wid->current_y, rtl);
1526 if (child_wid->current_x != 0) {
1527 uint padded_child_width = child_width + child_wid->padding.Horizontal() + inter;
1528 position = rtl ? position - padded_child_width : position + padded_child_width;
1529 }
1530 }
1531 }
1532
1534 NWidgetHorizontalLTR::NWidgetHorizontalLTR(NWidContainerFlags flags) : NWidgetHorizontal(flags)
1535 {
1536 this->type = NWID_HORIZONTAL_LTR;
1537 }
1538
1539 void NWidgetHorizontalLTR::AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool)
1540 {
1541 NWidgetHorizontal::AssignSizePosition(sizing, x, y, given_width, given_height, false);
1542 }
1543
1545 NWidgetVertical::NWidgetVertical(NWidContainerFlags flags) : NWidgetPIPContainer(NWID_VERTICAL, flags)
1546 {
1547 }
1548
1549 void NWidgetVertical::SetupSmallestSize(Window *w)
1550 {
1551 this->smallest_x = 0; // Biggest child.
1552 this->smallest_y = 0; // Sum of minimal size of all children.
1553 this->fill_x = 1; // smallest common child fill step.
1554 this->fill_y = 0; // smallest non-zero child widget fill step.
1555 this->resize_x = 1; // smallest common child resize step.
1556 this->resize_y = 0; // smallest non-zero child widget resize step.
1557 this->gaps = 0;
1558
1559 /* 1a. Forward call, collect longest/widest child length. */
1560 uint highest = 0; // Highest child found.
1561 uint max_hor_fill = 0; // Biggest horizontal fill step.
1562 for (const auto &child_wid : this->children) {
1563 child_wid->SetupSmallestSize(w);
1564 highest = std::max(highest, child_wid->smallest_y);
1565 max_hor_fill = std::max(max_hor_fill, child_wid->GetHorizontalStepSize(ST_SMALLEST));
1566 this->smallest_x = std::max(this->smallest_x, child_wid->smallest_x + child_wid->padding.Horizontal());
1567 if (child_wid->smallest_y != 0 || child_wid->fill_y != 0) this->gaps++;
1568 }
1569 if (this->gaps > 0) this->gaps--; // Number of gaps is number of widgets less one.
1570 /* 1b. Make the container wider if needed to accommodate all children nicely. */
1571 [[maybe_unused]] uint max_smallest = this->smallest_x + 3 * max_hor_fill; // Upper limit to computing smallest height.
1572 uint cur_width = this->smallest_x;
1573 for (;;) {
1574 for (const auto &child_wid : this->children) {
1575 uint step_size = child_wid->GetHorizontalStepSize(ST_SMALLEST);
1576 uint child_width = child_wid->smallest_x + child_wid->padding.Horizontal();
1577 if (step_size > 1 && child_width < cur_width) { // Small step sizes or already fitting children are not interesting.
1578 uint remainder = (cur_width - child_width) % step_size;
1579 if (remainder > 0) { // Child did not fit entirely, widen the container.
1580 cur_width += step_size - remainder;
1581 assert(cur_width < max_smallest); // Safeguard against infinite width expansion.
1582 /* Remaining children will adapt to the new cur_width, thus speeding up the computation. */
1583 }
1584 }
1585 }
1586 if (this->smallest_x == cur_width) break;
1587 this->smallest_x = cur_width; // Smallest width got changed, try again.
1588 }
1589 /* 2. For containers that must maintain equal width, extend children minimal size. */
1590 if (this->flags & NC_EQUALSIZE) {
1591 for (const auto &child_wid : this->children) {
1592 if (child_wid->fill_y == 1) child_wid->smallest_y = highest;
1593 }
1594 }
1595 /* 3. Compute smallest, fill, and resize values of the container. */
1596 for (const auto &child_wid : this->children) {
1597 this->smallest_y += child_wid->smallest_y + child_wid->padding.Vertical();
1598 if (child_wid->fill_y > 0) {
1599 if (this->fill_y == 0 || this->fill_y > child_wid->fill_y) this->fill_y = child_wid->fill_y;
1600 }
1601 this->fill_x = std::lcm(this->fill_x, child_wid->fill_x);
1602
1603 if (child_wid->resize_y > 0) {
1604 if (this->resize_y == 0 || this->resize_y > child_wid->resize_y) this->resize_y = child_wid->resize_y;
1605 }
1606 this->resize_x = std::lcm(this->resize_x, child_wid->resize_x);
1607 }
1608 if (this->fill_y == 0 && this->pip_ratio_pre + this->pip_ratio_inter + this->pip_ratio_post > 0) this->fill_y = 1;
1609 /* 4. Increase by required PIP space. */
1610 this->smallest_y += this->pip_pre + this->gaps * this->pip_inter + this->pip_post;
1611 }
1612
1613 void NWidgetVertical::AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl)
1614 {
1615 assert(given_width >= this->smallest_x && given_height >= this->smallest_y);
1616
1617 /* Compute additional height given to us. */
1618 uint additional_length = given_height - (this->pip_pre + this->gaps * this->pip_inter + this->pip_post);
1619 for (const auto &child_wid : this->children) {
1620 if (child_wid->smallest_y != 0 || child_wid->fill_y != 0) additional_length -= child_wid->smallest_y + child_wid->padding.Vertical();
1621 }
1622
1623 this->StoreSizePosition(sizing, x, y, given_width, given_height);
1624
1625 /* Like the horizontal container, the vertical container also distributes additional height evenly, starting with the children with the biggest resize steps.
1626 * It also stores computed widths and heights into current_x and current_y values of the child.
1627 */
1628
1629 /* 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. */
1630 int num_changing_childs = 0; // Number of children that can change size.
1631 uint biggest_stepsize = 0;
1632 for (const auto &child_wid : this->children) {
1633 uint vert_step = child_wid->GetVerticalStepSize(sizing);
1634 if (vert_step > 0) {
1635 if (!(flags & NC_BIGFIRST)) num_changing_childs++;
1636 biggest_stepsize = std::max(biggest_stepsize, vert_step);
1637 } else {
1638 child_wid->current_y = child_wid->smallest_y;
1639 }
1640
1641 uint hor_step = (sizing == ST_SMALLEST) ? 1 : child_wid->GetHorizontalStepSize(sizing);
1642 child_wid->current_x = ComputeMaxSize(child_wid->smallest_x, given_width - child_wid->padding.Horizontal(), hor_step);
1643 }
1644
1645 /* First.5 loop: count how many children are of the biggest step size. */
1646 if ((this->flags & NC_BIGFIRST) && biggest_stepsize > 0) {
1647 for (const auto &child_wid : this->children) {
1648 uint vert_step = child_wid->GetVerticalStepSize(sizing);
1649 if (vert_step == biggest_stepsize) {
1650 num_changing_childs++;
1651 }
1652 }
1653 }
1654
1655 /* Second loop: Allocate the additional vertical space over the resizing children, starting with the biggest resize steps. */
1656 while (biggest_stepsize > 0) {
1657 uint next_biggest_stepsize = 0;
1658 for (const auto &child_wid : this->children) {
1659 uint vert_step = child_wid->GetVerticalStepSize(sizing);
1660 if (vert_step > biggest_stepsize) continue; // Already done
1661 if (vert_step == biggest_stepsize) {
1662 uint increment = additional_length / num_changing_childs;
1663 num_changing_childs--;
1664 if (vert_step > 1) increment -= increment % vert_step;
1665 child_wid->current_y = child_wid->smallest_y + increment;
1666 additional_length -= increment;
1667 continue;
1668 }
1669 next_biggest_stepsize = std::max(next_biggest_stepsize, vert_step);
1670 }
1671 biggest_stepsize = next_biggest_stepsize;
1672
1673 if (num_changing_childs == 0 && (flags & NC_BIGFIRST) && biggest_stepsize > 0) {
1674 /* Second.5 loop: count how many children are of the updated biggest step size. */
1675 for (const auto &child_wid : this->children) {
1676 uint vert_step = child_wid->GetVerticalStepSize(sizing);
1677 if (vert_step == biggest_stepsize) {
1678 num_changing_childs++;
1679 }
1680 }
1681 }
1682 }
1683 assert(num_changing_childs == 0);
1684
1685 uint pre = this->pip_pre;
1686 uint inter = this->pip_inter;
1687
1688 if (additional_length > 0) {
1689 /* Allocate remaining space by pip ratios. If this doesn't round exactly, the unused space will fall into pip_post
1690 * which is never explicitly needed. */
1691 int r = this->pip_ratio_pre + this->gaps * this->pip_ratio_inter + this->pip_ratio_post;
1692 if (r > 0) {
1693 pre += this->pip_ratio_pre * additional_length / r;
1694 if (this->gaps > 0) inter += this->pip_ratio_inter * additional_length / r;
1695 }
1696 }
1697
1698 /* Third loop: Compute position and call the child. */
1699 uint position = pre; // Place to put next child relative to origin of the container.
1700 for (const auto &child_wid : this->children) {
1701 uint child_x = x + (rtl ? child_wid->padding.right : child_wid->padding.left);
1702 uint child_height = child_wid->current_y;
1703
1704 child_wid->AssignSizePosition(sizing, child_x, y + position + child_wid->padding.top, child_wid->current_x, child_height, rtl);
1705 if (child_wid->current_y != 0) {
1706 position += child_height + child_wid->padding.Vertical() + inter;
1707 }
1708 }
1709 }
1710
1716 NWidgetSpacer::NWidgetSpacer(int width, int height) : NWidgetResizeBase(NWID_SPACER, 0, 0)
1717 {
1718 this->SetMinimalSize(width, height);
1719 this->SetResize(0, 0);
1720 }
1721
1722 void NWidgetSpacer::SetupSmallestSize(Window *)
1723 {
1724 this->smallest_x = this->min_x;
1725 this->smallest_y = this->min_y;
1726 }
1727
1728 void NWidgetSpacer::FillWidgetLookup(WidgetLookup &)
1729 {
1730 }
1731
1732 void NWidgetSpacer::Draw(const Window *w)
1733 {
1734 /* Spacer widget is never normally visible. */
1735
1736 if (_draw_widget_outlines && this->current_x != 0 && this->current_y != 0) {
1737 /* Spacers indicate a potential design issue, so get extra highlighting. */
1738 GfxFillRect(this->GetCurrentRect(), PC_WHITE, FILLRECT_CHECKER);
1739
1740 DrawOutline(w, this);
1741 }
1742 }
1743
1744 void NWidgetSpacer::SetDirty(const Window *) const
1745 {
1746 /* Spacer widget never need repainting. */
1747 }
1748
1749 NWidgetCore *NWidgetSpacer::GetWidgetFromPos(int, int)
1750 {
1751 return nullptr;
1752 }
1753
1754 NWidgetMatrix::NWidgetMatrix(Colours colour, WidgetID index) : NWidgetPIPContainer(NWID_MATRIX, NC_EQUALSIZE), index(index), clicked(-1), count(-1)
1755 {
1756 this->colour = colour;
1757 }
1758
1763 void NWidgetMatrix::SetClicked(int clicked)
1764 {
1765 this->clicked = clicked;
1766 if (this->clicked >= 0 && this->sb != nullptr && this->widgets_x != 0) {
1767 int vpos = (this->clicked / this->widgets_x) * this->widget_h; // Vertical position of the top.
1768 /* Need to scroll down -> Scroll to the bottom.
1769 * However, last entry has no 'this->pip_inter' underneath, and we must stay below this->sb->GetCount() */
1770 if (this->sb->GetPosition() < vpos) vpos += this->widget_h - this->pip_inter - 1;
1771 this->sb->ScrollTowards(vpos);
1772 }
1773 }
1774
1780 void NWidgetMatrix::SetCount(int count)
1781 {
1782 this->count = count;
1783
1784 if (this->sb == nullptr || this->widgets_x == 0) return;
1785
1786 /* We need to get the number of pixels the matrix is high/wide.
1787 * So, determine the number of rows/columns based on the number of
1788 * columns/rows (one is constant/unscrollable).
1789 * Then multiply that by the height of a widget, and add the pre
1790 * and post spacing "offsets". */
1791 count = CeilDiv(count, this->sb->IsVertical() ? this->widgets_x : this->widgets_y);
1792 count *= (this->sb->IsVertical() ? this->children.front()->smallest_y : this->children.front()->smallest_x) + this->pip_inter;
1793 if (count > 0) count -= this->pip_inter; // We counted an inter too much in the multiplication above
1794 count += this->pip_pre + this->pip_post;
1795 this->sb->SetCount(count);
1796 this->sb->SetCapacity(this->sb->IsVertical() ? this->current_y : this->current_x);
1797 this->sb->SetStepSize(this->sb->IsVertical() ? this->widget_h : this->widget_w);
1798 }
1799
1804 void NWidgetMatrix::SetScrollbar(Scrollbar *sb)
1805 {
1806 this->sb = sb;
1807 }
1808
1813 int NWidgetMatrix::GetCurrentElement() const
1814 {
1815 return this->current_element;
1816 }
1817
1818 void NWidgetMatrix::SetupSmallestSize(Window *w)
1819 {
1820 assert(this->children.size() == 1);
1821
1822 this->children.front()->SetupSmallestSize(w);
1823
1824 Dimension padding = { (uint)this->pip_pre + this->pip_post, (uint)this->pip_pre + this->pip_post};
1825 Dimension size = {this->children.front()->smallest_x + padding.width, this->children.front()->smallest_y + padding.height};
1826 Dimension fill = {0, 0};
1827 Dimension resize = {this->pip_inter + this->children.front()->smallest_x, this->pip_inter + this->children.front()->smallest_y};
1828
1829 if (this->index >= 0) w->UpdateWidgetSize(this->index, &size, padding, &fill, &resize);
1830
1831 this->smallest_x = size.width;
1832 this->smallest_y = size.height;
1833 this->fill_x = fill.width;
1834 this->fill_y = fill.height;
1835 this->resize_x = resize.width;
1836 this->resize_y = resize.height;
1837 }
1838
1839 void NWidgetMatrix::AssignSizePosition(SizingType, int x, int y, uint given_width, uint given_height, bool)
1840 {
1841 assert(given_width >= this->smallest_x && given_height >= this->smallest_y);
1842
1843 this->pos_x = x;
1844 this->pos_y = y;
1845 this->current_x = given_width;
1846 this->current_y = given_height;
1847
1848 /* Determine the size of the widgets, and the number of visible widgets on each of the axis. */
1849 this->widget_w = this->children.front()->smallest_x + this->pip_inter;
1850 this->widget_h = this->children.front()->smallest_y + this->pip_inter;
1851
1852 /* Account for the pip_inter is between widgets, so we need to account for that when
1853 * the division assumes pip_inter is used for all widgets. */
1854 this->widgets_x = CeilDiv(this->current_x - this->pip_pre - this->pip_post + this->pip_inter, this->widget_w);
1855 this->widgets_y = CeilDiv(this->current_y - this->pip_pre - this->pip_post + this->pip_inter, this->widget_h);
1856
1857 /* When resizing, update the scrollbar's count. E.g. with a vertical
1858 * scrollbar becoming wider or narrower means the amount of rows in
1859 * the scrollbar becomes respectively smaller or higher. */
1860 this->SetCount(this->count);
1861 }
1862
1863 void NWidgetMatrix::FillWidgetLookup(WidgetLookup &widget_lookup)
1864 {
1865 if (this->index >= 0) widget_lookup[this->index] = this;
1866 NWidgetContainer::FillWidgetLookup(widget_lookup);
1867 }
1868
1869 NWidgetCore *NWidgetMatrix::GetWidgetFromPos(int x, int y)
1870 {
1871 /* Falls outside of the matrix widget. */
1872 if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return nullptr;
1873
1874 int start_x, start_y, base_offs_x, base_offs_y;
1875 this->GetScrollOffsets(start_x, start_y, base_offs_x, base_offs_y);
1876
1877 bool rtl = _current_text_dir == TD_RTL;
1878
1879 int widget_col = (rtl ?
1880 -x + (int)this->pip_post + this->pos_x + base_offs_x + this->widget_w - 1 - (int)this->pip_inter :
1881 x - (int)this->pip_pre - this->pos_x - base_offs_x
1882 ) / this->widget_w;
1883
1884 int widget_row = (y - base_offs_y - (int)this->pip_pre - this->pos_y) / this->widget_h;
1885
1886 this->current_element = (widget_row + start_y) * this->widgets_x + start_x + widget_col;
1887 if (this->current_element >= this->count) return nullptr;
1888
1889 NWidgetCore *child = dynamic_cast<NWidgetCore *>(this->children.front().get());
1890 assert(child != nullptr);
1891 child->AssignSizePosition(ST_RESIZE,
1892 this->pos_x + (rtl ? this->pip_post - widget_col * this->widget_w : this->pip_pre + widget_col * this->widget_w) + base_offs_x,
1893 this->pos_y + this->pip_pre + widget_row * this->widget_h + base_offs_y,
1894 child->smallest_x, child->smallest_y, rtl);
1895
1896 return child->GetWidgetFromPos(x, y);
1897 }
1898
1899 /* virtual */ void NWidgetMatrix::Draw(const Window *w)
1900 {
1901 /* Fill the background. */
1902 GfxFillRect(this->GetCurrentRect(), _colour_gradient[this->colour & 0xF][5]);
1903
1904 /* Set up a clipping area for the previews. */
1905 bool rtl = _current_text_dir == TD_RTL;
1906 DrawPixelInfo tmp_dpi;
1907 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;
1908
1909 {
1910 AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
1911
1912 /* Get the appropriate offsets so we can draw the right widgets. */
1913 NWidgetCore *child = dynamic_cast<NWidgetCore *>(this->children.front().get());
1914 assert(child != nullptr);
1915 int start_x, start_y, base_offs_x, base_offs_y;
1916 this->GetScrollOffsets(start_x, start_y, base_offs_x, base_offs_y);
1917
1918 int offs_y = base_offs_y;
1919 for (int y = start_y; y < start_y + this->widgets_y + 1; y++, offs_y += this->widget_h) {
1920 /* Are we within bounds? */
1921 if (offs_y + child->smallest_y <= 0) continue;
1922 if (offs_y >= (int)this->current_y) break;
1923
1924 /* We've passed our amount of widgets. */
1925 if (y * this->widgets_x >= this->count) break;
1926
1927 int offs_x = base_offs_x;
1928 for (int x = start_x; x < start_x + this->widgets_x + 1; x++, offs_x += rtl ? -this->widget_w : this->widget_w) {
1929 /* Are we within bounds? */
1930 if (offs_x + child->smallest_x <= 0) continue;
1931 if (offs_x >= (int)this->current_x) continue;
1932
1933 /* Do we have this many widgets? */
1934 this->current_element = y * this->widgets_x + x;
1935 if (this->current_element >= this->count) break;
1936
1937 child->AssignSizePosition(ST_RESIZE, offs_x, offs_y, child->smallest_x, child->smallest_y, rtl);
1938 child->SetLowered(this->clicked == this->current_element);
1939 child->Draw(w);
1940 }
1941 }
1942 }
1943
1944 DrawOutline(w, this);
1945 }
1946
1954 void NWidgetMatrix::GetScrollOffsets(int &start_x, int &start_y, int &base_offs_x, int &base_offs_y)
1955 {
1956 base_offs_x = _current_text_dir == TD_RTL ? this->widget_w * (this->widgets_x - 1) : 0;
1957 base_offs_y = 0;
1958 start_x = 0;
1959 start_y = 0;
1960 if (this->sb != nullptr) {
1961 if (this->sb->IsVertical()) {
1962 start_y = this->sb->GetPosition() / this->widget_h;
1963 base_offs_y += -this->sb->GetPosition() + start_y * this->widget_h;
1964 } else {
1965 start_x = this->sb->GetPosition() / this->widget_w;
1966 int sub_x = this->sb->GetPosition() - start_x * this->widget_w;
1967 if (_current_text_dir == TD_RTL) {
1968 base_offs_x += sub_x;
1969 } else {
1970 base_offs_x -= sub_x;
1971 }
1972 }
1973 }
1974 }
1975
1985 NWidgetBackground::NWidgetBackground(WidgetType tp, Colours colour, WidgetID index, std::unique_ptr<NWidgetPIPContainer> &&child) : NWidgetCore(tp, colour, index, 1, 1, 0x0, STR_NULL)
1986 {
1987 assert(tp == WWT_PANEL || tp == WWT_INSET || tp == WWT_FRAME);
1988 this->child = std::move(child);
1989 if (this->child != nullptr) this->child->parent = this;
1990 this->SetAlignment(SA_TOP | SA_LEFT);
1991 }
1992
2000 void NWidgetBackground::Add(std::unique_ptr<NWidgetBase> &&nwid)
2001 {
2002 if (this->child == nullptr) {
2003 this->child = std::make_unique<NWidgetVertical>();
2004 }
2005 nwid->parent = this->child.get();
2006 this->child->Add(std::move(nwid));
2007 }
2008
2019 void NWidgetBackground::SetPIP(uint8_t pip_pre, uint8_t pip_inter, uint8_t pip_post)
2020 {
2021 if (this->child == nullptr) {
2022 this->child = std::make_unique<NWidgetVertical>();
2023 }
2024 this->child->parent = this;
2025 this->child->SetPIP(pip_pre, pip_inter, pip_post);
2026 }
2027
2038 void NWidgetBackground::SetPIPRatio(uint8_t pip_ratio_pre, uint8_t pip_ratio_inter, uint8_t pip_ratio_post)
2039 {
2040 if (this->child == nullptr) {
2041 this->child = std::make_unique<NWidgetVertical>();
2042 }
2043 this->child->parent = this;
2044 this->child->SetPIPRatio(pip_ratio_pre, pip_ratio_inter, pip_ratio_post);
2045 }
2046
2047 void NWidgetBackground::AdjustPaddingForZoom()
2048 {
2049 if (child != nullptr) child->AdjustPaddingForZoom();
2050 NWidgetCore::AdjustPaddingForZoom();
2051 }
2052
2053 void NWidgetBackground::SetupSmallestSize(Window *w)
2054 {
2055 if (this->child != nullptr) {
2056 this->child->SetupSmallestSize(w);
2057
2058 this->smallest_x = this->child->smallest_x;
2059 this->smallest_y = this->child->smallest_y;
2060 this->fill_x = this->child->fill_x;
2061 this->fill_y = this->child->fill_y;
2062 this->resize_x = this->child->resize_x;
2063 this->resize_y = this->child->resize_y;
2064
2065 /* Don't apply automatic padding if there is no child widget. */
2066 if (w == nullptr) return;
2067
2068 if (this->type == WWT_FRAME) {
2069 /* Account for the size of the frame's text if that exists */
2070 this->child->padding = WidgetDimensions::scaled.frametext;
2071 this->child->padding.top = std::max<uint8_t>(WidgetDimensions::scaled.frametext.top, this->widget_data != STR_NULL ? GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.frametext.top / 2 : 0);
2072
2073 this->smallest_x += this->child->padding.Horizontal();
2074 this->smallest_y += this->child->padding.Vertical();
2075
2076 if (this->index >= 0) w->SetStringParameters(this->index);
2077 this->smallest_x = std::max(this->smallest_x, GetStringBoundingBox(this->widget_data, this->text_size).width + WidgetDimensions::scaled.frametext.Horizontal());
2078 } else if (this->type == WWT_INSET) {
2079 /* Apply automatic padding for bevel thickness. */
2080 this->child->padding = WidgetDimensions::scaled.bevel;
2081
2082 this->smallest_x += this->child->padding.Horizontal();
2083 this->smallest_y += this->child->padding.Vertical();
2084 }
2085 } else {
2086 Dimension d = {this->min_x, this->min_y};
2087 Dimension fill = {this->fill_x, this->fill_y};
2088 Dimension resize = {this->resize_x, this->resize_y};
2089 if (w != nullptr) { // A non-nullptr window pointer acts as switch to turn dynamic widget size on.
2090 if (this->type == WWT_FRAME || this->type == WWT_INSET) {
2091 if (this->index >= 0) w->SetStringParameters(this->index);
2092 Dimension background = GetStringBoundingBox(this->widget_data, this->text_size);
2093 background.width += (this->type == WWT_FRAME) ? (WidgetDimensions::scaled.frametext.Horizontal()) : (WidgetDimensions::scaled.inset.Horizontal());
2094 d = maxdim(d, background);
2095 }
2096 if (this->index >= 0) {
2097 Dimension padding;
2098 switch (this->type) {
2099 default: NOT_REACHED();
2100 case WWT_PANEL: padding = {WidgetDimensions::scaled.framerect.Horizontal(), WidgetDimensions::scaled.framerect.Vertical()}; break;
2101 case WWT_FRAME: padding = {WidgetDimensions::scaled.frametext.Horizontal(), WidgetDimensions::scaled.frametext.Vertical()}; break;
2102 case WWT_INSET: padding = {WidgetDimensions::scaled.inset.Horizontal(), WidgetDimensions::scaled.inset.Vertical()}; break;
2103 }
2104 w->UpdateWidgetSize(this->index, &d, padding, &fill, &resize);
2105 }
2106 }
2107 this->smallest_x = d.width;
2108 this->smallest_y = d.height;
2109 this->fill_x = fill.width;
2110 this->fill_y = fill.height;
2111 this->resize_x = resize.width;
2112 this->resize_y = resize.height;
2113 }
2114 }
2115
2116 void NWidgetBackground::AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl)
2117 {
2118 this->StoreSizePosition(sizing, x, y, given_width, given_height);
2119
2120 if (this->child != nullptr) {
2121 uint x_offset = (rtl ? this->child->padding.right : this->child->padding.left);
2122 uint width = given_width - this->child->padding.Horizontal();
2123 uint height = given_height - this->child->padding.Vertical();
2124 this->child->AssignSizePosition(sizing, x + x_offset, y + this->child->padding.top, width, height, rtl);
2125 }
2126 }
2127
2128 void NWidgetBackground::FillWidgetLookup(WidgetLookup &widget_lookup)
2129 {
2130 if (this->index >= 0) widget_lookup[this->index] = this;
2131 if (this->child != nullptr) this->child->FillWidgetLookup(widget_lookup);
2132 }
2133
2134 void NWidgetBackground::Draw(const Window *w)
2135 {
2136 if (this->current_x == 0 || this->current_y == 0) return;
2137
2138 Rect r = this->GetCurrentRect();
2139
2140 const DrawPixelInfo *dpi = _cur_dpi;
2141 if (dpi->left > r.right || dpi->left + dpi->width <= r.left || dpi->top > r.bottom || dpi->top + dpi->height <= r.top) return;
2142
2143 switch (this->type) {
2144 case WWT_PANEL:
2145 assert(this->widget_data == 0);
2146 DrawFrameRect(r.left, r.top, r.right, r.bottom, this->colour, this->IsLowered() ? FR_LOWERED : FR_NONE);
2147 break;
2148
2149 case WWT_FRAME:
2150 if (this->index >= 0) w->SetStringParameters(this->index);
2151 DrawFrame(r, this->colour, this->text_colour, this->widget_data, this->align, this->text_size);
2152 break;
2153
2154 case WWT_INSET:
2155 if (this->index >= 0) w->SetStringParameters(this->index);
2156 DrawInset(r, this->colour, this->text_colour, this->widget_data, this->align, this->text_size);
2157 break;
2158
2159 default:
2160 NOT_REACHED();
2161 }
2162
2163 if (this->index >= 0) w->DrawWidget(r, this->index);
2164 if (this->child != nullptr) this->child->Draw(w);
2165
2166 if (this->IsDisabled()) {
2167 GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), _colour_gradient[this->colour & 0xF][2], FILLRECT_CHECKER);
2168 }
2169
2170 DrawOutline(w, this);
2171 }
2172
2173 NWidgetCore *NWidgetBackground::GetWidgetFromPos(int x, int y)
2174 {
2175 NWidgetCore *nwid = nullptr;
2176 if (IsInsideBS(x, this->pos_x, this->current_x) && IsInsideBS(y, this->pos_y, this->current_y)) {
2177 if (this->child != nullptr) nwid = this->child->GetWidgetFromPos(x, y);
2178 if (nwid == nullptr) nwid = this;
2179 }
2180 return nwid;
2181 }
2182
2183 NWidgetBase *NWidgetBackground::GetWidgetOfType(WidgetType tp)
2184 {
2185 NWidgetBase *nwid = nullptr;
2186 if (this->child != nullptr) nwid = this->child->GetWidgetOfType(tp);
2187 if (nwid == nullptr && this->type == tp) nwid = this;
2188 return nwid;
2189 }
2190
2191 NWidgetViewport::NWidgetViewport(WidgetID index) : NWidgetCore(NWID_VIEWPORT, INVALID_COLOUR, index, 1, 1, 0x0, STR_NULL)
2192 {
2193 }
2194
2195 void NWidgetViewport::SetupSmallestSize(Window *)
2196 {
2197 this->smallest_x = this->min_x;
2198 this->smallest_y = this->min_y;
2199 }
2200
2201 void NWidgetViewport::Draw(const Window *w)
2202 {
2203 if (this->current_x == 0 || this->current_y == 0) return;
2204
2205 if (this->disp_flags & ND_NO_TRANSPARENCY) {
2206 TransparencyOptionBits to_backup = _transparency_opt;
2207 _transparency_opt &= (1 << TO_SIGNS) | (1 << TO_TEXT); // Disable all transparency, except textual stuff
2208 w->DrawViewport();
2209 _transparency_opt = to_backup;
2210 } else {
2211 w->DrawViewport();
2212 }
2213
2214 /* Optionally shade the viewport. */
2215 if (this->disp_flags & (ND_SHADE_GREY | ND_SHADE_DIMMED)) {
2216 GfxFillRect(this->GetCurrentRect(), (this->disp_flags & ND_SHADE_DIMMED) ? PALETTE_TO_TRANSPARENT : PALETTE_NEWSPAPER, FILLRECT_RECOLOUR);
2217 }
2218
2219 DrawOutline(w, this);
2220 }
2221
2228 void NWidgetViewport::InitializeViewport(Window *w, std::variant<TileIndex, VehicleID> focus, ZoomLevel zoom)
2229 {
2230 InitializeWindowViewport(w, this->pos_x, this->pos_y, this->current_x, this->current_y, focus, zoom);
2231 }
2232
2237 void NWidgetViewport::UpdateViewportCoordinates(Window *w)
2238 {
2239 Viewport *vp = w->viewport;
2240 if (vp != nullptr) {
2241 vp->left = w->left + this->pos_x;
2242 vp->top = w->top + this->pos_y;
2243 vp->width = this->current_x;
2244 vp->height = this->current_y;
2245
2246 vp->virtual_width = ScaleByZoom(vp->width, vp->zoom);
2247 vp->virtual_height = ScaleByZoom(vp->height, vp->zoom);
2248 }
2249 }
2250
2260 int Scrollbar::GetScrolledRowFromWidget(int clickpos, const Window * const w, WidgetID widget, int padding, int line_height) const
2261 {
2262 uint pos = w->GetRowFromWidget(clickpos, widget, padding, line_height);
2263 if (pos != INT_MAX) pos += this->GetPosition();
2264 return (pos >= this->GetCount()) ? INT_MAX : pos;
2265 }
2266
2281 EventState Scrollbar::UpdateListPositionOnKeyPress(int &list_position, uint16_t keycode) const
2282 {
2283 int new_pos = list_position;
2284 switch (keycode) {
2285 case WKC_UP:
2286 /* scroll up by one */
2287 new_pos--;
2288 break;
2289
2290 case WKC_DOWN:
2291 /* scroll down by one */
2292 new_pos++;
2293 break;
2294
2295 case WKC_PAGEUP:
2296 /* scroll up a page */
2297 new_pos -= this->GetCapacity();
2298 break;
2299
2300 case WKC_PAGEDOWN:
2301 /* scroll down a page */
2302 new_pos += this->GetCapacity();
2303 break;
2304
2305 case WKC_HOME:
2306 /* jump to beginning */
2307 new_pos = 0;
2308 break;
2309
2310 case WKC_END:
2311 /* jump to end */
2312 new_pos = this->GetCount() - 1;
2313 break;
2314
2315 default:
2316 return ES_NOT_HANDLED;
2317 }
2318
2319 /* If there are no elements, there is nothing to scroll/update. */
2320 if (this->GetCount() != 0) {
2321 list_position = Clamp(new_pos, 0, this->GetCount() - 1);
2322 }
2323 return ES_HANDLED;
2324 }
2325
2326
2334 void Scrollbar::SetCapacityFromWidget(Window *w, WidgetID widget, int padding)
2335 {
2336 NWidgetBase *nwid = w->GetWidget<NWidgetBase>(widget);
2337 if (this->IsVertical()) {
2338 this->SetCapacity(((int)nwid->current_y - padding) / (int)nwid->resize_y);
2339 } else {
2340 this->SetCapacity(((int)nwid->current_x - padding) / (int)nwid->resize_x);
2341 }
2342 }
2343
2350 NWidgetScrollbar::NWidgetScrollbar(WidgetType tp, Colours colour, WidgetID index) : NWidgetCore(tp, colour, index, 1, 1, 0x0, STR_NULL), Scrollbar(tp != NWID_HSCROLLBAR)
2351 {
2352 assert(tp == NWID_HSCROLLBAR || tp == NWID_VSCROLLBAR);
2353
2354 switch (this->type) {
2355 case NWID_HSCROLLBAR:
2356 this->SetResize(1, 0);
2357 this->SetFill(1, 0);
2358 this->SetDataTip(0x0, STR_TOOLTIP_HSCROLL_BAR_SCROLLS_LIST);
2359 break;
2360
2361 case NWID_VSCROLLBAR:
2362 this->SetResize(0, 1);
2363 this->SetFill(0, 1);
2364 this->SetDataTip(0x0, STR_TOOLTIP_VSCROLL_BAR_SCROLLS_LIST);
2365 break;
2366
2367 default: NOT_REACHED();
2368 }
2369 }
2370
2371 void NWidgetScrollbar::SetupSmallestSize(Window *)
2372 {
2373 this->min_x = 0;
2374 this->min_y = 0;
2375
2376 switch (this->type) {
2377 case NWID_HSCROLLBAR:
2378 this->SetMinimalSizeAbsolute(NWidgetScrollbar::GetHorizontalDimension().width * 3, NWidgetScrollbar::GetHorizontalDimension().height);
2379 break;
2380
2381 case NWID_VSCROLLBAR:
2382 this->SetMinimalSizeAbsolute(NWidgetScrollbar::GetVerticalDimension().width, NWidgetScrollbar::GetVerticalDimension().height * 3);
2383 break;
2384
2385 default: NOT_REACHED();
2386 }
2387
2388 this->smallest_x = this->min_x;
2389 this->smallest_y = this->min_y;
2390 }
2391
2392 void NWidgetScrollbar::Draw(const Window *w)
2393 {
2394 if (this->current_x == 0 || this->current_y == 0) return;
2395
2396 Rect r = this->GetCurrentRect();
2397
2398 const DrawPixelInfo *dpi = _cur_dpi;
2399 if (dpi->left > r.right || dpi->left + dpi->width <= r.left || dpi->top > r.bottom || dpi->top + dpi->height <= r.top) return;
2400
2401 bool up_lowered = HasBit(this->disp_flags, NDB_SCROLLBAR_UP);
2402 bool down_lowered = HasBit(this->disp_flags, NDB_SCROLLBAR_DOWN);
2403 bool middle_lowered = !(this->disp_flags & ND_SCROLLBAR_BTN) && w->mouse_capture_widget == this->index;
2404
2405 if (this->type == NWID_HSCROLLBAR) {
2406 DrawHorizontalScrollbar(r, this->colour, up_lowered, middle_lowered, down_lowered, this);
2407 } else {
2408 DrawVerticalScrollbar(r, this->colour, up_lowered, middle_lowered, down_lowered, this);
2409 }
2410
2411 if (this->IsDisabled()) {
2412 GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), _colour_gradient[this->colour & 0xF][2], FILLRECT_CHECKER);
2413 }
2414
2415 DrawOutline(w, this);
2416 }
2417
2418 /* static */ void NWidgetScrollbar::InvalidateDimensionCache()
2419 {
2420 vertical_dimension.width = vertical_dimension.height = 0;
2421 horizontal_dimension.width = horizontal_dimension.height = 0;
2422 }
2423
2424 /* static */ Dimension NWidgetScrollbar::GetVerticalDimension()
2425 {
2426 if (vertical_dimension.width == 0) {
2427 vertical_dimension = maxdim(GetScaledSpriteSize(SPR_ARROW_UP), GetScaledSpriteSize(SPR_ARROW_DOWN));
2428 vertical_dimension.width += WidgetDimensions::scaled.vscrollbar.Horizontal();
2429 vertical_dimension.height += WidgetDimensions::scaled.vscrollbar.Vertical();
2430 }
2431 return vertical_dimension;
2432 }
2433
2434 /* static */ Dimension NWidgetScrollbar::GetHorizontalDimension()
2435 {
2436 if (horizontal_dimension.width == 0) {
2437 horizontal_dimension = maxdim(GetScaledSpriteSize(SPR_ARROW_LEFT), GetScaledSpriteSize(SPR_ARROW_RIGHT));
2438 horizontal_dimension.width += WidgetDimensions::scaled.hscrollbar.Horizontal();
2439 horizontal_dimension.height += WidgetDimensions::scaled.hscrollbar.Vertical();
2440 }
2441 return horizontal_dimension;
2442 }
2443
2444 Dimension NWidgetScrollbar::vertical_dimension = {0, 0};
2445 Dimension NWidgetScrollbar::horizontal_dimension = {0, 0};
2446
2448 /* static */ void NWidgetLeaf::InvalidateDimensionCache()
2449 {
2450 shadebox_dimension.width = shadebox_dimension.height = 0;
2451 debugbox_dimension.width = debugbox_dimension.height = 0;
2452 defsizebox_dimension.width = defsizebox_dimension.height = 0;
2453 stickybox_dimension.width = stickybox_dimension.height = 0;
2454 resizebox_dimension.width = resizebox_dimension.height = 0;
2455 closebox_dimension.width = closebox_dimension.height = 0;
2456 dropdown_dimension.width = dropdown_dimension.height = 0;
2457 }
2458
2459 Dimension NWidgetLeaf::shadebox_dimension = {0, 0};
2460 Dimension NWidgetLeaf::debugbox_dimension = {0, 0};
2461 Dimension NWidgetLeaf::defsizebox_dimension = {0, 0};
2462 Dimension NWidgetLeaf::stickybox_dimension = {0, 0};
2463 Dimension NWidgetLeaf::resizebox_dimension = {0, 0};
2464 Dimension NWidgetLeaf::closebox_dimension = {0, 0};
2465 Dimension NWidgetLeaf::dropdown_dimension = {0, 0};
2466
2475 NWidgetLeaf::NWidgetLeaf(WidgetType tp, Colours colour, WidgetID index, uint32_t data, StringID tip) : NWidgetCore(tp, colour, index, 1, 1, data, tip)
2476 {
2477 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);
2478 this->min_x = 0;
2479 this->min_y = 0;
2480 this->SetResize(0, 0);
2481
2482 switch (tp) {
2483 case WWT_EMPTY:
2484 break;
2485
2486 case WWT_TEXT:
2487 this->SetFill(0, 0);
2488 this->SetAlignment(SA_LEFT | SA_VERT_CENTER);
2489 break;
2490
2491 case WWT_PUSHBTN:
2492 case WWT_IMGBTN:
2493 case WWT_PUSHIMGBTN:
2494 case WWT_IMGBTN_2:
2495 case WWT_TEXTBTN:
2496 case WWT_PUSHTXTBTN:
2497 case WWT_TEXTBTN_2:
2498 case WWT_LABEL:
2499 case WWT_MATRIX:
2500 case NWID_BUTTON_DROPDOWN:
2501 case NWID_PUSHBUTTON_DROPDOWN:
2502 case WWT_ARROWBTN:
2503 case WWT_PUSHARROWBTN:
2504 this->SetFill(0, 0);
2505 break;
2506
2507 case WWT_EDITBOX:
2508 this->SetFill(0, 0);
2509 break;
2510
2511 case WWT_CAPTION:
2512 this->SetFill(1, 0);
2513 this->SetResize(1, 0);
2514 this->SetMinimalSize(0, WidgetDimensions::WD_CAPTION_HEIGHT);
2515 this->SetMinimalTextLines(1, WidgetDimensions::unscaled.captiontext.Vertical(), FS_NORMAL);
2516 this->SetDataTip(data, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS);
2517 break;
2518
2519 case WWT_STICKYBOX:
2520 this->SetFill(0, 0);
2521 this->SetMinimalSize(WidgetDimensions::WD_STICKYBOX_WIDTH, WidgetDimensions::WD_CAPTION_HEIGHT);
2522 this->SetDataTip(STR_NULL, STR_TOOLTIP_STICKY);
2523 break;
2524
2525 case WWT_SHADEBOX:
2526 this->SetFill(0, 0);
2527 this->SetMinimalSize(WidgetDimensions::WD_SHADEBOX_WIDTH, WidgetDimensions::WD_CAPTION_HEIGHT);
2528 this->SetDataTip(STR_NULL, STR_TOOLTIP_SHADE);
2529 break;
2530
2531 case WWT_DEBUGBOX:
2532 this->SetFill(0, 0);
2533 this->SetMinimalSize(WidgetDimensions::WD_DEBUGBOX_WIDTH, WidgetDimensions::WD_CAPTION_HEIGHT);
2534 this->SetDataTip(STR_NULL, STR_TOOLTIP_DEBUG);
2535 break;
2536
2537 case WWT_DEFSIZEBOX:
2538 this->SetFill(0, 0);
2539 this->SetMinimalSize(WidgetDimensions::WD_DEFSIZEBOX_WIDTH, WidgetDimensions::WD_CAPTION_HEIGHT);
2540 this->SetDataTip(STR_NULL, STR_TOOLTIP_DEFSIZE);
2541 break;
2542
2543 case WWT_RESIZEBOX:
2544 this->SetFill(0, 0);
2545 this->SetMinimalSize(WidgetDimensions::WD_RESIZEBOX_WIDTH, 12);
2546 this->SetDataTip(RWV_SHOW_BEVEL, STR_TOOLTIP_RESIZE);
2547 break;
2548
2549 case WWT_CLOSEBOX:
2550 this->SetFill(0, 0);
2551 this->SetMinimalSize(WidgetDimensions::WD_CLOSEBOX_WIDTH, WidgetDimensions::WD_CAPTION_HEIGHT);
2552 this->SetDataTip(STR_NULL, STR_TOOLTIP_CLOSE_WINDOW);
2553 break;
2554
2555 case WWT_DROPDOWN:
2556 this->SetFill(0, 0);
2557 this->SetMinimalSize(0, WidgetDimensions::WD_DROPDOWN_HEIGHT);
2558 this->SetAlignment(SA_TOP | SA_LEFT);
2559 break;
2560
2561 default:
2562 NOT_REACHED();
2563 }
2564 }
2565
2566 void NWidgetLeaf::SetupSmallestSize(Window *w)
2567 {
2568 Dimension padding = {0, 0};
2569 Dimension size = {this->min_x, this->min_y};
2570 Dimension fill = {this->fill_x, this->fill_y};
2571 Dimension resize = {this->resize_x, this->resize_y};
2572 switch (this->type) {
2573 case WWT_EMPTY: {
2574 break;
2575 }
2576 case WWT_MATRIX: {
2577 padding = {WidgetDimensions::scaled.matrix.Horizontal(), WidgetDimensions::scaled.matrix.Vertical()};
2578 break;
2579 }
2580 case WWT_SHADEBOX: {
2581 padding = {WidgetDimensions::scaled.shadebox.Horizontal(), WidgetDimensions::scaled.shadebox.Vertical()};
2582 if (NWidgetLeaf::shadebox_dimension.width == 0) {
2583 NWidgetLeaf::shadebox_dimension = maxdim(GetScaledSpriteSize(SPR_WINDOW_SHADE), GetScaledSpriteSize(SPR_WINDOW_UNSHADE));
2584 NWidgetLeaf::shadebox_dimension.width += padding.width;
2585 NWidgetLeaf::shadebox_dimension.height += padding.height;
2586 }
2587 size = maxdim(size, NWidgetLeaf::shadebox_dimension);
2588 break;
2589 }
2590 case WWT_DEBUGBOX:
2591 if (_settings_client.gui.newgrf_developer_tools && w->IsNewGRFInspectable()) {
2592 padding = {WidgetDimensions::scaled.debugbox.Horizontal(), WidgetDimensions::scaled.debugbox.Vertical()};
2593 if (NWidgetLeaf::debugbox_dimension.width == 0) {
2594 NWidgetLeaf::debugbox_dimension = GetScaledSpriteSize(SPR_WINDOW_DEBUG);
2595 NWidgetLeaf::debugbox_dimension.width += padding.width;
2596 NWidgetLeaf::debugbox_dimension.height += padding.height;
2597 }
2598 size = maxdim(size, NWidgetLeaf::debugbox_dimension);
2599 } else {
2600 /* If the setting is disabled we don't want to see it! */
2601 size.width = 0;
2602 fill.width = 0;
2603 resize.width = 0;
2604 }
2605 break;
2606
2607 case WWT_STICKYBOX: {
2608 padding = {WidgetDimensions::scaled.stickybox.Horizontal(), WidgetDimensions::scaled.stickybox.Vertical()};
2609 if (NWidgetLeaf::stickybox_dimension.width == 0) {
2610 NWidgetLeaf::stickybox_dimension = maxdim(GetScaledSpriteSize(SPR_PIN_UP), GetScaledSpriteSize(SPR_PIN_DOWN));
2611 NWidgetLeaf::stickybox_dimension.width += padding.width;
2612 NWidgetLeaf::stickybox_dimension.height += padding.height;
2613 }
2614 size = maxdim(size, NWidgetLeaf::stickybox_dimension);
2615 break;
2616 }
2617
2618 case WWT_DEFSIZEBOX: {
2619 padding = {WidgetDimensions::scaled.defsizebox.Horizontal(), WidgetDimensions::scaled.defsizebox.Vertical()};
2620 if (NWidgetLeaf::defsizebox_dimension.width == 0) {
2621 NWidgetLeaf::defsizebox_dimension = GetScaledSpriteSize(SPR_WINDOW_DEFSIZE);
2622 NWidgetLeaf::defsizebox_dimension.width += padding.width;
2623 NWidgetLeaf::defsizebox_dimension.height += padding.height;
2624 }
2625 size = maxdim(size, NWidgetLeaf::defsizebox_dimension);
2626 break;
2627 }
2628
2629 case WWT_RESIZEBOX: {
2630 padding = {WidgetDimensions::scaled.resizebox.Horizontal(), WidgetDimensions::scaled.resizebox.Vertical()};
2631 if (NWidgetLeaf::resizebox_dimension.width == 0) {
2632 NWidgetLeaf::resizebox_dimension = maxdim(GetScaledSpriteSize(SPR_WINDOW_RESIZE_LEFT), GetScaledSpriteSize(SPR_WINDOW_RESIZE_RIGHT));
2633 NWidgetLeaf::resizebox_dimension.width += padding.width;
2634 NWidgetLeaf::resizebox_dimension.height += padding.height;
2635 }
2636 size = maxdim(size, NWidgetLeaf::resizebox_dimension);
2637 break;
2638 }
2639 case WWT_EDITBOX: {
2640 Dimension sprite_size = GetScaledSpriteSize(_current_text_dir == TD_RTL ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT);
2641 size.width = std::max(size.width, ScaleGUITrad(30) + sprite_size.width);
2642 size.height = std::max(sprite_size.height, GetStringBoundingBox("_").height + WidgetDimensions::scaled.framerect.Vertical());
2643 }
2644 [[fallthrough]];
2645 case WWT_PUSHBTN: {
2646 padding = {WidgetDimensions::scaled.frametext.Horizontal(), WidgetDimensions::scaled.framerect.Vertical()};
2647 break;
2648 }
2649 case WWT_IMGBTN:
2650 case WWT_IMGBTN_2:
2651 case WWT_PUSHIMGBTN: {
2652 padding = {WidgetDimensions::scaled.imgbtn.Horizontal(), WidgetDimensions::scaled.imgbtn.Vertical()};
2653 Dimension d2 = GetScaledSpriteSize(this->widget_data);
2654 if (this->type == WWT_IMGBTN_2) d2 = maxdim(d2, GetScaledSpriteSize(this->widget_data + 1));
2655 d2.width += padding.width;
2656 d2.height += padding.height;
2657 size = maxdim(size, d2);
2658 break;
2659 }
2660 case WWT_ARROWBTN:
2661 case WWT_PUSHARROWBTN: {
2662 padding = {WidgetDimensions::scaled.imgbtn.Horizontal(), WidgetDimensions::scaled.imgbtn.Vertical()};
2663 Dimension d2 = maxdim(GetScaledSpriteSize(SPR_ARROW_LEFT), GetScaledSpriteSize(SPR_ARROW_RIGHT));
2664 d2.width += padding.width;
2665 d2.height += padding.height;
2666 size = maxdim(size, d2);
2667 break;
2668 }
2669
2670 case WWT_CLOSEBOX: {
2671 padding = {WidgetDimensions::scaled.closebox.Horizontal(), WidgetDimensions::scaled.closebox.Vertical()};
2672 if (NWidgetLeaf::closebox_dimension.width == 0) {
2673 NWidgetLeaf::closebox_dimension = GetScaledSpriteSize(SPR_CLOSEBOX);
2674 NWidgetLeaf::closebox_dimension.width += padding.width;
2675 NWidgetLeaf::closebox_dimension.height += padding.height;
2676 }
2677 size = maxdim(size, NWidgetLeaf::closebox_dimension);
2678 break;
2679 }
2680 case WWT_TEXTBTN:
2681 case WWT_PUSHTXTBTN:
2682 case WWT_TEXTBTN_2: {
2683 padding = {WidgetDimensions::scaled.framerect.Horizontal(), WidgetDimensions::scaled.framerect.Vertical()};
2684 if (this->index >= 0) w->SetStringParameters(this->index);
2685 Dimension d2 = GetStringBoundingBox(this->widget_data, this->text_size);
2686 d2.width += padding.width;
2687 d2.height += padding.height;
2688 size = maxdim(size, d2);
2689 break;
2690 }
2691 case WWT_LABEL:
2692 case WWT_TEXT: {
2693 if (this->index >= 0) w->SetStringParameters(this->index);
2694 size = maxdim(size, GetStringBoundingBox(this->widget_data, this->text_size));
2695 break;
2696 }
2697 case WWT_CAPTION: {
2698 padding = {WidgetDimensions::scaled.captiontext.Horizontal(), WidgetDimensions::scaled.captiontext.Vertical()};
2699 if (this->index >= 0) w->SetStringParameters(this->index);
2700 Dimension d2 = GetStringBoundingBox(this->widget_data, this->text_size);
2701 d2.width += padding.width;
2702 d2.height += padding.height;
2703 size = maxdim(size, d2);
2704 break;
2705 }
2706 case WWT_DROPDOWN:
2707 case NWID_BUTTON_DROPDOWN:
2708 case NWID_PUSHBUTTON_DROPDOWN: {
2709 if (NWidgetLeaf::dropdown_dimension.width == 0) {
2710 NWidgetLeaf::dropdown_dimension = GetScaledSpriteSize(SPR_ARROW_DOWN);
2711 NWidgetLeaf::dropdown_dimension.width += WidgetDimensions::scaled.vscrollbar.Horizontal();
2712 NWidgetLeaf::dropdown_dimension.height += WidgetDimensions::scaled.vscrollbar.Vertical();
2713 }
2714 padding = {WidgetDimensions::scaled.dropdowntext.Horizontal() + NWidgetLeaf::dropdown_dimension.width + WidgetDimensions::scaled.fullbevel.Horizontal(), WidgetDimensions::scaled.dropdowntext.Vertical()};
2715 if (this->index >= 0) w->SetStringParameters(this->index);
2716 Dimension d2 = GetStringBoundingBox(this->widget_data, this->text_size);
2717 d2.width += padding.width;
2718 d2.height = std::max(d2.height + padding.height, NWidgetLeaf::dropdown_dimension.height);
2719 size = maxdim(size, d2);
2720 break;
2721 }
2722 default:
2723 NOT_REACHED();
2724 }
2725
2726 if (this->index >= 0) w->UpdateWidgetSize(this->index, &size, padding, &fill, &resize);
2727
2728 this->smallest_x = size.width;
2729 this->smallest_y = size.height;
2730 this->fill_x = fill.width;
2731 this->fill_y = fill.height;
2732 this->resize_x = resize.width;
2733 this->resize_y = resize.height;
2734 }
2735
2736 void NWidgetLeaf::Draw(const Window *w)
2737 {
2738 if (this->current_x == 0 || this->current_y == 0) return;
2739
2740 /* Setup a clipping rectangle... for WWT_EMPTY or WWT_TEXT, an extra scaled pixel is allowed in case text shadow encroaches. */
2741 int extra = (this->type == WWT_EMPTY || this->type == WWT_TEXT) ? ScaleGUITrad(1) : 0;
2742 DrawPixelInfo new_dpi;
2743 if (!FillDrawPixelInfo(&new_dpi, this->pos_x, this->pos_y, this->current_x + extra, this->current_y + extra)) return;
2744 /* ...but keep coordinates relative to the window. */
2745 new_dpi.left += this->pos_x;
2746 new_dpi.top += this->pos_y;
2747
2748 AutoRestoreBackup dpi_backup(_cur_dpi, &new_dpi);
2749
2750 Rect r = this->GetCurrentRect();
2751
2752 bool clicked = this->IsLowered();
2753 switch (this->type) {
2754 case WWT_EMPTY:
2755 /* WWT_EMPTY used as a spacer indicates a potential design issue. */
2756 if (this->index == -1 && _draw_widget_outlines) {
2757 GfxFillRect(r, PC_BLACK, FILLRECT_CHECKER);
2758 }
2759 break;
2760
2761 case WWT_PUSHBTN:
2762 assert(this->widget_data == 0);
2763 DrawFrameRect(r.left, r.top, r.right, r.bottom, this->colour, (clicked) ? FR_LOWERED : FR_NONE);
2764 break;
2765
2766 case WWT_IMGBTN:
2767 case WWT_PUSHIMGBTN:
2768 case WWT_IMGBTN_2:
2769 DrawImageButtons(r, this->type, this->colour, clicked, this->widget_data, this->align);
2770 break;
2771
2772 case WWT_TEXTBTN:
2773 case WWT_PUSHTXTBTN:
2774 case WWT_TEXTBTN_2:
2775 if (this->index >= 0) w->SetStringParameters(this->index);
2776 DrawFrameRect(r.left, r.top, r.right, r.bottom, this->colour, (clicked) ? FR_LOWERED : FR_NONE);
2777 DrawLabel(r, this->type, clicked, this->text_colour, this->widget_data, this->align, this->text_size);
2778 break;
2779
2780 case WWT_ARROWBTN:
2781 case WWT_PUSHARROWBTN: {
2782 SpriteID sprite;
2783 switch (this->widget_data) {
2784 case AWV_DECREASE: sprite = _current_text_dir != TD_RTL ? SPR_ARROW_LEFT : SPR_ARROW_RIGHT; break;
2785 case AWV_INCREASE: sprite = _current_text_dir == TD_RTL ? SPR_ARROW_LEFT : SPR_ARROW_RIGHT; break;
2786 case AWV_LEFT: sprite = SPR_ARROW_LEFT; break;
2787 case AWV_RIGHT: sprite = SPR_ARROW_RIGHT; break;
2788 default: NOT_REACHED();
2789 }
2790 DrawImageButtons(r, WWT_PUSHIMGBTN, this->colour, clicked, sprite, this->align);
2791 break;
2792 }
2793
2794 case WWT_LABEL:
2795 if (this->index >= 0) w->SetStringParameters(this->index);
2796 DrawLabel(r, this->type, clicked, this->text_colour, this->widget_data, this->align, this->text_size);
2797 break;
2798
2799 case WWT_TEXT:
2800 if (this->index >= 0) w->SetStringParameters(this->index);
2801 DrawText(r, this->text_colour, this->widget_data, this->align, this->text_size);
2802 break;
2803
2804 case WWT_MATRIX:
2805 DrawMatrix(r, this->colour, clicked, this->widget_data, this->resize_x, this->resize_y);
2806 break;
2807
2808 case WWT_EDITBOX: {
2809 const QueryString *query = w->GetQueryString(this->index);
2810 if (query != nullptr) query->DrawEditBox(w, this->index);
2811 break;
2812 }
2813
2814 case WWT_CAPTION:
2815 if (this->index >= 0) w->SetStringParameters(this->index);
2816 DrawCaption(r, this->colour, w->owner, this->text_colour, this->widget_data, this->align, this->text_size);
2817 break;
2818
2819 case WWT_SHADEBOX:
2820 assert(this->widget_data == 0);
2821 DrawShadeBox(r, this->colour, w->IsShaded());
2822 break;
2823
2824 case WWT_DEBUGBOX:
2825 DrawDebugBox(r, this->colour, clicked);
2826 break;
2827
2828 case WWT_STICKYBOX:
2829 assert(this->widget_data == 0);
2830 DrawStickyBox(r, this->colour, !!(w->flags & WF_STICKY));
2831 break;
2832
2833 case WWT_DEFSIZEBOX:
2834 assert(this->widget_data == 0);
2835 DrawDefSizeBox(r, this->colour, clicked);
2836 break;
2837
2838 case WWT_RESIZEBOX:
2839 DrawResizeBox(r, this->colour, this->pos_x < (w->width / 2), !!(w->flags & WF_SIZING), this->widget_data == 0);
2840 break;
2841
2842 case WWT_CLOSEBOX:
2843 DrawCloseBox(r, this->colour);
2844 break;
2845
2846 case WWT_DROPDOWN:
2847 if (this->index >= 0) w->SetStringParameters(this->index);
2848 DrawButtonDropdown(r, this->colour, false, clicked, this->widget_data, this->align);
2849 break;
2850
2851 case NWID_BUTTON_DROPDOWN:
2852 case NWID_PUSHBUTTON_DROPDOWN:
2853 if (this->index >= 0) w->SetStringParameters(this->index);
2854 DrawButtonDropdown(r, this->colour, clicked, (this->disp_flags & ND_DROPDOWN_ACTIVE) != 0, this->widget_data, this->align);
2855 break;
2856
2857 default:
2858 NOT_REACHED();
2859 }
2860 if (this->index >= 0) w->DrawWidget(r, this->index);
2861
2862 if (this->IsDisabled()) {
2863 GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), _colour_gradient[this->colour & 0xF][2], FILLRECT_CHECKER);
2864 }
2865
2866 DrawOutline(w, this);
2867 }
2868
2876 bool NWidgetLeaf::ButtonHit(const Point &pt)
2877 {
2878 if (_current_text_dir == TD_LTR) {
2879 int button_width = this->pos_x + this->current_x - NWidgetLeaf::dropdown_dimension.width;
2880 return pt.x < button_width;
2881 } else {
2882 int button_left = this->pos_x + NWidgetLeaf::dropdown_dimension.width;
2883 return pt.x >= button_left;
2884 }
2885 }
2886
2887 /* == Conversion code from NWidgetPart array to NWidgetBase* tree == */
2888
2902 static const NWidgetPart *MakeNWidget(const NWidgetPart *nwid_begin, const NWidgetPart *nwid_end, std::unique_ptr<NWidgetBase> &dest, bool *fill_dest)
2903 {
2904 dest = nullptr;
2905 *fill_dest = false;
2906
2907 while (nwid_begin < nwid_end) {
2908 switch (nwid_begin->type) {
2909 case NWID_SPACER:
2910 if (dest != nullptr) return nwid_begin;
2911 dest = std::make_unique<NWidgetSpacer>(0, 0);
2912 break;
2913
2914 case NWID_HORIZONTAL:
2915 if (dest != nullptr) return nwid_begin;
2916 dest = std::make_unique<NWidgetHorizontal>(nwid_begin->u.cont_flags);
2917 *fill_dest = true;
2918 break;
2919
2920 case NWID_HORIZONTAL_LTR:
2921 if (dest != nullptr) return nwid_begin;
2922 dest = std::make_unique<NWidgetHorizontalLTR>(nwid_begin->u.cont_flags);
2923 *fill_dest = true;
2924 break;
2925
2926 case WWT_PANEL:
2927 case WWT_INSET:
2928 case WWT_FRAME:
2929 if (dest != nullptr) return nwid_begin;
2930 dest = std::make_unique<NWidgetBackground>(nwid_begin->type, nwid_begin->u.widget.colour, nwid_begin->u.widget.index);
2931 *fill_dest = true;
2932 break;
2933
2934 case NWID_VERTICAL:
2935 if (dest != nullptr) return nwid_begin;
2936 dest = std::make_unique<NWidgetVertical>(nwid_begin->u.cont_flags);
2937 *fill_dest = true;
2938 break;
2939
2940 case NWID_MATRIX: {
2941 if (dest != nullptr) return nwid_begin;
2942 dest = std::make_unique<NWidgetMatrix>(nwid_begin->u.widget.colour, nwid_begin->u.widget.index);
2943 *fill_dest = true;
2944 break;
2945 }
2946
2947 case WPT_FUNCTION: {
2948 if (dest != nullptr) return nwid_begin;
2949 dest = nwid_begin->u.func_ptr();
2950 *fill_dest = false;
2951 break;
2952 }
2953
2954 case WPT_RESIZE: {
2955 NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(dest.get());
2956 if (nwrb == nullptr) [[unlikely]] throw std::runtime_error("WPT_RESIZE requires NWidgetResizeBase");
2957 assert(nwid_begin->u.xy.x >= 0 && nwid_begin->u.xy.y >= 0);
2958 nwrb->SetResize(nwid_begin->u.xy.x, nwid_begin->u.xy.y);
2959 break;
2960 }
2961
2962 case WPT_MINSIZE: {
2963 NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(dest.get());
2964 if (nwrb == nullptr) [[unlikely]] throw std::runtime_error("WPT_MINSIZE requires NWidgetResizeBase");
2965 assert(nwid_begin->u.xy.x >= 0 && nwid_begin->u.xy.y >= 0);
2966 nwrb->SetMinimalSize(nwid_begin->u.xy.x, nwid_begin->u.xy.y);
2967 break;
2968 }
2969
2970 case WPT_MINTEXTLINES: {
2971 NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(dest.get());
2972 if (nwrb == nullptr) [[unlikely]] throw std::runtime_error("WPT_MINTEXTLINES requires NWidgetResizeBase");
2973 assert(nwid_begin->u.text_lines.size >= FS_BEGIN && nwid_begin->u.text_lines.size < FS_END);
2974 nwrb->SetMinimalTextLines(nwid_begin->u.text_lines.lines, nwid_begin->u.text_lines.spacing, nwid_begin->u.text_lines.size);
2975 break;
2976 }
2977
2978 case WPT_TEXTSTYLE: {
2979 NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(dest.get());
2980 if (nwc == nullptr) [[unlikely]] throw std::runtime_error("WPT_TEXTSTYLE requires NWidgetCore");
2981 nwc->SetTextStyle(nwid_begin->u.text_style.colour, nwid_begin->u.text_style.size);
2982 break;
2983 }
2984
2985 case WPT_ALIGNMENT: {
2986 NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(dest.get());
2987 if (nwc == nullptr) [[unlikely]] throw std::runtime_error("WPT_ALIGNMENT requires NWidgetCore");
2988 nwc->SetAlignment(nwid_begin->u.align.align);
2989 break;
2990 }
2991
2992 case WPT_FILL: {
2993 NWidgetResizeBase *nwrb = dynamic_cast<NWidgetResizeBase *>(dest.get());
2994 if (nwrb == nullptr) [[unlikely]] throw std::runtime_error("WPT_FILL requires NWidgetResizeBase");
2995 nwrb->SetFill(nwid_begin->u.xy.x, nwid_begin->u.xy.y);
2996 break;
2997 }
2998
2999 case WPT_DATATIP: {
3000 NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(dest.get());
3001 if (nwc == nullptr) [[unlikely]] throw std::runtime_error("WPT_DATATIP requires NWidgetCore");
3002 nwc->widget_data = nwid_begin->u.data_tip.data;
3003 nwc->tool_tip = nwid_begin->u.data_tip.tooltip;
3004 break;
3005 }
3006
3007 case WPT_PADDING:
3008 if (dest == nullptr) [[unlikely]] throw std::runtime_error("WPT_PADDING requires NWidgetBase");
3009 dest->SetPadding(nwid_begin->u.padding);
3010 break;
3011
3012 case WPT_PIPSPACE: {
3013 NWidgetPIPContainer *nwc = dynamic_cast<NWidgetPIPContainer *>(dest.get());
3014 if (nwc != nullptr) nwc->SetPIP(nwid_begin->u.pip.pre, nwid_begin->u.pip.inter, nwid_begin->u.pip.post);
3015
3016 NWidgetBackground *nwb = dynamic_cast<NWidgetBackground *>(dest.get());
3017 if (nwb != nullptr) nwb->SetPIP(nwid_begin->u.pip.pre, nwid_begin->u.pip.inter, nwid_begin->u.pip.post);
3018
3019 if (nwc == nullptr && nwb == nullptr) [[unlikely]] throw std::runtime_error("WPT_PIPSPACE requires NWidgetPIPContainer or NWidgetBackground");
3020 break;
3021 }
3022
3023 case WPT_PIPRATIO: {
3024 NWidgetPIPContainer *nwc = dynamic_cast<NWidgetPIPContainer *>(dest.get());
3025 if (nwc != nullptr) nwc->SetPIPRatio(nwid_begin->u.pip.pre, nwid_begin->u.pip.inter, nwid_begin->u.pip.post);
3026
3027 NWidgetBackground *nwb = dynamic_cast<NWidgetBackground *>(dest.get());
3028 if (nwb != nullptr) nwb->SetPIPRatio(nwid_begin->u.pip.pre, nwid_begin->u.pip.inter, nwid_begin->u.pip.post);
3029
3030 if (nwc == nullptr && nwb == nullptr) [[unlikely]] throw std::runtime_error("WPT_PIPRATIO requires NWidgetPIPContainer or NWidgetBackground");
3031 break;
3032 }
3033
3034 case WPT_SCROLLBAR: {
3035 NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(dest.get());
3036 if (nwc == nullptr) [[unlikely]] throw std::runtime_error("WPT_SCROLLBAR requires NWidgetCore");
3037 nwc->scrollbar_index = nwid_begin->u.widget.index;
3038 break;
3039 }
3040
3041 case WPT_ENDCONTAINER:
3042 return nwid_begin;
3043
3044 case NWID_VIEWPORT:
3045 if (dest != nullptr) return nwid_begin;
3046 dest = std::make_unique<NWidgetViewport>(nwid_begin->u.widget.index);
3047 break;
3048
3049 case NWID_HSCROLLBAR:
3050 case NWID_VSCROLLBAR:
3051 if (dest != nullptr) return nwid_begin;
3052 dest = std::make_unique<NWidgetScrollbar>(nwid_begin->type, nwid_begin->u.widget.colour, nwid_begin->u.widget.index);
3053 break;
3054
3055 case NWID_SELECTION: {
3056 if (dest != nullptr) return nwid_begin;
3057 dest = std::make_unique<NWidgetStacked>(nwid_begin->u.widget.index);
3058 *fill_dest = true;
3059 break;
3060 }
3061
3062 default:
3063 if (dest != nullptr) return nwid_begin;
3064 assert((nwid_begin->type & WWT_MASK) < WWT_LAST || (nwid_begin->type & WWT_MASK) == NWID_BUTTON_DROPDOWN);
3065 dest = std::make_unique<NWidgetLeaf>(nwid_begin->type, nwid_begin->u.widget.colour, nwid_begin->u.widget.index, 0x0, STR_NULL);
3066 break;
3067 }
3068 nwid_begin++;
3069 }
3070
3071 return nwid_begin;
3072 }
3073
3079 bool IsContainerWidgetType(WidgetType tp)
3080 {
3081 return tp == NWID_HORIZONTAL || tp == NWID_HORIZONTAL_LTR || tp == NWID_VERTICAL || tp == NWID_MATRIX
3082 || tp == WWT_PANEL || tp == WWT_FRAME || tp == WWT_INSET || tp == NWID_SELECTION;
3083 }
3084
3092 static const NWidgetPart *MakeWidgetTree(const NWidgetPart *nwid_begin, const NWidgetPart *nwid_end, std::unique_ptr<NWidgetBase> &parent)
3093 {
3094 /* If *parent == nullptr, only the first widget is read and returned. Otherwise, *parent must point to either
3095 * a #NWidgetContainer or a #NWidgetBackground object, and parts are added as much as possible. */
3096 NWidgetContainer *nwid_cont = dynamic_cast<NWidgetContainer *>(parent.get());
3097 NWidgetBackground *nwid_parent = dynamic_cast<NWidgetBackground *>(parent.get());
3098 assert(parent == nullptr || (nwid_cont != nullptr && nwid_parent == nullptr) || (nwid_cont == nullptr && nwid_parent != nullptr));
3099
3100 for (;;) {
3101 std::unique_ptr<NWidgetBase> sub_widget = nullptr;
3102 bool fill_sub = false;
3103 nwid_begin = MakeNWidget(nwid_begin, nwid_end, sub_widget, &fill_sub);
3104
3105 /* Break out of loop when end reached */
3106 if (sub_widget == nullptr) break;
3107
3108 /* If sub-widget is a container, recursively fill that container. */
3109 if (fill_sub && IsContainerWidgetType(sub_widget->type)) {
3110 nwid_begin = MakeWidgetTree(nwid_begin, nwid_end, sub_widget);
3111 }
3112
3113 /* Add sub_widget to parent container if available, otherwise return the widget to the caller. */
3114 if (nwid_cont != nullptr) nwid_cont->Add(std::move(sub_widget));
3115 if (nwid_parent != nullptr) nwid_parent->Add(std::move(sub_widget));
3116 if (nwid_cont == nullptr && nwid_parent == nullptr) {
3117 parent = std::move(sub_widget);
3118 return nwid_begin;
3119 }
3120 }
3121
3122 if (nwid_begin == nwid_end) return nwid_begin; // Reached the end of the array of parts?
3123
3124 assert(nwid_begin < nwid_end);
3125 assert(nwid_begin->type == WPT_ENDCONTAINER);
3126 return nwid_begin + 1; // *nwid_begin is also 'used'
3127 }
3128
3137 std::unique_ptr<NWidgetBase> MakeNWidgets(const NWidgetPart *nwid_begin, const NWidgetPart *nwid_end, std::unique_ptr<NWidgetBase> &&container)
3138 {
3139 if (container == nullptr) container = std::make_unique<NWidgetVertical>();
3140 [[maybe_unused]] const NWidgetPart *nwid_part = MakeWidgetTree(nwid_begin, nwid_end, container);
3141 #ifdef WITH_ASSERT
3142 if (nwid_part != nwid_end) [[unlikely]] throw std::runtime_error("Did not consume all NWidgetParts");
3143 #endif
3144 return std::move(container);
3145 }
3146
3157 std::unique_ptr<NWidgetBase> MakeWindowNWidgetTree(const NWidgetPart *nwid_begin, const NWidgetPart *nwid_end, NWidgetStacked **shade_select)
3158 {
3159 *shade_select = nullptr;
3160
3161 /* Read the first widget recursively from the array. */
3162 std::unique_ptr<NWidgetBase> nwid = nullptr;
3163 nwid_begin = MakeWidgetTree(nwid_begin, nwid_end, nwid);
3164 assert(nwid != nullptr);
3165
3166 NWidgetHorizontal *hor_cont = dynamic_cast<NWidgetHorizontal *>(nwid.get());
3167
3168 auto root = std::make_unique<NWidgetVertical>();
3169 root->Add(std::move(nwid));
3170 if (nwid_begin == nwid_end) return root; // There is no body at all.
3171
3172 if (hor_cont != nullptr && hor_cont->GetWidgetOfType(WWT_CAPTION) != nullptr && hor_cont->GetWidgetOfType(WWT_SHADEBOX) != nullptr) {
3173 /* If the first widget has a title bar and a shade box, silently add a shade selection widget in the tree. */
3174 auto shade_stack = std::make_unique<NWidgetStacked>(-1);
3175 *shade_select = shade_stack.get();
3176 /* Load the remaining parts into the shade stack. */
3177 shade_stack->Add(MakeNWidgets(nwid_begin, nwid_end, std::make_unique<NWidgetVertical>()));
3178 root->Add(std::move(shade_stack));
3179 return root;
3180 }
3181
3182 /* Load the remaining parts into 'root'. */
3183 return MakeNWidgets(nwid_begin, nwid_end, std::move(root));
3184 }
3185
3196 std::unique_ptr<NWidgetBase> MakeCompanyButtonRows(WidgetID widget_first, WidgetID widget_last, Colours button_colour, int max_length, StringID button_tooltip, bool resizable)
3197 {
3198 assert(max_length >= 1);
3199 std::unique_ptr<NWidgetVertical> vert = nullptr; // Storage for all rows.
3200 std::unique_ptr<NWidgetHorizontal> hor = nullptr; // Storage for buttons in one row.
3201 int hor_length = 0;
3202
3203 Dimension sprite_size = GetSpriteSize(SPR_COMPANY_ICON, nullptr, ZOOM_LVL_OUT_4X);
3204 sprite_size.width += WidgetDimensions::unscaled.matrix.Horizontal();
3205 sprite_size.height += WidgetDimensions::unscaled.matrix.Vertical();
3206
3207 for (WidgetID widnum = widget_first; widnum <= widget_last; widnum++) {
3208 /* Ensure there is room in 'hor' for another button. */
3209 if (hor_length == max_length) {
3210 if (vert == nullptr) vert = std::make_unique<NWidgetVertical>();
3211 vert->Add(std::move(hor));
3212 hor = nullptr;
3213 hor_length = 0;
3214 }
3215 if (hor == nullptr) {
3216 hor = std::make_unique<NWidgetHorizontal>();
3217 hor_length = 0;
3218 }
3219
3220 auto panel = std::make_unique<NWidgetBackground>(WWT_PANEL, button_colour, widnum);
3221 panel->SetMinimalSize(sprite_size.width, sprite_size.height);
3222 panel->SetFill(1, 1);
3223 if (resizable) panel->SetResize(1, 0);
3224 panel->SetDataTip(0x0, button_tooltip);
3225 hor->Add(std::move(panel));
3226 hor_length++;
3227 }
3228 if (vert == nullptr) return hor; // All buttons fit in a single row.
3229
3230 if (hor_length > 0 && hor_length < max_length) {
3231 /* Last row is partial, add a spacer at the end to force all buttons to the left. */
3232 auto spc = std::make_unique<NWidgetSpacer>(sprite_size.width, sprite_size.height);
3233 spc->SetFill(1, 1);
3234 if (resizable) spc->SetResize(1, 0);
3235 hor->Add(std::move(spc));
3236 }
3237 if (hor != nullptr) vert->Add(std::move(hor));
3238 return vert;
3239 }
WidgetDimensions::WD_DROPDOWN_HEIGHT
@ WD_DROPDOWN_HEIGHT
Minimum height of a drop down widget.
Definition: window_gui.h:84
ES_HANDLED
@ ES_HANDLED
The passed event is handled.
Definition: window_type.h:739
WidgetDimensions::WD_CLOSEBOX_WIDTH
@ WD_CLOSEBOX_WIDTH
Minimum width of a close box widget.
Definition: window_gui.h:81
NWidgetSpacer::NWidgetSpacer
NWidgetSpacer(int width, int height)
Generic spacer widget.
Definition: widget.cpp:1716
NWidgetResizeBase
Base class for a resizable nested widget.
Definition: widget_type.h:291
NWidgetMatrix::clicked
int clicked
The currently clicked element.
Definition: widget_type.h:599
ScrollbarClickHandler
void ScrollbarClickHandler(Window *w, NWidgetCore *nw, int x, int y)
Special handling for the scrollbar widget type.
Definition: widget.cpp:242
NWidgetContainer::children
std::vector< std::unique_ptr< NWidgetBase > > children
Child widgets in contaier.
Definition: widget_type.h:462
NWidgetScrollbar::SetupSmallestSize
void SetupSmallestSize(Window *w) override
Definition: widget.cpp:2371
NWidgetMatrix::widgets_y
int widgets_y
The number of visible widgets in vertical direction.
Definition: widget_type.h:607
NWidgetBackground::SetupSmallestSize
void SetupSmallestSize(Window *w) override
Definition: widget.cpp:2053
NWidgetResizeBase::uz_min_x
uint uz_min_x
Unscaled Minimal horizontal size of only this widget.
Definition: widget_type.h:312
NWidgetCore::IsDisabled
bool IsDisabled() const
Return whether the widget is disabled.
Definition: widget_type.h:435
NWidgetPIPContainer::uz_pip_pre
uint8_t uz_pip_pre
Unscaled space before first widget.
Definition: widget_type.h:531
WWT_IMGBTN_2
@ WWT_IMGBTN_2
(Toggle) Button with diff image when clicked
Definition: widget_type.h:55
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
WPT_DATATIP
@ WPT_DATATIP
Widget part for specifying data and tooltip.
Definition: widget_type.h:94
Rect::Height
int Height() const
Get height of Rect.
Definition: geometry_type.hpp:91
WPT_PIPRATIO
@ WPT_PIPRATIO
Widget part for specifying pre/inter/post ratio for containers.
Definition: widget_type.h:97
WidgetDimensions::imgbtn
RectPadding imgbtn
Padding around image button image.
Definition: window_gui.h:36
TO_TEXT
@ TO_TEXT
loading and cost/income text
Definition: transparency.h:31
SA_HOR_MASK
@ SA_HOR_MASK
Mask for horizontal alignment.
Definition: gfx_type.h:341
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:1509
WF_SIZING
@ WF_SIZING
Window is being resized.
Definition: window_gui.h:227
NWidgetSpacer::GetWidgetFromPos
NWidgetCore * GetWidgetFromPos(int x, int y) override
Definition: widget.cpp:1749
WidgetDimensions::dropdownlist
RectPadding dropdownlist
Padding of complete drop down list.
Definition: window_gui.h:53
querystring_gui.h
SortButtonState
SortButtonState
State of a sort direction button.
Definition: window_gui.h:212
GUISettings::newgrf_developer_tools
bool newgrf_developer_tools
activate NewGRF developer tools and allow modifying NewGRFs in an existing game
Definition: settings_type.h:216
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:178
PALETTE_TEXT_RECOLOUR
@ PALETTE_TEXT_RECOLOUR
Set if palette is actually a magic text recolour.
Definition: sprites.h:1524
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:30
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
NWidgetLeaf::resizebox_dimension
static Dimension resizebox_dimension
Cached size of a resizebox widget.
Definition: widget_type.h:896
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:68
DrawCloseBox
static void DrawCloseBox(const Rect &r, Colours colour)
Draw a close box.
Definition: widget.cpp:658
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:98
_transparency_opt
TransparencyOptionBits _transparency_opt
The bits that should be transparent.
Definition: transparency_gui.cpp:23
NWidgetCore::SetDataTip
void SetDataTip(uint32_t widget_data, StringID tool_tip)
Set data and tool tip of the nested widget.
Definition: widget.cpp:1094
SZSP_BEGIN
@ SZSP_BEGIN
First zero-size plane.
Definition: widget_type.h:471
NWidgetPart::NWidgetPartUnion::text_lines
NWidgetPartTextLines text_lines
Part with text line data.
Definition: widget_type.h:1046
NWidgetPartTextStyle::size
FontSize size
Font size of text.
Definition: widget_type.h:1017
NWID_HSCROLLBAR
@ NWID_HSCROLLBAR
Horizontal scrollbar.
Definition: widget_type.h:85
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
NWidgetContainer::GetWidgetFromPos
NWidgetCore * GetWidgetFromPos(int x, int y) override
Definition: widget.cpp:1184
NWidgetContainer::Add
void Add(std::unique_ptr< NWidgetBase > &&wid)
Append widget wid to container.
Definition: widget.cpp:1161
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:821
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:63
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:608
NWidgetPIPContainer::SetPIP
void SetPIP(uint8_t pip_pre, uint8_t pip_inter, uint8_t pip_post)
Set additional pre/inter/post space for the container.
Definition: widget.cpp:1328
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
WWT_IMGBTN
@ WWT_IMGBTN
(Toggle) Button with image
Definition: widget_type.h:54
NWidgetViewport::InitializeViewport
void InitializeViewport(Window *w, std::variant< TileIndex, VehicleID > focus, ZoomLevel zoom)
Initialize the viewport of the window.
Definition: widget.cpp:2228
PC_WHITE
static const uint8_t PC_WHITE
White palette colour.
Definition: palette_func.h:58
Window::viewport
ViewportData * viewport
Pointer to viewport data, if present.
Definition: window_gui.h:312
ND_SHADE_DIMMED
@ ND_SHADE_DIMMED
Bit value of the 'dimmed colours' flag.
Definition: widget_type.h:343
NWidgetPIPContainer::pip_ratio_pre
uint8_t pip_ratio_pre
Ratio of remaining space before first widget.
Definition: widget_type.h:527
WWT_LABEL
@ WWT_LABEL
Centered label.
Definition: widget_type.h:59
Viewport::height
int height
Screen height of the viewport.
Definition: viewport_type.h:26
NWidgetCore::widget_data
uint32_t widget_data
Data of the widget.
Definition: widget_type.h:379
NWidgetSpacer::SetupSmallestSize
void SetupSmallestSize(Window *w) override
Definition: widget.cpp:1722
NWidgetBase::uz_padding
RectPadding uz_padding
Unscaled padding, for resize calculation.
Definition: widget_type.h:240
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:67
FrameFlags
FrameFlags
Flags to describe the look of the frame.
Definition: window_gui.h:24
GB
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
NWidgetStacked::Draw
void Draw(const Window *w) override
Definition: widget.cpp:1275
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:77
NWidgetMatrix::Draw
void Draw(const Window *w) override
Definition: widget.cpp:1899
NWidgetLeaf::stickybox_dimension
static Dimension stickybox_dimension
Cached size of a stickybox widget.
Definition: widget_type.h:902
NDB_SCROLLBAR_DOWN
@ NDB_SCROLLBAR_DOWN
Down-button is lowered bit.
Definition: widget_type.h:333
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:709
Window::IsNewGRFInspectable
virtual bool IsNewGRFInspectable() const
Is the data related to this window NewGRF inspectable?
Definition: window_gui.h:846
WF_STICKY
@ WF_STICKY
Window is made sticky by user.
Definition: window_gui.h:228
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:22
DrawInset
static void DrawInset(const Rect &r, Colours colour, TextColour text_colour, StringID str, StringAlignment align, FontSize fs)
Draw an inset widget.
Definition: widget.cpp:389
WWT_MATRIX
@ WWT_MATRIX
Grid of rows and columns.
Definition: widget_type.h:61
NWidgetBase::parent
NWidgetBase * parent
Parent widget of this widget, automatically filled in when added to container.
Definition: widget_type.h:242
NWidgetCore::NWidgetCore
NWidgetCore(WidgetType tp, Colours colour, WidgetID index, uint fill_x, uint fill_y, uint32_t widget_data, StringID tool_tip)
Initialization of a 'real' widget.
Definition: widget.cpp:1078
NWID_HORIZONTAL_LTR
@ NWID_HORIZONTAL_LTR
Horizontal container that doesn't change the order of the widgets for RTL languages.
Definition: widget_type.h:78
PALETTE_TO_TRANSPARENT
static const PaletteID PALETTE_TO_TRANSPARENT
This sets the sprite to transparent.
Definition: sprites.h:1599
WWT_ARROWBTN
@ WWT_ARROWBTN
(Toggle) Button with an arrow
Definition: widget_type.h:56
NWidgetBase::NWidgetBase
NWidgetBase(WidgetType tp)
Base class constructor.
Definition: widget.cpp:851
Scrollbar::SetStepSize
void SetStepSize(size_t stepsize)
Set the distance to scroll when using the buttons or the wheel.
Definition: widget_type.h:748
NWidgetResizeBase::uz_min_y
uint uz_min_y
Unscaled Minimal vertical size of only this widget.
Definition: widget_type.h:313
FILLRECT_CHECKER
@ FILLRECT_CHECKER
Draw only every second pixel, used for greying-out.
Definition: gfx_type.h:294
NWidgetPIPContainer::pip_ratio_inter
uint8_t pip_ratio_inter
Ratio of remaining space between widgets.
Definition: widget_type.h:528
MAT_ROW_START
@ MAT_ROW_START
Lowest bit of the number of rows.
Definition: widget_type.h:27
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:253
WidgetDimensions::closebox
RectPadding closebox
Padding around image in closebox widget.
Definition: window_gui.h:50
zoom_func.h
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, WidgetID widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition: widget.cpp:2334
MakeNWidget
static const NWidgetPart * MakeNWidget(const NWidgetPart *nwid_begin, const NWidgetPart *nwid_end, std::unique_ptr< NWidgetBase > &dest, bool *fill_dest)
Construct a single nested widget in *dest from its parts.
Definition: widget.cpp:2902
ZoomLevel
ZoomLevel
All zoom levels we know.
Definition: zoom_type.h:19
NWidgetResizeBase::UpdateVerticalSize
bool UpdateVerticalSize(uint min_y)
Set absolute (post-scaling) minimal size of the widget.
Definition: widget.cpp:1056
CeilDiv
constexpr uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
Definition: math_func.hpp:320
SA_BOTTOM
@ SA_BOTTOM
Bottom align the text.
Definition: gfx_type.h:345
NWidgetMatrix::SetScrollbar
void SetScrollbar(Scrollbar *sb)
Assign a scrollbar to this matrix.
Definition: widget.cpp:1804
StringAlignment
StringAlignment
How to align the to-be drawn text.
Definition: gfx_type.h:337
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:54
NWidgetMatrix::count
int count
Amount of valid elements.
Definition: widget_type.h:600
SZSP_HORIZONTAL
@ SZSP_HORIZONTAL
Display plane with zero size vertically, and filling and resizing horizontally.
Definition: widget_type.h:468
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition: widget_type.h:50
WidgetDimensions::hsep_wide
int hsep_wide
Wide horizontal spacing.
Definition: window_gui.h:64
Window::owner
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
Definition: window_gui.h:310
RectPadding::Vertical
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Definition: geometry_type.hpp:69
WWT_PUSHARROWBTN
@ WWT_PUSHARROWBTN
Normal push-button (no toggle button) with arrow caption.
Definition: widget_type.h:112
FR_LOWERED
@ FR_LOWERED
If set the frame is lowered and the background colour brighter (ie. buttons when pressed)
Definition: window_gui.h:28
Window::UpdateWidgetSize
virtual void UpdateWidgetSize([[maybe_unused]] WidgetID widget, [[maybe_unused]] Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize)
Update size and resize step of a widget in the window.
Definition: window_gui.h:617
NWidgetCore::tool_tip
StringID tool_tip
Tooltip of the widget.
Definition: widget_type.h:380
GetWidgetFromPos
WidgetID 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:266
NWidgetContainer::GetWidgetOfType
NWidgetBase * GetWidgetOfType(WidgetType tp) override
Retrieve a widget by its type.
Definition: widget.cpp:1139
Rect::Expand
Rect Expand(int s) const
Copy and expand Rect by s pixels.
Definition: geometry_type.hpp:153
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition: gfx_type.h:340
MakeWindowNWidgetTree
std::unique_ptr< NWidgetBase > MakeWindowNWidgetTree(const NWidgetPart *nwid_begin, const NWidgetPart *nwid_end, NWidgetStacked **shade_select)
Make a nested widget tree for a window from a parts array.
Definition: widget.cpp:3157
SA_VERT_CENTER
@ SA_VERT_CENTER
Vertically center the text.
Definition: gfx_type.h:344
NWidgetCore::SetLowered
void SetLowered(bool lowered)
Lower or raise the widget.
Definition: widget_type.h:414
NWidgetPIPContainer::SetPIPRatio
void SetPIPRatio(uint8_t pip_ratio_pre, uint8_t pip_ratio_inter, uint8_t pip_rato_post)
Set additional pre/inter/post space for the container.
Definition: widget.cpp:1348
NWidgetPart::NWidgetPartUnion::text_style
NWidgetPartTextStyle text_style
Part with text style data.
Definition: widget_type.h:1047
NWidgetLeaf::shadebox_dimension
static Dimension shadebox_dimension
Cached size of a shadebox widget.
Definition: widget_type.h:899
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
NWID_MATRIX
@ NWID_MATRIX
Matrix container.
Definition: widget_type.h:80
NWidgetBase::smallest_y
uint smallest_y
Smallest vertical size of the widget in a filled window.
Definition: widget_type.h:231
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:678
PaletteID
uint32_t PaletteID
The number of the palette.
Definition: gfx_type.h:18
FR_TRANSPARENT
@ FR_TRANSPARENT
Makes the background transparent if set.
Definition: window_gui.h:26
NWidgetCore::text_size
FontSize text_size
Size of text within widget.
Definition: widget_type.h:384
NWidgetPIPContainer::pip_pre
uint8_t pip_pre
Amount of space before first widget.
Definition: widget_type.h:524
Rect::WithHeight
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Definition: geometry_type.hpp:211
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:1038
DrawDefSizeBox
static void DrawDefSizeBox(const Rect &r, Colours colour, bool clicked)
Draw a defsize box.
Definition: widget.cpp:619
NWidgetScrollbar::NWidgetScrollbar
NWidgetScrollbar(WidgetType tp, Colours colour, WidgetID index)
Scrollbar widget.
Definition: widget.cpp:2350
Scrollbar::GetPosition
uint16_t GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:720
NWidgetMatrix::sb
Scrollbar * sb
The scrollbar we're associated with.
Definition: widget_type.h:602
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:23
NWidgetPartPIP::post
uint8_t post
Amount of space before/between/after child widgets.
Definition: widget_type.h:998
NWidgetPIPContainer::pip_inter
uint8_t pip_inter
Amount of space between widgets.
Definition: widget_type.h:525
_colour_gradient
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: palette.cpp:26
DrawMatrix
static void DrawMatrix(const Rect &r, Colours colour, bool clicked, uint16_t data, uint resize_x, uint resize_y)
Draw a matrix widget.
Definition: widget.cpp:404
Scrollbar::GetCount
uint16_t GetCount() const
Gets the number of elements in the list.
Definition: widget_type.h:702
NWidgetMatrix::current_element
int current_element
The element currently being processed.
Definition: widget_type.h:601
NWidgetBase::StoreSizePosition
void StoreSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height)
Store size and position.
Definition: widget_type.h:274
NWidgetResizeBase::UpdateMultilineWidgetSize
bool UpdateMultilineWidgetSize(const std::string &str, int max_lines)
Try to set optimum widget size for a multiline text widget.
Definition: widget.cpp:1022
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:1780
WidgetDimensions::shadebox
RectPadding shadebox
Padding around image in shadebox widget.
Definition: window_gui.h:45
WidgetID
int WidgetID
Widget ID.
Definition: window_type.h:18
RectPadding::Horizontal
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
Definition: geometry_type.hpp:63
NWidgetPart::NWidgetPartUnion::data_tip
NWidgetPartDataTip data_tip
Part with a data/tooltip.
Definition: widget_type.h:1042
Scrollbar::UpdateListPositionOnKeyPress
EventState UpdateListPositionOnKeyPress(int &list_position, uint16_t keycode) const
Update the given list position as if it were on this scroll bar when the given keycode was pressed.
Definition: widget.cpp:2281
window_gui.h
NWidgetLeaf::InvalidateDimensionCache
static void InvalidateDimensionCache()
Reset the cached dimensions.
Definition: widget.cpp:2448
NWidgetResizeBase::NWidgetResizeBase
NWidgetResizeBase(WidgetType tp, uint fill_x, uint fill_y)
Constructor for resizable nested widgets.
Definition: widget.cpp:939
NWidgetPIPContainer::uz_pip_post
uint8_t uz_pip_post
Unscaled space after last widget.
Definition: widget_type.h:533
RectPadding
Padding dimensions to apply to each side of a Rect.
Definition: geometry_type.hpp:51
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:508
NWidgetResizeBase::uz_text_spacing
uint8_t uz_text_spacing
'Unscaled' text padding, stored for resize calculation.
Definition: widget_type.h:316
ND_DROPDOWN_ACTIVE
@ ND_DROPDOWN_ACTIVE
Bit value of the 'dropdown active' flag.
Definition: widget_type.h:344
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:804
_company_colours
Colours _company_colours[MAX_COMPANIES]
NOSAVE: can be determined from company structs.
Definition: company_cmd.cpp:51
NWidgetPart::NWidgetPartUnion::func_ptr
NWidgetFunctionType * func_ptr
Part with a function call.
Definition: widget_type.h:1049
AWV_LEFT
@ AWV_LEFT
Force the arrow to the left.
Definition: widget_type.h:35
NWidgetMatrix::AssignSizePosition
void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override
Definition: widget.cpp:1839
MakeCompanyButtonRows
std::unique_ptr< NWidgetBase > MakeCompanyButtonRows(WidgetID widget_first, WidgetID widget_last, Colours button_colour, int max_length, StringID button_tooltip, bool resizable)
Make a number of rows with button-like graphics, for enabling/disabling each company.
Definition: widget.cpp:3196
IsInsideBS
constexpr 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:252
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:93
ComputeMaxSize
uint ComputeMaxSize(uint base, uint max_space, uint step)
Return the biggest possible size of a nested widget.
Definition: widget_type.h:912
WidgetDimensions::WD_RESIZEBOX_WIDTH
@ WD_RESIZEBOX_WIDTH
Minimum width of a resize box widget.
Definition: window_gui.h:80
WWT_PUSHBTN
@ WWT_PUSHBTN
Normal push-button (no toggle button) with custom drawing.
Definition: widget_type.h:109
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:464
NWidgetLeaf::dropdown_dimension
static Dimension dropdown_dimension
Cached size of a dropdown widget.
Definition: widget_type.h:895
NWidgetStacked::AssignSizePosition
void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override
Definition: widget.cpp:1249
ST_SMALLEST
@ ST_SMALLEST
Initialize nested widget tree to smallest size. Also updates current_x and current_y.
Definition: widget_type.h:118
DrawShadeBox
static void DrawShadeBox(const Rect &r, Colours colour, bool clicked)
Draw a shade box.
Definition: widget.cpp:597
NWidgetResizeBase::SetMinimalTextLines
void SetMinimalTextLines(uint8_t min_lines, uint8_t spacing, FontSize size)
Set minimal text lines for the widget.
Definition: widget.cpp:985
WidgetDimensions::matrix
RectPadding matrix
Padding of WWT_MATRIX items.
Definition: window_gui.h:44
NWidgetViewport::UpdateViewportCoordinates
void UpdateViewportCoordinates(Window *w)
Update the position and size of the viewport (after eg a resize).
Definition: widget.cpp:2237
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:203
NWidgetHorizontal::AssignSizePosition
void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override
Definition: widget.cpp:1424
SA_TOP
@ SA_TOP
Top align the text.
Definition: gfx_type.h:343
NWID_VIEWPORT
@ NWID_VIEWPORT
Nested widget containing a viewport.
Definition: widget_type.h:83
NWidgetPart::NWidgetPartUnion::align
NWidgetPartAlignment align
Part with internal alignment.
Definition: widget_type.h:1048
Window::nested_root
std::unique_ptr< NWidgetBase > nested_root
Root of the nested tree.
Definition: window_gui.h:315
WWT_EDITBOX
@ WWT_EDITBOX
a textbox for typing
Definition: widget_type.h:73
NWidgetBase::type
WidgetType type
Type of the widget / nested widget.
Definition: widget_type.h:222
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:306
NWidgetCore::FillWidgetLookup
void FillWidgetLookup(WidgetLookup &widget_lookup) override
Definition: widget.cpp:1129
NWidgetPartTextLines::lines
uint8_t lines
Number of text lines.
Definition: widget_type.h:1006
WF_WHITE_BORDER
@ WF_WHITE_BORDER
Window white border counter bit mask.
Definition: window_gui.h:230
NWidgetResizeBase::SetResize
void SetResize(uint resize_x, uint resize_y)
Set resize step of the widget.
Definition: widget.cpp:1009
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:941
WidgetDimensions::hscrollbar
RectPadding hscrollbar
Padding inside horizontal scrollbar buttons.
Definition: window_gui.h:39
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:230
NWidgetLeaf::debugbox_dimension
static Dimension debugbox_dimension
Cached size of a debugbox widget.
Definition: widget_type.h:900
NWidgetBase::GetWidgetOfType
virtual NWidgetBase * GetWidgetOfType(WidgetType tp)
Retrieve a widget by its type.
Definition: widget.cpp:923
WPT_PIPSPACE
@ WPT_PIPSPACE
Widget part for specifying pre/inter/post space for containers.
Definition: widget_type.h:96
NWidgetContainer::FillWidgetLookup
void FillWidgetLookup(WidgetLookup &widget_lookup) override
Definition: widget.cpp:1168
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:740
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:110
NWidgetPIPContainer::gaps
uint8_t gaps
Number of gaps between widgets.
Definition: widget_type.h:535
NWidgetBackground::FillWidgetLookup
void FillWidgetLookup(WidgetLookup &widget_lookup) override
Definition: widget.cpp:2128
NWidgetCore::SetToolTip
void SetToolTip(StringID tool_tip)
Set the tool tip of the nested widget.
Definition: widget.cpp:1115
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:135
NWidgetBackground::GetWidgetOfType
NWidgetBase * GetWidgetOfType(WidgetType tp) override
Retrieve a widget by its type.
Definition: widget.cpp:2183
NWidgetContainer::Draw
void Draw(const Window *w) override
Definition: widget.cpp:1175
Scrollbar::IsVertical
bool IsVertical() const
Is the scrollbar vertical or not?
Definition: widget_type.h:739
NWidgetMatrix::GetWidgetFromPos
NWidgetCore * GetWidgetFromPos(int x, int y) override
Definition: widget.cpp:1869
PALETTE_NEWSPAPER
static const PaletteID PALETTE_NEWSPAPER
Recolour sprite for newspaper-greying.
Definition: sprites.h:1601
Scrollbar::GetCapacity
uint16_t GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:711
NWidgetBackground::SetPIPRatio
void SetPIPRatio(uint8_t pip_ratio_pre, uint8_t pip_ratio_inter, uint8_t pip_ratio_post)
Set additional pre/inter/post space ratios for the background widget.
Definition: widget.cpp:2038
DrawDebugBox
static void DrawDebugBox(const Rect &r, Colours colour, bool clicked)
Draw a NewGRF debug box.
Definition: widget.cpp:630
_string_colourmap
static const byte _string_colourmap[17]
Colour mapping for TextColour.
Definition: string_colours.h:11
SA_FORCE
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
Definition: gfx_type.h:350
WPT_SCROLLBAR
@ WPT_SCROLLBAR
Widget part for attaching a scrollbar.
Definition: widget_type.h:102
NWidgetPIPContainer::pip_ratio_post
uint8_t pip_ratio_post
Ratio of remaining space after last widget.
Definition: widget_type.h:529
MAT_COL_BITS
@ MAT_COL_BITS
Number of bits for the number of columns in the matrix.
Definition: widget_type.h:24
NWidgetMatrix::index
const WidgetID index
If non-negative, index in the Window::widget_lookup.
Definition: widget_type.h:597
MAX_COMPANIES
@ MAX_COMPANIES
Maximum number of companies.
Definition: company_type.h:23
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:317
safeguards.h
NWidgetCore::SetAlignment
void SetAlignment(StringAlignment align)
Set the text/image alignment of the nested widget.
Definition: widget.cpp:1124
Window::left
int left
x position of left edge of the window
Definition: window_gui.h:303
NWidgetLeaf::defsizebox_dimension
static Dimension defsizebox_dimension
Cached size of a defsizebox widget.
Definition: widget_type.h:901
Window::flags
WindowFlags flags
Window flags.
Definition: window_gui.h:294
NWidgetVertical::SetupSmallestSize
void SetupSmallestSize(Window *w) override
Definition: widget.cpp:1549
GetStringHeight
int GetStringHeight(std::string_view str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition: gfx.cpp:705
WWT_LAST
@ WWT_LAST
Last Item. use WIDGETS_END to fill up padding!!
Definition: widget_type.h:74
Window::GetQueryString
const QueryString * GetQueryString(WidgetID widnum) const
Return the querystring associated to a editbox.
Definition: window.cpp:335
WPT_ALIGNMENT
@ WPT_ALIGNMENT
Widget part for specifying text/image alignment.
Definition: widget_type.h:99
DrawResizeBox
static void DrawResizeBox(const Rect &r, Colours colour, bool at_left, bool clicked, bool bevel)
Draw a resize box.
Definition: widget.cpp:643
NWidgetStacked::FillWidgetLookup
void FillWidgetLookup(WidgetLookup &widget_lookup) override
Definition: widget.cpp:1269
Rect::WithWidth
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Definition: geometry_type.hpp:185
NDB_SCROLLBAR_UP
@ NDB_SCROLLBAR_UP
Up-button is lowered bit.
Definition: widget_type.h:332
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:1007
NWidgetVertical::AssignSizePosition
void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override
Definition: widget.cpp:1613
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:231
WPT_MINSIZE
@ WPT_MINSIZE
Widget part for specifying minimal size.
Definition: widget_type.h:91
NWidgetCore::IsLowered
bool IsLowered() const
Return whether the widget is lowered.
Definition: widget_type.h:420
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:504
Scrollbar::SetCapacity
void SetCapacity(size_t capacity)
Set the capacity of visible elements.
Definition: widget_type.h:774
WidgetDimensions::debugbox
RectPadding debugbox
Padding around image in debugbox widget.
Definition: window_gui.h:47
CenterBounds
int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
Definition: gfx_func.h:166
WWT_FRAME
@ WWT_FRAME
Frame.
Definition: widget_type.h:62
NWidgetStacked::GetWidgetFromPos
NWidgetCore * GetWidgetFromPos(int x, int y) override
Definition: widget.cpp:1284
stdafx.h
GetScaledSpriteSize
Dimension GetScaledSpriteSize(SpriteID sprid)
Scale sprite size for GUI.
Definition: widget.cpp:54
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:113
DrawLabel
static void DrawLabel(const Rect &r, WidgetType type, bool clicked, TextColour colour, StringID str, StringAlignment align, FontSize fs)
Draw the label-part of a widget.
Definition: widget.cpp:356
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
NWidgetHorizontal::SetupSmallestSize
void SetupSmallestSize(Window *w) override
Definition: widget.cpp:1360
IsContainerWidgetType
bool IsContainerWidgetType(WidgetType tp)
Test if WidgetType is a container widget.
Definition: widget.cpp:3079
WidgetDimensions::inset
RectPadding inset
Padding inside inset container.
Definition: window_gui.h:37
viewport_func.h
NWidgetBase::current_y
uint current_y
Current vertical size (after resizing).
Definition: widget_type.h:234
NWidgetStacked
Stacked widgets, widgets all occupying the same space in the window.
Definition: widget_type.h:484
NWidgetScrollbar::vertical_dimension
static Dimension vertical_dimension
Cached size of vertical scrollbar button.
Definition: widget_type.h:876
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_type.h:339
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:79
WidgetType
WidgetType
Window widget types, nested widget types, and nested widget part types.
Definition: widget_type.h:48
NWidgetResizeBase::SetFill
void SetFill(uint fill_x, uint fill_y)
Set the filling of the widget from initial size.
Definition: widget.cpp:998
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:1571
Scrollbar::GetScrolledRowFromWidget
int GetScrolledRowFromWidget(int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const
Compute the row of a scrolled widget that a user clicked in.
Definition: widget.cpp:2260
WWT_TEXTBTN_2
@ WWT_TEXTBTN_2
(Toggle) Button with diff text when clicked
Definition: widget_type.h:58
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition: window_gui.h:67
MakeNWidgets
std::unique_ptr< NWidgetBase > MakeNWidgets(const NWidgetPart *nwid_begin, const NWidgetPart *nwid_end, std::unique_ptr< NWidgetBase > &&container)
Construct a nested widget tree from an array of parts.
Definition: widget.cpp:3137
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:941
NWidgetSpacer::SetDirty
void SetDirty(const Window *w) const override
Mark the widget as 'dirty' (in need of repaint).
Definition: widget.cpp:1744
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:71
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:70
WPT_MINTEXTLINES
@ WPT_MINTEXTLINES
Widget part for specifying minimal number of lines of text.
Definition: widget_type.h:92
NWidgetContainer::IsEmpty
bool IsEmpty()
Return whether the container is empty.
Definition: widget_type.h:457
NWidgetMatrix::FillWidgetLookup
void FillWidgetLookup(WidgetLookup &widget_lookup) override
Definition: widget.cpp:1863
DrawText
static void DrawText(const Rect &r, TextColour colour, StringID str, StringAlignment align, FontSize fs)
Draw text.
Definition: widget.cpp:373
Window::DrawWidget
virtual void DrawWidget([[maybe_unused]] const Rect &r, [[maybe_unused]] WidgetID widget) const
Draw the contents of a nested widget.
Definition: window_gui.h:603
NWidgetBackground::GetWidgetFromPos
NWidgetCore * GetWidgetFromPos(int x, int y) override
Definition: widget.cpp:2173
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:1954
NWidgetSpacer::Draw
void Draw(const Window *w) override
Definition: widget.cpp:1732
WWT_PUSHIMGBTN
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
Definition: widget_type.h:111
NWidgetBase::fill_y
uint fill_y
Vertical fill stepsize (from initial size, 0 means not resizable).
Definition: widget_type.h:224
SBS_DOWN
@ SBS_DOWN
Sort ascending.
Definition: window_gui.h:214
Window::DrawSortButtonState
void DrawSortButtonState(WidgetID widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
Definition: widget.cpp:763
NWidgetBackground::child
std::unique_ptr< NWidgetPIPContainer > child
Child widget.
Definition: widget_type.h:652
Window::SetStringParameters
virtual void SetStringParameters([[maybe_unused]] WidgetID widget) const
Initialize string parameters for a widget.
Definition: window_gui.h:625
NWidgetHorizontalLTR::AssignSizePosition
void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override
Definition: widget.cpp:1539
strings_func.h
WidgetDimensions::dropdowntext
RectPadding dropdowntext
Padding of drop down list item.
Definition: window_gui.h:52
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:86
WidgetDimensions::vsep_wide
int vsep_wide
Wide vertical spacing.
Definition: window_gui.h:62
NWidgetBackground::SetPIP
void SetPIP(uint8_t pip_pre, uint8_t pip_inter, uint8_t pip_post)
Set additional pre/inter/post space for the background widget.
Definition: widget.cpp:2019
SA_VERT_MASK
@ SA_VERT_MASK
Mask for vertical alignment.
Definition: gfx_type.h:346
NWidgetCore::disp_flags
NWidgetDisplay disp_flags
Flags that affect display and interaction with the widget.
Definition: widget_type.h:376
Window::IsShaded
bool IsShaded() const
Is window shaded currently?
Definition: window_gui.h:556
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:135
NWidgetBase::pos_x
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:236
NWidgetHorizontal
Horizontal container.
Definition: widget_type.h:542
NWidgetPIPContainer::pip_post
uint8_t pip_post
Amount of space after last widget.
Definition: widget_type.h:526
ST_RESIZE
@ ST_RESIZE
Resize the nested widget tree.
Definition: widget_type.h:119
WidgetLookup
std::map< WidgetID, class NWidgetBase * > WidgetLookup
Lookup between widget IDs and NWidget objects.
Definition: widget_type.h:127
Scrollbar::pos
uint16_t pos
Index of first visible item of the list.
Definition: widget_type.h:683
WWT_TEXT
@ WWT_TEXT
Pure simple text.
Definition: widget_type.h:60
WidgetDimensions::hsep_indent
int hsep_indent
Width of identation for tree layouts.
Definition: window_gui.h:65
NWidgetPIPContainer
Container with pre/inter/post child space.
Definition: widget_type.h:514
NWidgetLeaf::NWidgetLeaf
NWidgetLeaf(WidgetType tp, Colours colour, WidgetID index, uint32_t data, StringID tip)
Nested leaf widget.
Definition: widget.cpp:2475
NWidgetBase::fill_x
uint fill_x
Horizontal fill stepsize (from initial size, 0 means not resizable).
Definition: widget_type.h:223
NWidgetSpacer::FillWidgetLookup
void FillWidgetLookup(WidgetLookup &widget_lookup) override
Definition: widget.cpp:1728
NWidgetScrollbar
Nested widget to display and control a scrollbar in a window.
Definition: widget_type.h:864
geometry_func.hpp
NWidgetBackground::Draw
void Draw(const Window *w) override
Definition: widget.cpp:2134
WPT_RESIZE
@ WPT_RESIZE
Widget part for specifying resizing.
Definition: widget_type.h:90
NWidgetPIPContainer::flags
NWidContainerFlags flags
Flags of the container.
Definition: widget_type.h:523
transparency.h
NWidgetPartTextLines::spacing
uint8_t spacing
Extra spacing around lines.
Definition: widget_type.h:1007
NWidgetCore::scrollbar_index
WidgetID scrollbar_index
Index of an attached scrollbar.
Definition: widget_type.h:381
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:52
_window_highlight_colour
bool _window_highlight_colour
If false, highlight is white, otherwise the by the widget defined colour.
Definition: window.cpp:75
NWidgetPart::NWidgetPartUnion::pip
NWidgetPartPIP pip
Part with pre/inter/post spaces.
Definition: widget_type.h:1045
WidgetDimensions::WD_SHADEBOX_WIDTH
@ WD_SHADEBOX_WIDTH
Minimum width of a standard shade box widget.
Definition: window_gui.h:76
WidgetDimensions::vsep_normal
int vsep_normal
Normal vertical spacing.
Definition: window_gui.h:60
NWidgetStacked::SetDisplayedPlane
bool SetDisplayedPlane(int plane)
Select which plane to show (for NWID_SELECTION only).
Definition: widget.cpp:1299
AutoRestoreBackup
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
Definition: backup_type.hpp:153
NWidgetBase::resize_y
uint resize_y
Vertical resize step (0 means not resizable).
Definition: widget_type.h:226
ScaleSpriteTrad
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
Definition: zoom_func.h:107
NWidgetPIPContainer::uz_pip_inter
uint8_t uz_pip_inter
Unscaled space between widgets.
Definition: widget_type.h:532
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition: widget_type.h:760
EventState
EventState
State of handling an event.
Definition: window_type.h:738
Window::mouse_capture_widget
WidgetID mouse_capture_widget
ID of current mouse capture widget (e.g. dragged scrollbar). -1 if no widget has mouse capture.
Definition: window_gui.h:320
NWidgetMatrix::SetupSmallestSize
void SetupSmallestSize(Window *w) override
Definition: widget.cpp:1818
WidgetDimensions::vscrollbar
RectPadding vscrollbar
Padding inside vertical scrollbar buttons.
Definition: window_gui.h:38
WidgetDimensions::modalpopup
RectPadding modalpopup
Spacing for popup warning/information windows.
Definition: window_gui.h:54
NWidgetStacked::SetupSmallestSize
void SetupSmallestSize(Window *w) override
Definition: widget.cpp:1210
WidgetDimensions::stickybox
RectPadding stickybox
Padding around image in stickybox widget.
Definition: window_gui.h:46
NWidgetCore::colour
Colours colour
Colour of this widget.
Definition: widget_type.h:377
NWidgetMatrix::widget_h
int widget_h
The height of the child widget including inter spacing.
Definition: widget_type.h:605
Window::widget_lookup
WidgetLookup widget_lookup
Indexed access to the nested widget tree. Do not access directly, use Window::GetWidget() instead.
Definition: window_gui.h:316
PC_BLACK
static const uint8_t PC_BLACK
Black palette colour.
Definition: palette_func.h:55
NWidgetMatrix::GetCurrentElement
int GetCurrentElement() const
Get current element.
Definition: widget.cpp:1813
NWID_SPACER
@ NWID_SPACER
Invisible widget that takes some space.
Definition: widget_type.h:81
company_func.h
WWT_INSET
@ WWT_INSET
Pressed (inset) panel, most commonly used as combo box text area.
Definition: widget_type.h:53
WidgetDimensions::fullbevel
RectPadding fullbevel
Always-scaled bevel thickness.
Definition: window_gui.h:41
NWidgetContainer
Baseclass for container widgets.
Definition: widget_type.h:445
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:304
Window::DrawViewport
void DrawViewport() const
Draw the viewport of this window.
Definition: viewport.cpp:1826
InitializeWindowViewport
void InitializeWindowViewport(Window *w, int x, int y, int width, int height, std::variant< TileIndex, VehicleID > focus, ZoomLevel zoom)
Initialize viewport of the window for use.
Definition: viewport.cpp:219
NWidgetCore::index
const WidgetID index
Index of the nested widget (-1 means 'not used').
Definition: widget_type.h:378
SA_LEFT
@ SA_LEFT
Left align the text.
Definition: gfx_type.h:338
DrawFrameRect
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition: widget.cpp:281
NWidgetBase::SetDirty
virtual void SetDirty(const Window *w) const
Mark the widget as 'dirty' (in need of repaint).
Definition: widget.cpp:903
NWidgetResizeBase::uz_text_lines
uint8_t uz_text_lines
'Unscaled' text lines, stored for resize calculation.
Definition: widget_type.h:315
NWidgetBackground::NWidgetBackground
NWidgetBackground(WidgetType tp, Colours colour, WidgetID index, std::unique_ptr< NWidgetPIPContainer > &&child=nullptr)
Constructor parent nested widgets.
Definition: widget.cpp:1985
SA_CENTER
@ SA_CENTER
Center both horizontally and vertically.
Definition: gfx_type.h:348
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition: fontcache.cpp:78
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:305
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:106
Viewport::zoom
ZoomLevel zoom
The zoom level of the viewport.
Definition: viewport_type.h:33
NWidgetPart::NWidgetPartUnion::cont_flags
NWidContainerFlags cont_flags
Part with container flags.
Definition: widget_type.h:1050
Window::SortButtonWidth
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition: widget.cpp:780
NWidgetHorizontalLTR::NWidgetHorizontalLTR
NWidgetHorizontalLTR(NWidContainerFlags flags=NC_NONE)
Horizontal left-to-right container widget.
Definition: widget.cpp:1534
WidgetDimensions::resizebox
RectPadding resizebox
Padding around image in resizebox widget.
Definition: window_gui.h:49
DrawRectOutline
void DrawRectOutline(const Rect &r, int colour, int width, int dash)
Draw the outline of a Rect.
Definition: gfx.cpp:455
NWidgetPartDataTip::data
uint32_t data
Data value of the widget.
Definition: widget_type.h:973
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:29
NWidgetResizeBase::min_x
uint min_x
Minimal horizontal size of only this widget.
Definition: widget_type.h:308
NWidgetStacked::NWidgetStacked
NWidgetStacked(WidgetID index)
Widgets stacked on top of each other.
Definition: widget.cpp:1198
NWidgetBase::pos_y
int pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:237
NWidgetResizeBase::UpdateSize
bool UpdateSize(uint min_x, uint min_y)
Set absolute (post-scaling) minimal size of the widget.
Definition: widget.cpp:1042
NWidgetCore::align
StringAlignment align
Alignment of text/image within widget.
Definition: widget_type.h:385
Scrollbar::SS_BIG
@ SS_BIG
Step in cap units.
Definition: widget_type.h:691
DrawString
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:658
Window::GetRowFromWidget
int GetRowFromWidget(int clickpos, WidgetID widget, int padding, int line_height=-1) const
Compute the row of a widget that a user clicked in.
Definition: window.cpp:214
ND_SHADE_GREY
@ ND_SHADE_GREY
Bit value of the 'shade to grey' flag.
Definition: widget_type.h:342
WPT_PADDING
@ WPT_PADDING
Widget part for specifying a padding.
Definition: widget_type.h:95
NWidgetCore::SetTextStyle
void SetTextStyle(TextColour colour, FontSize size)
Set the text style of the nested widget.
Definition: widget.cpp:1105
NWidgetCore::text_colour
TextColour text_colour
Colour of text within widget.
Definition: widget_type.h:383
NWidgetPart::type
WidgetType type
Type of the part.
Definition: widget_type.h:1039
WidgetDimensions::WD_DEFSIZEBOX_WIDTH
@ WD_DEFSIZEBOX_WIDTH
Minimum width of a standard defsize box widget.
Definition: window_gui.h:79
WidgetDimensions::WD_STICKYBOX_WIDTH
@ WD_STICKYBOX_WIDTH
Minimum width of a standard sticky box widget.
Definition: window_gui.h:77
NWidgetResizeBase::min_y
uint min_y
Minimal vertical size of only this widget.
Definition: widget_type.h:309
WidgetDimensions::bevel
RectPadding bevel
Bevel thickness, affected by "scaled bevels" game option.
Definition: window_gui.h:40
WidgetDimensions::WD_DEBUGBOX_WIDTH
@ WD_DEBUGBOX_WIDTH
Minimum width of a standard debug box widget.
Definition: window_gui.h:78
WidgetDimensions::frametext
RectPadding frametext
Padding inside frame with text.
Definition: window_gui.h:43
FontSize
FontSize
Available font sizes.
Definition: gfx_type.h:202
NWidgetMatrix::widget_w
int widget_w
The width of the child widget including inter spacing.
Definition: widget_type.h:604
NWidgetViewport::SetupSmallestSize
void SetupSmallestSize(Window *w) override
Definition: widget.cpp:2195
MAT_ROW_BITS
@ MAT_ROW_BITS
Number of bits for the number of rows in the matrix.
Definition: widget_type.h:28
Window
Data structure for an opened window.
Definition: window_gui.h:267
SizingType
SizingType
Different forms of sizing nested widgets, using NWidgetBase::AssignSizePosition()
Definition: widget_type.h:117
NWidContainerFlags
NWidContainerFlags
Nested widget container flags,.
Definition: widget_type.h:503
SZSP_VERTICAL
@ SZSP_VERTICAL
Display plane with zero size horizontally, and filling and resizing vertically.
Definition: widget_type.h:467
RWV_SHOW_BEVEL
@ RWV_SHOW_BEVEL
Bevel of resize box is shown.
Definition: widget_type.h:41
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:731
Clamp
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:79
NWidgetResizeBase::absolute
bool absolute
Set if minimum size is fixed and should not be resized.
Definition: widget_type.h:311
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:633
Viewport::virtual_height
int virtual_height
height << zoom
Definition: viewport_type.h:31
NWidgetVertical::NWidgetVertical
NWidgetVertical(NWidContainerFlags flags=NC_NONE)
Vertical container widget.
Definition: widget.cpp:1545
DrawImageButtons
static void DrawImageButtons(const Rect &r, WidgetType type, Colours colour, bool clicked, SpriteID img, StringAlignment align)
Draw an image button.
Definition: widget.cpp:337
NWidgetViewport::Draw
void Draw(const Window *w) override
Definition: widget.cpp:2201
Rect::Width
int Width() const
Get width of Rect.
Definition: geometry_type.hpp:85
SBS_OFF
@ SBS_OFF
Do not sort (with this button).
Definition: window_gui.h:213
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:82
GUISettings::scale_bevels
bool scale_bevels
bevels are scaled with GUI scale.
Definition: settings_type.h:223
NWidgetMatrix::colour
Colours colour
Colour of this widget.
Definition: widget_type.h:598
NWidgetResizeBase::AssignSizePosition
void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override
Definition: widget.cpp:1063
NWidgetPart::NWidgetPartUnion::padding
NWidgetPartPaddings padding
Part with paddings.
Definition: widget_type.h:1044
NWidgetCore
Base class for a 'real' widget.
Definition: widget_type.h:356
DrawFrame
static void DrawFrame(const Rect &r, Colours colour, TextColour text_colour, StringID str, StringAlignment align, FontSize fs)
Draw a frame widget.
Definition: widget.cpp:544
NWidgetLeaf::closebox_dimension
static Dimension closebox_dimension
Cached size of a closebox widget.
Definition: widget_type.h:897
NWidgetLeaf::SetupSmallestSize
void SetupSmallestSize(Window *w) override
Definition: widget.cpp:2566
AWV_RIGHT
@ AWV_RIGHT
Force the arrow to the right.
Definition: widget_type.h:36
WidgetDimensions::WD_CAPTION_HEIGHT
@ WD_CAPTION_HEIGHT
Minimum height of a title bar.
Definition: window_gui.h:83
WWT_DEBUGBOX
@ WWT_DEBUGBOX
NewGRF debug box (at top-right of a window, between WWT_CAPTION and WWT_SHADEBOX)
Definition: widget_type.h:65
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:75
CursorVars::pos
Point pos
logical mouse position
Definition: gfx_type.h:117
NWidgetPartDataTip::tooltip
StringID tooltip
Tooltip of the widget.
Definition: widget_type.h:974
WPT_FUNCTION
@ WPT_FUNCTION
Widget part for calling a user function.
Definition: widget_type.h:101
NWidgetLeaf::Draw
void Draw(const Window *w) override
Definition: widget.cpp:2736
ScaleByZoom
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
WPT_TEXTSTYLE
@ WPT_TEXTSTYLE
Widget part for specifying text colour.
Definition: widget_type.h:98
WidgetDimensions::defsizebox
RectPadding defsizebox
Padding around image in defsizebox widget.
Definition: window_gui.h:48
NWidgetBase::resize_x
uint resize_x
Horizontal resize step (0 means not resizable).
Definition: widget_type.h:225
AWV_INCREASE
@ AWV_INCREASE
Arrow to the right or in case of RTL to the left.
Definition: widget_type.h:34
NWidgetPartWidget::colour
Colours colour
Widget colour.
Definition: widget_type.h:982
NWidgetPartTextLines::size
FontSize size
Font size of text lines.
Definition: widget_type.h:1008
NWidgetBase::current_x
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:233
NWidgetStacked::shown_plane
int shown_plane
Plane being displayed (for NWID_SELECTION only).
Definition: widget_type.h:498
WidgetDimensions::framerect
RectPadding framerect
Standard padding inside many panels.
Definition: window_gui.h:42
WidgetDimensions::hsep_normal
int hsep_normal
Normal horizontal spacing.
Definition: window_gui.h:63
NWidgetResizeBase::SetMinimalSize
void SetMinimalSize(uint min_x, uint min_y)
Set minimal size of the widget.
Definition: widget.cpp:959
NWidgetScrollbar::horizontal_dimension
static Dimension horizontal_dimension
Cached size of horizontal scrollbar button.
Definition: widget_type.h:877
DrawCaption
void DrawCaption(const Rect &r, Colours colour, Owner owner, TextColour text_colour, StringID str, StringAlignment align, FontSize fs)
Draw a caption bar.
Definition: widget.cpp:679
NWidgetResizeBase::SetMinimalSizeAbsolute
void SetMinimalSizeAbsolute(uint min_x, uint min_y)
Set absolute (post-scaling) minimal size of the widget.
Definition: widget.cpp:972
WidgetDimensions
Definition: window_gui.h:34
NWidgetScrollbar::Draw
void Draw(const Window *w) override
Definition: widget.cpp:2392
NWidgetCore::GetWidgetFromPos
NWidgetCore * GetWidgetFromPos(int x, int y) override
Definition: widget.cpp:1134
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:56
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:2876
NWidgetHorizontal::NWidgetHorizontal
NWidgetHorizontal(NWidContainerFlags flags=NC_NONE)
Horizontal container widget.
Definition: widget.cpp:1356
NWidgetPartTextStyle::colour
TextColour colour
TextColour for DrawString.
Definition: widget_type.h:1016
SetupWidgetDimensions
void SetupWidgetDimensions()
Set up pre-scaled versions of Widget Dimensions.
Definition: widget.cpp:66
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:852
NWidgetPart::NWidgetPartUnion::xy
Point xy
Part with an x/y size.
Definition: widget_type.h:1041
NWidgetBase::padding
RectPadding padding
Padding added to the widget. Managed by parent container widget. (parent container may swap left and ...
Definition: widget_type.h:239
NWidgetStacked::index
const WidgetID index
If non-negative, index in the Window::widget_lookup.
Definition: widget_type.h:499
ND_SCROLLBAR_BTN
@ ND_SCROLLBAR_BTN
Bit value of the 'scrollbar up' or 'scrollbar down' flag.
Definition: widget_type.h:347
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:57
NWidgetPartWidget::index
WidgetID index
Index of the widget.
Definition: widget_type.h:983
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:636
NWID_BUTTON_DROPDOWN
@ NWID_BUTTON_DROPDOWN
Button with a drop-down.
Definition: widget_type.h:84
FR_BORDERONLY
@ FR_BORDERONLY
Draw border only, no background.
Definition: window_gui.h:27
NWidgetMatrix::widgets_x
int widgets_x
The number of visible widgets in horizontal direction.
Definition: widget_type.h:606
AWV_DECREASE
@ AWV_DECREASE
Arrow to the left or in case of RTL to the right.
Definition: widget_type.h:33
WWT_DROPDOWN
@ WWT_DROPDOWN
Drop down list.
Definition: widget_type.h:72
ND_NO_TRANSPARENCY
@ ND_NO_TRANSPARENCY
Bit value of the 'no transparency' flag.
Definition: widget_type.h:341
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:509
NWidgetPartAlignment::align
StringAlignment align
Alignment of text/image.
Definition: widget_type.h:1025
ScaleGUITrad
static RectPadding ScaleGUITrad(const RectPadding &r)
Scale a RectPadding to GUI zoom level.
Definition: widget.cpp:35
WidgetDimensions::captiontext
RectPadding captiontext
Padding for text within caption widget.
Definition: window_gui.h:51
MakeWidgetTree
static const NWidgetPart * MakeWidgetTree(const NWidgetPart *nwid_begin, const NWidgetPart *nwid_end, std::unique_ptr< NWidgetBase > &parent)
Build a nested widget tree by recursively filling containers with nested widgets read from their part...
Definition: widget.cpp:3092
NWidgetBackground::AssignSizePosition
void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override
Definition: widget.cpp:2116
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:66
NWidgetBackground::Add
void Add(std::unique_ptr< NWidgetBase > &&nwid)
Add a child to the parent.
Definition: widget.cpp:2000
backup_type.hpp
NWidgetPart::NWidgetPartUnion::widget
NWidgetPartWidget widget
Part with a start of a widget.
Definition: widget_type.h:1043
Window::GetWidget
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition: window_gui.h:970
NWidgetMatrix::SetClicked
void SetClicked(int clicked)
Sets the clicked element in the matrix.
Definition: widget.cpp:1763
WPT_ENDCONTAINER
@ WPT_ENDCONTAINER
Widget part to denote end of a container.
Definition: widget_type.h:100
HasBit
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103