Beispiel #1
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            bool b = (bool)value;
            Tuple <Color, Color> clrs = parameter as Tuple <Color, Color> ?? TextWhiteRed;
            Color clr = b ? clrs.Item1 : clrs.Item2;

            return(new System.Windows.Media.SolidColorBrush(ColorUtils.DrawingColorToMediaColor(clr)));
        }
Beispiel #2
0
 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     return(ColorUtils.DrawingColorToMediaColor((System.Drawing.Color)value));
 }
Beispiel #3
0
 public static System.Windows.Media.Color ToMediaColor(this System.Drawing.Color self)
 {
     return(ColorUtils.DrawingColorToMediaColor(self));
 }
Beispiel #4
0
        public static System.Windows.Media.Brush DrawingBrushToMediaBrush(System.Drawing.Brush in_brush)
        {
            if (in_brush is System.Drawing.SolidBrush)
            {
                System.Windows.Media.SolidColorBrush brush = new System.Windows.Media.SolidColorBrush(
                    ColorUtils.DrawingColorToMediaColor((in_brush as System.Drawing.SolidBrush).Color)
                    );

                return(brush);
            }
            else if (in_brush is System.Drawing.Drawing2D.LinearGradientBrush)
            {
                System.Drawing.Drawing2D.LinearGradientBrush lgb = (in_brush as System.Drawing.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
                    );

                System.Windows.Media.GradientStopCollection collection = new System.Windows.Media.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 System.Windows.Media.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 System.Windows.Media.GradientStop(
                                ColorUtils.DrawingColorToMediaColor(lgb.LinearColors[x]),
                                x / (double)(lgb.LinearColors.Length - 1)
                                )
                            );
                    }
                }

                System.Windows.Media.LinearGradientBrush brush = new System.Windows.Media.LinearGradientBrush(
                    collection,
                    starting_point,
                    ending_point
                    );

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

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

                System.Windows.Media.GradientStopCollection collection = new System.Windows.Media.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 System.Windows.Media.GradientStop(
                                ColorUtils.DrawingColorToMediaColor(pgb.InterpolationColors.Colors[x]),
                                pgb.InterpolationColors.Positions[x]
                                )
                            );
                    }
                }

                System.Windows.Media.RadialGradientBrush brush = new System.Windows.Media.RadialGradientBrush(
                    collection
                    );

                brush.Center = starting_point;

                return(brush);
            }
            else
            {
                return(new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 255, 0, 0))); //Return error color
            }
        }
Beispiel #5
0
 public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => ColorUtils.DrawingColorToMediaColor((DrawingColor)value);
Beispiel #6
0
 public static MediaColor ToMediaColor(this DrawingColor self)
 {
     return(ColorUtils.DrawingColorToMediaColor(self));
 }