Exemple #1
0
        internal void SelectBrush(TPdfStream DataStream, PathGradientBrush aBrush, RectangleF Rect, RectangleF RotatedCoords, PointF CenterPoint, string DrawingMatrix)
        {
            ColorBlend cb = null;

            try
            {
                cb = aBrush.InterpolationColors;
            }
            catch (ArgumentException)//Awful way to tell if it has InterpolationColors, but the framework does not give us a choice.
            {
            }

            if (cb == null || cb.Colors.Length == 1)
            {
                cb = GetColorBlendWithoutInterpolationColors(aBrush.Blend, aBrush.SurroundColors[0], aBrush.CenterColor);
            }

            int n = cb.Colors.Length - 1;

            if (cb.Colors[0].A != 255 || cb.Colors[n].A != 255)
            {
                ColorBlend TransparencyBlend = new ColorBlend(2);
                TransparencyBlend.Colors[0]    = ColorUtil.FromArgb(cb.Colors[0].A, cb.Colors[0].A, cb.Colors[0].A);
                TransparencyBlend.Positions[0] = 0;
                TransparencyBlend.Colors[1]    = ColorUtil.FromArgb(cb.Colors[n].A, cb.Colors[n].A, cb.Colors[n].A);
                TransparencyBlend.Positions[1] = 1;
                TPdfGradient SMask = Resources.GetGradient(TGradientType.Radial, TransparencyBlend, Rect, aBrush.CenterPoint, RotatedCoords, DrawingMatrix);
                SelectTransparency(DataStream, 255, TPdfToken.CommandSetAlphaBrush, SMask.GetSMask(), PdfConv.ToRectangleXY(Rect, true));
            }

            Resources.SelectGradient(DataStream, TGradientType.Radial, cb, Rect, CenterPoint, RotatedCoords, DrawingMatrix);
        }
 /// <summary>
 ///     This method translates Avalon SD.Brushes into
 ///     WindowsForms color objects
 /// </summary>
 private static SD.Color TranslateSolidOrGradientBrush(SWM.Brush brush, out bool defined)
 {
     SWM.Color brushColor;
     SD.Color  wfColor = SD.Color.Empty;
     defined = false;
     SWM.SolidColorBrush solidColorBrush = brush as SWM.SolidColorBrush;
     if (solidColorBrush != null)
     {
         brushColor = solidColorBrush.Color;
         defined    = true;
         wfColor    = Convert.ToSystemDrawingColor(brushColor);
     }
     else
     {
         SWM.GradientBrush gradientBrush = brush as SWM.GradientBrush;
         if (gradientBrush != null)
         {
             SWM.GradientStopCollection grads = gradientBrush.GradientStops;
             if (grads != null)
             {
                 SWM.GradientStop firstStop = grads[0];
                 if (firstStop != null)
                 {
                     brushColor = firstStop.Color;
                     defined    = true;
                     wfColor    = Convert.ToSystemDrawingColor(brushColor);
                 }
             }
         }
     }
     return(wfColor);
 }
Exemple #3
0
        private ColorBlend GetColorBlendWithoutInterpolationColors(Blend bl, Color Color1, Color Color2)
        {
            //We will only use Blend when it has been set by SetSigmaBellShape. Since we only use SetSigmaBellShape in gradients without InterpolationColors, we can test this only here.
            ColorBlend Result = new ColorBlend(Math.Max(bl.Factors.Length, 2));

            real factor   = 0;
            real position = 0;

            for (int i = 0; i < Result.Colors.Length; i++)
            {
                if (bl.Factors.Length > 1 && i < bl.Factors.Length)
                {
                    factor = bl.Factors[i];
                }
                if (bl.Positions.Length > 1 && i < bl.Positions.Length)
                {
                    position = bl.Positions[i];
                }

                Result.Colors[i]    = InterpolateColorRGB(Color1, Color2, factor);
                Result.Positions[i] = position;

                factor   = 1;
                position = 1;
            }

            return(Result);
        }
