Changeset - r12825:b76c82800d1a
[Not reviewed]
master
0 3 0
alberth - 15 years ago 2009-08-30 17:38:28
alberth@openttd.org
(svn r17325) -Codechange: Un-duplicate engine drawing routines.
3 files changed with 41 insertions and 20 deletions:
0 comments (0 inline, 0 general)
src/build_vehicle_gui.cpp
Show inline comments
 
@@ -703,17 +703,6 @@ int DrawVehiclePurchaseInfo(int left, in
 
	return y;
 
}
 

	
 
static void DrawVehicleEngine(VehicleType type, int x, int y, EngineID engine, SpriteID pal)
 
{
 
	switch (type) {
 
		case VEH_TRAIN:    DrawTrainEngine(   x, y, engine, pal); break;
 
		case VEH_ROAD:     DrawRoadVehEngine( x, y, engine, pal); break;
 
		case VEH_SHIP:     DrawShipEngine(    x, y, engine, pal); break;
 
		case VEH_AIRCRAFT: DrawAircraftEngine(x, y, engine, pal); break;
 
		default: NOT_REACHED();
 
	}
 
}
 

	
 
/** Engine drawing loop
 
 * @param type Type of vehicle (VEH_*)
 
 * @param x,y Where should the list start
 
@@ -763,7 +752,7 @@ void DrawEngineList(VehicleType type, in
 

	
 
		SetDParam(0, engine);
 
		DrawString(x + x_offset, r, y, STR_ENGINE_NAME, engine == selected_id ? TC_WHITE : TC_BLACK);
 
		DrawVehicleEngine(type, x, y + y_offset, engine, (count_location != 0 && num_engines == 0) ? PALETTE_CRASH : GetEnginePalette(engine, _local_company));
 
		DrawVehicleEngine(x, y + y_offset, engine, (count_location != 0 && num_engines == 0) ? PALETTE_CRASH : GetEnginePalette(engine, _local_company));
 
		if (count_location != 0) {
 
			SetDParam(0, num_engines);
 
			DrawString(x, count_location, y + (GetVehicleListHeight(type) == 14 ? 3 : 8), STR_TINY_BLACK_COMA, TC_FROMSTRING, SA_RIGHT);
src/engine_gui.cpp
Show inline comments
 
@@ -72,11 +72,9 @@ static const NWidgetPart _nested_engine_
 
	EndContainer(),
 
};
 

	
 
typedef void DrawEngineProc(int x, int y, EngineID engine, SpriteID pal);
 
typedef void DrawEngineInfoProc(EngineID, int left, int right, int top, int bottom);
 

	
 
struct DrawEngineInfo {
 
	DrawEngineProc *engine_proc;
 
	DrawEngineInfoProc *info_proc;
 
};
 

	
 
@@ -86,10 +84,10 @@ static void DrawShipEngineInfo(EngineID 
 
static void DrawAircraftEngineInfo(EngineID engine, int left, int right, int top, int bottom);
 

	
 
static const DrawEngineInfo _draw_engine_list[4] = {
 
	{ DrawTrainEngine,    DrawTrainEngineInfo    },
 
	{ DrawRoadVehEngine,  DrawRoadVehEngineInfo  },
 
	{ DrawShipEngine,     DrawShipEngineInfo     },
 
	{ DrawAircraftEngine, DrawAircraftEngineInfo },
 
	{ DrawTrainEngineInfo    },
 
	{ DrawRoadVehEngineInfo  },
 
	{ DrawShipEngineInfo     },
 
	{ DrawAircraftEngineInfo },
 
};
 

	
 
struct EnginePreviewWindow : Window {
 
@@ -112,7 +110,7 @@ struct EnginePreviewWindow : Window {
 
		const DrawEngineInfo *dei = &_draw_engine_list[Engine::Get(engine)->type];
 

	
 
		int width = this->width;
 
		dei->engine_proc(width >> 1, 100, engine, GetEnginePalette(engine, _local_company));
 
		DrawVehicleEngine(width >> 1, 100, engine, GetEnginePalette(engine, _local_company));
 
		dei->info_proc(engine, this->widget[EPW_BACKGROUND].left + 26, this->widget[EPW_BACKGROUND].right - 26, 100, 170);
 
	}
 

	
 
@@ -231,6 +229,38 @@ static void DrawShipEngineInfo(EngineID 
 
	DrawStringMultiLine(left, right, top, bottom, STR_ENGINE_PREVIEW_COST_MAX_SPEED_CAPACITY_RUNCOST, TC_FROMSTRING, SA_CENTER);
 
}
 

	
 
/**
 
 * Draw an engine.
 
 * @param x      Horizontal position to use for drawing the engine.
 
 * @param y      Vertical position to use for drawing the engine.
 
 * @param engine Engine to draw.
 
 * @para, pal    Palette to use for drawing.
 
 */
 
void DrawVehicleEngine(int x, int y, EngineID engine, SpriteID pal)
 
{
 
	const Engine *e = Engine::Get(engine);
 

	
 
	switch (e->type) {
 
		case VEH_TRAIN:
 
			DrawTrainEngine(x, y, engine, pal);
 
			break;
 

	
 
		case VEH_ROAD:
 
			DrawRoadVehEngine(x, y, engine, pal);
 
			break;
 

	
 
		case VEH_SHIP:
 
			DrawShipEngine(x, y, engine, pal);
 
			break;
 

	
 
		case VEH_AIRCRAFT:
 
			DrawAircraftEngine(x, y, engine, pal);
 
			break;
 

	
 
		default: NOT_REACHED();
 
	}
 
}
 

	
 
void DrawNewsNewVehicleAvail(Window *w, const NewsItem *ni)
 
{
 
	assert(ni->reftype1 == NR_ENGINE);
 
@@ -245,7 +275,7 @@ void DrawNewsNewVehicleAvail(Window *w, 
 
	SetDParam(0, engine);
 
	DrawStringMultiLine(1, w->width - 2, 56, 88, STR_NEWS_NEW_VEHICLE_TYPE, TC_FROMSTRING, SA_CENTER);
 

	
 
	dei->engine_proc(w->width >> 1, 88, engine, GetEnginePalette(engine, _local_company));
 
	DrawVehicleEngine(w->width >> 1, 88, engine, GetEnginePalette(engine, _local_company));
 
	GfxFillRect(25, 56, w->width - 56, 112, PALETTE_TO_STRUCT_GREY, FILLRECT_RECOLOUR);
 
	dei->info_proc(engine, 26, w->width - 26, 100, 170);
 
}
src/engine_gui.h
Show inline comments
 
@@ -20,4 +20,6 @@ typedef int CDECL EngList_SortTypeFuncti
 
void EngList_Sort(GUIEngineList *el, EngList_SortTypeFunction compare);  ///< qsort of the engine list
 
void EngList_SortPartial(GUIEngineList *el, EngList_SortTypeFunction compare, uint begin, uint num_items); ///< qsort of specified portion of the engine list
 

	
 
void DrawVehicleEngine(int x, int y, EngineID engine, SpriteID pal);
 

	
 
#endif /* ENGINE_GUI_H */
0 comments (0 inline, 0 general)