1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-25 06:43:24 +03:00

GH-296 Better drag image

This commit is contained in:
Tae Won Ha 2016-11-17 22:51:47 +01:00
parent 278c1af454
commit 53f5928aa3
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44

View File

@ -152,11 +152,24 @@ extension WorkspaceToolButton {
self.dehighlight()
}
// https://www.raywenderlich.com/136272/drag-and-drop-tutorial-for-macos
// Modified version of snapshot() from https://www.raywenderlich.com/136272/drag-and-drop-tutorial-for-macos
fileprivate func snapshot() -> NSImage {
let pdfData = self.dataWithPDF(inside: self.bounds)
let image = NSImage(data: pdfData)
return image ?? NSImage()
guard let image = NSImage(data: pdfData) else {
return NSImage()
}
let result = NSImage()
let rect = CGRect(origin: .zero, size: image.size)
result.size = rect.size
result.lockFocus()
NSColor.controlShadowColor.set()
NSRectFill(rect)
image.draw(in: rect)
result.unlockFocus()
return result
}
}