Ejemplo n.º 1
0
 protected virtual void OnValuesChanged(IBrush brush)
 {
     if (ValuesChanged != null)
     {
         ValuesChanged(this, brush);
     }
 }
Ejemplo n.º 2
0
		private TextPaint getPaint(IBrush brush)
		{
			TextPaint paint = ((AndroidBrush)brush).InnerBrush;
			paint.SetTypeface(((AndroidFont)_config.Font).InnerFont);
			paint.TextSize = _config.Font.SizeInPoints;
			return paint;
		}
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a Direct2D brush wrapper for a Avalonia brush.
        /// </summary>
        /// <param name="brush">The avalonia brush.</param>
        /// <param name="destinationSize">The size of the brush's target area.</param>
        /// <returns>The Direct2D brush wrapper.</returns>
        public BrushImpl CreateBrush(IBrush brush, Size destinationSize)
        {
            var solidColorBrush = brush as Avalonia.Media.ISolidColorBrush;
            var linearGradientBrush = brush as Avalonia.Media.LinearGradientBrush;
            var radialGradientBrush = brush as Avalonia.Media.RadialGradientBrush;
            var imageBrush = brush as Avalonia.Media.ImageBrush;
            var visualBrush = brush as Avalonia.Media.VisualBrush;

            if (solidColorBrush != null)
            {
                return new SolidColorBrushImpl(solidColorBrush, _renderTarget);
            }
            else if (linearGradientBrush != null)
            {
                return new LinearGradientBrushImpl(linearGradientBrush, _renderTarget, destinationSize);
            }
            else if (radialGradientBrush != null)
            {
                return new RadialGradientBrushImpl(radialGradientBrush, _renderTarget, destinationSize);
            }
            else if (imageBrush != null)
            {
                return new TileBrushImpl(imageBrush, _renderTarget, destinationSize);
            }
            else if (visualBrush != null)
            {
                return new TileBrushImpl(visualBrush, _renderTarget, destinationSize);
            }
            else
            {
                return new SolidColorBrushImpl((Avalonia.Media.SolidColorBrush)null, _renderTarget);
            }
        }
Ejemplo n.º 4
0
        public FontChooserControl(IBrush brush)
            : base(brush)
        {
            InitializeComponent();

            FontPicker.Items.Clear();
            FontPicker.Items.AddRange(FontFamily.Families.Select(x => x.Name).OfType<object>().ToArray());
            FontPicker.SelectedItem = GetFontFamily().Name;
        }
Ejemplo n.º 5
0
        public PGDIRenderer(GDIContext gdi)
        {
            Graphics = new GDIRenderer(gdi);

            HollowBrush = new GDIBrush(BrushStyle.Hollow, HatchStyle.Horizontal, (Colorref)0, Guid.NewGuid());

            Graphics.UseDefaultPen();
            Graphics.UseDefaultBrush();
        }
Ejemplo n.º 6
0
        public PaintTool(DrawWindow parent, IBrush brush)
        {
            _parent = parent;
            _brush = brush;

            var map = _parent.TilerMap;

            if (_brush == null)
                _brush = new NormalBrush(map != null ? map.TileResolution : 1, TileTexture.None);
        }
Ejemplo n.º 7
0
 public SealControl()
 {
     InitializeComponent();
     SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque | ControlStyles.ResizeRedraw | ControlStyles.Selectable | ControlStyles.UserPaint, true);
     engine = new Engine();
     target = engine.CreateRenderTarget(this, this.Width, this.Height);
     var gm = engine.CreateGeometryManager();
     p = new PathGeometry(gm.CreatePath("M 10,10 C 300,200 50,5 60,40 C 10,10 200,160 100,110"));
     brush = target.CreateSolidColorBrush(Seal.Colors.DarkGoldenrod);
 }
Ejemplo n.º 8
0
        public override void SetBrush(IBrush brush)
        {
            if (brush.BrushStyle == BrushStyle.Hollow)
            {
                Graphics.SetBrush(HollowBrush);
                return;
            }

            Graphics.UseDefaultBrush();
            Graphics.SetDefaultBrushColor(brush.Color);
        }
Ejemplo n.º 9
0
        public void SetBrush(IBrush brush)
        {
            // Only allow normal brushes
            var b = brush as NormalBrush;
            if (b == null)
            {
                var map = _parent.TilerMap;
                b = new NormalBrush(map != null ? map.TileResolution : 1, TileTexture.None);
            }

            _brush = b;
        }
        IRenderBucket IRenderer.this[IBrush brush]
        {
            get
            {
                IRenderBucket bucket;
                var exists = _renderBuckets.TryGetValue(brush, out bucket);
                if (!exists)
                {
                    bucket = new PreTransformedRenderBucket();
                    _renderBuckets.Add(brush, bucket);
                }

                return bucket;
            }
        }
Ejemplo n.º 11
0
		private void drawString(Graphics gfx, IBrush ibrush, float x, float y)
		{
			Brush brush = getBrush(ibrush);
			if (brush == null)
				return;
			Font font = getFont(_config.Font);
			if (_maxWidth == int.MaxValue)
			{
                gfx.DrawString(_text, font, brush, x, y, StringFormat.GenericTypographic);                
			}
			else
			{
				alignWrap();
				gfx.DrawString(_text, font, brush, new RectangleF(x, y, _maxWidth, _height),
					_wrapFormat);
			}
		}
