public void SetImage (Gdk.Pixbuf pbuf) { this.pbuf = pbuf; SetPreferedSize (pbuf.Width, pbuf.Height); if (surfaceCache != null) surfaceCache.Dispose (); surfaceCache = null; }
protected override void OnRealized () { base.OnRealized (); using (Cairo.Context context = Gdk.CairoHelper.Create (GdkWindow)) { primarySurface = new SurfaceWrapper (context, primary); secondarySurface = new SurfaceWrapper (context, secondary); } primary.Dispose (); primary = null; secondary.Dispose (); secondary = null; }
protected override void OnRender (Cairo.Context context) { if (surfaceCache == null) { // will improve with CGLayer surfaces surfaceCache = new SurfaceWrapper (context, pbuf); } int x = (int)((Width - pbuf.Width) * XAlign); int y = (int)((Height - pbuf.Height) * YAlign); context.SetSourceSurface (surfaceCache.Surface, x, y); double opacity = Opacity; if (opacity == 1) context.Paint (); else context.PaintWithAlpha (Opacity); base.OnRender (context); }
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); }
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); }
public void QueueThreadedDraw (Action<Cairo.Context> drawCallback) { if (!owner.IsRealized) return; runningSignal.Wait (); UpdateScale (); if (surface == null || surface.Height != TargetHeight || surface.Width != TargetWidth) { using (var similar = Gdk.CairoHelper.Create (owner.GdkWindow)) { if (surface != null) surface.Dispose (); surface = new SurfaceWrapper (similar, TargetWidth, TargetHeight); } } runningSignal.Reset (); this.OnDraw (drawCallback); //ThreadPool.QueueUserWorkItem (new WaitCallback (this.OnDraw), drawCallback); owner.QueueDraw (); }
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); }
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 (); } }
public void Start () { allocation = mode.Allocation; var swapSurface = mode.swapIndicatorSurface; if (swapSurface != null) { if (swapSurface.Width == allocation.Width && swapSurface.Height == allocation.Height) { surface = swapSurface; } else { mode.DestroyIndicatorSwapSurface (); } } if (surface == null) { using (var similiar = CairoHelper.Create (IdeApp.Workbench.RootWindow.GdkWindow)) surface = new SurfaceWrapper (similiar, allocation.Width, allocation.Height); } searchResults = mode.TextEditor.TextViewMargin.SearchResults.ToList().GetEnumerator (); allUsages = mode.AllUsages.GetEnumerator (); allTasks = mode.AllTasks.GetEnumerator (); cr = new Cairo.Context (surface.Surface); GLib.Idle.Add (RunHandler); }