public SurfaceWrapper(Cairo.Context similar, Gdk.Pixbuf source)
        {
            Cairo.Surface surface;
            // There is a bug in Cairo for OSX right now that prevents creating additional accellerated surfaces.
            if (Platform.IsMac)
            {
                surface = new QuartzSurface(Cairo.Format.ARGB32, source.Width, source.Height);
            }
            else if (Platform.IsWindows)
            {
                surface = similar.Target.CreateSimilar(Cairo.Content.ColorAlpha, source.Width, source.Height);
            }
            else
            {
                surface = new ImageSurface(Cairo.Format.ARGB32, source.Width, source.Height);
            }

            using (Cairo.Context context = new Cairo.Context(surface)) {
                Gdk.CairoHelper.SetSourcePixbuf(context, source, 0, 0);
                context.Paint();
            }

            Surface = surface;
            Width   = source.Width;
            Height  = source.Height;
        }
 public SurfaceWrapper(Cairo.Context similar, int width, int height)
 {
     if (MonoDevelop.Core.Platform.IsMac)
     {
         Surface = new QuartzSurface(Cairo.Format.ARGB32, width, height);
     }
     else
     {
         Surface = similar.Target.CreateSimilar(Cairo.Content.ColorAlpha, width, height);
     }
     Width  = width;
     Height = height;
 }
        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();
        }
Exemple #4
0
 public SurfaceWrapper(Cairo.Context similar, int width, int height)
 {
     if (Platform.IsMac)
     {
         Surface = new QuartzSurface(Cairo.Format.ARGB32, width, height);
     }
     else if (Platform.IsWindows)
     {
         using (var target = similar.GetTarget()) {
             Surface = target.CreateSimilar(Cairo.Content.ColorAlpha, width, height);
         }
     }
     else
     {
         Surface = new ImageSurface(Cairo.Format.ARGB32, width, height);
     }
     Width  = width;
     Height = height;
 }
		public SurfaceWrapper (Cairo.Context similar, Gdk.Pixbuf source)
		{
			Cairo.Surface surface;
			// There is a bug in Cairo for OSX right now that prevents creating additional accellerated surfaces.
			if (MonoDevelop.Core.Platform.IsMac)
				surface = new QuartzSurface (Cairo.Format.ARGB32, source.Width, source.Height);
			else
				surface = similar.Target.CreateSimilar (Cairo.Content.ColorAlpha, source.Width, source.Height);

			using (Cairo.Context context = new Cairo.Context (surface)) {
				Gdk.CairoHelper.SetSourcePixbuf (context, source, 0, 0);
				context.Paint ();
			}

			Surface = surface;
			Width = source.Width;
			Height = source.Height;
		}
		public SurfaceWrapper (Cairo.Context similar, int width, int height)
		{
			if (MonoDevelop.Core.Platform.IsMac)
				Surface = new QuartzSurface (Cairo.Format.ARGB32, width, height);
			else
				Surface = similar.Target.CreateSimilar (Cairo.Content.ColorAlpha, width, height);
			Width = width;
			Height = height;
		}
		public SurfaceWrapper (Cairo.Context similar, Gdk.Pixbuf source)
		{
			Cairo.Surface surface;
			// There is a bug in Cairo for OSX right now that prevents creating additional accellerated surfaces.
			if (Platform.IsMac) {
				surface = new QuartzSurface (Format.ARGB32, source.Width, source.Height);
			} else if (Platform.IsWindows) {
				using (var t = similar.GetTarget ()) {
					surface = t.CreateSimilar (Content.ColorAlpha, source.Width, source.Height);
				}
			} else {
				surface = new ImageSurface (Format.ARGB32, source.Width, source.Height);
			}

			using (Context context = new Context (surface)) {
				Gdk.CairoHelper.SetSourcePixbuf (context, source, 0, 0);
				context.Paint ();
			}

			Surface = surface;
			Width = source.Width;
			Height = source.Height;
		}
		public SurfaceWrapper (Cairo.Context similar, int width, int height)
		{
			if (Platform.IsMac) {
				Surface = new QuartzSurface (Cairo.Format.ARGB32, width, height);
			} else if (Platform.IsWindows) {
				using (var target = similar.GetTarget ()) {
					Surface = target.CreateSimilar (Cairo.Content.ColorAlpha, width, height);
				}
			} else {
				Surface = new ImageSurface (Cairo.Format.ARGB32, width, height);
			}
			Width = width;
			Height = height;
		}