Exemplo n.º 1
0
        protected void TestDrawing2(Xwt.Drawing.Context ctx, double x, double y)
        {
            ctx.Save();
            ctx.Translate(x, y);
            var arcColor = new Color(1, 0, 1);

            ctx.Arc(100, 100, 15, 0, 360);
            ctx.ClosePath();
            arcColor.Alpha = 0.4;
            ctx.SetColor(arcColor);
            ctx.StrokePreserve();
            ctx.Fill();

            ctx.Restore();
        }
Exemplo n.º 2
0
        public virtual void Curves1(Context ctx, double x, double y)
        {
            ctx.Save ();
            ctx.Translate (x, y);

            ctx.SetLineWidth (1);
            Action curve1 = () => {
                ctx.MoveTo (0, 30);
                ctx.CurveTo (20, 0, 50, 0, 60, 25);
            };
            // curve2 with lineTo; curve1 is closed
            Action curve2 = () => {
                ctx.LineTo (0, 0);
                ctx.CurveTo (20, 30, 50, 30, 60, 5);
            };
            Action paint = () => {
                curve1 ();
                curve2 ();
                ctx.ClosePath ();
                ctx.SetColor (new Color (0, 0, 0, .5));
                ctx.StrokePreserve ();
                ctx.SetColor (new Color (1, 0, 1, .5));
                ctx.Fill ();
            };
            paint ();

            ctx.Translate (0, 40);
            // curve2 with moveTo; curve1 is open
            curve2 = () => {
                ctx.MoveTo (0, 0);
                ctx.CurveTo (20, 30, 50, 30, 60, 5);
            };
            paint ();
            ctx.Restore ();

            //Todo: same stuff with arc
        }
Exemplo n.º 3
0
		public virtual void Rectangles (Context ctx, double x, double y)
		{
			ctx.Save ();
			ctx.Translate (x, y);
			
			// Simple rectangles
			
			ctx.SetLineWidth (1);
			ctx.Rectangle (0, 0, 10, 10);
			ctx.SetColor (Colors.Black);
			ctx.Fill ();
			
			ctx.Rectangle (15, 0, 10, 10);
			ctx.SetColor (Colors.Black);
			ctx.Stroke ();
			
			ctx.SetLineWidth (3);
			ctx.Rectangle (0, 15, 10, 10);
			ctx.SetColor (Colors.Black);
			ctx.Fill ();
			
			ctx.Rectangle (15, 15, 10, 10);
			ctx.SetColor (Colors.Black);
			ctx.Stroke ();
			
			ctx.Restore ();
			
			// Rectangle with hole
			ctx.Save ();
			ctx.Translate (x + 50, y);
			
			ctx.Rectangle (0, 0, 40, 40);
			ctx.MoveTo (35, 35);
			ctx.RelLineTo (0, -20);
			ctx.RelLineTo (-20, 0);
			ctx.RelLineTo (0, 20);
			ctx.ClosePath ();
			ctx.SetColor (Colors.Black);
			ctx.Fill ();
			
			ctx.Restore ();
			
			// Rounded Rectangle with Arcs
			ctx.Save ();
			ctx.Translate (x + 120, y);
			
			var r = 5;
			var l = 0;
			var t = 0;
			var w = 50;
			var h = 30;

			ctx.SetColor (Colors.Black);
			// top left  
			ctx.Arc (l + r, t + r, r, 180, 270);
			// top right 
			ctx.Arc (l + w - r, t + r, r, 270, 0);
			// bottom right  
			ctx.Arc (l + w - r, t + h - r, r, 0, 90);
			// bottom left 
			ctx.Arc (l + r, t + h - r, r, 90, 180);
			
			ctx.ClosePath ();
			ctx.StrokePreserve ();
			ctx.SetColor (Colors.AntiqueWhite);
			ctx.Fill ();
			ctx.Restore ();
		}
