|
OpenTTD Source
13.0-beta1
|
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);
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);
1371 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1372 uint hor_step = child_wid->GetHorizontalStepSize(sizing);
1373 if (hor_step == biggest_stepsize) {
1374 num_changing_childs++;
1380 while (biggest_stepsize > 0) {
1381 uint next_biggest_stepsize = 0;
1382 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1383 uint hor_step = child_wid->GetHorizontalStepSize(sizing);
1384 if (hor_step > biggest_stepsize)
continue;
1385 if (hor_step == biggest_stepsize) {
1386 uint increment = additional_length / num_changing_childs;
1387 num_changing_childs--;
1388 if (hor_step > 1) increment -= increment % hor_step;
1389 child_wid->current_x = child_wid->smallest_x + increment;
1390 additional_length -= increment;
1393 next_biggest_stepsize = std::max(next_biggest_stepsize, hor_step);
1395 biggest_stepsize = next_biggest_stepsize;
1397 if (num_changing_childs == 0 && (
flags &
NC_BIGFIRST) && biggest_stepsize > 0) {
1399 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1400 uint hor_step = child_wid->GetHorizontalStepSize(sizing);
1401 if (hor_step == biggest_stepsize) {
1402 num_changing_childs++;
1407 assert(num_changing_childs == 0);
1410 uint position = rtl ? this->
current_x : 0;
1412 while (child_wid !=
nullptr) {
1413 uint child_width = child_wid->
current_x;
1419 position = rtl ? position - padded_child_width : position + padded_child_width;
1421 child_wid = child_wid->
next;
1452 uint max_hor_fill = 0;
1453 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1454 child_wid->SetupSmallestSize(w, init_array);
1455 highest = std::max(highest, child_wid->smallest_y);
1456 max_hor_fill = std::max(max_hor_fill, child_wid->GetHorizontalStepSize(
ST_SMALLEST));
1457 this->
smallest_x = std::max(this->
smallest_x, child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right);
1460 [[maybe_unused]] uint max_smallest = this->
smallest_x + 3 * max_hor_fill;
1463 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1464 uint step_size = child_wid->GetHorizontalStepSize(
ST_SMALLEST);
1465 uint child_width = child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right;
1466 if (step_size > 1 && child_width < cur_width) {
1467 uint remainder = (cur_width - child_width) % step_size;
1468 if (remainder > 0) {
1469 cur_width += step_size - remainder;
1470 assert(cur_width < max_smallest);
1480 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1481 if (child_wid->fill_y == 1) child_wid->smallest_y = highest;
1486 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1487 if (child_wid->next !=
nullptr) {
1488 child_wid->padding_bottom += this->
pip_inter;
1490 child_wid->padding_bottom += this->
pip_post;
1493 this->
smallest_y += child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom;
1494 if (child_wid->fill_y > 0) {
1495 if (this->
fill_y == 0 || this->
fill_y > child_wid->fill_y) this->
fill_y = child_wid->fill_y;
1499 if (child_wid->resize_y > 0) {
1513 uint additional_length = given_height;
1516 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1517 additional_length -= child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom;
1530 int num_changing_childs = 0;
1531 uint biggest_stepsize = 0;
1532 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1533 uint vert_step = child_wid->GetVerticalStepSize(sizing);
1534 if (vert_step > 0) {
1536 biggest_stepsize = std::max(biggest_stepsize, vert_step);
1538 child_wid->current_y = child_wid->smallest_y;
1541 uint hor_step = (sizing ==
ST_SMALLEST) ? 1 : child_wid->GetHorizontalStepSize(sizing);
1542 child_wid->current_x =
ComputeMaxSize(child_wid->smallest_x, given_width - child_wid->padding_left - child_wid->padding_right, hor_step);
1547 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1548 uint vert_step = child_wid->GetVerticalStepSize(sizing);
1549 if (vert_step == biggest_stepsize) {
1550 num_changing_childs++;
1556 while (biggest_stepsize > 0) {
1557 uint next_biggest_stepsize = 0;
1558 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1559 uint vert_step = child_wid->GetVerticalStepSize(sizing);
1560 if (vert_step > biggest_stepsize)
continue;
1561 if (vert_step == biggest_stepsize) {
1562 uint increment = additional_length / num_changing_childs;
1563 num_changing_childs--;
1564 if (vert_step > 1) increment -= increment % vert_step;
1565 child_wid->current_y = child_wid->smallest_y + increment;
1566 additional_length -= increment;
1569 next_biggest_stepsize = std::max(next_biggest_stepsize, vert_step);
1571 biggest_stepsize = next_biggest_stepsize;
1573 if (num_changing_childs == 0 && (
flags &
NC_BIGFIRST) && biggest_stepsize > 0) {
1575 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1576 uint vert_step = child_wid->GetVerticalStepSize(sizing);
1577 if (vert_step == biggest_stepsize) {
1578 num_changing_childs++;
1583 assert(num_changing_childs == 0);
1587 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1588 uint child_x = x + (rtl ? child_wid->padding_right : child_wid->padding_left);
1589 uint child_height = child_wid->current_y;
1591 child_wid->AssignSizePosition(sizing, child_x, y + position + child_wid->padding_top, child_wid->current_x, child_height, rtl);
1592 position += child_height + child_wid->padding_top + child_wid->padding_bottom;
1636 void NWidgetMatrix::SetIndex(
int index)
1638 this->index =
index;
1641 void NWidgetMatrix::SetColour(Colours colour)
1653 if (this->clicked >= 0 && this->
sb !=
nullptr && this->
widgets_x != 0) {
1669 this->count =
count;
1671 if (this->
sb ==
nullptr || this->
widgets_x == 0)
return;
1698 assert(this->
head !=
nullptr);
1699 assert(this->
head->
next ==
nullptr);
1701 if (this->
index >= 0 && init_array) {
1708 assert(nw !=
nullptr);
1721 this->
fill_x = fill.width;
1722 this->
fill_y = fill.height;
1753 if (this->
index >= 0 && (uint)(this->
index) < length) array[this->
index] =
this;
1762 int start_x, start_y, base_offs_x, base_offs_y;
1767 int widget_col = (rtl ?
1769 x - (int)this->
pip_pre - (
int)this->
pos_x - base_offs_x
1774 int sub_wid = (widget_row + start_y) * this->
widgets_x + start_x + widget_col;
1775 if (sub_wid >= this->
count)
return nullptr;
1778 assert(child !=
nullptr);
1784 SB(child->
index, 16, 16, sub_wid);
1799 _cur_dpi = &tmp_dpi;
1803 assert(child !=
nullptr);
1804 int start_x, start_y, base_offs_x, base_offs_y;
1807 int offs_y = base_offs_y;
1808 for (
int y = start_y; y < start_y + this->
widgets_y + 1; y++, offs_y += this->
widget_h) {
1810 if (offs_y + child->
smallest_y <= 0)
continue;
1811 if (offs_y >= (
int)this->
current_y)
break;
1816 int offs_x = base_offs_x;
1819 if (offs_x + child->
smallest_x <= 0)
continue;
1820 if (offs_x >= (
int)this->
current_x)
continue;
1823 int sub_wid = y * this->widgets_x + x;
1824 if (sub_wid >= this->
count)
break;
1828 SB(child->
index, 16, 16, sub_wid);
1850 if (this->
sb !=
nullptr) {
1858 base_offs_x += sub_x;
1860 base_offs_x -= sub_x;
1879 this->child =
child;
1883 NWidgetBackground::~NWidgetBackground()
1885 if (this->
child !=
nullptr)
delete this->
child;
1897 if (this->
child ==
nullptr) {
1915 if (this->
child ==
nullptr) {
1918 this->
child->
SetPIP(pip_pre, pip_inter, pip_post);
1921 void NWidgetBackground::AdjustPaddingForZoom()
1923 if (
child !=
nullptr)
child->AdjustPaddingForZoom();
1924 NWidgetCore::AdjustPaddingForZoom();
1929 if (init_array && this->
index >= 0) {
1933 if (this->
child !=
nullptr) {
1944 if (w ==
nullptr)
return;
1977 d =
maxdim(d, background);
1979 if (this->
index >= 0) {
1980 static const Dimension padding = {0, 0};
1986 this->
fill_x = fill.width;
1987 this->
fill_y = fill.height;
1997 if (this->
child !=
nullptr) {
2007 if (this->
index >= 0 && (uint)(this->
index) < length) array[this->
index] =
this;
2015 Rect r = this->GetCurrentRect();
2018 if (dpi->left > r.right || dpi->left + dpi->width <= r.left || dpi->top > r.bottom || dpi->top + dpi->height <= r.top)
return;
2020 switch (this->
type) {
2053 if (nwid ==
nullptr) nwid =
this;
2062 if (nwid ==
nullptr && this->
type == tp) nwid =
this;
2073 if (init_array && this->
index >= 0) {
2119 if (vp !=
nullptr) {
2161 int new_pos = list_position;
2233 switch (this->
type) {
2237 this->
SetDataTip(0x0, STR_TOOLTIP_HSCROLL_BAR_SCROLLS_LIST);
2243 this->
SetDataTip(0x0, STR_TOOLTIP_VSCROLL_BAR_SCROLLS_LIST);
2246 default: NOT_REACHED();
2252 if (init_array && this->
index >= 0) {
2259 switch (this->
type) {
2261 this->
SetMinimalSizeAbsolute(NWidgetScrollbar::GetHorizontalDimension().width * 3, NWidgetScrollbar::GetHorizontalDimension().height);
2265 this->
SetMinimalSizeAbsolute(NWidgetScrollbar::GetVerticalDimension().width, NWidgetScrollbar::GetVerticalDimension().height * 3);
2268 default: NOT_REACHED();
2279 Rect r = this->GetCurrentRect();
2282 if (dpi->left > r.right || dpi->left + dpi->width <= r.left || dpi->top > r.bottom || dpi->top + dpi->height <= r.top)
return;
2299 void NWidgetScrollbar::InvalidateDimensionCache()
2305 Dimension NWidgetScrollbar::GetVerticalDimension()
2316 Dimension NWidgetScrollbar::GetHorizontalDimension()
2385 case NWID_PUSHBUTTON_DROPDOWN:
2400 this->
SetDataTip(data, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS);
2406 this->
SetDataTip(STR_NULL, STR_TOOLTIP_STICKY);
2412 this->
SetDataTip(STR_NULL, STR_TOOLTIP_SHADE);
2418 this->
SetDataTip(STR_NULL, STR_TOOLTIP_DEBUG);
2424 this->
SetDataTip(STR_NULL, STR_TOOLTIP_DEFSIZE);
2430 this->
SetDataTip(STR_NULL, STR_TOOLTIP_RESIZE);
2436 this->
SetDataTip(STR_NULL, STR_TOOLTIP_CLOSE_WINDOW);
2452 if (this->
index >= 0 && init_array) {
2462 switch (this->
type) {
2539 size.width = std::max(size.width, 30 + sprite_size.width);
2555 d2.width += extra.width;
2556 d2.height += extra.height;
2565 d2.width += extra.width;
2566 d2.height += extra.height;
2589 d2.width += extra.width;
2590 d2.height += extra.height;
2607 d2.width += extra.width;
2608 d2.height += extra.height;
2614 case NWID_PUSHBUTTON_DROPDOWN: {
2625 d2.width += extra.width;
2638 this->
fill_x = fill.width;
2639 this->
fill_y = fill.height;
2652 new_dpi.left += this->
pos_x;
2653 new_dpi.top += this->
pos_y;
2656 _cur_dpi = &new_dpi;
2658 Rect r = this->GetCurrentRect();
2661 switch (this->
type) {
2690 case AWV_LEFT: sprite = SPR_ARROW_LEFT;
break;
2691 case AWV_RIGHT: sprite = SPR_ARROW_RIGHT;
break;
2692 default: NOT_REACHED();
2714 if (query !=
nullptr) query->DrawEditBox(w, this->
index);
2757 case NWID_PUSHBUTTON_DROPDOWN:
2784 int button_width = this->
pos_x + this->
current_x - NWidgetLeaf::dropdown_dimension.width;
2785 return pt.x < button_width;
2787 int button_left = this->
pos_x + NWidgetLeaf::dropdown_dimension.width;
2788 return pt.x >= button_left;
2816 while (count > num_used) {
2817 switch (parts->
type) {
2819 if (*dest !=
nullptr)
return num_used;
2824 if (*dest !=
nullptr)
return num_used;
2830 if (*dest !=
nullptr)
return num_used;
2838 if (*dest !=
nullptr)
return num_used;
2840 *biggest_index = std::max(*biggest_index, (
int)parts->u.
widget.
index);
2845 if (*dest !=
nullptr)
return num_used;
2851 if (*dest !=
nullptr)
return num_used;
2857 *biggest_index = std::max(*biggest_index, (
int)parts->u.
widget.
index);
2862 if (*dest !=
nullptr)
return num_used;
2865 *dest = parts->u.
func_ptr(&biggest);
2866 *biggest_index = std::max(*biggest_index, biggest);
2873 if (nwrb !=
nullptr) {
2874 assert(parts->u.
xy.x >= 0 && parts->u.
xy.y >= 0);
2882 if (nwrb !=
nullptr) {
2883 assert(parts->u.
xy.x >= 0 && parts->u.
xy.y >= 0);
2891 if (nwrb !=
nullptr) {
2900 if (nwc !=
nullptr) {
2908 if (nwc !=
nullptr) {
2916 if (nwrb !=
nullptr) nwrb->
SetFill(parts->u.
xy.x, parts->u.
xy.y);
2922 if (nwc !=
nullptr) {
2944 if (nwc !=
nullptr) {
2954 if (*dest !=
nullptr)
return num_used;
2956 *biggest_index = std::max(*biggest_index, (
int)parts->u.
widget.
index);
2961 if (*dest !=
nullptr)
return num_used;
2963 *biggest_index = std::max(*biggest_index, (
int)parts->u.
widget.
index);
2967 if (*dest !=
nullptr)
return num_used;
2972 *biggest_index = std::max(*biggest_index, (
int)parts->u.
widget.
index);
2977 if (*dest !=
nullptr)
return num_used;
2980 *biggest_index = std::max(*biggest_index, (
int)parts->u.
widget.
index);
3005 assert(*parent ==
nullptr || (nwid_cont !=
nullptr && nwid_parent ==
nullptr) || (nwid_cont ==
nullptr && nwid_parent !=
nullptr));
3010 bool fill_sub =
false;
3011 int num_used =
MakeNWidget(parts, count - total_used, &sub_widget, &fill_sub, biggest_index);
3013 total_used += num_used;
3016 if (sub_widget ==
nullptr)
break;
3023 int num_used =
MakeWidgetTree(parts, count - total_used, &sub_ptr, biggest_index);
3025 total_used += num_used;
3029 if (nwid_cont !=
nullptr) nwid_cont->
Add(sub_widget);
3030 if (nwid_parent !=
nullptr) nwid_parent->
Add(sub_widget);
3031 if (nwid_cont ==
nullptr && nwid_parent ==
nullptr) {
3032 *parent = sub_widget;
3037 if (count == total_used)
return total_used;
3039 assert(total_used < count);
3041 return total_used + 1;
3057 *biggest_index = -1;
3079 *biggest_index = -1;
3083 int num_used =
MakeWidgetTree(parts, count, &nwid, biggest_index);
3084 assert(nwid !=
nullptr);
3091 *shade_select =
nullptr;
3101 root->
Add(*shade_select);
3103 (*shade_select)->
Add(body);
3105 *shade_select =
nullptr;
3113 *biggest_index = std::max(*biggest_index, biggest2);
3130 assert(max_length >= 1);
3139 for (
int widnum = widget_first; widnum <= widget_last; widnum++) {
3141 if (hor_length == max_length) {
3147 if (hor ==
nullptr) {
3160 *biggest_index = widget_last;
3161 if (vert ==
nullptr)
return hor;
3163 if (hor_length > 0 && hor_length < max_length) {
3170 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.