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();
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Parse - returns an instance converted from the provided string
        /// using the current culture
        /// <param name="source"> string with GradientStopCollection data </param>
        /// </summary>
        public static GradientStopCollection Parse(string source)
        {
            IFormatProvider formatProvider = System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS;

            TokenizerHelper        th       = new TokenizerHelper(source, formatProvider);
            GradientStopCollection resource = new GradientStopCollection();

            GradientStop value;

            while (th.NextToken())
            {
                value = new GradientStop(
                    Parsers.ParseColor(th.GetCurrentToken(), formatProvider),
                    Convert.ToDouble(th.NextTokenRequired(), formatProvider));

                resource.Add(value);
            }

            return(resource);
        }
예제 #4
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();
                }
            }
        }
예제 #5
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
            }
        }
        /// <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);
                }
            }
        }
예제 #7
0
        /// <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);
                }
            }
        }