CurveTo() public method

public CurveTo ( PointD p1, PointD p2, PointD p3 ) : void
p1 PointD
p2 PointD
p3 PointD
return void
Example #1
0
        void DrawCurveTabs(Cairo.Context cr, Cairo.Rectangle rectangle)
        {
            if (IsSeparator)
            {
                return;
            }

            cr.MoveTo(rectangle.X, rectangle.Y);

            double bottom = rectangle.Y + rectangle.Height - 1;

            cr.CurveTo(
                rectangle.X + SpacerWidth / 2, rectangle.Y,
                rectangle.X + SpacerWidth / 2, bottom,
                rectangle.X + SpacerWidth, bottom);

            cr.LineTo(rectangle.X + rectangle.Width - SpacerWidth, bottom);

            cr.CurveTo(
                rectangle.X + rectangle.Width - SpacerWidth / 2, bottom,
                rectangle.X + rectangle.Width - SpacerWidth / 2, rectangle.Y,
                rectangle.X + rectangle.Width, rectangle.Y);

            cr.Color = (HslColor)parent.Style.Dark(StateType.Normal);
            cr.StrokePreserve();
            cr.ClosePath();
            if (Active)
            {
                cr.Color = (HslColor)parent.Style.Background(StateType.Prelight);
            }
            else if (HoverPosition.X >= 0)
            {
                double rx = rectangle.X + HoverPosition.X;
                double ry = rectangle.Y + HoverPosition.Y;
                Cairo.RadialGradient gradient = new Cairo.RadialGradient(rx, ry, rectangle.Height * 1.5,
                                                                         rx, ry, 2);
                var color = (HslColor)parent.Style.Mid(StateType.Normal);
                color.L *= 1.05;
                gradient.AddColorStop(0, color);
                color.L *= 1.07;
                gradient.AddColorStop(1, color);
                cr.Pattern = gradient;
            }
            else
            {
                cr.Color = (HslColor)parent.Style.Mid(StateType.Normal);
            }
            cr.Fill();

            cr.Save();
            cr.Translate(rectangle.X + (rectangle.Width - w) / 2, (rectangle.Height - h) / 2);
            cr.Color = (HslColor)parent.Style.Text(StateType.Normal);

            cr.ShowLayout(layout);

            cr.Restore();
        }
Example #2
0
 protected void DrawCurvedRectangle(Cairo.Context gr, double x, double y, double width, double height)
 {
     gr.Save();
     gr.MoveTo(x, y + height / 2);
     gr.CurveTo(x, y, x, y, x + width / 2, y);
     gr.CurveTo(x + width, y, x + width, y, x + width, y + height / 2);
     gr.CurveTo(x + width, y + height, x + width, y + height, x + width / 2, y + height);
     gr.CurveTo(x, y + height, x, y + height, x, y + height / 2);
     gr.Restore();
 }
Example #3
0
        private void DrawCurvedRectangle(Cairo.Context gr)
        {
            double x = 0, y = 0;

            gr.Save();
            gr.MoveTo(x, y + Height / 2);
            gr.CurveTo(x, y, x, y, x + Width / 2, y);
            gr.CurveTo(x + Width, y, x + Width, y, x + Width, y + Height / 2);
            gr.CurveTo(x + Width, y + Height, x + Width, y + Height, x + Width / 2, y + Height);
            gr.CurveTo(x, y + Height, x, y + Height, x, y + Height / 2);
            gr.Restore();
        }
Example #4
0
 public static void RoundedRectangle(Cairo.Context cr, float x, float y,
                                     float w, float h, float r)
 {
     cr.MoveTo(x + r, y);
     cr.LineTo(x + w - r, y);
     cr.CurveTo(x + w, y, x + w, y, x + w, y + r);
     cr.LineTo(x + w, y + h - r);
     cr.CurveTo(x + w, y + h, x + w, y + h, x + w - r, y + h);
     cr.LineTo(x + r, y + h);
     cr.CurveTo(x, y + h, x, y + h, x, y + h - r);
     cr.LineTo(x, y + r);
     cr.CurveTo(x, y, x, y, x + r, y);
 }
