Exemple #1
0
        public PaintStyleResult ResolvePaintStyle(PaintStyle ps, PaintStyleUse pst = PaintStyleUse.Background)
        {
            PaintStyle?      psTemp = null;
            PaletteEntryBase pRef   = null;

            // check for inherited data
            if (ps.StyleType == PaletteEntryType.Inherited)
            {
                psTemp = Atomic.FindPaintStyleByUsage(pst);
            }
            else
            {
                psTemp = ps;
            }

            if (psTemp.HasValue)
            {
                PaintStyle resolved = psTemp.Value;

                // resolve palette reference if needed
                if (resolved.StyleType == PaletteEntryType.PaletteReference)
                {
                    pRef = Atomic.FindPaintStyleTarget(resolved);
                }

                return(BlockBase.PreparePaintStyleResults(ref resolved, pRef));
            }
            else
            {
                return(new PaintStyleResult(PaintStyleResult.Result.NotFound, null));
            }
        }
        public static SKPaint ToSKPaint(this PaintStyle paintStyle)
        {
            var paint = new SKPaint();

            if (paintStyle.Type == PaintStyleType.Solid)
            {
                paint.Color = paintStyle.Color.ToSKColor();
            }
            else if (paintStyle.Type == PaintStyleType.Gradient)
            {
                var gradient = paintStyle.Gradient;

                paint.Shader = gradient.Type switch
                {
                    GradientType.Linear => SKShader.CreateLinearGradient(
                        gradient.Start.ToSKPoint(),
                        gradient.End.ToSKPoint(),
                        gradient.ColorStops.Select(s => s.Color.ToSKColor()).ToArray(),
                        gradient.ColorStops.Select(s => s.Percent).ToArray(),
                        SKShaderTileMode.Repeat
                        ),
                    _ => SKShader.CreateRadialGradient(
                        gradient.Start.ToSKPoint(),
                        gradient.InnerRadius,
                        gradient.ColorStops.Select(s => s.Color.ToSKColor()).ToArray(),
                        gradient.ColorStops.Select(s => s.Percent).ToArray(),
                        SKShaderTileMode.Repeat
                        )
                };
            }

            return(paint);
        }
    }
