diff --git a/src/Eto.Mac/Drawing/GraphicsHandler.cs b/src/Eto.Mac/Drawing/GraphicsHandler.cs index 9d360ba68..99f71481e 100644 --- a/src/Eto.Mac/Drawing/GraphicsHandler.cs +++ b/src/Eto.Mac/Drawing/GraphicsHandler.cs @@ -83,7 +83,7 @@ public GraphicsHandler() } #if OSX - public GraphicsHandler(NSView view, NSGraphicsContext graphicsContext, float height, CGRect? dirtyRect) + public GraphicsHandler(NSView view, NSGraphicsContext graphicsContext, float height, CGRect? clipRect) { DisplayView = view; this.height = height; @@ -92,8 +92,8 @@ public GraphicsHandler(NSView view, NSGraphicsContext graphicsContext, float hei Control = this.graphicsContext.CGContext; // Clip to bounds otherwise you can draw outside the control on macOS Sonoma - if (dirtyRect != null) - Control.ClipToRect(dirtyRect.Value); + if (clipRect != null) + Control.ClipToRect(clipRect.Value); InitializeContext(!flipped); } diff --git a/src/Eto.Mac/Forms/Controls/DrawableHandler.cs b/src/Eto.Mac/Forms/Controls/DrawableHandler.cs index c94f6a39a..62703ad26 100644 --- a/src/Eto.Mac/Forms/Controls/DrawableHandler.cs +++ b/src/Eto.Mac/Forms/Controls/DrawableHandler.cs @@ -28,16 +28,9 @@ public override void DrawRect(CGRect dirtyRect) var drawable = Drawable; if (drawable == null) return; - // restrict drawing to the bounds of the drawable - // macOS can give us dirty rects outside this range - var bounds = Bounds.ToEto(); - var dirty = dirtyRect.ToEto(); - dirty.Restrict(bounds); - - if (!IsFlipped) - dirty.Y = bounds.Height - dirty.Y - dirty.Height; + ApplicationHandler.QueueResizing = true; - drawable.DrawRegion(dirty); + drawable.DrawRegion(dirtyRect); ApplicationHandler.QueueResizing = false; } @@ -116,22 +109,33 @@ public override void Invalidate(Rectangle rect, bool invalidateChildren) base.Invalidate(rect, invalidateChildren); } - void DrawRegion(RectangleF rect) + void DrawRegion(CGRect dirtyRect) { var context = NSGraphicsContext.CurrentContext; - if (context != null) - { - var handler = new GraphicsHandler(Control, context, (float)Control.Frame.Height, rect.ToNS()); + if (context == null) + return; - using (var graphics = new Graphics(handler)) - { - if (backgroundBrush != null) - graphics.FillRectangle(backgroundBrush, rect); + var bounds = Control.Bounds; - var widget = Widget; - if (widget != null) - Callback.OnPaint(widget, new PaintEventArgs(graphics, rect)); - } + // restrict dirty rect to the bounds of the drawable + // macOS can give us dirty rects outside this range + var dirty = dirtyRect.ToEto(); + dirty.Restrict(bounds.ToEto()); + + var handler = new GraphicsHandler(Control, context, (float)bounds.Height, dirty.ToNS()); + + // dirty rect should be flipped when passed to Drawabe.Paint event + if (!Control.IsFlipped) + dirty.Y = (float)(bounds.Height - dirty.Y - dirty.Height); + + using (var graphics = new Graphics(handler)) + { + if (backgroundBrush != null) + graphics.FillRectangle(backgroundBrush, dirty); + + var widget = Widget; + if (widget != null) + Callback.OnPaint(widget, new PaintEventArgs(graphics, dirty)); } }