Exemple #4
0
        internal static void EnsureMinimumAndMaximum(Color Color1, Color Color2, ref ColorBlend BlendedColors)
        {
            int  Blends    = BlendCount(BlendedColors);
            bool NeedsZero = BlendPosition(BlendedColors, 0) != 0;
            bool NeedsOne  = BlendPosition(BlendedColors, Blends - 1) != 1;

            if (NeedsZero || NeedsOne)
            {
                if (NeedsZero)
                {
                    Blends++;
                }
                if (NeedsOne)
                {
                    Blends++;
                }
                ColorBlend Result = new ColorBlend(Blends);
                int        k1     = 0;
                if (NeedsZero)
                {
                    SetColorBlend(Result, 0, Color1, 0); k1++;
                }
                for (int i = 0; i < BlendCount(BlendedColors); i++)
                {
                    SetColorBlend(Result, k1 + i, BlendColor(BlendedColors, i), BlendPosition(BlendedColors, i));
                }
                if (NeedsOne)
                {
                    SetColorBlend(Result, Blends - 1, Color2, 1);
                }
                BlendedColors = Result;
            }
        }
Exemple #5
0
        private static Color BlendColor(ColorBlend BlendColors, int Position)
        {
#if (WPF)
            return(BlendColors[Position].Color);
#else
            return(BlendColors.Colors[Position]);
#endif
        }
Exemple #6
0
        private static int BlendCount(ColorBlend BlendColors)
        {
#if (WPF)
            return(BlendColors.Count);
#else
            return(BlendColors.Colors.Length);
#endif
        }
Exemple #7
0
        private static real BlendPosition(ColorBlend BlendColors, int Position)
        {
#if (WPF)
            return(BlendColors[Position].Offset);
#else
            return(BlendColors.Positions[Position]);
#endif
        }
Exemple #8
0
 private static double[] GetBounds(ColorBlend BlendColors)
 {
     double[] Result = new double[BlendCount(BlendColors) - 2];
     for (int i = BlendCount(BlendColors) - 2; i > 0; i--) //First and last are not written.
     {
         Result[Result.Length - i] = 1 - BlendPosition(BlendColors, i);
     }
     return(Result);
 }
Exemple #9
0
 public TPdfGradient(int aPatternId, TGradientType aGradientType, ColorBlend aBlendColors, RectangleF aCoords, PointF aCenterPoint, RectangleF aRotatedCoords, string aDrawingMatrix, List <TPdfFunction> FunctionList) : base(aPatternId, TPdfToken.GradientPrefix)
 {
     GradientType  = aGradientType;
     BlendFunction = GetBlendFunction(aBlendColors, FunctionList);
     CenterPoint   = aCenterPoint;
     Coords        = aCoords;
     RotatedCoords = aRotatedCoords;
     DrawingMatrix = aDrawingMatrix;
 }
Exemple #10
0
        public static void SetColorBlend(ColorBlend BlendColors, int i, Color ColorInPos, real Position)
        {
#if (WPF)
            BlendColors[i].Color  = ColorInPos;
            BlendColors[i].Offset = Position;
#else
            BlendColors.Colors[i]    = ColorInPos;
            BlendColors.Positions[i] = Position;
#endif
        }
Exemple #11
0
        private static Brush GetGradient(ref Color ColorFg, ref Color ColorBg, TExcelGradient GradientFill, RectangleF CellRect, IFlexCelPalette Palette)
        {
            if (GradientFill == null)
            {
                return(new SolidBrush(ColorFg));
            }

            Color Color1 = ColorFg;
            Color Color2 = ColorBg;

            if (GradientFill.Stops != null && GradientFill.Stops.Length > 0)
            {
                Color1 = GradientFill.Stops[0].Color.ToColor(Palette);
                Color2 = GradientFill.Stops[GradientFill.Stops.Length - 1].Color.ToColor(Palette);
            }

            switch (GradientFill.GradientType)
            {
            case TGradientType.Linear:
            {
                TExcelLinearGradient lgr    = GradientFill as TExcelLinearGradient;
                LinearGradientBrush  Result = new LinearGradientBrush(CellRect, Color1, Color2, (real)(lgr.RotationAngle), true);
                Result.WrapMode = WrapMode.TileFlipXY;
                ColorBlend cb = GetInterpolationColors(Color1, Color2, Palette, lgr, false);
                if (cb != null)
                {
                    Result.InterpolationColors = cb;
                }
                return(Result);
            }

            case TGradientType.Rectangular:
            {
                TExcelRectangularGradient rgr    = GradientFill as TExcelRectangularGradient;
                PathGradientBrush         Result = new PathGradientBrush(new PointF[] {
                        CellRect.Location,
                        new PointF(CellRect.Right, CellRect.Top),
                        new PointF(CellRect.Right, CellRect.Bottom),
                        new PointF(CellRect.Left, CellRect.Bottom)
                    });
                Result.WrapMode       = WrapMode.TileFlipXY;
                Result.CenterPoint    = new PointF(CellRect.Left + (float)rgr.Left * CellRect.Width, CellRect.Top + (float)rgr.Top * CellRect.Height);
                Result.CenterColor    = Color1;
                Result.SurroundColors = new Color[] { Color2 };
                ColorBlend cb = GetInterpolationColors(Color1, Color2, Palette, rgr, true);         //must be (Color1, Color2), not (Color2, Color1) even if the blending will be reversed. This is because it will be reversed *after* Color1 and 2 have been added.
                if (cb != null)
                {
                    Result.InterpolationColors = cb;
                }

                return(Result);
            }
            }
            return(new SolidBrush(ColorFg));
        }
