5 // Created by Hori,Masaki on 2017/01/01.
6 // Copyright © 2017年 Hori,Masaki. All rights reserved.
11 enum DamageType: Int {
19 final class DamageView: NSView {
21 @objc dynamic var damageType: Int = 0 {
24 guard let v = DamageType(rawValue: newValue) else {
26 print("Can not set damageType")
30 if innerDamageType != v { needsDisplay = true }
36 var controlSize: NSControl.ControlSize = .regular
37 private var innerDamageType: DamageType = .none
38 private var color: NSColor? {
40 switch innerDamageType {
45 return #colorLiteral(red: 1.000, green: 0.956, blue: 0.012, alpha: 0.5)
48 return NSColor.orange.withAlphaComponent(0.5)
51 return NSColor.red.withAlphaComponent(0.5)
55 private var borderColor: NSColor? {
57 switch innerDamageType {
62 return NSColor.orange.withAlphaComponent(0.5)
65 return NSColor.orange.withAlphaComponent(0.9)
68 return NSColor.red.withAlphaComponent(0.9)
72 private var path: NSBezierPath? {
83 private var pathForRegular: NSBezierPath? {
85 let height = bounds.height
87 switch innerDamageType {
92 return polygon(points:
94 NSPoint(x: 35.0, y: height - 2.0),
95 NSPoint(x: 0.0, y: height - 2.0),
96 NSPoint(x: 0.0, y: height - 35.0)
100 return polygon(points:
102 NSPoint(x: 50.0, y: height - 2.0),
103 NSPoint(x: 25.0, y: height - 2.0),
104 NSPoint(x: 0.0, y: height - 25.0),
105 NSPoint(x: 0.0, y: height - 50.0)
109 let p = polygon(points:
111 NSPoint(x: 60.0, y: height - 2.0),
112 NSPoint(x: 53.0, y: height - 2.0),
113 NSPoint(x: 0.0, y: height - 53.0),
114 NSPoint(x: 0.0, y: height - 60.0)
118 NSPoint(x: 47.0, y: height - 2.0),
119 NSPoint(x: 23.0, y: height - 2.0),
120 NSPoint(x: 0.0, y: height - 23.0),
121 NSPoint(x: 0.0, y: height - 47.0)
123 .map { p?.append($0) }
128 private var pathForSmall: NSBezierPath? {
130 let height = bounds.height
132 switch innerDamageType {
137 return polygon(points:
139 NSPoint(x: 35.0, y: height - 2.0),
140 NSPoint(x: 0.0, y: height - 2.0),
141 NSPoint(x: 0.0, y: height - 35.0)
145 return polygon(points:
147 NSPoint(x: 50.0, y: height - 2.0),
148 NSPoint(x: 25.0, y: height - 2.0),
149 NSPoint(x: 0.0, y: height - 25.0),
150 NSPoint(x: 0.0, y: height - 50.0)
154 let p = polygon(points:
156 NSPoint(x: 55.0, y: height - 2.0),
157 NSPoint(x: 48.0, y: height - 2.0),
158 NSPoint(x: 0.0, y: height - 48.0),
159 NSPoint(x: 0.0, y: height - 55.0)
163 NSPoint(x: 42.0, y: height - 2.0),
164 NSPoint(x: 20.0, y: height - 2.0),
165 NSPoint(x: 0.0, y: height - 20.0),
166 NSPoint(x: 0.0, y: height - 42.0)
168 .map { p?.append($0) }
173 override func draw(_ dirtyRect: NSRect) {
175 super.draw(dirtyRect)
178 borderColor?.setStroke()