Exemplo n.º 4
0
        /// <summary>
        /// Draws the arrow on a plot surface.
        /// </summary>
        /// <param name="ctx">the Drawing Context with which to draw</param>
        /// <param name="xAxis">The X-Axis to draw against.</param>
        /// <param name="yAxis">The Y-Axis to draw against.</param>
        public void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis )
        {
            if (To.X > xAxis.Axis.WorldMax || To.X < xAxis.Axis.WorldMin) {
                return;
            }
            if (To.Y > yAxis.Axis.WorldMax || To.Y < yAxis.Axis.WorldMin) {
                return;
            }

            ctx.Save ();

            TextLayout layout = new TextLayout ();
            layout.Font = textFont_;
            layout.Text = text_;

            double angle = angle_;
            if (angle_ < 0.0) {
                int mul = -(int)(angle_ / 360.0) + 2;
                angle = angle_ + 360.0 * (double)mul;
            }

            double normAngle = (double)angle % 360.0;	// angle in range 0 -> 360.

            Point toPoint = new Point (
                xAxis.WorldToPhysical (to_.X, true).X,
                yAxis.WorldToPhysical (to_.Y, true).Y);

            double xDir = Math.Cos (normAngle * 2.0 * Math.PI / 360.0);
            double yDir = Math.Sin (normAngle * 2.0 * Math.PI / 360.0);

            toPoint.X += xDir*headOffset_;
            toPoint.Y += yDir*headOffset_;

            double xOff = physicalLength_ * xDir;
            double yOff = physicalLength_ * yDir;

            Point fromPoint = new Point(
                (int)(toPoint.X + xOff),
                (int)(toPoint.Y + yOff) );

            ctx.SetLineWidth (1);
            ctx.SetColor (arrowColor_);
            ctx.MoveTo (fromPoint);
            ctx.LineTo (toPoint);
            ctx.Stroke ();

            xOff = headSize_ * Math.Cos ((normAngle-headAngle_/2) * 2.0 * Math.PI / 360.0);
            yOff = headSize_ * Math.Sin ((normAngle-headAngle_/2) * 2.0 * Math.PI / 360.0);

            ctx.LineTo (toPoint.X + xOff, toPoint.Y + yOff);

            double xOff2 = headSize_ * Math.Cos ((normAngle+headAngle_/2) * 2.0 * Math.PI / 360.0);
            double yOff2 = headSize_ * Math.Sin ((normAngle+headAngle_/2) * 2.0 * Math.PI / 360.0);

            ctx.LineTo (toPoint.X + xOff2, toPoint.Y + yOff2);
            ctx.LineTo (toPoint);
            ctx.ClosePath ();
            ctx.SetColor (arrowColor_);
            ctx.Fill ();

            Size textSize = layout.GetSize ();
            Size halfSize = new Size (textSize.Width/2, textSize.Height/2);

            double quadrantSlideLength = halfSize.Width + halfSize.Height;

            double quadrantD = normAngle / 90.0;		// integer part gives quadrant.
            int quadrant = (int)quadrantD;				// quadrant in.
            double prop = quadrantD - (double)quadrant;	// proportion of way through this qadrant.
            double dist = prop * quadrantSlideLength;	// distance along quarter of bounds rectangle.

            // now find the offset from the middle of the text box that the
            // rear end of the arrow should end at (reverse this to get position
            // of text box with respect to rear end of arrow).
            //
            // There is almost certainly an elgant way of doing this involving
            // trig functions to get all the signs right, but I'm about ready to
            // drop off to sleep at the moment, so this blatent method will have
            // to do.
            Point offsetFromMiddle = new Point (0, 0);
            switch (quadrant) {
            case 0:
                if (dist > halfSize.Height) {
                    dist -= halfSize.Height;
                    offsetFromMiddle = new Point ( -halfSize.Width + dist, halfSize.Height );
                }
                else {
                    offsetFromMiddle = new Point ( -halfSize.Width, - dist );
                }
                break;
            case 1:
                if (dist > halfSize.Width) {
                    dist -= halfSize.Width;
                    offsetFromMiddle = new Point ( halfSize.Width, halfSize.Height - dist );
                }
                else {
                    offsetFromMiddle = new Point ( dist, halfSize.Height );
                }
                break;
            case 2:
                if (dist > halfSize.Height) {
                    dist -= halfSize.Height;
                    offsetFromMiddle = new Point ( halfSize.Width - dist, -halfSize.Height );
                }
                else {
                    offsetFromMiddle = new Point ( halfSize.Width, -dist );
                }
                break;
            case 3:
                if (dist > halfSize.Width) {
                    dist -= halfSize.Width;
                    offsetFromMiddle = new Point ( -halfSize.Width, -halfSize.Height + dist );
                }
                else {
                    offsetFromMiddle = new Point ( -dist, -halfSize.Height );
                }
                break;
            default:
                throw new XwPlotException( "Programmer error." );
            }

            ctx.SetColor (textColor_);
            double x = fromPoint.X - halfSize.Width - offsetFromMiddle.X;
            double y = fromPoint.Y - halfSize.Height + offsetFromMiddle.Y;
            ctx.DrawTextLayout (layout, x, y);

            ctx.Restore ();
        }