Example #5
0
    static void draw(Cairo.Context gr, int width, int height)
    {
        double x = 0.1, y = 0.5;
        double x1 = 0.4, y1 = 0.9, x2 = 0.6, y2 = 0.1, x3 = 0.9, y3 = 0.5;


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

        gr.MoveTo(new PointD(x, y));

        gr.CurveTo(new PointD(x1, y1),
                   new PointD(x2, y2),
                   new PointD(x3, y3)
                   );

        gr.Stroke();

        gr.Color     = new Color(1, 0.2, 0.2, 0.6);
        gr.LineWidth = 0.03;
        gr.MoveTo(new PointD(x, y));
        gr.LineTo(new PointD(x1, y1));
        gr.MoveTo(new PointD(x2, y2));
        gr.LineTo(new PointD(x3, y3));
        gr.Stroke();
    }
Example #6
0
    static void draw(Cairo.Context gr, int width, int height)
    {
        gr.Scale(width, height);
        gr.LineWidth = 0.04;

        gr.MoveTo(new PointD(0.5, 0.1));
        gr.LineTo(new PointD(0.9, 0.9));
        gr.RelLineTo(new Distance(-0.4, 0.0));
        gr.CurveTo(new PointD(0.2, 0.9),
                   new PointD(0.2, 0.5),
                   new PointD(0.5, 0.5)
                   );
        gr.ClosePath();

        gr.MoveTo(new PointD(0.25, 0.1));
        gr.RelLineTo(new Distance(0.2, 0.2));
        gr.RelLineTo(new Distance(-0.2, 0.2));
        gr.RelLineTo(new Distance(-0.2, -0.2));
        gr.ClosePath();

        gr.Color = new Color(0, 0, 1, 1);
        gr.FillPreserve();
        gr.Color = new Color(0, 0, 0, 1);
        gr.Stroke();
    }
        void LayoutTabBorder(Cairo.Context ctx, Gdk.Rectangle allocation, int contentWidth, int px, int margin, bool active = true)
        {
            double x      = 0.5 + (double)px;
            double y      = (double)allocation.Height + 0.5 - BottomBarPadding + margin;
            double height = allocation.Height - TopBarPadding - BottomBarPadding;

            x            += TabSpacing + margin;
            contentWidth -= (TabSpacing + margin) * 2;

            double rightx = x + contentWidth;

            int lean      = Math.Min(LeanWidth, contentWidth / 2);
            int halfLean  = lean / 2;
            int smoothing = 2;

            if (active)
            {
                ctx.MoveTo(0, y + 0.5);
                ctx.LineTo(0, y);
                ctx.LineTo(x - halfLean, y);
            }
            else
            {
                ctx.MoveTo(x - halfLean, y + 0.5);
                ctx.LineTo(x - halfLean, y);
            }
            ctx.CurveTo(new PointD(x + smoothing, y),
                        new PointD(x - smoothing, y - height),
                        new PointD(x + halfLean, y - height));
            ctx.LineTo(rightx - halfLean, y - height);
            ctx.CurveTo(new PointD(rightx + smoothing, y - height),
                        new PointD(rightx - smoothing, y),
                        new PointD(rightx + halfLean, y));

            if (active)
            {
                ctx.LineTo(allocation.Width, y);
                ctx.LineTo(allocation.Width, y + 0.5);
            }
            else
            {
                ctx.LineTo(rightx + halfLean, y + 0.5);
            }
        }
Example #8
0
 private void DrawConnection(Cairo.Context gc, PointD start, PointD c1, PointD c2, PointD end)
 {
     gc.Save();
     gc.LineWidth = (2.0 / this.ScaleFactor);
     gc.Color     = connectionGreen;
     gc.MoveTo(start.X, start.Y);
     gc.CurveTo(c1.X, c1.Y, c2.X, c2.Y, end.X, end.Y);
     gc.Stroke();
     gc.Restore();
 }
