Skip to content

Commit

Permalink
Mac: Don't depend on ClipRectangle
Browse files Browse the repository at this point in the history
Starting in macOS 14 there is a new clipsToBounds property that defaults to false, which is a behavior change. This causes incompatibilities with anything that uses ClipRectangle directly or indirectly.

https://developer.apple.com/documentation/macos-release-notes/appkit-release-notes-for-macos-14#NSView

#227
  • Loading branch information
cyanfish committed Nov 19, 2023
1 parent 42b6bdb commit 1f0e529
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
8 changes: 4 additions & 4 deletions NAPS2.Lib/EtoForms/Notifications/CloseButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ public CloseButton(ColorScheme colorScheme)

private void OnPaint(object? sender, PaintEventArgs e)
{
var clearColor = _active && _hover ? ActiveBackground : _hover ? HoverBackground : DefaultBackground;
e.Graphics.Clear(clearColor);
var w = e.ClipRectangle.Width;
var h = e.ClipRectangle.Height;
var bgColor = _active && _hover ? ActiveBackground : _hover ? HoverBackground : DefaultBackground;
var w = Width;
var h = Height;
e.Graphics.FillRectangle(bgColor, 0, 0, w, h);
var p = CLOSE_BUTTON_PADDING;
var pen = new Pen(PenColor, 3);
e.Graphics.DrawLine(pen, p - 1, p - 1, w - p, h - p);
Expand Down
13 changes: 7 additions & 6 deletions NAPS2.Lib/EtoForms/Notifications/NotificationView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,24 @@ protected virtual void NotificationClicked()

private void DrawableOnPaint(object? sender, PaintEventArgs e)
{
var w = e.ClipRectangle.Width;
var h = e.ClipRectangle.Height;
var drawable = (Drawable) sender!;
var w = drawable.Width;
var h = drawable.Height;
e.Graphics.FillRectangle(BackgroundColor, 0, 0, w, h);
e.Graphics.DrawRectangle(BorderColor, 0, 0, w - 1, h - 1);
}

private void DrawWithRoundedCorners(PaintEventArgs e)
private void DrawWithRoundedCorners(Drawable drawable, PaintEventArgs e)
{
// TODO: We're not using this as the few pixels on the edges aren't transparent, which is a problem if there's
// an image underneath. Not sure if there's a way to make that work but I don't care enough about rounded
// corners at the moment.
var w = e.ClipRectangle.Width;
var h = e.ClipRectangle.Height;
var w = drawable.Width;
var h = drawable.Height;
var r = BORDER_RADIUS;
var d = r * 2;
var q = r / 2;
e.Graphics.Clear(Manager!.ColorScheme.BackgroundColor);
e.Graphics.FillRectangle(Manager!.ColorScheme.BackgroundColor, 0, 0, w, h);
// Corners
e.Graphics.FillEllipse(BackgroundColor, -1, -1, d, d);
e.Graphics.FillEllipse(BackgroundColor, w - d, -1, d, d);
Expand Down
4 changes: 2 additions & 2 deletions NAPS2.Lib/EtoForms/Widgets/ScrollZoomImageViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ private void OnMouseWheel(object? sender, MouseEventArgs e)

private void ImagePaint(object? sender, PaintEventArgs e)
{
e.Graphics.SetClip(e.ClipRectangle);
e.Graphics.Clear(ColorScheme?.BackgroundColor ?? Colors.White);
var bgColor = ColorScheme?.BackgroundColor ?? Colors.White;
e.Graphics.FillRectangle(bgColor, 0, 0, _imageView.Width, _imageView.Height);
if (Image != null)
{
e.Graphics.DrawRectangle(
Expand Down

0 comments on commit 1f0e529

Please sign in to comment.