Beispiel #1
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();
        }
        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 ();
        }
 public static void CachedDraw(this Cairo.Context self, ref SurfaceWrapper surface, Gdk.Point position, Gdk.Size size, 
                              object parameters = null, float opacity = 1.0f, Action<Cairo.Context, float> draw = null, double? forceScale = null)
 {
     self.CachedDraw (ref surface, new Gdk.Rectangle (position, size), parameters, opacity, draw, forceScale);
 }
        void RenderIcon(Cairo.Context context, SurfaceWrapper surface, double opacity)
        {
            context.SetSourceSurface(surface.Surface,
                                   Allocation.X + (Allocation.Width - surface.Width) / 2,
                                   Allocation.Y + (Allocation.Height - surface.Height) / 2);

             context.PaintWithAlpha(opacity);
        }
        protected override void OnRealized()
        {
            base.OnRealized();

             using (Cairo.Context context = Gdk.CairoHelper.Create(GdkWindow))
             {
            primarySurface = new SurfaceWrapper(context, primary);
            secondarySurface = new SurfaceWrapper(context, secondary);
            context.Dispose();
             }

             primary.Dispose();
             primary = null;

             secondary.Dispose();
             secondary = null;
        }
Beispiel #6
0
 public static void CachedDraw(this Cairo.Context self, ref SurfaceWrapper surface, Gdk.Point position, Gdk.Size size,
                               object parameters = null, float opacity = 1.0f, Action <Cairo.Context, float> draw = null, double?forceScale = null)
 {
     self.CachedDraw(ref surface, new Gdk.Rectangle(position, size), parameters, opacity, draw, forceScale);
 }