mirror of https://github.com/OpenTTD/OpenTTD
(svn r26960) -Codechange: Draw sort button symbols as sprites, and pad sort buttons with non-static width.
parent
42c65264f8
commit
0877f892c5
|
@ -259,7 +259,7 @@ public:
|
||||||
switch (widget) {
|
switch (widget) {
|
||||||
case WID_RV_SORT_ASCENDING_DESCENDING: {
|
case WID_RV_SORT_ASCENDING_DESCENDING: {
|
||||||
Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
|
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;
|
d.height += padding.height;
|
||||||
*size = maxdim(*size, d);
|
*size = maxdim(*size, d);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -168,7 +168,7 @@ public:
|
||||||
switch (widget) {
|
switch (widget) {
|
||||||
case WID_BBS_DROPDOWN_ORDER: {
|
case WID_BBS_DROPDOWN_ORDER: {
|
||||||
Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
|
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;
|
d.height += padding.height;
|
||||||
*size = maxdim(*size, d);
|
*size = maxdim(*size, d);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1391,7 +1391,7 @@ struct BuildVehicleWindow : Window {
|
||||||
|
|
||||||
case WID_BV_SORT_ASCENDING_DESCENDING: {
|
case WID_BV_SORT_ASCENDING_DESCENDING: {
|
||||||
Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
|
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;
|
d.height += padding.height;
|
||||||
*size = maxdim(*size, d);
|
*size = maxdim(*size, d);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -483,7 +483,7 @@ public:
|
||||||
case WID_SL_SORT_BYNAME:
|
case WID_SL_SORT_BYNAME:
|
||||||
case WID_SL_SORT_BYDATE: {
|
case WID_SL_SORT_BYDATE: {
|
||||||
Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
|
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;
|
d.height += padding.height;
|
||||||
*size = maxdim(*size, d);
|
*size = maxdim(*size, d);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -384,7 +384,7 @@ public:
|
||||||
|
|
||||||
case WID_GL_SORT_BY_ORDER: {
|
case WID_GL_SORT_BY_ORDER: {
|
||||||
Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
|
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;
|
d.height += padding.height;
|
||||||
*size = maxdim(*size, d);
|
*size = maxdim(*size, d);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1283,7 +1283,7 @@ public:
|
||||||
switch (widget) {
|
switch (widget) {
|
||||||
case WID_ID_DROPDOWN_ORDER: {
|
case WID_ID_DROPDOWN_ORDER: {
|
||||||
Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
|
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;
|
d.height += padding.height;
|
||||||
*size = maxdim(*size, d);
|
*size = maxdim(*size, d);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -523,11 +523,11 @@ public:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_NG_NAME:
|
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;
|
break;
|
||||||
|
|
||||||
case WID_NG_CLIENTS:
|
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(0, MAX_CLIENTS);
|
||||||
SetDParamMaxValue(1, MAX_CLIENTS);
|
SetDParamMaxValue(1, MAX_CLIENTS);
|
||||||
SetDParamMaxValue(2, MAX_COMPANIES);
|
SetDParamMaxValue(2, MAX_COMPANIES);
|
||||||
|
@ -536,7 +536,7 @@ public:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WID_NG_MAPSIZE:
|
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(0, MAX_MAP_SIZE);
|
||||||
SetDParamMaxValue(1, MAX_MAP_SIZE);
|
SetDParamMaxValue(1, MAX_MAP_SIZE);
|
||||||
*size = maxdim(*size, GetStringBoundingBox(STR_NETWORK_SERVER_LIST_MAP_SIZE_SHORT));
|
*size = maxdim(*size, GetStringBoundingBox(STR_NETWORK_SERVER_LIST_MAP_SIZE_SHORT));
|
||||||
|
@ -544,7 +544,7 @@ public:
|
||||||
|
|
||||||
case WID_NG_DATE:
|
case WID_NG_DATE:
|
||||||
case WID_NG_YEARS:
|
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);
|
SetDParamMaxValue(0, 5);
|
||||||
*size = maxdim(*size, GetStringBoundingBox(STR_JUST_INT));
|
*size = maxdim(*size, GetStringBoundingBox(STR_JUST_INT));
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -339,7 +339,7 @@ public:
|
||||||
switch (widget) {
|
switch (widget) {
|
||||||
case WID_STL_SORTBY: {
|
case WID_STL_SORTBY: {
|
||||||
Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
|
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;
|
d.height += padding.height;
|
||||||
*size = maxdim(*size, d);
|
*size = maxdim(*size, d);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -797,7 +797,7 @@ public:
|
||||||
switch (widget) {
|
switch (widget) {
|
||||||
case WID_TD_SORT_ORDER: {
|
case WID_TD_SORT_ORDER: {
|
||||||
Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
|
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;
|
d.height += padding.height;
|
||||||
*size = maxdim(*size, d);
|
*size = maxdim(*size, d);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1486,7 +1486,7 @@ public:
|
||||||
|
|
||||||
case WID_VL_SORT_ORDER: {
|
case WID_VL_SORT_ORDER: {
|
||||||
Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
|
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;
|
d.height += padding.height;
|
||||||
*size = maxdim(*size, d);
|
*size = maxdim(*size, d);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -26,9 +26,6 @@
|
||||||
|
|
||||||
#include "safeguards.h"
|
#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
|
* Compute the vertical position of the draggable part of scrollbar
|
||||||
* @param sb Scrollbar list data
|
* @param sb Scrollbar list data
|
||||||
|
@ -644,11 +641,22 @@ void Window::DrawSortButtonState(int widget, SortButtonState state) const
|
||||||
assert(this->nested_array != NULL);
|
assert(this->nested_array != NULL);
|
||||||
const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(widget);
|
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 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 x = offset + nwid->pos_x + (_current_text_dir == TD_LTR ? nwid->current_x - dim.width : 0);
|
||||||
int top = nwid->pos_y;
|
int y = offset + nwid->pos_y + (nwid->current_y - dim.height) / 2;
|
||||||
|
|
||||||
DrawString(base, base + WD_SORTBUTTON_ARROW_WIDTH, top + 1 + offset, state == SBS_DOWN ? DOWNARROW : UPARROW, TC_BLACK, SA_HOR_CENTER);
|
DrawSprite(state == SBS_DOWN ? SPR_ARROW_DOWN : SPR_ARROW_UP, PAL_NONE, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -136,8 +136,6 @@ enum WidgetDrawDistances {
|
||||||
WD_DROPDOWNTEXT_TOP = 1, ///< Top 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.
|
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_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.
|
WD_PAR_VSEP_WIDE = 8, ///< Large amount of vertical space between two paragraphs of text.
|
||||||
};
|
};
|
||||||
|
@ -509,6 +507,7 @@ public:
|
||||||
void DrawWidgets() const;
|
void DrawWidgets() const;
|
||||||
void DrawViewport() const;
|
void DrawViewport() const;
|
||||||
void DrawSortButtonState(int widget, SortButtonState state) const;
|
void DrawSortButtonState(int widget, SortButtonState state) const;
|
||||||
|
static int SortButtonWidth();
|
||||||
|
|
||||||
void DeleteChildWindows(WindowClass wc = WC_INVALID) const;
|
void DeleteChildWindows(WindowClass wc = WC_INVALID) const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue