LineTo() public méthode

public LineTo ( PointD p ) : void
p PointD
Résultat void
        //intro top Welcome
        public void IntroTop(Cairo.Context g, Int32 width)
        {
            PointD p1, p2, p3, p4, s1, s2, s3, s4;

            p1 = new PointD(10, 10); p2 = new PointD(width, 10); s1 = new PointD(width + 2, 12); s2 = new PointD(width + 2, 38);
            p3 = new PointD(width, 40); p4 = new PointD(10, 40); s3 = new PointD(8, 38); s4 = new PointD(8, 12);

            g.Color = new Color(0.3, 0.4, 0.6, 1);
            g.MoveTo(p1); g.LineTo(p2); g.LineTo(s1); g.LineTo(s2); g.LineTo(p3); g.LineTo(p4); g.LineTo(s3); g.LineTo(s4); g.LineTo(p1);
            g.ClosePath(); g.LineWidth = 1; g.Stroke();

            g.MoveTo(p1); g.LineTo(p2);  g.LineTo(s1); g.LineTo(s2); g.LineTo(p3); g.LineTo(p4); g.LineTo(s3); g.LineTo(s4); g.LineTo(p1);
            g.ClosePath();

            Cairo.Gradient pat = new Cairo.LinearGradient(80, 10, 80, 80);
            pat.AddColorStop(0, new Cairo.Color(0.3, 0.4, 0.6, 0.6));
            pat.AddColorStop(1, new Cairo.Color(0, 0, 0, 1));
            g.Pattern = pat; g.FillPreserve();

            g.SetFontSize(22);
            g.SelectFontFace("", FontSlant.Italic, FontWeight.Bold);
            g.MoveTo(new PointD(22, 33));
            g.Color = new Color(1, 1, 1, 1);
            g.ShowText("Welcome to");

            ((IDisposable)g.Target).Dispose();
            ((IDisposable)g).Dispose();
        }
Exemple #2
0
        void DrawBackground(Cairo.Context gr)
        {
            gr.Rectangle(0, 0, Allocation.Width, Allocation.Height);
            gr.Color = new Color(1, 1, 1);
            gr.Fill();

            gr.Rectangle(0, 0, Allocation.Width, timeHeight);
            var gradient = new LinearGradient(0, 0, 0, timeHeight);

            gradient.AddColorStop(0, timeGradientStartColor);
            gradient.AddColorStop(1, timeGradientEndColor);
            gr.Pattern = gradient;
            gr.Fill();

            gr.LineWidth = 1;
            gr.Color     = lineColor;
            gr.MoveTo(0, timeHeight + 0.5);
            gr.LineTo(Allocation.Width, timeHeight + 0.5);
            gr.Stroke();

            gr.MoveTo(0, timeHeight + eventHeight + 0.5);
            gr.LineTo(Allocation.Width, timeHeight + eventHeight + 0.5);
            gr.Stroke();

            gr.MoveTo(boxWidth + 0.5, 0);
            gr.LineTo(boxWidth + 0.5, Allocation.Height);
            gr.Stroke();
        }
Exemple #3
0
        /// <summary>
        /// Draw the robot taking into account the center x and y position of the map which
        /// will be different from the true center x and y positions on the drawing context.
        /// This method will result in a red wheeled robot with black tyres being drawn at
        /// the robots location on the map.
        ///
        /// The scale value is currently unused but it could be useful if the map was scaled
        /// in some way for example a mini-map may be 10 times smaller than the original
        /// results in 1:10 scale robot.
        /// </summary>
        /// <param name="cairoContext">Cairo context to draw to (assuming a map).</param>
        /// <param name="centerX">Center x position of map to draw onto.</param>
        /// <param name="centerY">Center y position of map to draw onto.</param>
        /// <param name="scale">Scale currently unused.</param>
        public void Draw(Cairo.Context cairoContext, int centerX, int centerY, double scale)
        {
            // Scale up to centimeters.
            int width  = (int)(robot.Width * 100);
            int height = (int)(robot.Height * 100);
            int x      = (int)(robot.X * 100);
            int y      = (int)(robot.Y * 100);

            // Set a red colour.
            cairoContext.SetSourceRGB(255, 0, 0);

            cairoContext.LineWidth = 1.0;
            cairoContext.LineCap   = LineCap.Butt;

            cairoContext.Translate(centerX + x, centerY - y);
            cairoContext.Rotate(relativeRotation);              // Rotate the robot based on its orientation in radians.

            // Draw the robot as a triangle.
            cairoContext.MoveTo(0, -height / 2);
            cairoContext.LineTo(-width / 2, height / 2);
            cairoContext.LineTo(width / 2, height / 2);
            cairoContext.LineTo(0, -height / 2);
            cairoContext.Stroke();

            // Reset the drawing context.
            cairoContext.Rotate(-relativeRotation);
            cairoContext.Translate(-(centerX + x), -(centerY - y));
        }
Exemple #4
0
        internal static void DrawArrow(this Cairo.Context g, Point p0, Point p1)
        {
            var x0 = p0.X;
            var y0 = p0.Y;
            var x1 = p1.X;
            var y1 = p1.Y;

            var dx = x1 - x0;
            var dy = y1 - y0;

            if (MathEx.AmostZero(dx) && MathEx.AmostZero(dy))
            {
                return;
            }

            var n0 = new Vector(-dy, dx); n0.Normalize();
            var n1 = new Vector(dy, -dx); n1.Normalize();

            var B = new Point(x1, y1);
            var d = new Vector(x0 - x1, y0 - y1); d.Normalize();

            var arrowEnd0 = B + 20 * (d + n0);
            var arrowEnd1 = B + 20 * (d + n1);

            g.MoveTo(x1, y1);
            g.LineTo(new Cairo.PointD(arrowEnd0.X, arrowEnd0.Y));
            g.MoveTo(x1, y1);
            g.LineTo(new Cairo.PointD(arrowEnd1.X, arrowEnd1.Y));
            g.MoveTo(x1, y1);
        }
Exemple #5
0
        public override void DrawFrameBorder(Cairo.Context cr, Gdk.Rectangle alloc)
        {
            if (IsPanelWidget)
            {
                return;
            }
            else if (!IsSourceViewWidget)
            {
                base.DrawFrameBorder(cr, alloc);
                return;
            }

            cr.Color     = TextMidColor;
            cr.LineWidth = 1.0;
            cr.Antialias = Cairo.Antialias.None;

            cr.MoveTo(alloc.Right - 1, alloc.Top);
            cr.LineTo(alloc.Right - 1, alloc.Bottom);
            cr.Stroke();

            if (Widget.Allocation.Bottom < Widget.Toplevel.Allocation.Height)
            {
                cr.MoveTo(alloc.Left, alloc.Bottom - 1);
                cr.LineTo(alloc.Right, alloc.Bottom - 1);
                cr.Stroke();
            }

            cr.Antialias = Cairo.Antialias.Default;
        }
Exemple #6
0
        static void Main()
        {
            // The using statement ensures that potentially heavy objects
            // are disposed immediately.
            using (ImageSurface draw = new ImageSurface(Format.Argb32, 70, 150))
            {
                using (Context gr = new Context(draw))
                {
                    gr.Antialias = Antialias.Subpixel;    // sets the anti-aliasing method
                    gr.LineWidth = 9;          // sets the line width
                    gr.SetSourceColor(new Color(0, 0, 0, 1));   // red, green, blue, alpha
                    gr.MoveTo(10, 10);          // sets the Context's start point.
                    gr.LineTo(40, 60);          // draws a "virtual" line from 5,5 to 20,30
                    gr.Stroke();          //stroke the line to the image surface

                    gr.Antialias = Antialias.Gray;
                    gr.LineWidth = 8;
                    gr.SetSourceColor(new Color(1, 0, 0, 1));
                    gr.LineCap = LineCap.Round;
                    gr.MoveTo(10, 50);
                    gr.LineTo(40, 100);
                    gr.Stroke();

                    gr.Antialias = Antialias.None;    //fastest method but low quality
                    gr.LineWidth = 7;
                    gr.MoveTo(10, 90);
                    gr.LineTo(40, 140);
                    gr.Stroke();

                    draw.WriteToPng("antialias.png");  //save the image as a png image.
                }
            }
        }
