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

public Scale ( double sx, double sy ) : void
sx double
sy double
Результат void
Пример #1
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();
    }
Пример #2
0
        protected override bool OnDrawn(Cairo.Context cr)
        {
            base.OnDrawn(cr);

            if (Surface != null)
            {
                cr.SetSourceSurface(Surface, XOffset, YOffset);
                cr.Paint();
            }
            else if (Image != null)
            {
                Bitmap orig = Image;
                using (Surface source = CairoHelper.LockBitmap(orig)) {
                    cr.Scale(Scale, Scale);
                    cr.SetSource(source, XOffset, YOffset);
                    ((SurfacePattern)cr.Source).Filter = Filter.Nearest;
                    cr.Scale(1.0 / Scale, 1.0 / Scale);
                    cr.Paint();
                    CairoHelper.UnlockBitmap(orig);
                }
            }

            if (hoveringIndex != -1)
            {
                cr.NewPath();
                cr.SetSourceColor(HoverColor);
                cr.Rectangle(new Cairo.Rectangle(XOffset + HoveringX * TileWidth * Scale + 0.5, YOffset + HoveringY * TileHeight * Scale + 0.5, ScaledTileWidth - 1, ScaledTileHeight - 1));
                cr.LineWidth = 1;
                cr.LineJoin  = LineJoin.Bevel;
                cr.Stroke();
            }

            return(true);
        }
Пример #3
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);
  }
    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));
    }
Пример #5
0
        public static void ShowAsReflection(this DockySurface self, DockySurface target, PointD point, double zoom,
                                            double rotation, double opacity, double height, DockPosition position)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            Cairo.Context cr = target.Context;

            switch (position)
            {
            case DockPosition.Left:
                point.X -= self.Width * zoom + height;
                break;

            case DockPosition.Top:
                point.Y -= self.Height * zoom + height;
                break;

            case DockPosition.Right:
                point.X += self.Width * zoom + height;
                break;

            case DockPosition.Bottom:
                point.Y += self.Height * zoom + height;
                break;
            }

            double cos, sin;

            cos = Math.Cos(rotation);
            sin = Math.Sin(rotation);
            Matrix m = new Matrix(cos, sin, -sin, cos, point.X, point.Y);

            cr.Transform(m);

            if (zoom != 1)
            {
                cr.Scale(zoom, zoom);
            }

            if (position == DockPosition.Left || position == DockPosition.Right)
            {
                cr.Scale(-1, 1);
            }
            else
            {
                cr.Scale(1, -1);
            }

            cr.SetSource(self.Internal,
                         -self.Width / 2,
                         -self.Height / 2);

            cr.PaintWithAlpha(opacity * .3);

            cr.IdentityMatrix();
        }
Пример #6
0
        protected override void Draw(Context cr, Pixbuf prev, Pixbuf next, int width, int height, double progress)
        {
            cr.Color = new Color (0, 0, 0);
            if (prev != null) {
                double scale = Math.Min ((double)width/(double)prev.Width, (double)height/(double)prev.Height);
                cr.Save ();
                cr.Translate (-progress * width, 0);

                cr.Rectangle (0, 0, width, .5 * (height - scale*prev.Height));
                cr.Fill ();

                cr.Rectangle (0, height - .5 * (height - scale*prev.Height), width, .5 * (height - scale*prev.Height));
                cr.Fill ();

                cr.Rectangle (0, 0, .5 * (width - scale*prev.Width), height);
                cr.Fill ();

                cr.Rectangle (width - .5 * (width - scale*prev.Width), 0, .5 * (width - scale*prev.Width), height);
                cr.Fill ();

                cr.Rectangle (0, 0, width, height);
                cr.Scale (scale, scale);
                CairoHelper.SetSourcePixbuf (cr, prev, .5 * ((double)width/scale - prev.Width), .5 * ((double)height/scale - prev.Height));
                cr.Fill ();
                cr.Restore ();
            }
            if (next != null) {
                double scale = Math.Min ((double)width/(double)next.Width, (double)height/(double)next.Height);
                cr.Save ();
                cr.Translate (width * (1.0 - progress), 0);

                cr.Rectangle (0, 0, width, .5 * (height - scale*next.Height));
                cr.Fill ();

                cr.Rectangle (0, height - .5 * (height - scale*next.Height), width, .5 * (height - scale*next.Height));
                cr.Fill ();

                cr.Rectangle (0, 0, .5 * (width - scale*next.Width), height);
                cr.Fill ();

                cr.Rectangle (width - .5 * (width - scale*next.Width), 0, .5 * (width - scale*next.Width), height);
                cr.Fill ();

                cr.Rectangle (0, 0, width, height);
                cr.Scale (scale, scale);
                CairoHelper.SetSourcePixbuf (cr, next, .5 * ((double)width/scale - next.Width), .5 * ((double)height/scale - next.Height));
                cr.Fill ();
                cr.Restore ();
            }
        }
Пример #7
0
        void UpdateHighlight()
        {
            Gdk.Window win = this.GdkWindow;

            Cairo.Context g = Gdk.CairoHelper.Create(win);

            int x, y, w, h, d;

            win.GetGeometry(out x, out y, out w, out h, out d);

            g.Scale(w, h);
            g.LineWidth = (1.0 / freqs.Length) * 0.6;

            if (previousHighlight != -1)
            {
                /*int start=previousHighlight-1;
                 * int end=previousHighlight+1;
                 * if (start<0) start=0;
                 * if (end>=barStart.Length) end=barStart.Length-1;*/
                g.Color = new Color(0.0, 0.0, 0.0);
                //for(int i=start; i<=end; i++)
                DrawBar(g, previousHighlight);
            }

            if (currentHighlight != -1)
            {
                g.Color = new Color(1.0, 0.0, 0.0);
                DrawBar(g, currentHighlight);
            }
        }
Пример #8
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();
        }
