Try to minimize redrawing.
This commit is contained in:
1 file changed
+17
-9
@@ -165,6 +165,8 @@ class ArtworkSelectorViewItemView: NSView {
|
|||||||
layer?.addSublayer(backgroundLayer)
|
layer?.addSublayer(backgroundLayer)
|
||||||
layer?.addSublayer(emptyLayer)
|
layer?.addSublayer(emptyLayer)
|
||||||
layer?.addSublayer(imageLayer)
|
layer?.addSublayer(imageLayer)
|
||||||
|
|
||||||
|
layerContentsRedrawPolicy = .onSetNeedsDisplay
|
||||||
}
|
}
|
||||||
|
|
||||||
override func hitTest(_ point: NSPoint) -> NSView? {
|
override func hitTest(_ point: NSPoint) -> NSView? {
|
||||||
@@ -181,6 +183,21 @@ class ArtworkSelectorViewItemView: NSView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override var wantsUpdateLayer: Bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override func updateLayer() {
|
||||||
|
if #available(OSX 10.14, *) {
|
||||||
|
imageLayer.shadowColor = NSColor.labelColor.cgColor
|
||||||
|
backgroundLayer.backgroundColor = NSColor.unemphasizedSelectedContentBackgroundColor.cgColor
|
||||||
|
emptyLayer.strokeColor = NSColor.secondarySelectedControlColor.cgColor
|
||||||
|
emptyLayer.fillColor = NSColor.windowBackgroundColor.cgColor
|
||||||
|
} else {
|
||||||
|
backgroundLayer.backgroundColor = NSColor.controlHighlightColor.cgColor
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override func layout() {
|
override func layout() {
|
||||||
super.layout()
|
super.layout()
|
||||||
imageLayer.bounds = CGRect(x: 0, y: 0, width: bounds.width - 8, height: bounds.height - 44)
|
imageLayer.bounds = CGRect(x: 0, y: 0, width: bounds.width - 8, height: bounds.height - 44)
|
||||||
@@ -191,15 +208,6 @@ class ArtworkSelectorViewItemView: NSView {
|
|||||||
path.addRoundedRect(in: emptyLayer.bounds, cornerWidth: 14, cornerHeight: 14)
|
path.addRoundedRect(in: emptyLayer.bounds, cornerWidth: 14, cornerHeight: 14)
|
||||||
emptyLayer.path = path
|
emptyLayer.path = path
|
||||||
|
|
||||||
if #available(OSX 10.14, *) {
|
|
||||||
imageLayer.shadowColor = NSColor.labelColor.cgColor
|
|
||||||
backgroundLayer.backgroundColor = NSColor.unemphasizedSelectedContentBackgroundColor.cgColor
|
|
||||||
emptyLayer.strokeColor = NSColor.secondarySelectedControlColor.cgColor
|
|
||||||
emptyLayer.fillColor = NSColor.windowBackgroundColor.cgColor
|
|
||||||
} else {
|
|
||||||
backgroundLayer.backgroundColor = NSColor.controlHighlightColor.cgColor
|
|
||||||
}
|
|
||||||
|
|
||||||
if let image = imageLayer.contents as? NSImage {
|
if let image = imageLayer.contents as? NSImage {
|
||||||
let rect = AVMakeRect(aspectRatio: image.size, insideRect: imageLayer.bounds)
|
let rect = AVMakeRect(aspectRatio: image.size, insideRect: imageLayer.bounds)
|
||||||
let path = CGMutablePath()
|
let path = CGMutablePath()
|
||||||
|
|||||||
Reference in new issue
Block a user