OSDN Git Service

Doutaku を 1.0 にアップデート
[kcd/KCD.git] / KCD / Graphics.swift
1 //
2 //  Graphics.swift
3 //  KCD
4 //
5 //  Created by Hori,Masaki on 2017/03/01.
6 //  Copyright © 2017年 Hori,Masaki. All rights reserved.
7 //
8
9 import Cocoa
10
11 struct Polygon {
12     
13     private let bezierPath: NSBezierPath
14     
15     init() {
16         
17         bezierPath = NSBezierPath()
18     }
19     
20     init(lineWidth: CGFloat) {
21         
22         self.init()
23         bezierPath.lineWidth = lineWidth
24     }
25     
26     init(point: NSPoint) {
27         
28         self.init()
29         bezierPath.move(to: point)
30     }
31     
32     private init(path: NSBezierPath) {
33         
34         bezierPath = path
35     }
36     
37     var lineWidth: CGFloat {
38         get { return bezierPath.lineWidth }
39         set { bezierPath.lineWidth = lineWidth }
40     }
41     
42     func line(to point: NSPoint) -> Polygon {
43         
44         bezierPath.line(to: point)
45         
46         return Polygon(path: bezierPath)
47     }
48     
49     func move(to point: NSPoint) -> Polygon {
50         
51         bezierPath.move(to: point)
52         
53         return Polygon(path: bezierPath)
54     }
55     
56     func close() -> Polygon {
57         
58         bezierPath.close()
59         
60         return Polygon(path: bezierPath)
61     }
62     
63     func stroke() {
64         
65         bezierPath.stroke()
66     }
67     
68     func fill() {
69         
70         bezierPath.fill()
71     }
72 }