Ejemplo n.º 1
1
 protected override void OnRender(DrawingContext drawingContext)
 {
     base.OnRender(drawingContext);
     drawingContext.PushTransform(new TranslateTransform(AdornedElement.RenderSize.Width - 14, (AdornedElement.RenderSize.Height - 18) / 2.0));
     drawingContext.DrawGeometry(ArrowBrush, null, sda_render_geometry);
     drawingContext.Pop();
 }
Ejemplo n.º 2
0
        protected override void DrawPointElement(DrawingContext dc, int Zoom)
        {
            dc.DrawLine(new Pen(Brushes.Black, 2), new Point(), new Point(0, -BodyOffset));

            dc.PushTransform(new TranslateTransform(0, - 0.5 * BodyHeight - BodyOffset));

            dc.DrawRectangle(Brushes.Black, null,
                             new Rect(-0.5 * BodyWidth, -0.5 * BodyHeight, BodyWidth, BodyHeight));

            for (int i = 0; i < Lights.Length; i++)
                dc.DrawEllipse(Lights[i], null, new Point(0, (2 + LightRadius + 1) * (i - 1)), LightRadius, LightRadius);

            dc.PushTransform(new TranslateTransform(0.5 * BodyWidth + 2, -0.5 * BodyHeight));

            if (Zoom > 11)
            {
                PrintStack(dc,
                           new FormattedText(Target.Name, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Verdana"), 10, Brushes.Black),
                           new FormattedText(OrdinateString, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Verdana"), 8, Brushes.Blue));
            }

            dc.Pop();

            dc.Pop();
        }
        protected override void OnRender(DrawingContext dc)
        {
            Point pos, tangent;
            double angleInRadians;
            double angleInDegrees;
            TransformGroup tg;
            Pen pen = new Pen(Stroke, StrokeThickness);
            //dc.DrawGeometry(null, pen, LinePath);
            if (BeginCap != null)
            {

                LinePath.GetPointAtFractionLength(0.01d, out pos, out tangent);
                angleInRadians = Math.Atan2(tangent.Y, tangent.X) + Math.PI;
                angleInDegrees = angleInRadians * 180 / Math.PI + 180;
                tg = new TransformGroup();
                tg.Children.Add(new RotateTransform(angleInDegrees));
                LinePath.GetPointAtFractionLength(0.0d, out pos, out tangent);
                tg.Children.Add(new TranslateTransform(pos.X, pos.Y));
                dc.PushTransform(tg);
                dc.DrawGeometry(Brushes.DeepPink, pen, BeginCap);
                dc.Pop();
            }
            if (EndCap != null)
            {
                LinePath.GetPointAtFractionLength(0.99, out pos, out tangent);
                angleInRadians = Math.Atan2(tangent.Y, tangent.X) + Math.PI;
                angleInDegrees = angleInRadians * 180 / Math.PI;
                tg = new TransformGroup();
                tg.Children.Add(new RotateTransform(angleInDegrees));
                LinePath.GetPointAtFractionLength(1, out pos, out tangent);
                tg.Children.Add(new TranslateTransform(pos.X, pos.Y));
                dc.PushTransform(tg);
                dc.DrawGeometry(Brushes.DeepPink, pen, EndCap);
            }
        }
Ejemplo n.º 4
0
		public void drawLimb(DrawingContext dc, Point p1, Point p2, int margin)
		{

			dc.PushTransform(new TranslateTransform(p1.X, p1.Y));
			
			Vector diff = p2 - p1;
			diff.Normalize();

			double angle = Math.Acos(diff.Y) * (180.0 / Math.PI);
			if (Double.IsNaN(angle))
				angle = 0;

            if (Double.IsNaN(diff.X))
                diff.X = 0;

			dc.PushTransform(new RotateTransform(Math.Sign(diff.X) * (-1) * angle));

			Vector diff2 = p2 - p1;
			double scale = diff2.Length / (this.Height - 2 * margin);
			dc.PushTransform(new ScaleTransform(1, scale));

			dc.PushTransform(new TranslateTransform(-this.Width / 2.0, -margin));

			
			dc.DrawImage(this.Image, new Rect(0, 0, this.Width, this.Height));

			dc.Pop();
			dc.Pop();
			dc.Pop();
			dc.Pop();
		}
Ejemplo n.º 5
0
		protected override void InnerDraw(DrawingContext drawingContext)
		{
			drawingContext.PushTransform(_translateTransform);
			drawingContext.PushTransform(_rotateTransform);
			base.InnerDraw(drawingContext);
			drawingContext.Pop();
			drawingContext.Pop();
		}
Ejemplo n.º 6
0
 protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
 {
     System.Windows.Media.Media3D.Size3D size = (agentBase as BusAgent).Size;
     drawingContext.PushTransform(new TranslateTransform(Location.X - size.X / 4, Location.Y));
     drawingContext.PushTransform(new RotateTransform((agentBase as BusAgent).Angle));
     drawingContext.DrawRectangle(GetGroupColor(agentBase.Group), null, new Rect(-size.X / 4, -size.Y / 2, size.X, size.Y));
     drawingContext.DrawRectangle(Brushes.LightBlue, null, new Rect(size.X / 4 * 3 - 2, -size.Y / 2, 2, size.Y));
     drawingContext.Pop();
     drawingContext.Pop();
 }
    private void DrawTriangle(DrawingContext drawingContext, Point origin, double rotation)
    {
      drawingContext.PushTransform(new TranslateTransform(origin.X, origin.Y));
      drawingContext.PushTransform(new RotateTransform(rotation));

      drawingContext.DrawGeometry(m_Pen.Brush, null, m_Triangle);

      drawingContext.Pop();
      drawingContext.Pop();
    }
Ejemplo n.º 8
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            Metric metric = Visual as Metric;

            if (metric != null)
            {
                drawingContext.PushTransform(new TranslateTransform(metric.MetricTranslationX, metric.MetricTranslationY));
                drawingContext.PushTransform(new RotateTransform(metric.MetricRotation, _center.X, _center.Y - metric.MetricTranslationY));
                drawingContext.DrawImage(_image, _imageRect);
                drawingContext.Pop( );
            }
        }
 /// <summary>This method performs the actual render operation to show a text label</summary>
 /// <param name="dc">Drawing context</param>
 /// <param name="info">Render info</param>
 /// <param name="scale">The scale.</param>
 /// <param name="offset">The offset.</param>
 public virtual void RenderHeader(DrawingContext dc, AutoHeaderTextRenderInfo info, double scale, Point offset)
 {
     dc.PushTransform(new TranslateTransform(offset.X, offset.Y));
     dc.PushTransform(new ScaleTransform(scale, scale));
     dc.PushClip(new RectangleGeometry(info.RenderRect));
     info.FormattedText.SetMaxTextWidths(new[] { info.RenderRect.Width });
     info.FormattedText.MaxLineCount = 1;
     info.FormattedText.Trimming = TextTrimming.CharacterEllipsis;
     dc.DrawText(info.FormattedText, info.RenderRect.TopLeft);
     dc.Pop();
     dc.Pop();
     dc.Pop();
 }
Ejemplo n.º 10
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            AnimationControl();
            var width = Width < 1 ? 1 : Width;
            drawingContext.PushTransform(new TranslateTransform(RenderSize.Width / 2, RenderSize.Height / 2));

            for (int i = 0; i < c_Blobs; i++)
            {
                drawingContext.PushTransform(new RotateTransform((360 / c_Blobs) * i));
                drawingContext.DrawRectangle(m_Brushes[i], null, new Rect(0, width / 4.25, width / 16.0, width / 4.0));
                drawingContext.Pop();
            }
            drawingContext.Pop();
        }
 /// <summary>This method draws a rectangular background around a group of elements</summary>
 /// <param name="dc">The drawing context.</param>
 /// <param name="info">Render info</param>
 /// <param name="scale">The scale.</param>
 /// <param name="offset">The offset.</param>
 public virtual void RenderBackground(DrawingContext dc, GroupBackgroundRenderInfo info, double scale, Point offset)
 {
     dc.PushTransform(new TranslateTransform(offset.X, offset.Y));
     dc.PushTransform(new ScaleTransform(scale, scale));
     dc.DrawRectangle(info.Background, null, info.RenderRect);
     if (info.Border != null && info.BorderWidth > 0)
     {
         var rect2 = new Rect(info.RenderRect.X + (info.BorderWidth/2),
                              info.RenderRect.Y + (info.BorderWidth/2),
                              info.RenderRect.Width + info.BorderWidth,
                              info.RenderRect.Height + info.BorderWidth);
         dc.DrawRectangle(null, new Pen(info.Border, info.BorderWidth), rect2);
     }
     dc.Pop();
     dc.Pop();
 }
Ejemplo n.º 12
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            PushButton pushButton = Visual as PushButton;
            if (pushButton.Pushed && _pushedImage != null)
            {
                drawingContext.DrawImage(_pushedImage, _imageRect);
            }
            else if (_image != null)
            {
                drawingContext.DrawImage(_image, _imageRect);
            }

            if (pushButton.Pushed)
            {
                drawingContext.PushTransform(new TranslateTransform(pushButton.TextPushOffset.X, pushButton.TextPushOffset.Y));
            }

            if (pushButton.Glyph != PushButtonGlyph.None)
            {
                drawingContext.DrawGeometry(_glyphBrush, _glyphPen, _glyphPath);
            }
            pushButton.TextFormat.RenderText(drawingContext, _textBrush, pushButton.Text, _imageRect);

            if (pushButton.Pushed)
            {
                drawingContext.Pop();
            }
        }
 protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
 {
     System.Windows.Media.Media3D.Size3D size = (agentBase as TrainAgent).Size;
     for (int i = 0; i < (agentBase as TrainAgent).Positions.Length; i++)
     {
         if ((agentBase as TrainAgent).NeedDraw[i] == true)
         {
             Point position = (agentBase as TrainAgent).Positions[i];
             drawingContext.PushTransform(new TranslateTransform(position.X, position.Y));
             drawingContext.PushTransform(new RotateTransform((agentBase as TrainAgent).Angles[i]));
             drawingContext.DrawRectangle(GetGroupColor(agentBase.Group), null, new Rect(-size.X / 2, -size.Y / 2, size.X, size.Y));
             drawingContext.Pop();
             drawingContext.Pop();
         }
     }
 }