Exemple #7
0
        private void DrawTriangle(Cairo.Context context)
        {
            double height = sideLength * Math.Sqrt(3) / 2;

            double x1 = offsetX;
            double y1 = height + offsetY;

            double x2 = 0.5 * sideLength + offsetX;
            double y2 = 0 + offsetY;

            double x3 = sideLength + offsetX;
            double y3 = height + offsetY;

            context.NewPath();
            context.SetSourceColor(Utility.Colour.ToOxy(owner.MainWidget.StyleContext.GetColor(StateFlags.Normal).ToColour().ToGdk()));

            context.MoveTo(x1, y1);

            context.LineTo(x2, y2);
            context.StrokePreserve();
            context.LineTo(x3, y3);
            context.StrokePreserve();
            context.LineTo(x1, y1);
            context.StrokePreserve();
        }
Exemple #8
0
    static void draw(Cairo.Context gr, int width, int height)
    {
        int          w, h;
        ImageSurface image;

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

        gr.Arc(0.5, 0.5, 0.3, 0, 2 * M_PI);
        gr.Clip();
        gr.NewPath();

        image = new ImageSurface("data/e.png");
        w     = image.Width;
        h     = image.Height;

        gr.Scale(1.0 / w, 1.0 / h);

        image.Show(gr, 0, 0);

        image.Destroy();

        gr.Arc(0.5, 0.5, 0.3, 0, 2 * M_PI);
        gr.Clip();

        gr.NewPath();
        gr.Rectangle(new PointD(0, 0), 1, 1);
        gr.Fill();
        gr.Color = new Color(0, 1, 0, 1);
        gr.MoveTo(new PointD(0, 0));
        gr.LineTo(new PointD(1, 1));
        gr.MoveTo(new PointD(1, 0));
        gr.LineTo(new PointD(0, 1));
        gr.Stroke();
    }
Exemple #9
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();
    }
Exemple #10
0
	static void draw (Context cr, int width, int height)
	{
		double xc = 0.5;
		double yc = 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
		
		cr.Scale (width, height);
		cr.LineWidth = 0.04;

		cr.Arc (xc, yc, radius, angle1, angle2);
		cr.Stroke ();
		
		// draw helping lines
		cr.Color = new Color(1, 0.2, 0.2, 0.6);
		cr.Arc (xc, yc, 0.05, 0, 2 * Math.PI);
		cr.Fill ();
		cr.LineWidth = 0.03;
		cr.Arc (xc, yc, radius, angle1, angle1);
		cr.LineTo (new PointD (xc, yc));
		cr.Arc (xc, yc, radius, angle2, angle2);
		cr.LineTo (new PointD (xc, yc));
		cr.Stroke ();
	}
Exemple #11
0
        protected void UpdateTexture ()
        {
            text.SetSurfaceSize ((uint) (Width+MarginX),(uint) (Height+MarginY));
            text.Clear ();
            Cairo.Context context = text.Create ();

            double lwidth = 1;
            double hlwidth = lwidth*0.5;
            double width = Width - lwidth;
            double height = Height - lwidth;
            double radius = Math.Min(marginX, marginY)*0.75;

            if ((radius > height / 2) || (radius > width / 2))
                radius = Math.Min(height / 2, width / 2);

            context.MoveTo (hlwidth, hlwidth + radius);
            context.Arc (hlwidth + radius, hlwidth + radius, radius, Math.PI, -Math.PI / 2);
            context.LineTo (hlwidth + width - radius, hlwidth);
            context.Arc (hlwidth + width - radius, hlwidth + radius, radius, -Math.PI / 2, 0);
            context.LineTo (hlwidth + width, hlwidth + height - radius);
            context.Arc (hlwidth + width - radius, hlwidth + height - radius, radius, 0, Math.PI / 2);
            context.LineTo (hlwidth + radius, hlwidth + height);
            context.Arc (hlwidth + radius, hlwidth + height - radius, radius, Math.PI / 2, Math.PI);
            context.ClosePath ();

            context.LineWidth = lwidth;
            context.SetSourceRGB (1.0,1.0,1.0);
            context.Stroke ();

            ((IDisposable) context.Target).Dispose ();
            ((IDisposable) context).Dispose ();
        }
Exemple #12
0
    //http://www.mono-project.com/docs/tools+libraries/libraries/Mono.Cairo/cookbook/
    private static void drawRoundedRectangle(double x, double y, double width, double height,
                                             double radius, Cairo.Context g, Cairo.Color color)
    {
        g.Save();

        if ((radius > height / 2) || (radius > width / 2))
        {
            radius = min(height / 2, width / 2);
        }

        g.MoveTo(x, y + radius);
        g.Arc(x + radius, y + radius, radius, Math.PI, -Math.PI / 2);
        g.LineTo(x + width - radius, y);
        g.Arc(x + width - radius, y + radius, radius, -Math.PI / 2, 0);
        g.LineTo(x + width, y + height - radius);
        g.Arc(x + width - radius, y + height - radius, radius, 0, Math.PI / 2);
        g.LineTo(x + radius, y + height);
        g.Arc(x + radius, y + height - radius, radius, Math.PI / 2, Math.PI);
        g.ClosePath();
        g.Restore();

        g.SetSourceRGB(color.R, color.G, color.B);
        g.FillPreserve();
        g.SetSourceRGB(0, 0, 0);
        g.LineWidth = 2;
        g.Stroke();
    }
        protected override void CreatePassiveTexture(Clutter.CairoTexture texture, int with_state)
        {
            texture.Clear();
            Cairo.Context context = texture.Create();

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

            //Draw outline rectangles:
            DrawSmallCovers(context, texture.Width, texture.Height, lwidth);

            //Draw play icon:
            context.MoveTo((texture.Width - lwidth) * 0.5, 0.3 * (texture.Height - lwidth));
            context.LineTo((texture.Width - lwidth) * 0.5, texture.Height - hlwidth);
            context.LineTo(texture.Width - hlwidth, 0.65 * (texture.Height - lwidth));
            context.ClosePath();
            context.LineWidth = lwidth;
            double sat = (with_state == 0 ? 0.4 : (with_state == 1 ? 0.6 : 0.8));

            context.SetSourceRGBA(sat, sat, sat, 1.0);
            context.FillPreserve();
            context.SetSourceRGB(1.0, 1.0, 1.0);
            context.Stroke();

            ((IDisposable)context.Target).Dispose();
            ((IDisposable)context).Dispose();
        }