Exemple #12
0
        private double[] GetEncode(ColorBlend BlendColors)
        {
            int functionCount = BlendCount(BlendColors) - 1;

            double[] Result = new double[2 * functionCount];
            for (int i = 1; i < Result.Length; i += 2)
            {
                Result[i] = 1;
            }
            return(Result);
        }
Exemple #13
0
        internal TPdfGradient GetGradient(TGradientType aGradientType, ColorBlend aBlendColors, RectangleF aCoords, PointF aCenterPoint, RectangleF RotatedCoords, string DrawingMatrix)
        {
            TPdfGradient SearchGradient = new TPdfGradient(GradientPatterns.Count, aGradientType, aBlendColors, aCoords, aCenterPoint, RotatedCoords, DrawingMatrix, Functions);
            int Index = GradientPatterns.BinarySearch(0, GradientPatterns.Count, SearchGradient, null);  //Only BinarySearch compatible with CF.

            if (Index < 0)
                GradientPatterns.Insert(~Index, SearchGradient);
            else SearchGradient = GradientPatterns[Index];

            return SearchGradient;
        }
Exemple #14
0
        internal static void InvertColorBlend(ColorBlend Result)
        {
            for (int i = 0; i < (FlxGradient.BlendCount(Result) + 1) / 2; i++)
            {
                int n = FlxGradient.BlendCount(Result) - 1 - i;

                Color Tmp    = FlxGradient.BlendColor(Result, n);
                real  TmpPos = FlxGradient.BlendPosition(Result, n);

                FlxGradient.SetColorBlend(Result, n, FlxGradient.BlendColor(Result, i), 1 - FlxGradient.BlendPosition(Result, i));
                FlxGradient.SetColorBlend(Result, i, Tmp, 1 - TmpPos);
            }
        }