Ejemplo n.º 14
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            RotarySwitch rotarySwitch = Visual as RotarySwitch;

            if (rotarySwitch != null)
            {
                if (rotarySwitch.DrawLines)
                {
                    drawingContext.DrawDrawing(_lines);
                }
                foreach (SwitchPositionLabel label in _labels)
                {
                    drawingContext.DrawText(label.Text, label.Location);
                }

                drawingContext.PushTransform(new RotateTransform(rotarySwitch.KnobRotation, _center.X, _center.Y));
                drawingContext.DrawRectangle(_imageBrush, null, _imageRect);
                if (rotarySwitch.VisualizeDragging)
                {
                    double length = (rotarySwitch.DragPoint - _center).Length;
                    drawingContext.DrawLine(HeadingPen, _center, _center + new Vector(0d, -length));
                }
                drawingContext.Pop();

                if (rotarySwitch.VisualizeDragging)
                {
                    drawingContext.DrawLine(DragPen, _center, rotarySwitch.DragPoint);
                }
            }
        }
Ejemplo n.º 15
0
        protected override void DrawPointElement(DrawingContext dc, int Zoom)
        {
            if (Zoom > 12 || IsMouseOver)
            {
                string postLabelText = string.Format("{0}км", (double)Post.Ordinate / 1000);
                var postLabel = new FormattedText(postLabelText, CultureInfo.CurrentCulture,
                                                  FlowDirection.LeftToRight, new Typeface("Verdana"), 10, mainBrush);

                const int flagHeight = 22;
                dc.PushTransform(new TranslateTransform(0, -flagHeight));

                dc.DrawRectangle(Brushes.White, new Pen(mainBrush, 1), new Rect(-0.5, -0.5, Math.Round(postLabel.Width) + 5, Math.Round(postLabel.Height) + 2));
                dc.DrawText(postLabel, new Point(2, 0));
                dc.DrawLine(new Pen(mainBrush, 2), new Point(0, 0), new Point(0, flagHeight));

                dc.Pop();
            }

            if (Zoom > 8)
                dc.DrawEllipse(SectionBrush, new Pen(mainBrush, 1.5), new Point(0, 0), 5, 5);
            else
                dc.DrawRectangle(SectionBrush, null, new Rect(-2, -2, 4, 4));

            if (IsMouseOver)
            {
                dc.PushTransform(new TranslateTransform(3, 10));
                PrintStack(dc,
                           new FormattedText(Post.Direction == OrdinateDirection.Increasing ? "Возрастает по неч." : "Убывает по неч.",
                                             CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Verdana"), 10, Brushes.DarkBlue),
                           new FormattedText(String.Format("Пути: {0}", string.Join(", ", Post.Tracks.Select(TrackName))),
                                             CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Verdana"), 10, Brushes.DarkOliveGreen));
                dc.Pop();
            }
        }
Ejemplo n.º 16
0
		protected override void InnerDraw(DrawingContext drawingContext)
		{
			base.InnerDraw(drawingContext);
			drawingContext.PushTransform(_scaleTransform);
			drawingContext.DrawDrawing(_textDrawing);
			drawingContext.Pop();
		}
Ejemplo n.º 17
0
        private void RenderImportanceArrow(DrawingContext dc, FrameworkElement mostImportant, FrameworkElement leastImportant)
        {
            var startPoint = FindPoint(mostImportant, new Point(mostImportant.ActualWidth/2, mostImportant.ActualHeight));
            var endPoint = FindPoint(leastImportant, new Point(leastImportant.ActualWidth/2, 0));

            var vector = Point.Subtract(endPoint, startPoint);

            var midPoint = Point.Add(startPoint, Vector.Multiply(vector, 0.66));

            Transform arrowTransform = Transform.Identity;
            double angle;
            if (Math.Abs((angle = Vector.AngleBetween(vector, new Vector(0, -1))) - 0) > double.Epsilon)
            {
                arrowTransform = new RotateTransform(angle, midPoint.X, midPoint.Y);
            }

            var line = BuildPath.From(startPoint).LineTo(endPoint.X, endPoint.Y).Build();
            var arrow = BuildPath.From(midPoint.X - 3, midPoint.Y - 3).LineTo(midPoint.X, midPoint.Y)
                .LineTo(midPoint.X + 3, midPoint.Y - 3).Build();

            dc.DrawGeometry(null, _pen, line);

            dc.PushTransform(arrowTransform);

            dc.DrawGeometry(null, _pen, arrow);

            dc.Pop();
        }
Ejemplo n.º 18
0
		protected override void OnRender(DrawingContext drawingContext)
		{
			base.OnRender(drawingContext);

			if (AdornedElement.RenderSize.Width < 20)
				return;

			drawingContext.PushTransform(
					 new TranslateTransform(
						 AdornedElement.RenderSize.Width - 15,
						(AdornedElement.RenderSize.Height - 5) / 2));

			if (IsSecondaryAdorner)
			{
				drawingContext.DrawGeometry(null, new Pen(Brushes.Black, 0.5),
						Direction == ListSortDirection.Ascending ?
							_AscGeometry : _DescGeometry);
			}
			else
			{
				drawingContext.DrawGeometry(Brushes.Black, null,
						Direction == ListSortDirection.Ascending ?
							_AscGeometry : _DescGeometry);
			}

			drawingContext.Pop();
		}
Ejemplo n.º 19
0
 protected override void ApplyFilter(FastBitmap source, DrawingContext dc, int width, int height)
 {
     Vector offsetSize = GetOffsetSize() + new Vector(Size, Size);
     dc.PushTransform(new TranslateTransform(offsetSize.X, offsetSize.Y));
     base.ApplyFilter(source, dc, width, height);
     dc.Pop();
 }
Ejemplo n.º 20
0
        /// <summary>
        /// Applies the <see cref="ShinyFloorFilter" /> to the specified <paramref name="source"/>.
        /// </summary>
        /// <param name="source">The source image.</param>
        /// <param name="dc"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        protected override void ApplyFilter(FastBitmap source, DrawingContext dc, int width, int height)
        {
            // First, draw reflected image with an opacity mask.
            int reflectionHeight = (int)(source.Height * (ReflectionPercentage / 100.0f));
            dc.PushTransform(new TransformGroup
            {
                Children = new TransformCollection
                {
                    new ScaleTransform {ScaleY = -1},
                    new TranslateTransform {Y = GetReflectionOffsetY(source) + reflectionHeight}
                }
            });
            dc.PushOpacityMask(new LinearGradientBrush(
                Colors.Transparent,
                Color.FromArgb((byte)(255.0f * (ReflectionOpacity / 100.0f)), 0, 0, 0),
                new Point(0, 0),
                new Point(0, 1)));

            dc.DrawImage(new CroppedBitmap(source.InnerBitmap, new Int32Rect(0, source.Height - reflectionHeight, source.Width, reflectionHeight)),
                new Rect(0, 0, source.Width, reflectionHeight));

            dc.Pop();
            dc.Pop();

            // Draw original image.
            dc.DrawImage(source.InnerBitmap, new Rect(0, 0, source.Width, source.Height));
        }
Ejemplo n.º 21
0
 protected override void Draw(DrawingContext dc, int Zoom)
 {
     Point elementPoint = Projector.Project(Position, Zoom);
     dc.PushTransform(new TranslateTransform(elementPoint.X, elementPoint.Y));
     DrawPointElement(dc, Zoom);
     dc.Pop();
 }
        protected override void OnRender(System.Windows.Media.DrawingContext dc)
        {
            RotateTransform RT = new RotateTransform();

            RT.Angle = -90;
            double        num           = this.Maximum - this.Minimum;
            double        y             = this.ReservedSpace * 0.5;
            FormattedText formattedText = null;
            double        x             = 0;

            for (double i = 0; i <= num; i += this.TickFrequency)
            {
                formattedText = new FormattedText(i.ToString(), System.Globalization.CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Verdana"), 8, Brushes.Black, 1);
                if (this.Minimum == i)
                {
                    x = 0;
                }
                else
                {
                    x += this.ActualWidth / (num / this.TickFrequency);
                }

                dc.PushTransform(RT);
                dc.DrawText(formattedText, new Point(-20, x));
                dc.Pop();
            }
        }
Ejemplo n.º 23
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            if (AdornedElement.RenderSize.Width < 20)
                return;

            TranslateTransform transform = new TranslateTransform
                    (
                            AdornedElement.RenderSize.Width - 15,
                            (AdornedElement.RenderSize.Height - 5) / 2
                    );
            transform = new TranslateTransform
                    (
                            AdornedElement.RenderSize.Width / 2 - 3.5,
                            AdornedElement.RenderSize.Height / 2 - 10
                    );
            drawingContext.PushTransform(transform);

            Geometry geometry = ascGeometry;
            if (this.Direction == ListSortDirection.Descending)
                geometry = descGeometry;
            drawingContext.DrawGeometry(Brushes.LightGray, null, geometry);

            drawingContext.Pop();
        }
Ejemplo n.º 24
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            if (ParentMap != null)
            {
                var bounds = ParentMap.ViewportTransform.Inverse.TransformBounds(new Rect(ParentMap.RenderSize));
                var start = ParentMap.MapTransform.Transform(new Point(bounds.X, bounds.Y));
                var end = ParentMap.MapTransform.Transform(new Point(bounds.X + bounds.Width, bounds.Y + bounds.Height));
                var minSpacing = MinLineSpacing * 360d / (Math.Pow(2d, ParentMap.ZoomLevel) * TileSource.TileSize);
                var spacing = LineSpacings[LineSpacings.Length - 1];

                if (spacing >= minSpacing)
                {
                    spacing = LineSpacings.FirstOrDefault(s => s >= minSpacing);
                }

                var latLabelStart = Math.Ceiling(start.Latitude / spacing) * spacing;
                var lonLabelStart = Math.Ceiling(start.Longitude / spacing) * spacing;
                var latLabels = new List<Label>((int)((end.Latitude - latLabelStart) / spacing) + 1);
                var lonLabels = new List<Label>((int)((end.Longitude - lonLabelStart) / spacing) + 1);
                var labelFormat = spacing < 1d ? "{0} {1}°{2:00}'" : "{0} {1}°";

                for (var lat = latLabelStart; lat <= end.Latitude; lat += spacing)
                {
                    latLabels.Add(new Label(lat, new FormattedText(
                        CoordinateString(lat, labelFormat, "NS"),
                        CultureInfo.InvariantCulture, FlowDirection.LeftToRight, Typeface, FontSize, Foreground)));

                    drawingContext.DrawLine(Pen,
                        ParentMap.LocationToViewportPoint(new Location(lat, start.Longitude)),
                        ParentMap.LocationToViewportPoint(new Location(lat, end.Longitude)));
                }

                for (var lon = lonLabelStart; lon <= end.Longitude; lon += spacing)
                {
                    lonLabels.Add(new Label(lon, new FormattedText(
                        CoordinateString(Location.NormalizeLongitude(lon), labelFormat, "EW"),
                        CultureInfo.InvariantCulture, FlowDirection.LeftToRight, Typeface, FontSize, Foreground)));

                    drawingContext.DrawLine(Pen,
                        ParentMap.LocationToViewportPoint(new Location(start.Latitude, lon)),
                        ParentMap.LocationToViewportPoint(new Location(end.Latitude, lon)));
                }

                foreach (var latLabel in latLabels)
                {
                    foreach (var lonLabel in lonLabels)
                    {
                        var position = ParentMap.LocationToViewportPoint(new Location(latLabel.Position, lonLabel.Position));

                        drawingContext.PushTransform(new RotateTransform(ParentMap.Heading, position.X, position.Y));
                        drawingContext.DrawText(latLabel.Text,
                            new Point(position.X + StrokeThickness / 2d + 2d, position.Y - StrokeThickness / 2d - latLabel.Text.Height));
                        drawingContext.DrawText(lonLabel.Text,
                            new Point(position.X + StrokeThickness / 2d + 2d, position.Y + StrokeThickness / 2d));
                        drawingContext.Pop();
                    }
                }
            }
        }
        protected override void OnRender(DrawingContext drawingContext)
        {
            if (this.textBoxHasSelection)
            {
                // up button
                drawingContext.PushTransform(new TranslateTransform(this.x, this.top));
                drawingContext.PushTransform(new ScaleTransform(1, -1));
                drawingContext.DrawGeometry(TextBoxUpDownAdorner.Fill, TextBoxUpDownAdorner.Outline, this.triangle);
                drawingContext.Pop();
                drawingContext.Pop();

                // down button
                drawingContext.PushTransform(new TranslateTransform(this.x, this.bottom));
                drawingContext.DrawGeometry(TextBoxUpDownAdorner.Fill, TextBoxUpDownAdorner.Outline, this.triangle);
                drawingContext.Pop();
            }
        }
Ejemplo n.º 26
0
        protected override void ApplyFilter(FastBitmap source, DrawingContext dc, int width, int height)
        {
            // Draw border.
            dc.DrawRectangle(Fill.GetBrush(), null, new Rect(0, 0, width, height));

            // Draw image.
            dc.PushTransform(new TranslateTransform(Width, Width));
            dc.DrawImage(source.InnerBitmap, new Rect(0, 0, source.Width, source.Height));
            dc.Pop();
        }
Ejemplo n.º 27
0
        public void Render(DrawingContext dc, Size renderSize, TileRenderContext ctx)
        {
            dc.DrawRectangle(Brushes.Black, null, new Rect(0, 0, renderSize.Width, renderSize.Height));

            dc.PushTransform(new TranslateTransform(ctx.RenderOffset.X, ctx.RenderOffset.Y));
            dc.PushTransform(new ScaleTransform(ctx.TileSize, ctx.TileSize));

            for (int y = 0; y < ctx.RenderGridSize.Height && y < m_renderData.Height; ++y)
            {
                for (int x = 0; x < ctx.RenderGridSize.Width && x < m_renderData.Width; ++x)
                {
                    dc.PushTransform(new TranslateTransform(x, y));
                    RenderTile(dc, x, y);
                    dc.Pop();
                }
            }

            dc.Pop();
            dc.Pop();
        }
Ejemplo n.º 28
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            if (AdornedElement.RenderSize.Width < 20) return;

            var transform = new TranslateTransform(AdornedElement.RenderSize.Width - 15, (AdornedElement.RenderSize.Height - 5) / 2);
            drawingContext.PushTransform(transform);

            Geometry geometry = (this.Direction == ListSortDirection.Descending ? descGeometry : ascGeometry);
            drawingContext.DrawGeometry(Brushes.Black, null, geometry);
            drawingContext.Pop();
        }
Ejemplo n.º 29
0
        protected override void DrawPointElement(DrawingContext dc, int Zoom)
        {
            dc.DrawRectangle(Brushes.Chocolate, new Pen(Brushes.White, 2), new Rect(-0.5 * Width, -0.5 * Height, Width, Height));

            var nameLabel = new FormattedText(Target.Name, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Verdana"), 10, Brushes.DarkRed);
            var ordinateLabel = new FormattedText(OrdinateString, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Verdana"), 8, Brushes.DarkRed);

            dc.PushTransform(new TranslateTransform(-0.5 * Math.Max((double)nameLabel.Width, ordinateLabel.Width), 0.5 * Height + 3));
            PrintStack(dc, nameLabel, ordinateLabel);
            dc.Pop();
        }
Ejemplo n.º 30
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            Point povCenter = new Point(ActualHeight / 2d, ActualWidth / 2d);

            drawingContext.DrawEllipse(null, _linePen, povCenter, povCenter.X - 5d, povCenter.Y - 5d);
            drawingContext.DrawEllipse(_lineBrush, null, povCenter, 5, 5);

            if (Direction == POVDirection.Center)
            {
                drawingContext.DrawEllipse(_activePositionBrush, null, povCenter, 4, 4);
            }
            else
            {
                drawingContext.PushTransform(new RotateTransform((double)Direction, povCenter.X, povCenter.Y));
                drawingContext.PushTransform(new TranslateTransform(povCenter.X - 5, 0));
                drawingContext.DrawGeometry(_activePositionBrush, null, _arrowPath);
                drawingContext.Pop();
                drawingContext.Pop();
            }
        }
Ejemplo n.º 31
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            Rotary rotary = Visual as Rotary;

            if (rotary != null)
            {
                drawingContext.PushTransform(new RotateTransform(rotary.KnobRotation, _center.X, _center.Y));
                drawingContext.DrawImage(_image, _imageRect);
                drawingContext.Pop();
            }
        }
Ejemplo n.º 32
0
        public override void Draw(DrawingContext drawingContext, double scale, double x, double y)
        {
            this.BaseBox.Draw(drawingContext, scale, x, y);

            if (this.Over)
            {
                // Draw delimeter and script boxes over base box.
                var centerY = y - this.BaseBox.Height - this.DelimeterBox.Width;
                var translationX = x + this.DelimeterBox.Width / 2;
                var translationY = centerY + this.DelimeterBox.Width / 2;

                drawingContext.PushTransform(new TranslateTransform(translationX * scale, translationY * scale));
                drawingContext.PushTransform(new RotateTransform(90));
                this.DelimeterBox.Draw(drawingContext, scale, -this.DelimeterBox.Width / 2,
                    -this.DelimeterBox.Depth + this.DelimeterBox.Width / 2);
                drawingContext.Pop();
                drawingContext.Pop();

                // Draw script box as superscript.
                if (this.ScriptBox != null)
                    this.ScriptBox.Draw(drawingContext, scale, x, centerY - this.Kern - this.ScriptBox.Depth);
            }
            else
            {
                // Draw delimeter and script boxes under base box.
                var centerY = y + this.BaseBox.Depth + this.DelimeterBox.Width;
                var translationX = x + this.DelimeterBox.Width / 2;
                var translationY = centerY - this.DelimeterBox.Width / 2;

                drawingContext.PushTransform(new TranslateTransform(translationX * scale, translationY * scale));
                drawingContext.PushTransform(new RotateTransform(90));
                this.DelimeterBox.Draw(drawingContext, scale, -this.DelimeterBox.Width / 2,
                    -this.DelimeterBox.Depth + this.DelimeterBox.Width / 2);
                drawingContext.Pop();
                drawingContext.Pop();

                // Draw script box as subscript.
                if (this.ScriptBox != null)
                    this.ScriptBox.Draw(drawingContext, scale, x, centerY + this.Kern + this.ScriptBox.Height);
            }
        }
Ejemplo n.º 33
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            TransformGroup transform = new TransformGroup();

            transform.Children.Add(new TranslateTransform((-_center.X + HorizontalOffset) * _xScale, (-_center.Y + VerticalOffset) * _yScale));
            transform.Children.Add(new RotateTransform(_rotation + _baseRotation));
            transform.Children.Add(new TranslateTransform(_location.X * _xScale, _location.Y * _yScale));

            drawingContext.PushTransform(transform);
            drawingContext.DrawImage(_image, _rectangle);
            drawingContext.Pop();
        }
