/// <summary>
        /// Basic method to draw a line starting at a point between two points.
        /// Parameters are in world coordinates and sizes.
        /// </summary>
        /// <param name="width"> Width of the line to draw in meters </param>
        /// <param name="color"> Color of the line</param>
        /// <param name="point"> WorldLocation of the first point of the line (for zero offset)</param>
        /// <param name="length"> length of the line to draw in meters (also when shifted by offset)</param>
        /// <param name="angle"> Angle (in rad east of North)</param>
        /// <param name="lengthOffset">Instead of starting to draw at the given point, only start to draw a distance offset further along the line</param>
        public void DrawLine(float width, Color color, WorldLocation point, float length, float angle, float lengthOffset)
        {
            WorldLocation beginPoint;
            float         sinAngle = (float)Math.Sin(angle);
            float         cosAngle = (float)Math.Cos(angle);

            if (lengthOffset == 0)
            {
                beginPoint = point;
            }
            else
            {
                beginPoint             = new WorldLocation(point);
                beginPoint.Location.X += lengthOffset * sinAngle;
                beginPoint.Location.Z += lengthOffset * cosAngle;
            }
            WorldLocation endPoint = new WorldLocation(beginPoint); //location of end-point

            endPoint.Location.X += length * sinAngle;
            endPoint.Location.Z += length * cosAngle;
            if (OutOfArea(beginPoint) && OutOfArea(endPoint))
            {
                return;
            }
            // definition of rotation in ORTS is angle right of North
            // rotation in the window/draw area is angle right/south of right-horizontal
            // hence a 90 degree correction
            // To prevent double calculations, offset is already taken into account here
            BasicShapes.DrawLine(GetWindowSize(width), color, GetWindowVector(beginPoint),
                                 GetWindowSize(length), angle - MathHelper.Pi / 2);
        }
Beispiel #2
0
        /// <summary>
        /// Draw the ruler on the screen
        /// </summary>
        public void Draw()
        {
            if (!Properties.Settings.Default.showScaleRuler)
            {
                return;
            }
            if (Properties.Settings.Default.useMilesNotMeters != useMilesNotMeters)
            {
                SetCurrentRuler(pixelsPerMeter); // Only do this when needed
            }

            string scaleText = " (" + (1.0f / pixelsPerMeter).ToString(System.Globalization.CultureInfo.CurrentCulture) + "m/pixel)";

            Vector2 lowerRightPoint = new Vector2(lowerLeftPoint.X + fullPixelWidth, lowerLeftPoint.Y);
            Vector2 bigMarker       = new Vector2(0, -halfFontHeight);
            Vector2 smallMarker     = new Vector2(0, -(int)(halfFontHeight / 2));
            Color   color           = DrawColors.colorsNormal.Text;

            BasicShapes.DrawLine(1, color, lowerLeftPoint, lowerRightPoint);
            BasicShapes.DrawLine(1, color, lowerLeftPoint, lowerLeftPoint + bigMarker);
            BasicShapes.DrawLine(1, color, lowerRightPoint, lowerRightPoint + bigMarker);
            BasicShapes.DrawString(lowerRightPoint + bigMarker, color, currentRuler.text + scaleText);
            for (int i = 1; i < currentRuler.subMarkers; i++)
            {
                Vector2 smallMarkerPoint = new Vector2(lowerLeftPoint.X + fullPixelWidth * i / currentRuler.subMarkers, lowerLeftPoint.Y);
                BasicShapes.DrawLine(1, color, smallMarkerPoint, smallMarkerPoint + smallMarker);
            }
        }
 /// <summary>
 /// Draw a border around the area
 /// </summary>
 /// <param name="color">The color of the border line</param>
 public void DrawBorder(Color color)
 {
     // We do not use DrawBorder below to prevent a line not being drawn because of OutOfArea
     BasicShapes.DrawLine(1, color, GetWindowVector(0, 0), GetWindowVector(0, AreaH));
     BasicShapes.DrawLine(1, color, GetWindowVector(AreaW, 0), GetWindowVector(AreaW, AreaH));
     BasicShapes.DrawLine(1, color, GetWindowVector(0, 0), GetWindowVector(AreaW, 0));
     BasicShapes.DrawLine(1, color, GetWindowVector(0, AreaH), GetWindowVector(AreaW, AreaH));
 }
 /// <summary>
 /// Basic method to draw a line between two points. Coordinates are in area coordinates.
 /// </summary>
 /// <param name="width"> Width of the line to draw in meters </param>
 /// <param name="color"> Color of the line</param>
 /// <param name="point1"> WorldLocation of the first point of the line</param>
 /// <param name="point2"> WorldLocation of to the last point of the line</param>
 public void DrawLine(float width, Color color, WorldLocation point1, WorldLocation point2)
 {
     if (OutOfArea(point1) && OutOfArea(point2))
     {
         return;
     }
     BasicShapes.DrawLine(GetWindowSize(width), color, GetWindowVector(point1), GetWindowVector(point2));
 }
        /// <summary>
        /// Draw a horizontal line trough the given world line, all the way from bottom to top. 1 pixel wide.
        /// </summary>
        /// <param name="color">Color of the line</param>
        /// <param name="point">Worldlocation through which to draw the line</param>
        private void DrawLineHorizontal(Color color, WorldLocation point)
        {
            Vector2 middle = GetWindowVector(point);
            Vector2 left   = GetWindowVector(0, 0);
            Vector2 right  = GetWindowVector(AreaW, 0);

            right.Y = middle.Y;
            left.Y  = middle.Y;
            BasicShapes.DrawLine(1, color, left, right);
        }
        /// <summary>
        /// Draw a vertical line trough the given world line, all the way from bottom to top. 1 pixel wide.
        /// </summary>
        /// <param name="color">Color of the line</param>
        /// <param name="point">Worldlocation through which to draw the line</param>
        private void DrawLineVertical(Color color, WorldLocation point)
        {
            Vector2 middle = GetWindowVector(point);
            Vector2 top    = GetWindowVector(0, 0);
            Vector2 bot    = GetWindowVector(0, AreaH);

            bot.X = middle.X;
            top.X = middle.X;
            BasicShapes.DrawLine(1, color, bot, top);
        }
 /// <summary>
 /// Simply draw a blank background for this area
 /// </summary>
 /// <param name="color">The background color you want</param>
 public void DrawBackground(Color color)
 {
     BasicShapes.DrawLine(AreaW, color, GetWindowVector(AreaW / 2, 0), GetWindowVector(AreaW / 2, AreaH));
 }
 /// <summary>
 /// Basic method to draw a line between two points without checking whether it is out of bounds or not. Coordinates are in area coordinates.
 /// </summary>
 /// <param name="width"> Width of the line to draw in meters </param>
 /// <param name="color"> Color of the line</param>
 /// <param name="point1"> WorldLocation of the first point of the line</param>
 /// <param name="point2"> WorldLocation of to the last point of the line</param>
 public void DrawLineAlways(float width, Color color, WorldLocation point1, WorldLocation point2)
 {
     BasicShapes.DrawLine(GetWindowSize(width), color, GetWindowVector(point1), GetWindowVector(point2));
 }