Changeset - r8349:749dc2cf52de
[Not reviewed]
master
0 11 0
peter1138 - 16 years ago 2008-01-18 10:36:55
peter1138@openttd.org
(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.
11 files changed with 38 insertions and 28 deletions:
0 comments (0 inline, 0 general)
src/build_vehicle_gui.cpp
Show inline comments
 
@@ -995,7 +995,7 @@ static void DrawBuildVehicleWindow(Windo
 
		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)
src/gfx_func.h
Show inline comments
 
@@ -83,12 +83,6 @@ void GfxScroll(int left, int top, int wi
 

	
 
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);
src/group_gui.cpp
Show inline comments
 
@@ -466,9 +466,9 @@ static void GroupWndProc(Window *w, Wind
 
				DrawStringRightAligned(187, y1 + 1, STR_GROUP_TINY_NUM, (gv->group_sel == g->index) ? TC_WHITE : 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 */
 
			DoDrawString(gv->l.flags & VL_DESC ? DOWNARROW : UPARROW, 269, 15, TC_BLACK);
 

	
 
			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];
src/industry_gui.cpp
Show inline comments
 
@@ -781,10 +781,6 @@ static void IndustryDirectoryWndProc(Win
 
{
 
	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(Win
 
		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];
src/misc_gui.cpp
Show inline comments
 
@@ -1505,11 +1505,7 @@ static void SaveLoadDlgWndProc(Window *w
 
		}
 

	
 
		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++) {
src/network/network_gui.cpp
Show inline comments
 
@@ -268,7 +268,7 @@ static void NetworkGameWindowWndProc(Win
 

	
 
	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(Win
 

	
 
		/* 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
src/station_gui.cpp
Show inline comments
 
@@ -344,7 +344,7 @@ static void PlayerStationsWndProc(Window
 
			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;
src/town_gui.cpp
Show inline comments
 
@@ -478,7 +478,7 @@ static void TownDirectoryWndProc(Window 
 
		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;
src/vehicle_gui.cpp
Show inline comments
 
@@ -988,7 +988,7 @@ static void DrawVehicleListWindow(Window
 
	/* 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) {
src/widget.cpp
Show inline comments
 
@@ -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,
 
		}
 
	}
 
}
 

	
 
/** 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);
 
}
src/window_gui.h
Show inline comments
 
@@ -581,6 +581,14 @@ static inline void GuiShowTooltips(Strin
 
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();
0 comments (0 inline, 0 general)