ArcNegative() public method

public ArcNegative ( double xc, double yc, double radius, double angle1, double angle2 ) : void
xc double
yc double
radius double
angle1 double
angle2 double
return void
Esempio n. 1
0
    static void draw(Cairo.Context gr, int width, int height)
    {
        double xc     = 0.5;
        double yc     = 0.5;
        double radius = 0.4;
        double angle1 = 45.0 * (M_PI / 180.0);         /* angles are specified */
        double angle2 = 180.0 * (M_PI / 180.0);        /* in radians           */

        gr.Scale(width, height);
        gr.LineWidth = 0.04;

        gr.ArcNegative(xc, yc, radius, angle1, angle2);
        gr.Stroke();

        /* draw helping lines */
        gr.Color = new Color(1, 0.2, 0.2, 0.6);
        gr.Arc(xc, yc, 0.05, 0, 2 * M_PI);
        gr.Fill();
        gr.LineWidth = 0.03;
        gr.Arc(xc, yc, radius, angle1, angle1);
        gr.LineTo(new PointD(xc, yc));
        gr.Arc(xc, yc, radius, angle2, angle2);
        gr.LineTo(new PointD(xc, yc));
        gr.Stroke();
    }
Esempio n. 2
0
    public static void RoundedCell(Cairo.Context gr, int i, int j, double radius, bool rotate)
    {
        double cellsize = radius * 2;
        double x = cellsize * i, y = cellsize * j;

        gr.Save();
        if (rotate)
        {
            gr.MoveTo(x + radius, y);
            gr.Arc(x, y, radius, 0, Math.PI / 2);
            gr.MoveTo(x + cellsize, y + radius);
            gr.ArcNegative(x + cellsize, y + cellsize, radius, -Math.PI / 2, Math.PI);
        }
        else
        {
            gr.MoveTo(x, y + radius);
            gr.Arc(x, y + cellsize, radius, -Math.PI / 2, 0);
            gr.MoveTo(x + radius, y);
            gr.ArcNegative(x + cellsize, y, radius, Math.PI, Math.PI / 2);
        }

        gr.Restore();
    }
Esempio n. 3
0
        protected override void CreateTexture(Clutter.CairoTexture texture, int with_state)
        {
            texture.Clear();
            Cairo.Context context = texture.Create();

            double lwidth   = 1;
            double hlwidth  = lwidth * 0.5;
            double rotation = Math.PI * (3 - (double)sense) * 0.5;
            PointD center   = new PointD(texture.Width * 0.5, texture.Height * 0.5);

            //Set the correct orientation:
            context.Translate(center.X, center.Y);
            context.Rotate(rotation);
            context.Translate(-center.X, -center.Y);

            //Draw border:
            context.MoveTo(texture.Width * 0.5, hlwidth);
            context.ArcNegative(texture.Width, center.Y, (texture.Height - lwidth) / 2, 1.5 * Math.PI, 0.5 * Math.PI);
            context.LineTo(texture.Width * 0.5, texture.Height - hlwidth);
            context.Arc(texture.Width * 0.5, center.Y, (texture.Height - lwidth) / 2, 0.5 * Math.PI, 1.5 * Math.PI);
            context.ClosePath();
            context.LineWidth = lwidth;
            context.SetSourceRGBA(1.0, 1.0, 1.0, with_state == 0 ? 0.4 : (with_state == 1 ? 0.6 : 0.8));
            context.FillPreserve();
            context.SetSourceRGB(1.0, 1.0, 1.0);
            context.Stroke();

            //Draw arrow:
            context.MoveTo(center.X, center.Y - texture.Height * 0.25);
            context.LineTo(center.X - texture.Height * 0.25, center.Y);
            context.LineTo(center.X, center.Y + texture.Height * 0.25);
            context.LineWidth = lwidth * 1.5;
            context.SetSourceRGB(0.0, 0.0, 0.0);
            context.Stroke();

            ((IDisposable)context.Target).Dispose();
            ((IDisposable)context).Dispose();
        }