Exemple #3
0
 public static SKPaintStyle ToSKPaintStyle(this PaintStyle paintStyle)
 {
     return(paintStyle switch
     {
         PaintStyle.Fill => SKPaintStyle.Fill,
         PaintStyle.Stroke => SKPaintStyle.Stroke,
         PaintStyle.StrokeAndFill => SKPaintStyle.StrokeAndFill,
         _ => SKPaintStyle.Fill
     });
Exemple #4
0
 private SKPaint StyledPaint(PaintStyle style, float?strokeWidth = null)
 {
     //In SkiaSharp, line will still be visible even if width is 0
     _paint.Color       = strokeWidth == 0 ? SKColors.Transparent : (CurrentColor ?? DefaultColor).ToNative();
     _paint.Style       = (SKPaintStyle)style;
     _paint.StrokeWidth = strokeWidth ?? 0;
     _paint.StrokeCap   = StrokeCap;
     return(_paint);
 }
        private bool ConvertPaintStyle(PaintStyle source)
        {
            switch (source)
            {
            case PaintStyle.STROKE:
                return(false);

            default:
                return(true);
            }
        }
Exemple #6
0
 public Style(Style style)
 {
     FontStyles = new FontStyles(style.FontStyles);
     Padding    = style.Padding;
     Margin     = style.Margin;
     Border     = style.Border;
     Background = new PaintStyle(style.Background);
     Display    = style.Display;
     Width      = style.Width;
     Height     = style.Height;
 }
Exemple #7
0
        public PaintStyleResult ResolvePaintStyle(PaintStyle ps)
        {
            PaletteEntryBase pRef = null;

            // resolve palette reference if needed
            if (ps.StyleType == PaletteEntryType.PaletteReference)
            {
                pRef = FindPaintStyleTarget(ps);
            }

            return(PreparePaintStyleResults(ref ps, pRef));
        }
        private Android.Graphics.Paint.Style ConvertPaintStyle(PaintStyle source)
        {
            switch (source)
            {
            case PaintStyle.STROKE:
                return(Android.Graphics.Paint.Style.Stroke);

            case PaintStyle.FILL_AND_STROKE:
                return(Android.Graphics.Paint.Style.FillAndStroke);

            default:
                return(Android.Graphics.Paint.Style.Fill);
            }
        }
Exemple #9
0
        public PaletteEntryBase FindPaintStyleTarget(PaintStyle ps)
        {
            PaletteEntryBase res = null;

            if ((ps.StyleType == PaletteEntryType.PaletteReference) && (ps.Data is int))
            {
                int entryIndex = (int)ps.Data;

                do
                {
                    res = FindCascadedPaletteItem(entryIndex) as PaletteEntryBase;
                }while
                ((res != null) && (res.EntryType == PaletteEntryType.PaletteReference));
            }

            return(res);
        }
Exemple #10
0
 /// <summary>
 /// 画笔信息
 /// </summary>
 /// <param name="style"></param>
 /// <param name="colorValue"></param>
 public Paint(PaintStyle style, int colorValue)
 {
     Style = style;
     Color = colorValue;
 }
Exemple #11
0
 public static SKPaintStyle ToSkia(this PaintStyle style) => style switch
 {
 protected void Fill(Color color)
 {
     paintStyle = ShouldStroke() ? PaintStyle.FillAndStroke : PaintStyle.Fill;
     fillBrush  = fillBrush.Clone();
     fillBrush.SetValue(SolidColorBrush.ColorProperty, color);
 }
 protected void NoFill()
 {
     paintStyle = ShouldStroke() ? PaintStyle.Stroke : PaintStyle.None;
 }
 protected void Stroke(Color color)
 {
     paintStyle  = ShouldFill() ? PaintStyle.FillAndStroke : PaintStyle.Stroke;
     strokeBrush = strokeBrush.Clone();
     strokeBrush.SetValue(SolidColorBrush.ColorProperty, color);
 }
Exemple #15
0
 /// <summary>
 /// 设置风格
 /// </summary>
 /// <param name="style"></param>
 public void SetStyle(PaintStyle style)
 {
     Style = style;
 }
Exemple #16
0
        public static PaintStyleResult PreparePaintStyleResults(ref PaintStyle ps, PaletteEntryBase pRef)
        {
            PaintStyleResult.Result resType = PaintStyleResult.Result.NotFound;
            Brush br = null;

            switch (ps.StyleType)
            {
            case PaletteEntryType.DoNotPaint:
                resType = PaintStyleResult.Result.Transparent;
                br      = new SolidColorBrush(Colors.Transparent);
                break;

            case PaletteEntryType.Colour:
                if (ps.Data is int)
                {
                    resType = PaintStyleResult.Result.Colour;
                    br      = new SolidColorBrush(DataHelper.IntToColour((int)ps.Data));
                    break;
                }
                else
                {
                    goto case PaletteEntryType.DoNotPaint;
                }

            case PaletteEntryType.PaletteReference:
                if ((pRef != null) &&
                    ((pRef.EntryType != PaletteEntryType.DoNotPaint) && (pRef.EntryType != PaletteEntryType.Inherited)))
                {
                    switch (pRef.EntryType)
                    {
                    case PaletteEntryType.Colour:
                    {
                        ColourPaletteEntry cl = pRef as ColourPaletteEntry;

                        if (cl != null)
                        {
                            resType = PaintStyleResult.Result.Colour;
                            br      = cl.ToBrush();
                            break;
                        }

                        goto default;
                    }

                    case PaletteEntryType.LinearGradient:
                    {
                        LinearGradientPaletteEntry lg = pRef as LinearGradientPaletteEntry;

                        if (lg != null)
                        {
                            resType = PaintStyleResult.Result.LinearGradient;
                            br      = lg.ToBrush();
                            break;
                        }

                        goto default;
                    }

                    //IMPLEMENT: other palette entry types

                    default:
                        resType = PaintStyleResult.Result.Transparent;
                        br      = new SolidColorBrush(Colors.Transparent);
                        break;
                    }

                    break;
                }
                else
                {
                    goto case PaletteEntryType.DoNotPaint;
                }
            }

            return(new PaintStyleResult(resType, br));
        }
Exemple #17
0
 /// <summary>
 /// 画笔信息
 /// </summary>
 /// <param name="style"></param>
 public Paint(PaintStyle style)
 {
     Style = style;
 }
 protected void NoStroke()
 {
     paintStyle = ShouldFill() ? PaintStyle.Fill : PaintStyle.None;
 }