Пример #9
0
        void RenderBackground(Cairo.Context context, Gdk.Rectangle region)
        {
            region.Inflate(-Padding, -Padding);
            context.RenderOuterShadow(new Gdk.Rectangle(region.X + 10, region.Y + 15, region.Width - 20, region.Height - 15), Padding, 3, .25);

            context.RoundedRectangle(region.X + 0.5, region.Y + 0.5, region.Width - 1, region.Height - 1, 5);
            using (var lg = new LinearGradient(0, region.Y, 0, region.Bottom)) {
                lg.AddColorStop(0, new Cairo.Color(.36, .53, .73));
                lg.AddColorStop(1, new Cairo.Color(.21, .37, .54));

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

            context.Save();
            context.Translate(IconPosition.X, IconPosition.Y);
            context.Scale(0.75, 0.75);
            Gdk.CairoHelper.SetSourcePixbuf(context, starburst, -starburst.Width / 2, -starburst.Height / 2);
            context.FillPreserve();
            context.Restore();

            context.LineWidth = 1;
            context.SetSourceRGB(.29, .47, .67);
            context.Stroke();
        }
Пример #10
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();
    }
Пример #11
0
        void HandleExposeEvent(object o, ExposeEventArgs args)
        {
            using (Cairo.Context cr = Gdk.CairoHelper.Create(window.GdkWindow)) {
                cr.Scale((double)size / 128, (double)size / 128);
                cr.AlphaPaint();
                int offset;
                switch ((int)Math.Floor(5 * AnimationState))
                {
                case 0:
                    offset = 0;
                    break;

                case 1:
                    offset = 128;
                    break;

                case 2:
                    offset = 128 * 2;
                    break;

                case 3:
                    offset = 128 * 3;
                    break;

                default:
                    offset = 128 * 4;
                    break;
                }

                Gdk.CairoHelper.SetSourcePixbuf(cr, poof, 0, -(offset));
                cr.Paint();

                (cr.Target as IDisposable).Dispose();
            }
        }
    protected void OnDrawingarea1ExposeEvent(object o, ExposeEventArgs args)
    {
        Console.WriteLine("Exposed");

        DrawingArea area = (DrawingArea)o;

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

        int width  = area.Allocation.Width;
        int height = area.Allocation.Height;
        int radius = (width < height ? width : height);

        cr.SetSourceRGB(0.0, 0.0, 0.0);
        cr.Rectangle(0, 0, width, height);
        cr.Fill();

        cr.Translate(this.offsetX, this.offsetY);           // move "pointer"
        cr.Scale(this.scale, this.scale);
        cr.SetSourceSurface(this.surface, 0, 0);            // offset surface
        cr.Rectangle(0, 0, this.surface.Width,              // offset cutout
                     this.surface.Height);
        cr.Fill();                                          // apply

        cr.SetSourceRGB(1.0, 0.0, 0.0);
        cr.Arc(this.pointX, this.pointY, 2, 0, 2 * Math.PI);
        cr.Fill();

        ((IDisposable)cr.GetTarget()).Dispose();
        ((IDisposable)cr).Dispose();
    }
Пример #13
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();
    }
Пример #14
0
        void DrawPixbuf(Cairo.Context ctx, Gdk.Pixbuf img, double x, double y, Size idesc)
        {
            ctx.Save();
            ctx.Translate(x, y);

            ctx.Scale(idesc.Width / (double)img.Width, idesc.Height / (double)img.Height);
            Gdk.CairoHelper.SetSourcePixbuf(ctx, img, 0, 0);

#pragma warning disable 618
            using (var p = ctx.Source) {
                if (p is SurfacePattern pattern)
                {
                    if (idesc.Width > img.Width || idesc.Height > img.Height)
                    {
                        // Fixes blur issue when rendering on an image surface
                        pattern.Filter = Cairo.Filter.Fast;
                    }
                    else
                    {
                        pattern.Filter = Cairo.Filter.Good;
                    }
                }
            }
#pragma warning restore 618


            ctx.Paint();

            ctx.Restore();
        }
Пример #15
0
        protected override void Draw(Context cr, Pixbuf prev, Pixbuf next, int width, int height, double progress)
        {
            cr.SetSourceColor (new Color (0, 0, 0, progress));
            if (next != null) {
                double scale = Math.Min ((double)width/(double)next.Width, (double)height/(double)next.Height);
                cr.Save ();

                cr.Rectangle (0, 0, width, .5 * (height - scale*next.Height));
                cr.Fill ();

                cr.Rectangle (0, height - .5 * (height - scale*next.Height), width, .5 * (height - scale*next.Height));
                cr.Fill ();

                cr.Rectangle (0, 0, .5 * (width - scale*next.Width), height);
                cr.Fill ();

                cr.Rectangle (width - .5 * (width - scale*next.Width), 0, .5 * (width - scale*next.Width), height);
                cr.Fill ();

                cr.Rectangle (0, 0, width, height);
                cr.Scale (scale, scale);
                CairoHelper.SetSourcePixbuf (cr, next, .5 * ((double)width/scale - next.Width), .5 * ((double)height/scale - next.Height));
                cr.PaintWithAlpha (progress);
                cr.Restore ();
            }
        }
Пример #16
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 ();
	}
    static void draw(Cairo.Context gr, int width, int height)
    {
        gr.Scale(width, height);
        gr.LineWidth = 0.04;
        LinearGradient pat;

        pat = new LinearGradient(0.0, 0.0, 0.0, 1.0);
        pat.AddColorStop(1, new Color(0, 0, 0, 1));
        pat.AddColorStop(0, new Color(1, 1, 1, 1));
        gr.Rectangle(new PointD(0, 0),
                     1, 1
                     );

        gr.Pattern = pat;
        gr.Fill();
        pat.Destroy();

        RadialGradient pat2 = new RadialGradient(0.45, 0.4, 0.1,
                                                 0.4, 0.4, 0.5);

        pat2.AddColorStop(0, new Color(1, 1, 1, 1));
        pat2.AddColorStop(1, new Color(0, 0, 0, 1));
        gr.Pattern = pat2;
        gr.Arc(0.5, 0.5, 0.3, 0, 2 * M_PI);
        gr.Fill();
        pat2.Destroy();
    }
Пример #18
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();
        }
Пример #19
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();
    }
