(svn r18121) -Codechange: pass the maximum left/right location to the Draw*Engine functions

This commit is contained in:
rubidium 2009-11-16 17:15:42 +00:00
parent 179b924173
commit 1c5a92ae98
9 changed files with 28 additions and 26 deletions

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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();

View File

@ -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();

View File

@ -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 */

View File

@ -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;
}

View File

@ -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)

View File

@ -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)

View File

@ -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);
}
}