Stroke() публичный Метод

public Stroke ( ) : void
Результат void
Пример #1
0
        public void DrawRowSelection(Cairo.Context cr, int x, int y, int width, int height,
                                     bool filled, bool stroked, Cairo.Color color, CairoCorners corners, bool flat_fill)
        {
            var selection_color     = color;
            var selection_highlight = CairoExtensions.ColorShade(selection_color, 1.24);
            var selection_stroke    = CairoExtensions.ColorShade(selection_color, 0.85);

            selection_highlight.A = 0.5;
            selection_stroke.A    = color.A;
            LinearGradient grad = null;

            if (filled)
            {
                if (flat_fill)
                {
                    cr.SetSourceColor(selection_color);
                }
                else
                {
                    var selection_fill_light = CairoExtensions.ColorShade(selection_color, 1.12);
                    var selection_fill_dark  = selection_color;

                    selection_fill_light.A = color.A;
                    selection_fill_dark.A  = color.A;

                    grad = new LinearGradient(x, y, x, y + height);
                    grad.AddColorStop(0, selection_fill_light);
                    grad.AddColorStop(0.4, selection_fill_dark);
                    grad.AddColorStop(1, selection_fill_light);

                    cr.SetSource(grad);
                }

                CairoExtensions.RoundedRectangle(cr, x, y, width, height, Context.Radius, corners, true);
                cr.Fill();

                if (grad != null)
                {
                    grad.Dispose();
                }
            }

            if (filled && stroked)
            {
                cr.LineWidth = 1.0;
                cr.SetSourceColor(selection_highlight);
                CairoExtensions.RoundedRectangle(cr, x + 1.5, y + 1.5, width - 3, height - 3,
                                                 Context.Radius - 1, corners, true);
                cr.Stroke();
            }

            if (stroked)
            {
                cr.LineWidth = 1.0;
                cr.SetSourceColor(selection_stroke);
                CairoExtensions.RoundedRectangle(cr, x + 0.5, y + 0.5, width - 1, height - 1,
                                                 Context.Radius, corners, true);
                cr.Stroke();
            }
        }
Пример #2
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 ();
	}
Пример #3
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();
        }
Пример #4
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();
        }
Пример #5
0
        void DrawButtonTabs(Cairo.Context cr, Cairo.Rectangle rectangle)
        {
            if (IsSeparator)
            {
                cr.NewPath();
                double x = Math.Ceiling(rectangle.X + rectangle.Width / 2) + 0.5;
                cr.MoveTo(x, rectangle.Y + 0.5 + 2);
                cr.RelLineTo(0, rectangle.Height - 1 - 4);
                cr.ClosePath();
                cr.Color     = (HslColor)parent.Style.Dark(StateType.Normal);
                cr.LineWidth = 1;
                cr.Stroke();
                return;
            }

            int topPadding = 2;

            if (Active || HoverPosition.X >= 0)
            {
                cr.NewPath();
                cr.Rectangle(rectangle.X + 0.5, rectangle.Y + 0.5 + topPadding, rectangle.Width - 1, rectangle.Height - topPadding);
                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.Dark(StateType.Normal);
                    color.L *= 1.1;
                    gradient.AddColorStop(0, color);
                    color.L *= 1.1;
                    gradient.AddColorStop(1, color);
                    cr.Pattern = gradient;
                }
                if (!Active)
                {
                    cr.Fill();
                }
                else
                {
                    cr.FillPreserve();
                    cr.Color     = (HslColor)parent.Style.Dark(StateType.Normal);
                    cr.LineWidth = 1;
                    cr.Stroke();
                }
            }

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

            cr.ShowLayout(layout);

            cr.Restore();
        }
Пример #6
0
        protected override bool OnExposeEvent(EventExpose evnt)
        {
            using (Cairo.Context ctx = CairoHelper.Create(evnt.Window)) {
                int dx = (int)((double)Allocation.Width * dividerPosition);
                ctx.LineWidth = 1;
                ctx.Rectangle(0, 0, dx, Allocation.Height);
                ctx.SetSourceColor(LabelBackgroundColor);
                ctx.Fill();
                ctx.Rectangle(dx, 0, Allocation.Width - dx, Allocation.Height);
                ctx.SetSourceRGB(1, 1, 1);
                ctx.Fill();

                if (PropertyContentRightPadding > 0)
                {
                    ctx.Rectangle(Allocation.Width - PropertyContentRightPadding, 0, PropertyContentRightPadding, Allocation.Height);
                    ctx.SetSourceColor(LabelBackgroundColor);
                    ctx.Fill();

                    ctx.MoveTo(Allocation.Width - PropertyContentRightPadding + 0.5, 0);
                    ctx.RelLineTo(0, Allocation.Height);
                    ctx.SetSourceColor(DividerColor);
                    ctx.Stroke();
                }

                ctx.MoveTo(dx + 0.5, 0);
                ctx.RelLineTo(0, Allocation.Height);
                ctx.SetSourceColor(DividerColor);
                ctx.Stroke();

                int y = 0;
                Draw(ctx, rows, dx, PropertyLeftPadding, ref y);
            }
            return(base.OnExposeEvent(evnt));
        }
Пример #7
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();
     }
 }
