From 53f5928aa3cccac2526a3a28c1ab7e4603ac1b98 Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Thu, 17 Nov 2016 22:51:47 +0100 Subject: [PATCH] GH-296 Better drag image --- VimR/Workspace/WorkspaceToolButton.swift | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/VimR/Workspace/WorkspaceToolButton.swift b/VimR/Workspace/WorkspaceToolButton.swift index 34ae71a2..23936db6 100644 --- a/VimR/Workspace/WorkspaceToolButton.swift +++ b/VimR/Workspace/WorkspaceToolButton.swift @@ -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 } }