Exemplo n.º 5
0
		public static void DrawRoundRectangle (Context cr, double x, double y, double r, double w, double h)
		{
			const double ARC_TO_BEZIER = 0.55228475;
			double radius_x = r;
			double radius_y = r / 4;
			
			if (radius_x > w - radius_x)
				radius_x = w / 2;
					
			if (radius_y > h - radius_y)
				radius_y = h / 2;
			
			double c1 = ARC_TO_BEZIER * radius_x;
			double c2 = ARC_TO_BEZIER * radius_y;
			
			cr.NewPath ();
			cr.MoveTo (x + radius_x, y);
			cr.RelLineTo (w - 2 * radius_x, 0.0);
			cr.RelCurveTo (c1, 0.0, radius_x, c2, radius_x, radius_y);
			cr.RelLineTo (0, h - 2 * radius_y);
			cr.RelCurveTo (0.0, c2, c1 - radius_x, radius_y, -radius_x, radius_y);
			cr.RelLineTo (-w + 2 * radius_x, 0);
			cr.RelCurveTo (-c1, 0, -radius_x, -c2, -radius_x, -radius_y);
			cr.RelLineTo (0, -h + 2 * radius_y);
			cr.RelCurveTo (0.0, -c2, radius_x - c1, -radius_y, radius_x, -radius_y);
			cr.ClosePath ();
		}
Exemplo n.º 6
0
        protected override void OnDraw(Xwt.Drawing.Context ctx)
        {
            base.OnDraw(ctx);

            // Simple rectangles

            ctx.SetLineWidth(1);
            ctx.Rectangle(100, 5, 10, 10);
            ctx.SetColor(Color.Black);
            ctx.Fill();

            ctx.Rectangle(115, 5, 10, 10);
            ctx.SetColor(Color.Black);
            ctx.Stroke();

            //

            ctx.SetLineWidth(3);
            ctx.Rectangle(100, 20, 10, 10);
            ctx.SetColor(Color.Black);
            ctx.Fill();

            ctx.Rectangle(115, 20, 10, 10);
            ctx.SetColor(Color.Black);
            ctx.Stroke();

            // Rectangle with hole

            ctx.Rectangle(10, 100, 40, 40);
            ctx.MoveTo(45, 135);
            ctx.RelLineTo(0, -20);
            ctx.RelLineTo(-20, 0);
            ctx.RelLineTo(0, 20);
            ctx.ClosePath();
            ctx.SetColor(Color.Black);
            ctx.Fill();

            // Dashed lines

            ctx.SetLineDash(15, 10, 10, 5, 5);
            ctx.Rectangle(100, 100, 100, 100);
            ctx.Stroke();
            ctx.SetLineDash(0);

            ImageBuilder ib = new ImageBuilder(30, 30, ImageFormat.ARGB32);

            ib.Context.Arc(15, 15, 15, 0, 360);
            ib.Context.SetColor(new Color(1, 0, 1));
            ib.Context.Rectangle(0, 0, 5, 5);
            ib.Context.Fill();
            var img = ib.ToImage();

            ctx.DrawImage(img, 90, 90);
            ctx.DrawImage(img, 90, 140, 50, 10);

            ctx.Arc(190, 190, 15, 0, 360);
            ctx.SetColor(new Color(1, 0, 1, 0.4));
            ctx.Fill();

            ctx.Save();
            ctx.Translate(90, 220);
            ctx.Pattern = new ImagePattern(img);
            ctx.Rectangle(0, 0, 100, 70);
            ctx.Fill();
            ctx.Restore();

            ctx.Translate(30, 30);
            double end = 270;

            for (double n = 0; n <= end; n += 5)
            {
                ctx.Save();
                ctx.Rotate(n);
                ctx.MoveTo(0, 0);
                ctx.RelLineTo(30, 0);
                double c = n / end;
                ctx.SetColor(new Color(c, c, c));
                ctx.Stroke();
                ctx.Restore();
            }

            ctx.ResetTransform();
        }
