예제 #1
0
        private A.Point GetTextOrigin(ShapeStyle style, ref Rect2 rect, ref A.Size size)
        {
            double ox, oy;

            switch (style.TextStyle.TextHAlignment)
            {
                case TextHAlignment.Left:
                    ox = rect.X;
                    break;
                case TextHAlignment.Right:
                    ox = rect.Right - size.Width;
                    break;
                case TextHAlignment.Center:
                default:
                    ox = (rect.Left + rect.Width / 2.0) - (size.Width / 2.0);
                    break;
            }

            switch (style.TextStyle.TextVAlignment)
            {
                case TextVAlignment.Top:
                    oy = rect.Y;
                    break;
                case TextVAlignment.Bottom:
                    oy = rect.Bottom - size.Height;
                    break;
                case TextVAlignment.Center:
                default:
                    oy = (rect.Bottom - rect.Height / 2f) - (size.Height / 2f);
                    break;
            }

            return new A.Point(ox, oy);
        }
        private void Editor_LostFocus(object sender, Avalonia.Interactivity.RoutedEventArgs e)
        {
            intellisenseJobRunner.InvokeAsync(() =>
            {
                CloseIntellisense();
            });

            completionAssistant.Close();
        }
예제 #3
0
 public IFormattedTextImpl CreateFormattedText(
     string text,
     string fontFamily,
     double fontSize,
     FontStyle fontStyle,
     TextAlignment textAlignment,
     Avalonia.Media.FontWeight fontWeight,
     TextWrapping wrapping)
 {
     return new FormattedTextImpl(s_pangoContext, text, fontFamily, fontSize, fontStyle, textAlignment, fontWeight);
 }
		public LinearGradientBrushImpl(Avalonia.Media.LinearGradientBrush brush, Size destinationSize)
		{
			var start = brush.StartPoint.ToPixels(destinationSize);
			var end = brush.EndPoint.ToPixels(destinationSize);

			this.PlatformBrush = new LinearGradient(start.X, start.Y, end.X, end.Y);

			foreach (var stop in brush.GradientStops)
				((LinearGradient)this.PlatformBrush).AddColorStop(stop.Offset, stop.Color.ToCairo());

			((LinearGradient)this.PlatformBrush).Extend = Extend.Pad;
		}