Ejemplo n.º 34
0
        protected override void ApplyFilter(FastBitmap source, DrawingContext dc, int width, int height)
        {
            // Draw image.
            dc.PushTransform(new TranslateTransform(BorderWidth, BorderWidth));
            dc.DrawImage(source.InnerBitmap, new Rect(0, 0, source.Width, source.Height));
            dc.Pop();

            // Draw border.
            dc.DrawRoundedRectangle(null, new Pen(new SolidColorBrush(BorderColor), BorderWidth),
                new Rect(BorderWidth / 2.0, BorderWidth / 2.0, width - BorderWidth, height - BorderWidth),
                Roundness, Roundness);
        }
Ejemplo n.º 35
0
		//private const int Margin = 3;
		protected override void InnerDraw(DrawingContext drawingContext)
		{
			base.InnerDraw(drawingContext);
			if (_scaleTransform != null)
				drawingContext.PushTransform(_scaleTransform);
			if (_clipGeometry != null)
				drawingContext.PushClip(_clipGeometry);
			drawingContext.DrawDrawing(_textDrawing);
			if (_clipGeometry != null)
				drawingContext.Pop();
			if (_scaleTransform != null)
				drawingContext.Pop();
		}
Ejemplo n.º 36
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            double x = AdornedElement.RenderSize.Width - 20;
            double y = (AdornedElement.RenderSize.Height - 5) / 2;

            if (x >= 20)
            {
                // Right order of the statements is important
                drawingContext.PushTransform(new TranslateTransform(x, y));
                drawingContext.DrawGeometry(Brushes.Black, null, _sortDirection);
                drawingContext.Pop();
            }
        }