Пример #20
0
    void Draw(Context cr, int width, int height)
    {
        cr.LineWidth = 1.0;
        cr.Color = new Color(1.0, 1.0, 1.0);
        cr.Rectangle(0, 0, width, height);
        cr.Fill();

        cr.Save();
        cr.Scale(scale_factor, scale_factor);
        try
        {
            if(diagram != null)
            {
                DiagramRenderer dr = new DiagramRenderer(cr, width, height, diagram);
                cr.Color = new Color(0.0, 0.0, 0.0);
                dr.Render();
                dr.Draw();
            }
        }
        catch
        {
            error_counter++;
        }
        cr.Restore();
    }
Пример #21
0
        public static void ShowWithOptions(this DockySurface self, DockySurface target, PointD point, double zoom, double rotation, double opacity)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            Cairo.Context cr = target.Context;

            double cos, sin;

            cos = Math.Cos(rotation);
            sin = Math.Sin(rotation);
            Matrix m = new Matrix(cos, sin, -sin, cos, point.X, point.Y);

            cr.Transform(m);

            if (zoom != 1)
            {
                cr.Scale(zoom, zoom);
            }

            cr.SetSource(self.Internal,
                         -self.Width / 2,
                         -self.Height / 2);

            cr.PaintWithAlpha(opacity);

            cr.IdentityMatrix();
        }
Пример #22
0
        void RenderPreview(Cairo.Context context, Gdk.Point position, double opacity)
        {
            if (brandedIcon != null)
            {
                /*				if (previewSurface == null) {
                 *      previewSurface = new SurfaceWrapper (context, brandedIcon);
                 * }
                 * double scale = PreviewSize / previewSurface.Width;
                 *
                 * context.Save ();
                 * context.Translate (position.X, position.Y);
                 * context.Scale (scale * IconScale, scale * IconScale);
                 * context.SetSourceSurface (previewSurface.Surface, -previewSurface.Width / 2, -previewSurface.Height / 2);
                 * context.PaintWithAlpha (opacity);
                 * context.Restore ();
                 */

                double scale = PreviewSize / brandedIcon.Width;
                context.Save();
                context.Translate(position.X, position.Y);
                context.Scale(scale * IconScale, scale * IconScale);
                context.DrawImage(this, brandedIcon.WithAlpha(opacity), -brandedIcon.Width / 2, -brandedIcon.Height / 2);
                context.Restore();
            }
        }
Пример #23
0
        protected override bool OnExposeEvent(EventExpose ev)
        {
            using (Cairo.Context context = CairoHelper.Create(ev.Window)) {
                context.Save();

                PointD translation = DrawingToView(0.0, 0.0);
                context.Translate(translation.X, translation.Y);
                context.Scale(Scale, Scale);

                foreach (IFigure figure in Drawing.FiguresEnumerator)
                {
                    // check region for update
                    bool shouldDraw = true;
                    if (shouldDraw)
                    {
                        figure.Draw(context);
                    }
                }
                foreach (IFigure figure in SelectionEnumerator)
                {
                    figure.DrawSelected(context);
                }

                context.Restore();

                foreach (IHandle handle in SelectionHandles)
                {
                    handle.Draw(context, this);
                }
            }

            DebugUpdateFrame();
            return(base.OnExposeEvent(ev));
        }
Пример #24
0
        protected void DrawBackground(Cairo.Context cr)
        {
            var totalRect = GetTotalBounds();

            cr.SetSourceColor(BackgroundColor);
            cr.Rectangle(totalRect.X, totalRect.Y, totalRect.Width, totalRect.Height);
            cr.Fill();

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

            if (Surface != null)
            {
                cr.SetSource(Surface, 0, 0);

                using (SurfacePattern pattern = (SurfacePattern)cr.GetSource()) {
                    pattern.Filter = Filter.Nearest;
                }

                cr.Paint();
            }
            else if (Image != null)
            {
                using (Surface source = new BitmapSurface(Image)) {
                    cr.SetSource(source, 0, 0);

                    using (SurfacePattern pattern = (SurfacePattern)cr.GetSource()) {
                        pattern.Filter = Filter.Nearest;
                    }

                    cr.Paint();
                }
            }
            else
            {
                Cairo.Rectangle extents = cr.ClipExtents();
                for (int i = 0; i < Width * Height; i++)
                {
                    int             tileX = i % Width;
                    int             tileY = i / Width;
                    Cairo.Rectangle rect  = GetTileRectWithPadding(tileX, tileY, scale: false, offset: false);

                    if (!CairoHelper.RectsOverlap(extents, rect))
                    {
                        continue;
                    }

                    cr.Save();
                    cr.Translate(rect.X + TilePaddingX, rect.Y + TilePaddingY);
                    cr.Rectangle(0, 0, TileWidth, TileHeight);
                    cr.Clip();
                    TileDrawer(i, cr);
                    cr.Restore();
                }
            }

            cr.Restore(); // Undo scale, offset
        }
 static void oval_path(Cairo.Context gr, double xc, double yc, double xr, double yr)
 {
     gr.Translate(xc, yc);
     gr.Scale(1.0, yr / xr);
     gr.MoveTo(new PointD(xr, 0.0));
     gr.Arc(0, 0, xr, 0, 2 * M_PI);
     gr.ClosePath();
 }
