OSDN Git Service

Equatableを自動実装させるようにした
[kcd/KCD.git] / KCD / NSTextFieldExtension.swift
index e0b9b33..dc620d8 100644 (file)
@@ -12,48 +12,49 @@ extension NSTextField {
     
     func maskImage(middle1: CGFloat, middle2: CGFloat) -> CGImage {
         
-        let colorspace = CGColorSpaceCreateDeviceGray()
-        
         guard let maskContext = CGContext(data: nil,
                                           width: Int(bounds.width),
                                           height: Int(bounds.height),
                                           bitsPerComponent: 8,
                                           bytesPerRow: Int(bounds.width),
-                                          space: colorspace,
-                                          bitmapInfo: 0)
-            else { fatalError("Can not create bitmap context") }
+                                          space: CGColorSpaceCreateDeviceGray(),
+                                          bitmapInfo: 0) else {
+                                            
+                                            fatalError("Can not create bitmap context")
+        }
         
         let maskGraphicsContext = NSGraphicsContext(cgContext: maskContext, flipped: false)
         
-        
         NSGraphicsContext.saveGraphicsState()
         defer { NSGraphicsContext.restoreGraphicsState() }
         
-        NSGraphicsContext.setCurrent(maskGraphicsContext)
+        NSGraphicsContext.current = maskGraphicsContext
         
-        let gradient = NSGradient(colorsAndLocations: (NSColor.white, 0.0),
-                                  (NSColor.white, middle1),
-                                  (NSColor.black, middle2),
-                                  (NSColor.black, 1.0))
+        let gradient = NSGradient(colorsAndLocations: (.white, 0.0),
+                                  (.white, middle1),
+                                  (.black, middle2),
+                                  (.black, 1.0))
         gradient?.draw(in: bounds, angle: 0.0)
         
-        guard let r = maskContext.makeImage()
-            else { fatalError(" can not create image from context") }
+        guard let r = maskContext.makeImage() else {
+            
+            fatalError(" can not create image from context")
+        }
         
         return r
     }
     
-    func isCharacterProtrude(kern: CGFloat = 0) -> Bool {
+    func isCharacterProtrude() -> Bool {
         
         guard let currentFont = font else {
             
-            Swift.print("TextField dose not set font")
+            Logger.shared.log("TextField dose not set font")
             
             return false
         }
         
         let string = stringValue as NSString
-        let size = string.size(withAttributes: [NSFontAttributeName: currentFont, NSKernAttributeName: kern])
+        let size = string.size(withAttributes: [.font: currentFont])
         
         return bounds.size.width - size.width < 3
     }