Ejemplo n.º 37
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            double x = AdornedElement.RenderSize.Width - 12;
            double y = (AdornedElement.RenderSize.Height - 8) / 2;

            if (x >= 10)
            {
                // Right order of the statements is important
                drawingContext.PushTransform(new TranslateTransform(x, y));
                drawingContext.DrawGeometry(brush, pen, direction);
                drawingContext.Pop();
            }
        }
Ejemplo n.º 38
0
 /// <summary>
 /// Applies the <see cref="RotationFilter" /> to the specified <paramref name="source"/>.
 /// </summary>
 protected override void ApplyFilter(FastBitmap source, DrawingContext dc, int width, int height)
 {
     dc.PushTransform(new TransformGroup
     {
         Children = new TransformCollection
         {
             _rotateTransform,
             new TranslateTransform((width - source.Width) / 2.0, (height - source.Height) / 2.0)
         }
     });
     dc.DrawImage(source.InnerBitmap, new Rect(0, 0, source.Width, source.Height));
     dc.Pop();
 }
Ejemplo n.º 39
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            if (AdornedElement.RenderSize.Width < 14)
            {
                return;
            }

            drawingContext.PushTransform( new TranslateTransform( AdornedElement.RenderSize.Width - 12, (AdornedElement.RenderSize.Height - 4) / 2));
            drawingContext.DrawGeometry (this.PaintBrush, null, SortDirection == ListSortDirection.Ascending ? m_AscGeometry : m_DescGeometry);

            drawingContext.Pop();
        }
