Esempio n. 1
0
        /// <Docs>The Canvas to which the View is rendered.</Docs>
        /// <summary>
        /// Draw the specified canvas.
        /// </summary>
        /// <param name="canvas">Canvas.</param>
        public override void Draw(Android.Graphics.Canvas canvas)
        {
            if (Element == null)
            {
                base.Draw(canvas);
                return;
            }

            // Should we clip?
            if (Element.IsClippedToBounds)
            {
                canvas.ClipRect(new Android.Graphics.Rect(0, 0, Width, Height), Region.Op.Replace);
            }

            // Draws the background and default android setup. Children will also be redrawn here
            base.Draw(canvas);

            // Perform custom drawing from the NGraphics subsystems
            var ncanvas = new CanvasCanvas(canvas);

            var rect = new NGraphics.Rect(0, 0, Width, Height);

            Element.Draw(ncanvas, rect);

            // Redraw children - since we might have a composite control containing both children
            // and custom drawing code, we want children to be drawn last. The reason for this double-
            // drawing is that the base.Draw(canvas) call will handle background which is needed before
            // doing NGraphics drawing - but unfortunately it also draws children - which then will
            // be drawn below NGraphics drawings.
            for (var i = 0; i < ChildCount; i++)
            {
                GetChildAt(i).Draw(canvas);
            }
        }
Esempio n. 2
0
        /// <Docs>The Canvas to which the View is rendered.</Docs>
        /// <summary>
        /// Draw the specified canvas.
        /// </summary>
        /// <param name="canvas">Canvas.</param>
        public override void Draw(Android.Graphics.Canvas canvas)
        {
            if (Element == null)
            {
                base.Draw(canvas);
                return;
            }

            // Draws the background and default android setup. Children will also be redrawn here
            // base.Draw(canvas);

            // Set up clipping
            if (Element.IsClippedToBounds)
            {
                canvas.ClipRect(new Android.Graphics.Rect(0, 0, Width, Height));
            }

            // Perform custom drawing from the NGraphics subsystems
            var ncanvas = new CanvasCanvas(canvas);

            var rect = new NGraphics.Rect(0, 0, Width, Height);

            // Fill background
            ncanvas.FillRectangle(rect, new NGraphics.Color(Element.BackgroundColor.R, Element.BackgroundColor.G, Element.BackgroundColor.B, Element.BackgroundColor.A));

            // Custom drawing
            Element.Draw(ncanvas, rect);

            // Redraw children - since we might have a composite control containing both children
            // and custom drawing code, we want children to be drawn last. The reason for this double-
            // drawing is that the base.Draw(canvas) call will handle background which is needed before
            // doing NGraphics drawing - but unfortunately it also draws children - which then will
            // be drawn below NGraphics drawings.
            base.Draw(canvas);
        }
Esempio n. 3
0
		public void DrawImage (IImage image, Rect frame, double alpha = 1.0)
		{
			var ch = GetChild (ChildType.Image);
			var s = (Shapes.Rectangle)ch.Shape;
			s.Width = frame.Width;
			s.Height = frame.Height;
		}
        public override void Draw(NGraphics.ICanvas canvas, NGraphics.Rect rect)
        {
            base.Draw(canvas, rect);

            rect.Inflate(-10, -10);
            canvas.DrawRectangle(rect, Pens.Blue, null);
        }
        /// <summary>
        /// Draw the specified canvas.
        /// </summary>
        /// <param name="canvas">Canvas.</param>
        /// <param name="rect">Rect.</param>
        public override void Draw(NGraphics.ICanvas canvas, NGraphics.Rect rect)
        {
            base.Draw(canvas, rect);

            canvas.DrawLine(0, rect.Height - 0.5, rect.Width, rect.Height - 0.5, NGraphics.Colors.Gray, 0.5);
            canvas.DrawEllipse(new Rect(-rect.Width / 3, 0, rect.Width, rect.Width), null, Brushes.Red);
        }
