Esempio n. 1
0
 private PenModifier GetPenModifierForWaypoint(clsWaypoint Waypoint)
 {
     if (Waypoint.Wait.HasValue)
     {
         return(PenModifier.Wait);
     }
     if (Waypoint.Crossing.HasValue)
     {
         return(PenModifier.Cross);
     }
     if (Waypoint.Reverse.HasValue)
     {
         return(PenModifier.Reverse);
     }
     if (Waypoint.Unload.HasValue)
     {
         return(PenModifier.Unload);
     }
     if (Waypoint.TurnStart.HasValue)
     {
         return(PenModifier.TurnStart);
     }
     if (Waypoint.TurnEnd.HasValue)
     {
         return(PenModifier.TurnEnd);
     }
     return(PenModifier.Default);
 }
Esempio n. 2
0
        private void panZoomBox1_Click(object sender, MouseEventArgs e)
        {
            Point CursorPosition = new Point(e.X, e.Y);

            if (e.Button == MouseButtons.Right)
            {
                try
                {
                    ClickedWaypoint = GetWaypointAtClientPosition(CursorPosition);
                    if (ClickedWaypoint != null || SelectedWaypoints.Count > 0)
                    {
                        if (SelectedWaypoints.Count == 0 && !SelectedWaypoints.Contains(ClickedWaypoint))
                        {
                            SelectWaypoint();
                        }
                        if (SelectedWaypoints.Count > 1)
                        {
                            MultiWaypointContextMenu.Show(panZoomBox1, CursorPosition);
                        }
                        else
                        {
                            WaypointContexMenu.Show(panZoomBox1, CursorPosition);
                        }

                        ShowedContext = true;
                    }
                }
                catch (Exception)
                {
                    return;
                }
            }
        }
Esempio n. 3
0
        private void WaypointSelectionAndMovement(Point CursorPosition)
        {
            if (ClickedWaypoint != null)
            {
                SelectWaypoint();
                ClickedWaypoint = null;
            }
            else if (!ControlKeyPressed())
            {
                StartSelection(CursorPosition);
                return;
            }

            if (SelectedWaypoints.Count > 0 && !ShowedContext && !ControlKeyPressed())
            {
                try
                {
                    MoveWaypoints(CursorPosition);
                    PreviousCursorPosition.X = CursorPosition.X; PreviousCursorPosition.Y = CursorPosition.Y;
                }
                catch (ArgumentNullException)
                {
                    return;
                }
            }
        }
Esempio n. 4
0
 private void ClearSelectedWaypoints()
 {
     while (SelectedWaypoints.Count > 0)
     {
         clsWaypoint CurrentWaypoint = SelectedWaypoints[0];
         SelectedWaypoints.Remove(CurrentWaypoint);
         InvalidateWaypoint(CurrentWaypoint);
     }
 }
Esempio n. 5
0
        private void panZoomBox1_MouseDown(object sender, MouseEventArgs e)
        {
            Point CursorPosition = new Point(e.X, e.Y);

            try
            {
                if (e.Button == MouseButtons.Left)
                {
                    ClickedWaypoint = GetWaypointAtClientPosition(CursorPosition);
                }
            }
            catch (ArgumentNullException)
            {
                return;
            }
        }
Esempio n. 6
0
        private clsWaypoint GetWaypointAtClientPosition(Point ClientPosition)
        {
            try
            {
                List <clsWaypoint> CloseWaypoints    = new List <clsWaypoint>();
                PointF             CursorMapPosition = ClientToWorldPosition(ClientPosition);

                foreach (clsWaypoint Waypoint in OnScreenWaypoints)
                {
                    if (Math.Abs(CursorMapPosition.X - Waypoint.position.X) <= 6 / panZoomBox1.ZoomFactor && Math.Abs(CursorMapPosition.Y - Waypoint.position.Y) <= 6 / panZoomBox1.ZoomFactor)
                    {
                        CloseWaypoints.Add(Waypoint);
                    }
                }
                if (CloseWaypoints.Count > 0)
                {
                    if (CloseWaypoints.Count == 1)
                    {
                        return(CloseWaypoints[0]);
                    }

                    clsWaypoint ClosestWaypoint = new clsWaypoint();
                    double      DeltaX          = double.MaxValue;
                    double      DeltaY          = double.MaxValue;

                    foreach (clsWaypoint Waypoint in CloseWaypoints)
                    {
                        if (ClientPosition.X - Waypoint.position.X < DeltaX && ClientPosition.Y - Waypoint.position.Y < DeltaY)
                        {
                            ClosestWaypoint = Waypoint;
                        }
                    }
                    return(ClosestWaypoint);
                }
                return(null);
            }
            catch (ArgumentNullException ex)
            {
                throw ex;
            }
        }
