Clamp() public static method

public static Clamp ( double min, double max, double value ) : double
min double
max double
value double
return double
Beispiel #1
0
        public override void DrawPie(double fraction)
        {
            // Calculate the pie path
            fraction = Theme.Clamp(0.0, 1.0, fraction);
            double a1 = 3.0 * Math.PI / 2.0;
            double a2 = a1 + 2.0 * Math.PI * fraction;

            if (fraction == 0.0)
            {
                return;
            }

            Context.Cairo.MoveTo(Context.X, Context.Y);
            Context.Cairo.Arc(Context.X, Context.Y, Context.Radius, a1, a2);
            Context.Cairo.LineTo(Context.X, Context.Y);

            // Fill the pie
            Color color_a = Colors.GetWidgetColor(GtkColorClass.Background, StateType.Selected);
            Color color_b = CairoExtensions.ColorShade(color_a, 1.4);

            var fill = new RadialGradient(Context.X, Context.Y, 0,
                                          Context.X, Context.Y, 2.0 * Context.Radius);

            fill.AddColorStop(0, color_a);
            fill.AddColorStop(1, color_b);
            Context.Cairo.SetSource(fill);

            Context.Cairo.FillPreserve();
            fill.Dispose();

            // Stroke the pie
            Context.Cairo.SetSourceColor(CairoExtensions.ColorShade(color_a, 0.8));
            Context.Cairo.LineWidth = Context.LineWidth;
            Context.Cairo.Stroke();
        }
Beispiel #2
0
        public override void DrawPie(double fraction)
        {
            // Calculate the pie path
            fraction = Theme.Clamp(0.0, 1.0, fraction);
            double a1 = 3.0 * Math.PI / 2.0;
            double a2 = a1 + 2.0 * Math.PI * fraction;

            if (fraction == 0.0)
            {
                return;
            }

            Context.Cairo.MoveTo(Context.X, Context.Y);
            Context.Cairo.Arc(Context.X, Context.Y, Context.Radius, a1, a2);
            Context.Cairo.LineTo(Context.X, Context.Y);

            // Fill the pie
            Color color_a = CairoExtensions.GdkRGBAToCairoColor(
                Widget.StyleContext.GetBackgroundColor(StateFlags.Selected));
            Color color_b = CairoExtensions.ColorShade(color_a, 1.4);

            RadialGradient fill = new RadialGradient(Context.X, Context.Y, 0,
                                                     Context.X, Context.Y, 2.0 * Context.Radius);

            fill.AddColorStop(0, color_a);
            fill.AddColorStop(1, color_b);
            Context.Cairo.Pattern = fill;

            Context.Cairo.FillPreserve();
            fill.Destroy();

            // Stroke the pie
            Context.Cairo.Color     = CairoExtensions.ColorShade(color_a, 0.8);
            Context.Cairo.LineWidth = Context.LineWidth;
            Context.Cairo.Stroke();
        }