Esempio n. 6
0
        NPoint CalculateEventPoint(IReadOnlyList <MonitorEvent> events, int index, NRect frame)
        {
            var x = (index + 1) * frame.Width / (events.Count + 1);
            var y = (1 - events[index].Value) * frame.Height;

            return(new NPoint(x, y));
        }
Esempio n. 7
0
		public Text (Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, Brush brush = null)
			: base (pen, brush)
		{
			Frame = frame;
			Font = font;
			Alignment = alignment;
			Spans = new List<TextSpan> ();
		}
Esempio n. 8
0
		public Text (string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, Brush brush = null)
			: base (pen, brush)
		{
			Frame = frame;
			Font = font;
			Alignment = alignment;
			Spans = new List<TextSpan> { new TextSpan (text) };
		}
Esempio n. 9
0
 public Text(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, Brush brush = null)
     : base(pen, brush)
 {
     String = text;
     Frame = frame;
     Font = font;
     Alignment = alignment;
 }
Esempio n. 10
0
		public void DrawEllipse (Rect frame, Pen pen = null, Brush brush = null)
		{
			var ch = GetChild (ChildType.Ellipse);
			var s = (Shapes.Rectangle)ch.Shape;
			s.Width = frame.Width;
			s.Height = frame.Height;
			FormatShape (s, pen, brush);
		}
Esempio n. 11
0
        protected override void OnDraw(Android.Graphics.Canvas canvasDroid)
        {
            base.OnDraw(canvasDroid);

            var canvas = new CanvasCanvas(canvasDroid);
            var rect   = new NGraphics.Rect(GetX(), GetY(), Width, Height);

            this.Draw(canvas, rect);
        }
Esempio n. 12
0
        public override void Draw(NGraphics.ICanvas canvas, NGraphics.Rect rect)
        {
            if (BackgroundColor == Xamarin.Forms.Color.Transparent && BorderColor == Xamarin.Forms.Color.Transparent)
            {
                return;
            }

            CustomPainter.Paint(this, canvas, rect);
        }
Esempio n. 13
0
		public Rect TransformRect (Rect rect)
		{
			var bbb = new BoundingBoxBuilder ();
			bbb.Add (TransformPoint (rect.TopLeft));
			bbb.Add (TransformPoint (rect.BottomLeft));
			bbb.Add (TransformPoint (rect.BottomRight));
			bbb.Add (TransformPoint (rect.TopRight));
			return bbb.BoundingBox;
		}
Esempio n. 14
0
		public override void Draw(ICanvas canvas, Rect rect)
		{
			if(DrawingFunction != null)
			{
				base.Draw(canvas, rect);
				return;
			}

			var borderColro = NGraphics.Color.FromHSL(
				                  BorderColor.Hue,
				                  BorderColor.Saturation,
				                  BorderColor.Luminosity,
				                  BorderColor.A);
			var pen = new Pen(borderColro, BorderWidth);
			var fillColor = NGraphics.Color.FromHSL(
				                BackColor.Hue,
				                BackColor.Saturation,
				                BackColor.Luminosity,
				                BackColor.A);
			var brush = new SolidBrush(fillColor);

			var padding = BorderWidth <= 0 ? 0.0 : BorderWidth;
			var newRect = rect.GetInflated(-padding);
			var curveSize = newRect.Height / 2;

			canvas.DrawPath(new PathOp []{ 
				new MoveTo(newRect.Left+curveSize, newRect.Top),
				new LineTo(newRect.Right-curveSize, newRect.Top),
				new CurveTo(
					new NGraphics.Point(newRect.Right-curveSize, newRect.Top),
					newRect.TopRight,
					new NGraphics.Point(newRect.Right, newRect.Top+curveSize)
				),
				new CurveTo(
					new NGraphics.Point(newRect.Right, newRect.Bottom-curveSize),
					newRect.BottomRight,
					new NGraphics.Point(newRect.Right-curveSize, newRect.Bottom)
				),
				new LineTo(newRect.Left+curveSize, newRect.Bottom),
				new CurveTo(
					new NGraphics.Point(newRect.Left+curveSize, newRect.Bottom),
					newRect.BottomLeft,
					new NGraphics.Point(newRect.Left, newRect.Bottom-curveSize)
				),
				new CurveTo(
					new NGraphics.Point(newRect.Left, newRect.Top+curveSize),
					newRect.TopLeft,
					new NGraphics.Point(newRect.Left+curveSize, newRect.Top)
				),
				new ClosePath()
			}, pen, brush);
		}