Exemplo n.º 7
0
        protected override void OnDraw(Context ctx, Rectangle dirtyRect)
        {
            base.OnDraw(ctx, dirtyRect);

            if (image != null) {
                if (Heighlighted && IsThumbnail) {
                    ctx.RoundRectangle(new Rectangle(Point.Zero, image.Size), 3);
                    ctx.SetColor(Colors.LightSteelBlue);
                    ctx.Fill();
                }

                ctx.DrawImage(image, (new Rectangle(Point.Zero, image.Size)).Inflate(-3, -3));

                if (mask != null && ShowMask) {
                    ctx.DrawImage(MaskBitmap, (new Rectangle(Point.Zero, image.Size)).Inflate(-3, -3), 0.6);
                }
            }

            if (isEditMode) {
                Point scaleFactor = new Point(
                                        scan.Size.Width / image.Size.Width,
                                        scan.Size.Height / image.Size.Height);
                ctx.SetColor(Mask.maskColor);

                foreach (MaskEntry p in scan.Mask.MaskPositions) {
                    switch (p.type) {
                    case MaskEntryType.Point:
                        ctx.SetLineWidth(p.pointerSize / scaleFactor.Y * 2);
                        ctx.LineTo(p.position.X / scaleFactor.X, p.position.Y / scaleFactor.Y);
                        ctx.Stroke();

                        ctx.Arc(
                            p.position.X / scaleFactor.X, p.position.Y / scaleFactor.Y,
                            p.pointerSize / scaleFactor.Y, 0, 360);
                        ctx.Fill();

                        ctx.MoveTo(p.position.X / scaleFactor.X, p.position.Y / scaleFactor.Y);
                        break;
                    case MaskEntryType.Space:
                        ctx.Stroke();
                        ctx.ClosePath();
                        break;
                    case MaskEntryType.Delete:
                        ctx.Arc(
                            p.position.X / scaleFactor.X, p.position.Y / scaleFactor.Y,
                            p.pointerSize / scaleFactor.Y, 0, 360);
                        ctx.Save();
                        ctx.Clip();
                        int newX = (int) Math.Min(Math.Max(
                                       p.position.X / scaleFactor.X - pointerSize / scaleFactor.Y, 0), scan.Size.Width);
                        int newY = (int) Math.Min(Math.Max(
                                       p.position.Y / scaleFactor.Y - pointerSize / scaleFactor.Y, 0), scan.Size.Height);

                        using (ImageBuilder ib =
                                   new ImageBuilder((pointerSize / scaleFactor.Y * 2), (pointerSize / scaleFactor.Y * 2))) {
                            BitmapImage bi = ib.ToBitmap();
                            image.WithBoxSize(image.Size).ToBitmap().CopyArea(
                                newX, newY,
                                (int) (pointerSize / scaleFactor.Y * 2), (int) (pointerSize / scaleFactor.Y * 2),
                                bi, 0, 0);
                            ctx.DrawImage(bi, new Point(newX, newY));
                        }
                        ctx.Restore();
                        ctx.ClosePath();
                        break;
                    }
                }

                ctx.Stroke();

                if (mousePosition != Point.Zero) {
                    ctx.Arc(mousePosition.X, mousePosition.Y, pointerSize / Math.Max(scaleFactor.X, scaleFactor.Y), 0, 360);
                    ctx.Fill();

                    if (mousePositionStart != Point.Zero) {
                        ctx.SetLineWidth((pointerSize / Math.Max(scaleFactor.X, scaleFactor.Y)) * 2);
                        ctx.SetColor(Mask.maskColor);
                        ctx.Arc(mousePositionStart.X, mousePositionStart.Y, pointerSize / Math.Max(scaleFactor.X, scaleFactor.Y), 0, 360);
                        ctx.Fill();
                        ctx.MoveTo(mousePosition);
                        ctx.LineTo(mousePositionStart);
                        ctx.Stroke();
                    }
                }
            }
        }
