diff options
author | peter1138 <peter1138@openttd.org> | 2008-01-18 10:36:55 +0000 |
---|---|---|
committer | peter1138 <peter1138@openttd.org> | 2008-01-18 10:36:55 +0000 |
commit | 68707808c015db1cda0723882ffce99977d4593c (patch) | |
tree | 4a7f2fbd16bbc5ad48c890141c722273c2efea2e | |
parent | b7f50533c29ea74e9973ac641ec677eb69411d5d (diff) | |
download | openttd-68707808c015db1cda0723882ffce99977d4593c.tar.xz |
(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.
-rw-r--r-- | src/build_vehicle_gui.cpp | 2 | ||||
-rw-r--r-- | src/gfx_func.h | 6 | ||||
-rw-r--r-- | src/group_gui.cpp | 4 | ||||
-rw-r--r-- | src/industry_gui.cpp | 10 | ||||
-rw-r--r-- | src/misc_gui.cpp | 6 | ||||
-rw-r--r-- | src/network/network_gui.cpp | 8 | ||||
-rw-r--r-- | src/station_gui.cpp | 2 | ||||
-rw-r--r-- | src/town_gui.cpp | 2 | ||||
-rw-r--r-- | src/vehicle_gui.cpp | 2 | ||||
-rw-r--r-- | src/widget.cpp | 16 | ||||
-rw-r--r-- | src/window_gui.h | 8 |
11 files changed, 38 insertions, 28 deletions
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index 4b1dfda3d..0cbdf8338 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -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) diff --git a/src/gfx_func.h b/src/gfx_func.h index a4033caed..fd6af565e 100644 --- a/src/gfx_func.h +++ b/src/gfx_func.h @@ -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); diff --git a/src/group_gui.cpp b/src/group_gui.cpp index 515ccf77a..28dca4663 100644 --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -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]; diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index b4621df00..393fd114c 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -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]; diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index f32a9902b..8ef6d5f3f 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -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++) { diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 022a0dabd..7ee613cd1 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -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 diff --git a/src/station_gui.cpp b/src/station_gui.cpp index 71d1fdd3c..24cf2ece3 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -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; diff --git a/src/town_gui.cpp b/src/town_gui.cpp index 828a722a5..4fdc9c169 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -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; diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 2e4c666d4..bba67dd13 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -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) { diff --git a/src/widget.cpp b/src/widget.cpp index 9cb767149..d13352f77 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -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); +} diff --git a/src/window_gui.h b/src/window_gui.h index 70deb5512..e8f5d7e7a 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -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(); |