Esempio n. 15
0
		void Read (XDocument doc)
		{
			var svg = doc.Root;
			var ns = svg.Name.Namespace;

			//
			// Find the defs (gradients)
			//
			foreach (var d in svg.Descendants ()) {
				var idA = d.Attribute ("id");
				if (idA != null) {
					defs [ReadString (idA).Trim ()] = d;
				}
			}

			//
			// Get the dimensions
			//
			var widthA = svg.Attribute ("width");
			var heightA = svg.Attribute ("height");
			var width = ReadNumber (widthA);
			var height = ReadNumber (heightA);
			var size = new Size (width, height);

			var viewBox = new Rect (size);
			var viewBoxA = svg.Attribute ("viewBox") ?? svg.Attribute ("viewPort");
			if (viewBoxA != null) {
				viewBox = ReadRectangle (viewBoxA.Value);
			}

			if (widthA != null && widthA.Value.Contains ("%")) {
				size.Width *= viewBox.Width;
			}
			if (heightA != null && heightA.Value.Contains ("%")) {
				size.Height *= viewBox.Height;
			}

			//
			// Add the elements
			//
			Graphic = new Graphic (size, viewBox);

			AddElements (Graphic.Children, svg.Elements (), null, Brushes.Black);
		}
Esempio n. 16
0
        /// <summary>
        /// Draw the specified canvas.
        /// </summary>
        /// <param name="canvas">Canvas.</param>
        /// <param name="rect">Rect.</param>
        public override void Draw(NGraphics.ICanvas canvas, NGraphics.Rect rect)
        {
            base.Draw(canvas, rect);

            var backgroundBrush = new SolidBrush(new NGraphics.Color(BackgroundColor.R,
                                                                     BackgroundColor.G, BackgroundColor.B, BackgroundColor.A));

            var curveSize = CornerRadius;
            var width     = rect.Width;
            var height    = rect.Height;

            canvas.DrawPath(new PathOp [] {
                new MoveTo(curveSize, 0),
                // Top Right corner
                new LineTo(width - curveSize, 0),
                new CurveTo(
                    new NGraphics.Point(width - curveSize, 0),
                    new NGraphics.Point(width, 0),
                    new NGraphics.Point(width, curveSize)
                    ),
                new LineTo(width, height - curveSize),
                // Bottom right corner
                new CurveTo(
                    new NGraphics.Point(width, height - curveSize),
                    new NGraphics.Point(width, height),
                    new NGraphics.Point(width - curveSize, height)
                    ),
                new LineTo(curveSize, height),
                // Bottom left corner
                new CurveTo(
                    new NGraphics.Point(curveSize, height),
                    new NGraphics.Point(0, height),
                    new NGraphics.Point(0, height - curveSize)
                    ),
                new LineTo(0, curveSize),
                new CurveTo(
                    new NGraphics.Point(0, curveSize),
                    new NGraphics.Point(0, 0),
                    new NGraphics.Point(curveSize, 0)
                    ),
                new ClosePath()
            }, null, backgroundBrush);
        }