Exemplo n.º 8
0
		void DrawCursor (Context ctx, ChartCursor cursor)
		{
			ctx.SetColor (cursor.Color);
			
			double x, y;
			GetPoint (cursor.Value, cursor.Value, out x, out y);
				
			if (cursor.Dimension == AxisDimension.X) {
				double cy = top - AreaBorderWidth - 1;
				ctx.MoveTo (x, cy);
				ctx.LineTo (x + (cursor.HandleSize/2), cy - cursor.HandleSize + 1);
				ctx.LineTo (x - (cursor.HandleSize/2), cy - cursor.HandleSize + 1);
				ctx.ClosePath ();
				if (activeCursor == cursor)
					ctx.FillPreserve ();
				ctx.Stroke ();
				ctx.MoveTo (x, top);
				ctx.RelLineTo (0, height);
				ctx.Stroke ();
			} else {
				throw new NotSupportedException ();
			}
		}
Exemplo n.º 9
0
        /// <summary>
        /// Draws the marker at the given position
        /// </summary>
        /// <param name="ctx">The Drawing Context with which to draw.</param>
        /// <param name="x">The [physical] x position to draw the marker.</param>
        /// <param name="y">The [physical] y position to draw the marker.</param>
        public void Draw(Context ctx, double x, double y )
        {
            ctx.Save ();
            ctx.SetLineWidth (lineWidth);
            ctx.SetColor (lineColor);

            switch (markerType) {
            case MarkerType.Cross1:
                ctx.MoveTo (x-h, y+h);
                ctx.LineTo (x+h, y-h);
                ctx.MoveTo (x+h, y+h);
                ctx.LineTo (x-h, y-h);
                ctx.Stroke ();
                break;

            case MarkerType.Cross2:
                ctx.MoveTo (x, y-h);
                ctx.LineTo (x, y+h);
                ctx.MoveTo (x-h, y);
                ctx.LineTo (x+h, y);
                ctx.Stroke ();
                break;

            case MarkerType.Circle:
                ctx.MoveTo (x+h,y);
                ctx.Arc (x, y, h, 0, 360);
                ctx.ClosePath ();
                if (filled ) {
                    ctx.SetColor (fillColor);
                    ctx.FillPreserve ();
                }
                ctx.SetColor (lineColor);
                ctx.Stroke ();
                break;

            case MarkerType.Square:
                ctx.Rectangle (x-h, y-h, size, size);
                ctx.ClosePath ();
                if (filled) {
                    ctx.SetColor (fillColor);
                    ctx.FillPreserve ();
                }
                ctx.SetColor (lineColor);
                ctx.Stroke ();
                break;

            case MarkerType.Triangle:
                ctx.MoveTo (x-h, y+h);
                ctx.LineTo (x, y-h);
                ctx.LineTo (x+h, y+h);
                ctx.ClosePath ();
                if (filled) {
                    ctx.SetColor (fillColor);
                    ctx.FillPreserve ();
                }
                ctx.SetColor (lineColor);
                ctx.Stroke ();
                break;

            case MarkerType.TriangleDown:
                ctx.MoveTo (x-h, y-h);
                ctx.LineTo (x, y+h);
                ctx.LineTo (x+h, y-h);
                ctx.ClosePath ();
                if (filled) {
                    ctx.SetColor (fillColor);
                    ctx.FillPreserve ();
                }
                ctx.SetColor (lineColor);
                ctx.Stroke ();
                break;

            case MarkerType.FilledCircle:
                ctx.MoveTo (x+h,y);
                ctx.Arc (x, y, h, 0, 360);
                ctx.ClosePath ();
                ctx.SetColor (fillColor);
                ctx.FillPreserve ();
                ctx.SetColor (lineColor);
                ctx.Stroke ();
                break;

            case MarkerType.FilledSquare:
                ctx.Rectangle (x-h, y-h, size, size);
                ctx.ClosePath ();
                ctx.SetColor (fillColor);
                ctx.FillPreserve ();
                ctx.SetColor (lineColor);
                ctx.Stroke ();
                break;

            case MarkerType.FilledTriangle:
                ctx.MoveTo (x-h, y+h);
                ctx.LineTo (x, y-h);
                ctx.LineTo (x+h, y+h);
                ctx.ClosePath ();
                ctx.SetColor (fillColor);
                ctx.FillPreserve ();
                ctx.SetColor (lineColor);
                ctx.Stroke ();
                break;

            case MarkerType.Diamond:
                ctx.MoveTo (x-h, y);
                ctx.LineTo (x, y-h);
                ctx.LineTo (x+h, y);
                ctx.LineTo (x, y+h);
                ctx.ClosePath ();
                if (filled) {
                    ctx.SetColor (fillColor);
                    ctx.FillPreserve ();
                }
                ctx.SetColor (lineColor);
                ctx.Stroke ();
                break;

            case MarkerType.Flag:
                ctx.MoveTo (x, y-size);
                ctx.LineTo (x+size, y-size+size/3);
                ctx.LineTo (x, y-size+2*size/3);
                ctx.ClosePath ();
                ctx.MoveTo (x, y);
                ctx.LineTo (x, y-size);
                if (filled) {
                    ctx.SetColor (fillColor);
                    ctx.FillPreserve ();
                }
                ctx.SetColor (lineColor);
                ctx.Stroke ();
                break;

            case MarkerType.FlagDown:
                ctx.MoveTo (x, y+size);
                ctx.LineTo (x+size, y+size-size/3);
                ctx.LineTo (x, y+size-2*size/3);
                ctx.ClosePath ();
                ctx.MoveTo (x, y);
                ctx.LineTo (x, y+size);
                if (filled) {
                    ctx.SetColor (fillColor);
                    ctx.FillPreserve ();
                }
                ctx.SetColor (lineColor);
                ctx.Stroke ();
                break;

            case MarkerType.FilledFlag:
                ctx.MoveTo (x, y-size);
                ctx.LineTo (x+size, y-size+size/3);
                ctx.LineTo (x, y-size+2*size/3);
                ctx.ClosePath ();
                ctx.MoveTo (x, y);
                ctx.LineTo (x, y-size);
                ctx.SetColor (fillColor);
                ctx.FillPreserve ();
                ctx.SetColor (lineColor);
                ctx.Stroke ();
                break;

            case MarkerType.None:
                    break;
            }
            ctx.Restore ();
        }