Ejemplo n.º 40
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            _scopeBrush = new SolidColorBrush(Color.FromRgb(255, 0, 0));
            Pen _scopePen = new Pen(_scopeBrush, 1d);


            CustomNeedle customNeedle = Visual as CustomNeedle;

            if (customNeedle != null)
            {
                drawingContext.DrawImage(_bgplate_image, _bgplate_imageRect);

                drawingContext.PushTransform(new RotateTransform(customNeedle.KnobRotation, _center.X, _center.Y));
                drawingContext.DrawImage(_image, _imageRect);
                drawingContext.DrawLine(_scopePen, _center, _punto); //draw rotation point for reference
                drawingContext.Pop();
            }
        }
Ejemplo n.º 41
0
        ImageSource RenderFrame(ApplicationContext actx, double scaleFactor, ImageDescription idesc)
        {
            SWM.DrawingVisual visual = new SWM.DrawingVisual();
            using (SWM.DrawingContext ctx = visual.RenderOpen()) {
                ctx.PushTransform(new ScaleTransform(scaleFactor, scaleFactor));
                Draw(actx, ctx, scaleFactor, 0, 0, idesc);
                ctx.Pop();
            }

            SWMI.RenderTargetBitmap bmp = new SWMI.RenderTargetBitmap((int)(idesc.Size.Width * scaleFactor), (int)(idesc.Size.Height * scaleFactor), 96, 96, PixelFormats.Pbgra32);
            bmp.Render(visual);

            var f = new ImageFrame(bmp, idesc.Size.Width, idesc.Size.Height);

            if (drawCallback == null)
            {
                AddFrame(f);
            }
            return(bmp);
        }