Exemple #14
0
        //system top
        public void SystemTop(Cairo.Context g, Int32 width)
        {
            PointD p1, p2, p3, p4, s1, s2, s3, s4;

            p1 = new PointD(5, 5); p2 = new PointD(width, 5); s1 = new PointD(width + 2, 7); s2 = new PointD(width + 2, 28);
            p3 = new PointD(width, 30); p4 = new PointD(5, 30); s3 = new PointD(3, 28); s4 = new PointD(3, 7);

            g.Color = new Color(0.3, 0.4, 0.6, 1);
            g.MoveTo(p1); g.LineTo(p2);  g.LineTo(s1);  g.LineTo(s2); g.LineTo(p3); g.LineTo(p4); g.LineTo(s3); g.LineTo(s4); g.LineTo(p1);
            g.ClosePath(); g.LineWidth = 1; g.Stroke();

            g.MoveTo(p1); g.LineTo(p2); g.LineTo(s1); g.LineTo(s2); g.LineTo(p3); g.LineTo(p4); g.LineTo(s3); g.LineTo(s4); g.LineTo(p1);
            g.ClosePath();

            Cairo.Gradient pat = new Cairo.LinearGradient(80, 10, 80, 60);
            pat.AddColorStop(0, new Cairo.Color(0.3, 0.4, 0.6, 0.6));
            pat.AddColorStop(1, new Cairo.Color(0, 0, 0, 1));
            g.Pattern = pat;
            g.FillPreserve();

            g.SetFontSize(17);
            g.SelectFontFace("", FontSlant.Normal, FontWeight.Bold);
            g.MoveTo(new PointD(12, 23));
            g.Color = new Color(1, 1, 1, 1);
            g.ShowText("General system information");

            ((IDisposable)g.Target).Dispose();
            ((IDisposable)g).Dispose();
        }
Exemple #15
0
        private void DrawGrid(Cairo.Context g)
        {
            if (daysInMonth < 28 && daysInMonth > 32)
            {
                return;
            }

            g.SetSourceRGB(0, 0, 0);
            for (int i = 0; i <= totalColums; i++)
            {
                PointD pTop = new PointD(cellWidth * i, 0);
                PointD pBot = new PointD(cellWidth * i, tableHeight);

                g.MoveTo(pTop);
                g.LineTo(pBot);
            }
            for (int i = 0; i <= totalRows; i++)
            {
                PointD pTop = new PointD(0, cellHeight * i);
                PointD pBot = new PointD(tableWidth, cellHeight * i);

                g.MoveTo(pTop);
                g.LineTo(pBot);
            }
            g.ClosePath();
            g.Stroke();
        }
Exemple #16
0
        public static Rectangle DrawRectangle(this Cairo.Context g, Cairo.Rectangle r, Cairo.Color color, int lineWidth)
        {
            // Put it on a pixel line
            if (lineWidth == 1)
            {
                r = new Rectangle(r.X - 0.5, r.Y - 0.5, r.Width, r.Height);
            }

            g.Save();

            g.MoveTo(r.X, r.Y);
            g.LineTo(r.X + r.Width, r.Y);
            g.LineTo(r.X + r.Width, r.Y + r.Height);
            g.LineTo(r.X, r.Y + r.Height);
            g.LineTo(r.X, r.Y);

            g.Color     = color;
            g.LineWidth = lineWidth;
            g.LineCap   = LineCap.Square;

            Rectangle dirty = g.StrokeExtents();

            g.Stroke();

            g.Restore();

            return(dirty);
        }
Exemple #17
0
        public override void DrawHeaderSeparator(Cairo.Context cr, Gdk.Rectangle alloc, int x)
        {
            Cairo.Color gtk_background_color = CairoExtensions.GdkRGBAToCairoColor(
                Widget.StyleContext.GetBackgroundColor(StateFlags.Normal));
            Cairo.Color dark_color  = CairoExtensions.ColorShade(gtk_background_color, 0.80);
            Cairo.Color light_color = CairoExtensions.ColorShade(gtk_background_color, 1.1);

            int y_1 = alloc.Top + 4;
            int y_2 = alloc.Bottom - 3;

            cr.LineWidth = 1;
            cr.Antialias = Cairo.Antialias.None;

            cr.Color = dark_color;
            cr.MoveTo(x, y_1);
            cr.LineTo(x, y_2);
            cr.Stroke();

            cr.Color = light_color;
            cr.MoveTo(x + 1, y_1);
            cr.LineTo(x + 1, y_2);
            cr.Stroke();

            cr.Antialias = Cairo.Antialias.Default;
        }
Exemple #18
0
        protected override void DrawGraduations(Context gr, PointD pStart, PointD pEnd)
        {
            Rectangle r = ClientRectangle;
            Foreground.SetAsSource (gr);

            gr.LineWidth = 2;
            gr.MoveTo(pStart);
            gr.LineTo(pEnd);

            gr.Stroke();
            gr.LineWidth = 1;

            double sst = unity * SmallIncrement;
            double bst = unity * LargeIncrement;

            PointD vBar = new PointD(0, sst);
            for (double x = Minimum; x <= Maximum - Minimum; x += SmallIncrement)
            {
                double lineLength = r.Height / 3;
                if (x % LargeIncrement != 0)
                    lineLength /= 3;
                PointD p = new PointD(pStart.X + x * unity, pStart.Y);
                gr.MoveTo(p);
                gr.LineTo(new PointD(p.X, p.Y + lineLength));
            }
            gr.Stroke();
        }
    void draw_grid(Cairo.Context gr, int w, int h)
    {
        double y_interval, y_spacing;
        double pixels    = 80;
        double num_ticks = h / pixels;
        double interval  = max_y / num_ticks;
        double min_size  = 1;

        while (true)
        {
            double new_size = min_size * 10;
            if (new_size < interval)
            {
                min_size = new_size;
                continue;
            }
            break;
        }
        y_spacing  = pixels * min_size / interval;
        y_interval = min_size;

        gr.Color     = new Color(0.4, 0.4, 0.4, 1);
        gr.LineWidth = .5;
        double y_label = 0;

        for (double i = h; i >= 0; i -= y_spacing)
        {
            gr.MoveTo(0, i);
            gr.LineTo(w, i);
            gr.Stroke();
            gr.LineTo(5, i);
            gr.ShowText(GetLabel(y_label));
            y_label += y_interval;
        }
    }
Exemple #20
0
    //http://www.mono-project.com/docs/tools+libraries/libraries/Mono.Cairo/cookbook/
    private static void drawRoundedRectangle(double x, double y, double width, double height,
                                             double radius, Cairo.Context g, Cairo.Color color)
    {
        g.Save();

        //manage negative widths
        if (width < 0)
        {
            x     += width;         //it will shift to the left (width is negative)
            width *= -1;
        }

        if ((radius > height / 2) || (radius > width / 2))
        {
            radius = min(height / 2, width / 2);
        }

        g.MoveTo(x, y + radius);
        g.Arc(x + radius, y + radius, radius, Math.PI, -Math.PI / 2);
        g.LineTo(x + width - radius, y);
        g.Arc(x + width - radius, y + radius, radius, -Math.PI / 2, 0);
        g.LineTo(x + width, y + height - radius);
        g.Arc(x + width - radius, y + height - radius, radius, 0, Math.PI / 2);
        g.LineTo(x + radius, y + height);
        g.Arc(x + radius, y + height - radius, radius, Math.PI / 2, Math.PI);
        g.ClosePath();
        g.Restore();

        g.SetSourceRGB(color.R, color.G, color.B);
        g.FillPreserve();
        g.SetSourceRGB(0, 0, 0);
        g.LineWidth = 2;
        g.Stroke();
    }
Exemple #21
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.Arc(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();
    }
Exemple #22
0
        /// <summary>
        /// Dibuja el Grid
        /// </summary>
        /// <param name="canvas">Canvas.</param>
        private void DrawGrid(Cairo.Context canvas)
        {
            double maxHeight = Margin.Height;
            double maxWidth  = Margin.Width;
            double yGap      = (maxHeight - Margin.Y) / (NumLineas - 1);
            double xGap      = (maxWidth - Margin.X) / (NumLineas - 1);
            double x         = Margin.X;
            double y         = Margin.Y;

            canvas.LineWidth = 0.25;
            canvas.SetSourceRGB(0, 0, 0);

            // Draw horizontal lines
            while (y < maxHeight)
            {
                canvas.MoveTo(Margin.X, y);
                canvas.LineTo(maxWidth, y);

                y += yGap;
            }

            // Draw vertical lines
            while (x < maxWidth + 1)
            {
                canvas.MoveTo(x, Margin.Y);
                canvas.LineTo(x, maxHeight);

                x += xGap;
            }
            canvas.Stroke();
        }