Esempio n. 4
0
		public void arc_negative(Context cr, int width, int height)
		{
			PointD c = new PointD(0.5, 0.5);
			double radius = 0.4;
			double angle1 = 45.0  * (Math.PI/180.0);  /* angles are specified */
			double angle2 = 180.0 * (Math.PI/180.0);  /* in radians           */

			Normalize(cr, width, height);

			cr.ArcNegative(c.X, c.Y, radius, angle1, angle2);
			cr.Stroke();

			// draw helping lines
			cr.Color = new Color (1, 0.2, 0.2, 0.6);
			cr.Arc(c.X, c.Y, 0.05, 0, 2*Math.PI);
			cr.Fill();
			cr.LineWidth = 0.03;
			cr.Arc(c.X, c.Y, radius, angle1, angle1);
			cr.LineTo(c);
			cr.Arc(c.X, c.Y, radius, angle2, angle2);
			cr.LineTo(c);
			cr.Stroke();
		}
Esempio n. 5
0
		public static void Draw(Context grw, Arc3PointsElement arc)
		{
			const double eps = 0.000001;
			double arcStart;
			double arcEnd;

			if (arc.Foregraund != null)
			{
				grw.SetSourceRGB(
					arc.Foregraund.Red,
					arc.Foregraund.Green,
					arc.Foregraund.Blue);
			}

			var arcCenter = new PointD(0, 0);
			
			var yDeltaA = arc.Middle.GeometryY - arc.Start.GeometryY;
			var xDeltaA = arc.Middle.GeometryX - arc.Start.GeometryX;

			var yDeltaB = arc.End.GeometryY - arc.Middle.GeometryY;
			var xDeltaB = arc.End.GeometryX - arc.Middle.GeometryX;

			//common case - no perpendicular & collinear lines
			if ((Math.Abs(xDeltaA) > eps)
				&& (Math.Abs(xDeltaB) > eps)
				&& (Math.Abs(yDeltaA) > eps)
				&& (Math.Abs(yDeltaB) > eps))
			{

				var aSlope = yDeltaA / xDeltaA;
				var bSlope = yDeltaB / xDeltaB;

				if (Math.Abs(aSlope - bSlope) <= eps)
				{
					//throw new ArgumentException("3 points lie at one line");
					return;
				}

				arcCenter.X = (aSlope * bSlope * (arc.Start.GeometryY - arc.End.GeometryY)
					+ bSlope * (arc.Start.GeometryX + arc.Middle.GeometryX)
					- aSlope * (arc.Middle.GeometryX + arc.End.GeometryX)) / (2 * (bSlope - aSlope));

				arcCenter.Y = -1 * (arcCenter.X - (arc.Start.GeometryX + arc.Middle.GeometryX) / 2)
					/ aSlope + (arc.Start.GeometryY + arc.Middle.GeometryY) / 2;
			}
			else
			{
				//vertical or horizontal cases
				if (Math.Abs(xDeltaA) <= eps)
				{
					//1st is vertical
					if (Math.Abs(xDeltaB) <= eps)
					{
						//2nd is vertical too
						//throw new ArgumentException("Both lines are vertical");
						return;
					}

					if (Math.Abs(yDeltaB) > eps)
					{
						// 2nd is not horizontal
						//throw new NotImplementedException("Only first vertical");
						return;
					}

					//square angle
					arcCenter.X = 0.5 * (arc.Middle.GeometryX + arc.End.GeometryX);
					arcCenter.Y = 0.5 * (arc.Start.GeometryY + arc.Middle.GeometryY);
				}

				if (Math.Abs(yDeltaA) <= eps)
				{
					//1st is horizontal
					if (Math.Abs(yDeltaB) <= eps)
					{
						//2nd is horizontal too
						//throw new ArgumentException("Both line are horizontal");
						return;
					}

					if (Math.Abs(xDeltaB) > eps)
					{
						//1st is not horizontal
						//throw new NotImplementedException("Only first horizontal");
						return;
					}

					//square angle
					arcCenter.X = 0.5 * (arc.Start.GeometryX + arc.Middle.GeometryX);
					arcCenter.Y = 0.5 * (arc.Middle.GeometryY + arc.End.GeometryY);
				}
			}

			//radius
			var arcRadius = Math.Sqrt(Math.Pow(arc.Start.GeometryX - arcCenter.X, 2)
			                             + Math.Pow(arc.Start.GeometryY - arcCenter.Y, 2));

			//arc angles
			var xStartDelta = arc.Start.GeometryX - arcCenter.X;
			var yStartDelta = arc.Start.GeometryY - arcCenter.Y;

			var xEndDelta = arc.End.GeometryX - arcCenter.X;
			var yEndDelta = arc.End.GeometryY - arcCenter.Y;

			//start of arc
			if (Math.Abs(xStartDelta) < eps)
			{
				if (yStartDelta < 0.0)
				{
					arcStart = -0.5 * Math.PI;
				}
				else
				{
					arcStart = 0.5 * Math.PI;
				}
			}
			else
			{
				arcStart = Math.Atan2(yStartDelta, xStartDelta);
			}

			//end of arc
			if (Math.Abs(xEndDelta) < eps)
			{
				if (yEndDelta < 0.0)
				{
					arcEnd = -0.5 * Math.PI;
				}
				else
				{
					arcEnd = 0.5 * Math.PI;
				}
			}
			else
			{
				arcEnd = Math.Atan2(yEndDelta, xEndDelta);
			}

			if (Math.Sign((arc.Middle.GeometryX - arc.Start.GeometryX)
				* (arc.Middle.GeometryY - arc.End.GeometryY)
				- (arc.Middle.GeometryY - arc.Start.GeometryY)
				* (arc.Middle.GeometryX - arc.End.GeometryX)) < 0)
			{
				grw.Arc(
					arcCenter.X,
					arcCenter.Y,
					arcRadius,
					arcStart,
					arcEnd);
			}
			else
			{
				grw.ArcNegative(
					arcCenter.X,
					arcCenter.Y,
					arcRadius,
					arcStart,
					arcEnd);
			}


			grw.Stroke();
		}
