summaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/settings_gui.cpp5
-rw-r--r--src/story_gui.cpp4
-rw-r--r--src/widget.cpp28
-rw-r--r--src/widget_type.h2
-rw-r--r--src/window_gui.h2
5 files changed, 26 insertions, 15 deletions
diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp
index efd958095..abeb78a31 100644
--- a/src/settings_gui.cpp
+++ b/src/settings_gui.cpp
@@ -393,11 +393,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/story_gui.cpp b/src/story_gui.cpp
index defbb6449..7a23dec7d 100644
--- a/src/story_gui.cpp
+++ b/src/story_gui.cpp
@@ -585,8 +585,8 @@ public:
}
}
- d.width += padding.width + WD_DROPDOWNTEXT_LEFT + WD_DROPDOWNTEXT_RIGHT;
- d.height += padding.height + WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM;
+ d.width += padding.width;
+ d.height += padding.height;
*size = maxdim(*size, d);
break;
}
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;
diff --git a/src/widget_type.h b/src/widget_type.h
index 60980f28c..6d8b32bc9 100644
--- a/src/widget_type.h
+++ b/src/widget_type.h
@@ -777,6 +777,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 b6b994d52..bf8500f0f 100644
--- a/src/window_gui.h
+++ b/src/window_gui.h
@@ -132,7 +132,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.