Window: Add accessors for cached NWidgetLeaf dimensions
This commit is contained in:
@@ -3019,7 +3019,7 @@ struct BuildVehicleWindowTrainAdvanced final : BuildVehicleWindowBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case WID_BV_RENAME_LOCO: {
|
case WID_BV_RENAME_LOCO: {
|
||||||
*size = maxdim(*size, NWidgetLeaf::resizebox_dimension);
|
*size = maxdim(*size, NWidgetLeaf::GetResizeBoxDimension());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -194,7 +194,7 @@ public:
|
|||||||
(*size).width = std::max((*size).width, WidgetDimensions::scaled.framerect.left + this->CARGO_ICON_WIDTH + WidgetDimensions::scaled.framerect.Horizontal() + this->max_cargo_name_width + padding.width);
|
(*size).width = std::max((*size).width, WidgetDimensions::scaled.framerect.left + this->CARGO_ICON_WIDTH + WidgetDimensions::scaled.framerect.Horizontal() + this->max_cargo_name_width + padding.width);
|
||||||
(*size).height = std::max((*size).height, (uint) FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.framerect.Vertical());
|
(*size).height = std::max((*size).height, (uint) FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.framerect.Vertical());
|
||||||
} else if ((WID_CTO_CARGO_DROPDOWN_FIRST <= widget && widget <= WID_CTO_CARGO_DROPDOWN_LAST) || widget == WID_CTO_SET_TO_ALL_DROPDOWN) {
|
} else if ((WID_CTO_CARGO_DROPDOWN_FIRST <= widget && widget <= WID_CTO_CARGO_DROPDOWN_LAST) || widget == WID_CTO_SET_TO_ALL_DROPDOWN) {
|
||||||
(*size).width = std::max((*size).width, WidgetDimensions::scaled.dropdowntext.Horizontal() + this->max_cargo_dropdown_width + NWidgetLeaf::dropdown_dimension.width);
|
(*size).width = std::max((*size).width, WidgetDimensions::scaled.dropdowntext.Horizontal() + this->max_cargo_dropdown_width + NWidgetLeaf::GetDropdownBoxDimension().width);
|
||||||
(*size).height = std::max((*size).height, (uint) WidgetDimensions::scaled.dropdowntext.Vertical() + FONT_HEIGHT_NORMAL);
|
(*size).height = std::max((*size).height, (uint) WidgetDimensions::scaled.dropdowntext.Vertical() + FONT_HEIGHT_NORMAL);
|
||||||
} else if (widget == WID_CTO_SET_TO_ALL_LABEL) {
|
} else if (widget == WID_CTO_SET_TO_ALL_LABEL) {
|
||||||
(*size).width = std::max((*size).width, this->max_cargo_name_width + WidgetDimensions::scaled.framerect.right + padding.width);
|
(*size).width = std::max((*size).width, this->max_cargo_name_width + WidgetDimensions::scaled.framerect.right + padding.width);
|
||||||
|
@@ -839,7 +839,7 @@ void DrawCaption(const Rect &r, Colours colour, Owner owner, TextColour text_col
|
|||||||
*/
|
*/
|
||||||
static inline void DrawButtonDropdown(const Rect &r, Colours colour, bool clicked_button, bool clicked_dropdown, StringID str, StringAlignment align)
|
static inline void DrawButtonDropdown(const Rect &r, Colours colour, bool clicked_button, bool clicked_dropdown, StringID str, StringAlignment align)
|
||||||
{
|
{
|
||||||
int dd_width = NWidgetLeaf::dropdown_dimension.width;
|
int dd_width = NWidgetLeaf::GetDropdownBoxDimension().width;
|
||||||
|
|
||||||
if (_current_text_dir == TD_LTR) {
|
if (_current_text_dir == TD_LTR) {
|
||||||
DrawFrameRect(r.left, r.top, r.right - dd_width, r.bottom, colour, clicked_button ? FR_LOWERED : FR_NONE);
|
DrawFrameRect(r.left, r.top, r.right - dd_width, r.bottom, colour, clicked_button ? FR_LOWERED : FR_NONE);
|
||||||
@@ -2739,6 +2739,27 @@ NWidgetLeaf::NWidgetLeaf(WidgetType tp, Colours colour, int index, uint32 data,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* static */ void NWidgetLeaf::UpdateDropdownBoxDimension()
|
||||||
|
{
|
||||||
|
NWidgetLeaf::dropdown_dimension = GetScaledSpriteSize(SPR_ARROW_DOWN);
|
||||||
|
NWidgetLeaf::dropdown_dimension.width += WidgetDimensions::scaled.vscrollbar.Horizontal();
|
||||||
|
NWidgetLeaf::dropdown_dimension.height += WidgetDimensions::scaled.vscrollbar.Vertical();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */ void NWidgetLeaf::UpdateResizeBoxDimension()
|
||||||
|
{
|
||||||
|
NWidgetLeaf::resizebox_dimension = maxdim(GetScaledSpriteSize(SPR_WINDOW_RESIZE_LEFT), GetScaledSpriteSize(SPR_WINDOW_RESIZE_RIGHT));
|
||||||
|
NWidgetLeaf::resizebox_dimension.width += WidgetDimensions::scaled.resizebox.Horizontal();
|
||||||
|
NWidgetLeaf::resizebox_dimension.height += WidgetDimensions::scaled.resizebox.Vertical();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */ void NWidgetLeaf::UpdateCloseBoxDimension()
|
||||||
|
{
|
||||||
|
NWidgetLeaf::closebox_dimension = GetScaledSpriteSize(SPR_CLOSEBOX);
|
||||||
|
NWidgetLeaf::closebox_dimension.width += WidgetDimensions::scaled.closebox.Horizontal();
|
||||||
|
NWidgetLeaf::closebox_dimension.height += WidgetDimensions::scaled.closebox.Vertical();
|
||||||
|
}
|
||||||
|
|
||||||
void NWidgetLeaf::SetupSmallestSize(Window *w, bool init_array)
|
void NWidgetLeaf::SetupSmallestSize(Window *w, bool init_array)
|
||||||
{
|
{
|
||||||
if (this->index >= 0 && init_array) { // Fill w->nested_array[]
|
if (this->index >= 0 && init_array) { // Fill w->nested_array[]
|
||||||
@@ -2809,12 +2830,7 @@ void NWidgetLeaf::SetupSmallestSize(Window *w, bool init_array)
|
|||||||
|
|
||||||
case WWT_RESIZEBOX: {
|
case WWT_RESIZEBOX: {
|
||||||
padding = {WidgetDimensions::scaled.resizebox.Horizontal(), WidgetDimensions::scaled.resizebox.Vertical()};
|
padding = {WidgetDimensions::scaled.resizebox.Horizontal(), WidgetDimensions::scaled.resizebox.Vertical()};
|
||||||
if (NWidgetLeaf::resizebox_dimension.width == 0) {
|
size = maxdim(size, NWidgetLeaf::GetResizeBoxDimension());
|
||||||
NWidgetLeaf::resizebox_dimension = maxdim(GetScaledSpriteSize(SPR_WINDOW_RESIZE_LEFT), GetScaledSpriteSize(SPR_WINDOW_RESIZE_RIGHT));
|
|
||||||
NWidgetLeaf::resizebox_dimension.width += padding.width;
|
|
||||||
NWidgetLeaf::resizebox_dimension.height += padding.height;
|
|
||||||
}
|
|
||||||
size = maxdim(size, NWidgetLeaf::resizebox_dimension);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WWT_EDITBOX: {
|
case WWT_EDITBOX: {
|
||||||
@@ -2850,12 +2866,7 @@ void NWidgetLeaf::SetupSmallestSize(Window *w, bool init_array)
|
|||||||
|
|
||||||
case WWT_CLOSEBOX: {
|
case WWT_CLOSEBOX: {
|
||||||
padding = {WidgetDimensions::scaled.closebox.Horizontal(), WidgetDimensions::scaled.closebox.Vertical()};
|
padding = {WidgetDimensions::scaled.closebox.Horizontal(), WidgetDimensions::scaled.closebox.Vertical()};
|
||||||
if (NWidgetLeaf::closebox_dimension.width == 0) {
|
size = maxdim(size, NWidgetLeaf::GetCloseBoxDimension());
|
||||||
NWidgetLeaf::closebox_dimension = GetScaledSpriteSize(SPR_CLOSEBOX);
|
|
||||||
NWidgetLeaf::closebox_dimension.width += padding.width;
|
|
||||||
NWidgetLeaf::closebox_dimension.height += padding.height;
|
|
||||||
}
|
|
||||||
size = maxdim(size, NWidgetLeaf::closebox_dimension);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WWT_TEXTBTN:
|
case WWT_TEXTBTN:
|
||||||
@@ -2887,16 +2898,12 @@ void NWidgetLeaf::SetupSmallestSize(Window *w, bool init_array)
|
|||||||
case WWT_DROPDOWN:
|
case WWT_DROPDOWN:
|
||||||
case NWID_BUTTON_DROPDOWN:
|
case NWID_BUTTON_DROPDOWN:
|
||||||
case NWID_PUSHBUTTON_DROPDOWN: {
|
case NWID_PUSHBUTTON_DROPDOWN: {
|
||||||
if (NWidgetLeaf::dropdown_dimension.width == 0) {
|
const Dimension &dropdown_dim = NWidgetLeaf::GetDropdownBoxDimension();
|
||||||
NWidgetLeaf::dropdown_dimension = GetScaledSpriteSize(SPR_ARROW_DOWN);
|
padding = {WidgetDimensions::scaled.dropdowntext.Horizontal() + dropdown_dim.width + WidgetDimensions::scaled.fullbevel.Horizontal(), WidgetDimensions::scaled.dropdowntext.Vertical()};
|
||||||
NWidgetLeaf::dropdown_dimension.width += WidgetDimensions::scaled.vscrollbar.Horizontal();
|
|
||||||
NWidgetLeaf::dropdown_dimension.height += WidgetDimensions::scaled.vscrollbar.Vertical();
|
|
||||||
}
|
|
||||||
padding = {WidgetDimensions::scaled.dropdowntext.Horizontal() + NWidgetLeaf::dropdown_dimension.width + WidgetDimensions::scaled.fullbevel.Horizontal(), WidgetDimensions::scaled.dropdowntext.Vertical()};
|
|
||||||
if (this->index >= 0) w->SetStringParameters(this->index);
|
if (this->index >= 0) w->SetStringParameters(this->index);
|
||||||
Dimension d2 = GetStringBoundingBox(this->widget_data, this->text_size);
|
Dimension d2 = GetStringBoundingBox(this->widget_data, this->text_size);
|
||||||
d2.width += padding.width;
|
d2.width += padding.width;
|
||||||
d2.height = std::max(d2.height + padding.height, NWidgetLeaf::dropdown_dimension.height);
|
d2.height = std::max(d2.height + padding.height, dropdown_dim.height);
|
||||||
size = maxdim(size, d2);
|
size = maxdim(size, d2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -3054,11 +3061,12 @@ void NWidgetLeaf::Draw(const Window *w)
|
|||||||
*/
|
*/
|
||||||
bool NWidgetLeaf::ButtonHit(const Point &pt)
|
bool NWidgetLeaf::ButtonHit(const Point &pt)
|
||||||
{
|
{
|
||||||
|
const Dimension &dimension = NWidgetLeaf::GetDropdownBoxDimension();
|
||||||
if (_current_text_dir == TD_LTR) {
|
if (_current_text_dir == TD_LTR) {
|
||||||
int button_width = this->pos_x + this->current_x - NWidgetLeaf::dropdown_dimension.width;
|
int button_width = this->pos_x + this->current_x - dimension.width;
|
||||||
return pt.x < button_width;
|
return pt.x < button_width;
|
||||||
} else {
|
} else {
|
||||||
int button_left = this->pos_x + NWidgetLeaf::dropdown_dimension.width;
|
int button_left = this->pos_x + dimension.width;
|
||||||
return pt.x >= button_left;
|
return pt.x >= button_left;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -877,10 +877,32 @@ public:
|
|||||||
|
|
||||||
static void InvalidateDimensionCache();
|
static void InvalidateDimensionCache();
|
||||||
|
|
||||||
|
static const Dimension &GetDropdownBoxDimension()
|
||||||
|
{
|
||||||
|
if (dropdown_dimension.width == 0) UpdateDropdownBoxDimension();
|
||||||
|
return dropdown_dimension;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const Dimension &GetResizeBoxDimension()
|
||||||
|
{
|
||||||
|
if (resizebox_dimension.width == 0) UpdateResizeBoxDimension();
|
||||||
|
return resizebox_dimension;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const Dimension &GetCloseBoxDimension()
|
||||||
|
{
|
||||||
|
if (closebox_dimension.width == 0) UpdateCloseBoxDimension();
|
||||||
|
return closebox_dimension;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static void UpdateDropdownBoxDimension();
|
||||||
|
static void UpdateResizeBoxDimension();
|
||||||
|
static void UpdateCloseBoxDimension();
|
||||||
|
|
||||||
static Dimension dropdown_dimension; ///< Cached size of a dropdown widget.
|
static Dimension dropdown_dimension; ///< Cached size of a dropdown widget.
|
||||||
static Dimension resizebox_dimension; ///< Cached size of a resizebox widget.
|
static Dimension resizebox_dimension; ///< Cached size of a resizebox widget.
|
||||||
static Dimension closebox_dimension; ///< Cached size of a closebox widget.
|
static Dimension closebox_dimension; ///< Cached size of a closebox widget.
|
||||||
private:
|
|
||||||
static Dimension shadebox_dimension; ///< Cached size of a shadebox widget.
|
static Dimension shadebox_dimension; ///< Cached size of a shadebox widget.
|
||||||
static Dimension debugbox_dimension; ///< Cached size of a debugbox widget.
|
static Dimension debugbox_dimension; ///< Cached size of a debugbox widget.
|
||||||
static Dimension defsizebox_dimension; ///< Cached size of a defsizebox widget.
|
static Dimension defsizebox_dimension; ///< Cached size of a defsizebox widget.
|
||||||
|
@@ -1791,8 +1791,9 @@ static Point GetAutoPlacePosition(int width, int height)
|
|||||||
* of the closebox
|
* of the closebox
|
||||||
*/
|
*/
|
||||||
int left = rtl ? _screen.width - width : 0, top = toolbar_y;
|
int left = rtl ? _screen.width - width : 0, top = toolbar_y;
|
||||||
int offset_x = rtl ? -(int)NWidgetLeaf::closebox_dimension.width : (int)NWidgetLeaf::closebox_dimension.width;
|
const Dimension &closebox_dimension = NWidgetLeaf::GetCloseBoxDimension();
|
||||||
int offset_y = std::max<int>(NWidgetLeaf::closebox_dimension.height, FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.captiontext.Vertical());
|
int offset_x = rtl ? -(int)closebox_dimension.width : (int)closebox_dimension.width;
|
||||||
|
int offset_y = std::max<int>(closebox_dimension.height, FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.captiontext.Vertical());
|
||||||
|
|
||||||
restart:
|
restart:
|
||||||
for (const Window *w : Window::IterateFromBack()) {
|
for (const Window *w : Window::IterateFromBack()) {
|
||||||
@@ -1858,11 +1859,12 @@ static Point LocalGetWindowPlacement(const WindowDesc *desc, int16 sm_width, int
|
|||||||
* - Y position: closebox of parent + closebox of child + statusbar
|
* - Y position: closebox of parent + closebox of child + statusbar
|
||||||
* - X position: closebox on left/right, resizebox on right/left (depending on ltr/rtl)
|
* - X position: closebox on left/right, resizebox on right/left (depending on ltr/rtl)
|
||||||
*/
|
*/
|
||||||
int indent_y = std::max<int>(NWidgetLeaf::closebox_dimension.height, FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.captiontext.Vertical());
|
const Dimension &closebox_dimension = NWidgetLeaf::GetCloseBoxDimension();
|
||||||
|
int indent_y = std::max<int>(closebox_dimension.height, FONT_HEIGHT_NORMAL + WidgetDimensions::scaled.captiontext.Vertical());
|
||||||
if (w->top + 3 * indent_y < _screen.height) {
|
if (w->top + 3 * indent_y < _screen.height) {
|
||||||
pt.y = w->top + indent_y;
|
pt.y = w->top + indent_y;
|
||||||
int indent_close = NWidgetLeaf::closebox_dimension.width;
|
int indent_close = closebox_dimension.width;
|
||||||
int indent_resize = NWidgetLeaf::resizebox_dimension.width;
|
int indent_resize = NWidgetLeaf::GetResizeBoxDimension().width;
|
||||||
if (_current_text_dir == TD_RTL) {
|
if (_current_text_dir == TD_RTL) {
|
||||||
pt.x = std::max(w->left + w->width - default_width - indent_close, 0);
|
pt.x = std::max(w->left + w->width - default_width - indent_close, 0);
|
||||||
if (pt.x + default_width >= indent_close && pt.x + indent_resize <= _screen.width) return pt;
|
if (pt.x + default_width >= indent_close && pt.x + indent_resize <= _screen.width) return pt;
|
||||||
|
Reference in New Issue
Block a user