Esempio n. 1
0
 static MySimpleNodeStyle()
 {
     // initialize fill colors
     color         = Color.FromArgb(200, 0, 130, 180);
     gradientStop1 = new GradientStop
     {
         Color =
             Color.FromArgb((byte)Math.Max(0, color.A - 50),
                            (byte)Math.Min(255, color.R * 1.7),
                            (byte)Math.Min(255, color.G * 1.7),
                            (byte)Math.Min(255, color.B * 1.7)),
         Offset = 1
     };
     gradientStop1.Freeze();
     gradientStop2 = new GradientStop(color, 0.5);
     gradientStop2.Freeze();
     gradientStop3 = new GradientStop
     {
         Color =
             Color.FromArgb((byte)Math.Max(0, color.A - 50),
                            (byte)Math.Min(255, color.R * 1.4),
                            (byte)Math.Min(255, color.G * 1.4),
                            (byte)Math.Min(255, color.B * 1.4)),
         Offset = 0
     };
     gradientStop3.Freeze();
 }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            LinearGradientBrush linearGradientBrush = (LinearGradientBrush)null;
            ColorModel          source = value as ColorModel;

            if (source != null)
            {
                ColorModel colorModel = new ColorModel(source);
                colorModel.ScA  = 1f;
                colorModel.HlsS = 1f;
                colorModel.HlsL = 0.5f;
                GradientStop gradientStop1 = new GradientStop(Colors.Black, 0.0);
                gradientStop1.Freeze();
                GradientStop gradientStop2 = new GradientStop(colorModel.Color, 0.5);
                gradientStop2.Freeze();
                GradientStop gradientStop3 = new GradientStop(Colors.White, 1.0);
                gradientStop3.Freeze();
                GradientStopCollection gradientStopCollection = new GradientStopCollection(3);
                gradientStopCollection.Add(gradientStop1);
                gradientStopCollection.Add(gradientStop2);
                gradientStopCollection.Add(gradientStop3);
                gradientStopCollection.Freeze();
                linearGradientBrush               = new LinearGradientBrush();
                linearGradientBrush.StartPoint    = new Point(0.0, 0.0);
                linearGradientBrush.EndPoint      = new Point(1.0, 0.0);
                linearGradientBrush.GradientStops = gradientStopCollection;
                linearGradientBrush.Freeze();
            }
            return((object)linearGradientBrush);
        }
Esempio n. 3
0
        private static GradientStop CreateFrozenGradient(Color color, double offset)
        {
            var grad = new GradientStop(color, offset);

            grad.Freeze();

            return(grad);
        }
Esempio n. 4
0
        public override IEnumerable <Tuple <object, object> > GetResourceKeyValues(ThemeColor hlColor)
        {
            var br = new LinearGradientBrush()
            {
                StartPoint = StartPoint,
                EndPoint   = EndPoint,
            };

            for (int i = 0; i < GradientOffsets.Length; i++)
            {
                var gs = new GradientStop(((SolidColorBrush)hlColor.GetBrushByIndex(i)).Color, GradientOffsets[i]);
                gs.Freeze();
                br.GradientStops.Add(gs);
            }
            br.Freeze();
            yield return(new Tuple <object, object>(ResourceKey, br));
        }
Esempio n. 5
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Brush      brush1 = (Brush)null;
            ColorModel source = value as ColorModel;

            if (source != null)
            {
                ColorModel model = new ColorModel(source);
                model.ScA = 1f;
                this.UpdateModelForGradientMin(model);
                GradientStop gradientStop1 = new GradientStop(model.Color, 0.0);
                gradientStop1.Freeze();
                this.UpdateModelForGradientMax(model);
                GradientStop gradientStop2 = new GradientStop(model.Color, 1.0);
                gradientStop2.Freeze();
                GradientStopCollection gradientStopCollection = new GradientStopCollection(2);
                gradientStopCollection.Add(gradientStop1);
                gradientStopCollection.Add(gradientStop2);
                gradientStopCollection.Freeze();
                LinearGradientBrush linearGradientBrush = new LinearGradientBrush();
                linearGradientBrush.StartPoint    = new Point(0.0, 0.0);
                linearGradientBrush.EndPoint      = new Point(1.0, 0.0);
                linearGradientBrush.GradientStops = gradientStopCollection;
                linearGradientBrush.Freeze();
                brush1 = (Brush)linearGradientBrush;
                Brush brush2 = parameter as Brush;
                if (brush2 != null)
                {
                    brush2.Freeze();
                    RectangleGeometry rectangleGeometry = new RectangleGeometry(new Rect(0.0, 0.0, 100.0, 10.0));
                    rectangleGeometry.Freeze();
                    GeometryDrawing geometryDrawing1 = new GeometryDrawing(brush2, (Pen)null, (Geometry)rectangleGeometry);
                    brush2.Freeze();
                    GeometryDrawing geometryDrawing2 = new GeometryDrawing(brush1, (Pen)null, (Geometry)rectangleGeometry);
                    geometryDrawing2.Freeze();
                    DrawingGroup drawingGroup = new DrawingGroup();
                    drawingGroup.Children.Add((Drawing)geometryDrawing1);
                    drawingGroup.Children.Add((Drawing)geometryDrawing2);
                    drawingGroup.Freeze();
                    DrawingBrush drawingBrush = new DrawingBrush((Drawing)drawingGroup);
                    drawingBrush.Freeze();
                    brush1 = (Brush)drawingBrush;
                }
            }
            return((object)brush1);
        }