예제 #5
0
		public SolidColorBrushImpl(Avalonia.Media.SolidColorBrush brush, double opacityOverride = 1.0f)
		{
			var color = brush?.Color.ToCairo() ?? new Color();

            if (brush != null)
				color.A = Math.Min(brush.Opacity, color.A);
			
            if (opacityOverride < 1.0f)
			    color.A = Math.Min(opacityOverride, color.A);

			this.PlatformBrush = new SolidPattern(color);
		}
		public RadialGradientBrushImpl(Avalonia.Media.RadialGradientBrush brush, Size destinationSize)
		{
			var center = brush.Center.ToPixels(destinationSize);
			var gradientOrigin = brush.GradientOrigin.ToPixels(destinationSize);
            var radius = brush.Radius;

			this.PlatformBrush = new RadialGradient(center.X, center.Y, radius, gradientOrigin.X, gradientOrigin.Y, radius);

            foreach (var stop in brush.GradientStops)
            {
                ((RadialGradient)this.PlatformBrush).AddColorStop(stop.Offset, stop.Color.ToCairo());
            }

			((RadialGradient)this.PlatformBrush).Extend = Extend.Pad;
		}
 public void ArcTo(
     Point point,
     Size size,
     double rotationAngle,
     bool isLargeArc,
     Avalonia.Media.SweepDirection sweepDirection)
 {
     _sink.AddArc(new D2D.ArcSegment
     {
         Point = point.ToSharpDX(),
         Size = size.ToSharpDX(),
         RotationAngle = (float)rotationAngle,
         ArcSize = isLargeArc ? ArcSize.Large : ArcSize.Small,
         SweepDirection = (SweepDirection)sweepDirection,
     });
 }
        public RadialGradientBrushImpl(
            Avalonia.Media.RadialGradientBrush brush,
            SharpDX.Direct2D1.RenderTarget target,
            Size destinationSize)
        {
            if (brush.GradientStops.Count == 0)
            {
                return;
            }

            var gradientStops = brush.GradientStops.Select(s => new SharpDX.Direct2D1.GradientStop
            {
                Color = s.Color.ToDirect2D(),
                Position = (float)s.Offset
            }).ToArray();

            var centerPoint = brush.Center.ToPixels(destinationSize);
            var GradientOriginOffset = brush.GradientOrigin.ToPixels(destinationSize);
            
            // Note: Direct2D supports RadiusX and RadiusY but Cairo backend supports only Radius property
            var radiusX = brush.Radius;
            var radiusY = brush.Radius;

            using (var stops = new SharpDX.Direct2D1.GradientStopCollection(
                target,
                gradientStops,
                brush.SpreadMethod.ToDirect2D()))
            {
                PlatformBrush = new SharpDX.Direct2D1.RadialGradientBrush(
                    target,
                    new SharpDX.Direct2D1.RadialGradientBrushProperties
                    {
                        Center = centerPoint.ToSharpDX(),
                        GradientOriginOffset = GradientOriginOffset.ToSharpDX(),
                        RadiusX = (float)radiusX,
                        RadiusY = (float)radiusY
                    },
                    new SharpDX.Direct2D1.BrushProperties
                    {
                        Opacity = (float)brush.Opacity,
                        Transform = PrimitiveExtensions.Matrix3x2Identity,
                    },
                    stops);
            }
        }
        public LinearGradientBrushImpl(
            Avalonia.Media.LinearGradientBrush brush,
            SharpDX.Direct2D1.RenderTarget target,
            Size destinationSize)
        {
            if (brush.GradientStops.Count == 0)
            {
                return;
            }

            var gradientStops = brush.GradientStops.Select(s => new SharpDX.Direct2D1.GradientStop
            {
                Color = s.Color.ToDirect2D(),
                Position = (float)s.Offset
            }).ToArray();

            var startPoint = brush.StartPoint.ToPixels(destinationSize);
            var endPoint = brush.EndPoint.ToPixels(destinationSize);

            using (var stops = new SharpDX.Direct2D1.GradientStopCollection(
                target,
                gradientStops,
                brush.SpreadMethod.ToDirect2D()))
            {
                PlatformBrush = new SharpDX.Direct2D1.LinearGradientBrush(
                    target,
                    new SharpDX.Direct2D1.LinearGradientBrushProperties
                    {
                        StartPoint = startPoint.ToSharpDX(),
                        EndPoint = endPoint.ToSharpDX()
                    },
                    new SharpDX.Direct2D1.BrushProperties
                    {
                        Opacity = (float)brush.Opacity,
                        Transform = PrimitiveExtensions.Matrix3x2Identity,
                    },
                    stops);
            }
        }
        public override void DrawGeometry(Brush brush, Pen pen, Geometry geometry, Avalonia.Media.Matrix transform)
        {
            Direct2D1StreamGeometry platformGeometry = (Direct2D1StreamGeometry)geometry.PlatformImpl;

            using (TransformedGeometry d2dGeometry = new TransformedGeometry(
                this.factory,
                platformGeometry.Direct2DGeometry,
                transform.ToSharpDX()))
            {
                if (brush != null)
                {
                    this.target.FillGeometry(d2dGeometry, brush.ToSharpDX(this.target));
                }

                if (pen != null)
                {
                    this.target.DrawGeometry(
                        d2dGeometry,
                        pen.Brush.ToSharpDX(this.target),
                        (float)pen.Thickness);
                }
            }
        }
예제 #11
0
 private static void DrawLineCurveInternal(AM.DrawingContext _dc, AM.Pen pen, bool isStroked, ref A.Point pt1, ref A.Point pt2, double curvature, CurveOrientation orientation, PointAlignment pt1a, PointAlignment pt2a)
 {
     if (isStroked)
     {
         var sg = new AM.StreamGeometry();
         using (var sgc = sg.Open())
         {
             sgc.BeginFigure(new A.Point(pt1.X, pt1.Y), false);
             double p1x = pt1.X;
             double p1y = pt1.Y;
             double p2x = pt2.X;
             double p2y = pt2.Y;
             XLineExtensions.GetCurvedLineBezierControlPoints(orientation, curvature, pt1a, pt2a, ref p1x, ref p1y, ref p2x, ref p2y);
             sgc.CubicBezierTo(
                 new A.Point(p1x, p1y),
                 new A.Point(p2x, p2y),
                 new A.Point(pt2.X, pt2.Y));
             sgc.EndFigure(false);
         }
         _dc.DrawGeometry(null, pen, sg);
     }
 }
예제 #12
0
        public void PushGeometryClip(Avalonia.Media.Geometry clip)
        {
            var parameters = new LayerParameters
            {
                ContentBounds = PrimitiveExtensions.RectangleInfinite,
                MaskTransform = PrimitiveExtensions.Matrix3x2Identity,
                Opacity = 1,
                GeometricMask = ((GeometryImpl)clip.PlatformImpl).Geometry
            };
            var layer = _layerPool.Count != 0 ? _layerPool.Pop() : new Layer(_renderTarget);
            _renderTarget.PushLayer(ref parameters, layer);

            _layers.Push(layer);

        }