Ejemplo n.º 42
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            RotaryKnob rotary = Visual as RotaryKnob;

            if (rotary != null)
            {
                drawingContext.PushTransform(new RotateTransform(rotary.KnobRotation, _center.X, _center.Y));
                drawingContext.DrawImage(_image, _imageRect);
                if (rotary.VisualizeDragging)
                {
                    double length = (rotary.DragPoint - _center).Length;
                    drawingContext.DrawLine(HeadingPen, _center, _center + new Vector(0d, -length));
                }
                drawingContext.Pop();

                if (rotary.VisualizeDragging)
                {
                    drawingContext.DrawLine(DragPen, _center, rotary.DragPoint);
                }
            }
        }
Ejemplo n.º 43
0
        ImageSource RenderFrame(ApplicationContext actx, double scaleFactor, double width, double height)
        {
            ImageDescription idesc = new ImageDescription()
            {
                Alpha = 1,
                Size  = new Size(width, height)
            };

            SWM.DrawingVisual visual = new SWM.DrawingVisual();
            using (SWM.DrawingContext ctx = visual.RenderOpen()) {
                ctx.PushTransform(new ScaleTransform(scaleFactor, scaleFactor));
                Draw(actx, ctx, scaleFactor, 0, 0, idesc);
                ctx.Pop();
            }

            SWMI.RenderTargetBitmap bmp = new SWMI.RenderTargetBitmap((int)(width * scaleFactor), (int)(height * scaleFactor), 96, 96, PixelFormats.Pbgra32);
            bmp.Render(visual);

            var f = new ImageFrame(bmp, width, height);

            AddFrame(f);
            return(bmp);
        }
Ejemplo n.º 44
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            drawingContext.PushTransform(new ScaleTransform(_scaleX, _scaleY));

            drawingContext.DrawEllipse(Brushes.Black, null, _center, 187d, 187d);

            if (_rwr != null && _rwr.IsOn)
            {
                bool primary = DateTime.Now.Millisecond < 500;

                // Draw heart beat lines
                drawingContext.DrawLine(_scopePen, new Point(160d, 193.5), new Point(180d, 193.5d));
                drawingContext.DrawLine(_scopePen, new Point(220d, 193.5), new Point(240d, 193.5d));
                drawingContext.DrawLine(_scopePen, new Point(200d, 153.5), new Point(200d, 173.5));
                drawingContext.DrawLine(_scopePen, new Point(200d, 213.5), new Point(200d, 233.5));
                if (primary)
                {
                    drawingContext.DrawLine(_scopePen, new Point(220d, 193.5d), new Point(220d, 203.5d));
                }
                else
                {
                    drawingContext.DrawLine(_scopePen, new Point(220d, 183.5d), new Point(220d, 193.5d));
                }

                if (_rwr.Contacts != null)
                {
                    foreach (RadarContact contact in _rwr.Contacts)
                    {
                        if (contact.Visible)
                        {
                            double y = 0.0f;
                            if (contact.Lethality > 1f)
                            {
                                y = -((2.0f - contact.Lethality) * 178.0d);
                            }
                            else
                            {
                                //lethality values range in 1 = lowest priority to .01 = highest priority
                                //substract -(1.0f - contact.Lethality) * 178.0d) from the elipse radious (187d) to get the inverse value
                                //so that the symbol maps into the correct threat ring
                                y = -(187d - ((1.0f - contact.Lethality) * 178.0d));
                            }

                            drawingContext.PushTransform(new RotateTransform(contact.RelativeBearing));
                            drawingContext.PushTransform(new TranslateTransform(0d, y));
                            drawingContext.PushTransform(new RotateTransform(-contact.RelativeBearing));

                            if (contact.NewDetection && !primary)
                            {
                                _format.FontSize = 24;
                            }
                            else
                            {
                                _format.FontSize = 22;
                            }

                            DrawContactSymbol(drawingContext, contact, primary);

                            if (contact.Selected)
                            {
                                drawingContext.DrawLine(_scopePen, new Point(200d, 168.5d), new Point(225d, 193.5d));
                                drawingContext.DrawLine(_scopePen, new Point(225d, 193.5d), new Point(200d, 218.5d));
                                drawingContext.DrawLine(_scopePen, new Point(200d, 218.5d), new Point(175d, 193.5d));
                                drawingContext.DrawLine(_scopePen, new Point(175d, 193.5d), new Point(200d, 168.5d));
                            }

                            if ((contact.MissileActivity && !contact.MissileLaunch) ||
                                (contact.MissileActivity && contact.MissileLaunch && _rwr.Flash4Hz))
                            {
                                drawingContext.DrawEllipse(null, _scopePen, _center, 25, 25);
                            }

                            drawingContext.Pop();
                            drawingContext.Pop();
                            drawingContext.Pop();
                        }
                    }
                }
            }

            if (_bezelBrush != null)
            {
                drawingContext.DrawRectangle(_bezelBrush, null, _bezelRect);
            }

            drawingContext.Pop();
        }
Ejemplo n.º 45
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            if (_editor.SelectedItems.Count > 0)
            {
                Pen   rectPen     = _drawFocus ? SelectionRectPen : SelectionRectPenNoFocus;
                Brush circleBrush = _drawFocus ? SelectionResizeBrush : SelectionResizeBrushNoFocus;

                if (_isline)
                {
                    Point start;
                    Point end;

                    drawingContext.PushTransform(new ScaleTransform(_editor.ZoomFactor, _editor.ZoomFactor));
                    if (_editor.SnapManager.Action == SnapAction.LineStart || _editor.SnapManager.Action == SnapAction.LineEnd)
                    {
                        drawingContext.PushTransform(new TranslateTransform(_tempLine.Left, _tempLine.Top));
                        _tempLine.Renderer.Render(drawingContext);
                        drawingContext.Pop();

                        start = _tempLine.Start;
                        end   = _tempLine.End;
                    }
                    else
                    {
                        Helios.Controls.LineDecoration line = _editor.SelectedItems[0] as Helios.Controls.LineDecoration;

                        start = line.Start;
                        end   = line.End;
                        if (_editor.SnapManager.Action == SnapAction.Move)
                        {
                            start += _editor.SnapManager.LocationOffset;
                            end   += _editor.SnapManager.LocationOffset;
                            _tempLine.Clone(line);

                            drawingContext.PushTransform(new TranslateTransform(_tempLine.Left + _editor.SnapManager.LocationOffset.X, _tempLine.Top + _editor.SnapManager.LocationOffset.Y));
                            _tempLine.Renderer.Render(drawingContext);
                            drawingContext.Pop();
                        }
                    }
                    drawingContext.Pop();

                    start.X *= _editor.ZoomFactor;
                    start.Y *= _editor.ZoomFactor;
                    end.X   *= _editor.ZoomFactor;
                    end.Y   *= _editor.ZoomFactor;

                    drawingContext.DrawEllipse(circleBrush, rectPen, start, ResizeRadius, ResizeRadius);
                    drawingContext.DrawEllipse(circleBrush, rectPen, end, ResizeRadius, ResizeRadius);
                }
                else
                {
                    foreach (HeliosVisual visual in _editor.SelectedItems)
                    {
                        Rect visualRect = visual.DisplayRectangle;
                        visualRect.Scale(_editor.ZoomFactor, _editor.ZoomFactor);
                        drawingContext.DrawRectangle(null, SelectionBorderPen, visualRect);
                    }

                    Rect selectionRect = (_editor.SnapManager.Action != SnapAction.None && _editor.SnapManager.Action != SnapAction.Drop && _editor.SnapManager.IsValidDrag) ? _editor.SnapManager.NewRectangle : _editor.SelectedItems.Rectangle;
                    selectionRect.Scale(_editor.ZoomFactor, _editor.ZoomFactor);

                    drawingContext.DrawRectangle(null, rectPen, selectionRect);

                    drawingContext.DrawEllipse(circleBrush, rectPen, selectionRect.TopLeft, ResizeRadius, ResizeRadius);
                    drawingContext.DrawEllipse(circleBrush, rectPen, selectionRect.TopRight, ResizeRadius, ResizeRadius);
                    drawingContext.DrawEllipse(circleBrush, rectPen, selectionRect.BottomLeft, ResizeRadius, ResizeRadius);
                    drawingContext.DrawEllipse(circleBrush, rectPen, selectionRect.BottomRight, ResizeRadius, ResizeRadius);
                }
            }
        }