Example #9
0
        /// <summary>Paint on the graphics context</summary>
        /// <param name="context">The graphics context to draw on</param>
        public override void Paint(Cairo.Context context)
        {
            CalcBezPoints();

            if (BezPoints.Count != 0)
            {
                // Create point for upper-left corner of drawing.
                context.NewPath();
                if (Selected)
                {
                    context.SetSourceColor(OxyColors.Blue);
                }
                else
                {
                    context.SetSourceColor(Colour);
                }

                // Draw text if necessary
                if (Name != null)
                {
                    DGNode.DrawCentredText(context, Name, Location);
                }

                context.MoveTo(BezPoints[0]);
                PointD controlPoint = new PointD(Location.X, Location.Y);
                context.CurveTo(controlPoint, controlPoint, BezPoints[BezPoints.Count - 1]);
                context.Stroke();

                // find closest point in the bezPoints to the intersection point that is outside the target
                // work backwards through BezPoints array and use the first one that is outside the target
                for (int i = BezPoints.Count - 1; i >= 0; i--)
                {
                    PointD arrowHead;
                    if (!TargetNode.HitTest(BezPoints[i]))
                    {
                        arrowHead = BezPoints[i];
                        i--;
                        //keep moving along the line until distance = target radius
                        double targetRadius = TargetNode.Width / 2;
                        while (i >= 0)
                        {
                            double dist = GetDistance(BezPoints[i], arrowHead);
                            if (dist >= 20)
                            {
                                DrawArrow(context, BezPoints[i], arrowHead);
                                break;
                            }

                            i--;
                        }
                        break;
                    }
                }
            }
        }
Example #10
0
		protected override Gdk.Rectangle OnMouseMove (Context g, Color strokeColor, ImageSurface surface,
		                                              int x, int y, int lastX, int lastY)
		{
			int line_width = (int)g.LineWidth;
			int size;

			// we want a minimum size of 2 for the splatter (except for when the brush width is 1), since a splatter of size 1 is very small
			if (line_width == 1)
			{
				size = 1;
			}
			else
			{
				size = Random.Next (2, line_width);
			}

			Rectangle r = new Rectangle (x - Random.Next (-15, 15), y - Random.Next (-15, 15), size, size);

			double rx = r.Width / 2;
			double ry = r.Height / 2;
			double cx = r.X + rx;
			double cy = r.Y + ry;
			double c1 = 0.552285;

			g.Save ();

			g.MoveTo (cx + rx, cy);

			g.CurveTo (cx + rx, cy - c1 * ry, cx + c1 * rx, cy - ry, cx, cy - ry);
			g.CurveTo (cx - c1 * rx, cy - ry, cx - rx, cy - c1 * ry, cx - rx, cy);
			g.CurveTo (cx - rx, cy + c1 * ry, cx - c1 * rx, cy + ry, cx, cy + ry);
			g.CurveTo (cx + c1 * rx, cy + ry, cx + rx, cy + c1 * ry, cx + rx, cy);

			g.ClosePath ();

			Rectangle dirty = g.FixedStrokeExtents ();

			g.Fill ();
			g.Restore ();

			return dirty.ToGdkRectangle ();
		}
Example #11
0
 protected override void OnPaint(PaintEventArgs e)
 {
     base.OnPaint(e);
     using (System.Drawing.Graphics graphics = e.Graphics)
     {
         using (Win32Surface surface = new Win32Surface(graphics.GetHdc()))
         {
             using (Context context = new Context(surface))
             {
                 context.LineWidth = 2.0;
                 context.SetSourceColor(this.bugColor);
                 context.MoveTo(7.0, 64.0);
                 context.CurveTo(1.0, 47.0, 2.0, 46.0, 9.0, 51.0);
                 context.MoveTo(25.0, 80.0);
                 context.CurveTo(10.0, 73.0, 11.0, 70.0, 14.0, 63.0);
                 context.MoveTo(10.0, 41.0);
                 context.CurveTo(2.0, 36.0, 1.0, 33.0, 1.0, 26.0);
                 context.LineWidth = 1.0;
                 context.MoveTo(1.0, 26.0);
                 context.CurveTo(5.0, 23.0, 7.0, 18.0, 12.0, 17.0);
                 context.LineTo(12.0, 14.0);
                 context.Stroke();
                 context.MoveTo(30.0, 74.0);
                 context.CurveTo(14.0, 64.0, 10.0, 48.0, 11.0, 46.0);
                 context.LineTo(10.0, 45.0);
                 context.LineTo(10.0, 40.0);
                 context.CurveTo(13.0, 37.0, 15.0, 35.0, 19.0, 34.0);
                 context.Stroke();
             }
         }
     }
 }