Esempio n. 6
0
 public static Gdk.Pixbuf GeneratePuzzlePiece(TypeColors tc, int size)
 {
     Gdk.Pixbuf pb;
     using (ImageSurface imsu = new ImageSurface (Format.ARGB32, size, size)) {
         using (Context ctx = new Context (imsu)) {
             ctx.Color = White;
             ctx.Paint ();
             double x1 = 0.9d * size, x0 = size - x1, x2 = 0.35d * size, x3 = 0.55d * size, x4 = 0.45d * size;
             ctx.MoveTo (0.0d, x0);
             ctx.LineTo (x2, x0);
             ctx.Arc (x4, x0, x0, Math.PI, 2.0d * Math.PI);
             ctx.LineTo (x1, x0);
             ctx.LineTo (x1, x2 + x0);
             ctx.Arc (x1, x4 + x0, x0, 1.5d * Math.PI, 2.5d * Math.PI);
             ctx.LineTo (x1, size);
             ctx.LineTo (x3, size);
             ctx.ArcNegative (x4, size, x0, 2.0d * Math.PI, Math.PI);
             ctx.LineTo (0.0d, size);
             ctx.LineTo (0.0d, x3 + x0);
             ctx.ArcNegative (0.0d, x4 + x0, x0, 2.5d * Math.PI, 1.5d * Math.PI);
             ctx.ClosePath ();
             ctx.Pattern = ExtensionMethods.GenerateColorSequencePattern (size, tc);
             ctx.Fill ();
             byte a, r, g, b;
             byte[] dat = new byte[imsu.Data.Length];
             for (int i = 0, j = 0; i < dat.Length;) {
                 b = imsu.Data [i++];
                 g = imsu.Data [i++];
                 r = imsu.Data [i++];
                 a = imsu.Data [i++];
                 dat [j++] = r;
                 dat [j++] = g;
                 dat [j++] = b;
                 dat [j++] = a;
             }
             pb = new Gdk.Pixbuf(dat,Gdk.Colorspace.Rgb,true,8,size,size,imsu.Stride);
         }
     }
     return pb;
 }