Ejemplo n.º 12
0
        public void DrawGeometry(IBrush brush, Pen pen, Geometry geometry)
        {
            var impl = ((StreamGeometryImpl)geometry.PlatformImpl);
            var size = geometry.Bounds.Size;

            using (var fill = brush != null ? CreatePaint(brush, size) : default(PaintWrapper))
            using (var stroke = pen?.Brush != null ? CreatePaint(pen, size) : default(PaintWrapper))
            {
                if (fill.Paint != null)
                {
                    Canvas.DrawPath(impl.EffectivePath, fill.Paint);
                }
                if (stroke.Paint != null)
                {
                    Canvas.DrawPath(impl.EffectivePath, stroke.Paint);
                }
            }
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Pen"/> class.
 /// </summary>
 /// <param name="brush">The brush used to draw.</param>
 /// <param name="thickness">The stroke thickness.</param>
 /// <param name="dashStyle">The dash style.</param>
 /// <param name="dashCap">The dash cap.</param>
 /// <param name="startLineCap">The start line cap.</param>
 /// <param name="endLineCap">The end line cap.</param>
 /// <param name="lineJoin">The line join.</param>
 /// <param name="miterLimit">The miter limit.</param>
 public Pen(
     IBrush brush, 
     double thickness = 1.0,
     DashStyle dashStyle = null, 
     PenLineCap dashCap = PenLineCap.Flat, 
     PenLineCap startLineCap = PenLineCap.Flat, 
     PenLineCap endLineCap = PenLineCap.Flat, 
     PenLineJoin lineJoin = PenLineJoin.Miter, 
     double miterLimit = 10.0)
 {
     Brush = brush;
     Thickness = thickness;
     DashCap = dashCap;
     StartLineCap = startLineCap;
     EndLineCap = endLineCap;
     LineJoin = lineJoin;
     MiterLimit = miterLimit;
     DashStyle = dashStyle;
 }
Ejemplo n.º 14
0
		public AGSTextConfig(IBrush brush = null, IFont font = null, IBrush outlineBrush = null, float outlineWidth = 0f,
			IBrush shadowBrush = null, float shadowOffsetX = 0f, float shadowOffsetY = 0f, 
			Alignment alignment = Alignment.TopLeft, AutoFit autoFit = AutoFit.NoFitting,
			float paddingLeft = 2f, float paddingRight = 2f, float paddingTop = 2f, float paddingBottom = 2f)
		{
			Brush = brush ?? Hooks.BrushLoader.LoadSolidBrush(Colors.White);
			Font = font ?? AGSGameSettings.DefaultTextFont;
			OutlineBrush = outlineBrush ?? Hooks.BrushLoader.LoadSolidBrush(Colors.White);
            OutlineWidth = outlineWidth;
			ShadowBrush = shadowBrush;
			ShadowOffsetX = shadowOffsetX;
			ShadowOffsetY = shadowOffsetY;
			Alignment = alignment;
			AutoFit = autoFit;
			PaddingLeft = paddingLeft;
			PaddingRight = paddingRight;
			PaddingTop = paddingTop;
			PaddingBottom = paddingBottom;
		}
Ejemplo n.º 15
0
        public StringLabel(string aString, string aFontName, int pointSize, int x, int y, FontStyle style)
            : base("StringLabel",x,y,0,0)
        {
			fNeedsCalculation = true;
			fStyle = style;
			fFont = null;
            fString = aString;
            fFontName = aFontName;
			fPointSize = pointSize;
			fStartPoint = new Point3D(x,y);
            fBasePoint = new Point3D(x, y);
 
			fTextColor = (Colorref)Colorrefs.Black;
            fBackColor = (Colorref)Colorref.TRANSPARENT;
            fBrush = new GDISolidBrush(fTextColor);

            fFont = new GDIFont(fFontName, fPointSize);

			Recalculate();
        }
		public DocumentTabControlViewModel()
		{
			Documents = new ObservableCollection<IDocumentTabViewModel>();
			Documents.CollectionChanged += (sender, e) =>
			{
				if (e.Action == NotifyCollectionChangedAction.Remove)
				{
					Dispatcher.UIThread.InvokeAsync(async () =>
					{
						await Task.Delay(25);
						GC.Collect();
					});
				}
			};

			tabBrush = Brush.Parse("#007ACC");
			tabHighlightBrush = Brush.Parse("#1c97ea");

			temporaryTabBrush = Brush.Parse("#68217A");
			temporaryTabHighlighBrush = Brush.Parse("#B064AB");
		}
    public void PaintTile(Point tileID, IBrush brush)
    {
        if (brush == null)
        {
            Debug.Log("Array doesn't exist");
            return;
        }

        var applyList = new HashSet<Texture2D>();

        // How far we travel
        var right = brush.BrushSize.X / 2;
        var left = (brush.BrushSize.X - 1) / 2;
        var up = brush.BrushSize.Y / 2;
        var down = (brush.BrushSize.Y - 1) / 2;

        for (var y = -down; y <= up; y++)
        {
            for (var x = -left; x <= right; x++)
            {
                var tid = new Point(tileID.X + x, tileID.Y + y);

                var data = brush.GetBrush(x, y);

                var changedTexture = ChangeTile(tid, data);
                if (changedTexture != null)
                    applyList.Add(changedTexture);
            }
        }

        // Apply any changes
        foreach (var texture in applyList)
        {
            texture.Apply();
        }
    }
Ejemplo n.º 18
0
 public void DrawImage(IBitmapImpl source, IBrush opacityMask, Rect opacityMaskRect, Rect destRect)
 {
     PushOpacityMask(opacityMask, opacityMaskRect);
     DrawImage(source, 1, new Rect(0, 0, source.PixelWidth, source.PixelHeight), destRect);
     PopOpacityMask();
 }
Ejemplo n.º 19
0
 public void DrawText(IBrush foreground, Point origin, FormattedText text)
 {
     using (var paint = CreatePaint(foreground, text.Measure()))
     {
         var textImpl = text.PlatformImpl as FormattedTextImpl;
         textImpl.Draw(this, Canvas, origin.ToSKPoint(), paint);
     }
 }
Ejemplo n.º 20
0
        internal PaintWrapper CreatePaint(IBrush brush, Size targetSize)
        {
            SKPaint paint = new SKPaint();
            var rv = new PaintWrapper(paint);
            paint.IsStroke = false;

            // TODO: SkiaSharp does not contain alpha yet!
            double opacity = brush.Opacity * _currentOpacity;
            //paint.SetAlpha(paint.GetAlpha() * opacity);
            paint.IsAntialias = true;

            SKColor color = new SKColor(255, 255, 255, 255);

            var solid = brush as ISolidColorBrush;
            if (solid != null)
                color = solid.Color.ToSKColor();

            paint.Color = (new SKColor(color.Red, color.Green, color.Blue, (byte)(color.Alpha * opacity)));

            if (solid != null)
            {
                return rv;
            }

            var gradient = brush as GradientBrush;
            if (gradient != null)
            {
                var tileMode = gradient.SpreadMethod.ToSKShaderTileMode();
                var stopColors = gradient.GradientStops.Select(s => s.Color.ToSKColor()).ToArray();
                var stopOffsets = gradient.GradientStops.Select(s => (float)s.Offset).ToArray();

                var linearGradient = brush as LinearGradientBrush;
                if (linearGradient != null)
                {
                    var start = linearGradient.StartPoint.ToPixels(targetSize).ToSKPoint();
                    var end = linearGradient.EndPoint.ToPixels(targetSize).ToSKPoint();

                    // would be nice to cache these shaders possibly?
                    var shader = SKShader.CreateLinearGradient(start, end, stopColors, stopOffsets, tileMode);
                    paint.Shader = shader;
                    shader.Dispose();
                }
                else
                {
                    var radialGradient = brush as RadialGradientBrush;
                    if (radialGradient != null)
                    {
                        var center = radialGradient.Center.ToPixels(targetSize).ToSKPoint();
                        var radius = (float)radialGradient.Radius;

                        // TODO: There is no SetAlpha in SkiaSharp
                        //paint.setAlpha(128);

                        // would be nice to cache these shaders possibly?
                        var shader = SKShader.CreateRadialGradient(center, radius, stopColors, stopOffsets, tileMode);
                        paint.Shader = shader;
                        shader.Dispose();
                    }
                }

                return rv;
            }

            var tileBrush = brush as TileBrush;
            if (tileBrush != null)
            {
                var helper = new TileBrushImplHelper(tileBrush, targetSize);
                var bitmap = new BitmapImpl((int)helper.IntermediateSize.Width, (int)helper.IntermediateSize.Height);
                rv.AddDisposable(bitmap);
                using (var ctx = bitmap.CreateDrawingContext())
                    helper.DrawIntermediate(ctx);
                SKMatrix translation = SKMatrix.MakeTranslation(-(float)helper.DestinationRect.X, -(float)helper.DestinationRect.Y);
                SKShaderTileMode tileX =
                    tileBrush.TileMode == TileMode.None
                        ? SKShaderTileMode.Clamp
                        : tileBrush.TileMode == TileMode.FlipX || tileBrush.TileMode == TileMode.FlipXY
                            ? SKShaderTileMode.Mirror
                            : SKShaderTileMode.Repeat;

                SKShaderTileMode tileY =
                    tileBrush.TileMode == TileMode.None
                        ? SKShaderTileMode.Clamp
                        : tileBrush.TileMode == TileMode.FlipY || tileBrush.TileMode == TileMode.FlipXY
                            ? SKShaderTileMode.Mirror
                            : SKShaderTileMode.Repeat;
                paint.Shader = SKShader.CreateBitmap(bitmap.Bitmap, tileX, tileY, translation);
                paint.Shader.Dispose();
            }

            return rv;
        }
Ejemplo n.º 21
0
        /// <summary>
        /// the dash style of the pen
        /// </summary>
        //private DashStyle _dashStyle = DashStyles.Solid;

        /// <summary>
        /// Init.
        /// </summary>
        public PenAdapter(IBrush brush)
        {
            _brush = brush;
        }
Ejemplo n.º 22
0
        private void OnRenderSelection(IDrawingContext dc, RectFloat clipRect)
        {
            IDeviceBitmap bitmap;
            IDeviceBitmap bitmap2;
            IDeviceBitmap bitmap3;
            bool          flag = false;

            try
            {
                this.GetInitializedRenderBitmaps(dc, out bitmap, out bitmap2, out bitmap3);
            }
            catch (RecreateTargetException)
            {
                bitmap  = null;
                bitmap2 = null;
                bitmap3 = null;
            }
            if (((bitmap == null) || (bitmap2 == null)) || (bitmap3 == null))
            {
                flag = true;
            }
            else
            {
                using (dc.UseAntialiasMode(AntialiasMode.Aliased))
                {
                    Matrix3x2Float  identity;
                    RectFloat       renderedMaskSourceRect = this.renderedMaskSourceRect;
                    RectFloat       renderedCanvasBounds   = (RectFloat)this.renderedCanvasBounds;
                    Matrix3x2Double interimTransform       = this.renderedRenderParams.SelectionSnapshot.InterimTransform;
                    VectorDouble    scale = interimTransform.GetScale();
                    if (((interimTransform.HasInverse && (Math.Abs(scale.X) > 0.001)) && (Math.Abs(scale.Y) > 0.001)) && (base.Owner.SelectionSnapshot.GeometryVersion == this.renderedRenderParams.SelectionSnapshot.GeometryVersion))
                    {
                        Matrix3x2Double inverse = interimTransform.Inverse;
                        Matrix3x2Double num9    = base.Owner.Selection.GetInterimTransform();
                        Matrix3x2Double num10   = inverse * num9;
                        identity = (Matrix3x2Float)num10;
                    }
                    else
                    {
                        identity = Matrix3x2Float.Identity;
                    }
                    RectFloat num6 = (RectFloat)RectDouble.Inflate(renderedCanvasBounds, 1.0, 1.0);
                    RectFloat num7 = new RectFloat(PointFloat.Zero, (SizeFloat)this.renderedRenderParams.CanvasSize);
                    using (dc.UseAxisAlignedClip(num7, AntialiasMode.Aliased))
                    {
                        using (dc.UseTransformMultiply(identity, MatrixMultiplyOrder.Prepend))
                        {
                            IBrush cachedOrCreateResource = dc.GetCachedOrCreateResource <IBrush>(this.renderedRenderParams.InteriorBrush);
                            dc.FillOpacityMask(bitmap, cachedOrCreateResource, OpacityMaskContent.Graphics, new RectFloat?(renderedCanvasBounds), new RectFloat?(renderedMaskSourceRect));
                        }
                    }
                    using (dc.UseTransformMultiply(identity, MatrixMultiplyOrder.Prepend))
                    {
                        using (dc.UseAxisAlignedClip(num6, AntialiasMode.Aliased))
                        {
                            IBrush brush = dc.GetCachedOrCreateResource <IBrush>(blackBrush);
                            dc.FillOpacityMask(bitmap2, brush, OpacityMaskContent.Graphics, new RectFloat?(renderedCanvasBounds), new RectFloat?(renderedMaskSourceRect));
                            IBrush brush3 = dc.GetCachedOrCreateResource <IBrush>(whiteBrush);
                            dc.FillOpacityMask(bitmap3, brush3, OpacityMaskContent.Graphics, new RectFloat?(renderedCanvasBounds), new RectFloat?(renderedMaskSourceRect));
                        }
                    }
                }
                if (this.renderedRenderParams.ViewportCanvasBounds != base.CanvasView.ViewportCanvasBounds)
                {
                    flag = true;
                }
            }
            if (flag && !this.isRedrawing)
            {
                this.QueueBeginRedraw();
            }
        }
Ejemplo n.º 23
0
 public override void Fill(IGraphics graphics, IBrush brush, Rectangle rect)
 {
     graphics.FillRoundRectangle(brush, rect, Round);
 }
Ejemplo n.º 24
0
 public abstract void FillPath(IBrush brush, IGfxPath path);
Ejemplo n.º 25
0
 public abstract void DrawArcText(string text, float centerX, float centerY, float radius,
                                  float startAngle, float wedgeAngle,
                                  bool inside, bool clockwise, IFont font, IBrush brush);
 /// <summary>
 /// Initializes a new instance of the <see cref="FillPathProcessor" /> class.
 /// </summary>
 /// <param name="options">The graphics options.</param>
 /// <param name="brush">The details how to fill the region of interest.</param>
 /// <param name="path">The logic path to be filled.</param>
 public FillPathProcessor(DrawingOptions options, IBrush brush, IPath path)
 {
     this.Region  = path;
     this.Brush   = brush;
     this.Options = options;
 }
Ejemplo n.º 27
0
 public abstract void DrawString(string text, IFont font, IBrush brush, float x, float y);
Ejemplo n.º 28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FillRegionProcessor{TPixel}" /> class.
 /// </summary>
 /// <param name="brush">The details how to fill the region of interest.</param>
 /// <param name="region">The region of interest to be filled.</param>
 /// <param name="options">The configuration options.</param>
 public FillRegionProcessor(IBrush <TPixel> brush, Region region, GraphicsOptions options)
 {
     this.Region  = region;
     this.Brush   = brush;
     this.Options = options;
 }
Ejemplo n.º 29
0
 /// <summary>
 /// Draws the text onto the the image filled via the brush.
 /// </summary>
 /// <typeparam name="TPixel">The type of the color.</typeparam>
 /// <param name="source">The image this method extends.</param>
 /// <param name="text">The text.</param>
 /// <param name="font">The font.</param>
 /// <param name="brush">The brush.</param>
 /// <param name="location">The location.</param>
 /// <returns>
 /// The <see cref="Image{TPixel}" />.
 /// </returns>
 public static Image <TPixel> DrawText <TPixel>(this Image <TPixel> source, string text, Font font, IBrush <TPixel> brush, Vector2 location)
     where TPixel : struct, IPixel <TPixel>
 {
     return(source.DrawText(text, font, brush, location, TextGraphicsOptions.Default));
 }
Ejemplo n.º 30
0
        /// <summary>
        /// Draws the text onto the the image filled via the brush then outlined via the pen.
        /// </summary>
        /// <typeparam name="TPixel">The type of the color.</typeparam>
        /// <param name="source">The image this method extends.</param>
        /// <param name="text">The text.</param>
        /// <param name="font">The font.</param>
        /// <param name="brush">The brush.</param>
        /// <param name="pen">The pen.</param>
        /// <param name="location">The location.</param>
        /// <param name="options">The options.</param>
        /// <returns>
        /// The <see cref="Image{TPixel}" />.
        /// </returns>
        public static Image <TPixel> DrawText <TPixel>(this Image <TPixel> source, string text, Font font, IBrush <TPixel> brush, IPen <TPixel> pen, Vector2 location, TextGraphicsOptions options)
            where TPixel : struct, IPixel <TPixel>
        {
            GlyphBuilder glyphBuilder = new GlyphBuilder(location);

            TextRenderer renderer = new TextRenderer(glyphBuilder);

            Vector2 dpi = DefaultTextDpi;

            if (options.UseImageResolution)
            {
                dpi = new Vector2((float)source.MetaData.HorizontalResolution, (float)source.MetaData.VerticalResolution);
            }

            FontSpan style = new FontSpan(font, dpi)
            {
                ApplyKerning  = options.ApplyKerning,
                TabWidth      = options.TabWidth,
                WrappingWidth = options.WrapTextWidth,
                Alignment     = options.TextAlignment
            };

            renderer.RenderText(text, style);

            System.Collections.Generic.IEnumerable <SixLabors.Shapes.IPath> shapesToDraw = glyphBuilder.Paths;

            GraphicsOptions pathOptions = (GraphicsOptions)options;

            if (brush != null)
            {
                foreach (SixLabors.Shapes.IPath s in shapesToDraw)
                {
                    source.Fill(brush, s, pathOptions);
                }
            }

            if (pen != null)
            {
                foreach (SixLabors.Shapes.IPath s in shapesToDraw)
                {
                    source.Draw(pen, s, pathOptions);
                }
            }

            return(source);
        }
Ejemplo n.º 31
0
 private void RenderSelection(IDrawingContext dc, float scale, PointFloat offset, SelectionRenderParameters renderParams, Result <IGeometry> lazyGeometry, IBrush interiorBrush, IBrush outlineBrush, IStrokeStyle outlineStrokeStyle, AntialiasMode antialiasMode)
 {
     using (dc.UseScaleTransform(scale, scale, MatrixMultiplyOrder.Prepend))
     {
         using (dc.UseTranslateTransform(offset.X, offset.Y, MatrixMultiplyOrder.Prepend))
         {
             if (renderParams.IsInteriorFilled && (interiorBrush != null))
             {
                 using (dc.UseAntialiasMode(AntialiasMode.Aliased))
                 {
                     dc.FillGeometry(lazyGeometry.Value, interiorBrush, null);
                 }
             }
             if (renderParams.IsOutlineEnabled && (outlineBrush != null))
             {
                 float strokeWidth = this.outlineStrokeWidthPx / scale;
                 using (dc.UseAntialiasMode(antialiasMode))
                 {
                     using (dc.UseTranslateTransform(0.5f, 0.5f, MatrixMultiplyOrder.Append))
                     {
                         dc.DrawGeometry(lazyGeometry.Value, outlineBrush, strokeWidth, outlineStrokeStyle);
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 32
0
        private static IEnumerable <BoxShadowLayer> GetShadowLayers(String value,
                                                                    IStyleVariableAccessor variableAccessor)
        {
            var multiTokens = GetMultiSplit(value, ',');

            foreach (var multiToken in multiTokens)
            {
                var tokens = GetMultiSplit(multiToken, ' ').ToArray();

                if (tokens.Length < 2)
                {
                    throw new InvalidOperationException();
                }

                var    offsetX = GetQuantity(tokens[0], variableAccessor);
                var    offsetY = GetQuantity(tokens[1], variableAccessor);
                var    blur    = QuantifiedDouble.Zero;
                var    spread  = QuantifiedDouble.Zero;
                IBrush color   = SolidColorBrush.Black;
                var    isInset = false;

                for (var c = 2; c < tokens.Length; c++)
                {
                    //if (tokens.Length > 2)
                    {
                        if (TryGetQuantity(tokens[c], variableAccessor, out var q))
                        {
                            if (blur.IsZero())
                            {
                                blur = q;
                            }
                            else
                            {
                                spread = q;
                            }
                        }

                        else if (TryGetColor(tokens[c], variableAccessor, out var clr))
                        {
                            color = clr;
                        }

                        else if (String.Equals(tokens[c], nameof(BoxShadowLayer.IsInset),
                                               StringComparison.OrdinalIgnoreCase))
                        {
                            isInset = true;
                        }

                        else
                        {
                            throw new NotImplementedException();
                        }
                    }
                }

                yield return(new BoxShadowLayer(offsetX, offsetY, blur, spread, color, isInset));
            }


            //foreach (var token in tokens)
            //    yield return new BoxShadow(token, variableAccessor);
        }
Ejemplo n.º 33
0
 /// <summary>
 /// Draws the text onto the the image filled via the brush.
 /// </summary>
 /// <typeparam name="TPixel">The type of the color.</typeparam>
 /// <param name="source">The image this method extends.</param>
 /// <param name="text">The text.</param>
 /// <param name="font">The font.</param>
 /// <param name="brush">The brush.</param>
 /// <param name="path">The path.</param>
 /// <param name="options">The options.</param>
 /// <returns>
 /// The <see cref="Image{TPixel}" />.
 /// </returns>
 public static Image <TPixel> DrawText <TPixel>(this Image <TPixel> source, string text, Font font, IBrush <TPixel> brush, IPath path, TextGraphicsOptions options)
     where TPixel : struct, IPixel <TPixel>
 {
     return(source.DrawText(text, font, brush, null, path, options));
 }
Ejemplo n.º 34
0
        /// <inheritdoc />
        public void DrawRectangle(IBrush brush, IPen pen, RoundedRect rect, BoxShadows boxShadows = default)
        {
            if (rect.Rect.Height <= 0 || rect.Rect.Width <= 0)
            {
                return;
            }
            // Arbitrary chosen values
            // On OSX Skia breaks OpenGL context when asked to draw, e. g. (0, 0, 623, 6666600) rect
            if (rect.Rect.Height > 8192 || rect.Rect.Width > 8192)
            {
                boxShadows = default;
            }

            var rc            = rect.Rect.ToSKRect();
            var isRounded     = rect.IsRounded;
            var needRoundRect = rect.IsRounded || (boxShadows.HasInsetShadows);

            using var skRoundRect = needRoundRect ? new SKRoundRect() : null;
            if (needRoundRect)
            {
                skRoundRect.SetRectRadii(rc,
                                         new[]
                {
                    rect.RadiiTopLeft.ToSKPoint(), rect.RadiiTopRight.ToSKPoint(),
                    rect.RadiiBottomRight.ToSKPoint(), rect.RadiiBottomLeft.ToSKPoint(),
                });
            }

            foreach (var boxShadow in boxShadows)
            {
                if (!boxShadow.IsEmpty && !boxShadow.IsInset)
                {
                    using (var shadow = BoxShadowFilter.Create(_boxShadowPaint, boxShadow, _currentOpacity))
                    {
                        var spread = (float)boxShadow.Spread;
                        if (boxShadow.IsInset)
                        {
                            spread = -spread;
                        }

                        Canvas.Save();
                        if (isRounded)
                        {
                            using var shadowRect = new SKRoundRect(skRoundRect);
                            if (spread != 0)
                            {
                                shadowRect.Inflate(spread, spread);
                            }
                            Canvas.ClipRoundRect(skRoundRect,
                                                 shadow.ClipOperation, true);

                            var oldTransform = Transform;
                            Transform = oldTransform * Matrix.CreateTranslation(boxShadow.OffsetX, boxShadow.OffsetY);
                            Canvas.DrawRoundRect(shadowRect, shadow.Paint);
                            Transform = oldTransform;
                        }
                        else
                        {
                            var shadowRect = rc;
                            if (spread != 0)
                            {
                                shadowRect.Inflate(spread, spread);
                            }
                            Canvas.ClipRect(rc, shadow.ClipOperation);
                            var oldTransform = Transform;
                            Transform = oldTransform * Matrix.CreateTranslation(boxShadow.OffsetX, boxShadow.OffsetY);
                            Canvas.DrawRect(shadowRect, shadow.Paint);
                            Transform = oldTransform;
                        }

                        Canvas.Restore();
                    }
                }
            }

            if (brush != null)
            {
                using (var paint = CreatePaint(_fillPaint, brush, rect.Rect.Size))
                {
                    if (isRounded)
                    {
                        Canvas.DrawRoundRect(skRoundRect, paint.Paint);
                    }
                    else
                    {
                        Canvas.DrawRect(rc, paint.Paint);
                    }
                }
            }

            foreach (var boxShadow in boxShadows)
            {
                if (!boxShadow.IsEmpty && boxShadow.IsInset)
                {
                    using (var shadow = BoxShadowFilter.Create(_boxShadowPaint, boxShadow, _currentOpacity))
                    {
                        var spread    = (float)boxShadow.Spread;
                        var offsetX   = (float)boxShadow.OffsetX;
                        var offsetY   = (float)boxShadow.OffsetY;
                        var outerRect = AreaCastingShadowInHole(rc, (float)boxShadow.Blur, spread, offsetX, offsetY);

                        Canvas.Save();
                        using var shadowRect = new SKRoundRect(skRoundRect);
                        if (spread != 0)
                        {
                            shadowRect.Deflate(spread, spread);
                        }
                        Canvas.ClipRoundRect(skRoundRect,
                                             shadow.ClipOperation, true);

                        var oldTransform = Transform;
                        Transform = oldTransform * Matrix.CreateTranslation(boxShadow.OffsetX, boxShadow.OffsetY);
                        using (var outerRRect = new SKRoundRect(outerRect))
                            Canvas.DrawRoundRectDifference(outerRRect, shadowRect, shadow.Paint);
                        Transform = oldTransform;
                        Canvas.Restore();
                    }
                }
            }

            if (pen?.Brush != null)
            {
                using (var paint = CreatePaint(_strokePaint, pen, rect.Rect.Size))
                {
                    if (paint.Paint is object)
                    {
                        if (isRounded)
                        {
                            Canvas.DrawRoundRect(skRoundRect, paint.Paint);
                        }
                        else
                        {
                            Canvas.DrawRect(rc, paint.Paint);
                        }
                    }
                }
            }
        }
Ejemplo n.º 35
0
 /// <summary>
 /// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
 /// </summary>
 /// <typeparam name="TPixel">The type of the color.</typeparam>
 /// <param name="source">The image this method extends.</param>
 /// <param name="brush">The brush.</param>
 /// <param name="thickness">The thickness.</param>
 /// <param name="points">The points.</param>
 /// <returns>The <see cref="Image{TPixel}"/>.</returns>
 public static IImageProcessingContext <TPixel> DrawLines <TPixel>(this IImageProcessingContext <TPixel> source, IBrush <TPixel> brush, float thickness, params PointF[] points)
     where TPixel : struct, IPixel <TPixel>
 => source.Draw(new Pen <TPixel>(brush, thickness), new Path(new LinearLineSegment(points)));
Ejemplo n.º 36
0
 /// <inheritdoc />
 public void DrawBitmap(IRef <IBitmapImpl> source, IBrush opacityMask, Rect opacityMaskRect, Rect destRect)
 {
     PushOpacityMask(opacityMask, opacityMaskRect);
     DrawBitmap(source, 1, new Rect(0, 0, source.Item.PixelSize.Width, source.Item.PixelSize.Height), destRect, BitmapInterpolationMode.Default);
     PopOpacityMask();
 }
Ejemplo n.º 37
0
 /// <summary>
 /// Flood fills the image in the shape of the provided polygon with the specified brush.
 /// </summary>
 /// <typeparam name="TColor">The type of the color.</typeparam>
 /// <param name="source">The image this method extends.</param>
 /// <param name="brush">The brush.</param>
 /// <param name="shape">The shape.</param>
 /// <returns>The <see cref="Image{TColor}"/>.</returns>
 public static Image <TColor> Fill <TColor>(this Image <TColor> source, IBrush <TColor> brush, IShape shape)
     where TColor : struct, IPackedPixel, IEquatable <TColor>
 {
     return(source.Fill(brush, new ShapeRegion(shape), GraphicsOptions.Default));
 }
Ejemplo n.º 38
0
 public override void Fill(IGraphics graphics, IBrush brush, Rectangle rect)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="FillProcessor"/> class.
 /// </summary>
 /// <param name="brush">The brush to use for filling.</param>
 /// <param name="options">The <see cref="GraphicsOptions"/> defining how to blend the brush pixels over the image pixels.</param>
 public FillProcessor(IBrush brush, GraphicsOptions options)
 {
     this.Brush   = brush;
     this.Options = options;
 }
Ejemplo n.º 40
0
 public TrueTypeMarkerSymbol()
 {
     _brush = Current.Engine.CreateSolidBrush(ArgbColor.Black);
     _font  = Current.Engine.CreateFont("Arial", 10f);
 }
Ejemplo n.º 41
0
 private TrueTypeMarkerSymbol(IFont font, ArgbColor color)
 {
     _brush = Current.Engine.CreateSolidBrush(color);
     _font  = font;
 }
Ejemplo n.º 42
0
 /// <summary>
 /// Sets the foreground brush for the specified text range.
 /// </summary>
 /// <param name="brush">The brush.</param>
 /// <param name="startIndex">The start of the text range.</param>
 /// <param name="length">The length of the text range.</param>
 public void SetForegroundBrush(IBrush brush, int startIndex, int length)
 {
     CheckDisposed();
     PlatformImpl.SetForegroundBrush(brush, startIndex, length);
 }
Ejemplo n.º 43
0
        public override void Render(DrawingContext context)
        {
            var selectionStart = SelectionStart;
            var selectionEnd = SelectionEnd;

            if (selectionStart != selectionEnd)
            {
                var start = Math.Min(selectionStart, selectionEnd);
                var length = Math.Max(selectionStart, selectionEnd) - start;

                // issue #600: set constaint before any FormattedText manipulation
                //             see base.Render(...) implementation
                FormattedText.Constraint = Bounds.Size;

                var rects = FormattedText.HitTestTextRange(start, length);

                if (_highlightBrush == null)
                {
                    _highlightBrush = (IBrush)this.FindStyleResource("HighlightBrush");
                }

                foreach (var rect in rects)
                {
                    context.FillRectangle(_highlightBrush, rect);
                }
            }

            base.Render(context);

            if (selectionStart == selectionEnd)
            {                
                var backgroundColor = (((Control)TemplatedParent).GetValue(BackgroundProperty) as SolidColorBrush)?.Color;
                var caretBrush = Brushes.Black;

                if(backgroundColor.HasValue)
                {
                    byte red = (byte)~(backgroundColor.Value.R);
                    byte green = (byte)~(backgroundColor.Value.G);
                    byte blue = (byte)~(backgroundColor.Value.B);

                    caretBrush = new SolidColorBrush(Color.FromRgb(red, green, blue));
                }
                
                if (_caretBlink)
                {
                    var charPos = FormattedText.HitTestTextPosition(CaretIndex);
                    var x = Math.Floor(charPos.X) + 0.5;
                    var y = Math.Floor(charPos.Y) + 0.5;
                    var b = Math.Ceiling(charPos.Bottom) - 0.5;

                    context.DrawLine(
                        new Pen(caretBrush, 1),
                        new Point(x, y),
                        new Point(x, b));
                }
            }
        }
Ejemplo n.º 44
0
 private void ValuesChanged(IBrush brush)
 {
     if (BrushManager.CurrentBrush == brush) _updatePreview = true;
 }
Ejemplo n.º 45
0
		public GUIStyle()
		{
			fBorderWidth = 2;

			fBaseColor = (Colorref)Colorrefs.LtGray;
            fHighlightColor = GUIStyle.brighter(fBaseColor);
            fShadowColor = GUIStyle.darker(fBaseColor);
            fBackground = GUIStyle.brighter(fHighlightColor);
            fForeground = (Colorref)Colorrefs.LtGray;
            fTextBackground = fBaseColor;
            fBottomShadow = GUIStyle.darker(fForeground); // 0x00616161;
            fBottomShadowTopLiner = GUIStyle.brighter(fBottomShadow); //fForeground;
            fTopShadow = GUIStyle.brighter(fForeground);  // 0x00cbcbcb;

            fBackground = GUIStyle.brighter((Colorref)Colorrefs.DarkGray); //0x009e9e9e;


            fBasePen = new GDIPen(fBaseColor);
            fHighlightPen = new GDIPen(fHighlightColor);
            fShadowPen = new GDIPen(fShadowColor);
            fBottomShadowBottomLinerPen = new GDIPen(fBottomShadowBottomLiner);

            fBaseColorBrush = new GDIBrush(fBaseColor);

			GUIStyle.Default = this;
		}
Ejemplo n.º 46
0
 public void PushOpacityMask(IBrush mask, Rect bounds)
 {
     Canvas.SaveLayer(new SKPaint());
     maskStack.Push(CreatePaint(mask, bounds.Size));
 }
Ejemplo n.º 47
0
 public void FillRectangle(IBrush brush, Rect rect, float cornerRadius = 0)
 {
     using (var paint = CreatePaint(brush, rect.Size))
     {
         var rc = rect.ToSKRect();
         if (cornerRadius == 0)
         {
             Canvas.DrawRect(rc, paint.Paint);
         }
         else
         {
             Canvas.DrawRoundRect(rc, cornerRadius, cornerRadius, paint.Paint);
         }
     }
 }
Ejemplo n.º 48
0
 /// <summary>
 /// Draws the text onto the the image filled via the brush then outlined via the pen.
 /// </summary>
 /// <typeparam name="TPixel">The type of the color.</typeparam>
 /// <param name="source">The image this method extends.</param>
 /// <param name="text">The text.</param>
 /// <param name="font">The font.</param>
 /// <param name="brush">The brush.</param>
 /// <param name="pen">The pen.</param>
 /// <param name="path">The path.</param>
 /// <returns>
 /// The <see cref="Image{TPixel}" />.
 /// </returns>
 public static Image <TPixel> DrawText <TPixel>(this Image <TPixel> source, string text, Font font, IBrush <TPixel> brush, IPen <TPixel> pen, IPath path)
     where TPixel : struct, IPixel <TPixel>
 {
     return(source.DrawText(text, font, brush, pen, path, TextGraphicsOptions.Default));
 }
Ejemplo n.º 49
0
 public void PushOpacityMask(IBrush mask, Rect bounds)
 {
     Canvas.SaveLayer(new SKPaint());
     maskStack.Push(CreatePaint(mask, bounds.Size));
 }
Ejemplo n.º 50
0
        /// <summary>
        /// Draws the text onto the the image filled via the brush then outlined via the pen.
        /// </summary>
        /// <typeparam name="TPixel">The type of the color.</typeparam>
        /// <param name="source">The image this method extends.</param>
        /// <param name="text">The text.</param>
        /// <param name="font">The font.</param>
        /// <param name="brush">The brush.</param>
        /// <param name="pen">The pen.</param>
        /// <param name="path">The path.</param>
        /// <param name="options">The options.</param>
        /// <returns>
        /// The <see cref="Image{TPixel}" />.
        /// </returns>
        public static Image <TPixel> DrawText <TPixel>(this Image <TPixel> source, string text, Font font, IBrush <TPixel> brush, IPen <TPixel> pen, IPath path, TextGraphicsOptions options)
            where TPixel : struct, IPixel <TPixel>
        {
            Vector2 dpi = DefaultTextDpi;

            if (options.UseImageResolution)
            {
                dpi = new Vector2((float)source.MetaData.HorizontalResolution, (float)source.MetaData.VerticalResolution);
            }

            var style = new FontSpan(font, dpi)
            {
                ApplyKerning        = options.ApplyKerning,
                TabWidth            = options.TabWidth,
                WrappingWidth       = options.WrapTextWidth,
                HorizontalAlignment = options.HorizontalAlignment,
                VerticalAlignment   = options.VerticalAlignment
            };

            IPathCollection glyphs = TextBuilder.GenerateGlyphs(text, path, style);

            var pathOptions = (GraphicsOptions)options;

            if (brush != null)
            {
                source.Fill(brush, glyphs, pathOptions);
            }

            if (pen != null)
            {
                source.Draw(pen, glyphs, pathOptions);
            }

            return(source);
        }
Ejemplo n.º 51
0
 public LineNumberMargin()
 { 
     foreground = Brush.Parse("#2691AF");  
     currentLineForeground = Brush.Parse("#2691AF");
 }
Ejemplo n.º 52
0
        private void RedrawOnBackgroundThread()
        {
            if (base.CheckAccess())
            {
                ExceptionUtil.ThrowInvalidOperationException();
            }
            if (this.redrawThreadFactory == null)
            {
                this.redrawThreadFactory = new Direct2DFactory(Direct2DFactoryType.MultiThreaded, DebugLevel.None);
            }
            if ((this.redrawThreadGeometryCache == null) || (this.redrawThreadGeometryCache.SelectionSnapshot != this.redrawRenderParams.SelectionSnapshot))
            {
                DisposableUtil.Free <SelectionGeometryCache>(ref this.redrawThreadGeometryCache);
                this.redrawThreadGeometryCache = new SelectionGeometryCache(this.redrawThreadFactory, this.redrawRenderParams.SelectionSnapshot);
            }
            double      scaleRatio           = this.redrawRenderParams.ScaleRatio;
            PointDouble location             = this.redrawRenderParams.ViewportCanvasBounds.Location;
            SizeDouble  viewportSize         = this.redrawRenderParams.ViewportSize;
            SizeInt32   num5                 = SizeDouble.Ceiling(viewportSize);
            RectDouble  b                    = RectDouble.Inflate(CanvasCoordinateConversions.ConvertExtentToViewport(CanvasCoordinateConversions.ConvertCanvasToExtent(this.redrawRenderParams.SelectionSnapshot.GeometryList.Value.Bounds, scaleRatio), scaleRatio, location), (double)this.outlineStrokeWidthPx, (double)this.outlineStrokeWidthPx);
            RectDouble  a                    = new RectDouble(PointDouble.Zero, viewportSize);
            RectDouble  renderViewportBounds = RectDouble.Intersect(a, b);
            RectInt32   viewportRect         = renderViewportBounds.Int32Bound;
            RectDouble  extentRect           = CanvasCoordinateConversions.ConvertViewportToExtent(viewportRect, scaleRatio, location);
            RectDouble  renderCanvasBounds   = CanvasCoordinateConversions.ConvertExtentToCanvas(extentRect, scaleRatio);

            if (!viewportRect.HasPositiveArea)
            {
                base.SyncContext.Post((SendOrPostCallback)(_ => this.EndRedraw(renderViewportBounds, RectFloat.Zero, null, null)));
            }
            else
            {
                IBitmap <ColorAlpha8> interiorMask;
                float                   scale;
                PointFloat              offset;
                Result <IGeometry>      lazyGeometry;
                IBitmap <ColorAlpha8>[] dashedOutlineMasks;
                RectFloat               maskSourceRect;
                SelectionSnapshot       selectionSnapshot         = this.redrawRenderParams.SelectionSnapshot;
                SelectionGeometryCache  redrawThreadGeometryCache = this.redrawThreadGeometryCache;
                bool flag = this.redrawRenderParams.SelectionRenderingQuality == SelectionRenderingQuality.Aliased;
                if (!flag)
                {
                    lazyGeometry = redrawThreadGeometryCache.Geometry;
                }
                else
                {
                    bool flag3 = selectionSnapshot.IsRectilinear.Value;
                    bool flag4 = selectionSnapshot.IsPixelated.Value;
                    if (flag3 & flag4)
                    {
                        lazyGeometry = redrawThreadGeometryCache.Geometry;
                    }
                    else
                    {
                        lazyGeometry = redrawThreadGeometryCache.PixelatedGeometry;
                    }
                }
                bool          flag2         = !flag && this.redrawRenderParams.IsOutlineAntialiased;
                AntialiasMode antialiasMode = ((flag || !flag2) || selectionSnapshot.IsRectilinear.Value) ? AntialiasMode.Aliased : AntialiasMode.PerPrimitive;
                if (this.CanContinueRedrawing(null, null))
                {
                    scale = (float)this.redrawRenderParams.ScaleRatio;
                    float x = -((float)renderCanvasBounds.X);
                    float y = -((float)renderCanvasBounds.Y);
                    offset       = new PointFloat(x, y);
                    interiorMask = BitmapAllocator.Alpha8.Allocate(viewportRect.Size, AllocationOptions.ZeroFillNotRequired);
                    try
                    {
                        RetryManager.RunMemorySensitiveOperation(delegate {
                            using (IDrawingContext context = DrawingContext.FromBitmap(this.redrawThreadFactory, interiorMask))
                            {
                                context.Clear(null);
                                IBrush interiorBrush = context.GetCachedOrCreateResource <IBrush>(whiteBrush);
                                this.RenderSelection(context, scale, offset, this.redrawRenderParams, lazyGeometry, interiorBrush, null, null, antialiasMode);
                            }
                        });
                    }
                    catch (OutOfMemoryException)
                    {
                    }
                    if (this.CanContinueRedrawing(interiorMask, null))
                    {
                        int num15;
                        dashedOutlineMasks = new IBitmap <ColorAlpha8> [SelectionCanvasLayer.DashLength];
                        for (int i = 0; i < dashedOutlineMasks.Length; i = num15)
                        {
                            if ((!this.redrawRenderParams.IsOutlineAnimated && (i != 0)) && (i != (SelectionCanvasLayer.DashLength / 2)))
                            {
                                dashedOutlineMasks[i] = null;
                            }
                            else
                            {
                                dashedOutlineMasks[i] = BitmapAllocator.Alpha8.Allocate(viewportRect.Size, AllocationOptions.ZeroFillNotRequired);
                                try
                                {
                                    RetryManager.RunMemorySensitiveOperation(delegate {
                                        using (IDrawingContext context = DrawingContext.FromBitmap(this.redrawThreadFactory, dashedOutlineMasks[i]))
                                        {
                                            context.Clear(null);
                                            StrokeStyle resourceSource      = SelectionCanvasLayer.GetDashedStrokeStyle(i);
                                            IStrokeStyle outlineStrokeStyle = context.GetCachedOrCreateResource <IStrokeStyle>(resourceSource);
                                            IBrush cachedOrCreateResource   = context.GetCachedOrCreateResource <IBrush>(whiteBrush);
                                            this.RenderSelection(context, scale, offset, this.redrawRenderParams, lazyGeometry, null, cachedOrCreateResource, outlineStrokeStyle, antialiasMode);
                                        }
                                    });
                                }
                                catch (OutOfMemoryException)
                                {
                                }
                                if (!this.CanContinueRedrawing(interiorMask, dashedOutlineMasks))
                                {
                                    return;
                                }
                            }
                            num15 = i + 1;
                        }
                        maskSourceRect = new RectFloat(PointFloat.Zero, interiorMask.Size);
                        base.SyncContext.Post(_ => this.EndRedraw(renderCanvasBounds, maskSourceRect, interiorMask, dashedOutlineMasks), null);
                    }
                }
            }
        }
Ejemplo n.º 53
0
        public void SetForegroundBrush(IBrush brush, int startIndex, int length)
        {
            var key = new FBrushRange(startIndex, length);
            int index = _foregroundBrushes.FindIndex(v => v.Key.Equals(key));

            if (index > -1)
            {
                _foregroundBrushes.RemoveAt(index);
            }

            if (brush != null)
            {
                _foregroundBrushes.Insert(0, new KeyValuePair<FBrushRange, IBrush>(key, brush));
            }
        }
Ejemplo n.º 54
0
        /// <summary>
        /// Creates a Direct2D brush wrapper for a Avalonia brush.
        /// </summary>
        /// <param name="brush">The avalonia brush.</param>
        /// <param name="destinationSize">The size of the brush's target area.</param>
        /// <returns>The Direct2D brush wrapper.</returns>
        public BrushImpl CreateBrush(IBrush brush, Size destinationSize)
        {
            var solidColorBrush     = brush as ISolidColorBrush;
            var linearGradientBrush = brush as ILinearGradientBrush;
            var radialGradientBrush = brush as IRadialGradientBrush;
            var imageBrush          = brush as IImageBrush;
            var visualBrush         = brush as IVisualBrush;

            if (solidColorBrush != null)
            {
                return(new SolidColorBrushImpl(solidColorBrush, _deviceContext));
            }
            else if (linearGradientBrush != null)
            {
                return(new LinearGradientBrushImpl(linearGradientBrush, _deviceContext, destinationSize));
            }
            else if (radialGradientBrush != null)
            {
                return(new RadialGradientBrushImpl(radialGradientBrush, _deviceContext, destinationSize));
            }
            else if (imageBrush?.Source != null)
            {
                return(new ImageBrushImpl(
                           imageBrush,
                           _deviceContext,
                           (BitmapImpl)imageBrush.Source.PlatformImpl.Item,
                           destinationSize));
            }
            else if (visualBrush != null)
            {
                if (_visualBrushRenderer != null)
                {
                    var intermediateSize = _visualBrushRenderer.GetRenderTargetSize(visualBrush);

                    if (intermediateSize.Width >= 1 && intermediateSize.Height >= 1)
                    {
                        // We need to ensure the size we're requesting is an integer pixel size, otherwise
                        // D2D alters the DPI of the render target, which messes stuff up. PixelSize.FromSize
                        // will do the rounding for us.
                        var dpi       = new Vector(_deviceContext.DotsPerInch.Width, _deviceContext.DotsPerInch.Height);
                        var pixelSize = PixelSize.FromSizeWithDpi(intermediateSize, dpi);

                        using (var intermediate = new BitmapRenderTarget(
                                   _deviceContext,
                                   CompatibleRenderTargetOptions.None,
                                   pixelSize.ToSizeWithDpi(dpi).ToSharpDX()))
                        {
                            using (var ctx = new RenderTarget(intermediate).CreateDrawingContext(_visualBrushRenderer))
                            {
                                intermediate.Clear(null);
                                _visualBrushRenderer.RenderVisualBrush(ctx, visualBrush);
                            }

                            return(new ImageBrushImpl(
                                       visualBrush,
                                       _deviceContext,
                                       new D2DBitmapImpl(intermediate.Bitmap),
                                       destinationSize));
                        }
                    }
                }
                else
                {
                    throw new NotSupportedException("No IVisualBrushRenderer was supplied to DrawingContextImpl.");
                }
            }

            return(new SolidColorBrushImpl(null, _deviceContext));
        }
Ejemplo n.º 55
0
 public NumericControl(IBrush brush) : base(brush)
 {
     InitializeComponent();
 }
Ejemplo n.º 56
0
        internal PaintWrapper CreatePaint(IBrush brush, Size targetSize)
        {
            SKPaint paint = new SKPaint();
            var     rv    = new PaintWrapper(paint);

            paint.IsStroke = false;


            double opacity = brush.Opacity * _currentOpacity;

            paint.IsAntialias = true;

            var solid = brush as ISolidColorBrush;

            if (solid != null)
            {
                paint.Color = new SKColor(solid.Color.R, solid.Color.G, solid.Color.B, (byte)(solid.Color.A * opacity));
                return(rv);
            }
            paint.Color = (new SKColor(255, 255, 255, (byte)(255 * opacity)));

            var gradient = brush as IGradientBrush;

            if (gradient != null)
            {
                var tileMode    = gradient.SpreadMethod.ToSKShaderTileMode();
                var stopColors  = gradient.GradientStops.Select(s => s.Color.ToSKColor()).ToArray();
                var stopOffsets = gradient.GradientStops.Select(s => (float)s.Offset).ToArray();

                var linearGradient = brush as ILinearGradientBrush;
                if (linearGradient != null)
                {
                    var start = linearGradient.StartPoint.ToPixels(targetSize).ToSKPoint();
                    var end   = linearGradient.EndPoint.ToPixels(targetSize).ToSKPoint();

                    // would be nice to cache these shaders possibly?
                    using (var shader = SKShader.CreateLinearGradient(start, end, stopColors, stopOffsets, tileMode))
                        paint.Shader = shader;
                }
                else
                {
                    var radialGradient = brush as IRadialGradientBrush;
                    if (radialGradient != null)
                    {
                        var center = radialGradient.Center.ToPixels(targetSize).ToSKPoint();
                        var radius = (float)radialGradient.Radius;

                        // TODO: There is no SetAlpha in SkiaSharp
                        //paint.setAlpha(128);

                        // would be nice to cache these shaders possibly?
                        using (var shader = SKShader.CreateRadialGradient(center, radius, stopColors, stopOffsets, tileMode))
                            paint.Shader = shader;
                    }
                }

                return(rv);
            }

            var tileBrush      = brush as ITileBrush;
            var visualBrush    = brush as IVisualBrush;
            var tileBrushImage = default(BitmapImpl);

            if (visualBrush != null)
            {
                if (_visualBrushRenderer != null)
                {
                    var intermediateSize = _visualBrushRenderer.GetRenderTargetSize(visualBrush);

                    if (intermediateSize.Width >= 1 && intermediateSize.Height >= 1)
                    {
                        var intermediate = new BitmapImpl((int)intermediateSize.Width, (int)intermediateSize.Height, _dpi);

                        using (var ctx = intermediate.CreateDrawingContext(_visualBrushRenderer))
                        {
                            ctx.Clear(Colors.Transparent);
                            _visualBrushRenderer.RenderVisualBrush(ctx, visualBrush);
                        }

                        rv.AddDisposable(tileBrushImage);
                        tileBrushImage = intermediate;
                    }
                }
                else
                {
                    throw new NotSupportedException("No IVisualBrushRenderer was supplied to DrawingContextImpl.");
                }
            }
            else
            {
                tileBrushImage = (BitmapImpl)((tileBrush as IImageBrush)?.Source?.PlatformImpl);
            }

            if (tileBrush != null && tileBrushImage != null)
            {
                var calc   = new TileBrushCalculator(tileBrush, new Size(tileBrushImage.PixelWidth, tileBrushImage.PixelHeight), targetSize);
                var bitmap = new BitmapImpl((int)calc.IntermediateSize.Width, (int)calc.IntermediateSize.Height, _dpi);
                rv.AddDisposable(bitmap);
                using (var context = bitmap.CreateDrawingContext(null))
                {
                    var rect = new Rect(0, 0, tileBrushImage.PixelWidth, tileBrushImage.PixelHeight);

                    context.Clear(Colors.Transparent);
                    context.PushClip(calc.IntermediateClip);
                    context.Transform = calc.IntermediateTransform;
                    context.DrawImage(tileBrushImage, 1, rect, rect);
                    context.PopClip();
                }

                SKMatrix         translation = SKMatrix.MakeTranslation(-(float)calc.DestinationRect.X, -(float)calc.DestinationRect.Y);
                SKShaderTileMode tileX       =
                    tileBrush.TileMode == TileMode.None
                        ? SKShaderTileMode.Clamp
                        : tileBrush.TileMode == TileMode.FlipX || tileBrush.TileMode == TileMode.FlipXY
                            ? SKShaderTileMode.Mirror
                            : SKShaderTileMode.Repeat;

                SKShaderTileMode tileY =
                    tileBrush.TileMode == TileMode.None
                        ? SKShaderTileMode.Clamp
                        : tileBrush.TileMode == TileMode.FlipY || tileBrush.TileMode == TileMode.FlipXY
                            ? SKShaderTileMode.Mirror
                            : SKShaderTileMode.Repeat;
                using (var shader = SKShader.CreateBitmap(bitmap.Bitmap, tileX, tileY, translation))
                    paint.Shader = shader;
            }

            return(rv);
        }
Ejemplo n.º 57
0
 protected BrushControl(IBrush brush)
 {
     Brush = brush;
 }
Ejemplo n.º 58
0
 private static void ControlValuesChanged(object sender, IBrush brush)
 {
     OnValuesChanged(brush);
 }
Ejemplo n.º 59
0
        static void ReplaceHandlerInternal( IBrush factory, Player player, CommandReader cmd ) {
            CuboidDrawOperation op = new CuboidDrawOperation( player );
            IBrushInstance brush = factory.MakeInstance( player, cmd, op );
            if( brush == null ) return;
            op.Brush = brush;

            player.SelectionStart( 2, DrawOperationCallback, op, Permission.Draw );
            player.MessageNow( "{0}: Click or &H/Mark&S 2 blocks.",
                               op.Brush.InstanceDescription );
        }
Ejemplo n.º 60
0
 public static void Register(IBrush brush)
 {
     Brushes.Add(brush);
     UpdateBrushControl();
 }