Exemplo n.º 10
0
        public static void DrawRoundRectangle(Xwt.Drawing.Context cr, bool topLeftRound, bool topRightRound, bool bottomLeftRound, bool bottomRightRound, double x, double y, double r, double w, double h)
        {
            //  UA****BQ
            //  H      C
            //  *      *
            //  G      D
            //  TF****ES

            cr.NewPath();

            if (topLeftRound)
            {
                cr.MoveTo(x + r, y);                 // Move to A
            }
            else
            {
                cr.MoveTo(x, y);             // Move to U
            }

            if (topRightRound)
            {
                cr.LineTo(x + w - r, y);             // Straight line to B

                cr.CurveTo(x + w, y,
                           x + w, y,
                           x + w, y + r);  // Curve to C, Control points are both at Q
            }
            else
            {
                cr.LineTo(x + w, y);         // Straight line to Q
            }

            if (bottomRightRound)
            {
                cr.LineTo(x + w, y + h - r);                              // Move to D

                cr.CurveTo(x + w, y + h,
                           x + w, y + h,
                           x + w - r, y + h);  // Curve to E
            }
            else
            {
                cr.LineTo(x + w, y + h); // Move to S
            }

            if (bottomLeftRound)
            {
                cr.LineTo(x + r, y + h);                      // Line to F
                cr.CurveTo(x, y + h,
                           x, y + h,
                           x, y + h - r);  // Curve to G
            }
            else
            {
                cr.LineTo(x, y + h); // Line to T
            }

            if (topLeftRound)
            {
                cr.LineTo(x, y + r);              // Line to H
                cr.CurveTo(x, y,
                           x, y,
                           x + r, y);  // Curve to A
            }
            else
            {
                cr.LineTo(x, y); // Line to U
            }
            cr.ClosePath();
        }