Esempio n. 7
0
        /// <summary>Draws a ribbon.</summary>
        public void DrawRibbon(Context cr, Gdk.Rectangle menuBarAllocation, Gdk.Rectangle bodyAllocation, double roundSize, double lineWidth, Ribbon widget)
        {
            double lineWidth05 = lineWidth / 2;
            double lineWidth15 = 3 * lineWidth05;
            double x0, x1, y0, y1;
            LinearGradient linGrad;

            if(menuBarAllocation.Height > 0)
            {
                cr.Rectangle (menuBarAllocation.X, menuBarAllocation.Y, menuBarAllocation.Width, menuBarAllocation.Height - 1);
                linGrad = new LinearGradient (0, menuBarAllocation.Y, 0, menuBarAllocation.Y + menuBarAllocation.Height - 1);
                linGrad.AddColorStop (0.0, new Color (1, 1, 1, 0.5));
                linGrad.AddColorStop (0.3, new Color (1, 1, 1, 0.2));
                linGrad.AddColorStop (0.3, new Color (1, 1, 1, 0.0));
                linGrad.AddColorStop (1.0, new Color (1, 1, 1, 0.5));
                cr.Pattern = linGrad;
                cr.Fill ();
                linGrad.Destroy ();

                cr.MoveTo (menuBarAllocation.X, menuBarAllocation.Bottom + 0.5);
                cr.LineTo (menuBarAllocation.Right, menuBarAllocation.Bottom + 0.5);
                cr.Color = new Color (1, 1, 1, 0.5);
                cr.LineWidth = 1;
                cr.Stroke ();

                // Quick Access Toolbar background

                Gdk.Rectangle alloc = widget.QuickAccessToolbar.Allocation;
                x0 = alloc.X;
                x1 = alloc.Right - 1;
                y0 = alloc.Y;
                y1 = alloc.Bottom - 1;
                double radius = (y1 - y0) / 2;

                cr.LineWidth = 1;

                if(widget.ApplicationButton != null)
                {
                    Gdk.Rectangle alloc2 = widget.ApplicationButton.Allocation;
                    double cx = alloc2.X + alloc2.Width / 2;
                    double cy = alloc2.Y + alloc2.Height / 2;
                    double radius2 = x0 - cx;
                    double alpha = Math.Asin ((y0 - cy) / radius2);
                    double beta = Math.Asin ((y1 - cy) / radius2);
                    double curveWidth0 = Math.Cos (Math.Abs (alpha)) * radius2;
                    double curveWidth1 = Math.Cos (Math.Abs (beta)) * radius2;
                    double curveWidth = Math.Min (curveWidth0, curveWidth1);

                    cr.Save ();
                    cr.Rectangle (cx + curveWidth, y0, x1 - cx - curveWidth, alloc.Height);
                    cr.ClipPreserve ();
                    cr.ArcNegative (cx, cy, radius2, -alpha, -beta);
                    linGrad = new LinearGradient (0, y0, 0, y1);
                    linGrad.AddColorStop (0.0, colorScheme.Bright);
                    linGrad.AddColorStop (1.0, colorScheme.PrettyDark);
                    cr.Pattern = linGrad;
                    //cr.Color = new Color (1, 0, 0);
                    cr.Fill ();
                    cr.Restore ();
                    cr.Arc (x1, y0 + radius, radius - 0.5, 1.5 * Math.PI, 0.5 * Math.PI);
                    cr.Pattern = linGrad;
                    cr.Fill ();
                    linGrad.Destroy ();

                    cr.Arc (cx, cy, radius2, alpha, beta);
                    cr.Color = new Color (0, 0, 0, 0.6);
                    cr.Stroke ();
                    radius2 -= 1;
                    cr.Arc (cx, cy, radius2, alpha, beta);
                    cr.Color = new Color (1, 1, 1, 0.4);
                    cr.Stroke ();

                    cr.MoveTo (cx + curveWidth0, y0 - 0.5);
                    cr.LineTo (x1, y0 - 0.5);
                    cr.Color = new Color (1, 1, 1, 0.4);
                    cr.Stroke ();

                    cr.MoveTo (cx + curveWidth0, y0 + 0.5);
                    cr.LineTo (x1, y0 + 0.5);
                    cr.Color = new Color (0, 0, 0, 0.6);
                    cr.Stroke ();

                    cr.MoveTo (cx + curveWidth1, y1 - 0.5);
                    cr.LineTo (x1, y1 - 0.5);
                    cr.Color = new Color (0, 0, 0, 0.6);
                    cr.Stroke ();

                    cr.MoveTo (cx + curveWidth1, y1 + 0.5);
                    cr.LineTo (x1, y1 + 0.5);
                    cr.Color = new Color (1, 1, 1, 0.4);
                    cr.Stroke ();
                }
                else
                {
                    cr.Rectangle (x0, y0, x1 - x0, alloc.Height);
                    linGrad = new LinearGradient (0, y0, 0, y1);
                    linGrad.AddColorStop (0.0, colorScheme.Bright);
                    linGrad.AddColorStop (1.0, colorScheme.PrettyDark);
                    cr.Pattern = linGrad;
                    cr.Fill ();

                    cr.Arc (x1, y0 + radius, radius - 0.5, 1.5 * Math.PI, 0.5 * Math.PI);
                    cr.Pattern = linGrad;
                    cr.Fill ();
                    linGrad.Destroy ();

                    cr.MoveTo (x0 + 0.5, y0);
                    cr.LineTo (x0 + 0.5, y1);
                    cr.Color = new Color (1, 1, 1, 0.4);
                    cr.Stroke ();

                    cr.MoveTo (x0 + 1.5, y0);
                    cr.LineTo (x0 + 1.5, y1);
                    cr.Color = new Color (0, 0, 0, 0.6);
                    cr.Stroke ();
                }

                cr.Arc (x1, y0 + radius, radius + 0.5, 1.5 * Math.PI, 0.5 * Math.PI);
                cr.Color = new Color (1, 1, 1, 0.4);
                cr.Stroke ();

                cr.Arc (x1, y0 + radius, radius - 0.5, 1.5 * Math.PI, 0.5 * Math.PI);
                cr.Color = new Color (0, 0, 0, 0.6);
                cr.Stroke ();
            }

            Ribbon.RibbonPage p = widget.CurrentPage;
            if(p != null)
            {
                //Color c = ColorScheme.GetColor(colorScheme.Bright, 0.92);
                Color c = colorScheme.Normal;

                if(bodyAllocation.Height > 0)
                {
                    /*** PAGE ***/

                    x0 = bodyAllocation.X; x1 = bodyAllocation.X + bodyAllocation.Width;
                    y0 = bodyAllocation.Y; y1 = bodyAllocation.Y + bodyAllocation.Height;

                    cr.Arc (x0 + roundSize, y1 - roundSize, roundSize - lineWidth05, Math.PI/2, Math.PI);
                    cr.Arc (x0 + roundSize, y0 + roundSize, roundSize - lineWidth05, Math.PI, 3*Math.PI/2);
                    cr.Arc (x1 - roundSize, y0 + roundSize, roundSize - lineWidth05, 3*Math.PI/2, 0);
                    cr.Arc (x1 - roundSize, y1 - roundSize, roundSize - lineWidth05, 0, Math.PI/2);
                    cr.LineTo (x0 + roundSize, y1 - lineWidth05);

                    /*** BACKGOUND ***/
                    cr.Color = c;
                    cr.FillPreserve ();

                    /*** DARK BORDER ***/
                    cr.LineWidth = lineWidth;
                    cr.Color = ColorScheme.GetColorAbsolute (colorScheme.Normal, 0.75);
                    cr.Stroke ();

                    /*** GLASS EFFECT ***/
                    double ymid = Math.Round (y0 + (y1 - y0) * 0.25);

                    cr.Arc (x0 + roundSize, y0 + roundSize, roundSize - lineWidth, Math.PI, 3*Math.PI/2);
                    cr.Arc (x1 - roundSize, y0 + roundSize, roundSize - lineWidth, 3*Math.PI/2, 0);
                    cr.LineTo (x1 - lineWidth, ymid);
                    cr.LineTo (x0 + lineWidth, ymid);
                    cr.LineTo (x0 + lineWidth, y0 + roundSize);
                    linGrad = new LinearGradient (0, y0, 0, ymid);
                    linGrad.AddColorStop (0.0, new Color (0, 0, 0, 0.0));
                    linGrad.AddColorStop (1.0, new Color (0, 0, 0, 0.075));
                    cr.Pattern = linGrad;
                    cr.Fill ();
                    linGrad.Destroy ();

                    cr.Arc (x0 + roundSize, y1 - roundSize, roundSize - lineWidth, Math.PI/2, Math.PI);
                    cr.LineTo (x0 + lineWidth, ymid);
                    cr.LineTo (x1 - lineWidth, ymid);
                    cr.Arc (x1 - roundSize, y1 - roundSize, roundSize - lineWidth, 0, Math.PI/2);
                    cr.LineTo (x0 + roundSize, y1 - lineWidth);
                    linGrad = new LinearGradient (0, ymid, 0, y1);
                    linGrad.AddColorStop (0.0, new Color (0, 0, 0, 0.1));
                    linGrad.AddColorStop (0.5, new Color (0, 0, 0, 0.0));
                    cr.Pattern = linGrad;
                    cr.Fill ();
                    linGrad.Destroy ();
                }

                /*** TAB ***/

                Gdk.Rectangle r = p.LabelAllocation;

                x0 = r.X; x1 = r.X + r.Width;
                y0 = r.Y; y1 = r.Y + r.Height + lineWidth;

                /*** TAB :: BACKGROUND ***/

                cr.MoveTo (x0 + lineWidth05, y1);
                cr.LineTo (x0 + lineWidth05, y0 + roundSize);
                cr.Arc (x0 + roundSize, y0 + roundSize, roundSize - lineWidth05, Math.PI, 3*Math.PI/2);
                cr.Arc (x1 - roundSize, y0 + roundSize, roundSize - lineWidth05, 3*Math.PI/2, 0);
                cr.LineTo (x1 - lineWidth05, y1);

                linGrad = new LinearGradient (0, y0, 0, y1);
                linGrad.AddColorStop (0.0, colorScheme.PrettyBright);
                linGrad.AddColorStop (1.0, c);
                cr.Pattern = linGrad;
                cr.Fill ();
                linGrad.Destroy ();

                /*** TAB :: DARK BORDER ***/

                cr.MoveTo (x0 + lineWidth05, y1);
                cr.LineTo (x0 + lineWidth05, y0 + roundSize);
                cr.Arc (x0 + roundSize, y0 + roundSize, roundSize - lineWidth05, Math.PI, 3*Math.PI/2);
                cr.Arc (x1 - roundSize, y0 + roundSize, roundSize - lineWidth05, 3*Math.PI/2, 0);
                cr.LineTo (x1 - lineWidth05, y1);

                cr.LineWidth = lineWidth;
                cr.Color = ColorScheme.GetColorRelative (colorScheme.Bright, -0.1);
                cr.Stroke ();

                y1 -= 1.0;

                /*** TAB :: HIGHLIGHT ***/

                cr.MoveTo (x0 + lineWidth15, y1);
                cr.LineTo (x0 + lineWidth15, y0 + roundSize);
                cr.Arc (x0 + roundSize, y0 + roundSize, roundSize - lineWidth15, Math.PI, 3*Math.PI/2);
                cr.Arc (x1 - roundSize, y0 + roundSize, roundSize - lineWidth15, 3*Math.PI/2, 0);
                cr.LineTo (x1 - lineWidth15, y1);

                cr.LineWidth = lineWidth;
                linGrad = new LinearGradient (0, y0+lineWidth, 0, y1);
                linGrad.AddColorStop (0.0, colorScheme.PrettyBright);
                linGrad.AddColorStop (1.0, ColorScheme.SetAlphaChannel (colorScheme.Bright, 0));
                cr.Pattern = linGrad;
                cr.Stroke ();
                linGrad.Destroy ();

                /*** TAB :: SHADOW ***/

                cr.MoveTo (x0 - lineWidth05, y1);
                cr.LineTo (x0 - lineWidth05, y0 + roundSize);
                cr.Arc (x0 + roundSize, y0 + roundSize, roundSize + lineWidth05, Math.PI, 3*Math.PI/2);
                cr.Arc (x1 - roundSize, y0 + roundSize, roundSize + lineWidth05, 3*Math.PI/2, 0);
                cr.LineTo (x1 + lineWidth05, y1);

                cr.LineWidth = lineWidth;
                cr.Color = new Color (0, 0, 0, 0.2);
                cr.Stroke ();
            }
        }
