Example #1
0
        public static RadialGradientBrush CreateRadialTwoGradientBrush(this Color color, Transform relativeTransform, int deltaA, int deltaB)
        {
            RadialGradientBrush brush = new RadialGradientBrush(new GradientStopCollection {
                new GradientStop(color.AddColorDelta(deltaA), 0.0), new GradientStop(color.AddColorDelta(deltaB), 1.0)
            });

            brush.RelativeTransform = relativeTransform;
            return(brush);
        }
Example #2
0
 public static LinearGradientBrush CreateLinearGradientsBrush(this Color color, double offset)
 {
     return(new LinearGradientBrush
     {
         GradientStops = { new GradientStop(color,                    0),
                           new GradientStop(color.AddColorDelta(-80), offset) },
         EndPoint = new Point(0.707, 0.707)
     });
 }
Example #3
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            double width  = this.ActualWidth / 2.0;
            double height = this.ActualHeight / 2.0;
            Point  point  = new Point(width, height);
            Color  color  = this.ControlBrush.Color;
            Brush  brush  = new SolidColorBrush(color.AddColorDelta(-80));
            Brush  brush1 = color.CreateLinearTwoGradientsBrush(90.0, 80, -80);
            Brush  brush2 = new SolidColorBrush(color);
            Brush  brush3 = color.CreateLinearTwoGradientsBrush(90.0, -80, 80);
            Pen    pen    = new Pen(brush, StrokeThickness);

            drawingContext.PushTransform(new RotateTransform(450 - this.StartAngle, width, height));
            StreamGeometry geometry;

            switch (Design)
            {
            case NeedleDesign.Standard:
                geometry = new StreamGeometry();
                using (StreamGeometryContext context = geometry.Open())
                {
                    context.BeginFigure(new Point(0.85 * width, 0), true, true);
                    context.PolyLineTo(new Point[] { new Point(1.15 * width, 0), new Point(1.45 * width, height), new Point(0.55 * width, height) }, false, false);
                }
                geometry.Freeze();
                drawingContext.DrawGeometry(Brushes.Red, pen, geometry);
                drawingContext.DrawEllipse(brush1, pen, point, width * 1.5, width * 1.5);
                drawingContext.DrawEllipse(brush2, null, point, width * 1.2, width * 1.2);
                break;

            case NeedleDesign.Classic:
                drawingContext.DrawLine(new Pen(Brushes.Blue, 5), new Point(width, 0), new Point(width, 1.3 * height));
                drawingContext.DrawEllipse(brush1, pen, point, width * 1.5, width * 1.5);
                drawingContext.DrawEllipse(brush2, null, point, width * 1.2, width * 1.2);
                break;

            case NeedleDesign.Shape:
                geometry = new StreamGeometry();
                using (StreamGeometryContext context = geometry.Open())
                {
                    context.BeginFigure(new Point(width, 0), true, true);
                    context.LineTo(new Point(1.5 * width, height), true, false);
                    context.ArcTo(new Point(0.5 * width, height), new Size(width * 1.2, width * 1.2), 0.0, true, SweepDirection.Clockwise, true, true);
                }
                geometry.Freeze();
                drawingContext.DrawGeometry(ControlBrush, pen, geometry);
                break;

            case NeedleDesign.Thin:
                drawingContext.DrawLine(pen, new Point(width, 0), new Point(width, height));
                break;
            }

            //base.OnRender(drawingContext);
        }
Example #4
0
        protected override void OnRender(DrawingContext dc)
        {
            double bevel = this.BevelWidth;

            //double glass = this.GlassEffectOffset;
            //dc.DrawEllipse(Background, null, point, width, height);
            if (bevel != 0)
            {
                Color  color = this.BevelColor;
                Color  color1 = this.FrameColor;
                Brush  brush = new SolidColorBrush(color.AddColorDelta(-80));
                Pen    pen = new Pen(brush, 0.5);
                Brush  brush1, brush2, brush3, brush4;
                double width, height;

                switch (this.Design)
                {
                case FrameDesign.Round:
                    width  = this.ActualWidth / 2.0;
                    height = this.ActualHeight / 2.0;
                    Point point = new Point(width, height);
                    brush1 = color.CreateLinearTwoGradientsBrush(90.0, 80, -80);
                    brush2 = new SolidColorBrush(color);
                    brush3 = color.CreateLinearTwoGradientsBrush(90.0, -80, 80);
                    brush4 = new RadialGradientBrush
                    {
                        GradientStops = new GradientStopCollection
                        {
                            new GradientStop(Colors.Black, 1),
                            new GradientStop(color1, 0)
                        },
                        GradientOrigin = new Point(0.2, 0.2),
                        Center         = new Point(0.1, 0.1),
                        RadiusX        = 1,
                        RadiusY        = 1
                    };
                    dc.DrawEllipse(brush1, pen, point, width, height);
                    dc.DrawEllipse(brush2, null, point, width - bevel, height - bevel);
                    dc.DrawEllipse(brush3, null, point, width - 2 * bevel, height - 2 * bevel);
                    dc.DrawEllipse(brush4, pen, point, width - 3 * bevel, height - 3 * bevel);
                    break;

                case FrameDesign.Square:
                    width  = this.ActualWidth;
                    height = this.ActualHeight;
                    brush1 = color.CreateLinearTwoGradientsBrush(90.0, 80, -80);
                    brush2 = color.CreateLinearTwoGradientsBrush(90.0, -80, 80);
                    brush3 = new SolidColorBrush(color1);
                    dc.DrawRectangle(brush1, pen, new Rect(0, 0, width, height));
                    dc.DrawRectangle(brush2, null, new Rect(bevel, bevel, width - 2 * bevel, height - 2 * bevel));
                    dc.DrawRectangle(brush3, pen, new Rect(2 * bevel, 2 * bevel, width - 4 * bevel, height - 4 * bevel));
                    break;

                case FrameDesign.SquareGlass:
                    width  = this.ActualWidth;
                    height = this.ActualHeight;
                    brush1 = color.CreateLinearTwoGradientsBrush(0, 80, -80);
                    brush2 = color.CreateLinearGradientsBrush(180.0, 0.05, Colors.White);
                    brush3 = new LinearGradientBrush(color1, color1.AddColorDelta(-80), new Point(0, 0.3), new Point(1, 0.7));
                    dc.DrawRoundedRectangle(brush1, null, new Rect(0, 0, width, height), bevel, bevel);
                    dc.DrawRoundedRectangle(brush2, null, new Rect(bevel, bevel, width - 2 * bevel, height - 2 * bevel), bevel, bevel);
                    dc.DrawRoundedRectangle(brush3, pen, new Rect(2 * bevel, 2 * bevel, width - 4 * bevel, height - 4 * bevel), bevel, bevel);
                    break;
                }
            }
        }