Esempio n. 17
0
        public override void Draw(NGraphics.ICanvas canvas, NGraphics.Rect rect)
        {
            base.Draw(canvas, rect);
            const double delta   = -10.0;
            const double yOffset = 20;
            var          width   = rect.Width;
            var          height  = rect.Height;

            var points = new PathOp[]
            {
                new MoveTo(0, yOffset - delta),
                new CurveTo(new NGraphics.Point(width / 2, yOffset + delta),
                            new NGraphics.Point(width / 2, yOffset + delta),
                            new NGraphics.Point(width, yOffset - delta)),
                new LineTo(width, height),
                new LineTo(0, height)
            };

            canvas.DrawPath(points, null, new SolidBrush(new NGraphics.Color(0, 0.722, 1, 1)));
        }
Esempio n. 18
0
        public override void Draw(NGraphics.ICanvas canvas, NGraphics.Rect rect)
        {
            DrawBackground(canvas, rect);

            LastRect = rect;
            // 0.65
            RadiusAll = Math.Min(rect.Width, rect.Height - textHeight) / 2.0;

            if (IsTitleOnTop)
            {
                Center = new NGraphics.Point(rect.Center.X, rect.Center.Y + textHeight);
            }
            else
            {
                Center = new NGraphics.Point(rect.Center.X, rect.Center.Y - textHeight);
            }

            double pullLength = RadiusAll.Value * PullRatio;
            double radius     = RadiusAll.Value - (RadiusAll.Value * PullRatio);

            double sumRadian = StartRadian;

            foreach (var eachSegment in ListItems)
            {
                sumRadian = eachSegment.DrawSegment(canvas, rect.Center, radius, sumRadian, pullLength, Font, TextColor, IsNameVisible, PercentColor, IsPercentVisible, ValueColor, IsValueVisible);
            }

            Rect rectText;

            if (IsTitleOnTop)
            {
                rectText = new Rect(rect.Center.X, rect.Center.Y - RadiusAll.Value - textHeight / 4.0, 20, 20);
            }
            else
            {
                rectText = new Rect(rect.Center.X, rect.Center.Y + RadiusAll.Value + textHeight / 4.0, 20, 20);
            }
            canvas.DrawText(Title ?? "", rectText, new NGraphics.Font(), NGraphics.TextAlignment.Center, new Pen(TitleColor.ToCross()), new SolidBrush(TitleColor.ToCross()));
        }
Esempio n. 19
0
        public void DrawText(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, Brush brush = null)
        {
            if (string.IsNullOrEmpty (text))
                return;
            if (font == null)
                throw new ArgumentNullException ("font");

            SetBrush (brush);

            //			string fontName = font.Name;
            //			context.SelectFont (font.Name, (nfloat)font.Size, CGTextEncoding.MacRoman);
            //
            //			context.ShowTextAtPoint ((nfloat)frame.X, (nfloat)frame.Y, text);

            var pt = frame.TopLeft;

            using (var atext = new NSMutableAttributedString (text)) {

                atext.AddAttributes (new CTStringAttributes {
                    ForegroundColorFromContext = true,
                    Font = font.GetCTFont (),
                }, new NSRange (0, text.Length));

                using (var l = new CTLine (atext)) {
                    nfloat asc, desc, lead;
                    var width = l.GetTypographicBounds (out asc, out desc, out lead);
                    context.SaveState ();
                    context.TranslateCTM ((nfloat)(pt.X - width / 2), (nfloat)(pt.Y + desc));
                    context.TextPosition = CGPoint.Empty;
                    l.Draw (context);
                    context.RestoreState ();
                }
            }
        }
Esempio n. 20
0
        public void DrawRectangle(Rect frame, Pen pen = null, Brush brush = null)
        {
            if (pen == null && brush == null)
                return;

            DrawElement (() => {
                context.AddRect (Conversions.GetCGRect (frame));
                return frame;
            }, pen, brush);
        }