Example #12
0
        public static void CurvedRectangle(Cairo.Context c, RectangleD rect, double radius)
        {
            if (rect.Width < (radius * 2.0))
            {
                radius = rect.Width / 2.0;
            }

            if (rect.Height < (radius * 2.0))
            {
                radius = rect.Height / 2.0;
            }

            c.MoveTo(rect.X, rect.Y + radius);
            c.LineTo(rect.X, rect.Y2 - radius);
            c.CurveTo(rect.X, rect.Y2 - radius, rect.X, rect.Y2, rect.X + radius, rect.Y2);
            c.LineTo(rect.X2 - radius, rect.Y2);
            c.CurveTo(rect.X2 - radius, rect.Y2, rect.X2, rect.Y2, rect.X2, rect.Y2 - radius);
            c.LineTo(rect.X2, rect.Y + radius);
            c.CurveTo(rect.X2, rect.Y + radius, rect.X2, rect.Y, rect.X2 - radius, rect.Y);
            c.LineTo(rect.X + radius, rect.Y);
            c.CurveTo(rect.X + radius, rect.Y, rect.X, rect.Y, rect.X, rect.Y + radius);
            c.ClosePath();
        }
Example #13
0
//		public void BeginPrint(object o, BeginPrintArgs args)
//		{
//			Console.WriteLine("BeginPrint");
//		}

        public void DrawPage(object o, DrawPageArgs args)
        {
            Console.WriteLine("DrawPage");

            Pango.Layout    layout;
            int             textWidth, textHeight;
            double          width;
            FontDescription desc;

            Cairo.Context con = args.Context.CairoContext;
            width = args.Context.Width;

            // Rectangle
            con.Rectangle(0, 0, width, HEADER_HEIGHT);
            con.Color = new Cairo.Color(1, 0.2, 0.2, 0.6);
            con.FillPreserve();

            // Draw another thing
            con.Color     = new Cairo.Color(0, 0, 0);
            con.LineWidth = 1;
            con.Stroke();

            con.Color = new Cairo.Color(0, 0, 0);
            con.MoveTo(20, 200);
            con.CurveTo(40, 270, 120, 165, 70, 60);
            con.Stroke();

            con.MoveTo(30, 100);
            con.LineTo(60, 80);
            con.Stroke();

            con.Color = new Cairo.Color(0, 0, 0);
            layout    = args.Context.CreatePangoLayout();
            layout.SetText("Prueba con Pango");
            desc = FontDescription.FromString("arial 14");
            layout.FontDescription = desc;

            layout.GetPixelSize(out textWidth, out textHeight);

            if (textWidth > width)
            {
                layout.Width     = (int)width;
                layout.Ellipsize = EllipsizeMode.Start;
                layout.GetPixelSize(out textWidth, out textHeight);
            }

            con.MoveTo((width - textWidth) / 2, (HEADER_HEIGHT - textHeight) / 2);
            Pango.CairoHelper.ShowLayout(con, layout);
        }
Example #14
0
    public static void CurvedCell(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 + cellsize, y + radius);
            gr.CurveTo(x + radius, y + radius, x + radius, y + radius, x + radius, y + cellsize);
            gr.MoveTo(x + radius, y);
            gr.CurveTo(x + radius, y + radius, x + radius, y + radius, x, y + radius);
        }
        else
        {
            gr.MoveTo(x + radius, y);
            gr.CurveTo(x + radius, y + radius, x + radius, y + radius, x + cellsize, y + radius);
            gr.MoveTo(x, y + radius);
            gr.CurveTo(x + radius, y + radius, x + radius, y + radius, x + radius, y + cellsize);
        }

        gr.Restore();
    }
    void LetsDraw(object sender, ExposeEventArgs args)
    {
        DrawingArea darea = (DrawingArea)sender;

        Cairo.Context shape = Gdk.CairoHelper.Create(darea.GdkWindow);

        //Write the shape code
        shape.SetSourceRGB(0.2, 0.5, 0.7);          // set the color
        shape.MoveTo(25, 130);
        shape.CurveTo(100, 235, 165, 25, 255, 130); //our curve line

        shape.StrokePreserve();
        shape.Fill();

        ((IDisposable)shape).Dispose();
    }
