mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-11 01:49:50 +00:00
(svn r11915) -Codechange: Add a function to draw a sort button's up/down arrow. Arrows are now drawn in a consistent position based on the widget, instead of randomly positioned by pixel.
This commit is contained in:
parent
b7f50533c2
commit
68707808c0
@ -995,7 +995,7 @@ static void DrawBuildVehicleWindow(Window *w)
|
||||
if (text_end > wi->bottom) ExpandPurchaseInfoWidget(w, text_end - wi->bottom);
|
||||
}
|
||||
|
||||
DoDrawString(bv->descending_sort_order ? DOWNARROW : UPARROW, 69, 15, TC_BLACK);
|
||||
DrawSortButtonState(w, BUILD_VEHICLE_WIDGET_SORT_ASSENDING_DESCENDING, bv->descending_sort_order ? SBS_DOWN : SBS_UP);
|
||||
}
|
||||
|
||||
static void BuildVehicleClickEvent(Window *w, WindowEvent *e)
|
||||
|
@ -83,12 +83,6 @@ void GfxScroll(int left, int top, int width, int height, int xo, int yo);
|
||||
|
||||
void DrawSprite(SpriteID img, SpriteID pal, int x, int y, const SubSprite *sub = NULL);
|
||||
|
||||
/* XXX doesn't really belong here, but the only
|
||||
* consumers always use it in conjunction with DoDrawString() */
|
||||
#define UPARROW "\xEE\x8A\x80"
|
||||
#define DOWNARROW "\xEE\x8A\xAA"
|
||||
|
||||
|
||||
int DrawStringCentered(int x, int y, StringID str, uint16 color);
|
||||
int DrawStringCenteredTruncated(int xl, int xr, int y, StringID str, uint16 color);
|
||||
int DoDrawStringCentered(int x, int y, const char *str, uint16 color);
|
||||
|
@ -466,9 +466,9 @@ static void GroupWndProc(Window *w, WindowEvent *e)
|
||||
DrawStringRightAligned(187, y1 + 1, STR_GROUP_TINY_NUM, (gv->group_sel == g->index) ? TC_WHITE : TC_BLACK);
|
||||
}
|
||||
|
||||
/* Draw Matrix Vehicle according to the vehicle list built before */
|
||||
DoDrawString(gv->l.flags & VL_DESC ? DOWNARROW : UPARROW, 269, 15, TC_BLACK);
|
||||
DrawSortButtonState(w, GRP_WIDGET_SORT_BY_ORDER, gv->l.flags & VL_DESC ? SBS_DOWN : SBS_UP);
|
||||
|
||||
/* Draw Matrix Vehicle according to the vehicle list built before */
|
||||
max = min(w->vscroll2.pos + w->vscroll2.cap, gv->l.list_length);
|
||||
for (i = w->vscroll2.pos ; i < max ; ++i) {
|
||||
const Vehicle* v = gv->sort_list[i];
|
||||
|
@ -781,10 +781,6 @@ static void IndustryDirectoryWndProc(Window *w, WindowEvent *e)
|
||||
{
|
||||
switch (e->event) {
|
||||
case WE_PAINT: {
|
||||
int n;
|
||||
uint p;
|
||||
static const uint16 _indicator_positions[4] = {88, 187, 284, 387};
|
||||
|
||||
if (_industry_sort_dirty) {
|
||||
_industry_sort_dirty = false;
|
||||
MakeSortedIndustryList();
|
||||
@ -793,10 +789,10 @@ static void IndustryDirectoryWndProc(Window *w, WindowEvent *e)
|
||||
SetVScrollCount(w, _num_industry_sort);
|
||||
|
||||
DrawWindowWidgets(w);
|
||||
DoDrawString(_industry_sort_order & 1 ? DOWNARROW : UPARROW, _indicator_positions[_industry_sort_order >> 1], 15, TC_BLACK);
|
||||
DrawSortButtonState(w, IDW_SORTBYNAME + (_industry_sort_order >> 1), _industry_sort_order & 1 ? SBS_DOWN : SBS_UP);
|
||||
|
||||
p = w->vscroll.pos;
|
||||
n = 0;
|
||||
uint p = w->vscroll.pos;
|
||||
int n = 0;
|
||||
|
||||
while (p < _num_industry_sort) {
|
||||
const Industry* i = _industry_sort[p];
|
||||
|
@ -1505,11 +1505,7 @@ static void SaveLoadDlgWndProc(Window *w, WindowEvent *e)
|
||||
}
|
||||
|
||||
GfxFillRect(w->widget[7].left + 1, w->widget[7].top + 1, w->widget[7].right, w->widget[7].bottom, 0xD7);
|
||||
DoDrawString(
|
||||
_savegame_sort_order & SORT_DESCENDING ? DOWNARROW : UPARROW,
|
||||
_savegame_sort_order & SORT_BY_NAME ? w->widget[2].right - 9 : w->widget[3].right - 9,
|
||||
15, TC_BLACK
|
||||
);
|
||||
DrawSortButtonState(w, _savegame_sort_order & SORT_BY_NAME ? 2 : 3, _savegame_sort_order & SORT_DESCENDING ? SBS_DOWN : SBS_UP);
|
||||
|
||||
y = w->widget[7].top + 1;
|
||||
for (pos = w->vscroll.pos; pos < _fios_num; pos++) {
|
||||
|
@ -268,7 +268,7 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
|
||||
|
||||
case WE_PAINT: {
|
||||
const NetworkGameList *sel = nd->server;
|
||||
const char *arrow = (ld->flags & VL_DESC) ? DOWNARROW : UPARROW;
|
||||
const SortButtonState arrow = (ld->flags & VL_DESC) ? SBS_DOWN : SBS_UP;
|
||||
|
||||
if (ld->flags & VL_REBUILD) {
|
||||
BuildNetworkGameList(&WP(w, network_ql_d));
|
||||
@ -300,9 +300,9 @@ static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
|
||||
|
||||
/* Sort based on widgets: name, clients, compatibility */
|
||||
switch (ld->sort_type) {
|
||||
case NGWW_NAME - NGWW_NAME: DoDrawString(arrow, w->widget[NGWW_NAME].right - 10, 42, TC_BLACK); break;
|
||||
case NGWW_CLIENTS - NGWW_NAME: DoDrawString(arrow, w->widget[NGWW_CLIENTS].right - 10, 42, TC_BLACK); break;
|
||||
case NGWW_INFO - NGWW_NAME: DoDrawString(arrow, w->widget[NGWW_INFO].right - 10, 42, TC_BLACK); break;
|
||||
case NGWW_NAME - NGWW_NAME: DrawSortButtonState(w, NGWW_NAME, arrow); break;
|
||||
case NGWW_CLIENTS - NGWW_NAME: DrawSortButtonState(w, NGWW_CLIENTS, arrow); break;
|
||||
case NGWW_INFO - NGWW_NAME: DrawSortButtonState(w, NGWW_INFO, arrow); break;
|
||||
}
|
||||
|
||||
{ // draw list of games
|
||||
|
@ -344,7 +344,7 @@ static void PlayerStationsWndProc(Window *w, WindowEvent *e)
|
||||
DrawWindowWidgets(w);
|
||||
|
||||
/* draw arrow pointing up/down for ascending/descending sorting */
|
||||
DoDrawString(sl->flags & SL_ORDER ? DOWNARROW : UPARROW, 69, 26, TC_BLACK);
|
||||
DrawSortButtonState(w, SLW_SORTBY, sl->flags & SL_ORDER ? SBS_DOWN : SBS_UP);
|
||||
|
||||
int cg_ofst;
|
||||
int x = 89;
|
||||
|
@ -478,7 +478,7 @@ static void TownDirectoryWndProc(Window *w, WindowEvent *e)
|
||||
SetVScrollCount(w, _num_town_sort);
|
||||
|
||||
DrawWindowWidgets(w);
|
||||
DoDrawString(_town_sort_order & 1 ? DOWNARROW : UPARROW, (_town_sort_order <= 1) ? 88 : 187, 15, TC_BLACK);
|
||||
DrawSortButtonState(w, (_town_sort_order <= 1) ? 3 : 4, _town_sort_order & 1 ? SBS_DOWN : SBS_UP);
|
||||
|
||||
{
|
||||
int n = 0;
|
||||
|
@ -988,7 +988,7 @@ static void DrawVehicleListWindow(Window *w)
|
||||
/* draw sorting criteria string */
|
||||
DrawString(85, 15, _vehicle_sort_listing[vl->l.sort_type], TC_BLACK);
|
||||
/* draw arrow pointing up/down for ascending/descending sorting */
|
||||
DoDrawString(vl->l.flags & VL_DESC ? DOWNARROW : UPARROW, 69, 15, TC_BLACK);
|
||||
DrawSortButtonState(w, VLW_WIDGET_SORT_ORDER, vl->l.flags & VL_DESC ? SBS_DOWN : SBS_UP);
|
||||
|
||||
max = min(w->vscroll.pos + w->vscroll.cap, vl->l.list_length);
|
||||
for (i = w->vscroll.pos; i < max; ++i) {
|
||||
|
@ -14,6 +14,9 @@
|
||||
#include "table/sprites.h"
|
||||
#include "table/strings.h"
|
||||
|
||||
static const char *UPARROW = "\xEE\x8A\x80";
|
||||
static const char *DOWNARROW = "\xEE\x8A\xAA";
|
||||
|
||||
static Point HandleScrollbarHittest(const Scrollbar *sb, int top, int bottom)
|
||||
{
|
||||
Point pt;
|
||||
@ -579,3 +582,16 @@ void ResizeButtons(Window *w, byte left, byte right)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Draw a sort button's up or down arrow symbol.
|
||||
* @param w Window of widget
|
||||
* @param widget Sort button widget
|
||||
* @param state State of sort button
|
||||
*/
|
||||
void DrawSortButtonState(const Window *w, int widget, SortButtonState state)
|
||||
{
|
||||
if (state == SBS_OFF) return;
|
||||
|
||||
int offset = w->IsWidgetLowered(widget) ? 1 : 0;
|
||||
DoDrawString(state == SBS_DOWN ? DOWNARROW : UPARROW, w->widget[widget].right - 11 + offset, w->widget[widget].top + 1 + offset, TC_BLACK);
|
||||
}
|
||||
|
@ -581,6 +581,14 @@ static inline void GuiShowTooltips(StringID str)
|
||||
int GetWidgetFromPos(const Window *w, int x, int y);
|
||||
void DrawWindowWidgets(const Window *w);
|
||||
|
||||
enum SortButtonState {
|
||||
SBS_OFF,
|
||||
SBS_DOWN,
|
||||
SBS_UP,
|
||||
};
|
||||
|
||||
void DrawSortButtonState(const Window *w, int widget, SortButtonState state);
|
||||
|
||||
|
||||
Window *GetCallbackWnd();
|
||||
void DeleteNonVitalWindows();
|
||||
|
Loading…
Reference in New Issue
Block a user