Пример #8
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();
    }
Пример #9
0
        protected void DrawHoverAndSelection(Cairo.Context cr)
        {
            cr.Save();

            cr.Translate(XOffset, YOffset);
            cr.Scale(Scale, Scale);

            if (Hoverable && hoveringIndex != -1)
            {
                Cairo.Rectangle rect = GetTileRectSansPadding(HoveringX, HoveringY, scale: false, offset: false);
                cr.NewPath();
                cr.SetSourceColor(HoverColor);
                cr.Rectangle(new Cairo.Rectangle(rect.X + 0.5, rect.Y + 0.5, rect.Width - 1, rect.Height - 1));
                cr.LineWidth = 1;
                cr.LineJoin  = LineJoin.Bevel;
                cr.Stroke();
            }

            if (Selectable)
            {
                var rect = GetTileRectSansPadding(SelectedX, SelectedY, scale: false, offset: false);

                if (IsInBounds((int)rect.X, (int)rect.Y, scale: false, offset: false))
                {
                    cr.NewPath();
                    cr.SetSourceColor(SelectionColor);
                    cr.Rectangle(rect.X + 0.5, rect.Y + 0.5, rect.Width - 1, rect.Height - 1);
                    cr.LineWidth = 1;
                    cr.Stroke();
                }
            }

            cr.Restore();
        }
Пример #10
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;
        }
Пример #11
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();
    }
Пример #12
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;
        }
Пример #13
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.
                }
            }
        }
        protected void DrawSmallCovers(Cairo.Context context, float width, float height, double lwidth)
        {
            context.Save();

            double hlwidth = lwidth * 0.5;

            context.MoveTo(hlwidth, height - hlwidth);
            context.LineTo(hlwidth, 0.3 * (height - lwidth));
            context.LineTo((width - lwidth) * 0.65, hlwidth);
            context.LineTo((width - lwidth) * 0.65, 0.7 * (height - lwidth));
            context.ClosePath();
            context.LineWidth = lwidth;
            context.SetSourceRGBA(0.1, 0.1, 0.1, 1.0);
            context.FillPreserve();
            context.SetSourceRGBA(1.0, 1.0, 1.0, 0.7);
            context.Stroke();
            context.Translate((4 + hlwidth), 0);
            context.MoveTo(hlwidth, height - hlwidth);
            context.LineTo(hlwidth, 0.3 * (height - lwidth));
            context.LineTo((width - lwidth) * 0.65, hlwidth);
            context.LineTo((width - lwidth) * 0.65, 0.7 * (height - lwidth));
            context.ClosePath();
            context.SetSourceRGBA(0.1, 0.1, 0.1, 1.0);
            context.FillPreserve();
            context.SetSourceRGBA(1.0, 1.0, 1.0, 0.7);
            context.Stroke();
            context.Translate(-(4 + hlwidth), 0);

            context.Restore();
        }
Пример #15
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();
             }
         }
     }
 }
Пример #16
0
        public void Draw(Cairo.Context cr, Cairo.Rectangle rectangle)
        {
            if (IsSeparator)
            {
                cr.NewPath();
                double x = Math.Ceiling(rectangle.X + rectangle.Width / 2) + 0.5;
                cr.MoveTo(x, rectangle.Y + 0.5 + 2);
                cr.RelLineTo(0, rectangle.Height - 1 - 4);
                cr.ClosePath();
                cr.SetSourceColor(parent.Style.Dark(StateType.Normal).ToCairoColor());
                cr.LineWidth = 1;
                cr.Stroke();
                return;
            }

            if (Active || HoverPosition.X >= 0)
            {
                if (Active)
                {
                    cr.Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
                    using (var gr = new LinearGradient(rectangle.X, rectangle.Y, rectangle.X, rectangle.Y + rectangle.Height)) {
                        gr.AddColorStop(0, Tabstrip.ActiveGradientStart);
                        gr.AddColorStop(1, Tabstrip.ActiveGradientEnd);
                        cr.SetSource(gr);
                    }
                    cr.Fill();
                    cr.Rectangle(rectangle.X + 0.5, rectangle.Y + 0.5, rectangle.Width - 1, rectangle.Height - 1);
                    cr.SetSourceRGBA(1, 1, 1, 0.05);
                    cr.LineWidth = 1;
                    cr.Stroke();
                }
                else if (HoverPosition.X >= 0)
                {
                    cr.Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
                    using (var gr = new LinearGradient(rectangle.X, rectangle.Y, rectangle.X, rectangle.Y + rectangle.Height)) {
                        var c1 = Tabstrip.ActiveGradientStart;
                        var c2 = Tabstrip.ActiveGradientEnd;
                        c1.A = 0.2;
                        c2.A = 0.2;
                        gr.AddColorStop(0, c1);
                        gr.AddColorStop(1, c2);
                        cr.SetSource(gr);
                    }
                    cr.Fill();
                }
            }

            if (Active)
            {
                cr.SetSourceRGB(1, 1, 1);
            }
            else
            {
                cr.SetSourceColor(parent.Style.Text(StateType.Normal).ToCairoColor());
            }

            cr.MoveTo(rectangle.X + (rectangle.Width - w) / 2, (rectangle.Height - h) / 2);
            Pango.CairoHelper.ShowLayout(cr, layout);
        }