Example #16
0
		public void Execute(Context ctx)
		{
			PointD point;
			var first = true;

			using (var mpath = ctx.CopyPath())
			{
				var path = mpath.GetPath();

				for (var i = 0; i < path.num_data; )
				{
					var hdr = path.GetPathHeader(i); //hdr.Dump();

					switch (hdr.type)
					{
						case NativePath.cairo_path_data_type_t.CAIRO_PATH_MOVE_TO:
							if (first)
							{
								ctx.NewPath();
								first = false;
							}
							point = path.GetPathPoint(i + 1);
							ctx.MoveTo(WarpPoint(point));
							break;
						case NativePath.cairo_path_data_type_t.CAIRO_PATH_LINE_TO:
							point = path.GetPathPoint(i + 1);
							ctx.LineTo(WarpPoint(point));
							break;
						case NativePath.cairo_path_data_type_t.CAIRO_PATH_CURVE_TO:
							var p1 = WarpPoint(path.GetPathPoint(i + 1));
							var p2 = WarpPoint(path.GetPathPoint(i + 2));
							var p3 = WarpPoint(path.GetPathPoint(i + 3));
							ctx.CurveTo(p1, p2, p3);
							break;
						case NativePath.cairo_path_data_type_t.CAIRO_PATH_CLOSE_PATH:
							ctx.ClosePath();
							break;
					}

					i += hdr.length;
				}
			}
		}
Example #17
0
		public void curve_to(Context cr, int width, int height)
		{
			double x=0.1,  y=0.5;
			double x1=0.4, y1=0.9, x2=0.6, y2=0.1, x3=0.9, y3=0.5;

			Normalize (cr, width, height);

			cr.MoveTo(x, y);
			cr.CurveTo(x1, y1, x2, y2, x3, y3);

			cr.Stroke();

			cr.Color = new Color (1, 0.2, 0.2, 0.6);
			cr.LineWidth = 0.03;
			cr.MoveTo(x,y);
			cr.LineTo(x1,y1);
			cr.MoveTo(x2,y2);
			cr.LineTo(x3,y3);
			cr.Stroke();
		}
		static void LayoutTabBorder (Context ctx, Gdk.Rectangle allocation, int contentWidth, int px, int margin, bool active = true)
		{
			double x = 0.5 + (double)px;
			double y = (double)allocation.Height + 0.5 - BottomBarPadding + margin;
			double height = allocation.Height - TopBarPadding - BottomBarPadding;

			x += TabSpacing + margin;
			contentWidth -= (TabSpacing + margin) * 2;

			double rightx = x + contentWidth;

			int lean = Math.Min (LeanWidth, contentWidth / 2);
			int halfLean = lean / 2;
			const int smoothing = 2;
			if (active) {
				ctx.MoveTo (0, y + 0.5);
				ctx.LineTo (0, y);
				ctx.LineTo (x - halfLean, y);
			} else {
				ctx.MoveTo (x - halfLean, y + 0.5);
				ctx.LineTo (x - halfLean, y);
			}
			ctx.CurveTo (new PointD (x + smoothing, y),
				new PointD (x - smoothing, y - height),
				new PointD (x + halfLean, y - height));
			ctx.LineTo (rightx - halfLean, y - height);
			ctx.CurveTo (new PointD (rightx + smoothing, y - height),
				new PointD (rightx - smoothing, y),
				new PointD (rightx + halfLean, y));

			if (active) {
				ctx.LineTo (allocation.Width, y);
				ctx.LineTo (allocation.Width, y + 0.5);
			} else {
				ctx.LineTo (rightx + halfLean, y + 0.5);
			}
		}
