Skip to content

Commit

Permalink
fix: sharper images on non-retina displays
Browse files Browse the repository at this point in the history
  • Loading branch information
lwouis committed Mar 10, 2020
1 parent a2bb19f commit 1bb4d2a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/api-wrappers/HelperExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,15 @@ extension NSControl {
}
}
}

extension NSImage {
// copy and resize an image using high quality interpolation
func resizedCopy(_ width: CGFloat, _ height: CGFloat) -> NSImage {
let img = NSImage(size: CGSize(width: width, height: height))
img.lockFocus()
NSGraphicsContext.current?.imageInterpolation = .high
draw(in: NSMakeRect(0, 0, width, height), from: NSMakeRect(0, 0, size.width, size.height), operation: .copy, fraction: 1)
img.unlockFocus()
return img
}
}
4 changes: 2 additions & 2 deletions src/ui/FeedbackWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class FeedbackWindow: NSWindow {
}

private func setupView() {
let appIcon = NSImageView(image: App.shared.applicationIconImage)
appIcon.fit(80, 80)
let appIcon = NSImageView(image: NSImage(named: "app-icon")!.resizedCopy(80, 80))
appIcon.imageScaling = .scaleNone
let appText = NSStackView(views: [
BoldLabel(NSLocalizedString("Share improvement ideas, or report bugs", comment: "")),
HyperlinkLabel(NSLocalizedString("View existing discussions", comment: ""), App.repository + "/issues"),
Expand Down
4 changes: 2 additions & 2 deletions src/ui/preferences-window/tabs/AboutTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class AboutTab: NSObject {
}

static func makeView() -> NSGridView {
let appIcon = NSImageView(image: App.shared.applicationIconImage)
appIcon.fit(150, 150)
let appIcon = NSImageView(image: NSImage(named: "app-icon")!.resizedCopy(150, 150))
appIcon.imageScaling = .scaleNone
let appText = NSStackView(views: [
BoldLabel(App.name),
NSTextField(wrappingLabelWithString: NSLocalizedString("Version", comment: "") + " " + App.version),
Expand Down

0 comments on commit 1bb4d2a

Please sign in to comment.