Exemple #15
0
        private TPdfFunction GetBlendFunction(ColorBlend BlendColors, List <TPdfFunction> FunctionList)
        {
            TPdfFunction SearchFunction = CreateBlendFunction(BlendColors, FunctionList);
            int          Index          = FunctionList.BinarySearch(0, FunctionList.Count, SearchFunction, null);

            if (Index < 0)
            {
                FunctionList.Insert(~Index, SearchFunction);
            }
            else
            {
                SearchFunction = FunctionList[Index];
            }
            return(SearchFunction);
        }
        protected override void UpdateBackground()
        {
            // background color change must be handled separately
            // because the background would protrude through the border if the corners are rounded
            // as the background would be applied to the renderer's FrameworkElement
            var pancake = (PancakeView)Element;

            if (Control != null)
            {
                if ((pancake.BackgroundGradientStartColor != default(Color) && pancake.BackgroundGradientEndColor != default(Color)) || (pancake.BackgroundGradientStops != null && pancake.BackgroundGradientStops.Any()))
                {
                    // Create a gradient layer that draws our background.
                    if (pancake.BackgroundGradientStops != null && pancake.BackgroundGradientStops.Count > 0)
                    {
                        // A range of colors is given. Let's add them.
                        var orderedStops = pancake.BackgroundGradientStops.OrderBy(x => x.Offset).ToList();
                        var gc           = new System.Windows.Media.GradientStopCollection();

                        foreach (var item in orderedStops)
                        {
                            gc.Add(new System.Windows.Media.GradientStop {
                                Offset = item.Offset, Color = item.Color.ToMediaColor()
                            });
                        }

                        this.Control.Background = new LinearGradientBrush(gc, pancake.BackgroundGradientAngle);
                    }
                    else
                    {
                        var gs1 = new System.Windows.Media.GradientStop {
                            Offset = 0, Color = pancake.BackgroundGradientStartColor.ToMediaColor()
                        };
                        var gs2 = new System.Windows.Media.GradientStop {
                            Offset = 1, Color = pancake.BackgroundGradientEndColor.ToMediaColor()
                        };
                        var gc = new System.Windows.Media.GradientStopCollection {
                            gs1, gs2
                        };
                        this.Control.Background = new LinearGradientBrush(gc, pancake.BackgroundGradientAngle);
                    }
                }
                else
                {
                    Control.Background = Element.BackgroundColor.IsDefault ? null : Element.BackgroundColor.ToBrush();
                }
            }
        }
        private void UpdateBorder(PancakeView pancake)
        {
            //// Create the border layer
            if (Control != null)
            {
                this.Control.BorderThickness = new System.Windows.Thickness(pancake.BorderThickness);

                if ((pancake.BorderGradientStartColor != default(Color) && pancake.BorderGradientEndColor != default(Color)) || (pancake.BorderGradientStops != null && pancake.BorderGradientStops.Any()))
                {
                    // Create a gradient layer that draws our background.
                    if (pancake.BorderGradientStops != null && pancake.BorderGradientStops.Count > 0)
                    {
                        // A range of colors is given. Let's add them.
                        var orderedStops = pancake.BorderGradientStops.OrderBy(x => x.Offset).ToList();
                        var gc           = new System.Windows.Media.GradientStopCollection();

                        foreach (var item in orderedStops)
                        {
                            gc.Add(new System.Windows.Media.GradientStop {
                                Offset = item.Offset, Color = item.Color.ToMediaColor()
                            });
                        }

                        this.Control.BorderBrush = new LinearGradientBrush(gc, pancake.BorderGradientAngle);
                    }
                    else
                    {
                        var gs1 = new System.Windows.Media.GradientStop {
                            Offset = 0, Color = pancake.BorderGradientStartColor.ToMediaColor()
                        };
                        var gs2 = new System.Windows.Media.GradientStop {
                            Offset = 1, Color = pancake.BorderGradientEndColor.ToMediaColor()
                        };
                        var gc = new System.Windows.Media.GradientStopCollection {
                            gs1, gs2
                        };
                        this.Control.BorderBrush = new LinearGradientBrush(gc, pancake.BorderGradientAngle);
                    }
                }
                else
                {
                    this.Control.BorderBrush = pancake.BorderColor.IsDefault ? null : pancake.BorderColor.ToBrush();
                }
            }
        }
Exemple #18
0
        private static byte[] GetType0Array(ColorBlend BlendColors)
        {
            int bc = BlendCount(BlendColors);

            byte[] Result = new byte[bc * 3];

            int i = 0;

            for (int x = 0; x < bc; x++)
            {
                Color c = BlendColor(BlendColors, bc - x - 1);
                Result[i] = c.R; i++;
                Result[i] = c.G; i++;
                Result[i] = c.B; i++;
            }


            return(Result);
        }
Exemple #19
0
        private static bool IsUniform(ColorBlend BlendColors)
        {
            int bc = BlendCount(BlendColors);

            if (bc <= 2)
            {
                return(true);
            }
            real diff = BlendPosition(BlendColors, 1) - BlendPosition(BlendColors, 0);

            for (int i = 2; i < bc; i++)
            {
                real newdiff = BlendPosition(BlendColors, i) - BlendPosition(BlendColors, i - 1);
                if (!AlmostEqual(diff, newdiff))
                {
                    return(false);
                }
            }
            return(true);
        }