Esempio n. 7
0
        public void ReadXml(XmlReader reader)
        {
            do
            {
                if (reader.Name.Contains("course") && reader.HasAttributes)
                {
                    for (int i = 0; i < reader.AttributeCount; i++)
                    {
                        // Take care of this courses properties via reflection.
                        reader.MoveToNextAttribute();
                        foreach (PropertyInfo prop in this.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
                        {
                            foreach (XmlAttributeAttribute attrib in prop.GetCustomAttributes(typeof(XmlAttributeAttribute), false))
                            {
                                if (attrib.AttributeName == reader.Name)
                                {
                                    prop.SetValue(this, reader.Value, null);
                                }
                            }
                        }
                    }
                }
                else if (reader.Name.Contains("waypoint"))
                {
                    // Remove Index from Element tag then use normal XmlSerialization to convert to waypoint
                    string      Xml         = reader.ReadOuterXml();
                    string      ModXml      = Xml.Substring(0, "<waypoint".Length) + Xml.Substring(Xml.IndexOf(" "), Xml.Length - Xml.IndexOf(" "));
                    clsWaypoint NewWaypoint = clsXmlSaveLoad.DeserializeXmlFromString <clsWaypoint>(ModXml);
                    if (PreviousWaypoint != null)
                    {
                        NewWaypoint.Previous  = PreviousWaypoint;
                        PreviousWaypoint.Next = NewWaypoint;
                    }
                    Waypoints.Add(NewWaypoint);
                    PreviousWaypoint = NewWaypoint;
                }

                reader.Read();
            } while (!reader.EOF);
        }
Esempio n. 8
0
        private void panZoomBox1_MouseUp(object sender, MouseEventArgs e)
        {
            Point CursorPosition = new Point(e.X, e.Y);

            if (e.Button == MouseButtons.Left)
            {
                if (ClickedWaypoint != null && ClickedWaypoint == GetWaypointAtClientPosition(CursorPosition))
                {
                    SelectWaypoint();
                }
                else
                {
                    EndSelection(CursorPosition);
                }
                ClickedWaypoint = null;
                if (SelectionStarted)
                {
                    SelectionStarted = false;
                    UpdateSelection(CursorPosition);
                }
            }
        }
Esempio n. 9
0
 private void InvalidateWaypoint(clsWaypoint Waypoint)
 {
     panZoomBox1.Invalidate(BufferedRectangleFromPoint(WorldToClientPosition(Waypoint.position), WaypointBuffer));
 }
Esempio n. 10
0
        public List <clsWaypoint> DrawCourse(clsCourse Course, Graphics g, Rectangle Client, Rectangle ViewPort, List <clsWaypoint> SelectedWaypoints, int Quality)
        {
            //TODO: Draw On seperate surface? Prerender a waypoint marker in each color. Blit to screen.
            clsWaypoint        PreviousWaypoint = null;
            Matrix             TransformMatrix  = new Matrix();
            Matrix             PenMatrix        = new Matrix();
            Pen                CurrentPen;
            clsWaypoint        CurrentWaypoint = Course.waypoint[0];
            List <clsWaypoint> ReturnList      = new List <clsWaypoint>();

            TransformMatrix.Translate(((MapSize.Width / 2) - (ViewPort.X)) * ZoomFactor, ((MapSize.Height / 2) - (ViewPort.Y)) * ZoomFactor);
            TransformMatrix.Scale(ZoomFactor, ZoomFactor);
            g.Transform = TransformMatrix;

            PenMatrix = TransformMatrix.Clone();
            PenMatrix.Invert();

            CurrentPen           = pens[PenModifier.Default];
            CurrentPen.Transform = PenMatrix;

            for (int i = 0; i < Course.waypoint.Count; i++)
            {
                PenModifier CurrentModifier;
                if (i != 0 && i < Course.waypoint.Count)
                {
                    PreviousWaypoint = CurrentWaypoint;
                    CurrentWaypoint  = Course.waypoint[i];
                }

                if (IsOnScreen(CurrentWaypoint.position, ViewPort))
                {
                    ReturnList.Add(CurrentWaypoint);
                    if (i == 0)
                    {
                        CurrentModifier = PenModifier.Start;
                    }
                    else if (i == Course.waypoint.Count - 1)
                    {
                        CurrentModifier = PenModifier.End;
                    }
                    else
                    {
                        CurrentModifier = GetPenModifierForWaypoint(CurrentWaypoint);
                    }

                    if (SelectedWaypoints != null && SelectedWaypoints.Contains(CurrentWaypoint))
                    {
                        CurrentModifier = PenModifier.Selected;
                    }

                    g.DrawImage(WaypointMarkers[CurrentModifier], CurrentWaypoint.position);

                    if (PreviousWaypoint != null)
                    {
                        g.DrawLine(CurrentPen, PreviousWaypoint.position, CurrentWaypoint.position);
                    }
                }
                else
                {
                    if (PreviousWaypoint != null && IsOnScreen(PreviousWaypoint.position, ViewPort))
                    {
                        g.DrawLine(CurrentPen, PreviousWaypoint.position, CurrentWaypoint.position);
                    }
                }
                if (Quality < 2)
                {
                    i += 2;
                }
            }

            //TransformMatrix.Reset();
            TransformMatrix.Invert();//TransformMatrix.Translate((MapSize.Width / 2) * -1, (MapSize.Height / 2) * -1);
            TransformMatrix.Scale(1, 1);
            g.Transform = TransformMatrix;
            return(ReturnList);
        }
Esempio n. 11
0
 private Pen GetPenForWaypoint(clsWaypoint Waypoint)
 {
     return(pens[GetPenModifierForWaypoint(Waypoint)]);
 }