OpenTTD Source
12.0-beta2
|
Go to the documentation of this file.
22 #include "table/strings.h"
40 case SA_LEFT: p.x = r.left;
break;
42 case SA_RIGHT: p.x = r.right - d.width;
break;
43 default: NOT_REACHED();
46 case SA_TOP: p.y = r.top;
break;
48 case SA_BOTTOM: p.y = r.bottom - d.height;
break;
49 default: NOT_REACHED();
66 int rev_base = top + bottom;
69 button_size = NWidgetScrollbar::GetHorizontalDimension().width;
71 button_size = NWidgetScrollbar::GetVerticalDimension().height;
74 bottom -= button_size;
76 int height = (bottom - top);
81 if (count != 0) top += height * pos / count;
83 if (cap > count) cap = count;
84 if (count != 0) bottom -= (count - pos - cap) * height / count;
88 pt.x = rev_base - bottom;
89 pt.y = rev_base - top;
111 bool changed =
false;
116 button_size = NWidgetScrollbar::GetHorizontalDimension().width;
119 button_size = NWidgetScrollbar::GetVerticalDimension().height;
121 if (pos < mi + button_size) {
124 if (_scroller_click_timeout <= 1) {
125 _scroller_click_timeout = 3;
129 }
else if (pos >= ma - button_size) {
133 if (_scroller_click_timeout <= 1) {
134 _scroller_click_timeout = 3;
143 }
else if (pos > pt.y) {
146 _scrollbar_start_pos = pt.x - mi - button_size;
147 _scrollbar_size = ma - mi - button_size * 2;
149 _cursorpos_drag_start = _cursor.
pos;
182 assert(scrollbar !=
nullptr);
197 return (nw !=
nullptr) ? nw->
index : -1;
211 assert(colour < COLOUR_END);
228 interior = (flags &
FR_DARKENED ? medium_dark : medium_light);
234 interior = medium_dark;
256 if ((type & WWT_MASK) ==
WWT_IMGBTN_2 && clicked) img++;
259 DrawSprite(img, PAL_NONE, p.x + clicked, p.y + clicked);
273 if (str == STR_NULL)
return;
277 DrawString(r.left + clicked, r.right + clicked, p.y + clicked, str, colour, align);
291 if (str != STR_NULL)
DrawString(r.left, r.right, p.y, str, colour, align);
317 static inline void DrawMatrix(
const Rect &r, Colours colour,
bool clicked, uint16 data, uint resize_x, uint resize_y)
323 if (num_columns == 0) {
324 column_width = resize_x;
325 num_columns = (r.right - r.left + 1) / column_width;
327 column_width = (r.right - r.left + 1) / num_columns;
333 row_height = resize_y;
334 num_rows = (r.bottom - r.top + 1) / row_height;
336 row_height = (r.bottom - r.top + 1) / num_rows;
342 for (
int ctr = num_columns; ctr > 1; ctr--) {
348 for (
int ctr = num_rows; ctr > 1; ctr--) {
356 for (
int ctr = num_columns; ctr > 1; ctr--) {
362 for (
int ctr = num_rows; ctr > 1; ctr--) {
379 int centre = (r.right - r.left) / 2;
380 int height = NWidgetScrollbar::GetVerticalDimension().height;
384 DrawSprite(SPR_ARROW_UP, PAL_NONE, r.left + 1 + up_clicked, r.top + 1 + up_clicked);
386 DrawFrameRect(r.left, r.bottom - (height - 1), r.right, r.bottom, colour, (down_clicked) ?
FR_LOWERED : FR_NONE);
387 DrawSprite(SPR_ARROW_DOWN, PAL_NONE, r.left + 1 + down_clicked, r.bottom - (height - 2) + down_clicked);
393 GfxFillRect(r.left, r.top + height, r.right, r.bottom - height, c2);
397 GfxFillRect(r.left + centre - 3, r.top + height, r.left + centre - 3, r.bottom - height, c1);
398 GfxFillRect(r.left + centre - 2, r.top + height, r.left + centre - 2, r.bottom - height, c2);
399 GfxFillRect(r.left + centre + 2, r.top + height, r.left + centre + 2, r.bottom - height, c1);
400 GfxFillRect(r.left + centre + 3, r.top + height, r.left + centre + 3, r.bottom - height, c2);
417 int centre = (r.bottom - r.top) / 2;
418 int width = NWidgetScrollbar::GetHorizontalDimension().width;
421 DrawSprite(SPR_ARROW_LEFT, PAL_NONE, r.left + 1 + left_clicked, r.top + 1 + left_clicked);
424 DrawSprite(SPR_ARROW_RIGHT, PAL_NONE, r.right - (width - 2) + right_clicked, r.top + 1 + right_clicked);
430 GfxFillRect(r.left + width, r.top, r.right - width, r.bottom, c2);
434 GfxFillRect(r.left + width, r.top + centre - 3, r.right - width, r.top + centre - 3, c1);
435 GfxFillRect(r.left + width, r.top + centre - 2, r.right - width, r.top + centre - 2, c2);
436 GfxFillRect(r.left + width, r.top + centre + 2, r.right - width, r.top + centre + 2, c1);
437 GfxFillRect(r.left + width, r.top + centre + 3, r.right - width, r.top + centre + 3, c2);
468 GfxFillRect(r.left, r.top + dy1, r.left + 4, r.top + dy1, c1);
469 GfxFillRect(r.left + 1, r.top + dy2, r.left + 4, r.top + dy2, c2);
472 GfxFillRect(x2, r.top + dy1, r.right - 1, r.top + dy1, c1);
473 GfxFillRect(x2, r.top + dy2, r.right - 2, r.top + dy2, c2);
476 GfxFillRect(r.left, r.top + dy1, x2 - 2, r.top + dy1, c1);
477 GfxFillRect(r.left + 1, r.top + dy2, x2 - 2, r.top + dy2, c2);
480 GfxFillRect(r.right - 5, r.top + dy1, r.right - 1, r.top + dy1, c1);
481 GfxFillRect(r.right - 5, r.top + dy2, r.right - 2, r.top + dy2, c2);
485 GfxFillRect(r.left, r.top + dy2, r.left, r.bottom - 1, c1);
486 GfxFillRect(r.left + 1, r.top + dy2 + 1, r.left + 1, r.bottom - 2, c2);
489 GfxFillRect(r.right - 1, r.top + dy2, r.right - 1, r.bottom - 2, c1);
490 GfxFillRect(r.right, r.top + dy1, r.right, r.bottom - 1, c2);
492 GfxFillRect(r.left + 1, r.bottom - 1, r.right - 1, r.bottom - 1, c1);
493 GfxFillRect(r.left, r.bottom, r.right, r.bottom, c2);
568 if (colour != COLOUR_WHITE)
DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, FR_NONE);
594 if (str != STR_NULL) {
614 int text_offset = std::max(0, ((
int)(r.bottom - r.top + 1) -
FONT_HEIGHT_NORMAL) / 2);
618 int image_offset = std::max(0, ((
int)(r.bottom - r.top + 1) - dd_height) / 2);
622 DrawFrameRect(r.right + 1 - dd_width, r.top, r.right, r.bottom, colour, clicked_dropdown ?
FR_LOWERED : FR_NONE);
623 DrawSprite(SPR_ARROW_DOWN, PAL_NONE, r.right - (dd_width - 2) + clicked_dropdown, r.top + image_offset + clicked_dropdown);
627 DrawFrameRect(r.left, r.top, r.left + dd_width - 1, r.bottom, colour, clicked_dropdown ?
FR_LOWERED : FR_NONE);
628 DrawSprite(SPR_ARROW_DOWN, PAL_NONE, r.left + 1 + clicked_dropdown, r.top + image_offset + clicked_dropdown);
647 const NWidgetBase *widget = this->GetWidget<NWidgetBase>(i);
648 if (widget ==
nullptr || !widget->IsHighlighted())
continue;
675 const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(widget);
678 Dimension dim = NWidgetScrollbar::GetVerticalDimension();
681 int y = offset + nwid->
pos_y + (nwid->
current_y - dim.height) / 2;
692 return NWidgetScrollbar::GetVerticalDimension().width + 1;
829 return (this->
type == tp) ? this :
nullptr;
832 void NWidgetBase::AdjustPaddingForZoom()
852 void NWidgetResizeBase::AdjustPaddingForZoom()
858 NWidgetBase::AdjustPaddingForZoom();
882 this->min_x = std::max(this->min_x,
min_x);
883 this->min_y = std::max(this->min_y,
min_y);
997 if (this->
index >= 0 && (uint)(this->
index) < length) array[this->
index] =
this;
1011 this->
head =
nullptr;
1012 this->
tail =
nullptr;
1015 NWidgetContainer::~NWidgetContainer()
1017 while (this->
head !=
nullptr) {
1022 this->
tail =
nullptr;
1027 if (this->
type == tp)
return this;
1028 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1030 if (nwid !=
nullptr)
return nwid;
1035 void NWidgetContainer::AdjustPaddingForZoom()
1037 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1038 child_wid->AdjustPaddingForZoom();
1040 NWidgetBase::AdjustPaddingForZoom();
1049 assert(wid->
next ==
nullptr && wid->
prev ==
nullptr);
1051 if (this->
head ==
nullptr) {
1055 assert(this->
tail !=
nullptr);
1056 assert(this->
tail->
next ==
nullptr);
1066 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1067 child_wid->FillNestedArray(array, length);
1079 void NWidgetStacked::SetIndex(
int index)
1081 this->index =
index;
1084 void NWidgetStacked::AdjustPaddingForZoom()
1086 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1087 child_wid->AdjustPaddingForZoom();
1089 NWidgetContainer::AdjustPaddingForZoom();
1094 if (this->
index >= 0 && init_array) {
1110 this->
fill_x = fill.width;
1111 this->
fill_y = fill.height;
1120 this->
fill_x = (this->
head !=
nullptr) ? 1 : 0;
1121 this->
fill_y = (this->
head !=
nullptr) ? 1 : 0;
1124 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1125 child_wid->SetupSmallestSize(w, init_array);
1127 this->
smallest_x = std::max(this->
smallest_x, child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right);
1128 this->
smallest_y = std::max(this->
smallest_y, child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom);
1143 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1144 uint hor_step = (sizing ==
ST_SMALLEST) ? 1 : child_wid->GetHorizontalStepSize(sizing);
1145 uint child_width =
ComputeMaxSize(child_wid->smallest_x, given_width - child_wid->padding_left - child_wid->padding_right, hor_step);
1146 uint child_pos_x = (rtl ? child_wid->padding_right : child_wid->padding_left);
1148 uint vert_step = (sizing ==
ST_SMALLEST) ? 1 : child_wid->GetVerticalStepSize(sizing);
1149 uint child_height =
ComputeMaxSize(child_wid->smallest_y, given_height - child_wid->padding_top - child_wid->padding_bottom, vert_step);
1150 uint child_pos_y = child_wid->padding_top;
1152 child_wid->AssignSizePosition(sizing, x + child_pos_x, y + child_pos_y, child_width, child_height, rtl);
1158 if (this->
index >= 0 && (uint)(this->
index) < length) array[this->
index] =
this;
1167 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; plane++, child_wid = child_wid->
next) {
1183 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; plane++, child_wid = child_wid->
next) {
1202 this->flags = flags;
1205 void NWidgetPIPContainer::AdjustPaddingForZoom()
1210 NWidgetContainer::AdjustPaddingForZoom();
1235 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1244 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1246 if (nwid !=
nullptr)
return nwid;
1267 uint max_vert_fill = 0;
1268 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1269 child_wid->SetupSmallestSize(w, init_array);
1270 longest = std::max(longest, child_wid->smallest_x);
1271 max_vert_fill = std::max(max_vert_fill, child_wid->GetVerticalStepSize(
ST_SMALLEST));
1272 this->
smallest_y = std::max(this->
smallest_y, child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom);
1275 [[maybe_unused]] uint max_smallest = this->
smallest_y + 3 * max_vert_fill;
1278 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1279 uint step_size = child_wid->GetVerticalStepSize(
ST_SMALLEST);
1280 uint child_height = child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom;
1281 if (step_size > 1 && child_height < cur_height) {
1282 uint remainder = (cur_height - child_height) % step_size;
1283 if (remainder > 0) {
1284 cur_height += step_size - remainder;
1285 assert(cur_height < max_smallest);
1295 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1296 if (child_wid->fill_x == 1) child_wid->smallest_x = longest;
1301 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1302 if (child_wid->next !=
nullptr) {
1303 child_wid->padding_right += this->
pip_inter;
1305 child_wid->padding_right += this->
pip_post;
1308 this->
smallest_x += child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right;
1309 if (child_wid->fill_x > 0) {
1310 if (this->
fill_x == 0 || this->
fill_x > child_wid->fill_x) this->
fill_x = child_wid->fill_x;
1314 if (child_wid->resize_x > 0) {
1328 uint additional_length = given_width;
1331 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1332 additional_length -= child_wid->smallest_x + child_wid->padding_right + child_wid->padding_left;
1354 int num_changing_childs = 0;
1355 uint biggest_stepsize = 0;
1356 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1357 uint hor_step = child_wid->GetHorizontalStepSize(sizing);
1359 num_changing_childs++;
1360 biggest_stepsize = std::max(biggest_stepsize, hor_step);
1362 child_wid->current_x = child_wid->smallest_x;
1365 uint vert_step = (sizing ==
ST_SMALLEST) ? 1 : child_wid->GetVerticalStepSize(sizing);
1366 child_wid->current_y =
ComputeMaxSize(child_wid->smallest_y, given_height - child_wid->padding_top - child_wid->padding_bottom, vert_step);
1370 while (biggest_stepsize > 0) {
1371 uint next_biggest_stepsize = 0;
1372 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1373 uint hor_step = child_wid->GetHorizontalStepSize(sizing);
1374 if (hor_step > biggest_stepsize)
continue;
1375 if (hor_step == biggest_stepsize) {
1376 uint increment = additional_length / num_changing_childs;
1377 num_changing_childs--;
1378 if (hor_step > 1) increment -= increment % hor_step;
1379 child_wid->current_x = child_wid->smallest_x + increment;
1380 additional_length -= increment;
1383 next_biggest_stepsize = std::max(next_biggest_stepsize, hor_step);
1385 biggest_stepsize = next_biggest_stepsize;
1387 assert(num_changing_childs == 0);
1390 uint position = rtl ? this->
current_x : 0;
1392 while (child_wid !=
nullptr) {
1393 uint child_width = child_wid->
current_x;
1399 position = rtl ? position - padded_child_width : position + padded_child_width;
1401 child_wid = child_wid->
next;
1432 uint max_hor_fill = 0;
1433 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1434 child_wid->SetupSmallestSize(w, init_array);
1435 highest = std::max(highest, child_wid->smallest_y);
1436 max_hor_fill = std::max(max_hor_fill, child_wid->GetHorizontalStepSize(
ST_SMALLEST));
1437 this->
smallest_x = std::max(this->
smallest_x, child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right);
1440 [[maybe_unused]] uint max_smallest = this->
smallest_x + 3 * max_hor_fill;
1443 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1444 uint step_size = child_wid->GetHorizontalStepSize(
ST_SMALLEST);
1445 uint child_width = child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right;
1446 if (step_size > 1 && child_width < cur_width) {
1447 uint remainder = (cur_width - child_width) % step_size;
1448 if (remainder > 0) {
1449 cur_width += step_size - remainder;
1450 assert(cur_width < max_smallest);
1460 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1461 if (child_wid->fill_y == 1) child_wid->smallest_y = highest;
1466 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1467 if (child_wid->next !=
nullptr) {
1468 child_wid->padding_bottom += this->
pip_inter;
1470 child_wid->padding_bottom += this->
pip_post;
1473 this->
smallest_y += child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom;
1474 if (child_wid->fill_y > 0) {
1475 if (this->
fill_y == 0 || this->
fill_y > child_wid->fill_y) this->
fill_y = child_wid->fill_y;
1479 if (child_wid->resize_y > 0) {
1493 uint additional_length = given_height;
1496 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1497 additional_length -= child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom;
1510 int num_changing_childs = 0;
1511 uint biggest_stepsize = 0;
1512 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1513 uint vert_step = child_wid->GetVerticalStepSize(sizing);
1514 if (vert_step > 0) {
1515 num_changing_childs++;
1516 biggest_stepsize = std::max(biggest_stepsize, vert_step);
1518 child_wid->current_y = child_wid->smallest_y;
1521 uint hor_step = (sizing ==
ST_SMALLEST) ? 1 : child_wid->GetHorizontalStepSize(sizing);
1522 child_wid->current_x =
ComputeMaxSize(child_wid->smallest_x, given_width - child_wid->padding_left - child_wid->padding_right, hor_step);
1526 while (biggest_stepsize > 0) {
1527 uint next_biggest_stepsize = 0;
1528 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1529 uint vert_step = child_wid->GetVerticalStepSize(sizing);
1530 if (vert_step > biggest_stepsize)
continue;
1531 if (vert_step == biggest_stepsize) {
1532 uint increment = additional_length / num_changing_childs;
1533 num_changing_childs--;
1534 if (vert_step > 1) increment -= increment % vert_step;
1535 child_wid->current_y = child_wid->smallest_y + increment;
1536 additional_length -= increment;
1539 next_biggest_stepsize = std::max(next_biggest_stepsize, vert_step);
1541 biggest_stepsize = next_biggest_stepsize;
1543 assert(num_changing_childs == 0);
1547 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1548 uint child_x = x + (rtl ? child_wid->padding_right : child_wid->padding_left);
1549 uint child_height = child_wid->current_y;
1551 child_wid->AssignSizePosition(sizing, child_x, y + position + child_wid->padding_top, child_wid->current_x, child_height, rtl);
1552 position += child_height + child_wid->padding_top + child_wid->padding_bottom;
1596 void NWidgetMatrix::SetIndex(
int index)
1598 this->index =
index;
1601 void NWidgetMatrix::SetColour(Colours colour)
1613 if (this->clicked >= 0 && this->
sb !=
nullptr && this->
widgets_x != 0) {
1629 this->count =
count;
1631 if (this->
sb ==
nullptr || this->
widgets_x == 0)
return;
1658 assert(this->
head !=
nullptr);
1659 assert(this->
head->
next ==
nullptr);
1661 if (this->
index >= 0 && init_array) {
1668 assert(nw !=
nullptr);
1681 this->
fill_x = fill.width;
1682 this->
fill_y = fill.height;
1713 if (this->
index >= 0 && (uint)(this->
index) < length) array[this->
index] =
this;
1722 int start_x, start_y, base_offs_x, base_offs_y;
1727 int widget_col = (rtl ?
1729 x - (int)this->
pip_pre - (
int)this->
pos_x - base_offs_x
1734 int sub_wid = (widget_row + start_y) * this->
widgets_x + start_x + widget_col;
1735 if (sub_wid >= this->
count)
return nullptr;
1738 assert(child !=
nullptr);
1744 SB(child->
index, 16, 16, sub_wid);
1759 _cur_dpi = &tmp_dpi;
1763 assert(child !=
nullptr);
1764 int start_x, start_y, base_offs_x, base_offs_y;
1767 int offs_y = base_offs_y;
1768 for (
int y = start_y; y < start_y + this->
widgets_y + 1; y++, offs_y += this->
widget_h) {
1770 if (offs_y + child->
smallest_y <= 0)
continue;
1771 if (offs_y >= (
int)this->
current_y)
break;
1776 int offs_x = base_offs_x;
1779 if (offs_x + child->
smallest_x <= 0)
continue;
1780 if (offs_x >= (
int)this->
current_x)
continue;
1783 int sub_wid = y * this->widgets_x + x;
1784 if (sub_wid >= this->
count)
break;
1788 SB(child->
index, 16, 16, sub_wid);
1810 if (this->
sb !=
nullptr) {
1818 base_offs_x += sub_x;
1820 base_offs_x -= sub_x;
1839 this->child =
child;
1843 NWidgetBackground::~NWidgetBackground()
1845 if (this->
child !=
nullptr)
delete this->
child;
1857 if (this->
child ==
nullptr) {
1875 if (this->
child ==
nullptr) {
1878 this->
child->
SetPIP(pip_pre, pip_inter, pip_post);
1881 void NWidgetBackground::AdjustPaddingForZoom()
1883 if (
child !=
nullptr)
child->AdjustPaddingForZoom();
1884 NWidgetCore::AdjustPaddingForZoom();
1889 if (init_array && this->
index >= 0) {
1893 if (this->
child !=
nullptr) {
1904 if (w ==
nullptr)
return;
1937 d =
maxdim(d, background);
1939 if (this->
index >= 0) {
1940 static const Dimension padding = {0, 0};
1946 this->
fill_x = fill.width;
1947 this->
fill_y = fill.height;
1957 if (this->
child !=
nullptr) {
1967 if (this->
index >= 0 && (uint)(this->
index) < length) array[this->
index] =
this;
1975 Rect r = this->GetCurrentRect();
1978 if (dpi->left > r.right || dpi->left + dpi->width <= r.left || dpi->top > r.bottom || dpi->top + dpi->height <= r.top)
return;
1980 switch (this->
type) {
2013 if (nwid ==
nullptr) nwid =
this;
2022 if (nwid ==
nullptr && this->
type == tp) nwid =
this;
2033 if (init_array && this->
index >= 0) {
2079 if (vp !=
nullptr) {
2121 int new_pos = list_position;
2193 switch (this->
type) {
2197 this->
SetDataTip(0x0, STR_TOOLTIP_HSCROLL_BAR_SCROLLS_LIST);
2203 this->
SetDataTip(0x0, STR_TOOLTIP_VSCROLL_BAR_SCROLLS_LIST);
2206 default: NOT_REACHED();
2212 if (init_array && this->
index >= 0) {
2219 switch (this->
type) {
2221 this->
SetMinimalSizeAbsolute(NWidgetScrollbar::GetHorizontalDimension().width * 3, NWidgetScrollbar::GetHorizontalDimension().height);
2225 this->
SetMinimalSizeAbsolute(NWidgetScrollbar::GetVerticalDimension().width, NWidgetScrollbar::GetVerticalDimension().height * 3);
2228 default: NOT_REACHED();
2239 Rect r = this->GetCurrentRect();
2242 if (dpi->left > r.right || dpi->left + dpi->width <= r.left || dpi->top > r.bottom || dpi->top + dpi->height <= r.top)
return;
2259 void NWidgetScrollbar::InvalidateDimensionCache()
2265 Dimension NWidgetScrollbar::GetVerticalDimension()
2276 Dimension NWidgetScrollbar::GetHorizontalDimension()
2345 case NWID_PUSHBUTTON_DROPDOWN:
2360 this->
SetDataTip(data, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS);
2366 this->
SetDataTip(STR_NULL, STR_TOOLTIP_STICKY);
2372 this->
SetDataTip(STR_NULL, STR_TOOLTIP_SHADE);
2378 this->
SetDataTip(STR_NULL, STR_TOOLTIP_DEBUG);
2384 this->
SetDataTip(STR_NULL, STR_TOOLTIP_DEFSIZE);
2390 this->
SetDataTip(STR_NULL, STR_TOOLTIP_RESIZE);
2396 this->
SetDataTip(STR_NULL, STR_TOOLTIP_CLOSE_WINDOW);
2412 if (this->
index >= 0 && init_array) {
2422 switch (this->
type) {
2499 size.width = std::max(size.width, 30 + sprite_size.width);
2515 d2.width += extra.width;
2516 d2.height += extra.height;
2525 d2.width += extra.width;
2526 d2.height += extra.height;
2549 d2.width += extra.width;
2550 d2.height += extra.height;
2567 d2.width += extra.width;
2568 d2.height += extra.height;
2574 case NWID_PUSHBUTTON_DROPDOWN: {
2585 d2.width += extra.width;
2598 this->
fill_x = fill.width;
2599 this->
fill_y = fill.height;
2612 new_dpi.left += this->
pos_x;
2613 new_dpi.top += this->
pos_y;
2616 _cur_dpi = &new_dpi;
2618 Rect r = this->GetCurrentRect();
2621 switch (this->
type) {
2650 case AWV_LEFT: sprite = SPR_ARROW_LEFT;
break;
2651 case AWV_RIGHT: sprite = SPR_ARROW_RIGHT;
break;
2652 default: NOT_REACHED();
2674 if (query !=
nullptr) query->DrawEditBox(w, this->
index);
2717 case NWID_PUSHBUTTON_DROPDOWN:
2744 int button_width = this->
pos_x + this->
current_x - NWidgetLeaf::dropdown_dimension.width;
2745 return pt.x < button_width;
2747 int button_left = this->
pos_x + NWidgetLeaf::dropdown_dimension.width;
2748 return pt.x >= button_left;
2776 while (count > num_used) {
2777 switch (parts->
type) {
2779 if (*dest !=
nullptr)
return num_used;
2784 if (*dest !=
nullptr)
return num_used;
2790 if (*dest !=
nullptr)
return num_used;
2798 if (*dest !=
nullptr)
return num_used;
2800 *biggest_index = std::max(*biggest_index, (
int)parts->u.
widget.
index);
2805 if (*dest !=
nullptr)
return num_used;
2811 if (*dest !=
nullptr)
return num_used;
2817 *biggest_index = std::max(*biggest_index, (
int)parts->u.
widget.
index);
2822 if (*dest !=
nullptr)
return num_used;
2825 *dest = parts->u.
func_ptr(&biggest);
2826 *biggest_index = std::max(*biggest_index, biggest);
2833 if (nwrb !=
nullptr) {
2834 assert(parts->u.
xy.x >= 0 && parts->u.
xy.y >= 0);
2842 if (nwrb !=
nullptr) {
2843 assert(parts->u.
xy.x >= 0 && parts->u.
xy.y >= 0);
2851 if (nwrb !=
nullptr) {
2860 if (nwc !=
nullptr) {
2868 if (nwc !=
nullptr) {
2876 if (nwrb !=
nullptr) nwrb->
SetFill(parts->u.
xy.x, parts->u.
xy.y);
2882 if (nwc !=
nullptr) {
2904 if (nwc !=
nullptr) {
2914 if (*dest !=
nullptr)
return num_used;
2916 *biggest_index = std::max(*biggest_index, (
int)parts->u.
widget.
index);
2921 if (*dest !=
nullptr)
return num_used;
2923 *biggest_index = std::max(*biggest_index, (
int)parts->u.
widget.
index);
2927 if (*dest !=
nullptr)
return num_used;
2932 *biggest_index = std::max(*biggest_index, (
int)parts->u.
widget.
index);
2937 if (*dest !=
nullptr)
return num_used;
2940 *biggest_index = std::max(*biggest_index, (
int)parts->u.
widget.
index);
2965 assert(*parent ==
nullptr || (nwid_cont !=
nullptr && nwid_parent ==
nullptr) || (nwid_cont ==
nullptr && nwid_parent !=
nullptr));
2970 bool fill_sub =
false;
2971 int num_used =
MakeNWidget(parts, count - total_used, &sub_widget, &fill_sub, biggest_index);
2973 total_used += num_used;
2976 if (sub_widget ==
nullptr)
break;
2983 int num_used =
MakeWidgetTree(parts, count - total_used, &sub_ptr, biggest_index);
2985 total_used += num_used;
2989 if (nwid_cont !=
nullptr) nwid_cont->
Add(sub_widget);
2990 if (nwid_parent !=
nullptr) nwid_parent->
Add(sub_widget);
2991 if (nwid_cont ==
nullptr && nwid_parent ==
nullptr) {
2992 *parent = sub_widget;
2997 if (count == total_used)
return total_used;
2999 assert(total_used < count);
3001 return total_used + 1;
3017 *biggest_index = -1;
3039 *biggest_index = -1;
3043 int num_used =
MakeWidgetTree(parts, count, &nwid, biggest_index);
3044 assert(nwid !=
nullptr);
3051 *shade_select =
nullptr;
3061 root->
Add(*shade_select);
3063 (*shade_select)->
Add(body);
3065 *shade_select =
nullptr;
3073 *biggest_index = std::max(*biggest_index, biggest2);
3090 assert(max_length >= 1);
3099 for (
int widnum = widget_first; widnum <= widget_last; widnum++) {
3101 if (hor_length == max_length) {
3107 if (hor ==
nullptr) {
3120 *biggest_index = widget_last;
3121 if (vert ==
nullptr)
return hor;
3123 if (hor_length > 0 && hor_length < max_length) {
3130 if (hor !=
nullptr) vert->
Add(hor);
@ ES_HANDLED
The passed event is handled.
uint8 lines
Number of text lines.
@ WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
@ WD_DEFSIZEBOX_LEFT
Left offset of defsize sprite.
@ WD_RESIZEBOX_BOTTOM
Bottom offset of resize sprite.
@ SA_HOR_MASK
Mask for horizontal alignment.
@ WD_MATRIX_RIGHT
Offset at right of a matrix cell.
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.
@ WF_SIZING
Window is being resized.
SortButtonState
State of a sort direction button.
@ WD_STICKYBOX_WIDTH
Width of a standard sticky box widget.
bool newgrf_developer_tools
activate NewGRF developer tools and allow modifying NewGRFs in an existing game
@ PALETTE_TEXT_RECOLOUR
Set if palette is actually a magic text recolour.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Dimensions (a width and height) of a rectangle in 2D.
void DrawSortButtonState(int widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
NWidgetBase * nested_root
Root of the nested tree.
@ WD_SHADEBOX_BOTTOM
Bottom offset of shade sprite.
TransparencyOptionBits _transparency_opt
The bits that should be transparent.
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
@ WD_MATRIX_TOP
Offset at top of a matrix cell.
@ TD_LTR
Text is written left-to-right by default.
@ TO_LOADING
loading indicators
int width
Screen width of the viewport.
ViewportData * viewport
Pointer to viewport data, if present.
@ WD_STICKYBOX_TOP
Top offset of sticky sprite.
int height
Screen height of the viewport.
@ FILLRECT_RECOLOUR
Apply a recolour sprite to the screen content.
FrameFlags
Flags to describe the look of the frame.
@ WD_CLOSEBOX_RIGHT
Right offset of closebox string.
int top
Screen coordinate top edge of the viewport.
virtual bool IsNewGRFInspectable() const
Is the data related to this window NewGRF inspectable?
@ WF_STICKY
Window is made sticky by user.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
static int UnScaleGUI(int value)
Short-hand to apply GUI zoom level.
static const PaletteID PALETTE_TO_TRANSPARENT
This sets the sprite to transparent.
@ FILLRECT_CHECKER
Draw only every second pixel, used for greying-out.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
@ WD_FRAMETEXT_TOP
Top offset of the text of the frame.
@ WD_SCROLLBAR_RIGHT
Right offset of scrollbar.
ZoomLevel
All zoom levels we know.
@ SA_BOTTOM
Bottom align the text.
StringAlignment
How to align the to-be drawn text.
ClientSettings _settings_client
The current settings for this game.
@ WD_DEFSIZEBOX_BOTTOM
Bottom offset of defsize sprite.
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Owner owner
The owner of the content shown in this window. Company colour is acquired from this variable.
@ FR_LOWERED
If set the frame is lowered and the background colour brighter (ie. buttons when pressed)
@ SA_RIGHT
Right align the text (must be a single bit).
@ SA_VERT_CENTER
Vertically center the text.
@ WD_DEBUGBOX_LEFT
Left offset of debug sprite.
Owner
Enum for all companies/owners.
@ WD_FRAMETEXT_LEFT
Left offset of the text of the frame.
@ FR_TRANSPARENT
Makes the background transparent if set.
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Data stored about a string that can be modified in the GUI.
@ WD_IMGBTN_BOTTOM
Bottom offset of image in the button.
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
@ WD_INSET_TOP
Top offset of string.
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
const NWID * GetWidget(uint widnum) const
Get the nested widget with number widnum from the nested widget tree.
Colours _company_colours[MAX_COMPANIES]
NOSAVE: can be determined from company structs.
Data structure for viewport, display of a part of the world.
@ WD_RESIZEBOX_RIGHT
Right offset of resize sprite.
@ WD_SHADEBOX_RIGHT
Right offset of shade sprite.
@ FS_NORMAL
Index of the normal font in the font tables.
@ SA_TOP
Top align the text.
@ WD_CLOSEBOX_TOP
Top offset of closebox string.
int height
Height of the window (number of pixels down in y direction)
@ WF_WHITE_BORDER
Window white border counter bit mask.
@ WD_INSET_RIGHT
Right offset of string.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
int left
Screen coordinate left edge of the viewport.
@ WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
static T SB(T &x, const uint8 s, const uint8 n, const U d)
Set n bits in x starting at bit s to d.
static bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
@ WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
Base class that provides memory initialization on dynamically created objects.
@ ES_NOT_HANDLED
The passed event is not handled.
@ WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
@ WD_DEFSIZEBOX_RIGHT
Right offset of defsize sprite.
@ WD_FRAMETEXT_BOTTOM
Bottom offset of the text of the frame.
static const PaletteID PALETTE_NEWSPAPER
Recolour sprite for newspaper-greying.
static const byte _string_colourmap[17]
Colour mapping for TextColour.
const QueryString * GetQueryString(uint widnum) const
Return the querystring associated to a editbox.
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
@ MAX_COMPANIES
Maximum number of companies.
uint TransparencyOptionBits
transparency option bits
@ WD_STICKYBOX_RIGHT
Right offset of sticky sprite.
int left
x position of left edge of the window
WindowFlags flags
Window flags.
@ WD_INSET_LEFT
Left offset of string.
@ WD_DEBUGBOX_RIGHT
Right offset of debug sprite.
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
int virtual_width
width << zoom
Coordinates of a point in 2D.
@ WF_HIGHLIGHTED
Window has a widget that has a highlight.
uint8 spacing
Extra spacing around lines.
@ WD_FRAMETEXT_RIGHT
Right offset of the text of the frame.
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.
@ WD_DROPDOWNTEXT_RIGHT
Right offset of the dropdown widget string.
@ WD_SCROLLBAR_LEFT
Left offset of scrollbar.
int mouse_capture_widget
Widgetindex of current mouse capture widget (e.g. dragged scrollbar). -1 if no widget has mouse captu...
@ SA_HOR_CENTER
Horizontally center the text.
NWidgetBase ** nested_array
Array of pointers into the tree. Do not access directly, use Window::GetWidget() instead.
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
@ WD_SHADEBOX_TOP
Top offset of shade sprite.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
@ WD_SCROLLBAR_BOTTOM
Bottom offset of scrollbar.
@ WD_DROPDOWNTEXT_TOP
Top offset of the dropdown widget string.
@ WD_SHADEBOX_LEFT
Left offset of shade sprite.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
@ SBS_DOWN
Sort ascending.
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
@ WD_DROPDOWN_HEIGHT
Height of a drop down widget.
static int ScaleByZoom(int value, ZoomLevel zoom)
Scale by zoom level, usually shift left (when zoom > ZOOM_LVL_NORMAL) When shifting right,...
@ SA_VERT_MASK
Mask for vertical alignment.
bool IsShaded() const
Is window shaded currently?
@ WD_CLOSEBOX_WIDTH
Width of a close box widget.
@ WD_BEVEL_RIGHT
Width of right bevel border.
@ WD_CAPTIONTEXT_TOP
Offset of the caption text at the top.
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
@ WD_DEFSIZEBOX_WIDTH
Width of a standard defsize box widget.
@ WD_SHADEBOX_WIDTH
Width of a standard shade box widget.
static int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
@ WD_DEBUGBOX_WIDTH
Width of a standard debug box widget.
@ WD_DEBUGBOX_BOTTOM
Bottom offset of debug sprite.
@ WD_SCROLLBAR_TOP
Top offset of scrollbar.
TextColour colour
TextColour for DrawString.
bool _window_highlight_colour
If false, highlight is white, otherwise the by the widget defined colour.
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
EventState
State of handling an event.
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
@ WD_IMGBTN_TOP
Top offset of image in the button.
@ WD_RESIZEBOX_WIDTH
Width of a resize box widget.
@ WD_STICKYBOX_BOTTOM
Bottom offset of sticky sprite.
int top
y position of top edge of the window
void DrawViewport() const
Draw the viewport of this window.
@ SA_LEFT
Left align the text.
@ WD_BEVEL_TOP
Height of top bevel border.
@ WD_BEVEL_LEFT
Width of left bevel border.
@ WD_MATRIX_BOTTOM
Offset at bottom of a matrix cell.
static int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
@ SA_CENTER
Center both horizontally and vertically.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
int width
width of the window (number of pixels to the right in x direction)
ZoomLevel zoom
The zoom level of the viewport.
@ WD_CAPTIONTEXT_BOTTOM
Offset of the caption text at the bottom.
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
@ FR_DARKENED
If set the background is darker, allows for lowered frames with normal background colour when used wi...
@ WD_RESIZEBOX_TOP
Top offset of resize sprite.
@ WD_DEBUGBOX_TOP
Top offset of debug sprite.
@ WD_CAPTION_HEIGHT
Height of a title bar.
static uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
@ WD_DROPDOWNTEXT_BOTTOM
Bottom offset of the dropdown widget string.
FontSize
Available font sizes.
Data structure for an opened window.
@ WD_CAPTIONTEXT_LEFT
Offset of the caption text at the left.
@ WD_MATRIX_LEFT
Offset at left of a matrix cell.
void DrawWidgets() const
Paint all widgets of a window.
@ ZOOM_LVL_OUT_4X
Zoomed 4 times out.
int virtual_height
height << zoom
@ WD_DROPDOWNTEXT_LEFT
Left offset of the dropdown widget string.
@ WD_IMGBTN_LEFT
Left offset of the image in the button.
@ SBS_OFF
Do not sort (with this button).
uint nested_array_size
Size of the nested array.
Specification of a rectangle with absolute coordinates of all edges.
Point pos
logical mouse position
@ WD_CLOSEBOX_BOTTOM
Bottom offset of closebox string.
int GetRowFromWidget(int clickpos, int widget, int padding, int line_height=-1) const
Compute the row of a widget that a user clicked in.
void InitializeWindowViewport(Window *w, int x, int y, int width, int height, uint32 follow_flags, ZoomLevel zoom)
Initialize viewport of the window for use.
FontSize size
Font size of text lines.
@ WD_BEVEL_BOTTOM
Height of bottom bevel border.
@ WD_IMGBTN_RIGHT
Right offset of the image in the button.
@ TD_RTL
Text is written right-to-left by default.
@ WD_CLOSEBOX_LEFT
Left offset of closebox string.
TextDirection _current_text_dir
Text direction of the currently selected language.
int LeastCommonMultiple(int a, int b)
Compute least common multiple (lcm) of arguments a and b, the smallest integer value that is a multip...
@ WD_RESIZEBOX_LEFT
Left offset of resize sprite.
@ WD_STICKYBOX_LEFT
Left offset of sticky sprite.
GUISettings gui
settings related to the GUI
@ FR_BORDERONLY
Draw border only, no background.
Data about how and where to blit pixels.
@ WD_CAPTIONTEXT_RIGHT
Offset of the caption text at the right.
@ WD_DEFSIZEBOX_TOP
Top offset of defsize sprite.