Esempio n. 21
0
        public void DrawImage(IImage image, Rect frame, double alpha = 1.0)
        {
            var cgi = image as CGImageImage;

            if (cgi != null) {
                var i = cgi.Image;
                var h = frame.Height;
                context.SaveState ();
                context.SetAlpha ((nfloat)alpha);
                context.TranslateCTM ((nfloat)frame.X, (nfloat)(h + frame.Y));
                context.ScaleCTM (1, -1);
                context.DrawImage (new CGRect (0, 0, (nfloat)frame.Width, (nfloat)frame.Height), cgi.Image);
                context.RestoreState ();
            }
        }
Esempio n. 22
0
        public SurfaceImageSourceCanvas(SurfaceImageSource surfaceImageSource, Rect updateRect, Direct2DFactories factories = null)
            : base(factories)
        {
            sisn = ComObject.As<DXGI.ISurfaceImageSourceNative> (surfaceImageSource);
            SharpDX.Point offset;
            var surface = sisn.BeginDraw (updateRect.ToRectangle (), out offset);

            var dpi = 96.0;
            var properties = new D2D1.RenderTargetProperties (D2D1.RenderTargetType.Default, new D2D1.PixelFormat (DXGI.Format.Unknown, D2D1.AlphaMode.Unknown), (float)(dpi), (float)(dpi), D2D1.RenderTargetUsage.None, D2D1.FeatureLevel.Level_DEFAULT);
            Initialize (new D2D1.RenderTarget (this.factories.D2DFactory, surface, properties));
        }
Esempio n. 23
0
 void DrawBackground(ICanvas canvas, NGraphics.Rect rect)
 {
     canvas.DrawRectangle(rect, new Pen(BackgroundColor.ToCross()), new SolidBrush(BackgroundColor.ToCross()));
 }
Esempio n. 24
0
 public Point GetAbsoluteEnd(Rect frame)
 {
     if (Absolute) return End;
     return frame.TopLeft + End * frame.Size;
 }
Esempio n. 25
0
        /// <summary>
        /// Draws an image
        /// </summary>
        /// <param name="image"></param>
        /// <param name="frame"></param>
        /// <param name="alpha"></param>
        public void DrawImage(IImage image, Rect frame, double alpha = 1.0)
        {
            var ii = image as BitmapImageImage;
            if (ii != null)
            {
                var imageEl = new Image();
                imageEl.Source = ii.Bitmap;
                imageEl.Width = frame.Width;
                imageEl.Height = frame.Height;

                imageEl.RenderTransform = Conversions.GetTransform(CurrentTransform);
                _canvas.Children.Add(imageEl);
                Canvas.SetLeft(imageEl, frame.X);
                Canvas.SetTop(imageEl, frame.Y);
            }
        }
