|
OpenTTD Source
1.11.0-beta1
|
Go to the documentation of this file.
22 #include "table/strings.h"
39 int rev_base = top + bottom;
42 button_size = NWidgetScrollbar::GetHorizontalDimension().width;
44 button_size = NWidgetScrollbar::GetVerticalDimension().height;
47 bottom -= button_size;
49 int height = (bottom - top);
54 if (count != 0) top +=
height * pos / count;
56 if (cap > count) cap = count;
57 if (count != 0) bottom -= (count - pos - cap) *
height / count;
61 pt.x = rev_base - bottom;
62 pt.y = rev_base - top;
88 button_size = NWidgetScrollbar::GetHorizontalDimension().width;
91 button_size = NWidgetScrollbar::GetVerticalDimension().height;
93 if (pos < mi + button_size) {
96 if (_scroller_click_timeout <= 1) {
97 _scroller_click_timeout = 3;
101 }
else if (pos >= ma - button_size) {
105 if (_scroller_click_timeout <= 1) {
106 _scroller_click_timeout = 3;
115 }
else if (pos > pt.y) {
118 _scrollbar_start_pos = pt.x - mi - button_size;
119 _scrollbar_size = ma - mi - button_size * 2;
121 _cursorpos_drag_start = _cursor.
pos;
148 assert(scrollbar !=
nullptr);
163 return (nw !=
nullptr) ? nw->
index : -1;
177 assert(colour < COLOUR_END);
194 interior = (flags &
FR_DARKENED ? medium_dark : medium_light);
200 interior = medium_dark;
221 if ((type & WWT_MASK) ==
WWT_IMGBTN_2 && clicked) img++;
235 if (str == STR_NULL)
return;
238 int offset = std::max(0, ((
int)(r.bottom - r.top + 1) - (
int)d.height) / 2);
251 int offset = std::max(0, ((
int)(r.bottom - r.top + 1) - (
int)d.height) / 2);
252 if (str != STR_NULL)
DrawString(r.left, r.right, r.top + offset, str, colour);
276 static inline void DrawMatrix(
const Rect &r, Colours colour,
bool clicked, uint16 data, uint resize_x, uint resize_y)
282 if (num_columns == 0) {
283 column_width = resize_x;
284 num_columns = (r.right - r.left + 1) / column_width;
286 column_width = (r.right - r.left + 1) / num_columns;
292 row_height = resize_y;
293 num_rows = (r.bottom - r.top + 1) / row_height;
295 row_height = (r.bottom - r.top + 1) / num_rows;
301 for (
int ctr = num_columns; ctr > 1; ctr--) {
307 for (
int ctr = num_rows; ctr > 1; ctr--) {
315 for (
int ctr = num_columns; ctr > 1; ctr--) {
321 for (
int ctr = num_rows; ctr > 1; ctr--) {
338 int centre = (r.right - r.left) / 2;
339 int height = NWidgetScrollbar::GetVerticalDimension().height;
343 DrawSprite(SPR_ARROW_UP, PAL_NONE, r.left + 1 + up_clicked, r.top + 1 + up_clicked);
346 DrawSprite(SPR_ARROW_DOWN, PAL_NONE, r.left + 1 + down_clicked, r.bottom - (
height - 2) + down_clicked);
376 int centre = (r.bottom - r.top) / 2;
377 int width = NWidgetScrollbar::GetHorizontalDimension().width;
380 DrawSprite(SPR_ARROW_LEFT, PAL_NONE, r.left + 1 + left_clicked, r.top + 1 + left_clicked);
383 DrawSprite(SPR_ARROW_RIGHT, PAL_NONE, r.right - (
width - 2) + right_clicked, r.top + 1 + right_clicked);
425 GfxFillRect(r.left, r.top + dy1, r.left + 4, r.top + dy1, c1);
426 GfxFillRect(r.left + 1, r.top + dy2, r.left + 4, r.top + dy2, c2);
429 GfxFillRect(x2, r.top + dy1, r.right - 1, r.top + dy1, c1);
430 GfxFillRect(x2, r.top + dy2, r.right - 2, r.top + dy2, c2);
433 GfxFillRect(r.left, r.top + dy1, x2 - 2, r.top + dy1, c1);
434 GfxFillRect(r.left + 1, r.top + dy2, x2 - 2, r.top + dy2, c2);
437 GfxFillRect(r.right - 5, r.top + dy1, r.right - 1, r.top + dy1, c1);
438 GfxFillRect(r.right - 5, r.top + dy2, r.right - 2, r.top + dy2, c2);
442 GfxFillRect(r.left, r.top + dy2, r.left, r.bottom - 1, c1);
443 GfxFillRect(r.left + 1, r.top + dy2 + 1, r.left + 1, r.bottom - 2, c2);
446 GfxFillRect(r.right - 1, r.top + dy2, r.right - 1, r.bottom - 2, c1);
447 GfxFillRect(r.right, r.top + dy1, r.right, r.bottom - 1, c2);
449 GfxFillRect(r.left + 1, r.bottom - 1, r.right - 1, r.bottom - 1, c1);
450 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 = std::max(0, ((
int)(r.bottom - r.top + 1) - (
int)d.height) / 2);
568 int text_offset = std::max(0, ((
int)(r.bottom - r.top + 1) -
FONT_HEIGHT_NORMAL) / 2);
572 int image_offset = std::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 ==
nullptr || !widget->IsHighlighted())
continue;
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 :
nullptr;
817 this->min_x = std::max(this->min_x,
min_x);
818 this->min_y = std::max(this->min_y,
min_y);
909 if (this->
index >= 0 && (uint)(this->
index) < length) array[this->
index] =
this;
923 this->
head =
nullptr;
924 this->
tail =
nullptr;
927 NWidgetContainer::~NWidgetContainer()
929 while (this->
head !=
nullptr) {
934 this->
tail =
nullptr;
939 if (this->
type == tp)
return this;
940 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
942 if (nwid !=
nullptr)
return nwid;
953 assert(wid->
next ==
nullptr && wid->
prev ==
nullptr);
955 if (this->
head ==
nullptr) {
959 assert(this->
tail !=
nullptr);
960 assert(this->
tail->
next ==
nullptr);
970 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
971 child_wid->FillNestedArray(array, length);
983 void NWidgetStacked::SetIndex(
int index)
990 if (this->
index >= 0 && init_array) {
1006 this->
fill_x = fill.width;
1007 this->
fill_y = fill.height;
1016 this->
fill_x = (this->
head !=
nullptr) ? 1 : 0;
1017 this->
fill_y = (this->
head !=
nullptr) ? 1 : 0;
1020 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1021 child_wid->SetupSmallestSize(w, init_array);
1023 this->
smallest_x = std::max(this->
smallest_x, child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right);
1024 this->
smallest_y = std::max(this->
smallest_y, child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom);
1039 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1040 uint hor_step = (sizing ==
ST_SMALLEST) ? 1 : child_wid->GetHorizontalStepSize(sizing);
1041 uint child_width =
ComputeMaxSize(child_wid->smallest_x, given_width - child_wid->padding_left - child_wid->padding_right, hor_step);
1042 uint child_pos_x = (rtl ? child_wid->padding_right : child_wid->padding_left);
1044 uint vert_step = (sizing ==
ST_SMALLEST) ? 1 : child_wid->GetVerticalStepSize(sizing);
1045 uint child_height =
ComputeMaxSize(child_wid->smallest_y, given_height - child_wid->padding_top - child_wid->padding_bottom, vert_step);
1046 uint child_pos_y = child_wid->padding_top;
1048 child_wid->AssignSizePosition(sizing, x + child_pos_x, y + child_pos_y, child_width, child_height, rtl);
1054 if (this->
index >= 0 && (uint)(this->
index) < length) array[this->
index] =
this;
1063 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; plane++, child_wid = child_wid->
next) {
1079 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; plane++, child_wid = child_wid->
next) {
1098 this->flags = flags;
1119 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1128 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1130 if (nwid !=
nullptr)
return nwid;
1151 uint max_vert_fill = 0;
1152 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1153 child_wid->SetupSmallestSize(w, init_array);
1154 longest = std::max(longest, child_wid->smallest_x);
1155 max_vert_fill = std::max(max_vert_fill, child_wid->GetVerticalStepSize(
ST_SMALLEST));
1156 this->
smallest_y = std::max(this->
smallest_y, child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom);
1159 uint max_smallest = this->
smallest_y + 3 * max_vert_fill;
1162 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1163 uint step_size = child_wid->GetVerticalStepSize(
ST_SMALLEST);
1164 uint child_height = child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom;
1165 if (step_size > 1 && child_height < cur_height) {
1166 uint remainder = (cur_height - child_height) % step_size;
1167 if (remainder > 0) {
1168 cur_height += step_size - remainder;
1169 assert(cur_height < max_smallest);
1179 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1180 if (child_wid->fill_x == 1) child_wid->smallest_x = longest;
1185 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1186 if (child_wid->next !=
nullptr) {
1187 child_wid->padding_right += this->
pip_inter;
1189 child_wid->padding_right += this->
pip_post;
1192 this->
smallest_x += child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right;
1193 if (child_wid->fill_x > 0) {
1194 if (this->
fill_x == 0 || this->
fill_x > child_wid->fill_x) this->
fill_x = child_wid->fill_x;
1198 if (child_wid->resize_x > 0) {
1212 uint additional_length = given_width;
1215 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1216 additional_length -= child_wid->smallest_x + child_wid->padding_right + child_wid->padding_left;
1238 int num_changing_childs = 0;
1239 uint biggest_stepsize = 0;
1240 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1241 uint hor_step = child_wid->GetHorizontalStepSize(sizing);
1243 num_changing_childs++;
1244 biggest_stepsize = std::max(biggest_stepsize, hor_step);
1246 child_wid->current_x = child_wid->smallest_x;
1249 uint vert_step = (sizing ==
ST_SMALLEST) ? 1 : child_wid->GetVerticalStepSize(sizing);
1250 child_wid->current_y =
ComputeMaxSize(child_wid->smallest_y, given_height - child_wid->padding_top - child_wid->padding_bottom, vert_step);
1254 while (biggest_stepsize > 0) {
1255 uint next_biggest_stepsize = 0;
1256 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1257 uint hor_step = child_wid->GetHorizontalStepSize(sizing);
1258 if (hor_step > biggest_stepsize)
continue;
1259 if (hor_step == biggest_stepsize) {
1260 uint increment = additional_length / num_changing_childs;
1261 num_changing_childs--;
1262 if (hor_step > 1) increment -= increment % hor_step;
1263 child_wid->current_x = child_wid->smallest_x + increment;
1264 additional_length -= increment;
1267 next_biggest_stepsize = std::max(next_biggest_stepsize, hor_step);
1269 biggest_stepsize = next_biggest_stepsize;
1271 assert(num_changing_childs == 0);
1274 uint position = rtl ? this->
current_x : 0;
1276 while (child_wid !=
nullptr) {
1277 uint child_width = child_wid->
current_x;
1283 position = rtl ? position - padded_child_width : position + padded_child_width;
1285 child_wid = child_wid->
next;
1316 uint max_hor_fill = 0;
1317 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1318 child_wid->SetupSmallestSize(w, init_array);
1319 highest = std::max(highest, child_wid->smallest_y);
1320 max_hor_fill = std::max(max_hor_fill, child_wid->GetHorizontalStepSize(
ST_SMALLEST));
1321 this->
smallest_x = std::max(this->
smallest_x, child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right);
1324 uint max_smallest = this->
smallest_x + 3 * max_hor_fill;
1327 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1328 uint step_size = child_wid->GetHorizontalStepSize(
ST_SMALLEST);
1329 uint child_width = child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right;
1330 if (step_size > 1 && child_width < cur_width) {
1331 uint remainder = (cur_width - child_width) % step_size;
1332 if (remainder > 0) {
1333 cur_width += step_size - remainder;
1334 assert(cur_width < max_smallest);
1344 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1345 if (child_wid->fill_y == 1) child_wid->smallest_y = highest;
1350 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1351 if (child_wid->next !=
nullptr) {
1352 child_wid->padding_bottom += this->
pip_inter;
1354 child_wid->padding_bottom += this->
pip_post;
1357 this->
smallest_y += child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom;
1358 if (child_wid->fill_y > 0) {
1359 if (this->
fill_y == 0 || this->
fill_y > child_wid->fill_y) this->
fill_y = child_wid->fill_y;
1363 if (child_wid->resize_y > 0) {
1377 uint additional_length = given_height;
1380 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1381 additional_length -= child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom;
1394 int num_changing_childs = 0;
1395 uint biggest_stepsize = 0;
1396 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1397 uint vert_step = child_wid->GetVerticalStepSize(sizing);
1398 if (vert_step > 0) {
1399 num_changing_childs++;
1400 biggest_stepsize = std::max(biggest_stepsize, vert_step);
1402 child_wid->current_y = child_wid->smallest_y;
1405 uint hor_step = (sizing ==
ST_SMALLEST) ? 1 : child_wid->GetHorizontalStepSize(sizing);
1406 child_wid->current_x =
ComputeMaxSize(child_wid->smallest_x, given_width - child_wid->padding_left - child_wid->padding_right, hor_step);
1410 while (biggest_stepsize > 0) {
1411 uint next_biggest_stepsize = 0;
1412 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1413 uint vert_step = child_wid->GetVerticalStepSize(sizing);
1414 if (vert_step > biggest_stepsize)
continue;
1415 if (vert_step == biggest_stepsize) {
1416 uint increment = additional_length / num_changing_childs;
1417 num_changing_childs--;
1418 if (vert_step > 1) increment -= increment % vert_step;
1419 child_wid->current_y = child_wid->smallest_y + increment;
1420 additional_length -= increment;
1423 next_biggest_stepsize = std::max(next_biggest_stepsize, vert_step);
1425 biggest_stepsize = next_biggest_stepsize;
1427 assert(num_changing_childs == 0);
1431 for (
NWidgetBase *child_wid = this->
head; child_wid !=
nullptr; child_wid = child_wid->
next) {
1432 uint child_x = x + (rtl ? child_wid->padding_right : child_wid->padding_left);
1433 uint child_height = child_wid->current_y;
1435 child_wid->AssignSizePosition(sizing, child_x, y + position + child_wid->padding_top, child_wid->current_x, child_height, rtl);
1436 position += child_height + child_wid->padding_top + child_wid->padding_bottom;
1480 void NWidgetMatrix::SetIndex(
int index)
1482 this->index =
index;
1485 void NWidgetMatrix::SetColour(Colours colour)
1497 if (this->clicked >= 0 && this->
sb !=
nullptr && this->
widgets_x != 0) {
1513 this->count =
count;
1515 if (this->
sb ==
nullptr || this->
widgets_x == 0)
return;
1542 assert(this->
head !=
nullptr);
1543 assert(this->
head->
next ==
nullptr);
1545 if (this->
index >= 0 && init_array) {
1552 assert(nw !=
nullptr);
1565 this->
fill_x = fill.width;
1566 this->
fill_y = fill.height;
1597 if (this->
index >= 0 && (uint)(this->
index) < length) array[this->
index] =
this;
1606 int start_x, start_y, base_offs_x, base_offs_y;
1611 int widget_col = (rtl ?
1613 x - (int)this->
pip_pre - (
int)this->
pos_x - base_offs_x
1618 int sub_wid = (widget_row + start_y) * this->
widgets_x + start_x + widget_col;
1619 if (sub_wid >= this->
count)
return nullptr;
1622 assert(child !=
nullptr);
1628 SB(child->
index, 16, 16, sub_wid);
1643 _cur_dpi = &tmp_dpi;
1647 assert(child !=
nullptr);
1648 int start_x, start_y, base_offs_x, base_offs_y;
1651 int offs_y = base_offs_y;
1652 for (
int y = start_y; y < start_y + this->
widgets_y + 1; y++, offs_y += this->
widget_h) {
1654 if (offs_y + child->
smallest_y <= 0)
continue;
1655 if (offs_y >= (
int)this->
current_y)
break;
1660 int offs_x = base_offs_x;
1663 if (offs_x + child->
smallest_x <= 0)
continue;
1664 if (offs_x >= (
int)this->
current_x)
continue;
1667 int sub_wid = y * this->widgets_x + x;
1668 if (sub_wid >= this->
count)
break;
1672 SB(child->
index, 16, 16, sub_wid);
1694 if (this->
sb !=
nullptr) {
1702 base_offs_x += sub_x;
1704 base_offs_x -= sub_x;
1723 this->child =
child;
1726 NWidgetBackground::~NWidgetBackground()
1728 if (this->
child !=
nullptr)
delete this->
child;
1740 if (this->
child ==
nullptr) {
1758 if (this->
child ==
nullptr) {
1761 this->
child->
SetPIP(pip_pre, pip_inter, pip_post);
1766 if (init_array && this->
index >= 0) {
1770 if (this->
child !=
nullptr) {
1802 d =
maxdim(d, background);
1804 if (this->
index >= 0) {
1805 static const Dimension padding = {0, 0};
1811 this->
fill_x = fill.width;
1812 this->
fill_y = fill.height;
1822 if (this->
child !=
nullptr) {
1832 if (this->
index >= 0 && (uint)(this->
index) < length) array[this->
index] =
this;
1841 r.left = this->
pos_x;
1843 r.top = this->
pos_y;
1847 if (dpi->left > r.right || dpi->left + dpi->width <= r.left || dpi->top > r.bottom || dpi->top + dpi->height <= r.top)
return;
1849 switch (this->
type) {
1882 if (nwid ==
nullptr) nwid =
this;
1891 if (nwid ==
nullptr && this->
type == tp) nwid =
this;
1902 if (init_array && this->
index >= 0) {
1946 if (vp !=
nullptr) {
2004 if (init_array && this->
index >= 0) {
2011 switch (this->
type) {
2013 this->
SetMinimalSize(NWidgetScrollbar::GetHorizontalDimension().
width * 3, NWidgetScrollbar::GetHorizontalDimension().
height);
2016 this->
SetDataTip(0x0, STR_TOOLTIP_HSCROLL_BAR_SCROLLS_LIST);
2020 this->
SetMinimalSize(NWidgetScrollbar::GetVerticalDimension().
width, NWidgetScrollbar::GetVerticalDimension().
height * 3);
2023 this->
SetDataTip(0x0, STR_TOOLTIP_VSCROLL_BAR_SCROLLS_LIST);
2026 default: NOT_REACHED();
2038 r.left = this->
pos_x;
2040 r.top = this->
pos_y;
2044 if (dpi->left > r.right || dpi->left + dpi->width <= r.left || dpi->top > r.bottom || dpi->top + dpi->height <= r.top)
return;
2061 void NWidgetScrollbar::InvalidateDimensionCache()
2067 Dimension NWidgetScrollbar::GetVerticalDimension()
2078 Dimension NWidgetScrollbar::GetHorizontalDimension()
2143 case NWID_PUSHBUTTON_DROPDOWN:
2157 this->
SetDataTip(data, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS);
2163 this->
SetDataTip(STR_NULL, STR_TOOLTIP_STICKY);
2169 this->
SetDataTip(STR_NULL, STR_TOOLTIP_SHADE);
2175 this->
SetDataTip(STR_NULL, STR_TOOLTIP_DEBUG);
2181 this->
SetDataTip(STR_NULL, STR_TOOLTIP_DEFSIZE);
2187 this->
SetDataTip(STR_NULL, STR_TOOLTIP_RESIZE);
2193 this->
SetDataTip(STR_NULL, STR_TOOLTIP_CLOSE_WINDOW);
2208 if (this->
index >= 0 && init_array) {
2218 switch (this->
type) {
2295 size.width = std::max(size.width, 30 + sprite_size.width);
2311 d2.width += extra.width;
2312 d2.height += extra.height;
2321 d2.width += extra.width;
2322 d2.height += extra.height;
2345 d2.width += extra.width;
2346 d2.height += extra.height;
2363 d2.width += extra.width;
2364 d2.height += extra.height;
2370 case NWID_PUSHBUTTON_DROPDOWN: {
2381 d2.width += extra.width;
2394 this->
fill_x = fill.width;
2395 this->
fill_y = fill.height;
2408 new_dpi.left += this->
pos_x;
2409 new_dpi.top += this->
pos_y;
2412 _cur_dpi = &new_dpi;
2415 r.left = this->
pos_x;
2417 r.top = this->
pos_y;
2421 switch (this->
type) {
2450 case AWV_LEFT: sprite = SPR_ARROW_LEFT;
break;
2451 case AWV_RIGHT: sprite = SPR_ARROW_RIGHT;
break;
2452 default: NOT_REACHED();
2474 if (query !=
nullptr) query->DrawEditBox(w, this->
index);
2517 case NWID_PUSHBUTTON_DROPDOWN:
2544 int button_width = this->
pos_x + this->
current_x - NWidgetLeaf::dropdown_dimension.width;
2545 return pt.x < button_width;
2547 int button_left = this->
pos_x + NWidgetLeaf::dropdown_dimension.width;
2548 return pt.x >= button_left;
2576 while (count > num_used) {
2577 switch (parts->
type) {
2579 if (*dest !=
nullptr)
return num_used;
2584 if (*dest !=
nullptr)
return num_used;
2590 if (*dest !=
nullptr)
return num_used;
2598 if (*dest !=
nullptr)
return num_used;
2600 *biggest_index = std::max(*biggest_index, (
int)parts->u.
widget.
index);
2605 if (*dest !=
nullptr)
return num_used;
2611 if (*dest !=
nullptr)
return num_used;
2617 *biggest_index = std::max(*biggest_index, (
int)parts->u.
widget.
index);
2622 if (*dest !=
nullptr)
return num_used;
2625 *dest = parts->u.
func_ptr(&biggest);
2626 *biggest_index = std::max(*biggest_index, biggest);
2633 if (nwrb !=
nullptr) {
2634 assert(parts->u.
xy.x >= 0 && parts->u.
xy.y >= 0);
2642 if (nwrb !=
nullptr) {
2643 assert(parts->u.
xy.x >= 0 && parts->u.
xy.y >= 0);
2651 if (nwrb !=
nullptr) {
2660 if (nwrb !=
nullptr) nwrb->
SetFill(parts->u.
xy.x, parts->u.
xy.y);
2666 if (nwc !=
nullptr) {
2688 if (nwc !=
nullptr) {
2698 if (*dest !=
nullptr)
return num_used;
2700 *biggest_index = std::max(*biggest_index, (
int)parts->u.
widget.
index);
2705 if (*dest !=
nullptr)
return num_used;
2707 *biggest_index = std::max(*biggest_index, (
int)parts->u.
widget.
index);
2711 if (*dest !=
nullptr)
return num_used;
2716 *biggest_index = std::max(*biggest_index, (
int)parts->u.
widget.
index);
2721 if (*dest !=
nullptr)
return num_used;
2724 *biggest_index = std::max(*biggest_index, (
int)parts->u.
widget.
index);
2749 assert(*parent ==
nullptr || (nwid_cont !=
nullptr && nwid_parent ==
nullptr) || (nwid_cont ==
nullptr && nwid_parent !=
nullptr));
2754 bool fill_sub =
false;
2755 int num_used =
MakeNWidget(parts, count - total_used, &sub_widget, &fill_sub, biggest_index);
2757 total_used += num_used;
2760 if (sub_widget ==
nullptr)
break;
2767 int num_used =
MakeWidgetTree(parts, count - total_used, &sub_ptr, biggest_index);
2769 total_used += num_used;
2773 if (nwid_cont !=
nullptr) nwid_cont->
Add(sub_widget);
2774 if (nwid_parent !=
nullptr) nwid_parent->
Add(sub_widget);
2775 if (nwid_cont ==
nullptr && nwid_parent ==
nullptr) {
2776 *parent = sub_widget;
2781 if (count == total_used)
return total_used;
2783 assert(total_used < count);
2785 return total_used + 1;
2801 *biggest_index = -1;
2823 *biggest_index = -1;
2827 int num_used =
MakeWidgetTree(parts, count, &nwid, biggest_index);
2828 assert(nwid !=
nullptr);
2835 *shade_select =
nullptr;
2845 root->
Add(*shade_select);
2847 (*shade_select)->
Add(body);
2849 *shade_select =
nullptr;
2857 *biggest_index = std::max(*biggest_index, biggest2);
2873 assert(max_length >= 1);
2882 for (
int widnum = widget_first; widnum <= widget_last; widnum++) {
2884 if (hor_length == max_length) {
2890 if (hor ==
nullptr) {
2903 *biggest_index = widget_last;
2904 if (vert ==
nullptr)
return hor;
2906 if (hor_length > 0 && hor_length < max_length) {
2913 if (hor !=
nullptr) vert->
Add(hor);
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.
@ 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.
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_HOR_CENTER
Horizontally 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.
int height
Height in pixels of our display surface.
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.
@ 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.
@ 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.
@ 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...
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.
@ 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,...
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.
static int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
@ WD_DEBUGBOX_BOTTOM
Bottom offset of debug sprite.
@ WD_SCROLLBAR_TOP
Top offset of scrollbar.
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.
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.
int width
Width in pixels of our display surface.
@ 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.
@ 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.
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.
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.