Exemple #23
0
        public static void DrawRoundedRectangle(Cairo.Context gr, double x, double y,
                                                double width, double height, double radius,
                                                Cairo.Color color, Cairo.Color borderColor)
        {
            gr.Save();

            if ((radius > height / 2) || (radius > width / 2))
            {
                radius = Math.Min(height / 2, width / 2);
            }

            gr.MoveTo(x, y + radius);
            gr.Arc(x + radius, y + radius, radius, Math.PI, -Math.PI / 2);
            gr.LineTo(x + width - radius, y);
            gr.Arc(x + width - radius, y + radius, radius, -Math.PI / 2, 0);
            gr.LineTo(x + width, y + height - radius);
            gr.Arc(x + width - radius, y + height - radius, radius, 0, Math.PI / 2);
            gr.LineTo(x + radius, y + height);
            gr.Arc(x + radius, y + height - radius, radius, Math.PI / 2, Math.PI);
            gr.ClosePath();
            gr.Restore();

            gr.LineJoin = LineJoin.Round;
            gr.Color    = borderColor;
            gr.StrokePreserve();
            gr.Color = color;
            gr.Fill();
        }
Exemple #24
0
 private void dibujar_grilla(DrawingArea area, Cairo.Context cr)
 {
     for (int x = 0; x < Constantes.nro_casillas; x++)
     {
         int x0 = Logica.grilla.get_casillero(x, 0).inicioX;
         cr.Save();
         cr.LineWidth = 0.5;
         cr.SetSourceRGBA(0, 0, 0, 0.5);
         cr.MoveTo(x0, 0);
         cr.LineTo(x0, Constantes.limites.Height);
         cr.Stroke();
         cr.Restore();
     }
     for (int y = 0; y < Constantes.nro_casillas; y++)
     {
         int y0 = Logica.grilla.get_casillero(0, y).inicioY;
         cr.Save();
         cr.LineWidth = 0.5;
         cr.SetSourceRGBA(0, 0, 0, 0.5);
         cr.MoveTo(0, y0);
         cr.LineTo(Constantes.limites.Width, y0);
         cr.Stroke();
         cr.Restore();
     }
 }
Exemple #25
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();
             }
         }
     }
 }
Exemple #26
0
 private void Image_Loaded(object sender, RoutedEventArgs e)
 {
     Image image = (Image)sender;
     using (ImageSurface surface = new ImageSurface(Format.Argb32, (int)image.Width, (int)image.Height))
     {
         using (Context context = new Context(surface))
         {
             PointD p = new PointD(10.0, 10.0);
             PointD p2 = new PointD(100.0, 10.0);
             PointD p3 = new PointD(100.0, 100.0);
             PointD p4 = new PointD(10.0, 100.0);
             context.MoveTo(p);
             context.LineTo(p2);
             context.LineTo(p3);
             context.LineTo(p4);
             context.LineTo(p);
             context.ClosePath();
             context.Fill();
             context.MoveTo(140.0, 110.0);
             context.SetFontSize(32.0);
             context.SetSourceColor(new Color(0.0, 0.0, 0.8, 1.0));
             context.ShowText("Hello Cairo!");
             surface.Flush();
             RgbaBitmapSource source = new RgbaBitmapSource(surface.Data, surface.Width);
             image.Source = source;
         }
     }
 }
Exemple #27
0
        //intro bottom tips
        public void IntroBottom(Cairo.Context g)
        {
            PointD p1, p2, p3, p4, s1, s2, s3, s4;

            p1 = new PointD(30, 10); p2 = new PointD(420, 10); s1 = new PointD(422, 12); s2 = new PointD(422, 88);
            p3 = new PointD(420, 90); p4 = new PointD(30, 90); s3 = new PointD(28, 88); s4 = new PointD(28, 12);

            g.Color = new Color(0.3, 0.4, 0.6, 0.8);
            g.MoveTo(p1); g.LineTo(p2); g.LineTo(s1); g.LineTo(s2); g.LineTo(p3); g.LineTo(p4); g.LineTo(s3); g.LineTo(s4); g.LineTo(p1);
            g.ClosePath(); g.LineWidth = 1; g.Stroke();

            g.MoveTo(p1); g.LineTo(p2); g.LineTo(s1); g.LineTo(s2); g.LineTo(p3); g.LineTo(p4); g.LineTo(s3); g.LineTo(s4); g.LineTo(p1);
            g.ClosePath();

            Cairo.Gradient pat = new Cairo.LinearGradient(80, 20, 80, 80);
            pat.AddColorStop(0, new Cairo.Color(0.3, 0.4, 0.6, 0));
            pat.AddColorStop(1, new Cairo.Color(0.3, 0.4, 0.6, 0.3));
            g.Pattern = pat;
            g.FillPreserve();


            g.Color = new Color(0, 0, 0, 0.8);
            g.SelectFontFace("", FontSlant.Italic, FontWeight.Bold);
            g.SetFontSize(18);
            g.MoveTo(new PointD(88, 28));
            g.ShowText(".");
            g.MoveTo(new PointD(88, 58));
            g.ShowText(".");
            g.SelectFontFace("", FontSlant.Italic, FontWeight.Normal);
            g.SetFontSize(10);
            g.MoveTo(new PointD(98, 30));
            g.ShowText("Use the navigation on the left to choose different categories");
            g.MoveTo(new PointD(98, 42));
            g.ShowText("of your computer and system information to display.");
            g.MoveTo(new PointD(98, 60));
            g.ShowText("When you click on a category in the navigation, the dynamic");
            g.MoveTo(new PointD(98, 72));
            g.ShowText("information is automatically refreshed.");

            g.MoveTo(new PointD(38, 35));
            g.Color = new Color(0.3, 0.4, 0.6, 1);
            g.SelectFontFace("", FontSlant.Normal, FontWeight.Bold);
            g.SetFontSize(18);
            g.ShowText("Tips");

            g.NewPath();

            /*
             * g.Color = new Color (0.3, 0.4, 0.6, 0.8);
             * g.Scale (34, 34);
             * g.LineWidth = 0.06;
             * g.Arc (1.0, 1.0, 0.6, 0, 360);
             * g.Stroke ();*/

            ((IDisposable)g.Target).Dispose();
            ((IDisposable)g).Dispose();
        }
Exemple #28
0
 public static void DrawTriangle(Cairo.Context g, double x, double y,
                                 int width, int height, Cairo.Color color)
 {
     g.Color = color;
     g.MoveTo(x, y);
     g.LineTo(x + width / 2, y - height);
     g.LineTo(x - width / 2, y - height);
     g.ClosePath();
     g.Fill();
     g.Stroke();
 }