Пример #17
0
 public void DrawLine(double x1, double y1, double x2, double y2, double thickness, Cairo.Color color)
 {
     cairoContext.LineWidth = thickness * drawingScaleX;
     cairoContext.Antialias = Antialias.None;
     cairoContext.MoveTo(x1 * drawingScaleX, y1 * drawingScaleY);
     cairoContext.LineTo(x2 * drawingScaleX, y2 * drawingScaleY);
     cairoContext.Color = color;
     cairoContext.Stroke();
 }
Пример #18
0
        public static void RenderThumbnail(Cairo.Context cr, ImageSurface image, bool dispose,
                                           double x, double y, double width, double height, bool drawBorder, double radius,
                                           bool fill, Color fillColor, CairoCorners corners)
        {
            if (image == null || image.Handle == IntPtr.Zero)
            {
                return;
            }

            double p_x = x;
            double p_y = y;

            p_x += image.Width < width ? (width - image.Width) / 2 : 0;
            p_y += image.Height < height ? (height - image.Height) / 2 : 0;

            cr.Antialias = Cairo.Antialias.Default;

            if (fill)
            {
                cr.Rectangle(x, y, width, height);
                cr.Color = fillColor;
                cr.Fill();
            }

            CairoExtensions.RoundedRectangle(cr, p_x, p_y, image.Width, image.Height, radius, corners);
            cr.SetSource(image, p_x, p_y);
            cr.Fill();

            if (!drawBorder)
            {
                if (dispose)
                {
                    ((IDisposable)image).Dispose();
                }

                return;
            }

            cr.LineWidth = 1.0;
            if (radius < 1)
            {
                cr.Antialias = Antialias.None;

                CairoExtensions.RoundedRectangle(cr, x + 1.5, y + 1.5, width - 3, height - 3, radius, corners);
                cr.Color = cover_border_light_color;
                cr.Stroke();
            }

            CairoExtensions.RoundedRectangle(cr, x + 0.5, y + 0.5, width - 1, height - 1, radius, corners);
            cr.Color = cover_border_dark_color;
            cr.Stroke();

            if (dispose)
            {
                ((IDisposable)image).Dispose();
            }
        }
        void DrawBuildEffect(Cairo.Context context, Gdk.Rectangle area, double progress, double opacity)
        {
            context.Save();
            LayoutRoundedRectangle(context, area);
            context.Clip();

            Gdk.Point center = new Gdk.Point(area.Left + 19, (area.Top + area.Bottom) / 2);
            context.Translate(center.X, center.Y);
            var circles = new [] {
                new { Radius = 200, Thickness = 12, Speed = 1, ArcLength = Math.PI * 1.50 },
                new { Radius = 195, Thickness = 15, Speed = 2, ArcLength = Math.PI * 0.50 },
                new { Radius = 160, Thickness = 17, Speed = 3, ArcLength = Math.PI * 0.75 },
                new { Radius = 200, Thickness = 15, Speed = 2, ArcLength = Math.PI * 0.25 },
                new { Radius = 240, Thickness = 12, Speed = 3, ArcLength = Math.PI * 1.50 },
                new { Radius = 160, Thickness = 17, Speed = 3, ArcLength = Math.PI * 0.75 },
                new { Radius = 200, Thickness = 15, Speed = 2, ArcLength = Math.PI * 0.25 },
                new { Radius = 215, Thickness = 20, Speed = 2, ArcLength = Math.PI * 1.25 }
            };

            double zmod  = 1.0d;
            double zporg = progress;

            foreach (var arc in circles)
            {
                double zoom = 1.0d;
                zoom = (double)Math.Sin(zporg * Math.PI * 2 + zmod);
                zoom = ((zoom + 1) / 6.0d) + .05d;

                context.Rotate(Math.PI * 2 * progress * arc.Speed);
                context.MoveTo(arc.Radius * zoom, 0);
                context.Arc(0, 0, arc.Radius * zoom, 0, arc.ArcLength);
                context.LineWidth = arc.Thickness * zoom;
                context.SetSourceColor(CairoExtensions.ParseColor("B1DDED", 0.35 * opacity));
                context.Stroke();
                context.Rotate(Math.PI * 2 * -progress * arc.Speed);

                progress = -progress;

                context.Rotate(Math.PI * 2 * progress * arc.Speed);
                context.MoveTo(arc.Radius * zoom, 0);
                context.Arc(0, 0, arc.Radius * zoom, 0, arc.ArcLength);
                context.LineWidth = arc.Thickness * zoom;
                context.Stroke();
                context.Rotate(Math.PI * 2 * -progress * arc.Speed);

                progress = -progress;

                zmod += (float)Math.PI / circles.Length;
            }

            context.LineWidth = 1;
            context.ResetClip();
            context.Restore();
        }
Пример #20
0
        public void DrawLine(Coordinate a, Coordinate b)
        {
            var pt1 = ToCairoPoint(a);
            var pt2 = ToCairoPoint(b);

            context.LineWidth = 1.0;
            context.SetSourceColor(currentLineColor);
            context.MoveTo(pt1);
            context.LineTo(pt2);
            context.Stroke();
        }
