summaryrefslogtreecommitdiff
path: root/src/widget.cpp
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2014-10-05 11:20:02 +0000
committerpeter1138 <peter1138@openttd.org>2014-10-05 11:20:02 +0000
commit0877f892c5a3dbffef8f482c9b0c35bd41f77cee (patch)
treebf50e6f3cb9bf2641df1a56f1001b3688e41a5a9 /src/widget.cpp
parent42c65264f8dd60805b6a42a495ea446332f13b16 (diff)
downloadopenttd-0877f892c5a3dbffef8f482c9b0c35bd41f77cee.tar.xz
(svn r26960) -Codechange: Draw sort button symbols as sprites, and pad sort buttons with non-static width.
Diffstat (limited to 'src/widget.cpp')
-rw-r--r--src/widget.cpp20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/widget.cpp b/src/widget.cpp
index a1bd7a3c7..2bd060535 100644
--- a/src/widget.cpp
+++ b/src/widget.cpp
@@ -26,9 +26,6 @@
#include "safeguards.h"
-static const char *UPARROW = "\xEE\x8A\xA0"; ///< String containing an upwards pointing arrow.
-static const char *DOWNARROW = "\xEE\x8A\xAA"; ///< String containing a downwards pointing arrow.
-
/**
* Compute the vertical position of the draggable part of scrollbar
* @param sb Scrollbar list data
@@ -644,11 +641,22 @@ void Window::DrawSortButtonState(int widget, SortButtonState state) const
assert(this->nested_array != NULL);
const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(widget);
+ /* Sort button uses the same sprites as vertical scrollbar */
+ Dimension dim = NWidgetScrollbar::GetVerticalDimension();
int offset = this->IsWidgetLowered(widget) ? 1 : 0;
- int base = offset + nwid->pos_x + (_current_text_dir == TD_LTR ? nwid->current_x - WD_SORTBUTTON_ARROW_WIDTH : 0);
- int top = nwid->pos_y;
+ int x = offset + nwid->pos_x + (_current_text_dir == TD_LTR ? nwid->current_x - dim.width : 0);
+ int y = offset + nwid->pos_y + (nwid->current_y - dim.height) / 2;
+
+ DrawSprite(state == SBS_DOWN ? SPR_ARROW_DOWN : SPR_ARROW_UP, PAL_NONE, x, y);
+}
- DrawString(base, base + WD_SORTBUTTON_ARROW_WIDTH, top + 1 + offset, state == SBS_DOWN ? DOWNARROW : UPARROW, TC_BLACK, SA_HOR_CENTER);
+/**
+ * Get width of up/down arrow of sort button state.
+ * @return Width of space required by sort button arrow.
+ */
+int Window::SortButtonWidth()
+{
+ return NWidgetScrollbar::GetVerticalDimension().width + 1;
}