Esempio n. 8
0
        private void HandleExposeEventHandler(object o, ExposeEventArgs args)
        {
            jobInProgress = true;

            DrawingArea area = (DrawingArea)o;

            Cairo.Context cr = Gdk.CairoHelper.Create(area.GdkWindow);

            Cairo.Color localFillColor, localBorderColor, localFontColor, localStrikeoutColor;
            double      val = currentValue;
            int         width, height;

            if ((Sensitive == false) || (invalid == true))
            {
                localFillColor      = sensitiveFillColor;
                localBorderColor    = sensitiveBorderColor;
                localFontColor      = sensitiveFontColor;
                localStrikeoutColor = sensitiveBorderColor;
            }
            else
            {
                localFillColor      = fillColor;
                localBorderColor    = borderColor;
                localFontColor      = fontColor;
                localStrikeoutColor = new Cairo.Color(0.85, 0, 0);
            }

            width  = area.Allocation.Width;
            height = area.Allocation.Height;
            cr.SelectFontFace("Cantarell", FontSlant.Normal, FontWeight.Bold);
            cr.SetSourceColor(localFontColor);
            cr.SetFontSize(16);

            string      text = title;
            TextExtents te   = cr.TextExtents(text);

            cr.MoveTo((width - te.Width) / 2,
                      te.Height / 2 + 10);
            cr.ShowText(text);

            if (val < minValue)
            {
                val = minValue;
            }
            else if (val > maxValue)
            {
                val = maxValue;
            }

            if (invalid == true)
            {
                val = minValue;
            }

            //// Draw external border of widget
            //cr.LineWidth = 1;
            ////cr.SetSourceRGB(0.0, 0.0, 0.0);
            //cr.SetSourceColor(this.borderColor);

            //cr.Rectangle(new PointD(0, 0), width, height);
            cr.Stroke();

            int radius = (width < height ? width : height) / 2 - 10;

            cr.LineWidth = 2;

            cr.Translate(width / 2, (height / 2) + (height / 3));
            cr.Arc(0, 0, radius, DegreeToRadian(-180), DegreeToRadian(ValueToAngle(val)));
            cr.ArcNegative(0, 0, radius - 40, DegreeToRadian(ValueToAngle(val)), DegreeToRadian(-180));
            cr.ClosePath();

            //cr.SetSourceRGB(0.7, 0.2, 0.0);
            cr.SetSourceColor(localFillColor);
            cr.FillPreserve();

            //cr.SetSourceRGB(0, 0, 0);
            cr.SetSourceColor(localBorderColor);
            cr.Stroke();

            //cr.SetSourceRGB(0, 0, 0);
            cr.SetSourceColor(localBorderColor);
            cr.Arc(0, 0, radius, DegreeToRadian(ValueToAngle(val)), DegreeToRadian(0));
            cr.ArcNegative(0, 0, radius - 40, DegreeToRadian(0), DegreeToRadian(ValueToAngle(val)));
            cr.ClosePath();
            cr.Stroke();

            //cr.SetSourceRGB(0, 0, 0);
            cr.SetSourceColor(localFontColor);
            cr.SelectFontFace("Cantarell", FontSlant.Normal, FontWeight.Normal);
            text = currentValue.ToString("F2");
            te   = cr.TextExtents(text);
            cr.MoveTo(-te.Width / 2,
                      te.Height / 2 - 5);
            cr.ShowText(text);

            cr.MoveTo(0, 0);
            text = minValue.ToString("F2");
            te   = cr.TextExtents(text);
            cr.MoveTo(-te.Width - radius - 10,
                      te.Height / 2 - 5);
            cr.ShowText(text);

            cr.MoveTo(0, 0);
            text = maxValue.ToString("F2");
            te   = cr.TextExtents(text);
            cr.MoveTo(+radius + 10,
                      te.Height / 2 - 5);
            cr.ShowText(text);

            cr.MoveTo(0, 0);
            text = ((maxValue + minValue) / 2).ToString("F2");
            te   = cr.TextExtents(text);
            cr.MoveTo(-te.Width / 2,
                      -radius - te.Height - 5);
            cr.ShowText(text);

            ((IDisposable)cr.GetTarget()).Dispose();
            ((IDisposable)cr).Dispose();

            jobInProgress = false;
        }