Пример #21
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();
        }
        protected virtual void DrawBackground(Cairo.Context context, Gdk.Rectangle region)
        {
            LayoutRoundedRectangle(context, region);
            context.ClipPreserve();

            using (LinearGradient lg = new LinearGradient(region.X, region.Y, region.X, region.Y + region.Height)) {
                lg.AddColorStop(0, Styles.StatusBarFill1Color);
                lg.AddColorStop(1, Styles.StatusBarFill4Color);

                context.SetSource(lg);
                context.FillPreserve();
            }

            context.Save();
            double midX = region.X + region.Width / 2.0;
            double midY = region.Y + region.Height;

            context.Translate(midX, midY);

            using (RadialGradient rg = new RadialGradient(0, 0, 0, 0, 0, region.Height * 1.2)) {
                rg.AddColorStop(0, Styles.StatusBarFill1Color);
                rg.AddColorStop(1, Styles.WithAlpha(Styles.StatusBarFill1Color, 0));

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

            using (LinearGradient lg = new LinearGradient(0, region.Y, 0, region.Y + region.Height)) {
                lg.AddColorStop(0, Styles.StatusBarShadowColor1);
                lg.AddColorStop(1, Styles.WithAlpha(Styles.StatusBarShadowColor1, Styles.StatusBarShadowColor1.A * 0.2));

                LayoutRoundedRectangle(context, region, 0, -1);
                context.LineWidth = 1;
                context.SetSource(lg);
                context.Stroke();
            }

            using (LinearGradient lg = new LinearGradient(0, region.Y, 0, region.Y + region.Height)) {
                lg.AddColorStop(0, Styles.StatusBarShadowColor2);
                lg.AddColorStop(1, Styles.WithAlpha(Styles.StatusBarShadowColor2, Styles.StatusBarShadowColor2.A * 0.2));

                LayoutRoundedRectangle(context, region, 0, -2);
                context.LineWidth = 1;
                context.SetSource(lg);
                context.Stroke();
            }

            context.ResetClip();
        }
Пример #23
0
        protected override bool OnDrawn(Cairo.Context cr)
        {
            if (this.isDirty)
            {
                this.Rebuild();
            }

            bool baseDrawnResult = base.OnDrawn(cr);

            cr.SetFontSize(FONT_HEIGHT);
            cr.SelectFontFace("Mono", FontSlant.Normal, FontWeight.Normal);

            cr.Rectangle(0.0, 0.0, this.allocRect.Width, this.allocRect.Height);
            cr.SetSourceRGB(1, 1, 1);
            cr.Fill();

            var gradient = new LinearGradient(0.0, 0.0, 0.0, this.allocRect.Height);

            gradient.AddColorStopRgb(0.0, new Color(0.4, 0.4, 0.4));
            gradient.AddColorStopRgb(0.1, new Color(1.0, 1.0, 1.0));
            gradient.AddColorStopRgb(0.2, new Color(0.6, 0.6, 0.6));
            gradient.AddColorStopRgb(1.0, new Color(0.1, 0.1, 0.1));

            cr.LineWidth = 1;

            foreach (var box in this.boxen)
            {
                this.RoundedRect(cr, box.Rect, 4.0);
                cr.SetSource(gradient);
                cr.FillPreserve();
                cr.SetSourceRGB(0, 0, 0);
                cr.Stroke();


                int x = (int)(box.Rect.X + TAGBOX_PADDING * 2 + TAGBOX_XSIZE);
                int y = (int)(box.Rect.Y + box.Rect.Height / 2 + cr.FontExtents.Height / 2 - cr.FontExtents.Descent / 2);
                cr.MoveTo(x, y);
                cr.TextPath(box.Tag);
                cr.SetSourceRGB(1.0, 1.0, 1.0);
                cr.Fill();

                cr.MoveTo(box.Rect.X + TAGBOX_PADDING + TAGBOX_XOFFSET, box.Rect.Y + TAGBOX_PADDING + TAGBOX_XOFFSET);
                cr.RelLineTo(TAGBOX_XSIZE - TAGBOX_XOFFSET * 2, TAGBOX_XSIZE - TAGBOX_XOFFSET * 2);
                cr.MoveTo(box.Rect.X + TAGBOX_PADDING + TAGBOX_XOFFSET, box.Rect.Y + TAGBOX_PADDING + TAGBOX_XSIZE - TAGBOX_XOFFSET);
                cr.RelLineTo(TAGBOX_XSIZE - TAGBOX_XOFFSET * 2, -TAGBOX_XSIZE + TAGBOX_XOFFSET * 2);
                cr.Stroke();
            }

            return(baseDrawnResult);
        }
Пример #24
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);
        }