Exemple #29
0
        public static void RoundedRectangle(Cairo.Context cr, double x, double y, double w, double h,
                                            double r, CairoCorners corners)
        {
            if (r < 0.0001 || corners == CairoCorners.None)
            {
                cr.Rectangle(x, y, w, h);
                return;
            }

            if ((corners & CairoCorners.TopLeft) != 0)
            {
                cr.MoveTo(x + r, y);
            }
            else
            {
                cr.MoveTo(x, y);
            }

            if ((corners & CairoCorners.TopRight) != 0)
            {
                cr.Arc(x + w - r, y + r, r, Math.PI * 1.5, Math.PI * 2);
            }
            else
            {
                cr.LineTo(x + w, y);
            }

            if ((corners & CairoCorners.BottomRight) != 0)
            {
                cr.Arc(x + w - r, y + h - r, r, 0, Math.PI * 0.5);
            }
            else
            {
                cr.LineTo(x + w, y + h);
            }

            if ((corners & CairoCorners.BottomLeft) != 0)
            {
                cr.Arc(x + r, y + h - r, r, Math.PI * 0.5, Math.PI);
            }
            else
            {
                cr.LineTo(x, y + h);
            }

            if ((corners & CairoCorners.TopLeft) != 0)
            {
                cr.Arc(x + r, y + r, r, Math.PI, Math.PI * 1.5);
            }
            else
            {
                cr.LineTo(x, y);
            }
        }
		public static void Draw(Context grw, Line line)
		{
			var color = AppController.Instance.Config.LineColor;
			grw.SetSourceRGB (
				color.Red, 
				color.Green, 
				color.Blue);

			var segments = AppController.Instance.Surface.Segments;

			var s1 = segments.FirstOrDefault (s => s.Position.X == line.Input.X 
				&& s.Position.Y == line.Input.Y);

			var s2 = segments.FirstOrDefault (s => s.Position.X == line.Output.X 
				&& s.Position.Y == line.Output.Y);
			
			if (s1 == null || s2 == null)
			{
				return;
			}

			//todo : use one func.
			var start = s1.Connectors
				.FirstOrDefault (p => p.Marker == line.InputMarker);

			//todo : use one func.
			var stop = s2.Connectors
				.FirstOrDefault (p => p.Marker == line.OutputMarker);
			if (start == null || stop == null)
			{
				return;
			}

			grw.MoveTo (
				start.Center.GeometryX, 
				start.Center.GeometryY);

			if (line.Input.X == line.Output.X ||
			   line.Input.Y == line.Output.Y) {
				grw.LineTo (
					stop.Center.GeometryX, 
					stop.Center.GeometryY);    
			} else {
				grw.LineTo (
					stop.Center.GeometryX, 
					start.Center.GeometryY);    

				grw.LineTo (
					stop.Center.GeometryX, 
					stop.Center.GeometryY);    
			}

			grw.Stroke();
		}
Exemple #31
0
 public override void Draw(Gdk.Drawable d, Cairo.Context g, int width, int height, bool screenChanged)
 {
     g.MoveTo(0, 0);
     g.LineTo(width, 0);
     g.LineTo(width, height);
     g.LineTo(0, height);
     g.LineTo(0, 0);
     g.ClosePath();
     g.Color = GetCurrentColor();
     g.Fill();
 }
Exemple #32
0
        /// <summary>
        /// Dibuja los ejes del gráfico x e y
        /// </summary>
        /// <param name="canvas">Canvas</param>
        private void DrawAxis(Cairo.Context canvas)
        {
            canvas.LineWidth = 2;
            canvas.SetSourceRGB(0, 0, 0);

            canvas.MoveTo(Margin.X, Margin.Y);
            canvas.LineTo(Margin.X, Margin.Height);
            canvas.MoveTo(Margin.X, Margin.Height);
            canvas.LineTo(Margin.Width, Margin.Height);

            canvas.Stroke();
        }
Exemple #33
0
        /// <summary>
        /// Raises the expose event and draws the map.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="args">Arguments.</param>
        private void OnExpose(object sender, ExposeEventArgs args)
        {
            DrawingArea area = (DrawingArea)sender;

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

            // Draw the background.
            cairoContext.Rectangle(0, 0, viewWidth, viewHeight);
            cairoContext.SetSourceRGB(255, 255, 255);
            cairoContext.StrokePreserve();
            cairoContext.Fill();

            // Draw the grid.
            cairoContext.LineWidth = 1.0;
            cairoContext.LineCap   = LineCap.Butt;
            cairoContext.SetSourceRGB(0, 0, 0);

            // Columns.
            int position = cellWidth;

            for (; position <= viewWidth - cellWidth; position += cellWidth)
            {
                // We have to add 0.5 to the x position otherwise Cairo will
                // smear it across 2 pixels.
                cairoContext.MoveTo(position + 0.5, 0.0);
                cairoContext.LineTo(position + 0.5, viewHeight);
                cairoContext.Stroke();
            }

            // Rows.
            position = cellHeight;

            for (; position <= viewHeight - cellHeight; position += cellHeight)
            {
                // We have to add 0.5 to the y position otherwise Cairo will
                // smear it across 2 pixels.
                cairoContext.MoveTo(0.0, position + 0.5);
                cairoContext.LineTo(viewWidth, position + 0.5);
                cairoContext.Stroke();
            }

            if (robotView.Robot.PathPointList.Count > 1)
            {
                pathView.Draw(cairoContext, centerX, centerY, 1.0);
            }

            robotView.Draw(cairoContext, centerX, centerY, 1.0);
            landmarkView.Draw(cairoContext, centerX, centerY, 1.0);

            ((IDisposable)cairoContext.GetTarget()).Dispose();
            ((IDisposable)cairoContext).Dispose();
        }
Exemple #34
0
        private void SetTitlePath(Cairo.Context cr)
        {
            int    radius = parent.WindowRadius;
            double x      = .5;
            double y      = .5;
            double width  = parent.ThreePaneWidth - 1;

            cr.MoveTo(x + radius, y);
            cr.Arc(x + width - radius, y + radius, radius, Math.PI * 1.5, Math.PI * 2);
            cr.LineTo(x + width, Height);
            cr.LineTo(x, Height);
            cr.Arc(x + radius, y + radius, radius, Math.PI, Math.PI * 1.5);
        }
Exemple #35
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);
 }
        private void Render(Clutter.CairoTexture texture, int with_state, bool outwards)
        {
            texture.Clear();
            Cairo.Context context = texture.Create();

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

            //Draw outline rectangles:
            context.Rectangle(hlwidth, hlwidth, texture.Width - lwidth, texture.Height - lwidth);
            context.SetSourceRGB(1.0, 1.0, 1.0);
            context.LineWidth = lwidth;
            context.StrokePreserve();
            double sat = (with_state == 0 ? 0.4 : (with_state == 1 ? 0.6 : 0.8));

            context.SetSourceRGB(sat, sat, sat);
            context.Fill();

            double dim = 4;

            context.MoveTo(-dim, 0);
            context.LineTo(outwards ? 0 : -dim, outwards ? 0 : dim);
            context.LineTo(0, dim);
            context.MoveTo(-dim, dim);
            context.LineTo(0, 0);
            context.ClosePath();
            Cairo.Path arrow = context.CopyPath();
            context.NewPath();

            double margin = 2 + hlwidth;
            PointD center = new PointD(texture.Width * 0.5, texture.Height * 0.5);
            PointD transl = new PointD(center.X - margin, -(center.Y - margin));

            context.LineWidth = lwidth;
            sat = (with_state == 1 ? 0.0 : 1.0);
            context.SetSourceRGB(sat, sat, sat);

            context.Translate(center.X, center.Y);
            for (int i = 0; i < 4; i++)
            {
                context.Rotate(Math.PI * 0.5 * i);
                context.Translate(transl.X, transl.Y);
                context.AppendPath(arrow);
                context.Stroke();
                context.Translate(-transl.X, -transl.Y);
            }

            ((IDisposable)arrow).Dispose();
            ((IDisposable)context.Target).Dispose();
            ((IDisposable)context).Dispose();
        }