Esempio n. 9
0
        private void Render(Clutter.CairoTexture texture, int with_state, bool outwards)
        {
            texture.Clear();
            Cairo.Context context = texture.Create();

            double alpha_f = with_state == 0 ? 0.5 : (with_state == 1 ? 0.8 : 1);

            double lwidth  = 1;
            double hlwidth = lwidth * 0.5;

            context.LineWidth = lwidth;

            if (outwards)
            {
                context.MoveTo(texture.Width * 0.5 - texture.Height * 0.45, texture.Height * 0.9);
                context.CurveTo(texture.Width * 0.3, texture.Height, texture.Width * 0.6, texture.Height, texture.Width * 0.5 + texture.Height * 0.45, texture.Height * 0.9);
                context.ArcNegative(texture.Width * 0.5, texture.Height * 0.9, texture.Height * 0.45, 0, Math.PI);
                context.ClosePath();
                Gradient g1 = new LinearGradient(0, texture.Height / 2, 0, texture.Height);
                g1.AddColorStop(0, new Cairo.Color(0.6, 0.6, 0.6, 1.0 * alpha_f));
                g1.AddColorStop(1.0, new Cairo.Color(1.0, 1.0, 1.0, 1.0 * alpha_f));
                context.Pattern = g1;
                context.FillPreserve();
                context.SetSourceRGBA(1.0, 1.0, 1.0, 1.0 * alpha_f);
                context.Stroke();
                ((IDisposable)g1).Dispose();

                context.Arc(Width * 0.5, Height * 0.33 + lwidth, Height * 0.33, 0, Math.PI * 2);
                context.ClosePath();
                context.Operator = Operator.Source;
                Gradient g2 = new RadialGradient(texture.Width * 0.5, texture.Height * 0.25, 0, texture.Width * 0.5, texture.Height * 0.25, texture.Width * 0.5);
                g2.AddColorStop(0, new Cairo.Color(1.0, 1.0, 1.0, 1.0 * alpha_f));
                g2.AddColorStop(1.0, new Cairo.Color(0.6, 0.6, 0.6, 1.0 * alpha_f));
                context.Pattern = g2;
                //context.SetSourceRGBA (1.0, 1.0, 1.0, 1.0*alpha_f);
                context.FillPreserve();
                Gradient g3 = new LinearGradient(0, 0, 0, texture.Height * 0.5);
                g3.AddColorStop(0, new Cairo.Color(1.0, 1.0, 1.0, 1.0 * alpha_f));
                g3.AddColorStop(1.0, new Cairo.Color(0, 0, 0, 1.0 * alpha_f));
                context.Pattern = g3;
                //context.SetSourceRGBA (1.0, 1.0, 1.0, 1.0*alpha_f);
                context.Stroke();
                ((IDisposable)g2).Dispose();
                ((IDisposable)g3).Dispose();
            }
            else
            {
                Cairo.PointD c     = new Cairo.PointD(texture.Width * 0.5, texture.Height * 0.5);
                double       max_r = Math.Min(c.X, c.Y) - hlwidth;

                context.Arc(c.X, c.Y, max_r, 0, Math.PI * 2);
                context.ArcNegative(c.X, c.Y, max_r * 0.25, Math.PI * 2, 0);
                context.ClosePath();
                context.SetSourceRGBA(0.5, 0.5, 0.5, 1.0 * alpha_f);
                context.StrokePreserve();
                Gradient g1 = new LinearGradient(0, texture.Height, texture.Width, 0);
                g1.AddColorStop(0, new Cairo.Color(1.0, 1.0, 1.0, 1.0 * alpha_f));
                g1.AddColorStop(0.5, new Cairo.Color(0.7, 0.7, 0.7, 1.0 * alpha_f));
                g1.AddColorStop(1, new Cairo.Color(0.9, 0.9, 0.9, 1.0 * alpha_f));
                context.Pattern = g1;
                context.Fill();
                ((IDisposable)g1).Dispose();

                context.ArcNegative(c.X, c.Y, max_r * 0.25 + lwidth, Math.PI * 1.75, Math.PI * 0.75);
                context.Arc(c.X, c.Y, max_r, Math.PI * 0.75, Math.PI * 1.75);
                context.ClosePath();
                Gradient g2 = new LinearGradient(c.X, c.Y, c.X * 0.35, c.Y * 0.35);
                g2.AddColorStop(0, new Cairo.Color(1.0, 1.0, 1.0, 1.0 * alpha_f));
                g2.AddColorStop(1, new Cairo.Color(1.0, 1.0, 1.0, 0.0));
                context.Pattern = g2;
                context.Fill();
                ((IDisposable)g2).Dispose();

                context.ArcNegative(c.X, c.Y, max_r * 0.25 + lwidth, Math.PI * 2, 0);
                context.Arc(c.X, c.Y, max_r * 0.45, 0, Math.PI * 2);
                context.SetSourceRGBA(1.0, 1.0, 1.0, 0.8 * alpha_f);
                context.Fill();

                context.Arc(c.X, c.Y, max_r - lwidth, 0, Math.PI * 2);
                Gradient g3 = new LinearGradient(0, texture.Height, texture.Width, 0);
                g3.AddColorStop(0, new Cairo.Color(1.0, 1.0, 1.0, 0.0));
                g3.AddColorStop(1, new Cairo.Color(0.9, 0.9, 0.9, 1.0 * alpha_f));
                context.Pattern = g3;
                context.Stroke();
                ((IDisposable)g3).Dispose();
            }

            ((IDisposable)context.Target).Dispose();
            ((IDisposable)context).Dispose();
        }