public Cairo.Pattern GetPattern(ApplicationContext actx, double scaleFactor)
 {
     if (pattern == null || currentScaleFactor != scaleFactor)
     {
         if (pattern != null)
         {
             pattern.Dispose();
         }
         Gdk.Pixbuf pb = ((GtkImage)Image.Backend).GetBestFrame(actx, scaleFactor, Image.Size.Width, Image.Size.Height, false);
         using (var imgs = new Cairo.ImageSurface(Cairo.Format.ARGB32, (int)(Image.Size.Width * scaleFactor), (int)(Image.Size.Height * scaleFactor))) {
             var ic = new Cairo.Context(imgs);
             ic.Scale((double)imgs.Width / (double)pb.Width, (double)imgs.Height / (double)pb.Height);
             Gdk.CairoHelper.SetSourcePixbuf(ic, pb, 0, 0);
             ic.Paint();
             imgs.Flush();
             ((IDisposable)ic).Dispose();
             pattern = new Cairo.SurfacePattern(imgs);
         }
         pattern.Extend = Cairo.Extend.Repeat;
         var cm = new Cairo.Matrix();
         cm.Scale(scaleFactor, scaleFactor);
         pattern.Matrix     = cm;
         currentScaleFactor = scaleFactor;
     }
     return(pattern);
 }
Beispiel #2
0
 public override void Draw(Bitmap bitmap, int x, int y)
 {
     using (Cairo.Surface s = new BitmapSurface(bitmap)) {
         cr.SetSourceSurface(s, x + xOffset, y + yOffset);
         using (Cairo.SurfacePattern pattern = (Cairo.SurfacePattern)cr.GetSource()) {
             pattern.Filter = Cairo.Filter.Nearest;
         }
         cr.Paint();
     }
 }
 public override object Create(object img)
 {
     Gdk.Pixbuf pb = (Gdk.Pixbuf)img;
     var imgs = new Cairo.ImageSurface (Cairo.Format.ARGB32, pb.Width, pb.Height);
     var ic = new Cairo.Context (imgs);
     Gdk.CairoHelper.SetSourcePixbuf (ic, pb, 0, 0);
     ic.Paint ();
     imgs.Flush ();
     ((IDisposable)ic).Dispose ();
     var p = new Cairo.SurfacePattern (imgs);
     p.Extend = Cairo.Extend.Repeat;
     return p;
 }
        public object Create(object img)
        {
            Gdk.Pixbuf pb   = (Gdk.Pixbuf)img;
            var        imgs = new Cairo.ImageSurface(Cairo.Format.ARGB32, pb.Width, pb.Height);
            var        ic   = new Cairo.Context(imgs);

            Gdk.CairoHelper.SetSourcePixbuf(ic, pb, 0, 0);
            ic.Paint();
            imgs.Flush();
            ((IDisposable)ic).Dispose();
            var p = new Cairo.SurfacePattern(imgs);

            p.Extend = Cairo.Extend.Repeat;
            return(p);
        }
		public Cairo.Pattern GetPattern (ApplicationContext actx, double scaleFactor)
		{
			if (pattern == null || currentScaleFactor != scaleFactor) {
				if (pattern != null)
					pattern.Dispose ();
				Gdk.Pixbuf pb = ((GtkImage)Image.Backend).GetBestFrame (actx, scaleFactor, Image.Size.Width, Image.Size.Height, false);
				using (var imgs = new Cairo.ImageSurface (Cairo.Format.ARGB32, (int)(Image.Size.Width * scaleFactor), (int)(Image.Size.Height * scaleFactor))) {
					var ic = new Cairo.Context (imgs);
					ic.Scale ((double)imgs.Width / (double)pb.Width, (double)imgs.Height / (double)pb.Height);
					Gdk.CairoHelper.SetSourcePixbuf (ic, pb, 0, 0);
					ic.Paint ();
					imgs.Flush ();
					((IDisposable)ic).Dispose ();
					pattern = new Cairo.SurfacePattern (imgs);
				}
				pattern.Extend = Cairo.Extend.Repeat;
				var cm = new Cairo.Matrix ();
				cm.Scale (scaleFactor, scaleFactor);
				pattern.Matrix = cm;
				currentScaleFactor = scaleFactor;
			}
			return pattern;
		}
