OSDN Git Service

描画関数群を変更
authormasakih <masakih@users.sourceforge.jp>
Fri, 21 Jul 2017 15:48:45 +0000 (00:48 +0900)
committermasakih <masakih@users.sourceforge.jp>
Fri, 21 Jul 2017 15:48:45 +0000 (00:48 +0900)
KCD/BorderTextField.swift
KCD/Graphics.swift
KCD/SlotItemFrameView.swift
KCD/SlotItemLevelView.swift
KCD/StrengthenListItemView.swift

index d8f8c1c..966c306 100644 (file)
@@ -17,11 +17,12 @@ class BorderTextField: NSTextField {
         let height = bounds.height
         NSColor.controlShadowColor.set()
         NSBezierPath.setDefaultLineWidth(1.0)
-        multiline {
-            [(NSPoint, NSPoint)]()
-                .appended { (NSPoint(x: 3, y: height), NSPoint(x: bounds.maxX, y: height)) }
-                .appended { (NSPoint(x: width, y: 0), NSPoint(x: width, y: height)) }
-            }
-            .map { $0.stroke() }
+        multiline(lines:
+            [
+                (NSPoint(x: 3, y: height), NSPoint(x: bounds.maxX, y: height)),
+                (NSPoint(x: width, y: 0), NSPoint(x: width, y: height))
+            ]
+            )
+            .stroke()
     }
 }
index b601d82..eec47b3 100644 (file)
@@ -8,32 +8,58 @@
 
 import Cocoa
 
+extension NSBezierPath {
+    
+    convenience init(start point: NSPoint) {
+        
+        self.init()
+        move(to: point)
+    }
+}
+
 func polygon(_ point: () -> [NSPoint]) -> NSBezierPath? {
-    let points = point()
-    let count = points.count
-    guard count > 2 else { return nil }
-    let path = NSBezierPath()
-    path.move(to: points[0])
-    points[1..<count].forEach { path.line(to: $0) }
-    path.close()
+    
+    return polygon(points: point())
+}
+func polygon(points: [NSPoint]) -> NSBezierPath? {
+    
+    guard points.count > 2 else { return nil }
+    
+    let path = polyline(points: points)
+    path?.close()
     
     return path
 }
+
 func polyline(_ point: () -> [NSPoint]) -> NSBezierPath? {
-    let points = point()
-    let count = points.count
-    guard count > 1 else { return nil }
-    let path = NSBezierPath()
-    path.move(to: points[0])
-    points[1..<count].forEach { path.line(to: $0) }
     
+    return polyline(points: point())
+}
+func polyline(points: [NSPoint]) -> NSBezierPath? {
+    
+    guard points.count > 1 else { return nil }
+    
+    return points.dropFirst().reduce(NSBezierPath(start: points[0]), lineToPoint)
+}
+func lineToPoint(path: NSBezierPath, point: NSPoint) -> NSBezierPath {
+    
+    path.line(to: point)
     return path
 }
-func multiline(_ lines: () -> [(NSPoint, NSPoint)]) -> NSBezierPath? {
-    let path = NSBezierPath()
-    lines().forEach {
-        path.move(to: $0.0)
-        path.line(to: $0.1)
-    }
+
+func multiline(_ lines: () -> [(NSPoint, NSPoint)]) -> NSBezierPath {
+    
+    return multiline(lines: lines())
+}
+
+func multiline(lines: [(NSPoint, NSPoint)]) -> NSBezierPath {
+    
+    return lines.reduce(NSBezierPath(), line)
+}
+
+func line(_ path: NSBezierPath, _ points: (NSPoint, NSPoint)) -> NSBezierPath {
+    
+    path.move(to: points.0)
+    path.line(to: points.1)
     return path
 }
index 90964a4..6a78328 100644 (file)
@@ -24,6 +24,6 @@ class SlotItemFrameView: NSBox {
                 .appended { (NSPoint(x: 0, y: 34.5), NSPoint(x: width, y: 34.5)) }
                 .appended { (NSPoint(x: 0, y: 51.5), NSPoint(x: width, y: 51.5)) }
             }
-            .map { $0.stroke() }
+            .stroke()
     }
 }