Пример #26
0
        protected override bool OnDrawn(Cairo.Context ctx)
        {
            // color the screen black
            ctx.SetSourceRGB(0, 0, 0);
            ctx.Paint();
            // Normally (0,0) is in the corner, but we want it in the middle, so we must translate:
            ctx.Translate(AllocatedWidth / 2, AllocatedHeight / 2);
            var bounds = bounds_multiplier * max * new Vector3(1, 1, 1);
            // we care about the limiting factor, since most orbits will be bounded roughly by a square
            // but screens are rectangular
            var scale = Math.Min((AllocatedWidth / 2) * bounds.x, (AllocatedHeight / 2) / bounds.y);

            ctx.Scale(scale, scale);

            if (paths == null)
            {
                this.ClearPaths();
            }
            order = order.OrderByDescending(x => Vector3.Magnitude(sys[x].position - camera.position)).ToArray();
            for (int i = 0; i < sys.Count; i++)
            {
                var body = sys[order[i]];
                var cl   = body.color;
                ctx.SetSourceRGB(cl.x, cl.y, cl.z);

                var T = camera.Transform(body.position - sys.origin);                           //camera.position);// - camera.Transform(sys.origin);

                var r   = radius_multiplier * camera.TransformProjectionRadius(T, body.radius); //body.radius;
                var pos = camera.TransformProjection(T);
                ctx.Arc(pos.x, pos.y, r, 0, 2 * Math.PI);
                ctx.Fill();
                Vector3 lastPath;
                try {
                    lastPath = camera.TransformProjection(camera.Transform(paths[order[i]][0]));
                } catch (ArgumentOutOfRangeException) {
                    lastPath = Vector3.zero;
                }
                ctx.LineWidth = Math.Min(LINE_MULTIPLIER * radius_multiplier * body.radius, LINE_MULTIPLIER * r);
                foreach (Vector3 p in paths[order[i]])
                {
                    pos = camera.TransformProjection(camera.Transform(p));
                    ctx.MoveTo(lastPath.x, lastPath.y);
                    ctx.LineTo(pos.x, pos.y);
                    ctx.Stroke();
                    lastPath = pos;
                }
                paths[order[i]].Add(body.position - sys.origin);
                if (paths[order[i]].Count > line_max)
                {
                    paths[order[i]] = paths[order[i]].TakeLast(line_max).ToList();
                }
            }
            return(true);
        }
Пример #27
0
    static void draw(Cairo.Context gr, int width, int height)
    {
        int          w, h;
        ImageSurface image;

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

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

        gr.Translate(0.5, 0.5);
        gr.Rotate(45 * M_PI / 180);
        gr.Scale(1.0 / w, 1.0 / h);
        gr.Translate(-0.5 * w, -0.5 * h);

        image.Show(gr, 0, 0);
        image.Destroy();
    }
Пример #28
0
        void RedrawBoard()
        {
            boardContext = Gdk.CairoHelper.Create(BoardArea.GdkWindow);
            double transx = Math.Abs((BoardArea.Allocation.Width - (boardBackground.Width * 0.75))) / 2;

            boardContext.Translate(transx, 0);
            boardContext.Scale(0.75, 0.75);
            boardBackground.Show(boardContext, 0, 0);
            PieceDisplay.DrawPieces(boardContext);
            boardContext.Dispose();
        }
Пример #29
0
 void RenderPreview(Cairo.Context context, Gdk.Point position, double opacity)
 {
     if (brandedIcon != null)
     {
         double scale = PreviewSize / brandedIcon.Width;
         context.Save();
         context.Translate(position.X, position.Y);
         context.Scale(scale * IconScale, scale * IconScale);
         context.DrawImage(this, brandedIcon.WithAlpha(opacity), -brandedIcon.Width / 2, -brandedIcon.Height / 2);
         context.Restore();
     }
 }
Пример #30
0
	void OvalPath (Context cr, double xc, double yc, double xr, double yr)
	{
		Matrix m = cr.Matrix;

		cr.Translate (xc, yc);
		cr.Scale (1.0, yr / xr);
		cr.MoveTo (xr, 0.0);
		cr.Arc (0, 0, xr, 0, 2 * Math.PI);
		cr.ClosePath ();

		cr.Matrix = m;
	}
Пример #31
0
        public static void Render (Context cr, Rectangle box,
            double xalign, double yalign, Color innerColor, Color outerColor)
        {
            // virtual size of the figure we will draw below on the 1:1 scale
            double original_width = 8;
            double original_height = 12;

            // figure out the scale dimensions of the bounding box and the glyph
            double box_size = Math.Min (box.Width, box.Height);
            double original_size = Math.Max (original_width, original_height);

            // create a scale for the box (ratio between virtual glyph size and the box),
            // then re-scale to account for the extra size that will be added via stroke.
            // glyph_scale is the stroke width and the actual transformation size
            double box_scale = box_size / original_size;
            double glyph_scale = Math.Floor ((box_size - box_scale) / original_size);

            // compute the alignment to the pixel grid for the stroke/scale
            double pixel_align = Math.Floor (glyph_scale + 0.5) / 2.0;

            // figure out the actual size in pixels of the glyph
            double actual_width = glyph_scale * original_width + 2 * Math.Floor (pixel_align);
            double actual_height = glyph_scale * original_height + 2 * Math.Floor (pixel_align);

            // compute the offset accounting for box, grid alignment, and figure alignment
            double tx = box.X + pixel_align + Math.Round ((box.Width - actual_width) * xalign);
            double ty = box.Y + pixel_align + Math.Round ((box.Height - actual_height) * yalign);

            // save the context, and transform the current/new context
            cr.Save ();
            cr.Translate (tx, ty);
            cr.Scale (glyph_scale, glyph_scale);

            // define how the strokes look
            cr.LineWidth = 1;
            cr.LineCap = LineCap.Round;
            cr.LineJoin = LineJoin.Round;

            // inner 'b' note
            cr.Color = innerColor;
            cr.MoveTo (0, 2);
            cr.LineTo (2, 0);
            cr.Arc (4, 8, 2, Math.PI, Math.PI * 3);
            cr.Stroke ();

            // outer 'cut' circle
            cr.Color = outerColor;
            cr.Arc (4, 8, 4, Math.PI * 1.5, Math.PI * 1.12);
            cr.Stroke ();

            cr.Restore ();
        }
        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();
        }
		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 ();
		}
Пример #34
0
        public void DrawBasis(Context cr, int CubePxSize)
        {
            if (OriginalFile == null)
                return;
            if (DrawingSvg == null)
                ModifyDrawingImage();

            FrameScale = DrawingSvg.Dimensions.Width / SvgWidht;

            double ratio = CubePxSize / (BaseWidht * FrameScale);
            cr.Scale(ratio, ratio);
            cr.Translate(0.0 - ((BaseX - AddX) * FrameScale), 0.0 - ((BaseY - AddY) * FrameScale));
            DrawingSvg.RenderCairo(cr);
        }
    static void draw(Cairo.Context gr, int width, int height)
    {
        int            w, h;
        ImageSurface   image;
        Matrix         matrix;
        SurfacePattern pattern;

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

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

        pattern        = new SurfacePattern(image);
        pattern.Extend = Cairo.Extend.Repeat;

        gr.Translate(0.5, 0.5);
        gr.Rotate(M_PI / 4);
        gr.Scale(1 / Math.Sqrt(2), 1 / Math.Sqrt(2));
        gr.Translate(-0.5, -0.5);

        matrix = new Matrix();
        matrix.InitScale(w * 5.0, h * 5.0);

        pattern.Matrix = matrix;

        gr.Pattern = pattern;

        gr.Rectangle(new PointD(0, 0),
                     1.0, 1.0);
        gr.Fill();

        pattern.Destroy();
        image.Destroy();
    }