Exemple #20
0
        private void UpdateBorder(PancakeView pancake)
        {
            //// Create the border layer
            if (Control != null && pancake?.Border != null)
            {
                this.Control.BorderThickness = new System.Windows.Thickness(pancake.Border.Thickness);

                if (pancake.Border.GradientStops != null && pancake.Border.GradientStops.Any())
                {
                    // Create a gradient layer that draws our background.
                    if (pancake.Border.GradientStops != null && pancake.Border.GradientStops.Count > 0)
                    {
                        // A range of colors is given. Let's add them.
                        var orderedStops = pancake.Border.GradientStops.OrderBy(x => x.Offset).ToList();
                        var gc           = new System.Windows.Media.GradientStopCollection();

                        foreach (var item in orderedStops)
                        {
                            gc.Add(new System.Windows.Media.GradientStop {
                                Offset = item.Offset, Color = item.Color.ToMediaColor()
                            });
                        }

                        var gradient = new System.Windows.Media.LinearGradientBrush(gc, 0)
                        {
                            StartPoint = new System.Windows.Point(pancake.Border.GradientStartPoint.X,
                                                                  pancake.Border.GradientStartPoint.Y),
                            EndPoint = new System.Windows.Point(pancake.Border.GradientEndPoint.X,
                                                                pancake.Border.GradientEndPoint.Y)
                        };

                        this.Control.BorderBrush = gradient;
                    }
                }
                else
                {
                    this.Control.BorderBrush = pancake.Border.Color.IsDefault ? null : pancake.Border.Color.ToBrush();
                }
            }
        }
Exemple #21
0
        private static ColorBlend GetInterpolationColors(Color Color1, Color Color2, IFlexCelPalette Palette, TExcelGradient gr, bool InvertColors)
        {
            ColorBlend Result = null;

            if (gr.Stops != null && gr.Stops.Length > 0) //It should be gr.Stops.Length > 2, but we will add them even if not needed, so there aren't exceptions when retrieving them.
            {
                Result = new ColorBlend(gr.Stops.Length);
                for (int i = 0; i < gr.Stops.Length; i++)
                {
                    Result.Colors[i]    = gr.Stops[i].Color.ToColor(Palette);
                    Result.Positions[i] = (float)gr.Stops[i].Position;
                }

                FlxGradient.EnsureMinimumAndMaximum(Color1, Color2, ref Result);
                if (InvertColors)
                {
                    FlxGradient.InvertColorBlend(Result);
                }
            }

            return(Result);
        }
Exemple #22
0
        private TPdfFunction[] GetFunctions(ColorBlend BlendColors, List <TPdfFunction> FunctionList)
        {
            int functionCount = BlendCount(BlendColors) - 1;

            TPdfFunction[] Result = new TPdfFunction[functionCount];
            for (int i = 1; i <= functionCount; i++)
            {
                TPdfFunction SearchFunction = new TPdfType2Function(new Double[] { 0, 1 }, null, BlendColorArray(BlendColors, i), BlendColorArray(BlendColors, i - 1), 1);
                int          Index          = FunctionList.BinarySearch(0, FunctionList.Count, SearchFunction, null);

                if (Index < 0)
                {
                    FunctionList.Insert(~Index, SearchFunction);
                }
                else
                {
                    SearchFunction = FunctionList[Index];
                }
                Result[functionCount - i] = SearchFunction;
            }
            return(Result);
        }
Exemple #23
0
        private TPdfFunction CreateBlendFunction(ColorBlend BlendColors, List <TPdfFunction> FunctionList)
        {
            //Decide what kind of function we want:
            //For 2 values: type2:
            //For more values: If they are uniform, type 1, else type 3.

            if (BlendCount(BlendColors) == 1)
            {
                return(new TPdfType2Function(new Double[] { 0, 1 }, null, BlendColorArray(BlendColors, 0), BlendColorArray(BlendColors, 0), 1));
            }

            if (BlendCount(BlendColors) == 2)
            {
                return(new TPdfType2Function(new Double[] { 0, 1 }, null, BlendColorArray(BlendColors, 1), BlendColorArray(BlendColors, 0), 1));
            }

            if (IsUniform(BlendColors))
            {
                return(new TPdfType0Function(new Double[] { 0, 1 }, new Double[] { 0, 1, 0, 1, 0, 1 }, GetType0Array(BlendColors), 8, new int[] { BlendCount(BlendColors) }));
            }

            return(new TPdfType3Function(new Double[] { 0, 1 }, null, GetFunctions(BlendColors, FunctionList), GetBounds(BlendColors), GetEncode(BlendColors)));
        }