Пример #25
0
        void RenderButton(Cairo.Context context, Gdk.Point corner, double opacity, bool hovered)
        {
            Gdk.Rectangle region = new Gdk.Rectangle(corner.X,
                                                     corner.Y,
                                                     ButtonSize.Width, ButtonSize.Height);



            context.RoundedRectangle(region.X + 0.5, region.Y + 0.5, region.Width - 1, region.Height - 1, 3);
            using (var lg = new LinearGradient(0, region.Top, 0, region.Bottom)) {
                if (hovered)
                {
                    lg.AddColorStop(0, new Cairo.Color(.15, .76, .09, opacity));
                    lg.AddColorStop(1, new Cairo.Color(.41, .91, .46, opacity));
                }
                else
                {
                    lg.AddColorStop(0, new Cairo.Color(.41, .91, .46, opacity));
                    lg.AddColorStop(1, new Cairo.Color(.15, .76, .09, opacity));
                }

                context.SetSource(lg);
                context.FillPreserve();
            }

            context.SetSourceRGBA(.29, .79, .28, opacity);
            context.LineWidth = 1;
            context.Stroke();

            region.Inflate(-1, -1);
            context.RoundedRectangle(region.X + 0.5, region.Y + 0.5, region.Width - 1, region.Height - 1, 2);

            using (var lg = new LinearGradient(0, region.Top, 0, region.Bottom)) {
                lg.AddColorStop(0, new Cairo.Color(1, 1, 1, .74 * opacity));
                lg.AddColorStop(0.1, new Cairo.Color(1, 1, 1, 0));
                lg.AddColorStop(0.9, new Cairo.Color(0, 0, 0, 0));
                lg.AddColorStop(1, new Cairo.Color(0, 0, 0, .34 * opacity));

                context.SetSource(lg);
                context.Stroke();
            }

            using (var layout = ButtonLayout(PangoContext)) {
                int w, h;
                layout.GetPixelSize(out w, out h);

                RenderShadowedText(context, new Gdk.Point(corner.X + ButtonSize.Width / 2 - w / 2, corner.Y + ButtonSize.Height / 2 - h / 2 - 1), opacity, layout);
            }
        }
Пример #26
0
        public void DrawFooterBackground(Cairo.Context cr, Gdk.Rectangle alloc, int top_offset, bool fill)
        {
            Color gtk_background_color = GetWidgetColor(GtkColorClass.Background, StateType.Normal);
            Color gtk_base_color       = GetWidgetColor(GtkColorClass.Base, StateType.Normal);
            Color light_color          = gtk_background_color.ColorShade(1.1);
            Color dark_color           = gtk_background_color.ColorShade(0.95);

            const CairoCorners corners = CairoCorners.BottomLeft | CairoCorners.BottomRight;

            if (fill)
            {
                LinearGradient grad = new LinearGradient(alloc.X, alloc.Y, alloc.X, alloc.Y + alloc.Height);
                grad.AddColorStop(0, light_color);
                grad.AddColorStop(0.75, dark_color);
                grad.AddColorStop(0, light_color);

                cr.Pattern = grad;
                cr.RoundedRectangle(alloc.X, alloc.Y + top_offset, alloc.Width, alloc.Height - top_offset, BORDER_RADIUS, corners);
                cr.Fill();

                cr.Color = gtk_base_color;
                cr.Rectangle(alloc.X, alloc.Y, alloc.Width, top_offset);
                cr.Fill();
            }
            else
            {
                cr.Color = gtk_base_color;
                cr.RoundedRectangle(alloc.X, alloc.Y, alloc.Width, alloc.Height, BORDER_RADIUS, corners);
                cr.Fill();
            }

            cr.LineWidth = 1.0;
            cr.Translate(alloc.Y + 0.5, alloc.Y - 0.5);

            cr.Color = border_color;
            cr.RoundedRectangle(alloc.X, alloc.Y - 4, alloc.Width - 1, alloc.Height + 4, BORDER_RADIUS, corners);
            cr.Stroke();

            if (fill)
            {
                cr.LineWidth = 1;
                cr.Antialias = Cairo.Antialias.None;
                cr.MoveTo(alloc.X + 1, alloc.Y + 1 + top_offset);
                cr.LineTo(alloc.X + alloc.Width - 1, alloc.Y + 1 + top_offset);
                cr.Stroke();
                cr.Antialias = Cairo.Antialias.Default;
            }
        }
Пример #27
0
        private void DrawEdge(Cairo.Context cx, NodeVisualization _from, NodeVisualization _to)
        {
            int beginX = _from.X + _from.Width / 2;
            int beginY = _from.Y + _from.Height / 2;
            int endX   = _to.X + _to.Width / 2;
            int endY   = _to.Y + _to.Height / 2;

            cx.Antialias = Antialias.Gray;
            cx.LineWidth = 3;
            if (!_from.successors.ContainsKey(_to) || _from.successors[_to] == false)
            {
                cx.SetSourceColor(new Color(0, 0, 0, 1));
            }
            else
            {
                cx.SetSourceColor(new Color(0, 0.8, 0, 1));
            }

            cx.LineCap = LineCap.Round;
            cx.MoveTo(beginX, beginY);
            cx.LineTo(endX, endY);
            cx.Stroke();

            int tipX = ((2 * endX) + beginX) / 3;
            int tipY = ((2 * endY) + beginY) / 3;

            int arrowLength = 10;             //can be adjusted
            int dx          = endX - beginX;
            int dy          = endY - beginY;

            double theta = Math.Atan2(dy, dx);

            double rad = 35 * Math.PI / 180;         //35 angle
            double x   = tipX - arrowLength * Math.Cos(theta + rad);
            double y   = tipY - arrowLength * Math.Sin(theta + rad);

            double phi2 = -35 * Math.PI / 180;        //-35 angle
            double x2   = tipX - arrowLength * Math.Cos(theta + phi2);
            double y2   = tipY - arrowLength * Math.Sin(theta + phi2);

            cx.MoveTo(tipX, tipY);
            cx.LineTo(x, y);
            cx.Stroke();

            cx.MoveTo(tipX, tipY);
            cx.LineTo(x2, y2);
            cx.Stroke();
        }
