From dff569beb660e880a1a9808d9e193a7245854d1d Mon Sep 17 00:00:00 2001 From: rubidium Date: Wed, 13 Nov 2013 21:56:48 +0000 Subject: [PATCH] (svn r25988) [1.3] -Backport from trunk: - Fix: Center the edit sign window like all query windows (r25918) - Fix: Initialization of default objects swapped cost and dates (r25868) - Fix: Use the actual sprite dimensions for sizing the dropdown arrow of dropdown widgets (r25864) - Fix: If the child widgets of a NWidgetHorizontal container do not fill the complete container, align them according to text direction [FS#5686] (r25862, r25729) --- src/newgrf_object.h | 5 ++++- src/settings_gui.cpp | 5 ++--- src/signs_gui.cpp | 2 +- src/table/object_land.h | 2 +- src/widget.cpp | 39 +++++++++++++++++++++++++-------------- src/widget_type.h | 2 ++ src/window_gui.h | 2 +- 7 files changed, 36 insertions(+), 21 deletions(-) diff --git a/src/newgrf_object.h b/src/newgrf_object.h index 4ccca97b8d..e8ce31d4d5 100644 --- a/src/newgrf_object.h +++ b/src/newgrf_object.h @@ -52,7 +52,10 @@ enum ObjectClassID { /** Allow incrementing of ObjectClassID variables */ DECLARE_POSTFIX_INCREMENT(ObjectClassID) -/** An object that isn't use for transport, industries or houses. */ +/** An object that isn't use for transport, industries or houses. + * @note If you change this struct, adopt the initialization of + * default objects in table/object_land.h + */ struct ObjectSpec { /* 2 because of the "normal" and "buy" sprite stacks. */ GRFFilePropsBase<2> grf_prop; ///< Properties related the the grf file diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 0b59174906..4eb20a3609 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -417,11 +417,10 @@ struct GameOptionsWindow : Window { if (list != NULL) { /* Find the biggest item for the default size. */ for (DropDownList::iterator it = list->begin(); it != list->end(); it++) { - static const Dimension extra = {WD_DROPDOWNTEXT_LEFT + WD_DROPDOWNTEXT_RIGHT, WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM}; Dimension string_dim; int width = (*it)->Width(); - string_dim.width = width + extra.width; - string_dim.height = (*it)->Height(width) + extra.height; + string_dim.width = width + padding.width; + string_dim.height = (*it)->Height(width) + padding.height; *size = maxdim(*size, string_dim); delete *it; } diff --git a/src/signs_gui.cpp b/src/signs_gui.cpp index d488aa3d5f..a52da12af8 100644 --- a/src/signs_gui.cpp +++ b/src/signs_gui.cpp @@ -532,7 +532,7 @@ static const NWidgetPart _nested_query_sign_edit_widgets[] = { }; static const WindowDesc _query_sign_edit_desc( - WDP_AUTO, 0, 0, + WDP_CENTER, 0, 0, WC_QUERY_STRING, WC_NONE, WDF_CONSTRUCTION, _nested_query_sign_edit_widgets, lengthof(_nested_query_sign_edit_widgets) diff --git a/src/table/object_land.h b/src/table/object_land.h index ed15a11bfe..685178ef7e 100644 --- a/src/table/object_land.h +++ b/src/table/object_land.h @@ -123,7 +123,7 @@ static const DrawTileSprites _object_hq[] = { #undef TILE_SPRITE_LINE -#define M(name, size, build_cost_multiplier, clear_cost_multiplier, height, flags) { GRFFilePropsBase<2>(), INVALID_OBJECT_CLASS, name, 0xF, size, 0, 0, build_cost_multiplier, clear_cost_multiplier, flags, {0, 0, 0, 0}, 0, height, 1, true } +#define M(name, size, build_cost_multiplier, clear_cost_multiplier, height, flags) { GRFFilePropsBase<2>(), INVALID_OBJECT_CLASS, name, 0xF, size, build_cost_multiplier, clear_cost_multiplier, 0, 0, flags, {0, 0, 0, 0}, 0, height, 1, true } /** Specification of the original object structures. */ extern const ObjectSpec _original_objects[] = { diff --git a/src/widget.cpp b/src/widget.cpp index ed8921818e..2dd3d3cccf 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -541,16 +541,18 @@ static inline void DrawButtonDropdown(const Rect &r, Colours colour, bool clicke { int text_offset = max(0, ((int)(r.bottom - r.top + 1) - FONT_HEIGHT_NORMAL) / 2); // Offset for rendering the text vertically centered + int dd_width = NWidgetLeaf::dropdown_dimension.width; + if (_current_text_dir == TD_LTR) { - DrawFrameRect(r.left, r.top, r.right - 12, r.bottom, colour, clicked_button ? FR_LOWERED : FR_NONE); - DrawFrameRect(r.right - 11, r.top, r.right, r.bottom, colour, clicked_dropdown ? FR_LOWERED : FR_NONE); - DrawString(r.right - (clicked_dropdown ? 10 : 11), r.right, r.top + (clicked_dropdown ? 2 : 1), DOWNARROW, TC_BLACK, SA_HOR_CENTER); - if (str != STR_NULL) DrawString(r.left + WD_DROPDOWNTEXT_LEFT + clicked_button, r.right - WD_DROPDOWNTEXT_RIGHT + clicked_button, r.top + text_offset + clicked_button, str, TC_BLACK); + DrawFrameRect(r.left, r.top, r.right - dd_width, r.bottom, colour, clicked_button ? FR_LOWERED : FR_NONE); + DrawFrameRect(r.right + 1 - dd_width, r.top, r.right, r.bottom, colour, clicked_dropdown ? FR_LOWERED : FR_NONE); + DrawString(r.right - dd_width + (clicked_dropdown ? 2 : 1), r.right, r.top + (clicked_dropdown ? 2 : 1), DOWNARROW, TC_BLACK, SA_HOR_CENTER); + if (str != STR_NULL) DrawString(r.left + WD_DROPDOWNTEXT_LEFT + clicked_button, r.right - dd_width - WD_DROPDOWNTEXT_RIGHT + clicked_button, r.top + text_offset + clicked_button, str, TC_BLACK); } else { - DrawFrameRect(r.left + 12, r.top, r.right, r.bottom, colour, clicked_button ? FR_LOWERED : FR_NONE); - DrawFrameRect(r.left, r.top, r.left + 11, r.bottom, colour, clicked_dropdown ? FR_LOWERED : FR_NONE); - DrawString(r.left + clicked_dropdown, r.left + 11, r.top + (clicked_dropdown ? 2 : 1), DOWNARROW, TC_BLACK, SA_HOR_CENTER); - if (str != STR_NULL) DrawString(r.left + WD_DROPDOWNTEXT_RIGHT + clicked_button, r.right - WD_DROPDOWNTEXT_LEFT + clicked_button, r.top + text_offset + clicked_button, str, TC_BLACK); + DrawFrameRect(r.left + dd_width, r.top, r.right, r.bottom, colour, clicked_button ? FR_LOWERED : FR_NONE); + DrawFrameRect(r.left, r.top, r.left + dd_width - 1, r.bottom, colour, clicked_dropdown ? FR_LOWERED : FR_NONE); + DrawString(r.left + (clicked_dropdown ? 2 : 1), r.left + dd_width, r.top + (clicked_dropdown ? 2 : 1), DOWNARROW, TC_BLACK, SA_HOR_CENTER); + if (str != STR_NULL) DrawString(r.left + dd_width + WD_DROPDOWNTEXT_LEFT + clicked_button, r.right - WD_DROPDOWNTEXT_RIGHT + clicked_button, r.top + text_offset + clicked_button, str, TC_BLACK); } } @@ -1221,17 +1223,18 @@ void NWidgetHorizontal::AssignSizePosition(SizingType sizing, uint x, uint y, ui assert(num_changing_childs == 0); /* Third loop: Compute position and call the child. */ - uint position = 0; // Place to put next child relative to origin of the container. - NWidgetBase *child_wid = rtl ? this->tail : this->head; + uint position = rtl ? this->current_x : 0; // Place to put next child relative to origin of the container. + NWidgetBase *child_wid = this->head; while (child_wid != NULL) { uint child_width = child_wid->current_x; - uint child_x = x + position + (rtl ? child_wid->padding_right : child_wid->padding_left); + uint child_x = x + (rtl ? position - child_width - child_wid->padding_left : position + child_wid->padding_left); uint child_y = y + child_wid->padding_top; child_wid->AssignSizePosition(sizing, child_x, child_y, child_width, child_wid->current_y, rtl); - position += child_width + child_wid->padding_right + child_wid->padding_left; + uint padded_child_width = child_width + child_wid->padding_right + child_wid->padding_left; + position = rtl ? position - padded_child_width : position + padded_child_width; - child_wid = rtl ? child_wid->prev : child_wid->next; + child_wid = child_wid->next; } } @@ -2039,6 +2042,7 @@ Dimension NWidgetScrollbar::horizontal_dimension = {0, 0}; stickybox_dimension.width = stickybox_dimension.height = 0; resizebox_dimension.width = resizebox_dimension.height = 0; closebox_dimension.width = closebox_dimension.height = 0; + dropdown_dimension.width = dropdown_dimension.height = 0; } Dimension NWidgetLeaf::shadebox_dimension = {0, 0}; @@ -2046,6 +2050,7 @@ Dimension NWidgetLeaf::debugbox_dimension = {0, 0}; Dimension NWidgetLeaf::stickybox_dimension = {0, 0}; Dimension NWidgetLeaf::resizebox_dimension = {0, 0}; Dimension NWidgetLeaf::closebox_dimension = {0, 0}; +Dimension NWidgetLeaf::dropdown_dimension = {0, 0}; /** * Nested leaf widget. @@ -2286,8 +2291,14 @@ void NWidgetLeaf::SetupSmallestSize(Window *w, bool init_array) case WWT_DROPDOWN: case NWID_BUTTON_DROPDOWN: case NWID_PUSHBUTTON_DROPDOWN: { - static const Dimension extra = {WD_DROPDOWNTEXT_LEFT + WD_DROPDOWNTEXT_RIGHT, WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM}; + static Dimension extra = {WD_DROPDOWNTEXT_LEFT + WD_DROPDOWNTEXT_RIGHT, WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM}; padding = &extra; + if (NWidgetLeaf::dropdown_dimension.width == 0) { + NWidgetLeaf::dropdown_dimension = GetSpriteSize(SPR_ARROW_DOWN); + NWidgetLeaf::dropdown_dimension.width += WD_DROPDOWNTEXT_LEFT + WD_DROPDOWNTEXT_RIGHT; + NWidgetLeaf::dropdown_dimension.height += WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM; + extra.width = WD_DROPDOWNTEXT_LEFT + WD_DROPDOWNTEXT_RIGHT + NWidgetLeaf::dropdown_dimension.width; + } if (this->index >= 0) w->SetStringParameters(this->index); Dimension d2 = GetStringBoundingBox(this->widget_data); d2.width += extra.width; diff --git a/src/widget_type.h b/src/widget_type.h index eed23f0089..69f7d28f85 100644 --- a/src/widget_type.h +++ b/src/widget_type.h @@ -775,6 +775,8 @@ public: bool ButtonHit(const Point &pt); static void InvalidateDimensionCache(); + + static Dimension dropdown_dimension; ///< Cached size of a dropdown widget. private: static Dimension shadebox_dimension; ///< Cached size of a shadebox widget. static Dimension debugbox_dimension; ///< Cached size of a debugbox widget. diff --git a/src/window_gui.h b/src/window_gui.h index bcb06d6036..86fb802b1b 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -131,7 +131,7 @@ enum WidgetDrawDistances { /* Dropdown widget. */ WD_DROPDOWN_HEIGHT = 12, ///< Height of a drop down widget. WD_DROPDOWNTEXT_LEFT = 2, ///< Left offset of the dropdown widget string. - WD_DROPDOWNTEXT_RIGHT = 14, ///< Right offset of the dropdown widget string. + WD_DROPDOWNTEXT_RIGHT = 2, ///< Right offset of the dropdown widget string. WD_DROPDOWNTEXT_TOP = 1, ///< Top offset of the dropdown widget string. WD_DROPDOWNTEXT_BOTTOM = 1, ///< Bottom offset of the dropdown widget string.