Example #19
0
 public static void RoundedRectangle (Context cr,
                                      Gdk.Rectangle area,
                                      int radius,
                                      Corners corners)
 {
     // Top Line
     cr.MoveTo (area.X + radius + m_Offset, area.Y + m_Offset);
     cr.LineTo (area.X + area.Width - radius - m_Offset,
                area.Y + m_Offset);
     
     // Top Right Corner
     if ((corners & Corners.TopRight) > 0) {
         cr.CurveTo (area.X + area.Width - radius - m_Offset,
                     area.Y + m_Offset,
                     area.X + area.Width,
                     area.Y,
                     area.X + area.Width - m_Offset,
                     area.Y + radius + m_Offset);
     }
     else {
         cr.LineTo (area.X + area.Width - m_Offset,
                    area.Y + m_Offset);
         cr.LineTo (area.X + area.Width - m_Offset,
                    area.Y + m_Offset + radius);
     }
     
     // Right Line
     cr.LineTo (area.X + area.Width - m_Offset,
                area.Y + area.Height - radius - m_Offset);
     
     // Bottom Right Corner
     if ((corners & Corners.BottomRight) > 0) {
         cr.CurveTo (area.X + area.Width - m_Offset,
                     area.Y + area.Height - m_Offset - radius,
                     area.X + area.Width,
                     area.Y + area.Height,
                     area.X + area.Width - m_Offset - radius,
                     area.Y + area.Height - m_Offset);
     }
     else {
         cr.LineTo (area.X + area.Width - m_Offset,
                    area.Y + area.Height - m_Offset);
         cr.LineTo (area.X + area.Width - m_Offset - radius,
                    area.Y + area.Height - m_Offset);
     }
     
     // Bottom Line
     cr.LineTo (area.X + m_Offset + radius,
                area.Y + area.Height - m_Offset);
     
     // Bottom Left Corner
     if ((corners & Corners.BottomLeft) > 0) {
         cr.CurveTo (area.X + m_Offset + radius,
                     area.Y + area.Height - m_Offset,
                     area.X,
                     area.Y + area.Height,
                     area.X + m_Offset,
                     area.Y + area.Height - m_Offset - radius);
     }
     else {
         cr.LineTo (area.X + m_Offset,
                    area.Y + area.Height - m_Offset);
         cr.LineTo (area.X + m_Offset,
                    area.Y + area.Height - m_Offset - radius);
     }
     
     // Left Line
     cr.LineTo (area.X + m_Offset,
                area.Y + m_Offset + radius);
     
     // Top Left Corner
     if ((corners & Corners.TopLeft) > 0) {
         cr.CurveTo (area.X + m_Offset,
                     area.Y + m_Offset + radius,
                     area.X,
                     area.Y,
                     area.X + m_Offset + radius,
                     area.Y + m_Offset);
     }
     else {
         cr.LineTo (area.X + m_Offset, area.Y + m_Offset);
         cr.LineTo (area.X + m_Offset + radius, area.Y + m_Offset);
     }
 }
Example #20
0
		public void xxx_dash(Context cr, int width, int height)
		{
			double[] dashes = new double[] {
				0.20,  // ink
				0.05,  // skip
				0.05,  // ink
				0.05   // skip 
			};
			double offset = -0.2; 

			Normalize(cr, width, height);

			cr.SetDash(dashes, offset);

			cr.MoveTo(0.5, 0.1);
			cr.LineTo(0.9, 0.9);
			cr.RelLineTo(-0.4, 0.0);
			cr.CurveTo(0.2, 0.9, 0.2, 0.5, 0.5, 0.5);
			cr.Stroke();
		}
Example #21
0
		public void path(Context cr, int width, int height)
		{
			Normalize(cr, width, height);
			cr.MoveTo(0.5, 0.1);
			cr.LineTo(0.9, 0.9);
			cr.RelLineTo(-0.4, 0.0);
			cr.CurveTo(0.2, 0.9, 0.2, 0.5, 0.5, 0.5);

			cr.Stroke();
		}
Example #22
0
		public void fill_and_stroke2(Context cr, int width, int height)
		{
			Normalize (cr, width, height);

			cr.MoveTo(0.5, 0.1);
			cr.LineTo(0.9, 0.9);
			cr.RelLineTo(-0.4, 0.0);
			cr.CurveTo(0.2, 0.9, 0.2, 0.5, 0.5, 0.5);
			cr.ClosePath();

			cr.MoveTo(0.25, 0.1);
			cr.RelLineTo(0.2, 0.2);
			cr.RelLineTo(-0.2, 0.2);
			cr.RelLineTo(-0.2, -0.2);
			cr.ClosePath();

			cr.Color = new Color (0, 0, 1);
			cr.FillPreserve();
			cr.Color = new Color (0, 0, 0);

			cr.Stroke();
		}