Exemple #24
0
        internal void SelectBrush(TPdfStream DataStream, LinearGradientBrush aBrush, RectangleF Rect, RectangleF RotatedCoords, string DrawingMatrix)
        {
#if (WPF)
            ColorBlend cb = aBrush.GradientStops;
#else
            ColorBlend cb = null;
            try
            {
                if (aBrush.Blend == null)
                {
                    cb = aBrush.InterpolationColors;                       //if it has interpolationcolors, blend must be null.
                }
            }
            catch (ArgumentException) //Awful way to tell if it has Interpolationcolors, but the framework does not give us a choice.
            {
            }

            if (cb == null)
            {
                cb = GetColorBlendWithoutInterpolationColors(aBrush.Blend, aBrush.LinearColors[0], aBrush.LinearColors[1]);
            }
#endif

            int n = cb.Colors.Length - 1;
            if (cb.Colors[0].A != 255 || cb.Colors[n].A != 255)
            {
                ColorBlend TransparencyBlend = new ColorBlend(2);
                TransparencyBlend.Colors[0]    = ColorUtil.FromArgb(cb.Colors[0].A, cb.Colors[0].A, cb.Colors[0].A);
                TransparencyBlend.Positions[0] = 0;
                TransparencyBlend.Colors[1]    = ColorUtil.FromArgb(cb.Colors[n].A, cb.Colors[n].A, cb.Colors[n].A);
                TransparencyBlend.Positions[1] = 1;
                TPdfGradient SMask = Resources.GetGradient(TGradientType.Axial, TransparencyBlend, Rect, Rect.Location, RotatedCoords, DrawingMatrix);
                SelectTransparency(DataStream, 255, TPdfToken.CommandSetAlphaBrush, SMask.GetSMask(), PdfConv.ToRectangleXY(Rect, true));
            }
            Resources.SelectGradient(DataStream, TGradientType.Axial, cb, Rect, Rect.Location, RotatedCoords, DrawingMatrix);
        }
Exemple #25
0
 internal void SelectGradient(TPdfStream DataStream, TGradientType aGradientType, ColorBlend aBlendColors, RectangleF aCoords, PointF aCenterPoint, RectangleF aRotatedCoords, string DrawingMatrix)
 {
     TPdfGradient SearchGradient = GetGradient(aGradientType, aBlendColors, aCoords, aCenterPoint, aRotatedCoords, DrawingMatrix);
     SearchGradient.Select(DataStream);
 }
Exemple #26
0
 /// <summary>
 /// Protected constructor for GradientBrush
 /// Sets all the values of the GradientStopCollection, all other values are left as default.
 /// </summary>
 protected GradientBrush(GradientStopCollection gradientStopCollection)
 {
     GradientStops = gradientStopCollection;
 }
Exemple #27
0
 /// <summary>
 /// RadialGradientBrush Constructor
 /// Constructs a RadialGradientBrush with GradientStops set to the passed-in
 /// collection.
 /// </summary>
 /// <param name="gradientStopCollection"> GradientStopCollection to set on this brush. </param>
 public RadialGradientBrush(GradientStopCollection gradientStopCollection)
     : base(gradientStopCollection)
 {
 }