Exemple #37
0
        public override void Draw(Context context)
        {
            SetupLayout(context);

            RectangleD displayBox = DisplayBox;
            displayBox.OffsetDot5();
            double side = 10.0;

            context.LineWidth = LineWidth;
            context.Save ();
            //Box
            context.MoveTo (displayBox.X, displayBox.Y);
            context.LineTo (displayBox.X, displayBox.Y + displayBox.Height);
            context.LineTo (displayBox.X + displayBox.Width, displayBox.Y + displayBox.Height);
            context.LineTo (displayBox.X + displayBox.Width, displayBox.Y + side);
            context.LineTo (displayBox.X + displayBox.Width - side, displayBox.Y);
            context.LineTo (displayBox.X, displayBox.Y);
            context.Save ();
            //Triangle
            context.MoveTo (displayBox.X + displayBox.Width - side, displayBox.Y);
            context.LineTo (displayBox.X + displayBox.Width - side, displayBox.Y + side);
            context.LineTo (displayBox.X + displayBox.Width, displayBox.Y + side);
            context.LineTo (displayBox.X + displayBox.Width - side, displayBox.Y);
            context.Restore ();

            context.Color = FillColor;
            context.FillPreserve ();
            context.Color = LineColor;
            context.Stroke ();

            DrawText (context);
        }
		protected override void DrawBackground (Context context, Gdk.Rectangle region)
		{
			LayoutRoundedRectangle (context, region);
			context.Clip ();

			context.SetSourceColor (CairoExtensions.ParseColor ("D3E6FF"));
			context.Paint ();

			context.Save ();
			context.Translate (region.X + region.Width / 2.0, region.Y + region.Height);

			using (var rg = new RadialGradient (0, 0, 0, 0, 0, region.Height * 1.2)) {
				var color = CairoExtensions.ParseColor ("E5F0FF");
				rg.AddColorStop (0, color);
				color.A = 0;
				rg.AddColorStop (1, color);

				context.Scale (region.Width / (double)region.Height, 1.0);
				context.SetSource (rg);
				context.Paint ();
			}

			context.Restore ();

			LayoutRoundedRectangle (context, region, -3, -3, 2);
			context.SetSourceRGBA (1, 1, 1, 0.4);
			context.LineWidth = 1;
			context.StrokePreserve ();

			context.Clip ();

			int boxSize = 11;
			int x = region.Left + (region.Width % boxSize) / 2;
			for (; x < region.Right; x += boxSize) {
				context.MoveTo (x + 0.5, region.Top);
				context.LineTo (x + 0.5, region.Bottom);
			}

			int y = region.Top + (region.Height % boxSize) / 2;
			y += boxSize / 2;
			for (; y < region.Bottom; y += boxSize) {
				context.MoveTo (region.Left, y + 0.5);
				context.LineTo (region.Right, y + 0.5);
			}

			context.SetSourceRGBA (1, 1, 1, 0.2);
			context.Stroke ();

			context.ResetClip ();
		}
        public void DrawObject(Context ctx, DrawingObject body)
        {
            if (body == null)
                return;
            ctx.Save ();
            ctx.Color = new Cairo.Color (0, 0, 0);

            ctx.LineWidth = 1;
            foreach (Tuple<PointDouble, PointDouble> line in body.lines) {
                ctx.MoveTo (line.Item1.toPointD());
                ctx.LineTo (line.Item2.toPointD());
            }

            if (body.points.Count > 1)
                ctx.Rectangle(body._centerOfMass.X - 5, body._centerOfMass.Y - 5, 10, 10);
            ctx.Stroke ();

            foreach (PointDouble point in body.points) {
                ctx.Rectangle (point.X - 5, point.Y - 5, 10, 10);
                ctx.Fill ();
            }
            foreach (Tuple<PointDouble, double, double> force in body._forces) {
                DrawForce (ctx, force);
            }

            foreach (Tuple<PointDouble, double> moment in body._moments) {
                DrawMoment (ctx, moment);
            }

            ctx.Restore ();
        }
		public override PointD Draw (Context context, PointD a, PointD b) {
			PointD leftPoint = new PointD ();
			PointD middlePoint = new PointD ();
			PointD rightPoint = new PointD ();
			Geometry.GetArrowPoints (a, b, _lineDistance, _pointDistance, 
									out leftPoint, out rightPoint, out middlePoint);
			
			context.MoveTo (middlePoint);
			context.LineTo (leftPoint);
			context.LineTo (a);
			context.LineTo (rightPoint);
			context.LineTo (middlePoint);
			context.Stroke ();
			
			return middlePoint;
		}
Exemple #41
0
		protected override Gdk.Rectangle OnMouseMove (Context g, Color strokeColor, ImageSurface surface,
		                                              int x, int y, int lastX, int lastY)
		{
			// Cairo does not support a single-pixel-long single-pixel-wide line
			if (x == lastX && y == lastY && g.LineWidth == 1 &&
			    PintaCore.Workspace.ActiveWorkspace.PointInCanvas (new PointD(x,y))) {
				surface.Flush ();

				ColorBgra source = surface.GetColorBgraUnchecked (x, y);
				source = UserBlendOps.NormalBlendOp.ApplyStatic (source, strokeColor.ToColorBgra ());
				surface.SetColorBgra (source, x, y);
				surface.MarkDirty ();

				return new Gdk.Rectangle (x - 1, y - 1, 3, 3);
			}

			g.MoveTo (lastX + 0.5, lastY + 0.5);
			g.LineTo (x + 0.5, y + 0.5);
			g.StrokePreserve ();

			Gdk.Rectangle dirty = g.FixedStrokeExtents ().ToGdkRectangle ();

			// For some reason (?!) we need to inflate the dirty
			// rectangle for small brush widths in zoomed images
			dirty.Inflate (1, 1);

			return dirty;
		}
		public override void Draw (Context context, IDrawingView view) {
			RectangleD rect = ViewDisplayBox(view);
			
			context.LineWidth = LineWidth;

			context.MoveTo (rect.Center.X, rect.Top);
			context.LineTo (rect.Right, rect.Center.Y);
			context.LineTo (rect.Center.X, rect.Bottom);
			context.LineTo (rect.Left, rect.Center.Y);
			context.LineTo (rect.Center.X, rect.Top);

			context.Color = new Cairo.Color (1.0, 0.0, 0.0, 0.8);
			context.FillPreserve ();
			context.Color = new Cairo.Color (0.0, 0.0, 0.0, 1.0);
			context.Stroke ();
		}
Exemple #43
0
  protected override FlowReturn OnTransformIp (Gst.Buffer buf) {
    if (!buf.IsWritable)
      return FlowReturn.Error;

    Cairo.ImageSurface img = new Cairo.ImageSurface (buf.Data, Cairo.Format.Rgb24, width, height, width*4);

    using (Cairo.Context context = new Cairo.Context (img)) {
      double dx = (double) ( (buf.Timestamp / Clock.MSecond) % 2180) / 5;
      context.Save ();
      context.Scale (width / 640.0, height / 480.0);
      context.MoveTo (300, 10 + dx);
      context.LineTo (500 - dx, 400);
      context.LineWidth = 4.0;
      context.Color = new Color (0, 0, 1.0);
      context.Stroke();
      context.Restore ();

      if (lastX != -1 && lastY != -1) {
        context.Color = new Color (1.0, 0, 0);
        context.Translate (lastX, lastY);
        context.Scale (Math.Min (width / 640.0, height / 480.0), Math.Min (width / 640.0, height / 480.0));
        context.Arc (0, 0, 10.0, 0.0, 2 * Math.PI);
        context.Fill();
      }
    }

    img.Destroy ();
    return base.OnTransformIp (buf);
  }
