summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-11-16 17:15:42 +0000
committerrubidium <rubidium@openttd.org>2009-11-16 17:15:42 +0000
commit1c5a92ae98954adb4c8e3841577ad771f79aaa47 (patch)
treefe3616b09774c5199a985cd3bf9461134335caad /src
parent179b924173e250de707102f319da03d609c482b4 (diff)
downloadopenttd-1c5a92ae98954adb4c8e3841577ad771f79aaa47.tar.xz
(svn r18121) -Codechange: pass the maximum left/right location to the Draw*Engine functions
Diffstat (limited to 'src')
-rw-r--r--src/aircraft_cmd.cpp6
-rw-r--r--src/build_vehicle_gui.cpp2
-rw-r--r--src/engine_func.h5
-rw-r--r--src/engine_gui.cpp16
-rw-r--r--src/engine_gui.h7
-rw-r--r--src/news_gui.cpp2
-rw-r--r--src/roadveh_cmd.cpp4
-rw-r--r--src/ship_cmd.cpp4
-rw-r--r--src/train_cmd.cpp8
9 files changed, 28 insertions, 26 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index 2d4e2160b..767b8531d 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -198,14 +198,14 @@ static SpriteID GetAircraftIcon(EngineID engine)
return DIR_W + _aircraft_sprite[spritenum];
}
-void DrawAircraftEngine(int x, int y, EngineID engine, SpriteID pal)
+void DrawAircraftEngine(int left, int right, int preferred_x, int y, EngineID engine, SpriteID pal)
{
- DrawSprite(GetAircraftIcon(engine), pal, x, y);
+ DrawSprite(GetAircraftIcon(engine), pal, preferred_x, y);
if (!(AircraftVehInfo(engine)->subtype & AIR_CTOL)) {
SpriteID rotor_sprite = GetCustomRotorIcon(engine);
if (rotor_sprite == 0) rotor_sprite = SPR_ROTOR_STOPPED;
- DrawSprite(rotor_sprite, PAL_NONE, x, y - 5);
+ DrawSprite(rotor_sprite, PAL_NONE, preferred_x, y - 5);
}
}
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp
index 44818d309..fa896016f 100644
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -728,7 +728,7 @@ void DrawEngineList(VehicleType type, int l, int r, int y, const GUIEngineList *
SetDParam(0, engine);
DrawString(text_left, text_right, y + normal_text_y_offset, STR_ENGINE_NAME, engine == selected_id ? TC_WHITE : TC_BLACK);
- DrawVehicleEngine(sprite_x, y + sprite_y_offset, engine, (show_count && num_engines == 0) ? PALETTE_CRASH : GetEnginePalette(engine, _local_company));
+ DrawVehicleEngine(l, r, sprite_x, y + sprite_y_offset, engine, (show_count && num_engines == 0) ? PALETTE_CRASH : GetEnginePalette(engine, _local_company));
if (show_count) {
SetDParam(0, num_engines);
DrawString(text_left, text_right, y + small_text_y_offset, STR_TINY_BLACK_COMA, TC_FROMSTRING, SA_RIGHT);
diff --git a/src/engine_func.h b/src/engine_func.h
index 3402576d5..518bdc422 100644
--- a/src/engine_func.h
+++ b/src/engine_func.h
@@ -21,11 +21,6 @@ void StartupEngines();
extern const uint8 _engine_counts[4];
extern const uint8 _engine_offsets[4];
-void DrawTrainEngine(int x, int y, EngineID engine, SpriteID pal);
-void DrawRoadVehEngine(int x, int y, EngineID engine, SpriteID pal);
-void DrawShipEngine(int x, int y, EngineID engine, SpriteID pal);
-void DrawAircraftEngine(int x, int y, EngineID engine, SpriteID pal);
-
bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company);
bool IsEngineRefittable(EngineID engine);
void SetCachedEngineCounts();
diff --git a/src/engine_gui.cpp b/src/engine_gui.cpp
index 0ce2428bc..60343bfb8 100644
--- a/src/engine_gui.cpp
+++ b/src/engine_gui.cpp
@@ -104,7 +104,7 @@ struct EnginePreviewWindow : Window {
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_ENGINE_NAME, TC_BLACK, SA_CENTER);
y += FONT_HEIGHT_NORMAL;
- DrawVehicleEngine(this->width >> 1, y + VEHICLE_SPACE / 2, engine, GetEnginePalette(engine, _local_company));
+ DrawVehicleEngine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, this->width >> 1, y + VEHICLE_SPACE / 2, engine, GetEnginePalette(engine, _local_company));
y += VEHICLE_SPACE;
DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, r.bottom, GetEngineInfoString(engine), TC_FROMSTRING, SA_CENTER);
@@ -248,30 +248,32 @@ StringID GetEngineInfoString(EngineID engine)
/**
* Draw an engine.
- * @param x Horizontal position to use for drawing the engine.
+ * @param left Minimum horizontal position to use for drawing the engine
+ * @param right Maximum horizontal position to use for drawing the engine
+ * @param preferred_x Horizontal position to use for drawing the engine.
* @param y Vertical position to use for drawing the engine.
* @param engine Engine to draw.
* @param pal Palette to use for drawing.
*/
-void DrawVehicleEngine(int x, int y, EngineID engine, SpriteID pal)
+void DrawVehicleEngine(int left, int right, int preferred_x, int y, EngineID engine, SpriteID pal)
{
const Engine *e = Engine::Get(engine);
switch (e->type) {
case VEH_TRAIN:
- DrawTrainEngine(x, y, engine, pal);
+ DrawTrainEngine(left, right, preferred_x, y, engine, pal);
break;
case VEH_ROAD:
- DrawRoadVehEngine(x, y, engine, pal);
+ DrawRoadVehEngine(left, right, preferred_x, y, engine, pal);
break;
case VEH_SHIP:
- DrawShipEngine(x, y, engine, pal);
+ DrawShipEngine(left, right, preferred_x, y, engine, pal);
break;
case VEH_AIRCRAFT:
- DrawAircraftEngine(x, y, engine, pal);
+ DrawAircraftEngine(left, right, preferred_x, y, engine, pal);
break;
default: NOT_REACHED();
diff --git a/src/engine_gui.h b/src/engine_gui.h
index eb752f48a..139b6107c 100644
--- a/src/engine_gui.h
+++ b/src/engine_gui.h
@@ -22,6 +22,11 @@ void EngList_SortPartial(GUIEngineList *el, EngList_SortTypeFunction compare, ui
StringID GetEngineCategoryName(EngineID engine);
StringID GetEngineInfoString(EngineID engine);
-void DrawVehicleEngine(int x, int y, EngineID engine, SpriteID pal);
+
+void DrawVehicleEngine(int left, int right, int preferred_x, int y, EngineID engine, SpriteID pal);
+void DrawTrainEngine(int left, int right, int preferred_x, int y, EngineID engine, SpriteID pal);
+void DrawRoadVehEngine(int left, int right, int preferred_x, int y, EngineID engine, SpriteID pal);
+void DrawShipEngine(int left, int right, int preferred_x, int y, EngineID engine, SpriteID pal);
+void DrawAircraftEngine(int left, int right, int preferred_x, int y, EngineID engine, SpriteID pal);
#endif /* ENGINE_GUI_H */
diff --git a/src/news_gui.cpp b/src/news_gui.cpp
index 8f94646b8..55aec1c22 100644
--- a/src/news_gui.cpp
+++ b/src/news_gui.cpp
@@ -427,7 +427,7 @@ struct NewsWindow : Window {
case NTW_VEH_SPR: {
assert(this->ni->reftype1 == NR_ENGINE);
EngineID engine = this->ni->ref1;
- DrawVehicleEngine((r.left + r.right) / 2, (r.top + r.bottom) / 2, engine, GetEnginePalette(engine, _local_company));
+ DrawVehicleEngine(r.left, r.right, (r.left + r.right) / 2, (r.top + r.bottom) / 2, engine, GetEnginePalette(engine, _local_company));
GfxFillRect(r.left, r.top, r.right, r.bottom, PALETTE_TO_STRUCT_GREY, FILLRECT_RECOLOUR);
break;
}
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index b5121095b..b0a535d04 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -138,9 +138,9 @@ SpriteID RoadVehicle::GetImage(Direction direction) const
return sprite;
}
-void DrawRoadVehEngine(int x, int y, EngineID engine, SpriteID pal)
+void DrawRoadVehEngine(int left, int right, int preferred_x, int y, EngineID engine, SpriteID pal)
{
- DrawSprite(GetRoadVehIcon(engine), pal, x, y);
+ DrawSprite(GetRoadVehIcon(engine), pal, preferred_x, y);
}
static uint GetRoadVehLength(const RoadVehicle *v)
diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp
index 05e77d534..d2bf6a7fb 100644
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -68,9 +68,9 @@ static SpriteID GetShipIcon(EngineID engine)
return DIR_W + _ship_sprites[spritenum];
}
-void DrawShipEngine(int x, int y, EngineID engine, SpriteID pal)
+void DrawShipEngine(int left, int right, int preferred_x, int y, EngineID engine, SpriteID pal)
{
- DrawSprite(GetShipIcon(engine), pal, x, y);
+ DrawSprite(GetShipIcon(engine), pal, preferred_x, y);
}
/** Get the size of the sprite of a ship sprite heading west (used for lists)
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 73d69eb82..aa6c53fce 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -657,7 +657,7 @@ static SpriteID GetRailIcon(EngineID engine, bool rear_head, int &y)
return GetDefaultTrainSprite(spritenum, DIR_W);
}
-void DrawTrainEngine(int x, int y, EngineID engine, SpriteID pal)
+void DrawTrainEngine(int left, int right, int preferred_x, int y, EngineID engine, SpriteID pal)
{
if (RailVehInfo(engine)->railveh_type == RAILVEH_MULTIHEAD) {
int yf = y;
@@ -665,11 +665,11 @@ void DrawTrainEngine(int x, int y, EngineID engine, SpriteID pal)
SpriteID spritef = GetRailIcon(engine, false, yf);
SpriteID spriter = GetRailIcon(engine, true, yr);
- DrawSprite(spritef, pal, x - 14, yf);
- DrawSprite(spriter, pal, x + 15, yr);
+ DrawSprite(spritef, pal, preferred_x - 14, yf);
+ DrawSprite(spriter, pal, preferred_x + 15, yr);
} else {
SpriteID sprite = GetRailIcon(engine, false, y);
- DrawSprite(sprite, pal, x, y);
+ DrawSprite(sprite, pal, preferred_x, y);
}
}