Esempio n. 26
0
        public GraphCell() : base()
        {
            StackLayout dateLayout;
            Label       dateLabel;

            /* Used when drawing. */
            var points    = new List <NPoint>();
            var pointSize = new NSize(CaptionSize * 5 / 6);
            var halfPoint = pointSize / 2;

            View = dataView = new NControlView {
                Content = new StackLayout {
                    //BackgroundColor = MainApp.RandomColor(),
                    Orientation = StackOrientation.Horizontal,
                    Children    =
                    {
                        (dateLayout                         = new StackLayout {
                            HorizontalOptions               = LayoutOptions.EndAndExpand,
                            //Padding = new Thickness(7, 0),
                            WidthRequest                    = SpaceUnderGraph,
                            Children                        =
                            {
                                (dateLabel                  = new Label       {
                                    HorizontalTextAlignment = TextAlignment.Center,
                                    VerticalOptions         = LayoutOptions.CenterAndExpand,
                                    Rotation                =                   -90,
                                    Style                   = StyleKit.AutoDarkLabelStyles.Caption,
                                    //FontSize = 12,
                                    BindingContext          = this
                                })
                            }
                        })
                    }
                },
                DrawingFunction = (canvas, rect) => {
                    /* Transforms for natural drawing - as in the end, the whole graph is rotated 90 degrees! */
                    canvas.Rotate(-90);
                    canvas.Translate(-rect.Height, halfPoint.Height);
                    rect = new NRect(NPoint.Zero,
                                     new NSize(rect.Size.Height, rect.Size.Width - dateLayout.Width - pointSize.Height));

                    //canvas.DrawLine(rect.BottomLeft, rect.BottomRight, Colors.Black, 2);

                    if (Data == null)
                    {
                        return;
                    }

                    points.Clear();

                    /* Add past points */
                    var yesterday = Data.Yesterday;
                    if (yesterday?.Events?.Count == 1)
                    {
                        var beforeYesterday = yesterday?.Yesterday;
                        points.AddRange(CalculateEventPoints(beforeYesterday?.Events, rect, -2));
                    }
                    points.AddRange(CalculateEventPoints(yesterday?.Events, rect, -1));
                    /* Add today's points */
                    points.AddRange(CalculateEventPoints(Data.Events, rect));
                    /* Add future points */
                    var tomorrow = Data.Tomorrow;
                    points.AddRange(CalculateEventPoints(tomorrow?.Events, rect, 1));
                    if (tomorrow?.Events?.Count == 1)
                    {
                        var afterTomorrow = tomorrow?.Tomorrow;
                        points.AddRange(CalculateEventPoints(afterTomorrow?.Events, rect, 2));
                    }

                    if (Data.Events.Count > 0)
                    {
                        var path = new Path(pen: new Pen(Colors.Black, pointSize.Width / 4));
                        path.MoveTo(points[0]);
                        for (int i = 1; i < points.Count; i++)
                        {
                            path.Operations.Add(SplineTo(
                                                    from: points[i - 1],
                                                    to: points[i],
                                                    beforeFrom: i >= 2
                                    ? points[i - 2]
                                    : points[i - 1] - (points[i] - points[i - 1]).WithY(0),
                                                    afterTo: i <= points.Count - 2
                                    ? points[i + 1]
                                    : points[i] + (points[i] - points[i - 1]).WithY(0)
                                                    ));
                        }
                        path.Draw(canvas);
                    }

                    foreach (var p in points)
                    {
                        if (p.X >= -halfPoint.Width && p.X <= rect.Width + halfPoint.Width)
                        {
                            canvas.FillEllipse(p - halfPoint, pointSize, Colors.Black);
                            canvas.FillEllipse(p - halfPoint * 4 / 5, pointSize * 4 / 5, Colors.White);
                        }
                    }

                    /* canvas.DrawText(Math.Round(data.Value * 5 + 1, 1).ToString("F1"),
                     *      rect.Center, new NFont(), Colors.Black); */
                }
            };

            View.SizeChanged += (sender, e) => dataView.Invalidate();

            dateLabel.SetBinding <GraphCell, DateTime, string>(Label.TextProperty, cell => cell.Data.Day, dt => dt.ToString("ddd\ndd/MM"));
            dateLabel.SizeChanged += (sender, e) => dataView.Invalidate();
        }
Esempio n. 27
0
 public Size GetAbsoluteRadius(Rect frame)
 {
     if (Absolute) return Radius;
     return Radius * frame.Size;
 }
Esempio n. 28
0
 public Point GetAbsoluteCenter(Rect frame)
 {
     if (Absolute) return Center;
     return frame.TopLeft + Center * frame.Size;
 }
Esempio n. 29
0
 public override void Draw(NGraphics.ICanvas canvas, NGraphics.Rect rect)
 {
     //base.Draw(canvas, rect);
     //canvas.DrawLine(rect.Left, rect.Top, rect.Width, rect.Height, NGraphics.Colors.Blue);
     //canvas.DrawLine(rect.Width, rect.Top, rect.Left, rect.Height, NGraphics.Colors.Yellow);
 }
