public void DrawOfflineTrains(List <TrainWebData> listTrains, LegendUILoader legendLoader) { MouseButtonEventHandler handler = null; foreach (TrainWebData data in listTrains) { Track peHead = base.GetElement(data.HeadElement) as Track; if (peHead != null) { Point trainPoint = peHead.GetTrainPoint(); Track.GetOffsettedValue(peHead, (double)data.HeadOffset, data.HeadElementArrivedSource, ref trainPoint); FrameworkElement control = legendLoader.GetControl(); control.set_Tag(data); double num = 0.0; Point point2 = new Point(0.5, 1.0); if (peHead.PointPlus.get_X() == peHead.PointMinus.get_X()) { point2 = new Point(1.0, 0.5); num = 90.0; } control.SetValue(Canvas.LeftProperty, trainPoint.get_X() - (point2.get_X() * 16.0)); control.SetValue(Canvas.TopProperty, trainPoint.get_Y() - (point2.get_Y() * 16.0)); this.g.get_Children().Add(control); RotateTransform transform = new RotateTransform(); transform.set_Angle(-num); control.set_RenderTransform(transform); ToolTipService.SetToolTip(control, TrainControl.CreateTooltipControl(data.Tooltip)); if (handler == null) { handler = new MouseButtonEventHandler(this, (IntPtr)this.< DrawOfflineTrains > b__1); } control.add_MouseLeftButtonDown(handler); } } }
private void DrawTrain(Canvas g, Train train, Point pt, bool small, bool allowToDraw, out Rectangle rectangle) { Color color; Color color2; rectangle = new Rectangle(); TrainControl control = new TrainControl(train); control.OnTrainProperties += new TrainControl.TrainPropertiesHandler(this.TrainControl_OnTrainProperties); Train.GetTrainColors(train, out color, out color2); control.BodyColorHi = color2; control.BodyColorLo = color; Point connectionSourcePoint = new Point(0.0, 0.0); Point point2 = new Point(0.0, 0.0); PathElement headElement = train.HeadElement; if ((train.NextElement != null) && (train.NextElement != headElement)) { connectionSourcePoint = train.NextElement.GetConnectionSourcePoint(train.m_nNextElementSource); point2 = train.HeadElement.GetConnectionSourcePoint(train.m_nHeadElementArrivedSource); } else if (train.m_nHeadElementArrivedSource != -1) { connectionSourcePoint = headElement.GetConnectionSourcePoint(headElement.GetOppositeSource(train.m_nHeadElementArrivedSource)); point2 = headElement.GetConnectionSourcePoint(train.m_nHeadElementArrivedSource); } double rotationAngle = 0.0; if ((((connectionSourcePoint.get_X() != 0.0) || (connectionSourcePoint.get_Y() != 0.0)) && ((point2.get_X() != 0.0) || (point2.get_Y() != 0.0))) && (point2 != connectionSourcePoint)) { rotationAngle = SilverlightHelper.GetRotationAngle(point2, connectionSourcePoint); } else if (train.HeadElement != null) { int[] sources = train.HeadElement.GetSources(); if ((sources != null) && (sources.Length > 1)) { point2 = train.HeadElement.GetConnectionSourcePoint(sources[0]); connectionSourcePoint = train.HeadElement.GetConnectionSourcePoint(sources[1]); rotationAngle = SilverlightHelper.GetRotationAngle(point2, connectionSourcePoint); } } control.ID = train.ID; control.Tooltip = train.GetToolTipText(); control.IDToDisplay = train.IDToDisplay; control.Small = small; control.Direction = 1; rectangle = new Rectangle(); rectangle.X = (int)pt.get_X(); rectangle.Y = (int)pt.get_Y(); rectangle.Width = (int)control.WIDTH_ACTUAL; rectangle.Height = (int)control.HEIGHT_ACTUAL; if (allowToDraw) { control.SetValue(Canvas.LeftProperty, (double)rectangle.X); control.SetValue(Canvas.TopProperty, (double)rectangle.Y); control.SetValue(FrameworkElement.WidthProperty, (double)rectangle.Width); control.SetValue(FrameworkElement.HeightProperty, (double)rectangle.Height); double num2 = point2.get_X() - connectionSourcePoint.get_X(); double num3 = point2.get_Y() - connectionSourcePoint.get_Y(); int[] textOrientationVectorHor = TextOrientationVectorHor; if (train.HeadElement is Track) { Track track = train.HeadElement as Track; if (track.PointMinus.get_Y() == track.PointPlus.get_Y()) { textOrientationVectorHor = TextOrientationVectorVer; } } double num4 = SilverlightHelper.GetAngleBetweenVercors((double)textOrientationVectorHor[0], (double)textOrientationVectorHor[1], num2, num3); control.Draw(num4 >= 90.0); RotateTransform transform = new RotateTransform(); transform.set_Angle(-rotationAngle); control.set_RenderTransform(transform); g.get_Children().Add(control); } rectangle.Width += (int)(2.0 * control.NOSE_LEN); rectangle.Height = rectangle.Width = Math.Max(rectangle.Width, rectangle.Height); }