Exemplo n.º 11
0
        /// <summary>
        /// Draw the filled region
        /// </summary>
        /// <param name="g">The Drawing Context with which to draw.</param>
        /// <param name="xAxis">The X-Axis to draw against.</param>
        /// <param name="yAxis">The Y-Axis to draw against.</param>
        public void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis)
        {
            ITransform2D t = Transform2D.GetTransformer (xAxis, yAxis);

            ctx.Save ();

            if (hl1 != null && hl2 != null) {
                ctx.MoveTo (t.Transform (xAxis.Axis.WorldMin, hl1.OrdinateValue));
                ctx.LineTo (t.Transform (xAxis.Axis.WorldMax, hl1.OrdinateValue));
                ctx.LineTo (t.Transform (xAxis.Axis.WorldMax, hl2.OrdinateValue));
                ctx.LineTo (t.Transform (xAxis.Axis.WorldMin, hl2.OrdinateValue));
                ctx.ClosePath ();
            } else if (vl1 != null && vl2 != null) {
                ctx.MoveTo (t.Transform (vl1.AbscissaValue, yAxis.Axis.WorldMin));
                ctx.LineTo (t.Transform (vl1.AbscissaValue, yAxis.Axis.WorldMax));
                ctx.LineTo (t.Transform (vl2.AbscissaValue, yAxis.Axis.WorldMax));
                ctx.LineTo (t.Transform (vl2.AbscissaValue, yAxis.Axis.WorldMin));
                ctx.ClosePath ();
            } else if (lp1 != null && lp2 != null) {

                SequenceAdapter a1 = new SequenceAdapter (lp1.DataSource, lp1.DataMember, lp1.OrdinateData, lp1.AbscissaData);
                SequenceAdapter a2 = new SequenceAdapter (lp2.DataSource, lp2.DataMember, lp2.OrdinateData, lp2.AbscissaData);

                // Start at first point of LinePlot 1 within plot bounds
                int start = 0;
                while (t.Transform (a1 [start]).X < xAxis.PhysicalMin.X) {
                    ++start;
                }
                Point first = t.Transform (a1 [start]);
                ctx.MoveTo (first);
                // Join LinePlot 1 points in ascending order
                Point next;
                for (int i = start+1; i < a1.Count-1; ++i) {
                    next = t.Transform (a1 [i]);
                    if (next.X > xAxis.PhysicalMax.X)
                        break;
                    ctx.LineTo (next);
                }
                // Then join LinePlot 2 points in descending order
                int end = a2.Count-1;
                while (t.Transform (a2 [end]).X > xAxis.PhysicalMax.X) {
                    --end;
                }
                for (int i = end; i > 0; --i) {
                    next = t.Transform (a2 [i]);
                    if (next.X < xAxis.PhysicalMin.X)
                        break;
                    ctx.LineTo (next);
                }
                ctx.LineTo (first);
                ctx.ClosePath ();
            }
            else {
                throw new XwPlotException ("Filled Region bounds not defined");
            }
            ctx.SetColor (FillColor);
            ctx.Fill ();
            ctx.Restore ();
        }
