Skip to content

STY: Update macosx zoom rect styling #24367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/_macosx.m
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,18 @@ -(void)drawRect:(NSRect)rect
goto exit;
}
if (!NSIsEmptyRect(rubberband)) {
NSFrameRect(rubberband);
// We use bezier paths so we can stroke the outside with a dash
// pattern alternating white/black with two separate paths offset
// in phase.
NSBezierPath *white_path = [NSBezierPath bezierPathWithRect: rubberband];
NSBezierPath *black_path = [NSBezierPath bezierPathWithRect: rubberband];
CGFloat dash_pattern[2] = {3, 3};
[white_path setLineDash: dash_pattern count: 2 phase: 0];
[black_path setLineDash: dash_pattern count: 2 phase: 3];
[[NSColor whiteColor] setStroke];
[white_path stroke];
[[NSColor blackColor] setStroke];
[black_path stroke];
}

exit:
Expand Down Expand Up @@ -1526,9 +1537,11 @@ - (void)otherMouseDragged:(NSEvent *)event { [self mouseDragged: event]; }

- (void)setRubberband:(NSRect)rect
{
if (!NSIsEmptyRect(rubberband)) { [self setNeedsDisplayInRect: rubberband]; }
// The space we want to redraw is a union of the previous rubberband
// with the new rubberband and then expanded (negative inset) by one
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checking if this is in logical space or physical space (i.e., should be one or one * display ratio)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On HiDPI, this still clears the region and I'm not sure we want to bring in the deviceScale/contextRegion if we don't absolutely need to here. The linewidth is drawn in points and centered on the rectangle area, so the default linewidth of 1 expands 0.5 points on either side of the rect. (linewidth section from here
https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CocoaDrawingGuide/Paths/Paths.html#//apple_ref/doc/uid/TP40003290-CH206-BBCDEJGD)

// in each direction to account for the stroke linewidth.
[self setNeedsDisplayInRect: NSInsetRect(NSUnionRect(rect, rubberband), -1, -1)];
rubberband = rect;
[self setNeedsDisplayInRect: rubberband];
}

- (void)removeRubberband
Expand Down