Ejemplo n.º 46
0
 public void PushTransform(Transform t)
 {
     Context.PushTransform(t);
     transforms.Children.Add(t);
     pushCount++;
 }
Ejemplo n.º 47
0
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            if (model == null)
            {
                return;
            }

            renderStopwatch.Restart();
            Pen forwardPen  = new Pen(Brushes.Silver, 1);
            Pen backwardPen = new Pen(Brushes.Pink, 1);
            Pen fixedPen    = new Pen(Brushes.Black, 1);

            foreach (var link in model.Links)
            {
                drawingContext.DrawLine(link.A.Position[0] < link.B.Position[0] ? forwardPen : backwardPen,
                                        transform.ToScreen(link.A.Position),
                                        transform.ToScreen(link.B.Position));
            }
            foreach (var particle in model.Particles)
            {
                DrawData drawData = particle.Tag as DrawData;
                if (drawData == null)
                {
                    drawData = new DrawData();
                    if (particle.FillColor.A != 0)
                    {
                        drawData.Brush = new SolidColorBrush(particle.FillColor);
                    }
                    if (particle.StrokeColor.A != 0)
                    {
                        drawData.Pen = new Pen(new SolidColorBrush(particle.StrokeColor), 1);
                    }
                    drawData.Pinned = particle.Fixed;
                    if (particle.Name != null)
                    {
                        drawData.Text = new FormattedText(particle.Name, CultureInfo.CurrentCulture,
                                                          FlowDirection.LeftToRight, textTypeface, textSize, Brushes.Black);
                    }
                    particle.Tag = drawData;
                }

                Point p = transform.ToScreen(particle.Position);
                drawingContext.DrawEllipse(drawData.Brush, drawData.Pen,
                                           p,
                                           ParticleSize,
                                           ParticleSize);
                if (drawData.Selected)
                {
                    drawingContext.DrawEllipse(null, fixedPen,
                                               p,
                                               ParticleSize * 1.3,
                                               ParticleSize * 1.3);
                }


                if (drawData.Text != null)
                {
                    drawingContext.DrawText(drawData.Text, p);
                }
                if (drawData.Pinned)
                {
                    //                    drawingContext.DrawRectangle(Brushes.Black, fixedPen, new Rect(0, 0, 8, 8));
                    drawingContext.PushTransform(new TranslateTransform(p.X, p.Y));
                    drawingContext.PushTransform(new ScaleTransform(ParticleSize / 8, ParticleSize / 8));
                    drawingContext.DrawGeometry(Brushes.LightCoral, fixedPen, pinImage);
                    drawingContext.Pop();
                    drawingContext.Pop();
                }
            }

            RenderElapsedTime = renderStopwatch.Elapsed.TotalSeconds;
            renderStopwatch.Restart();
        }
Ejemplo n.º 48
0
        private void RenderMeasurings(RenderArea arg1, DrawingVisual arg2, System.Windows.Media.DrawingContext arg3)
        {
            const double TH_DEFAULT = 1; const double RADIUS_ELLIPSE_DEFAULT = 3;
            double       stroke         = TH_DEFAULT;
            double       radius_ellipse = RADIUS_ELLIPSE_DEFAULT;

            var d = context;

            if (arg1 == renderAreaMagnifier)
            {
                if (!GetIsZoomEnabled())
                {
                    return;
                }

                arg3.PushTransform(GetMagnfierRenderAreaTransform());

                stroke         = TH_DEFAULT / MagnifierZoom;
                radius_ellipse = RADIUS_ELLIPSE_DEFAULT / MagnifierZoom;
            }



            foreach (var l in d.Lines)
            {
                arg3.DrawLine(new Pen(new SolidColorBrush(l.Color), stroke), l.P0, l.P1);
            }
            if (d.LinesUnderMouse.Length > 0)
            {
                var nl = d.LinesUnderMouse[0].Line;

                drawPointHighlighted(nl.P0, nl.Color, arg3, radius_ellipse, stroke);
                drawPointHighlighted(nl.P1, nl.Color, arg3, radius_ellipse, stroke);

                mouseOverLine_info.LineInfo   = nl;
                mouseOverLine_info.Foreground = new SolidColorBrush(nl.Color);
                mouseOverLine_info.Visibility = Visibility.Visible;
            }
            else
            {
                mouseOverLine_info.Visibility = Visibility.Hidden;
            }

            if (d.MousePosition.HasValue && d.TempPoint.HasValue)
            {
                var tempLine = new MeasureLine(d.MousePosition.Value, d.TempPoint.Value, d.CurrentColor);
                //drawLineText(1, tempLine, arg3);

                arg3.DrawLine(new Pen(new SolidColorBrush(tempLine.Color), stroke), tempLine.P0, tempLine.P1);
                currentLine_info.LineInfo   = tempLine;
                currentLine_info.Foreground = new SolidColorBrush(tempLine.Color);
                currentLine_info.Visibility = Visibility.Visible;
            }
            else
            {
                currentLine_info.Visibility = Visibility.Hidden;
            }

            if (d.MousePosition.HasValue)
            {
                drawPointHighlighted(d.MousePosition.Value, d.CurrentColor, arg3, radius_ellipse, stroke);
            }

            if (d.TempPoint.HasValue)
            {
                drawPointHighlighted(d.TempPoint.Value, d.CurrentColor, arg3, radius_ellipse, stroke);
            }
        }
