summaryrefslogtreecommitdiff
path: root/src/widget.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2013-10-13 19:18:30 +0000
committerfrosch <frosch@openttd.org>2013-10-13 19:18:30 +0000
commit12ddbb7cb11ddeba47a6bed8d36bef6432aa3236 (patch)
treeec386d7d837736fbff2d859be90eb5686b4a5e46 /src/widget.cpp
parentd9717c0b017a9783bab4793ac367a8a5d12bef5d (diff)
downloadopenttd-12ddbb7cb11ddeba47a6bed8d36bef6432aa3236.tar.xz
(svn r25864) -Fix: Use the actual sprite dimensions for sizing the dropdown arrow of dropdown widgets.
Diffstat (limited to 'src/widget.cpp')
-rw-r--r--src/widget.cpp28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/widget.cpp b/src/widget.cpp
index 6edcd1d74..839ee98ce 100644
--- a/src/widget.cpp
+++ b/src/widget.cpp
@@ -567,16 +567,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);
}
}
@@ -2066,6 +2068,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};
@@ -2074,6 +2077,7 @@ Dimension NWidgetLeaf::defsizebox_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.
@@ -2333,8 +2337,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;