Exemple #44
0
    public void DrawGraph(Context gr)
    {
        int mag = Magnification;
        double xoffset =  (Allocation.Width/2) ;
        double yoffset =  (Allocation.Height/2) ;

        if (ForceGraph != null) {
            this.GdkWindow.Clear ();
            gr.Antialias = Antialias.Subpixel;
            foreach (var p in ForceGraph.Springs){
                gr.LineWidth = 1.5;

                if ( p.Data != null ){
                    var data = p.Data as NodeData;
                    if ( data != null )
                        gr.Color = data.Stroke;
                } else {
                    gr.Color = new Color( 0,0,0,1);
                }
                gr.MoveTo( xoffset + ( p.NodeA.Location.X * mag ), yoffset + ( p.NodeA.Location.Y * mag ) );
                gr.LineTo( xoffset + ( p.NodeB.Location.X * mag ), yoffset + ( p.NodeB.Location.Y * mag ) );
                gr.Stroke();

            }

            foreach (var n in ForceGraph.Nodes) {
                var stroke = new Color( 0.1, 0.1, 0.1, 0.8 );
                var fill   = new Color( 0.2, 0.7, 0.7, 0.8 );
                var size = 5.5;

                NodeData nd = n.Data as NodeData;
                if ( nd != null ){
                    stroke = nd.Stroke;
                    fill = nd.Fill;
                    size = nd.Size;

                }

                DrawFilledCircle (gr,
                    xoffset + (mag * n.Location.X),
                    yoffset + (mag * n.Location.Y),
                    size,
                    stroke,
                    fill
                    );

                if ( nd != null ) {
                    if ( nd.Label != null ){
                        gr.Color = new Color(0,0,0,0.7);
                        gr.SetFontSize(24);
                        gr.MoveTo( 25 + xoffset + (mag * n.Location.X), 25 + yoffset + (mag * n.Location.Y));
                        gr.ShowText( nd.Label );
                    }
                }

            }

        }
    }
        public override void Draw(Context cr, Gdk.Rectangle clip)
        {
            base.Draw(cr, clip);

            double X      = clip.X;
            double Y      = clip.Y;
            double Width  = clip.Width;
            double Height = clip.Height;

            // Blue Rulings
            if(horizontalRule) {
                cr.Color = blue;
                for(double i = Y - (Y % ruleDistance) + ruleDistance;
                        i <= Y + Height; i += ruleDistance) {
                    cr.MoveTo(X, i);
                    cr.LineTo(X + Width, i);
                    cr.Stroke();
                }
            }
            if(verticalRule) {
                cr.Color = blue;
                for(double i = X - (X % ruleDistance) + ruleDistance;
                        i <= X + Width; i += ruleDistance) {
                    cr.MoveTo(i, Y);
                    cr.LineTo(i, Y + Height);
                    cr.Stroke();
                }
            }

            // Red Margin Line
            if(leftMargin) {
                cr.Color = red;
                cr.MoveTo(marginSize, Y);
                cr.LineTo(marginSize, Y + Height);
                cr.Stroke();
            }

            // Holes
            if(holes) {
                cr.Color = black;
                cr.Arc(ruleDistance/2, 150, 17, 0, 2 * Math.PI);
                cr.Arc(ruleDistance/2, 650, 17, 0, 2 * Math.PI);
                cr.Arc(ruleDistance/2, 1150,17, 0, 2 * Math.PI);
                cr.Fill();
            }
        }
Exemple #46
0
		protected override Gdk.Rectangle OnMouseMove (Context g, Color strokeColor, ImageSurface surface,
		                                              int x, int y, int lastX, int lastY)
		{
			int dx = x - lastX;
			int dy = y - lastY;
			double px = Math.Cos (theta) * dx - Math.Sin (theta) * dy;
			double py = Math.Sin (theta) * dx + Math.Cos (theta) * dy;

			g.MoveTo (lastX - px, lastY - py);
			g.LineTo (lastX + px, lastY + py);
			g.LineTo (x + px, y + py);
			g.LineTo (x - px, y - py);
			g.LineTo (lastX - px, lastY - py);

			g.StrokePreserve ();

			return g.FixedStrokeExtents ().ToGdkRectangle ();
		}
Exemple #47
0
        public override void LayoutOutline(Node node, Context context)
        {
            PolygonNode poly = node as PolygonNode;
            // polygons have 3 sides
            if (poly.Verticies.Count <= 2)
                return;

            var renderVerts = poly.Verticies.Select (v => new Point (v.X * node.Width, v.Y * node.Height)).ToList ();
            context.MoveTo (renderVerts.First ().ToCairo ());
            renderVerts.ForEach (v => context.LineTo (v.ToCairo ()));
        }
        public void draw(Context cr)
        {
            Triangle t = model.tri;
            switch (model.alignment) {
            case ActiveTriangle.TriangleAlignment.ChaoticEvil:
                cr.SetSourceRGB (0.5, 0, 0);
                break;
            case ActiveTriangle.TriangleAlignment.TrueNeutral:
                cr.SetSourceRGB (0, 0.8, 0);
                break;
            default:
                cr.SetSourceRGB (1.0, 1.0, 0);
                break;

            }
            cr.LineWidth = 1.1;
            cr.MoveTo (t.a);
            cr.LineTo (t.b);
            cr.MoveTo (t.b);
            cr.LineTo (t.c);
            cr.MoveTo (t.c);
            cr.LineTo (t.a);
            cr.Stroke ();

            cr.Fill();

            Tuple<PointD,PointD,PointD,PointD> points;

            points = model.getSharpestPointAndAssociatedMidpointAndDullestPoints ();
            PointD sharpest = points.Item1;
            PointD midPoint = points.Item2;

            cr.SetSourceRGB (1.0, 0.3, 0.3);
            cr.Arc (sharpest.X, sharpest.Y, 2, 0, 2 * Math.PI);
            cr.Fill ();

            cr.Arc (midPoint.X, midPoint.Y, 2, 0, 2 * Math.PI);
            cr.Fill ();
        }
Exemple #49
0
		public void arc(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.Arc(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();
		}
Exemple #50
0
 // Returns a Gst.Buffer presentation of one 640x480 BGRA frame using Cairo
 static Gst.Buffer DrawData (ulong seconds) {
   Gst.Buffer buffer = new Gst.Buffer (640*480*4);
   Cairo.ImageSurface img = new Cairo.ImageSurface (buffer.Data, Cairo.Format.Argb32, 640, 480, 640*4);
   using (Cairo.Context context = new Cairo.Context (img)) {
     double dx = (double) (seconds % 2180) / 5;
     context.Color = new Color (1.0, 1.0, 0);
     context.Paint();
     context.MoveTo (300, 10 + dx);
     context.LineTo (500 - dx, 400);
     context.LineWidth = 4.0;
     context.Color = new Color (0, 0, 1.0);
     context.Stroke();
   }
   img.Destroy();
   return buffer;
 }
Exemple #51
0
 public static void DrawVertexStructure(VertexStructure vs, Context cr)
 {
     VertexStructure head = vs;
     int i = 0;
     do {
         cr.MoveTo (vs.v);
         cr.SetSourceRGB (0, 0, 0.8);
         cr.Arc (vs.v.X, vs.v.Y, 2, 0, 2 * Math.PI);
         cr.Fill ();
         cr.LineWidth = 1;
         cr.MoveTo (vs.v);
         cr.LineTo(vs.next.v);
         cr.Stroke();
         vs = vs.next;
         //Logger.Log("Meh..." + i);
         i++;
     } while(!ReferenceEquals(vs,head));
 }
Exemple #52
0
		public static void Draw(Context grw, LineElement line)
		{
			if (line.Foregraund != null) {
				grw.SetSourceRGB (
					line.Foregraund.Red, 
					line.Foregraund.Green, 
					line.Foregraund.Blue);
			}

			grw.MoveTo(
				line.Start.GeometryX, 
				line.Start.GeometryY);
			grw.LineTo(
				line.End.GeometryX, 
				line.End.GeometryY);    

			grw.Stroke();
		}
Exemple #53
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;
				}
			}
		}