Exemplo n.º 12
0
        void DrawPopover(Context ctx)
        {
            lock (trackerLock)
            {
                if (actualTrackerHitResult != null)
                {
                    var trackerSettings = DefaultTrackerSettings;
                    if (actualTrackerHitResult.Series != null && !string.IsNullOrEmpty(actualTrackerHitResult.Series.TrackerKey))
                        trackerSettings = trackerDefinitions[actualTrackerHitResult.Series.TrackerKey];

                    if (trackerSettings.Enabled)
                    {
                        var extents = actualTrackerHitResult.LineExtents;
                        if (Math.Abs(extents.Width) < double.Epsilon)
                        {
                            extents = new OxyRect(actualTrackerHitResult.XAxis.ScreenMin.X, extents.Top, actualTrackerHitResult.XAxis.ScreenMax.X - actualTrackerHitResult.XAxis.ScreenMin.X, extents.Height);
                        }
                        if (Math.Abs(extents.Height) < double.Epsilon)
                        {
                            extents = new OxyRect(extents.Left, actualTrackerHitResult.YAxis.ScreenMin.Y, extents.Width, actualTrackerHitResult.YAxis.ScreenMax.Y - actualTrackerHitResult.YAxis.ScreenMin.Y);
                        }

                        var pos = actualTrackerHitResult.Position;

                        if (trackerSettings.HorizontalLineVisible)
                        {

                            renderContext.DrawLine(
                                new[] { new ScreenPoint(extents.Left, pos.Y), new ScreenPoint(extents.Right, pos.Y) },
                                trackerSettings.HorizontalLineColor,
                                trackerSettings.HorizontalLineWidth,
                                trackerSettings.HorizontalLineActualDashArray,
                                LineJoin.Miter,
                                true);
                        }
                        if (trackerSettings.VerticalLineVisible)
                        {
                            renderContext.DrawLine(
                                new[] { new ScreenPoint(pos.X, extents.Top), new ScreenPoint(pos.X, extents.Bottom) },
                                trackerSettings.VerticalLineColor,
                                trackerSettings.VerticalLineWidth,
                                trackerSettings.VerticalLineActualDashArray,
                                LineJoin.Miter,
                                true);
                        }

                        TextLayout text = new TextLayout();
                        text.Font = trackerSettings.Font;
                        text.Text = actualTrackerHitResult.Text;

                        var arrowTop = actualTrackerHitResult.Position.Y <= Bounds.Height / 2;
                        const int arrowPadding = 10;

                        var textSize = text.GetSize();
                        var outerSize = new Size(textSize.Width + (trackerSettings.Padding * 2),
                                                  textSize.Height + (trackerSettings.Padding * 2) + arrowPadding);

                        var trackerBounds = new Rectangle(pos.X - (outerSize.Width / 2),
                                                           0,
                                                           outerSize.Width,
                                                           outerSize.Height - arrowPadding);
                        if (arrowTop)
                            trackerBounds.Y = pos.Y + arrowPadding + trackerSettings.BorderWidth;
                        else
                            trackerBounds.Y = pos.Y - outerSize.Height - trackerSettings.BorderWidth;

                        var borderColor = trackerSettings.BorderColor.ToXwtColor();

                        ctx.RoundRectangle(trackerBounds, 6);
                        ctx.SetLineWidth(trackerSettings.BorderWidth);
                        ctx.SetColor(borderColor);
                        ctx.StrokePreserve();
                        ctx.SetColor(trackerSettings.Background.ToXwtColor());
                        ctx.Fill();

                        ctx.Save();
                        var arrowX = trackerBounds.Center.X;
                        var arrowY = arrowTop ? trackerBounds.Top : trackerBounds.Bottom;
                        ctx.NewPath();
                        ctx.MoveTo(arrowX, arrowY);
                        var triangleSide = 2 * arrowPadding / Math.Sqrt(3);
                        var halfSide = triangleSide / 2;
                        var verticalModifier = arrowTop ? -1 : 1;
                        ctx.RelMoveTo(-halfSide, 0);
                        ctx.RelLineTo(halfSide, verticalModifier * arrowPadding);
                        ctx.RelLineTo(halfSide, verticalModifier * -arrowPadding);
                        ctx.SetColor(borderColor);
                        ctx.StrokePreserve();
                        ctx.ClosePath();
                        ctx.SetColor(trackerSettings.Background.ToXwtColor());
                        ctx.Fill();
                        ctx.Restore();

                        ctx.SetColor(trackerSettings.TextColor.ToXwtColor());
                        ctx.DrawTextLayout(text,
                                            trackerBounds.Left + trackerSettings.Padding,
                                            trackerBounds.Top + trackerSettings.Padding);
                    }
                }
            }
        }