Beispiel #6
0
        public override void DrawImage(GraphicsHandler graphics, RectangleF source, RectangleF destination)
        {
            FixupAlpha();
            var context = graphics.Control;

            context.Save();
            context.Rectangle(destination.ToCairo());
            double scalex = 1;
            double scaley = 1;

            if (Math.Abs(source.Width - destination.Width) > 0.5f || Math.Abs(source.Height - destination.Height) > 0.5f)
            {
                scalex = (double)destination.Width / (double)source.Width;
                scaley = (double)destination.Height / (double)source.Height;
                context.Scale(scalex, scaley);
            }
            Cairo.SurfacePattern pattern;
            if (Surface != null)
            {
                // we got a surface (by drawing on the bitmap using Graphics), so use that directly.
                pattern = new Cairo.SurfacePattern(Surface);
                var m = new Cairo.Matrix();
                m.InitTranslate(source.Left - (destination.Left / scalex), source.Top - (destination.Top / scaley));
                pattern.Matrix = m;
                context.SetSource(pattern);
            }
            else
            {
                Gdk.CairoHelper.SetSourcePixbuf(context, Control, (destination.Left / scalex) - source.Left, (destination.Top / scaley) - source.Top);
                pattern = (Cairo.SurfacePattern)context.GetSource();
            }

            pattern.Filter = graphics.ImageInterpolation.ToCairo();
            context.Fill();
            context.Restore();
            pattern.Dispose();

            /*
             * Gdk.Pixbuf pb = Control;
             *
             *
             * if (source.Width != destination.Width || source.Height != destination.Height) {
             *      Gdk.Pixbuf pbDest = new Gdk.Pixbuf (Gdk.Colorspace.Rgb, true, 8, destination.Width, destination.Height);
             *      double scalex = (double)(destination.Width) / (double)(source.Width);
             *      double scaley = (double)(destination.Height) / (double)(source.Height);
             *      pb.Scale (pbDest, 0, 0, destination.Width, destination.Height, -(source.X * scalex), -(source.Y * scaley),
             *              scalex, scaley, Gdk.InterpType.Bilinear);
             *      source.Location = new Point (0, 0);
             *      pb = pbDest;
             * }
             * /*
             *
             * pb.RenderToDrawable (graphics.Control, graphics.GC, source.X, source.Y, destination.X, destination.Y, destination.Width, destination.Height, Gdk.RgbDither.None, 0, 0);
             * /*
             *
             * Gdk.Pixmap pm, mask;
             * pb.RenderPixmapAndMask(out pm, out mask, 0);
             * graphics.Drawable.DrawDrawable(graphics.GC, pm, source.X, source.Y, destination.X, destination.Y, destination.Width, destination.Height);
             * pm.Dispose();
             * mask.Dispose();
             * /*
             *
             * graphics.Drawable.DrawPixbuf(null, pb, source.X, source.Y, destination.X, destination.Y, destination.Width, destination.Height, Gdk.RgbDither.None, 0, 0);
             * /*
             */
            /*if (pb != Control)
             *      pb.Dispose ();*/
        }
Beispiel #7
0
        private void OnDrawingarea1ExposeEvent(object o, Gtk.ExposeEventArgs args)
        {
            double scale = PintaCore.Workspace.Scale;

            double x = PintaCore.Workspace.Offset.X;
            double y = PintaCore.Workspace.Offset.Y;

            using (Cairo.Context g = CairoHelper.Create (drawingarea1.GdkWindow)) {
                // Black 1px border around image
                g.DrawRectangle (new Cairo.Rectangle (x, y, PintaCore.Workspace.CanvasSize.X + 1, PintaCore.Workspace.CanvasSize.Y + 1), new Cairo.Color (0, 0, 0), 1);

                // Transparent checkerboard pattern
                using (Cairo.SurfacePattern sp = new Cairo.SurfacePattern (PintaCore.Layers.TransparentLayer.Surface)) {
                    sp.Extend = Cairo.Extend.Repeat;

                    g.FillRectangle (new Cairo.Rectangle (x, y, PintaCore.Workspace.CanvasSize.X, PintaCore.Workspace.CanvasSize.Y), sp);
                }

                // User's layers
                g.Save ();
                g.Translate (x, y);
                g.Scale (scale, scale);

                foreach (Layer layer in PintaCore.Layers.GetLayersToPaint ()) {
                    g.SetSourceSurface (layer.Surface, (int)layer.Offset.X, (int)layer.Offset.Y);
                    g.PaintWithAlpha (layer.Opacity);
                }

                g.Restore ();

                // Selection outline
                if (PintaCore.Layers.ShowSelection) {
                    g.Save ();
                    g.Translate (x, y);
                    g.Translate (0.5, 0.5);
                    g.Scale (scale, scale);

                    g.AppendPath (PintaCore.Layers.SelectionPath);

                    if (PintaCore.Tools.CurrentTool.Name.Contains ("Select") && !PintaCore.Tools.CurrentTool.Name.Contains ("Selected")) {
                        g.Color = new Cairo.Color (.7, .8, .9, .2);
                        g.FillRule = Cairo.FillRule.EvenOdd;
                        g.FillPreserve ();
                    }

                    g.SetDash (new double[] { 2 / scale, 4 / scale }, 0);
                    g.LineWidth = 1 / scale;
                    g.Color = new Cairo.Color (0, 0, 0);

                    g.Stroke ();
                    g.Restore ();
                }
            }
        }