summaryrefslogtreecommitdiff
path: root/src/roadveh_cmd.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2009-07-18 12:34:19 +0000
committerfrosch <frosch@openttd.org>2009-07-18 12:34:19 +0000
commite8c2992ae698e63c437807a15504999493b1060b (patch)
treeb49230ca1c6be6e2916b642db513591e96912454 /src/roadveh_cmd.cpp
parent36576371c05edf9a3498196d7ebdb8824a6910d1 (diff)
downloadopenttd-e8c2992ae698e63c437807a15504999493b1060b.tar.xz
(svn r16872) -Codechange: Add RoadVehicle::GetDisplayImageWidth and simplify DrawRoadVehImage.
Diffstat (limited to 'src/roadveh_cmd.cpp')
-rw-r--r--src/roadveh_cmd.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index 50a7d4e95..811a0e422 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -85,6 +85,22 @@ static const Trackdir _roadveh_depot_exit_trackdir[DIAGDIR_END] = {
TRACKDIR_X_NE, TRACKDIR_Y_SE, TRACKDIR_X_SW, TRACKDIR_Y_NW
};
+/**
+ * Get the width of a road vehicle image in the GUI.
+ * @param offset Additional offset for positioning the sprite; set to NULL if not needed
+ * @return Width in pixels
+ */
+int RoadVehicle::GetDisplayImageWidth(Point *offset) const
+{
+ int reference_width = ROADVEHINFO_DEFAULT_VEHICLE_WIDTH;
+
+ if (offset != NULL) {
+ offset->x = reference_width / 2;
+ offset->y = 0;
+ }
+ return this->rcache.cached_veh_length * reference_width / 8;
+}
+
static SpriteID GetRoadVehIcon(EngineID engine)
{
uint8 spritenum = RoadVehInfo(engine)->image_index;