Пример #36
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 ();
		}
        //FIXME: Figure produces invalid results
        public override PointD Draw(Context context, PointD a, PointD b)
        {
            // Save context
            context.Save ();

            if (_scaleX != _scaleY)
                context.Scale(_scaleX, _scaleY);

            var midpoint = new PointD (a.X + 2 * _radius, a.Y + 2 * _radius);

            context.Arc (midpoint.X, midpoint.Y, _radius, 0, (2 * Math.PI));
            context.Restore ();
            context.Stroke ();

            return Geometry.EdgePointOfCircle (midpoint, _radius, b);
        }
Пример #38
0
        protected override bool OnExposeEvent(EventExpose evnt)
        {
            if (!IsRealized)
            {
                return(false);
            }
            using (Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window)) {
                if (background_buffer == null)
                {
                    if (Orientation == DockPosition.Bottom || Orientation == DockPosition.Top)
                    {
                        background_buffer = new DockySurface(allocation.Width, allocation.Height, cr.Target);
                    }
                    else
                    {
                        // switch width and height so we can rotate it later
                        background_buffer = new DockySurface(allocation.Height, allocation.Width, cr.Target);
                    }
                    DrawBackground(background_buffer);
                }

                switch (Orientation)
                {
                case DockPosition.Top:
                    cr.Scale(1, -1);
                    cr.Translate(0, -background_buffer.Height);
                    break;

                case DockPosition.Left:
                    cr.Rotate(Math.PI * .5);
                    cr.Translate(0, -background_buffer.Height);
                    break;

                case DockPosition.Right:
                    cr.Rotate(Math.PI * -0.5);
                    cr.Translate(-background_buffer.Width, 0);
                    break;
                }

                cr.Operator = Operator.Source;
                background_buffer.Internal.Show(cr, 0, 0);

                (cr.Target as IDisposable).Dispose();
            }

            return(base.OnExposeEvent(evnt));
        }
Пример #39
0
        private static void DrawClock(object sender, DrawnArgs args)
        {
            Cairo.Context cr     = args.Cr;
            int           width  = args.Width;
            int           height = args.Height;

            DateTime now = DateTime.Now;
            double   hours, minutes, seconds;

            Clutter.Color color;

            seconds = now.Second * Math.PI / 30;
            minutes = now.Minute * Math.PI / 30;
            hours   = now.Hour * Math.PI / 6;

            cr.Save();
            cr.Operator = Operator.Clear;
            cr.Paint();
            cr.Restore();
            cr.Operator = Operator.Over;
            cr.Scale(width, height);
            cr.LineCap   = LineCap.Round;
            cr.LineWidth = 0.1;

            Global.CairoSetSourceColor(cr, Clutter.Color.New(0, 0, 0, 255));
            cr.Translate(0.5, 0.5);
            cr.Arc(0, 0, 0.4, 0, Math.PI * 2);
            cr.Stroke();

            color = Clutter.Color.New(255, 255, 255, 128);
            Global.CairoSetSourceColor(cr, color);
            cr.MoveTo(0, 0);
            cr.Arc(Math.Sin(seconds) * 0.4, -Math.Cos(seconds) * 0.4, 0.05, 0, Math.PI * 2);
            cr.Fill();

            color = Clutter.Color.New(78, 154, 6, 196);
            Global.CairoSetSourceColor(cr, color);
            cr.MoveTo(0, 0);
            cr.LineTo(Math.Sin(minutes) * 0.4, -Math.Cos(minutes) * 0.4);
            cr.Stroke();

            cr.MoveTo(0, 0);
            cr.LineTo(Math.Sin(hours) * 0.2, -Math.Cos(hours) * 0.2);
            cr.Stroke();

            args.RetVal = true;
        }
        public static void CachedDraw(this Cairo.Context self, ref SurfaceWrapper surface, Gdk.Rectangle region,
                                      object parameters = null, float opacity = 1.0f, Action <Cairo.Context, float> draw = null, double?forceScale = null)
        {
            double displayScale = forceScale.HasValue ? forceScale.Value : QuartzSurface.GetRetinaScale(self);
            int    targetWidth  = (int)(region.Width * displayScale);
            int    targetHeight = (int)(region.Height * displayScale);

            bool redraw = false;

            if (surface == null || surface.Width != targetWidth || surface.Height != targetHeight)
            {
                if (surface != null)
                {
                    surface.Dispose();
                }
                surface = new SurfaceWrapper(self, targetWidth, targetHeight);
                redraw  = true;
            }
            else if ((surface.Data == null && parameters != null) || (surface.Data != null && !surface.Data.Equals(parameters)))
            {
                redraw = true;
            }


            if (redraw)
            {
                surface.Data = parameters;
                using (var context = new Cairo.Context(surface.Surface)) {
                    context.Operator = Operator.Clear;
                    context.Paint();
                    context.Operator = Operator.Over;
                    context.Save();
                    context.Scale(displayScale, displayScale);
                    draw(context, 1.0f);
                    context.Restore();
                }
            }

            self.Save();
            self.Translate(region.X, region.Y);
            self.Scale(1 / displayScale, 1 / displayScale);
            self.SetSourceSurface(surface.Surface, 0, 0);
            self.PaintWithAlpha(opacity);
            self.Restore();
        }
Пример #41
0
    static void draw(Cairo.Context gr, int width, int height)
    {
        gr.Scale(width, height);
        gr.LineWidth = 0.04;

        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();
    }
