24 #include "table/strings.h"
41 int rev_base = top + bottom;
44 button_size = NWidgetScrollbar::GetHorizontalDimension().width;
46 button_size = NWidgetScrollbar::GetVerticalDimension().height;
49 bottom -= button_size;
51 int height = (bottom - top);
56 if (count != 0) top += height * pos / count;
58 if (cap > count) cap = count;
59 if (count != 0) bottom -= (count - pos - cap) * height / count;
63 pt.x = rev_base - bottom;
64 pt.y = rev_base - top;
90 button_size = NWidgetScrollbar::GetHorizontalDimension().width;
93 button_size = NWidgetScrollbar::GetVerticalDimension().height;
95 if (pos < mi + button_size) {
98 if (_scroller_click_timeout <= 1) {
99 _scroller_click_timeout = 3;
103 }
else if (pos >= ma - button_size) {
107 if (_scroller_click_timeout <= 1) {
108 _scroller_click_timeout = 3;
117 }
else if (pos > pt.y) {
120 _scrollbar_start_pos = pt.x - mi - button_size;
121 _scrollbar_size = ma - mi - button_size * 2;
123 _cursorpos_drag_start = _cursor.
pos;
150 assert(scrollbar != NULL);
165 return (nw != NULL) ? nw->
index : -1;
179 assert(colour < COLOUR_END);
196 interior = (flags &
FR_DARKENED ? medium_dark : medium_light);
202 interior = medium_dark;
223 if ((type & WWT_MASK) ==
WWT_IMGBTN_2 && clicked) img++;
237 if (str == STR_NULL)
return;
240 int offset =
max(0, ((
int)(r.bottom - r.top + 1) - (
int)d.height) / 2);
253 int offset =
max(0, ((
int)(r.bottom - r.top + 1) - (
int)d.height) / 2);
254 if (str != STR_NULL)
DrawString(r.left, r.right, r.top + offset, str, colour);
278 static inline void DrawMatrix(
const Rect &r, Colours colour,
bool clicked, uint16 data, uint resize_x, uint resize_y)
284 if (num_columns == 0) {
285 column_width = resize_x;
286 num_columns = (r.right - r.left + 1) / column_width;
288 column_width = (r.right - r.left + 1) / num_columns;
294 row_height = resize_y;
295 num_rows = (r.bottom - r.top + 1) / row_height;
297 row_height = (r.bottom - r.top + 1) / num_rows;
303 for (
int ctr = num_columns; ctr > 1; ctr--) {
309 for (
int ctr = num_rows; ctr > 1; ctr--) {
317 for (
int ctr = num_columns; ctr > 1; ctr--) {
323 for (
int ctr = num_rows; ctr > 1; ctr--) {
340 int centre = (r.right - r.left) / 2;
341 int height = NWidgetScrollbar::GetVerticalDimension().height;
345 DrawSprite(SPR_ARROW_UP, PAL_NONE, r.left + 1 + up_clicked, r.top + 1 + up_clicked);
347 DrawFrameRect(r.left, r.bottom - (height - 1), r.right, r.bottom, colour, (down_clicked) ?
FR_LOWERED : FR_NONE);
348 DrawSprite(SPR_ARROW_DOWN, PAL_NONE, r.left + 1 + down_clicked, r.bottom - (height - 2) + down_clicked);
354 GfxFillRect(r.left, r.top + height, r.right, r.bottom - height, c2);
358 GfxFillRect(r.left + centre - 3, r.top + height, r.left + centre - 3, r.bottom - height, c1);
359 GfxFillRect(r.left + centre - 2, r.top + height, r.left + centre - 2, r.bottom - height, c2);
360 GfxFillRect(r.left + centre + 2, r.top + height, r.left + centre + 2, r.bottom - height, c1);
361 GfxFillRect(r.left + centre + 3, r.top + height, r.left + centre + 3, r.bottom - height, c2);
378 int centre = (r.bottom - r.top) / 2;
379 int width = NWidgetScrollbar::GetHorizontalDimension().width;
382 DrawSprite(SPR_ARROW_LEFT, PAL_NONE, r.left + 1 + left_clicked, r.top + 1 + left_clicked);
385 DrawSprite(SPR_ARROW_RIGHT, PAL_NONE, r.right - (width - 2) + right_clicked, r.top + 1 + right_clicked);
391 GfxFillRect(r.left + width, r.top, r.right - width, r.bottom, c2);
395 GfxFillRect(r.left + width, r.top + centre - 3, r.right - width, r.top + centre - 3, c1);
396 GfxFillRect(r.left + width, r.top + centre - 2, r.right - width, r.top + centre - 2, c2);
397 GfxFillRect(r.left + width, r.top + centre + 2, r.right - width, r.top + centre + 2, c1);
398 GfxFillRect(r.left + width, r.top + centre + 3, r.right - width, r.top + centre + 3, c2);
427 GfxFillRect(r.left, r.top + dy1, r.left + 4, r.top + dy1, c1);
428 GfxFillRect(r.left + 1, r.top + dy2, r.left + 4, r.top + dy2, c2);
431 GfxFillRect(x2, r.top + dy1, r.right - 1, r.top + dy1, c1);
432 GfxFillRect(x2, r.top + dy2, r.right - 2, r.top + dy2, c2);
435 GfxFillRect(r.left, r.top + dy1, x2 - 2, r.top + dy1, c1);
436 GfxFillRect(r.left + 1, r.top + dy2, x2 - 2, r.top + dy2, c2);
439 GfxFillRect(r.right - 5, r.top + dy1, r.right - 1, r.top + dy1, c1);
440 GfxFillRect(r.right - 5, r.top + dy2, r.right - 2, r.top + dy2, c2);
444 GfxFillRect(r.left, r.top + dy2, r.left, r.bottom - 1, c1);
445 GfxFillRect(r.left + 1, r.top + dy2 + 1, r.left + 1, r.bottom - 2, c2);
448 GfxFillRect(r.right - 1, r.top + dy2, r.right - 1, r.bottom - 2, c1);
449 GfxFillRect(r.right, r.top + dy1, r.right, r.bottom - 1, c2);
451 GfxFillRect(r.left + 1, r.bottom - 1, r.right - 1, r.bottom - 1, c1);
452 GfxFillRect(r.left, r.bottom, r.right, r.bottom, c2);
525 if (colour != COLOUR_WHITE)
DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, FR_NONE);
549 if (str != STR_NULL) {
551 int offset =
max(0, ((
int)(r.bottom - r.top + 1) - (
int)d.height) / 2);
572 int image_offset =
max(0, ((
int)(r.bottom - r.top + 1) - dd_height) / 2);
576 DrawFrameRect(r.right + 1 - dd_width, r.top, r.right, r.bottom, colour, clicked_dropdown ?
FR_LOWERED : FR_NONE);
577 DrawSprite(SPR_ARROW_DOWN, PAL_NONE, r.right - (dd_width - 2) + clicked_dropdown, r.top + image_offset + clicked_dropdown);
581 DrawFrameRect(r.left, r.top, r.left + dd_width - 1, r.bottom, colour, clicked_dropdown ?
FR_LOWERED : FR_NONE);
582 DrawSprite(SPR_ARROW_DOWN, PAL_NONE, r.left + 1 + clicked_dropdown, r.top + image_offset + clicked_dropdown);
613 const NWidgetBase *widget = this->GetWidget<NWidgetBase>(i);
614 if (widget == NULL || !widget->IsHighlighted())
continue;
618 int right = left + widget->
current_x - 1;
619 int bottom = top + widget->
current_y - 1;
621 int colour =
_string_colourmap[_window_highlight_colour ? widget->GetHighlightColour() : TC_WHITE];
641 const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(widget);
644 Dimension dim = NWidgetScrollbar::GetVerticalDimension();
647 int y = offset + nwid->
pos_y + (nwid->
current_y - dim.height) / 2;
658 return NWidgetScrollbar::GetVerticalDimension().width + 1;
795 return (this->
type == tp) ?
this : NULL;
817 this->min_x =
max(this->min_x, min_x);
818 this->min_y =
max(this->min_y, min_y);
898 void NWidgetCore::FillNestedArray(
NWidgetBase **array, uint length)
900 if (this->
index >= 0 && (uint)(this->
index) < length) array[this->
index] =
this;
918 NWidgetContainer::~NWidgetContainer()
920 while (this->
head != NULL) {
930 if (this->
type == tp)
return this;
931 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
933 if (nwid != NULL)
return nwid;
944 assert(wid->
next == NULL && wid->
prev == NULL);
946 if (this->
head == NULL) {
950 assert(this->
tail != NULL);
959 void NWidgetContainer::FillNestedArray(
NWidgetBase **array, uint length)
961 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
962 child_wid->FillNestedArray(array, length);
974 void NWidgetStacked::SetIndex(
int index)
981 if (this->
index >= 0 && init_array) {
997 this->
fill_x = fill.width;
998 this->
fill_y = fill.height;
1011 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1012 child_wid->SetupSmallestSize(w, init_array);
1014 this->
smallest_x =
max(this->
smallest_x, child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right);
1015 this->
smallest_y =
max(this->
smallest_y, child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom);
1030 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1031 uint hor_step = (sizing ==
ST_SMALLEST) ? 1 : child_wid->GetHorizontalStepSize(sizing);
1032 uint child_width =
ComputeMaxSize(child_wid->smallest_x, given_width - child_wid->padding_left - child_wid->padding_right, hor_step);
1033 uint child_pos_x = (rtl ? child_wid->padding_right : child_wid->padding_left);
1035 uint vert_step = (sizing ==
ST_SMALLEST) ? 1 : child_wid->GetVerticalStepSize(sizing);
1036 uint child_height =
ComputeMaxSize(child_wid->smallest_y, given_height - child_wid->padding_top - child_wid->padding_bottom, vert_step);
1037 uint child_pos_y = child_wid->padding_top;
1039 child_wid->AssignSizePosition(sizing, x + child_pos_x, y + child_pos_y, child_width, child_height, rtl);
1043 void NWidgetStacked::FillNestedArray(
NWidgetBase **array, uint length)
1045 if (this->
index >= 0 && (uint)(this->
index) < length) array[this->
index] =
this;
1046 NWidgetContainer::FillNestedArray(array, length);
1054 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; plane++, child_wid = child_wid->
next) {
1070 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; plane++, child_wid = child_wid->
next) {
1089 this->flags = flags;
1110 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1119 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1121 if (nwid != NULL)
return nwid;
1142 uint max_vert_fill = 0;
1143 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1144 child_wid->SetupSmallestSize(w, init_array);
1145 longest =
max(longest, child_wid->smallest_x);
1146 max_vert_fill =
max(max_vert_fill, child_wid->GetVerticalStepSize(
ST_SMALLEST));
1147 this->
smallest_y =
max(this->smallest_y, child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom);
1150 uint max_smallest = this->
smallest_y + 3 * max_vert_fill;
1153 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1154 uint step_size = child_wid->GetVerticalStepSize(
ST_SMALLEST);
1155 uint child_height = child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom;
1156 if (step_size > 1 && child_height < cur_height) {
1157 uint remainder = (cur_height - child_height) % step_size;
1158 if (remainder > 0) {
1159 cur_height += step_size - remainder;
1160 assert(cur_height < max_smallest);
1170 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1171 if (child_wid->fill_x == 1) child_wid->smallest_x = longest;
1176 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1177 if (child_wid->next != NULL) {
1178 child_wid->padding_right += this->
pip_inter;
1180 child_wid->padding_right += this->
pip_post;
1183 this->
smallest_x += child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right;
1184 if (child_wid->fill_x > 0) {
1185 if (this->
fill_x == 0 || this->
fill_x > child_wid->fill_x) this->
fill_x = child_wid->fill_x;
1189 if (child_wid->resize_x > 0) {
1203 uint additional_length = given_width;
1206 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1207 additional_length -= child_wid->smallest_x + child_wid->padding_right + child_wid->padding_left;
1229 int num_changing_childs = 0;
1230 uint biggest_stepsize = 0;
1231 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1232 uint hor_step = child_wid->GetHorizontalStepSize(sizing);
1234 num_changing_childs++;
1235 biggest_stepsize =
max(biggest_stepsize, hor_step);
1237 child_wid->current_x = child_wid->smallest_x;
1240 uint vert_step = (sizing ==
ST_SMALLEST) ? 1 : child_wid->GetVerticalStepSize(sizing);
1241 child_wid->current_y =
ComputeMaxSize(child_wid->smallest_y, given_height - child_wid->padding_top - child_wid->padding_bottom, vert_step);
1245 while (biggest_stepsize > 0) {
1246 uint next_biggest_stepsize = 0;
1247 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1248 uint hor_step = child_wid->GetHorizontalStepSize(sizing);
1249 if (hor_step > biggest_stepsize)
continue;
1250 if (hor_step == biggest_stepsize) {
1251 uint increment = additional_length / num_changing_childs;
1252 num_changing_childs--;
1253 if (hor_step > 1) increment -= increment % hor_step;
1254 child_wid->current_x = child_wid->smallest_x + increment;
1255 additional_length -= increment;
1258 next_biggest_stepsize =
max(next_biggest_stepsize, hor_step);
1260 biggest_stepsize = next_biggest_stepsize;
1262 assert(num_changing_childs == 0);
1265 uint position = rtl ? this->
current_x : 0;
1267 while (child_wid != NULL) {
1268 uint child_width = child_wid->
current_x;
1274 position = rtl ? position - padded_child_width : position + padded_child_width;
1276 child_wid = child_wid->
next;
1307 uint max_hor_fill = 0;
1308 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1309 child_wid->SetupSmallestSize(w, init_array);
1310 highest =
max(highest, child_wid->smallest_y);
1311 max_hor_fill =
max(max_hor_fill, child_wid->GetHorizontalStepSize(
ST_SMALLEST));
1312 this->
smallest_x =
max(this->smallest_x, child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right);
1315 uint max_smallest = this->
smallest_x + 3 * max_hor_fill;
1318 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1319 uint step_size = child_wid->GetHorizontalStepSize(
ST_SMALLEST);
1320 uint child_width = child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right;
1321 if (step_size > 1 && child_width < cur_width) {
1322 uint remainder = (cur_width - child_width) % step_size;
1323 if (remainder > 0) {
1324 cur_width += step_size - remainder;
1325 assert(cur_width < max_smallest);
1335 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1336 if (child_wid->fill_y == 1) child_wid->smallest_y = highest;
1341 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1342 if (child_wid->next != NULL) {
1343 child_wid->padding_bottom += this->
pip_inter;
1345 child_wid->padding_bottom += this->
pip_post;
1348 this->
smallest_y += child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom;
1349 if (child_wid->fill_y > 0) {
1350 if (this->
fill_y == 0 || this->
fill_y > child_wid->fill_y) this->
fill_y = child_wid->fill_y;
1354 if (child_wid->resize_y > 0) {
1368 uint additional_length = given_height;
1371 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1372 additional_length -= child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom;
1385 int num_changing_childs = 0;
1386 uint biggest_stepsize = 0;
1387 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1388 uint vert_step = child_wid->GetVerticalStepSize(sizing);
1389 if (vert_step > 0) {
1390 num_changing_childs++;
1391 biggest_stepsize =
max(biggest_stepsize, vert_step);
1393 child_wid->current_y = child_wid->smallest_y;
1396 uint hor_step = (sizing ==
ST_SMALLEST) ? 1 : child_wid->GetHorizontalStepSize(sizing);
1397 child_wid->current_x =
ComputeMaxSize(child_wid->smallest_x, given_width - child_wid->padding_left - child_wid->padding_right, hor_step);
1401 while (biggest_stepsize > 0) {
1402 uint next_biggest_stepsize = 0;
1403 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1404 uint vert_step = child_wid->GetVerticalStepSize(sizing);
1405 if (vert_step > biggest_stepsize)
continue;
1406 if (vert_step == biggest_stepsize) {
1407 uint increment = additional_length / num_changing_childs;
1408 num_changing_childs--;
1409 if (vert_step > 1) increment -= increment % vert_step;
1410 child_wid->current_y = child_wid->smallest_y + increment;
1411 additional_length -= increment;
1414 next_biggest_stepsize =
max(next_biggest_stepsize, vert_step);
1416 biggest_stepsize = next_biggest_stepsize;
1418 assert(num_changing_childs == 0);
1422 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1423 uint child_x = x + (rtl ? child_wid->padding_right : child_wid->padding_left);
1424 uint child_height = child_wid->current_y;
1426 child_wid->AssignSizePosition(sizing, child_x, y + position + child_wid->padding_top, child_wid->current_x, child_height, rtl);
1427 position += child_height + child_wid->padding_top + child_wid->padding_bottom;
1448 void NWidgetSpacer::FillNestedArray(
NWidgetBase **array, uint length)
1471 void NWidgetMatrix::SetIndex(
int index)
1473 this->index =
index;
1476 void NWidgetMatrix::SetColour(Colours colour)
1488 if (this->clicked >= 0 && this->
sb != NULL && this->
widgets_x != 0) {
1504 this->count =
count;
1506 if (this->
sb == NULL || this->
widgets_x == 0)
return;
1515 if (count > 0) count -= this->
pip_inter;
1533 assert(this->
head != NULL);
1536 if (this->
index >= 0 && init_array) {
1556 this->
fill_x = fill.width;
1557 this->
fill_y = fill.height;
1586 void NWidgetMatrix::FillNestedArray(
NWidgetBase **array, uint length)
1588 if (this->
index >= 0 && (uint)(this->
index) < length) array[this->
index] =
this;
1589 NWidgetContainer::FillNestedArray(array, length);
1597 int start_x, start_y, base_offs_x, base_offs_y;
1602 int widget_col = (rtl ?
1604 x - (int)this->
pip_pre - (
int)this->
pos_x - base_offs_x
1609 int sub_wid = (widget_row + start_y) * this->
widgets_x + start_x + widget_col;
1610 if (sub_wid >= this->
count)
return NULL;
1613 assert(child != NULL);
1619 SB(child->
index, 16, 16, sub_wid);
1634 _cur_dpi = &tmp_dpi;
1638 assert(child != NULL);
1639 int start_x, start_y, base_offs_x, base_offs_y;
1642 int offs_y = base_offs_y;
1643 for (
int y = start_y; y < start_y + this->
widgets_y + 1; y++, offs_y += this->
widget_h) {
1645 if (offs_y + child->
smallest_y <= 0)
continue;
1646 if (offs_y >= (
int)this->
current_y)
break;
1651 int offs_x = base_offs_x;
1654 if (offs_x + child->
smallest_x <= 0)
continue;
1655 if (offs_x >= (
int)this->
current_x)
continue;
1658 int sub_wid = y * this->widgets_x + x;
1659 if (sub_wid >= this->
count)
break;
1663 SB(child->
index, 16, 16, sub_wid);
1685 if (this->
sb != NULL) {
1693 base_offs_x += sub_x;
1695 base_offs_x -= sub_x;
1713 if (index >= 0) this->
SetIndex(index);
1714 this->child =
child;
1717 NWidgetBackground::~NWidgetBackground()
1731 if (this->
child == NULL) {
1749 if (this->
child == NULL) {
1752 this->
child->
SetPIP(pip_pre, pip_inter, pip_post);
1757 if (init_array && this->
index >= 0) {
1761 if (this->
child != NULL) {
1793 d =
maxdim(d, background);
1795 if (this->
index >= 0) {
1796 static const Dimension padding = {0, 0};
1802 this->
fill_x = fill.width;
1803 this->
fill_y = fill.height;
1813 if (this->
child != NULL) {
1821 void NWidgetBackground::FillNestedArray(
NWidgetBase **array, uint length)
1823 if (this->
index >= 0 && (uint)(this->
index) < length) array[this->
index] =
this;
1824 if (this->
child != NULL) this->
child->FillNestedArray(array, length);
1832 r.left = this->
pos_x;
1834 r.top = this->
pos_y;
1838 if (dpi->left > r.right || dpi->left + dpi->width <= r.left || dpi->top > r.bottom || dpi->top + dpi->height <= r.top)
return;
1840 switch (this->
type) {
1873 if (nwid == NULL) nwid =
this;
1882 if (nwid == NULL && this->
type == tp) nwid =
this;
1893 if (init_array && this->
index >= 0) {
1995 if (init_array && this->
index >= 0) {
2002 switch (this->
type) {
2004 this->
SetMinimalSize(NWidgetScrollbar::GetHorizontalDimension().width * 3, NWidgetScrollbar::GetHorizontalDimension().height);
2007 this->
SetDataTip(0x0, STR_TOOLTIP_HSCROLL_BAR_SCROLLS_LIST);
2011 this->
SetMinimalSize(NWidgetScrollbar::GetVerticalDimension().width, NWidgetScrollbar::GetVerticalDimension().height * 3);
2014 this->
SetDataTip(0x0, STR_TOOLTIP_VSCROLL_BAR_SCROLLS_LIST);
2017 default: NOT_REACHED();
2029 r.left = this->
pos_x;
2031 r.top = this->
pos_y;
2035 if (dpi->left > r.right || dpi->left + dpi->width <= r.left || dpi->top > r.bottom || dpi->top + dpi->height <= r.top)
return;
2052 void NWidgetScrollbar::InvalidateDimensionCache()
2058 Dimension NWidgetScrollbar::GetVerticalDimension()
2069 Dimension NWidgetScrollbar::GetHorizontalDimension()
2114 if (index >= 0) this->
SetIndex(index);
2134 case NWID_PUSHBUTTON_DROPDOWN:
2148 this->
SetDataTip(data, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS);
2154 this->
SetDataTip(STR_NULL, STR_TOOLTIP_STICKY);
2160 this->
SetDataTip(STR_NULL, STR_TOOLTIP_SHADE);
2166 this->
SetDataTip(STR_NULL, STR_TOOLTIP_DEBUG);
2172 this->
SetDataTip(STR_NULL, STR_TOOLTIP_DEFSIZE);
2178 this->
SetDataTip(STR_NULL, STR_TOOLTIP_RESIZE);
2184 this->
SetDataTip(STR_NULL, STR_TOOLTIP_CLOSE_WINDOW);
2199 if (this->
index >= 0 && init_array) {
2209 switch (this->
type) {
2223 if (NWidgetLeaf::shadebox_dimension.width == 0) {
2225 NWidgetLeaf::shadebox_dimension.width += extra.width;
2226 NWidgetLeaf::shadebox_dimension.height += extra.height;
2228 size =
maxdim(size, NWidgetLeaf::shadebox_dimension);
2235 if (NWidgetLeaf::debugbox_dimension.width == 0) {
2236 NWidgetLeaf::debugbox_dimension =
GetSpriteSize(SPR_WINDOW_DEBUG);
2237 NWidgetLeaf::debugbox_dimension.width += extra.width;
2238 NWidgetLeaf::debugbox_dimension.height += extra.height;
2240 size =
maxdim(size, NWidgetLeaf::debugbox_dimension);
2252 if (NWidgetLeaf::stickybox_dimension.width == 0) {
2254 NWidgetLeaf::stickybox_dimension.width += extra.width;
2255 NWidgetLeaf::stickybox_dimension.height += extra.height;
2257 size =
maxdim(size, NWidgetLeaf::stickybox_dimension);
2264 if (NWidgetLeaf::defsizebox_dimension.width == 0) {
2265 NWidgetLeaf::defsizebox_dimension =
GetSpriteSize(SPR_WINDOW_DEFSIZE);
2266 NWidgetLeaf::defsizebox_dimension.width += extra.width;
2267 NWidgetLeaf::defsizebox_dimension.height += extra.height;
2269 size =
maxdim(size, NWidgetLeaf::defsizebox_dimension);
2276 if (NWidgetLeaf::resizebox_dimension.width == 0) {
2278 NWidgetLeaf::resizebox_dimension.width += extra.width;
2279 NWidgetLeaf::resizebox_dimension.height += extra.height;
2281 size =
maxdim(size, NWidgetLeaf::resizebox_dimension);
2286 size.width =
max(size.width, 30 + sprite_size.width);
2302 d2.width += extra.width;
2303 d2.height += extra.height;
2312 d2.width += extra.width;
2313 d2.height += extra.height;
2321 if (NWidgetLeaf::closebox_dimension.width == 0) {
2322 NWidgetLeaf::closebox_dimension =
GetSpriteSize(SPR_CLOSEBOX);
2323 NWidgetLeaf::closebox_dimension.width += extra.width;
2324 NWidgetLeaf::closebox_dimension.height += extra.height;
2326 size =
maxdim(size, NWidgetLeaf::closebox_dimension);
2336 d2.width += extra.width;
2337 d2.height += extra.height;
2354 d2.width += extra.width;
2355 d2.height += extra.height;
2361 case NWID_PUSHBUTTON_DROPDOWN: {
2364 if (NWidgetLeaf::dropdown_dimension.width == 0) {
2365 NWidgetLeaf::dropdown_dimension =
GetSpriteSize(SPR_ARROW_DOWN);
2368 extra.width =
WD_DROPDOWNTEXT_LEFT + WD_DROPDOWNTEXT_RIGHT + NWidgetLeaf::dropdown_dimension.width;
2372 d2.width += extra.width;
2373 d2.height =
max(d2.height, NWidgetLeaf::dropdown_dimension.height) + extra.height;
2385 this->
fill_x = fill.width;
2386 this->
fill_y = fill.height;
2399 new_dpi.left += this->
pos_x;
2400 new_dpi.top += this->
pos_y;
2403 _cur_dpi = &new_dpi;
2406 r.left = this->
pos_x;
2408 r.top = this->
pos_y;
2412 switch (this->
type) {
2441 case AWV_LEFT: sprite = SPR_ARROW_LEFT;
break;
2442 case AWV_RIGHT: sprite = SPR_ARROW_RIGHT;
break;
2443 default: NOT_REACHED();
2465 if (query != NULL) query->DrawEditBox(w, this->
index);
2508 case NWID_PUSHBUTTON_DROPDOWN:
2535 int button_width = this->
pos_x + this->
current_x - NWidgetLeaf::dropdown_dimension.width;
2536 return pt.x < button_width;
2538 int button_left = this->
pos_x + NWidgetLeaf::dropdown_dimension.width;
2539 return pt.x >= button_left;
2567 while (count > num_used) {
2568 switch (parts->
type) {
2570 if (*dest != NULL)
return num_used;
2575 if (*dest != NULL)
return num_used;
2581 if (*dest != NULL)
return num_used;
2589 if (*dest != NULL)
return num_used;
2591 *biggest_index =
max(*biggest_index, (
int)parts->u.
widget.
index);
2596 if (*dest != NULL)
return num_used;
2602 if (*dest != NULL)
return num_used;
2608 *biggest_index =
max(*biggest_index, (
int)parts->u.
widget.
index);
2613 if (*dest != NULL)
return num_used;
2616 *dest = parts->u.
func_ptr(&biggest);
2617 *biggest_index =
max(*biggest_index, biggest);
2625 assert(parts->u.
xy.x >= 0 && parts->u.
xy.y >= 0);
2634 assert(parts->u.
xy.x >= 0 && parts->u.
xy.y >= 0);
2651 if (nwrb != NULL) nwrb->
SetFill(parts->u.
xy.x, parts->u.
xy.y);
2689 if (*dest != NULL)
return num_used;
2691 *biggest_index =
max(*biggest_index, (
int)parts->u.
widget.
index);
2696 if (*dest != NULL)
return num_used;
2698 *biggest_index =
max(*biggest_index, (
int)parts->u.
widget.
index);
2702 if (*dest != NULL)
return num_used;
2707 *biggest_index =
max(*biggest_index, (
int)parts->u.
widget.
index);
2712 if (*dest != NULL)
return num_used;
2715 *biggest_index =
max(*biggest_index, (
int)parts->u.
widget.
index);
2740 assert(*parent == NULL || (nwid_cont != NULL && nwid_parent == NULL) || (nwid_cont == NULL && nwid_parent != NULL));
2745 bool fill_sub =
false;
2746 int num_used =
MakeNWidget(parts, count - total_used, &sub_widget, &fill_sub, biggest_index);
2748 total_used += num_used;
2751 if (sub_widget == NULL)
break;
2758 int num_used =
MakeWidgetTree(parts, count - total_used, &sub_ptr, biggest_index);
2760 total_used += num_used;
2764 if (nwid_cont != NULL) nwid_cont->
Add(sub_widget);
2765 if (nwid_parent != NULL) nwid_parent->
Add(sub_widget);
2766 if (nwid_cont == NULL && nwid_parent == NULL) {
2767 *parent = sub_widget;
2772 if (count == total_used)
return total_used;
2774 assert(total_used < count);
2776 return total_used + 1;
2792 *biggest_index = -1;
2814 *biggest_index = -1;
2818 int num_used =
MakeWidgetTree(parts, count, &nwid, biggest_index);
2819 assert(nwid != NULL);
2826 *shade_select = NULL;
2836 root->
Add(*shade_select);
2838 (*shade_select)->
Add(body);
2840 *shade_select = NULL;
2848 *biggest_index =
max(*biggest_index, biggest2);
2864 assert(max_length >= 1);
2873 for (
int widnum = widget_first; widnum <= widget_last; widnum++) {
2875 if (hor_length == max_length) {
2894 *biggest_index = widget_last;
2895 if (vert == NULL)
return hor;
2897 if (hor_length > 0 && hor_length < max_length) {
2904 if (hor != NULL) vert->
Add(hor);