summaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/autoreplace_gui.cpp2
-rw-r--r--src/bridge_gui.cpp2
-rw-r--r--src/build_vehicle_gui.cpp2
-rw-r--r--src/fios_gui.cpp2
-rw-r--r--src/group_gui.cpp2
-rw-r--r--src/industry_gui.cpp2
-rw-r--r--src/network/network_gui.cpp8
-rw-r--r--src/station_gui.cpp2
-rw-r--r--src/town_gui.cpp2
-rw-r--r--src/vehicle_gui.cpp2
-rw-r--r--src/widget.cpp20
-rw-r--r--src/window_gui.h3
12 files changed, 28 insertions, 21 deletions
diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp
index a558724a9..691042a1d 100644
--- a/src/autoreplace_gui.cpp
+++ b/src/autoreplace_gui.cpp
@@ -259,7 +259,7 @@ public:
switch (widget) {
case WID_RV_SORT_ASCENDING_DESCENDING: {
Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
- d.width += padding.width + WD_SORTBUTTON_ARROW_WIDTH * 2; // Doubled since the string is centred and it also looks better.
+ d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
d.height += padding.height;
*size = maxdim(*size, d);
break;
diff --git a/src/bridge_gui.cpp b/src/bridge_gui.cpp
index 95c9d7137..797ead1f5 100644
--- a/src/bridge_gui.cpp
+++ b/src/bridge_gui.cpp
@@ -168,7 +168,7 @@ public:
switch (widget) {
case WID_BBS_DROPDOWN_ORDER: {
Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
- d.width += padding.width + WD_SORTBUTTON_ARROW_WIDTH * 2; // Doubled since the string is centred and it also looks better.
+ d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
d.height += padding.height;
*size = maxdim(*size, d);
break;
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp
index c71b49f3b..bd4bf3b59 100644
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -1391,7 +1391,7 @@ struct BuildVehicleWindow : Window {
case WID_BV_SORT_ASCENDING_DESCENDING: {
Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
- d.width += padding.width + WD_SORTBUTTON_ARROW_WIDTH * 2; // Doubled since the string is centred and it also looks better.
+ d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
d.height += padding.height;
*size = maxdim(*size, d);
break;
diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp
index 14c335e94..9316deb65 100644
--- a/src/fios_gui.cpp
+++ b/src/fios_gui.cpp
@@ -483,7 +483,7 @@ public:
case WID_SL_SORT_BYNAME:
case WID_SL_SORT_BYDATE: {
Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
- d.width += padding.width + WD_SORTBUTTON_ARROW_WIDTH * 2; // Doubled since the string is centred and it also looks better.
+ d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
d.height += padding.height;
*size = maxdim(*size, d);
break;
diff --git a/src/group_gui.cpp b/src/group_gui.cpp
index c332c934d..06f56b950 100644
--- a/src/group_gui.cpp
+++ b/src/group_gui.cpp
@@ -384,7 +384,7 @@ public:
case WID_GL_SORT_BY_ORDER: {
Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
- d.width += padding.width + WD_SORTBUTTON_ARROW_WIDTH * 2; // Doubled since the string is centred and it also looks better.
+ d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
d.height += padding.height;
*size = maxdim(*size, d);
break;
diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp
index 605c7bc60..47ca4fd21 100644
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -1283,7 +1283,7 @@ public:
switch (widget) {
case WID_ID_DROPDOWN_ORDER: {
Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
- d.width += padding.width + WD_SORTBUTTON_ARROW_WIDTH * 2; // Doubled since the string is centred and it also looks better.
+ d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
d.height += padding.height;
*size = maxdim(*size, d);
break;
diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp
index 1a027cb62..3a36f146c 100644
--- a/src/network/network_gui.cpp
+++ b/src/network/network_gui.cpp
@@ -523,11 +523,11 @@ public:
break;
case WID_NG_NAME:
- size->width += 2 * WD_SORTBUTTON_ARROW_WIDTH; // Make space for the arrow
+ size->width += 2 * Window::SortButtonWidth(); // Make space for the arrow
break;
case WID_NG_CLIENTS:
- size->width += 2 * WD_SORTBUTTON_ARROW_WIDTH; // Make space for the arrow
+ size->width += 2 * Window::SortButtonWidth(); // Make space for the arrow
SetDParamMaxValue(0, MAX_CLIENTS);
SetDParamMaxValue(1, MAX_CLIENTS);
SetDParamMaxValue(2, MAX_COMPANIES);
@@ -536,7 +536,7 @@ public:
break;
case WID_NG_MAPSIZE:
- size->width += 2 * WD_SORTBUTTON_ARROW_WIDTH; // Make space for the arrow
+ size->width += 2 * Window::SortButtonWidth(); // Make space for the arrow
SetDParamMaxValue(0, MAX_MAP_SIZE);
SetDParamMaxValue(1, MAX_MAP_SIZE);
*size = maxdim(*size, GetStringBoundingBox(STR_NETWORK_SERVER_LIST_MAP_SIZE_SHORT));
@@ -544,7 +544,7 @@ public:
case WID_NG_DATE:
case WID_NG_YEARS:
- size->width += 2 * WD_SORTBUTTON_ARROW_WIDTH; // Make space for the arrow
+ size->width += 2 * Window::SortButtonWidth(); // Make space for the arrow
SetDParamMaxValue(0, 5);
*size = maxdim(*size, GetStringBoundingBox(STR_JUST_INT));
break;
diff --git a/src/station_gui.cpp b/src/station_gui.cpp
index a6fc67c88..12c22e1af 100644
--- a/src/station_gui.cpp
+++ b/src/station_gui.cpp
@@ -339,7 +339,7 @@ public:
switch (widget) {
case WID_STL_SORTBY: {
Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
- d.width += padding.width + WD_SORTBUTTON_ARROW_WIDTH * 2; // Doubled since the string is centred and it also looks better.
+ d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
d.height += padding.height;
*size = maxdim(*size, d);
break;
diff --git a/src/town_gui.cpp b/src/town_gui.cpp
index 2d9be9359..6ae37d71a 100644
--- a/src/town_gui.cpp
+++ b/src/town_gui.cpp
@@ -797,7 +797,7 @@ public:
switch (widget) {
case WID_TD_SORT_ORDER: {
Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
- d.width += padding.width + WD_SORTBUTTON_ARROW_WIDTH * 2; // Doubled since the string is centred and it also looks better.
+ d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
d.height += padding.height;
*size = maxdim(*size, d);
break;
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index 3d122ff6a..10f2cfe39 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -1486,7 +1486,7 @@ public:
case WID_VL_SORT_ORDER: {
Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
- d.width += padding.width + WD_SORTBUTTON_ARROW_WIDTH * 2; // Doubled since the string is centred and it also looks better.
+ d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
d.height += padding.height;
*size = maxdim(*size, d);
break;
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;
}
diff --git a/src/window_gui.h b/src/window_gui.h
index bf8500f0f..e3314d12b 100644
--- a/src/window_gui.h
+++ b/src/window_gui.h
@@ -136,8 +136,6 @@ enum WidgetDrawDistances {
WD_DROPDOWNTEXT_TOP = 1, ///< Top offset of the dropdown widget string.
WD_DROPDOWNTEXT_BOTTOM = 1, ///< Bottom offset of the dropdown widget string.
- WD_SORTBUTTON_ARROW_WIDTH = 11, ///< Width of up/down arrow of sort button state.
-
WD_PAR_VSEP_NORMAL = 2, ///< Normal amount of vertical space between two paragraphs of text.
WD_PAR_VSEP_WIDE = 8, ///< Large amount of vertical space between two paragraphs of text.
};
@@ -509,6 +507,7 @@ public:
void DrawWidgets() const;
void DrawViewport() const;
void DrawSortButtonState(int widget, SortButtonState state) const;
+ static int SortButtonWidth();
void DeleteChildWindows(WindowClass wc = WC_INVALID) const;