Пример #28
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();
    }
Пример #29
0
 public virtual void Draw(Context cr, Gdk.Rectangle clip)
 {
     cr.Rectangle(clip.X, clip.Y, clip.Width, clip.Height);
     cr.Color = BackgroundColor;
     cr.Fill();
     cr.Stroke();
 }
Пример #30
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);
  }
Пример #31
0
        public override void Apply (CanvasItem item, Context cr)
        {
            int steps = ShadowSize;
            double opacity_step = ShadowOpacity / ShadowSize;
            Color color = new Color (0, 0, 0);

            double width = Math.Round (item.Allocation.Width);
            double height = Math.Round (item.Allocation.Height);

            if (Fill != null) {
                cr.Rectangle (shadow_size, shadow_size, width - ShadowSize * 2, height - ShadowSize * 2);
                Fill.Apply (cr);
                cr.Fill ();
            }

            cr.LineWidth = 1.0;

            for (int i = 0; i < steps; i++) {
                CairoExtensions.RoundedRectangle (cr,
                    i + 0.5,
                    i + 0.5,
                    (width - 2 * i) - 1,
                    (height - 2 * i) - 1,
                    steps - i);

                color.A = opacity_step * (i + 1);
                cr.Color = color;
                cr.Stroke ();
            }
        }
Пример #32
0
        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 ();
        }
            void DrawFoldSegment(Cairo.Context ctx, double x, double y, bool isOpen, bool isSelected)
            {
                var drawArea = new Cairo.Rectangle(System.Math.Floor(x + (Margin.Width - foldSegmentSize) / 2) + 0.5,
                                                   System.Math.Floor(y + (Editor.LineHeight - foldSegmentSize) / 2) + 0.5, foldSegmentSize, foldSegmentSize);

                ctx.Rectangle(drawArea);
                ctx.SetSourceColor(isOpen ? foldBgGC : foldToggleMarkerBackground);
                ctx.FillPreserve();
                ctx.SetSourceColor(isSelected ? foldLineHighlightedGC : foldLineGC);
                ctx.Stroke();

                ctx.DrawLine(isSelected ? foldLineHighlightedGC : foldToggleMarkerGC,
                             drawArea.X + drawArea.Width * 2 / 10,
                             drawArea.Y + drawArea.Height / 2,
                             drawArea.X + drawArea.Width - drawArea.Width * 2 / 10,
                             drawArea.Y + drawArea.Height / 2);

                if (!isOpen)
                {
                    ctx.DrawLine(isSelected ? foldLineHighlightedGC : foldToggleMarkerGC,
                                 drawArea.X + drawArea.Width / 2,
                                 drawArea.Y + drawArea.Height * 2 / 10,
                                 drawArea.X + drawArea.Width / 2,
                                 drawArea.Y + drawArea.Height - drawArea.Height * 2 / 10);
                }
            }
Пример #34
0
 public override void Run()
 {
     ICollection<double> chapters = this.Theory.Chapters;
     StripCanvasSize scs = this.Manager.GenerateStripCanvasSize (chapters.Count);
     double dw = scs.CanvasSize.Width;
     double dh = scs.CanvasSize.Height;
     using (PdfSurface surface = new PdfSurface (this.Manager.OutputFile, scs.TotalWidth, scs.TotalHeight)) {
         using (Context ctx = new Context (surface)) {
             int index = 0x00;
             IPoint3 p;
             foreach (double chapter in chapters) {
                 p = scs.GetCanvasOffset (index);
                 ctx.Save ();
                 ctx.Translate (p.X, p.Y);
                 ctx.Rectangle (0.0d, 0.0d, dw, dh);
                 ctx.Stroke ();
                 this.Theory.Time = chapter;
                 CairoEngine engine = new CairoEngine (this.Theory);
                 engine.Context = ctx;
                 engine.Process ();
                 ctx.Restore ();
                 index++;
             }
         }
     }
 }
Пример #35
0
        private void DrawOutputndicator(Cairo.Context context)
        {
            context.Save();
            RelativeLocator locator = new RelativeLocator(-0.04, 1.2);
            PointD          point   = locator.Locate(this);

            context.MoveTo(point);
            context.LineCap = LineCap.Round;
            context.Color   = s_ioIndicatorColor;

            double l = 4;   //arm lenght of indicator icon
            double s = 0.4; //spacing between arms in the indicator icon

            //draw <<
            //up
            context.RelLineTo(new Distance(-s, -l));
            context.RelMoveTo(new Distance(s, l));   //back

            //right
            context.RelLineTo(new Distance(l, s));
            context.RelMoveTo(new Distance(-l, -s));   //back

            context.RelMoveTo(new Distance(3, -3));

            //repeat above for second arrow
            context.RelLineTo(new Distance(-s, -l));
            context.RelMoveTo(new Distance(s, l));   //back
            context.RelLineTo(new Distance(l, s));
            context.RelMoveTo(new Distance(-l, -s)); //back

            context.Stroke();

            context.Restore();
        }