Ejemplo n.º 49
0
        /// <summary>
        /// Draws the contours against a horizontal and vertical axis.
        /// </summary>
        /// <param name="dc">The drawing context on which to draw.</param>
        /// <param name="hAxis">The horizontal physical axis to draw against.</param>
        /// <param name="vAxis">The vertical physical axis to draw against.</param>
        public void Draw(System.Windows.Media.DrawingContext dc, HorizontalPhysicalAxis hAxis, VerticalPhysicalAxis vAxis)
        {
            double worldHorizontalRange = hAxis.Axis.WorldMax - hAxis.Axis.WorldMin;
            double worldVerticalRange   = vAxis.Axis.WorldMax - vAxis.Axis.WorldMin;

            for (int i = 0; i < _internalGridSize.Rows; ++i)
            {
                for (int j = 0; j < _internalGridSize.Columns; ++j)
                {
                    double worldY = (double)i / (double)(_internalGridSize.Rows - 1) * worldVerticalRange + vAxis.Axis.WorldMin;
                    double worldX = (double)j / (double)(_internalGridSize.Columns - 1) * worldHorizontalRange + hAxis.Axis.WorldMin;
                    _grid[i, j] = _fieldMethod(worldX, worldY);
                }
            }

            Pair <List <double>, List <List <LineSegment> > > contourGroups = ContourUtils.ContourGenCore.Generate(_grid, _levels);

            double physicalHorizontalRange = hAxis.PhysicalMaxX - hAxis.PhysicalMinX;
            double physicalVerticalRange   = vAxis.PhysicalMaxY - vAxis.PhysicalMinY;

            Pen p = new Pen(_stroke, _strokeThickness);

            for (int i = 0; i < contourGroups.First.Count; ++i)
            {
                List <LineSegment> lineSegments = contourGroups.Second[i];

                // find best index to put label.
                int bestJ = DetermineBestLabelPosition(lineSegments, 0, _internalGridSize.Columns - 1, 0, _internalGridSize.Rows - 1);

                // see if line segment sequence is reasonably long. If so, put a contour label on it.
                bool drawingLabel = false;
                if (_showContourLabels)
                {
                    double sum = 0.0;
                    for (int k = 0; k < lineSegments.Count; ++k)
                    {
                        sum += Math.Abs(lineSegments[k].X1 - lineSegments[k].X2) + Math.Abs(lineSegments[k].Y1 - lineSegments[k].Y2);
                        if (sum > _internalGridSize.Rows / 6.0)
                        {
                            drawingLabel = true;
                            break;
                        }
                    }
                }

                if (drawingLabel)
                {
                    LineSegment ls = lineSegments[bestJ];

                    double x1 = ls.X1 / (double)(_internalGridSize.Columns - 1) * physicalHorizontalRange + hAxis.PhysicalMinX;
                    double x2 = ls.X2 / (double)(_internalGridSize.Columns - 1) * physicalHorizontalRange + hAxis.PhysicalMinX;
                    double y1 = ls.Y1 / (double)(_internalGridSize.Rows - 1) * physicalVerticalRange + vAxis.PhysicalMinY;
                    double y2 = ls.Y2 / (double)(_internalGridSize.Rows - 1) * physicalVerticalRange + vAxis.PhysicalMinY;

                    FormattedText ft = new FormattedText(contourGroups.First[i].ToString(_contourLabelFormat),
                                                         System.Globalization.CultureInfo.CurrentCulture,
                                                         FlowDirection.LeftToRight, new Typeface("Arial"), 11, _stroke);

                    double angle = Math.Atan2(
                        contourGroups.Second[i][bestJ].Y1 - contourGroups.Second[i][bestJ].Y2,
                        contourGroups.Second[i][bestJ].X2 - contourGroups.Second[i][bestJ].X1) / Math.PI * 180.0;

                    if (angle > 90)
                    {
                        angle -= 180;
                    }
                    if (angle < -90)
                    {
                        angle += 180;
                    }

                    RotateTransform rt = new RotateTransform(angle);

                    dc.PushTransform(new TranslateTransform((x1 + x2) / 2.0, (y1 + y2) / 2.0));
                    dc.PushTransform(rt);
                    dc.DrawText(ft, new Point(-ft.Width / 2.0, -ft.Height / 2.0));
                    dc.Pop();
                    dc.Pop();

                    Rect r1 = new Rect(hAxis.PhysicalMinX, vAxis.PhysicalMaxY, hAxis.PhysicalMaxX - hAxis.PhysicalMinX, vAxis.PhysicalMinY - vAxis.PhysicalMaxY);
                    Rect r2 = new Rect((x1 + x2) / 2.0 - ft.Width * 1.6 / 2.0, (y1 + y2) / 2.0 - ft.Height * 1.6 / 2.0, ft.Width * 1.6, ft.Height * 1.6);

                    DrawingBrush db = new DrawingBrush();
                    db.ViewboxUnits  = BrushMappingMode.Absolute;
                    db.ViewportUnits = BrushMappingMode.Absolute;
                    db.Viewport      = r1;
                    db.Viewbox       = r1;

                    GeometryGroup gg = new GeometryGroup();
                    gg.FillRule = FillRule.Nonzero;

                    if (r2.Left - r1.Left > 0)
                    {
                        RectangleGeometry rg = new RectangleGeometry(new Rect(r1.Left, r1.Top, r2.Left - r1.Left, r1.Height));
                        gg.Children.Add(rg);
                    }
                    if (r1.Right - r2.Right > 0)
                    {
                        RectangleGeometry rg = new RectangleGeometry(new Rect(r2.Right, r1.Top, r1.Right - r2.Right, r1.Height));
                        gg.Children.Add(rg);
                    }
                    if (r2.Top - r1.Top > 0)
                    {
                        RectangleGeometry rg = new RectangleGeometry(new Rect(r1.Left, r1.Top, r1.Width, r2.Top - r1.Top));
                        gg.Children.Add(rg);
                    }
                    if (r1.Bottom - r2.Bottom > 0)
                    {
                        RectangleGeometry rg = new RectangleGeometry(new Rect(r1.Left, r2.Bottom, r1.Width, r1.Bottom - r2.Bottom));
                        gg.Children.Add(rg);
                    }

                    SolidColorBrush scb = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));
                    GeometryDrawing gd  = new GeometryDrawing(scb, null, gg);
                    db.Drawing = gd;

                    dc.PushOpacityMask(db);
                }

                for (int j = 0; j < lineSegments.Count; ++j)
                {
                    LineSegment ls = lineSegments[j];

                    double x1 = ls.X1 / (double)(_internalGridSize.Columns - 1) * physicalHorizontalRange + hAxis.PhysicalMinX;
                    double x2 = ls.X2 / (double)(_internalGridSize.Columns - 1) * physicalHorizontalRange + hAxis.PhysicalMinX;
                    double y1 = ls.Y1 / (double)(_internalGridSize.Rows - 1) * physicalVerticalRange + vAxis.PhysicalMinY;
                    double y2 = ls.Y2 / (double)(_internalGridSize.Rows - 1) * physicalVerticalRange + vAxis.PhysicalMinY;

                    dc.DrawLine(p, new Point(x1, y1), new Point(x2, y2));
                }

                if (drawingLabel)
                {
                    // pop opacity mask.
                    dc.Pop();
                }
            }
        }