Пример #42
0
        public void Resize(int width, int height)
        {
            ImageSurface dest = new ImageSurface (Format.Argb32, width, height);

            using (Context g = new Context (dest)) {
                g.Scale ((double)width / (double)Surface.Width, (double)height / (double)Surface.Height);
                g.SetSourceSurface (Surface, 0, 0);
                g.Paint ();
            }

            (Surface as IDisposable).Dispose ();
            Surface = dest;
        }
Пример #43
0
        public void RedrawReport(Context c)
        {
            if (Zoom != 1) {
                c.Scale (Zoom, Zoom);
            }

            if (SelectedTool != null) {
                SelectedTool.OnBeforeDraw (c);
            }
            for (int i = 0; i < SectionViews.Count; i++) {
                var renderedSection = SectionViews [i];
                renderedSection.Render (c);
            }
            if (SelectedTool != null) {
                SelectedTool.OnAfterDraw (c);
            }
        }
        public void DrawCube(Context cr, int CubePxSize, bool Coloring)
        {
            logger.Debug("Начали рисовать куб {0}", Name);
            int PxWidth = CubesH * CubePxSize;
            int PxHeight = CubesV * CubePxSize;

            //Фон
            if(Coloring)
            {
                cr.Rectangle(0, 0, PxWidth, PxHeight);
                //cr.SetSourceRGB(1, 0.9, 0.6);
                cr.SetSourceRGB(0.77254902, 0.631372549, 0.435294118);
                cr.Fill();
            }

            //Куб
            double vratio = (double) PxHeight / SvgImage.Dimensions.Height;
            double hratio = (double) PxWidth / SvgImage.Dimensions.Width;
            double ratio = Math.Min(vratio, hratio);
            cr.Scale(ratio, ratio);
            SvgImage.RenderCairo(cr);
            logger.Debug("Закончили рисовать куб.");
        }
Пример #45
0
        private void RenderCell(Context g, int width, int height)
        {
            // Add some padding
            width -= 2;
            height -= 2;

            double scale;
            int draw_width = width;
            int draw_height = height;

            // The image is more constrained by height than width
            if ((double)width / (double)surface.Width >= (double)height / (double)surface.Height) {
                scale = (double)height / (double)(surface.Height);
                draw_width = (int)(surface.Width * height / surface.Height);
            } else {
                scale = (double)width / (double)(surface.Width);
                draw_height = (int)(surface.Height * width / surface.Width);
            }

            int offset_x = (int)((width - draw_width) / 2f);
            int offset_y = (int)((height - draw_height) / 2f);

            g.Save ();
            g.Rectangle (offset_x, offset_y, draw_width, draw_height);
            g.Clip ();

            g.SetSource (transparent);
            g.Paint ();

            g.Scale (scale, scale);
            g.SetSourceSurface (surface, (int)(offset_x / scale), (int)(offset_y / scale));
            g.Paint ();

            g.Restore ();

            // TODO: scale this box correctly to match layer aspect ratio
            g.Color = new Cairo.Color (0.5, 0.5, 0.5);
            g.Rectangle (offset_x + 0.5, offset_y + 0.5, draw_width, draw_height);
            g.LineWidth = 1;
            g.Stroke ();
        }
Пример #46
0
        protected override bool OnExposed(Context cr, Rectangle area)
        {
            cr.Color = Color;
            if(rL > 0.0 && rR > 0.0 && rT > 0.0 && rB > 0.0)
            {
                double width = Allocation.Width;
                double height = Allocation.Height;
                double radL = rL * width;
                double radR = rR * width;
                double radT = rT * height;
                double radB = rB * height;

                Matrix m = cr.Matrix;
                cr.Translate(radL, radT);
                cr.Scale(radL, radT);
                cr.Arc(0.0, 0.0, 1.0, 1.0 * Math.PI, 1.5 * Math.PI);

                cr.Matrix = m;
                cr.Translate(width - radR, radT);
                cr.Scale(radR, radT);
                cr.Arc(0.0, 0.0, 1.0, 1.5 * Math.PI, 2.0 * Math.PI);

                cr.Matrix = m;
                cr.Translate(width - radR, height - radB);
                cr.Scale(radR, radB);
                cr.Arc(0.0, 0.0, 1.0, 0.0 * Math.PI, 0.5 * Math.PI);

                cr.Matrix = m;
                cr.Translate(radL, height - radB);
                cr.Scale(radL, radB);
                cr.Arc(0.0, 0.0, 1.0, 0.5 * Math.PI, 1.0 * Math.PI);

                cr.ClosePath();
            }
            else
                cr.Rectangle(area);
            cr.Fill();
            return true;
        }
Пример #47
0
 /** ASYNC */
 public static ImageSurface ScaleDownSurface(ImageSurface s, uint size)
 {
     double scale = (double)size / (double)Math.Max(s.Width, s.Height);
     int nw = Math.Max(1, (int)(s.Width * scale));
     int nh = Math.Max(1, (int)(s.Height * scale));
     ImageSurface rv = new ImageSurface (Format.ARGB32, nw, nh);
     using (Context cr = new Context(rv)) {
       using (SurfacePattern p = new SurfacePattern(s)) {
     cr.Rectangle (0,0, rv.Width, rv.Height);
     cr.Scale (scale, scale);
     cr.Pattern = p;
     cr.Fill ();
       }
     }
     return rv;
 }
Пример #48
0
		public void imagepattern(Context cr, int width, int height)
		{
			Normalize (cr, width, height);
			
			ImageSurface image = new ImageSurface ("data/romedalen.png");
			int w = image.Width;
			int h = image.Height;

			SurfacePattern pattern = new SurfacePattern (image);
			pattern.Extend = Extend.Repeat;

			cr.Translate (0.5, 0.5);
			cr.Rotate (Math.PI / 4);
			cr.Scale (1 / Math.Sqrt (2), 1 / Math.Sqrt (2));
			cr.Translate (- 0.5, - 0.5);

			Matrix matrix = new Matrix ();
			matrix.InitScale (w * 5.0, h * 5.0);
			pattern.Matrix = matrix;

			cr.Source = pattern;

			cr.Rectangle (0, 0, 1.0, 1.0);
			cr.Fill ();

			pattern.Destroy ();
			image.Destroy ();
		}