Esempio n. 30
0
        /// <summary>
        /// Draws text
        /// </summary>
        /// <param name="text"></param>
        /// <param name="frame"></param>
        /// <param name="font"></param>
        /// <param name="alignment"></param>
        /// <param name="pen"></param>
        /// <param name="brush"></param>
        public void DrawText(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left,
            Pen pen = null, NGraphics.Brush brush = null)
        {
            var textBlock = new TextBlock();
            textBlock.Text = text;
            textBlock.Width = frame.Width;
            textBlock.Height = frame.Height;
            Canvas.SetLeft(textBlock, frame.X);
            Canvas.SetTop(textBlock, frame.Y);

            textBlock.FontFamily = new FontFamily(font.Family);
            textBlock.FontSize = font.Size;

            switch (alignment)
            {
                case TextAlignment.Left:
                    textBlock.TextAlignment = System.Windows.TextAlignment.Left;
                    break;
                case TextAlignment.Center:
                    textBlock.TextAlignment = System.Windows.TextAlignment.Center;
                    break;
                case TextAlignment.Right:
                    textBlock.TextAlignment = System.Windows.TextAlignment.Right;
                    break;
            }

            if (pen != null)
                textBlock.Foreground = new SolidColorBrush(new System.Windows.Media.Color
                {
                    A = pen.Color.A,
                    R = pen.Color.R,
                    G = pen.Color.G,
                    B = pen.Color.B
                });

            textBlock.RenderTransform = Conversions.GetTransform(CurrentTransform);
            _canvas.Children.Add(textBlock);
        }
Esempio n. 31
0
        /// <summary>
        /// Draws an ellipse
        /// </summary>
        /// <param name="frame"></param>
        /// <param name="pen"></param>
        /// <param name="brush"></param>
        public void DrawEllipse(Rect frame, Pen pen = null, NGraphics.Brush brush = null)
        {
            var ellipseEl = new System.Windows.Shapes.Ellipse();
            var offset = pen != null ? pen.Width : 0.0;

            ellipseEl.Width = frame.Width + offset;
            ellipseEl.Height = frame.Height + offset;

            if (brush != null)
                ellipseEl.Fill = GetBrush(brush);

            if (pen != null)
            {
                ellipseEl.Stroke = GetStroke(pen);
                ellipseEl.StrokeThickness = pen.Width;
            }

            ellipseEl.RenderTransform = Conversions.GetTransform(CurrentTransform);
            _canvas.Children.Add(ellipseEl);
            Canvas.SetLeft(ellipseEl, frame.X - offset / 2.0);
            Canvas.SetTop(ellipseEl, frame.Y - offset / 2.0);
        }
Esempio n. 32
0
 public void DrawRectangle(Rect frame, Pen pen = null, Brush brush = null)
 {
     var p = GetBrush (pen);
     var b = GetBrush (frame, brush);
     if (b != null) {
         renderTarget.FillRectangle (frame.ToRectangleF (), b);
     }
     if (p != null) {
         renderTarget.DrawRectangle (frame.ToRectangleF (), p, (float)pen.Width, GetStrokeStyle (pen));
     }
 }
Esempio n. 33
0
		static IImage RenderSectionToImage (/*this*/ Graphic graphics, Rect sourceFrame, Rect outputFrame, double finalScale, Func<Size, double, IImageCanvas> createPlatformImageCanvas)
		{
			var originalSize = graphics.Size;
			var sectionCanvas = createPlatformImageCanvas (outputFrame.Size, finalScale);

			// Redraw into final version with any scaling between the original and the output slice.
			var sliceVerticalScale = outputFrame.Height / sourceFrame.Height;
			var sliceHorizontalScale = outputFrame.Width / sourceFrame.Width;
			// Potentially setting ViewBox size smaller to enlarge result.
			graphics.ViewBox = new Rect (sourceFrame.Position, new Size (originalSize.Width / sliceHorizontalScale, originalSize.Height / sliceVerticalScale));

			graphics.Draw (sectionCanvas);
			return sectionCanvas.GetImage ();
		}