Example #23
0
    static void draw(Cairo.Context gr, int width, int height)
    {
        double x0          = 0.1;
        double y0          = 0.1;
        double rect_width  = 0.8;
        double rect_height = 0.8;
        double radius      = 0.4;

        double x1, y1;

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

        x1 = x0 + rect_width;
        y1 = y0 + rect_height;
        if (rect_width == 0 || rect_height == 0)
        {
            return;
        }

        if (rect_width / 2 < radius)
        {
            if (rect_height / 2 < radius)
            {
                gr.MoveTo(new PointD(x0, (y0 + y1) / 2));

                gr.CurveTo(new PointD(x0, y0),
                           new PointD(x0, y0),
                           new PointD((x0 + x1) / 2, y0)
                           );

                gr.CurveTo(new PointD(x1, y0),
                           new PointD(x1, y0),
                           new PointD(x1, (y0 + y1) / 2)
                           );

                gr.CurveTo(new PointD(x1, y1),
                           new PointD(x1, y1),
                           new PointD((x1 + x0) / 2, y1)
                           );

                gr.CurveTo(new PointD(x0, y1),
                           new PointD(x0, y1),
                           new PointD(x0, (y0 + y1) / 2)
                           );
            }
            else
            {
                gr.MoveTo(new PointD(x0, y0 + radius));

                gr.CurveTo(new PointD(x0, y0),
                           new PointD(x0, y0),
                           new PointD((x0 + x1) / 2, y0)
                           );

                gr.CurveTo(new PointD(x1, y0),
                           new PointD(x1, y0),
                           new PointD(x1, y0 + radius)
                           );

                gr.LineTo(new PointD(x1, y1 - radius));

                gr.CurveTo(new PointD(x1, y1),
                           new PointD(x1, y1),
                           new PointD((x1 + x0) / 2, y1)
                           );

                gr.CurveTo(new PointD(x0, y1),
                           new PointD(x0, y1),
                           new PointD(x0, y1 - radius)
                           );
            }
        }
        else
        {
            if (rect_height / 2 < radius)
            {
                gr.MoveTo(new PointD(x0, (y0 + y1) / 2));

                gr.CurveTo(new PointD(x0, y0),
                           new PointD(x0, y0),
                           new PointD(x0 + radius, y0)
                           );

                gr.LineTo(new PointD(x1 - radius, y0));

                gr.CurveTo(new PointD(x1, y0),
                           new PointD(x1, y0),
                           new PointD(x1, (y0 + y1) / 2)
                           );

                gr.CurveTo(new PointD(x1, y1),
                           new PointD(x1, y1),
                           new PointD(x1 - radius, y1)
                           );

                gr.LineTo(new PointD(x0 + radius, y1));

                gr.CurveTo(new PointD(x0, y1),
                           new PointD(x0, y1),
                           new PointD(x0, (y0 + y1) / 2)
                           );
            }
            else
            {
                gr.MoveTo(new PointD(x0, y0 + radius));

                gr.CurveTo(new PointD(x0, y0),
                           new PointD(x0, y0),
                           new PointD(x0 + radius, y0)
                           );

                gr.LineTo(new PointD(x1 - radius, y0));

                gr.CurveTo(new PointD(x1, y0),
                           new PointD(x1, y0),
                           new PointD(x1, y0 + radius)
                           );

                gr.LineTo(new PointD(x1, y1 - radius));

                gr.CurveTo(new PointD(x1, y1),
                           new PointD(x1, y1),
                           new PointD(x1 - radius, y1)
                           );

                gr.LineTo(new PointD(x0 + radius, y1));
                gr.CurveTo(new PointD(x0, y1),
                           new PointD(x0, y1),
                           new PointD(x0, y1 - radius)
                           );
            }
        }

        gr.Color = new Color(0.5, 0.5, 1, 1);
        gr.FillPreserve();
        gr.Color = new Color(0.5, 0, 0, 0.5);
        gr.Stroke();
    }
