summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2009-08-30 17:38:28 +0000
committeralberth <alberth@openttd.org>2009-08-30 17:38:28 +0000
commit1a15f7e6a73ed7bbc16813fcd69b3e8b270a8a73 (patch)
treeb90b1e2744df4701f0f88490532eaf847a86f1b5 /src
parentfe7ca1b3e3a5cef63d61a117dbe1fda80b5e877d (diff)
downloadopenttd-1a15f7e6a73ed7bbc16813fcd69b3e8b270a8a73.tar.xz
(svn r17325) -Codechange: Un-duplicate engine drawing routines.
Diffstat (limited to 'src')
-rw-r--r--src/build_vehicle_gui.cpp13
-rw-r--r--src/engine_gui.cpp46
-rw-r--r--src/engine_gui.h2
3 files changed, 41 insertions, 20 deletions
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp
index 1d67a221f..84ca486bb 100644
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -703,17 +703,6 @@ int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number)
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, int x, int r, int y, const GUIEngineList *
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);
diff --git a/src/engine_gui.cpp b/src/engine_gui.cpp
index b71b28cf3..0ecd94d15 100644
--- a/src/engine_gui.cpp
+++ b/src/engine_gui.cpp
@@ -72,11 +72,9 @@ static const NWidgetPart _nested_engine_preview_widgets[] = {
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 engine, int left, int right, int top, in
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 engine, int left, int right, int top, in
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, const NewsItem *ni)
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);
}
diff --git a/src/engine_gui.h b/src/engine_gui.h
index 02223b69d..937215183 100644
--- a/src/engine_gui.h
+++ b/src/engine_gui.h
@@ -20,4 +20,6 @@ typedef int CDECL EngList_SortTypeFunction(const void*, const void*); ///< argum
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 */