Exemple #28
0
        public static M.Brush DrawingBrushToMediaBrush(D.Brush in_brush)
        {
            if (in_brush is D.SolidBrush)
            {
                M.SolidColorBrush brush = new M.SolidColorBrush(
                    ColorUtils.DrawingColorToMediaColor((in_brush as D.SolidBrush).Color)
                    );

                return(brush);
            }
            else if (in_brush is D.Drawing2D.LinearGradientBrush)
            {
                D.Drawing2D.LinearGradientBrush lgb = (in_brush as D.Drawing2D.LinearGradientBrush);

                System.Windows.Point starting_point = new System.Windows.Point(
                    lgb.Rectangle.X,
                    lgb.Rectangle.Y
                    );

                System.Windows.Point ending_point = new System.Windows.Point(
                    lgb.Rectangle.Right,
                    lgb.Rectangle.Bottom
                    );

                M.GradientStopCollection collection = new M.GradientStopCollection();

                try
                {
                    if (lgb.InterpolationColors != null && lgb.InterpolationColors.Colors.Length == lgb.InterpolationColors.Positions.Length)
                    {
                        for (int x = 0; x < lgb.InterpolationColors.Colors.Length; x++)
                        {
                            collection.Add(
                                new M.GradientStop(
                                    ColorUtils.DrawingColorToMediaColor(lgb.InterpolationColors.Colors[x]),
                                    lgb.InterpolationColors.Positions[x]
                                    )
                                );
                        }
                    }
                }
                catch (Exception exc)
                {
                    for (int x = 0; x < lgb.LinearColors.Length; x++)
                    {
                        collection.Add(
                            new M.GradientStop(
                                ColorUtils.DrawingColorToMediaColor(lgb.LinearColors[x]),
                                x / (double)(lgb.LinearColors.Length - 1)
                                )
                            );
                    }
                }

                M.LinearGradientBrush brush = new M.LinearGradientBrush(
                    collection,
                    starting_point,
                    ending_point
                    );

                return(brush);
            }
            else if (in_brush is D.Drawing2D.PathGradientBrush)
            {
                D.Drawing2D.PathGradientBrush pgb = (in_brush as D.Drawing2D.PathGradientBrush);

                System.Windows.Point starting_point = new System.Windows.Point(
                    pgb.CenterPoint.X,
                    pgb.CenterPoint.Y
                    );

                M.GradientStopCollection collection = new M.GradientStopCollection();

                if (pgb.InterpolationColors != null && pgb.InterpolationColors.Colors.Length == pgb.InterpolationColors.Positions.Length)
                {
                    for (int x = 0; x < pgb.InterpolationColors.Colors.Length; x++)
                    {
                        collection.Add(
                            new M.GradientStop(
                                ColorUtils.DrawingColorToMediaColor(pgb.InterpolationColors.Colors[x]),
                                pgb.InterpolationColors.Positions[x]
                                )
                            );
                    }
                }

                M.RadialGradientBrush brush = new M.RadialGradientBrush(
                    collection
                    );

                brush.Center = starting_point;

                return(brush);
            }
            else
            {
                return(new M.SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 255, 0, 0))); //Return error color
            }
        }