Example #24
0
 public void CreateRoundedRectPath(Context gc, double x, double y, double width, double height, double radius)
 {
     double x1, y1;
     x1 = x + width;
     y1 = y + height;
     if (width / 2 < radius) {
         if (height / 2 < radius) {
             gc.MoveTo (x, (y + y1) / 2);
             gc.CurveTo (x ,y, x, y, (x + x1) / 2, y);
             gc.CurveTo (x1, y, x1, y, x1, (y + y1) / 2);
             gc.CurveTo (x1, y1, x1, y1, (x1 + x) / 2, y1);
             gc.CurveTo (x, y1, x, y1, x, (y + y1) / 2);
         } else {
             gc.MoveTo (x, y + radius);
             gc.CurveTo (x, y, x, y, (x + x1) / 2, y);
             gc.CurveTo (x1, y, x1, y, x1, y + radius);
             gc.LineTo (x1 , y1 - radius);
             gc.CurveTo (x1, y1, x1, y1, (x1 + x) / 2, y1);
             gc.CurveTo (x, y1, x, y1, x, y1 - radius);
         }
     } else {
         if (height / 2 < radius) {
             gc.MoveTo (x, (y + y1) / 2);
             gc.CurveTo (x , y, x, y, x + radius, y);
             gc.LineTo (x1 - radius, y);
             gc.CurveTo (x1, y, x1, y, x1, (y + y1) / 2);
             gc.CurveTo (x1, y1, x1, y1, x1 - radius, y1);
             gc.LineTo (x + radius, y1);
             gc.CurveTo (x, y1, x, y1, x, (y + y1) / 2);
         } else {
             gc.MoveTo (x, y + radius);
             gc.CurveTo (x , y, x , y, x + radius, y);
             gc.LineTo (x1 - radius, y);
             gc.CurveTo (x1, y, x1, y, x1, y + radius);
             gc.LineTo (x1, y1 - radius);
             gc.CurveTo (x1, y1, x1, y1, x1 - radius, y1);
             gc.LineTo (x + radius, y1);
             gc.CurveTo (x, y1, x, y1, x, y1 - radius);
         }
     }
     gc.ClosePath ();
 }
Example #25
0
		public void curve_rectangle(Context cr, int width, int height)
		{
			// a custom shape, that could be wrapped in a function
			double x0	   = 0.1,   //< parameters like cairo_rectangle
			       y0	   = 0.1,
			       rect_width  = 0.8,
		    	   rect_height = 0.8,
				   radius = 0.4;   //< and an approximate curvature radius

			double x1,y1;

			Normalize(cr, width, height);

			x1=x0+rect_width;
			y1=y0+rect_height;

			if (rect_width/2<radius) {
				if (rect_height/2<radius) {
					cr.MoveTo(x0, (y0 + y1)/2);
					cr.CurveTo(x0 ,y0, x0, y0, (x0 + x1)/2, y0);
					cr.CurveTo(x1, y0, x1, y0, x1, (y0 + y1)/2);
					cr.CurveTo(x1, y1, x1, y1, (x1 + x0)/2, y1);
					cr.CurveTo(x0, y1, x0, y1, x0, (y0 + y1)/2);
				} else {
					cr.MoveTo(x0, y0 + radius);
					cr.CurveTo(x0 ,y0, x0, y0, (x0 + x1)/2, y0);
					cr.CurveTo(x1, y0, x1, y0, x1, y0 + radius);
					cr.LineTo(x1 , y1 - radius);
					cr.CurveTo(x1, y1, x1, y1, (x1 + x0)/2, y1);
					cr.CurveTo(x0, y1, x0, y1, x0, y1- radius);
				}
			} else {
				if (rect_height/2<radius) {
					cr.MoveTo(x0, (y0 + y1)/2);
					cr.CurveTo(x0 , y0, x0 , y0, x0 + radius, y0);
					cr.LineTo(x1 - radius, y0);
					cr.CurveTo(x1, y0, x1, y0, x1, (y0 + y1)/2);
					cr.CurveTo(x1, y1, x1, y1, x1 - radius, y1);
					cr.LineTo(x0 + radius, y1);
					cr.CurveTo(x0, y1, x0, y1, x0, (y0 + y1)/2);
				} else {
					cr.MoveTo(x0, y0 + radius);
					cr.CurveTo(x0 , y0, x0 , y0, x0 + radius, y0);
					cr.LineTo(x1 - radius, y0);
					cr.CurveTo(x1, y0, x1, y0, x1, y0 + radius);
					cr.LineTo(x1 , y1 - radius);
					cr.CurveTo(x1, y1, x1, y1, x1 - radius, y1);
					cr.LineTo(x0 + radius, y1);
					cr.CurveTo(x0, y1, x0, y1, x0, y1- radius);
				}
			}
			cr.ClosePath();

			// and fill/stroke it
			cr.Color = new Color (0.5, 0.5, 1);
			cr.FillPreserve();
			cr.Color = new Color (0.5, 0, 0, 0.5);
			cr.Stroke();
		}
Example #26
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();
        }