Пример #36
0
 public override void DrawRowCursor(Cairo.Context cr, int x, int y, int width, int height, Cairo.Color color, CairoCorners corners)
 {
     cr.LineWidth = 1.25;
     cr.SetSourceColor(color);
     CairoExtensions.RoundedRectangle(cr, x + cr.LineWidth / 2.0, y + cr.LineWidth / 2.0, width - cr.LineWidth, height - cr.LineWidth, Context.Radius, corners, true);
     cr.Stroke();
 }
Пример #37
0
        public void Draw(Cairo.Context g, double scale, bool fillSelection)
        {
            g.Save();
            g.Translate(0.5, 0.5);
            g.Scale(scale, scale);

            g.AppendPath(selection_path);

            if (fillSelection)
            {
                g.Color    = new Cairo.Color(0.7, 0.8, 0.9, 0.2);
                g.FillRule = Cairo.FillRule.EvenOdd;
                g.FillPreserve();
            }

            g.LineWidth = 1 / scale;

            // Draw a white line first so it shows up on dark backgrounds
            g.Color = new Cairo.Color(1, 1, 1);
            g.StrokePreserve();

            // Draw a black dashed line over the white line
            g.SetDash(new double[] { 2 / scale, 4 / scale }, 0);
            g.Color = new Cairo.Color(0, 0, 0);

            g.Stroke();
            g.Restore();
        }
Пример #38
0
        public void Draw(Gdk.Drawable d)
        {
            if (!Visible)
            {
                return;
            }

            Gdk.GC        gc = new Gdk.GC(d);
            Cairo.Context g  = Gdk.CairoHelper.Create(d);

            d.DrawPixbuf(gc, _background, 0, 0, _x, _y, _w, _h, Gdk.RgbDither.None, 0, 0);

            int x0 = _x, x1 = _x + _w;
            int y0 = _y, y1 = _y + _h;

            g.MoveTo(x0 + 3, y0);
            g.LineTo(x1 - 3, y0);
            g.LineTo(x1, y0 + 3);
            g.LineTo(x1, y1 - 3);
            g.LineTo(x1 - 3, y1);
            g.LineTo(x0 + 3, y1);
            g.LineTo(x0, y1 - 3);
            g.LineTo(x0, y0 + 3);
            g.LineTo(x0 + 3, y0);
            g.ClosePath();
            g.LineWidth = 6;
            g.Color     = new Color(0.8, 0.8, 0.8, _opaque ? 1 : 0.6);
            g.Stroke();

            ((IDisposable)g.Target).Dispose();
            ((IDisposable)g).Dispose();

            DrawContents(d);
        }
Пример #39
0
 //Original function which draws a straight line from start to end
 void DrawLine(Cairo.Context ctx, PointD start, PointD end)
 {
     ctx.SetSourceRGBA(R, G, B, A);
     ctx.MoveTo(start);
     ctx.LineTo(end);
     ctx.Stroke();
 }
Пример #40
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 );
                    }
                }

            }

        }
    }
Пример #41
0
        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();
            }
        }
Пример #42
0
		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();
		}
		public override void BasicDraw (Context context) {
			RectangleD displayBox = DisplayBox;

			context.LineWidth = LineWidth;
			context.Save ();
			displayBox.OffsetDot5 ();
			context.Rectangle (GdkCairoHelper.CairoRectangle(displayBox));
			context.Restore ();
			context.Color = FillColor;
			context.FillPreserve ();
			context.Color = LineColor;
			context.Stroke ();
		}
Пример #44
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();
		}
Пример #45
0
 public override void BasicDrawSelected(Context context)
 {
     if (Text != "") {
         return;
     }
     context.LineWidth = LineWidth;
     Color c = LineColor;
     c.A = 0.5;
     context.Color = c;
     RectangleD r = DisplayBox;
     r.OffsetDot5();
     context.Rectangle(GdkCairoHelper.CairoRectangle(r));
     context.Stroke();
 }
		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 ();
		}
Пример #47
0
        public override void Draw(Context context)
        {
            double middle = DisplayBox.Width / 2.0;

            context.LineWidth = LineWidth;
            context.Save ();
            context.Translate (DisplayBox.X + middle, DisplayBox.Y + middle);
            context.Arc (0.0, 0.0, middle, 0.0, 2.0 * Math.PI);
            context.Restore ();
            context.Color = new Cairo.Color (1.0, 1.0, 0.2, 0.2);
            context.FillPreserve ();
            context.Color = new Cairo.Color (0.0, 0.0, 0.0, 1.0);
            context.Stroke ();
        }