Пример #49
0
        private void DrawImage(Context cr, Gdk.Pixbuf pixbuf, double x, double y, double w, double h)
        {
            double scalex, scaley;
            switch (fit) {
            case CustomPrintWidget.FitMode.Zoom:
                scalex = scaley = Math.Max (w/pixbuf.Width, h/pixbuf.Height);
                break;
            case CustomPrintWidget.FitMode.Fill:
                scalex = w/pixbuf.Width;
                scaley = h/pixbuf.Height;
                break;
            default:
            case CustomPrintWidget.FitMode.Scaled:
                scalex = scaley = Math.Min (w/pixbuf.Width, h/pixbuf.Height);
                break;
            }

            double rectw = w / scalex;
            double recth = h / scaley;

            cr.Save ();
            if (white_borders)
                cr.Translate (w * .025, h * .025);

            cr.Translate (x, y);
            if (white_borders)
                cr.Scale (.95, .95);
            cr.Scale (scalex, scaley);
            cr.Rectangle (0, 0, rectw, recth);
            Gdk.CairoHelper.SetSourcePixbuf (cr, pixbuf, (rectw - pixbuf.Width) / 2.0, (recth - pixbuf.Height) / 2.0);
            cr.Fill ();

            if (white_borders) {
                cr.Rectangle (0, 0 ,rectw, recth);
                cr.Color = new Color (0, 0, 0);
                cr.LineWidth = 1 / scalex;
                cr.Stroke ();
            }
            cr.Restore ();
        }
Пример #50
0
		public static void CachedDraw (this Cairo.Context self, ref SurfaceWrapper surface, Gdk.Rectangle region, 
		                               object parameters = null, float opacity = 1.0f, Action<Cairo.Context, float> draw = null, double? forceScale = null)
		{
			double displayScale = forceScale.HasValue ? forceScale.Value : QuartzSurface.GetRetinaScale (self);
			int targetWidth = (int) (region.Width * displayScale);
			int targetHeight = (int) (region.Height * displayScale);

			bool redraw = false;
			if (surface == null || surface.Width != targetWidth || surface.Height != targetHeight) {
				if (surface != null)
					surface.Dispose ();
				surface = new SurfaceWrapper (self, targetWidth, targetHeight);
				redraw = true;
			} else if ((surface.Data == null && parameters != null) || (surface.Data != null && !surface.Data.Equals (parameters))) {
				redraw = true;
			}


			if (redraw) {
				surface.Data = parameters;
				using (var context = new Cairo.Context (surface.Surface)) {
					context.Operator = Operator.Clear;
					context.Paint();
					context.Operator = Operator.Over;
					context.Save ();
					context.Scale (displayScale, displayScale);
					draw(context, 1.0f);
					context.Restore ();
				}
			}

			self.Save ();
			self.Translate (region.X, region.Y);
			self.Scale (1 / displayScale, 1 / displayScale);
			self.SetSourceSurface (surface.Surface, 0, 0);
			self.PaintWithAlpha (opacity);
			self.Restore ();
		}
 private void paintNodes(Context ctx, int w, int h, IEnumerable<Node> nodes)
 {
     ctx.LineWidth = 2.0d;
     foreach(Node node in nodes) {
         PointD abs = new PointD(node.Item2.X*w, node.Item2.Y*h);
         ctx.Arc(abs.X, abs.Y, AlgorithmRadius, 0.0d, 2.0d*Math.PI);
         ctx.ClosePath();
         ctx.NewSubPath();
         ctx.Arc(abs.X, abs.Y, AlgorithmRadius-BlueprintStyle.Thickness, 0.0d, 2.0d*Math.PI);
         ctx.ClosePath();
         ctx.NewSubPath();
     }
     ctx.Pattern = BlueprintStyle.FillPattern;
     ctx.FillPreserve();
     ctx.Color = BlueprintStyle.HardWhite;
     ctx.Stroke();
     double r_2, dx, dy;
     this.nodeCenters.Clear();
     foreach(Node node in nodes) {
         PointD abs = new PointD(node.Item2.X*w, node.Item2.Y*h);
         this.nodeCenters.Add(abs);
         TextExtents te = ctx.TextExtents(node.Item1);
         r_2 = (AlgorithmRadius-BlueprintStyle.Thickness)/Math.Sqrt(te.Width*te.Width+te.Height*te.Height);
         ctx.Save();
         ctx.MoveTo(abs.X-r_2*te.Width, abs.Y+r_2*te.Height);
         ctx.Scale(2.0d*r_2, 2.0d*r_2);
         ctx.ShowText(node.Item1);
         ctx.Restore();
     }
 }
Пример #52
0
        void Draw(Context cr, int width, int height)
        {
            Surface overlay = cr.Target.CreateSimilar(Content.ColorAlpha, width, height);
            Surface addSurface = cr.Target.CreateSimilar(Content.ColorAlpha, width, height);

            //	FillChecks (cr, 0, 0,width, height);//w, h);
            //	cr.Save ();

            using (Context cr_overlay = new Context(overlay))
                if (listPoint != null && listPoint.Count > 0) {

                    using (Context cr_addSurface = new Context(addSurface)) {

                        BarierPoint actualPoint;
                        BarierPoint nearstBP;

                        for (int i = 0; i < listPoint.Count; i++) {

                            actualPoint = listPoint[i];
                            if (i == listPoint.Count-1) {
                                nearstBP = listPoint[0];
                            } else
                                nearstBP = listPoint[i + 1];
                            Cairo.Color clrPoint;

                            if (actualPoint.Equals(movingPoint))
                                clrPoint =colorSelectPoint;
                            else
                                clrPoint = colorPoint;

                            cr_addSurface.Color = clrPoint;
                            OvalPath(cr_addSurface, actualPoint.X * scaling, actualPoint.Y * scaling, pointWidth, pointWidth);
                            cr_addSurface.Fill();

                            cr_addSurface.Color = colorLine;
                            LinePath(cr_addSurface, actualPoint.X * scaling, actualPoint.Y * scaling, nearstBP.X * scaling, nearstBP.Y * scaling);
                            cr_addSurface.Fill();
                        }

                    cr_overlay.Operator = Operator.Add;
                    cr_overlay.SetSourceSurface(addSurface, 0, 0);
                    cr_overlay.Paint();
                }

            cr.Scale(1 / scaling, 1 / scaling);

            cr.SetSourceSurface(overlay, (int)(drawOffsetX), (int)(drawOffsetY));

            cr.Paint();

            }

            addSurface.Destroy();
            overlay.Destroy();
        }
        public override void DrawSelected(Context context)
        {
            context.Save ();
            context.Translate (DisplayBox.X, DisplayBox.Y);
            context.Scale (DisplayBox.Width, DisplayBox.Height);
            context.Rectangle (0.0, 0.0, 1, 1);
            context.Restore ();
            context.Save ();
            context.LineWidth = 3;
            context.Color = new Cairo.Color (1, 0.0784314, 0.576471, 1);
            context.Stroke ();
            context.Restore ();

            context.Save ();
            BasicDrawSelected (context);
            foreach (IFigure fig in FiguresEnumerator) {
                fig.Draw (context);
            }
            context.Restore ();
        }