index fc43990..564096e 100644 (file)
@@ -67,7 +67,7 @@ class SlotItemLevelView: NSTextField {
         let width = bounds.width
         let height = bounds.height
         let path = multiline { [(NSPoint(x: width - offset, y: 0), NSPoint(x: width - offset, y: height))] }
-        path?.lineWidth = 1.0
+        path.lineWidth = 1.0
         return path
     }
     private var levelTwoBezierPath: NSBezierPath? {
@@ -80,7 +80,7 @@ class SlotItemLevelView: NSTextField {
                     (NSPoint(x: width - offset - padding, y: 0), NSPoint(x: width - offset - padding, y: height))
             }
         }
-        path?.lineWidth = 1.0
+        path.lineWidth = 1.0
         return path
     }
     private var levelThreeBezierPath: NSBezierPath? {
@@ -97,7 +97,7 @@ class SlotItemLevelView: NSTextField {
                      NSPoint(x: width - offset - padding * 2, y: height))
             }
         }
-        path?.lineWidth = 1.0
+        path.lineWidth = 1.0
         return path
     }
     private var levelFourBezierPath: NSBezierPath? {
@@ -107,7 +107,7 @@ class SlotItemLevelView: NSTextField {
             [(NSPoint, NSPoint)]()
                 .appended { (NSPoint(x: width - offset - slideOffset, y: 0), NSPoint(x: width - offset, y: height)) }
         }
-        path?.lineWidth = 2.0
+        path.lineWidth = 2.0
         return path
     }
     private var levelFiveBezierPath: NSBezierPath? {
@@ -121,7 +121,7 @@ class SlotItemLevelView: NSTextField {
                      NSPoint(x: width - offset - padding, y: height))
             }
         }
-        path?.lineWidth = 2.0
+        path.lineWidth = 2.0
         return path
     }
     private var levelSixBezierPath: NSBezierPath? {
@@ -139,7 +139,7 @@ class SlotItemLevelView: NSTextField {
                      NSPoint(x: width - offset - padding * 2, y: height))
             }
         }
-        path?.lineWidth = 2.0
+        path.lineWidth = 2.0
         return path
     }
     private var levelSevenBezierPath: NSBezierPath? {
index aab215a..ea449eb 100644 (file)
@@ -18,14 +18,15 @@ class StrengthenListItemView: NSBox {
         borderColor.set()
         NSBezierPath.setDefaultLineWidth(borderWidth)
         NSBezierPath.stroke(bounds)
-        multiline {
-            [(NSPoint, NSPoint)]()
-                .appended { (NSPoint(x: 29.5, y: 0), NSPoint(x: 29.5, y: height)) }
-                .appended { (NSPoint(x: 67.5, y: 0), NSPoint(x: 67.5, y: height)) }
-                .appended { (NSPoint(x: 209.5, y: 0), NSPoint(x: 209.5, y: height)) }
-                .appended { (NSPoint(x: 0, y: 17.5), NSPoint(x: width, y: 17.5)) }
-                .appended { (NSPoint(x: 0, y: 34.5), NSPoint(x: width, y: 34.5)) }
-            }
-            .map { $0.stroke() }
+        multiline(lines:
+            [
+                (NSPoint(x: 29.5, y: 0), NSPoint(x: 29.5, y: height)),
+                (NSPoint(x: 67.5, y: 0), NSPoint(x: 67.5, y: height)),
+                (NSPoint(x: 209.5, y: 0), NSPoint(x: 209.5, y: height)),
+                (NSPoint(x: 0, y: 17.5), NSPoint(x: width, y: 17.5)),
+                (NSPoint(x: 0, y: 34.5), NSPoint(x: width, y: 34.5))
+            ]
+            )
+            .stroke()
     }
 }