Пример #48
0
		public override void BasicDraw (Context context) {
			double midwidth  = DisplayBox.Width / 2.0;
			double midheight = DisplayBox.Height / 2.0;

			context.LineWidth = LineWidth;
			context.Save ();
			context.Translate (DisplayBox.X + midwidth, DisplayBox.Y + midheight);
			context.Scale (midwidth - 1.0, midheight - 1.0);
			context.Arc (0.0, 0.0, 1.0, 0.0, 2.0 * Math.PI);
			context.Restore ();
			context.Color = FillColor;
			context.FillPreserve ();
			context.Color = LineColor;
			context.Stroke ();
		}
		public override void Draw (Context context, IDrawingView view) {
			RectangleD rect = ViewDisplayBox(view);
			
			double middle = rect.Width / 2.0;

			context.LineWidth = LineWidth;
			context.Save ();
			context.Translate (rect.X + middle, rect.Y + middle);
			context.Arc (0.0, 0.0, middle, 0.0, 2.0 * Math.PI);
			context.Restore ();
			context.Color = new Cairo.Color (0.2, 0.2, 1.0, 0.5);
			context.FillPreserve ();
			context.Color = new Cairo.Color (0.0, 0.0, 0.0, 1.0);
			context.Stroke ();
		}
		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 ();
		}
		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;
		}
Пример #52
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;
 }
Пример #53
0
        public override void Render(Node node, Context context)
        {
            ButtonNode button = node as ButtonNode;

            context.RoundedRectangle (0.5, 0.5, button.Width - 1, button.Height - 1, button.Rounding);
            if (button.Relief) {
                using (var lg = new global::Cairo.LinearGradient (0, 0, 0, button.Height)) {
                    CreateGradient (lg, button.State, button.Opacity);
                    context.Pattern = lg;
                    context.FillPreserve ();
                }

                context.LineWidth = 1;
                context.Color = new Color (0.8, 0.8, 0.8, button.Opacity).ToCairo ();
                context.Stroke ();
            }
        }
Пример #54
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));
 }
Пример #55
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();
		}
Пример #56
0
		public static void Draw (Context grw, ArcElement arc)
		{
			if (arc.Foregraund != null) {
				grw.SetSourceRGB (
					arc.Foregraund.Red, 
					arc.Foregraund.Green, 
					arc.Foregraund.Blue);
			}

			grw.Arc (
				arc.Center.GeometryX, 
				arc.Center.GeometryY, 
				arc.GeometryRadius, 
				arc.ArcStart, 
				arc.ArcStop);

			grw.Stroke ();
		}
Пример #57
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);
        }
Пример #58
0
        public static Gtk.Image create_big_starred_image(string pic_path)
        {
            using (Cairo.ImageSurface img_surface = new ImageSurface(pic_path)) {
                using (Cairo.ImageSurface surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, img_surface.Width + 2, img_surface.Height + 2)) {
                    using (Cairo.Context context = new Context(surface)) {
                        Gdk.Pixbuf tmp_pixbuf = new Gdk.Pixbuf(pic_path);
                        if (!tmp_pixbuf.HasAlpha) { // img_surface.Format not available...
                            context.Rectangle(0, 0, img_surface.Width+2, img_surface.Height+2);
                            context.Fill();
                            context.Stroke();
                        }

                        context.SetSource(img_surface, 1, 1);
                        context.Paint();

                        // evil hack because the interface to cairo is pretty bad

                        Assembly asm = Assembly.GetCallingAssembly();

                        Stream s = asm.GetManifestResourceStream("big_star.png");

                        FileStream fs = new System.IO.FileStream(tmp_image_path, FileMode.Create);

                        for (int i = 0; i < s.Length; ++i)
                            fs.WriteByte((byte)s.ReadByte());

                        fs.Close();

                        using (Cairo.ImageSurface star_surface = new ImageSurface(tmp_image_path)) {
                            System.IO.File.Delete(tmp_image_path);

                            context.SetSource(star_surface, img_surface.Width-star_surface.Width, img_surface.Height-star_surface.Height);
                            context.Paint();

                            surface.WriteToPng(tmp_image_path);
                            Gtk.Image img = new Gtk.Image(tmp_image_path);
                            System.IO.File.Delete(tmp_image_path);
                            return img;
                        }
                    }
                }
            }
        }
Пример #59
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 d = Math.Sqrt (dx * dx + dy * dy) * 2.0;

			double cx = Math.Floor (x / 100.0) * 100 + 50;
			double cy = Math.Floor (y / 100.0) * 100 + 50;

			int steps = Random.Next (1, 10);
			double step_delta = d / steps;

			for (int i = 0; i < steps; i++) {
				g.Arc (cx, cy, (steps - i) * step_delta, 0, Math.PI * 2);
				g.Stroke ();
			}

			return Gdk.Rectangle.Zero;
		}
Пример #60
0
		protected override Gdk.Rectangle OnMouseMove (Context g, Color strokeColor, ImageSurface surface,
		                                              int x, int y, int lastX, int lastY)
		{
			double cx = Math.Round (x / 100.0) * 100.0;
			double cy = Math.Round (y / 100.0) * 100.0;
			double dx = (cx - x) * 10.0;
			double dy = (cy - y) * 10.0;

			for (int i = 0; i < 50; i++) {
				g.MoveTo (cx, cy);
				g.QuadraticCurveTo (
					x + Random.NextDouble () * dx,
					y + Random.NextDouble () * dy,
					cx,
					cy);
				g.Stroke ();
			}

			return Gdk.Rectangle.Zero;
		}