예제 #13
0
        /// <summary>
        /// Draws a geometry.
        /// </summary>
        /// <param name="brush">The fill brush.</param>
        /// <param name="pen">The stroke pen.</param>
        /// <param name="geometry">The geometry.</param>
        public void DrawGeometry(IBrush brush, Pen pen, Avalonia.Media.Geometry geometry)
        {
            if (brush != null)
            {
                using (var d2dBrush = CreateBrush(brush, geometry.Bounds.Size))
                {
                    if (d2dBrush.PlatformBrush != null)
                    {
                        var impl = (GeometryImpl)geometry.PlatformImpl;
                        _renderTarget.FillGeometry(impl.Geometry, d2dBrush.PlatformBrush);
                    }
                }
            }

            if (pen != null)
            {
                using (var d2dBrush = CreateBrush(pen.Brush, geometry.GetRenderBounds(pen.Thickness).Size))
                using (var d2dStroke = pen.ToDirect2DStrokeStyle(_renderTarget))
                {
                    if (d2dBrush.PlatformBrush != null)
                    {
                        var impl = (GeometryImpl)geometry.PlatformImpl;
                        _renderTarget.DrawGeometry(impl.Geometry, d2dBrush.PlatformBrush, (float)pen.Thickness, d2dStroke);
                    }
                }
            }
        }
예제 #14
0
		public VisualBrushImpl(Avalonia.Media.VisualBrush brush, Size destinationSize)
		{
			this.PlatformBrush = TileBrushes.CreateTileBrush(brush, destinationSize);
		}
예제 #15
0
        private void DrawLineArrowsInternal(AM.DrawingContext dc, XLine line, double dx, double dy, out A.Point pt1, out A.Point pt2)
        {
            AM.IBrush fillStartArrow = ToBrush(line.Style.StartArrowStyle.Fill);
            AM.Pen strokeStartArrow = ToPen(line.Style.StartArrowStyle, _scaleToPage);

            AM.IBrush fillEndArrow = ToBrush(line.Style.EndArrowStyle.Fill);
            AM.Pen strokeEndArrow = ToPen(line.Style.EndArrowStyle, _scaleToPage);

            double _x1 = line.Start.X + dx;
            double _y1 = line.Start.Y + dy;
            double _x2 = line.End.X + dx;
            double _y2 = line.End.Y + dy;

            line.GetMaxLength(ref _x1, ref _y1, ref _x2, ref _y2);

            float x1 = _scaleToPage(_x1);
            float y1 = _scaleToPage(_y1);
            float x2 = _scaleToPage(_x2);
            float y2 = _scaleToPage(_y2);

            var sas = line.Style.StartArrowStyle;
            var eas = line.Style.EndArrowStyle;
            double a1 = Math.Atan2(y1 - y2, x1 - x2);
            double a2 = Math.Atan2(y2 - y1, x2 - x1);

            // Draw start arrow.
            pt1 = DrawLineArrowInternal(dc, strokeStartArrow, fillStartArrow, x1, y1, a1, sas);

            // Draw end arrow.
            pt2 = DrawLineArrowInternal(dc, strokeEndArrow, fillEndArrow, x2, y2, a2, eas);
        }
        public override IPlatformRenderTargetBitmap CreateRenderTargetBitmap(
            int pixelWidth, 
            int pixelHeight, 
            double dpiX, 
            double dpiY, 
            Avalonia.Media.PixelFormat pixelFormat)
        {
            SharpDX.WIC.Bitmap bitmap = new SharpDX.WIC.Bitmap(
                this.wicFactory,
                pixelWidth,
                pixelHeight,
                pixelFormat.ToSharpDX(),
                BitmapCreateCacheOption.CacheOnLoad);

            return new Direct2D1RenderTargetBitmap(
                this.Direct2DFactory,
                this.wicFactory,
                bitmap);
        }
예제 #17
0
 private static void DrawLineInternal(AM.DrawingContext dc, AM.Pen pen, bool isStroked, ref A.Point p0, ref A.Point p1)
 {
     if (isStroked)
     {
         dc.DrawLine(pen, p0, p1);
     }
 }
예제 #18
0
 public NameScopeWrapper(Avalonia.Controls.INameScope inner)
 {
     _inner = inner;
 }