Пример #54
0
		public void image(Context cr, int width, int height)
		{
			Normalize (cr, width, height);
			ImageSurface image = new ImageSurface ("data/romedalen.png");
			int w = image.Width;
			int h = image.Height;

			cr.Translate (0.5, 0.5);
			cr.Rotate (45* Math.PI/180);
			cr.Scale  (1.0/w, 1.0/h);
			cr.Translate (-0.5*w, -0.5*h);

			cr.SetSourceSurface (image, 0, 0);
			cr.Paint ();
			image.Destroy ();
		}
Пример #55
0
		public void Normalize (Context cr, int width, int height)
		{
			cr.Scale (width, height);
			cr.LineWidth = 0.04;
		}
 private ImageSurface GenerateStub()
 {
     ImageSurface stub = new ImageSurface (Format.ARGB32, 600, 300);
     Context cairo  = new Context(stub);
     cairo.IdentityMatrix ();
     cairo.Scale (600,300);
     cairo.Rectangle (0, 0, 1, 1);
     cairo.SetSourceRGB (1,1,1);
     cairo.Fill ();
     cairo.MoveTo (0.14, 0.5);
     cairo.SetFontSize (0.08);
     cairo.SetSourceRGB (0, 0, 0);
     cairo.ShowText ("Загрузите подложку");
     cairo.Dispose ();
     return stub;
 }
Пример #57
0
    /**
    The Draw method draws the clock on the given Cairo.Context in a width by
    height -area.

    Draw clears the canvas, sets up the clock transform and calls the clock
    drawing methods. In the clock transform, the clock area coords go from
    -1.0 to 1.0, rotation 0 is at 12:00 and rotation increases clockwise.
    The clock drawing functions are DrawClockFace, DrawHourHand, DrawMinuteHand,
    DrawSecondHand and DrawPin. The transform origin is at the middle of the
    window and the transform preserves the aspect ratio.

    All operations on the context take place inside a Save-Restore -pair.

    @param cr Cairo.Context to draw on.
    @param width The width of the drawable area.
    @param height The height of the drawable area.
      */
    void Draw(Context cr, uint width, uint height)
    {
        uint boxSize = Math.Min (width, height);

        DateTime date = DateTime.Now;

        cr.Save ();
          // Clear the canvas
          cr.Color = new Color (1, 1, 1);
          cr.Rectangle (0, 0, width, height);
          cr.Fill ();

        // Set canvas transform so that the coords go from -1.0 to 1.0,
        // rotation 0.0 is 12:00 and rotation increases clockwise.
        //
        // First, center the clock box to the window.
          cr.Translate ((width - boxSize) / 2.0, (height - boxSize) / 2.0);
        // Then scale the box so that -1.0 .. 1.0 spans the whole box.
          cr.Scale (boxSize / 2.0, boxSize / 2.0);
        // And move the origin to the center of the box.
          cr.Translate (1.0, 1.0);
        // Finally, rotate CCW by 90 degrees to make rotation 0 point up.
        // We don't need to flip the rotation direction, because angle grows
        // clockwise in the "Y grows down" default transform.
          cr.Rotate (-Math.PI / 2.0);

          // Draw the clock
          DrawClockFace (cr);
          DrawHourHand (cr, (uint)date.Hour);
          DrawMinuteHand (cr, (uint)date.Minute);
          DrawSecondHand (cr, (uint)date.Second);
          DrawPin (cr);
        cr.Restore ();
    }
Пример #58
0
 void CairoEllipse(Context cr, double x, double y, double width, double height)
 {
     cr.Save();
     cr.Translate(x + width / 2f, y + height / 2f);
     cr.Scale(width / 2f, height / 2f);
     cr.Arc(0, 0, 1, 0, 2 * Math.PI);
     cr.Restore();
 }
Пример #59
0
		public void clip_image(Context cr, int width, int height)
		{
			Normalize (cr, width, height);
			cr.Arc (0.5, 0.5, 0.3, 0, 2*Math.PI);
			cr.Clip ();
			cr.NewPath (); // path not consumed by clip()

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

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

			cr.SetSourceSurface (image, 0, 0);
			cr.Paint ();

			image.Destroy ();
		}
Пример #60
0
        public override void SetAsSource(Context ctx, Rectangle bounds = default(Rectangle))
        {
            float widthRatio = 1f;
            float heightRatio = 1f;

            if (Scaled){
                widthRatio = (float)bounds.Width / Dimensions.Width;
                heightRatio = (float)bounds.Height / Dimensions.Height;
            }

            if (KeepProportions) {
                if (widthRatio < heightRatio)
                    heightRatio = widthRatio;
                else
                    widthRatio = heightRatio;
            }

            using (ImageSurface tmp = new ImageSurface (Format.Argb32, bounds.Width, bounds.Height)) {
                using (Cairo.Context gr = new Context (tmp)) {
                    gr.Translate (bounds.Left, bounds.Top);
                    gr.Scale (widthRatio, heightRatio);
                    gr.Translate ((bounds.Width/widthRatio - Dimensions.Width)/2, (bounds.Height/heightRatio - Dimensions.Height)/2);

                    hSVG.RenderCairo (gr);
                }
                ctx.SetSource (tmp);
            }
        }