Exemple #29
0
        private void ManualUpdateResource(DUCE.Channel channel, bool skipOnChannelCheck)
        {
            // If we're told we can skip the channel check, then we must be on channel
            Debug.Assert(!skipOnChannelCheck || _duceResource.IsOnChannel(channel));

            if (skipOnChannelCheck || _duceResource.IsOnChannel(channel))
            {
                Transform vTransform                  = Transform;
                Transform vRelativeTransform          = RelativeTransform;
                GradientStopCollection vGradientStops = GradientStops;

                DUCE.ResourceHandle hTransform;
                if (vTransform == null ||
                    Object.ReferenceEquals(vTransform, Transform.Identity)
                    )
                {
                    hTransform = DUCE.ResourceHandle.Null;
                }
                else
                {
                    hTransform = ((DUCE.IResource)vTransform).GetHandle(channel);
                }
                DUCE.ResourceHandle hRelativeTransform;
                if (vRelativeTransform == null ||
                    Object.ReferenceEquals(vRelativeTransform, Transform.Identity)
                    )
                {
                    hRelativeTransform = DUCE.ResourceHandle.Null;
                }
                else
                {
                    hRelativeTransform = ((DUCE.IResource)vRelativeTransform).GetHandle(channel);
                }
                DUCE.ResourceHandle hOpacityAnimations        = GetAnimationResourceHandle(OpacityProperty, channel);
                DUCE.ResourceHandle hCenterAnimations         = GetAnimationResourceHandle(CenterProperty, channel);
                DUCE.ResourceHandle hRadiusXAnimations        = GetAnimationResourceHandle(RadiusXProperty, channel);
                DUCE.ResourceHandle hRadiusYAnimations        = GetAnimationResourceHandle(RadiusYProperty, channel);
                DUCE.ResourceHandle hGradientOriginAnimations = GetAnimationResourceHandle(GradientOriginProperty, channel);

                DUCE.MILCMD_RADIALGRADIENTBRUSH data;
                unsafe
                {
                    data.Type   = MILCMD.MilCmdRadialGradientBrush;
                    data.Handle = _duceResource.GetHandle(channel);
                    double tempOpacity = Opacity;
                    DUCE.CopyBytes((byte *)&data.Opacity, (byte *)&tempOpacity, 8);
                    data.hOpacityAnimations     = hOpacityAnimations;
                    data.hTransform             = hTransform;
                    data.hRelativeTransform     = hRelativeTransform;
                    data.ColorInterpolationMode = ColorInterpolationMode;
                    data.MappingMode            = MappingMode;
                    data.SpreadMethod           = SpreadMethod;

                    Point tempCenter = Center;
                    DUCE.CopyBytes((byte *)&data.Center, (byte *)&tempCenter, 16);
                    data.hCenterAnimations = hCenterAnimations;
                    double tempRadiusX = RadiusX;
                    DUCE.CopyBytes((byte *)&data.RadiusX, (byte *)&tempRadiusX, 8);
                    data.hRadiusXAnimations = hRadiusXAnimations;
                    double tempRadiusY = RadiusY;
                    DUCE.CopyBytes((byte *)&data.RadiusY, (byte *)&tempRadiusY, 8);
                    data.hRadiusYAnimations = hRadiusYAnimations;
                    Point tempGradientOrigin = GradientOrigin;
                    DUCE.CopyBytes((byte *)&data.GradientOrigin, (byte *)&tempGradientOrigin, 16);
                    data.hGradientOriginAnimations = hGradientOriginAnimations;

                    // GradientStopCollection:  Need to enforce upper-limit of gradient stop capacity

                    int count = (vGradientStops == null) ? 0 : vGradientStops.Count;
                    data.GradientStopsSize = (UInt32)(sizeof(DUCE.MIL_GRADIENTSTOP) * count);

                    channel.BeginCommand(
                        (byte *)&data,
                        sizeof(DUCE.MILCMD_RADIALGRADIENTBRUSH),
                        sizeof(DUCE.MIL_GRADIENTSTOP) * count
                        );

                    for (int i = 0; i < count; i++)
                    {
                        DUCE.MIL_GRADIENTSTOP stopCmd;
                        GradientStop          gradStop = vGradientStops.Internal_GetItem(i);

                        double temp = gradStop.Offset;
                        DUCE.CopyBytes((byte *)&stopCmd.Position, (byte *)&temp, sizeof(double));
                        stopCmd.Color = CompositionResourceManager.ColorToMilColorF(gradStop.Color);

                        channel.AppendCommandData(
                            (byte *)&stopCmd,
                            sizeof(DUCE.MIL_GRADIENTSTOP)
                            );
                    }

                    channel.EndCommand();
                }
            }
        }
        /// <summary>
        /// Apply settings to a panel
        /// </summary>
        /// <param name="settings">the custom caption settings</param>
        /// <param name="isRoot">is this the root panel</param>
        /// <param name="panel">the panel</param>
        private void ApplyPanel(CustomCaptionSettings settings, bool isRoot, StackPanel panel)
        {
            var children = System.Convert.ToDouble(panel.Children.Count);

            var startIndex = -1;

            var endIndex = -1;

            var index = 0;

            foreach (var item in panel.Children)
            {
                bool empty = IsRowEmpty(item);

                if (!empty && startIndex == -1)
                {
                    startIndex = index;
                }

                if (!empty)
                {
                    endIndex = index + 1;
                }

                this.ApplySettings(item, settings, panel);

                index++;
            }

            if (isRoot && settings.WindowColor != null)
            {
                if (startIndex >= 0 && endIndex >= 0)
                {
                    var startPercentage = Math.Max(0.0, (System.Convert.ToDouble(startIndex) / children) - 0.01);
                    var endPercentage = Math.Min(1.0, (System.Convert.ToDouble(endIndex) / children) + 0.01);

                    var gradientStops = new Media.GradientStopCollection();
                    var color = settings.WindowColor.ToColor();

                    gradientStops.Add(new Media.GradientStop
                        {
                            Color = Colors.Transparent,
                            Offset = startPercentage
                        });
                    gradientStops.Add(new Media.GradientStop
                    {
                        Color = color,
                        Offset = startPercentage
                    });
                    gradientStops.Add(new Media.GradientStop
                    {
                        Color = color,
                        Offset = endPercentage
                    });
                    gradientStops.Add(new Media.GradientStop
                    {
                        Color = Colors.Transparent,
                        Offset = endPercentage
                    });

                    panel.Background = new Media.LinearGradientBrush(gradientStops, 90);
                }
            }
        }
Exemple #31
0
        private static double[] BlendColorArray(ColorBlend BlendColors, int Position)
        {
            Color c = BlendColor(BlendColors, Position);

            return(new double[] { c.R / 255.0, c.G / 255.0, c.B / 255.0 });
        }