Esempio n. 34
0
 public void DrawText(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, Brush brush = null)
 {
     var layout = new DW.TextLayout (factories.DWFactory, text, GetTextFormat (font), (float)frame.Width, (float)frame.Height);
     var h = layout.Metrics.Height;
     renderTarget.DrawTextLayout ((frame.TopLeft - h*Point.OneY).ToVector2 (), layout, GetBrush (frame, brush));
 }
Esempio n. 35
0
 public Point GetAbsoluteStart(Rect frame)
 {
     if (Absolute) return Start;
     return frame.TopLeft + Start * frame.Size;
 }
Esempio n. 36
0
        D2D1.Brush GetBrush(Rect frame, Brush brush)
        {
            if (brush == null) return null;
            var sb = brush as SolidBrush;
            if (sb != null) {
                return new D2D1.SolidColorBrush (renderTarget, sb.Color.ToColor4 ());
            }

            var lgb = brush as LinearGradientBrush;
            if (lgb != null) {
                if (lgb.Stops.Count < 2) return null;
                var props = new D2D1.LinearGradientBrushProperties {
                    StartPoint = lgb.GetAbsoluteStart (frame).ToVector2 (),
                    EndPoint = lgb.GetAbsoluteEnd (frame).ToVector2 (),
                };
                return new D2D1.LinearGradientBrush (renderTarget, props, GetStops (lgb.Stops));
            }

            var rgb = brush as RadialGradientBrush;
            if (rgb != null) {
                if (rgb.Stops.Count < 2) return null;
                var rad = rgb.GetAbsoluteRadius (frame);
                var center = rgb.GetAbsoluteCenter (frame);
                var focus = rgb.GetAbsoluteFocus (frame);
                var props = new D2D1.RadialGradientBrushProperties {
                    Center = center.ToVector2 (),
                    RadiusX = (float)rad.Width,
                    RadiusY = (float)rad.Height,
                    GradientOriginOffset = (focus - center).ToVector2 (),
                };
                return new D2D1.RadialGradientBrush (renderTarget, props, GetStops (rgb.Stops));
            }

            // TODO: Radial gradient brushes
            return new D2D1.SolidColorBrush (renderTarget, Colors.Black.ToColor4 ());
        }
Esempio n. 37
0
 public Point GetAbsoluteFocus(Rect frame)
 {
     if (Absolute) return Focus;
     return frame.TopLeft + Focus * frame.Size;
 }
 public void DrawRectangle(Rect frame, Pen pen = null, Brush brush = null)
 {
 }
 public void DrawEllipse(Rect frame, Pen pen = null, Brush brush = null)
 {
 }
Esempio n. 40
0
 IEnumerable <NPoint> CalculateEventPoints(IReadOnlyList <MonitorEvent> events, NRect frame, int offset = 0)
 {
     return(events != null?events.Select((ev, i) => CalculateEventPoint(events, i, frame))
            .Select(p => p.WithX(p.X + offset * frame.Width)) : new List <NPoint>());
 }
 public void DrawText(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, Brush brush = null)
 {
 }
Esempio n. 42
0
 public void DrawEllipse(Rect frame, Pen pen = null, Brush brush = null)
 {
     var p = GetBrush (pen);
     var b = GetBrush (frame, brush);
     var c = frame.Center;
     var s = new D2D1.Ellipse (new Vector2 ((float)c.X, (float)c.Y), (float)(frame.Width / 2.0), (float)(frame.Height / 2.0));
     if (b != null) {
         renderTarget.FillEllipse (s, b);
     }
     if (p != null) {
         renderTarget.DrawEllipse (s, p, (float)pen.Width, GetStrokeStyle (pen));
     }
 }
 public void DrawImage(IImage image, Rect frame, double alpha = 1.0)
 {
 }
Esempio n. 44
0
 public void DrawImage(IImage image, Rect frame, double alpha = 1.0)
 {
     var i = GetImage (image);
     renderTarget.DrawBitmap (i, frame.ToRectangleF (), (float)alpha, D2D1.BitmapInterpolationMode.Linear);
 }