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++;
236 if (str == STR_NULL)
return;
239 int offset =
max(0, ((
int)(r.bottom - r.top + 1) - (
int)d.height) / 2);
252 int offset =
max(0, ((
int)(r.bottom - r.top + 1) - (
int)d.height) / 2);
253 if (str != STR_NULL)
DrawString(r.left, r.right, r.top + offset, str, colour);
277 static inline void DrawMatrix(
const Rect &r, Colours colour,
bool clicked, uint16 data, uint resize_x, uint resize_y)
283 if (num_columns == 0) {
284 column_width = resize_x;
285 num_columns = (r.right - r.left + 1) / column_width;
287 column_width = (r.right - r.left + 1) / num_columns;
293 row_height = resize_y;
294 num_rows = (r.bottom - r.top + 1) / row_height;
296 row_height = (r.bottom - r.top + 1) / num_rows;
302 for (
int ctr = num_columns; ctr > 1; ctr--) {
308 for (
int ctr = num_rows; ctr > 1; ctr--) {
316 for (
int ctr = num_columns; ctr > 1; ctr--) {
322 for (
int ctr = num_rows; ctr > 1; ctr--) {
339 int centre = (r.right - r.left) / 2;
340 int height = NWidgetScrollbar::GetVerticalDimension().height;
344 DrawSprite(SPR_ARROW_UP, PAL_NONE, r.left + 1 + up_clicked, r.top + 1 + up_clicked);
346 DrawFrameRect(r.left, r.bottom - (height - 1), r.right, r.bottom, colour, (down_clicked) ?
FR_LOWERED : FR_NONE);
347 DrawSprite(SPR_ARROW_DOWN, PAL_NONE, r.left + 1 + down_clicked, r.bottom - (height - 2) + down_clicked);
353 GfxFillRect(r.left, r.top + height, r.right, r.bottom - height, c2);
357 GfxFillRect(r.left + centre - 3, r.top + height, r.left + centre - 3, r.bottom - height, c1);
358 GfxFillRect(r.left + centre - 2, r.top + height, r.left + centre - 2, r.bottom - height, c2);
359 GfxFillRect(r.left + centre + 2, r.top + height, r.left + centre + 2, r.bottom - height, c1);
360 GfxFillRect(r.left + centre + 3, r.top + height, r.left + centre + 3, r.bottom - height, c2);
377 int centre = (r.bottom - r.top) / 2;
378 int width = NWidgetScrollbar::GetHorizontalDimension().width;
381 DrawSprite(SPR_ARROW_LEFT, PAL_NONE, r.left + 1 + left_clicked, r.top + 1 + left_clicked);
384 DrawSprite(SPR_ARROW_RIGHT, PAL_NONE, r.right - (width - 2) + right_clicked, r.top + 1 + right_clicked);
390 GfxFillRect(r.left + width, r.top, r.right - width, r.bottom, c2);
394 GfxFillRect(r.left + width, r.top + centre - 3, r.right - width, r.top + centre - 3, c1);
395 GfxFillRect(r.left + width, r.top + centre - 2, r.right - width, r.top + centre - 2, c2);
396 GfxFillRect(r.left + width, r.top + centre + 2, r.right - width, r.top + centre + 2, c1);
397 GfxFillRect(r.left + width, r.top + centre + 3, r.right - width, r.top + centre + 3, c2);
426 GfxFillRect(r.left, r.top + dy1, r.left + 4, r.top + dy1, c1);
427 GfxFillRect(r.left + 1, r.top + dy2, r.left + 4, r.top + dy2, c2);
430 GfxFillRect(x2, r.top + dy1, r.right - 1, r.top + dy1, c1);
431 GfxFillRect(x2, r.top + dy2, r.right - 2, r.top + dy2, c2);
434 GfxFillRect(r.left, r.top + dy1, x2 - 2, r.top + dy1, c1);
435 GfxFillRect(r.left + 1, r.top + dy2, x2 - 2, r.top + dy2, c2);
438 GfxFillRect(r.right - 5, r.top + dy1, r.right - 1, r.top + dy1, c1);
439 GfxFillRect(r.right - 5, r.top + dy2, r.right - 2, r.top + dy2, c2);
443 GfxFillRect(r.left, r.top + dy2, r.left, r.bottom - 1, c1);
444 GfxFillRect(r.left + 1, r.top + dy2 + 1, r.left + 1, r.bottom - 2, c2);
447 GfxFillRect(r.right - 1, r.top + dy2, r.right - 1, r.bottom - 2, c1);
448 GfxFillRect(r.right, r.top + dy1, r.right, r.bottom - 1, c2);
450 GfxFillRect(r.left + 1, r.bottom - 1, r.right - 1, r.bottom - 1, c1);
451 GfxFillRect(r.left, r.bottom, r.right, r.bottom, c2);
530 if (colour != COLOUR_WHITE)
DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, FR_NONE);
552 if (str != STR_NULL) {
554 int offset =
max(0, ((
int)(r.bottom - r.top + 1) - (
int)d.height) / 2);
575 int image_offset =
max(0, ((
int)(r.bottom - r.top + 1) - dd_height) / 2);
579 DrawFrameRect(r.right + 1 - dd_width, r.top, r.right, r.bottom, colour, clicked_dropdown ?
FR_LOWERED : FR_NONE);
580 DrawSprite(SPR_ARROW_DOWN, PAL_NONE, r.right - (dd_width - 2) + clicked_dropdown, r.top + image_offset + clicked_dropdown);
584 DrawFrameRect(r.left, r.top, r.left + dd_width - 1, r.bottom, colour, clicked_dropdown ?
FR_LOWERED : FR_NONE);
585 DrawSprite(SPR_ARROW_DOWN, PAL_NONE, r.left + 1 + clicked_dropdown, r.top + image_offset + clicked_dropdown);
616 const NWidgetBase *widget = this->GetWidget<NWidgetBase>(i);
617 if (widget == NULL || !widget->IsHighlighted())
continue;
621 int right = left + widget->
current_x - 1;
622 int bottom = top + widget->
current_y - 1;
624 int colour =
_string_colourmap[_window_highlight_colour ? widget->GetHighlightColour() : TC_WHITE];
644 const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(widget);
647 Dimension dim = NWidgetScrollbar::GetVerticalDimension();
650 int y = offset + nwid->
pos_y + (nwid->
current_y - dim.height) / 2;
661 return NWidgetScrollbar::GetVerticalDimension().width + 1;
798 return (this->
type == tp) ?
this : NULL;
820 this->min_x =
max(this->min_x, min_x);
821 this->min_y =
max(this->min_y, min_y);
901 void NWidgetCore::FillNestedArray(
NWidgetBase **array, uint length)
903 if (this->
index >= 0 && (uint)(this->
index) < length) array[this->
index] =
this;
921 NWidgetContainer::~NWidgetContainer()
923 while (this->
head != NULL) {
933 if (this->
type == tp)
return this;
934 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
936 if (nwid != NULL)
return nwid;
947 assert(wid->
next == NULL && wid->
prev == NULL);
949 if (this->
head == NULL) {
953 assert(this->
tail != NULL);
962 void NWidgetContainer::FillNestedArray(
NWidgetBase **array, uint length)
964 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
965 child_wid->FillNestedArray(array, length);
977 void NWidgetStacked::SetIndex(
int index)
984 if (this->
index >= 0 && init_array) {
1000 this->
fill_x = fill.width;
1001 this->
fill_y = fill.height;
1014 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1015 child_wid->SetupSmallestSize(w, init_array);
1017 this->
smallest_x =
max(this->
smallest_x, child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right);
1018 this->
smallest_y =
max(this->
smallest_y, child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom);
1033 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1034 uint hor_step = (sizing ==
ST_SMALLEST) ? 1 : child_wid->GetHorizontalStepSize(sizing);
1035 uint child_width =
ComputeMaxSize(child_wid->smallest_x, given_width - child_wid->padding_left - child_wid->padding_right, hor_step);
1036 uint child_pos_x = (rtl ? child_wid->padding_right : child_wid->padding_left);
1038 uint vert_step = (sizing ==
ST_SMALLEST) ? 1 : child_wid->GetVerticalStepSize(sizing);
1039 uint child_height =
ComputeMaxSize(child_wid->smallest_y, given_height - child_wid->padding_top - child_wid->padding_bottom, vert_step);
1040 uint child_pos_y = child_wid->padding_top;
1042 child_wid->AssignSizePosition(sizing, x + child_pos_x, y + child_pos_y, child_width, child_height, rtl);
1046 void NWidgetStacked::FillNestedArray(
NWidgetBase **array, uint length)
1048 if (this->
index >= 0 && (uint)(this->
index) < length) array[this->
index] =
this;
1049 NWidgetContainer::FillNestedArray(array, length);
1057 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; plane++, child_wid = child_wid->
next) {
1073 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; plane++, child_wid = child_wid->
next) {
1092 this->flags = flags;
1113 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1122 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1124 if (nwid != NULL)
return nwid;
1145 uint max_vert_fill = 0;
1146 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1147 child_wid->SetupSmallestSize(w, init_array);
1148 longest =
max(longest, child_wid->smallest_x);
1149 max_vert_fill =
max(max_vert_fill, child_wid->GetVerticalStepSize(
ST_SMALLEST));
1150 this->
smallest_y =
max(this->smallest_y, child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom);
1153 uint max_smallest = this->
smallest_y + 3 * max_vert_fill;
1156 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1157 uint step_size = child_wid->GetVerticalStepSize(
ST_SMALLEST);
1158 uint child_height = child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom;
1159 if (step_size > 1 && child_height < cur_height) {
1160 uint remainder = (cur_height - child_height) % step_size;
1161 if (remainder > 0) {
1162 cur_height += step_size - remainder;
1163 assert(cur_height < max_smallest);
1173 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1174 if (child_wid->fill_x == 1) child_wid->smallest_x = longest;
1179 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1180 if (child_wid->next != NULL) {
1181 child_wid->padding_right += this->
pip_inter;
1183 child_wid->padding_right += this->
pip_post;
1186 this->
smallest_x += child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right;
1187 if (child_wid->fill_x > 0) {
1188 if (this->
fill_x == 0 || this->
fill_x > child_wid->fill_x) this->
fill_x = child_wid->fill_x;
1192 if (child_wid->resize_x > 0) {
1206 uint additional_length = given_width;
1209 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1210 additional_length -= child_wid->smallest_x + child_wid->padding_right + child_wid->padding_left;
1232 int num_changing_childs = 0;
1233 uint biggest_stepsize = 0;
1234 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1235 uint hor_step = child_wid->GetHorizontalStepSize(sizing);
1237 num_changing_childs++;
1238 biggest_stepsize =
max(biggest_stepsize, hor_step);
1240 child_wid->current_x = child_wid->smallest_x;
1243 uint vert_step = (sizing ==
ST_SMALLEST) ? 1 : child_wid->GetVerticalStepSize(sizing);
1244 child_wid->current_y =
ComputeMaxSize(child_wid->smallest_y, given_height - child_wid->padding_top - child_wid->padding_bottom, vert_step);
1248 while (biggest_stepsize > 0) {
1249 uint next_biggest_stepsize = 0;
1250 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1251 uint hor_step = child_wid->GetHorizontalStepSize(sizing);
1252 if (hor_step > biggest_stepsize)
continue;
1253 if (hor_step == biggest_stepsize) {
1254 uint increment = additional_length / num_changing_childs;
1255 num_changing_childs--;
1256 if (hor_step > 1) increment -= increment % hor_step;
1257 child_wid->current_x = child_wid->smallest_x + increment;
1258 additional_length -= increment;
1261 next_biggest_stepsize =
max(next_biggest_stepsize, hor_step);
1263 biggest_stepsize = next_biggest_stepsize;
1265 assert(num_changing_childs == 0);
1268 uint position = rtl ? this->
current_x : 0;
1270 while (child_wid != NULL) {
1271 uint child_width = child_wid->
current_x;
1277 position = rtl ? position - padded_child_width : position + padded_child_width;
1279 child_wid = child_wid->
next;
1310 uint max_hor_fill = 0;
1311 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1312 child_wid->SetupSmallestSize(w, init_array);
1313 highest =
max(highest, child_wid->smallest_y);
1314 max_hor_fill =
max(max_hor_fill, child_wid->GetHorizontalStepSize(
ST_SMALLEST));
1315 this->
smallest_x =
max(this->smallest_x, child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right);
1318 uint max_smallest = this->
smallest_x + 3 * max_hor_fill;
1321 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1322 uint step_size = child_wid->GetHorizontalStepSize(
ST_SMALLEST);
1323 uint child_width = child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right;
1324 if (step_size > 1 && child_width < cur_width) {
1325 uint remainder = (cur_width - child_width) % step_size;
1326 if (remainder > 0) {
1327 cur_width += step_size - remainder;
1328 assert(cur_width < max_smallest);
1338 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1339 if (child_wid->fill_y == 1) child_wid->smallest_y = highest;
1344 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1345 if (child_wid->next != NULL) {
1346 child_wid->padding_bottom += this->
pip_inter;
1348 child_wid->padding_bottom += this->
pip_post;
1351 this->
smallest_y += child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom;
1352 if (child_wid->fill_y > 0) {
1353 if (this->
fill_y == 0 || this->
fill_y > child_wid->fill_y) this->
fill_y = child_wid->fill_y;
1357 if (child_wid->resize_y > 0) {
1371 uint additional_length = given_height;
1374 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1375 additional_length -= child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom;
1388 int num_changing_childs = 0;
1389 uint biggest_stepsize = 0;
1390 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1391 uint vert_step = child_wid->GetVerticalStepSize(sizing);
1392 if (vert_step > 0) {
1393 num_changing_childs++;
1394 biggest_stepsize =
max(biggest_stepsize, vert_step);
1396 child_wid->current_y = child_wid->smallest_y;
1399 uint hor_step = (sizing ==
ST_SMALLEST) ? 1 : child_wid->GetHorizontalStepSize(sizing);
1400 child_wid->current_x =
ComputeMaxSize(child_wid->smallest_x, given_width - child_wid->padding_left - child_wid->padding_right, hor_step);
1404 while (biggest_stepsize > 0) {
1405 uint next_biggest_stepsize = 0;
1406 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1407 uint vert_step = child_wid->GetVerticalStepSize(sizing);
1408 if (vert_step > biggest_stepsize)
continue;
1409 if (vert_step == biggest_stepsize) {
1410 uint increment = additional_length / num_changing_childs;
1411 num_changing_childs--;
1412 if (vert_step > 1) increment -= increment % vert_step;
1413 child_wid->current_y = child_wid->smallest_y + increment;
1414 additional_length -= increment;
1417 next_biggest_stepsize =
max(next_biggest_stepsize, vert_step);
1419 biggest_stepsize = next_biggest_stepsize;
1421 assert(num_changing_childs == 0);
1425 for (
NWidgetBase *child_wid = this->
head; child_wid != NULL; child_wid = child_wid->
next) {
1426 uint child_x = x + (rtl ? child_wid->padding_right : child_wid->padding_left);
1427 uint child_height = child_wid->current_y;
1429 child_wid->AssignSizePosition(sizing, child_x, y + position + child_wid->padding_top, child_wid->current_x, child_height, rtl);
1430 position += child_height + child_wid->padding_top + child_wid->padding_bottom;
1451 void NWidgetSpacer::FillNestedArray(
NWidgetBase **array, uint length)
1474 void NWidgetMatrix::SetIndex(
int index)
1476 this->index =
index;
1479 void NWidgetMatrix::SetColour(Colours colour)
1491 if (this->clicked >= 0 && this->
sb != NULL && this->
widgets_x != 0) {
1507 this->count =
count;
1509 if (this->
sb == NULL || this->
widgets_x == 0)
return;
1518 if (count > 0) count -= this->
pip_inter;
1536 assert(this->
head != NULL);
1539 if (this->
index >= 0 && init_array) {
1559 this->
fill_x = fill.width;
1560 this->
fill_y = fill.height;
1589 void NWidgetMatrix::FillNestedArray(
NWidgetBase **array, uint length)
1591 if (this->
index >= 0 && (uint)(this->
index) < length) array[this->
index] =
this;
1592 NWidgetContainer::FillNestedArray(array, length);
1600 int start_x, start_y, base_offs_x, base_offs_y;
1605 int widget_col = (rtl ?
1607 x - (int)this->
pip_pre - (
int)this->
pos_x - base_offs_x
1612 int sub_wid = (widget_row + start_y) * this->
widgets_x + start_x + widget_col;
1613 if (sub_wid >= this->
count)
return NULL;
1616 assert(child != NULL);
1622 SB(child->
index, 16, 16, sub_wid);
1637 _cur_dpi = &tmp_dpi;
1641 assert(child != NULL);
1642 int start_x, start_y, base_offs_x, base_offs_y;
1645 int offs_y = base_offs_y;
1646 for (
int y = start_y; y < start_y + this->
widgets_y + 1; y++, offs_y += this->
widget_h) {
1648 if (offs_y + child->
smallest_y <= 0)
continue;
1649 if (offs_y >= (
int)this->
current_y)
break;
1654 int offs_x = base_offs_x;
1657 if (offs_x + child->
smallest_x <= 0)
continue;
1658 if (offs_x >= (
int)this->
current_x)
continue;
1661 int sub_wid = y * this->widgets_x + x;
1662 if (sub_wid >= this->
count)
break;
1666 SB(child->
index, 16, 16, sub_wid);
1688 if (this->
sb != NULL) {
1696 base_offs_x += sub_x;
1698 base_offs_x -= sub_x;
1716 if (index >= 0) this->
SetIndex(index);
1717 this->child =
child;
1720 NWidgetBackground::~NWidgetBackground()
1734 if (this->
child == NULL) {
1752 if (this->
child == NULL) {
1755 this->
child->
SetPIP(pip_pre, pip_inter, pip_post);
1760 if (init_array && this->
index >= 0) {
1764 if (this->
child != NULL) {
1796 d =
maxdim(d, background);
1798 if (this->
index >= 0) {
1799 static const Dimension padding = {0, 0};
1805 this->
fill_x = fill.width;
1806 this->
fill_y = fill.height;
1816 if (this->
child != NULL) {
1824 void NWidgetBackground::FillNestedArray(
NWidgetBase **array, uint length)
1826 if (this->
index >= 0 && (uint)(this->
index) < length) array[this->
index] =
this;
1827 if (this->
child != NULL) this->
child->FillNestedArray(array, length);
1835 r.left = this->
pos_x;
1837 r.top = this->
pos_y;
1841 if (dpi->left > r.right || dpi->left + dpi->width <= r.left || dpi->top > r.bottom || dpi->top + dpi->height <= r.top)
return;
1843 switch (this->
type) {
1876 if (nwid == NULL) nwid =
this;
1885 if (nwid == NULL && this->
type == tp) nwid =
this;
1896 if (init_array && this->
index >= 0) {
1998 if (init_array && this->
index >= 0) {
2005 switch (this->
type) {
2007 this->
SetMinimalSize(NWidgetScrollbar::GetHorizontalDimension().width * 3, NWidgetScrollbar::GetHorizontalDimension().height);
2010 this->
SetDataTip(0x0, STR_TOOLTIP_HSCROLL_BAR_SCROLLS_LIST);
2014 this->
SetMinimalSize(NWidgetScrollbar::GetVerticalDimension().width, NWidgetScrollbar::GetVerticalDimension().height * 3);
2017 this->
SetDataTip(0x0, STR_TOOLTIP_VSCROLL_BAR_SCROLLS_LIST);
2020 default: NOT_REACHED();
2032 r.left = this->
pos_x;
2034 r.top = this->
pos_y;
2038 if (dpi->left > r.right || dpi->left + dpi->width <= r.left || dpi->top > r.bottom || dpi->top + dpi->height <= r.top)
return;
2055 void NWidgetScrollbar::InvalidateDimensionCache()
2061 Dimension NWidgetScrollbar::GetVerticalDimension()
2072 Dimension NWidgetScrollbar::GetHorizontalDimension()
2117 if (index >= 0) this->
SetIndex(index);
2137 case NWID_PUSHBUTTON_DROPDOWN:
2151 this->
SetDataTip(data, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS);
2157 this->
SetDataTip(STR_NULL, STR_TOOLTIP_STICKY);
2163 this->
SetDataTip(STR_NULL, STR_TOOLTIP_SHADE);
2169 this->
SetDataTip(STR_NULL, STR_TOOLTIP_DEBUG);
2175 this->
SetDataTip(STR_NULL, STR_TOOLTIP_DEFSIZE);
2181 this->
SetDataTip(STR_NULL, STR_TOOLTIP_RESIZE);
2187 this->
SetDataTip(STR_NULL, STR_TOOLTIP_CLOSE_WINDOW);
2202 if (this->
index >= 0 && init_array) {
2212 switch (this->
type) {
2226 if (NWidgetLeaf::shadebox_dimension.width == 0) {
2228 NWidgetLeaf::shadebox_dimension.width += extra.width;
2229 NWidgetLeaf::shadebox_dimension.height += extra.height;
2231 size =
maxdim(size, NWidgetLeaf::shadebox_dimension);
2238 if (NWidgetLeaf::debugbox_dimension.width == 0) {
2239 NWidgetLeaf::debugbox_dimension =
GetSpriteSize(SPR_WINDOW_DEBUG);
2240 NWidgetLeaf::debugbox_dimension.width += extra.width;
2241 NWidgetLeaf::debugbox_dimension.height += extra.height;
2243 size =
maxdim(size, NWidgetLeaf::debugbox_dimension);
2255 if (NWidgetLeaf::stickybox_dimension.width == 0) {
2257 NWidgetLeaf::stickybox_dimension.width += extra.width;
2258 NWidgetLeaf::stickybox_dimension.height += extra.height;
2260 size =
maxdim(size, NWidgetLeaf::stickybox_dimension);
2267 if (NWidgetLeaf::defsizebox_dimension.width == 0) {
2268 NWidgetLeaf::defsizebox_dimension =
GetSpriteSize(SPR_WINDOW_DEFSIZE);
2269 NWidgetLeaf::defsizebox_dimension.width += extra.width;
2270 NWidgetLeaf::defsizebox_dimension.height += extra.height;
2272 size =
maxdim(size, NWidgetLeaf::defsizebox_dimension);
2279 if (NWidgetLeaf::resizebox_dimension.width == 0) {
2281 NWidgetLeaf::resizebox_dimension.width += extra.width;
2282 NWidgetLeaf::resizebox_dimension.height += extra.height;
2284 size =
maxdim(size, NWidgetLeaf::resizebox_dimension);
2289 size.width =
max(size.width, 30 + sprite_size.width);
2305 d2.width += extra.width;
2306 d2.height += extra.height;
2315 d2.width += extra.width;
2316 d2.height += extra.height;
2324 if (NWidgetLeaf::closebox_dimension.width == 0) {
2325 NWidgetLeaf::closebox_dimension =
GetSpriteSize(SPR_CLOSEBOX);
2326 NWidgetLeaf::closebox_dimension.width += extra.width;
2327 NWidgetLeaf::closebox_dimension.height += extra.height;
2329 size =
maxdim(size, NWidgetLeaf::closebox_dimension);
2339 d2.width += extra.width;
2340 d2.height += extra.height;
2357 d2.width += extra.width;
2358 d2.height += extra.height;
2364 case NWID_PUSHBUTTON_DROPDOWN: {
2367 if (NWidgetLeaf::dropdown_dimension.width == 0) {
2368 NWidgetLeaf::dropdown_dimension =
GetSpriteSize(SPR_ARROW_DOWN);
2371 extra.width =
WD_DROPDOWNTEXT_LEFT + WD_DROPDOWNTEXT_RIGHT + NWidgetLeaf::dropdown_dimension.width;
2375 d2.width += extra.width;
2376 d2.height =
max(d2.height, NWidgetLeaf::dropdown_dimension.height) + extra.height;
2388 this->
fill_x = fill.width;
2389 this->
fill_y = fill.height;
2402 new_dpi.left += this->
pos_x;
2403 new_dpi.top += this->
pos_y;
2406 _cur_dpi = &new_dpi;
2409 r.left = this->
pos_x;
2411 r.top = this->
pos_y;
2415 switch (this->
type) {
2444 case AWV_LEFT: sprite = SPR_ARROW_LEFT;
break;
2445 case AWV_RIGHT: sprite = SPR_ARROW_RIGHT;
break;
2446 default: NOT_REACHED();
2468 if (query != NULL) query->DrawEditBox(w, this->
index);
2511 case NWID_PUSHBUTTON_DROPDOWN:
2538 int button_width = this->
pos_x + this->
current_x - NWidgetLeaf::dropdown_dimension.width;
2539 return pt.x < button_width;
2541 int button_left = this->
pos_x + NWidgetLeaf::dropdown_dimension.width;
2542 return pt.x >= button_left;
2570 while (count > num_used) {
2571 switch (parts->
type) {
2573 if (*dest != NULL)
return num_used;
2578 if (*dest != NULL)
return num_used;
2584 if (*dest != NULL)
return num_used;
2592 if (*dest != NULL)
return num_used;
2594 *biggest_index =
max(*biggest_index, (
int)parts->u.
widget.
index);
2599 if (*dest != NULL)
return num_used;
2605 if (*dest != NULL)
return num_used;
2611 *biggest_index =
max(*biggest_index, (
int)parts->u.
widget.
index);
2616 if (*dest != NULL)
return num_used;
2619 *dest = parts->u.
func_ptr(&biggest);
2620 *biggest_index =
max(*biggest_index, biggest);
2628 assert(parts->u.
xy.x >= 0 && parts->u.
xy.y >= 0);
2637 assert(parts->u.
xy.x >= 0 && parts->u.
xy.y >= 0);
2654 if (nwrb != NULL) nwrb->
SetFill(parts->u.
xy.x, parts->u.
xy.y);
2692 if (*dest != NULL)
return num_used;
2694 *biggest_index =
max(*biggest_index, (
int)parts->u.
widget.
index);
2699 if (*dest != NULL)
return num_used;
2701 *biggest_index =
max(*biggest_index, (
int)parts->u.
widget.
index);
2705 if (*dest != NULL)
return num_used;
2710 *biggest_index =
max(*biggest_index, (
int)parts->u.
widget.
index);
2715 if (*dest != NULL)
return num_used;
2718 *biggest_index =
max(*biggest_index, (
int)parts->u.
widget.
index);
2743 assert(*parent == NULL || (nwid_cont != NULL && nwid_parent == NULL) || (nwid_cont == NULL && nwid_parent != NULL));
2748 bool fill_sub =
false;
2749 int num_used =
MakeNWidget(parts, count - total_used, &sub_widget, &fill_sub, biggest_index);
2751 total_used += num_used;
2754 if (sub_widget == NULL)
break;
2761 int num_used =
MakeWidgetTree(parts, count - total_used, &sub_ptr, biggest_index);
2763 total_used += num_used;
2767 if (nwid_cont != NULL) nwid_cont->
Add(sub_widget);
2768 if (nwid_parent != NULL) nwid_parent->
Add(sub_widget);
2769 if (nwid_cont == NULL && nwid_parent == NULL) {
2770 *parent = sub_widget;
2775 if (count == total_used)
return total_used;
2777 assert(total_used < count);
2779 return total_used + 1;
2795 *biggest_index = -1;
2817 *biggest_index = -1;
2821 int num_used =
MakeWidgetTree(parts, count, &nwid, biggest_index);
2822 assert(nwid != NULL);
2829 *shade_select = NULL;
2839 root->
Add(*shade_select);
2841 (*shade_select)->
Add(body);
2843 *shade_select = NULL;
2851 *biggest_index =
max(*biggest_index, biggest2);
2867 assert(max_length >= 1);
2876 for (
int widnum = widget_first; widnum <= widget_last; widnum++) {
2878 if (hor_length == max_length) {
2897 *biggest_index = widget_last;
2898 if (vert == NULL)
return hor;
2900 if (hor_length > 0 && hor_length < max_length) {
2907 if (hor != NULL) vert->
Add(hor);