Exemple #54
0
        protected override void onDraw(Context gr)
        {
            base.onDraw (gr);

            Rectangle r = ClientRectangle;
            Point m = r.Center;

            gr.Save ();

            double aUnit = Math.PI*2.0 / (Maximum - Minimum);
            gr.Translate (m.X, r.Height *1.1);
            gr.Rotate (Value/4.0 * aUnit - Math.PI/4.0);
            gr.Translate (-m.X, -m.Y);

            gr.LineWidth = 2;
            Foreground.SetAsSource (gr);
            gr.MoveTo (m.X,0.0);
            gr.LineTo (m.X, -m.Y*0.5);
            gr.Stroke ();

            gr.Restore ();
        }
Exemple #55
0
        protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            if (mouse_button <= 0) {
                last_point = point_empty;
                return;
            }

            int x = (int)point.X;
            int y = (int)point.Y;

            if (last_point.Equals (point_empty))
                last_point = new Point (x, y);

            if (doc.Workspace.PointInCanvas (point))
                surface_modified = true;

            ImageSurface surf = doc.CurrentUserLayer.Surface;

            using (Context g = new Context (surf)) {
                g.AppendPath (doc.Selection.SelectionPath);
                g.FillRule = FillRule.EvenOdd;
                g.Clip ();

                g.Antialias = UseAntialiasing ? Antialias.Subpixel : Antialias.None;

                // Adding 0.5 forces cairo into the correct square:
                // See https://bugs.launchpad.net/bugs/672232
                g.MoveTo (last_point.X + 0.5, last_point.Y + 0.5);
                g.LineTo (x + 0.5, y + 0.5);

                // Right-click is erase to background color, left-click is transparent
                if (mouse_button == 3)
                    g.SetSourceRGBA(PintaCore.Palette.SecondaryColor);
                else
                    g.Operator = Operator.Clear;

                g.LineWidth = BrushWidth;
                g.LineJoin = LineJoin.Round;
                g.LineCap = LineCap.Round;

                g.Stroke ();
            }

            Gdk.Rectangle r = GetRectangleFromPoints (last_point, new Point (x, y));

            if (doc.Workspace.IsPartiallyOffscreen (r)) {
                doc.Workspace.Invalidate ();
            } else {
                doc.Workspace.Invalidate (doc.ClampToImageSize (r));
            }

            last_point = new Point (x, y);
        }
Exemple #56
0
        public override void Render(Context cr)
        {
            if (!CanResize) {
                return;
            }

            var selected_color = CairoExtensions.GdkColorToCairoColor (Window.Style.Dark (StateType.Active));
            var grad = new LinearGradient (0, 0, 0, Allocation.Height);

            selected_color.A = 0.4;
            grad.AddColorStop (0, selected_color);
            selected_color.A = 1.0;
            grad.AddColorStop (1, selected_color);

            cr.Pattern = grad;
            cr.LineWidth = 1.0;
            cr.Rectangle (0.5, 0.5, Allocation.Width - 1, Allocation.Height - 1);
            cr.Stroke ();

            selected_color.A = 0.5;
            cr.Color = selected_color;

            double handle_size = 8;
            double ty = 0.5 + Allocation.Height - handle_size - 3;
            double tx = 0.5 + (Window.Direction == TextDirection.Ltr
                ? Allocation.Width - handle_size - 3
                : 3);

            cr.Translate (tx, ty);

            for (double i = 0; i < 3; i++) {
                if (Window.Direction == TextDirection.Ltr) {
                    cr.MoveTo (i * 3, handle_size);
                    cr.LineTo (handle_size, i * 3);
                } else {
                    cr.MoveTo (0, i * 3);
                    cr.LineTo (handle_size - i * 3, handle_size);
                }
            }

            cr.Stroke ();

            cr.Translate (-tx, -ty);
        }
Exemple #57
0
        private void DrawGrid(Context g)
        {
            g.Color = new Color (0.05, 0.05, 0.05);
            g.SetDash (new double[] {4, 4}, 2);
            g.LineWidth = 1;

            for (int i = 1; i < 4; i++) {
                g.MoveTo (i * size / 4, 0);
                g.LineTo (i * size / 4, size);
                g.MoveTo (0, i * size / 4);
                g.LineTo (size, i * size / 4);
            }

            g.MoveTo (0, size - 1);
            g.LineTo (size - 1, 0);
            g.Stroke ();

            g.SetDash (new double[] {}, 0);
        }
Exemple #58
0
        protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            Color tool_color;

            if ((args.Event.State & Gdk.ModifierType.Button1Mask) == Gdk.ModifierType.Button1Mask)
                tool_color = PintaCore.Palette.PrimaryColor;
            else if ((args.Event.State & Gdk.ModifierType.Button3Mask) == Gdk.ModifierType.Button3Mask)
                tool_color = PintaCore.Palette.SecondaryColor;
            else {
                last_point = point_empty;
                return;
            }

            DrawingArea drawingarea1 = (DrawingArea)o;

            int x = (int)point.X;
            int y = (int)point.Y;

            if (last_point.Equals (point_empty)) {
                last_point = new Point (x, y);
                return;
            }

            if (PintaCore.Workspace.PointInCanvas (point))
                surface_modified = true;

            ImageSurface surf = PintaCore.Layers.CurrentLayer.Surface;

            using (Context g = new Context (surf)) {
                g.AppendPath (PintaCore.Layers.SelectionPath);
                g.FillRule = FillRule.EvenOdd;
                g.Clip ();

                g.Antialias = Antialias.None;

                g.MoveTo (last_point.X, last_point.Y);
                g.LineTo (x, y);

                g.Color = tool_color;
                g.LineWidth = 1;
                g.LineCap = LineCap.Square;

                g.Stroke ();
            }

            Gdk.Rectangle r = GetRectangleFromPoints (last_point, new Point (x, y));

            PintaCore.Workspace.Invalidate (r);

            last_point = new Point (x, y);
        }
Exemple #59
0
        private void DrawPointerCross(Context g)
        {
            int x, y;
            Gdk.ModifierType mask;
            drawing.GdkWindow.GetPointer (out x, out y, out mask);

            if (x >= 0 && x < size && y >= 0 && y < size) {
                g.LineWidth = 0.5;
                g.MoveTo (x, 0);
                g.LineTo (x, size);
                g.MoveTo (0, y);
                g.LineTo (size , y);
                g.Stroke ();

                this.labelPoint.Text = string.Format ("({0}, {1})", x, y);
            } else
                this.labelPoint.Text = string.Empty;
        }
Exemple #60
0
        private void DrawSpline(Context g)
        {
            var infos = GetDrawingInfos ();

            foreach (var controlPoints in ControlPoints) {

                int points = controlPoints.Count;
                SplineInterpolator interpolator = new SplineInterpolator ();
                IList<int> xa = controlPoints.Keys;
                IList<int> ya = controlPoints.Values;
                PointD[] line = new PointD [size];

                for (int i = 0; i < points; i++) {
                    interpolator.Add (xa [i], ya [i]);
                }

                for (int i = 0; i < line.Length; i++) {
                   			line[i].X = (float)i;
                            line[i].Y = (float)(Utility.Clamp(size - 1 - interpolator.Interpolate (i), 0, size - 1));

                        }

                g.LineWidth = 2;
                g.LineJoin = LineJoin.Round;

                g.MoveTo (line [0]);
                for (int i = 1; i < line.Length; i++)
                    g.LineTo (line [i]);

                infos.MoveNext ();
                var info = infos.Current;

                g.Color = info.Color;
                g.LineWidth = info.IsActive ? 2 : 1;
                g.Stroke ();
            }
        }