-
Notifications
You must be signed in to change notification settings - Fork 13
/
actor_rectangle.swift
59 lines (50 loc) · 1.88 KB
/
actor_rectangle.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// actor_rectangle.swift
// Flare
//
// Created by Umberto Sonnino on 2/20/19.
// Copyright © 2019 2Dimensions. All rights reserved.
//
import Foundation
public class ActorRectangle: ActorProceduralPath {
var _radius = 0.0
override public var isClosed: Bool { return true }
var doesDraw: Bool { return !self.renderCollapsed }
var radius: Double {
get { return _radius }
set {
if newValue != _radius {
_radius = newValue
invalidateDrawable()
}
}
}
override public var points: [PathPoint] {
let hw = Float32(self._width/2)
let hh = Float32(self._height/2)
let minH = Float32(min(hw, hh))
let renderRadius = min(_radius, Double(minH))
return [
StraightPathPoint.init(fromValues: Vec2D(fromValues: -hw, -hh), renderRadius),
StraightPathPoint.init(fromValues: Vec2D(fromValues: hw, -hh), renderRadius),
StraightPathPoint.init(fromValues: Vec2D(fromValues: hw, hh), renderRadius),
StraightPathPoint.init(fromValues: Vec2D(fromValues: -hw, hh), renderRadius),
]
}
override public func invalidatePath() {}
override func makeInstance(_ resetArtboard: ActorArtboard) -> ActorComponent {
let rectangle = ActorRectangle()
rectangle.copyRectangle(self, resetArtboard)
return rectangle
}
func copyRectangle(_ node: ActorRectangle, _ ab: ActorArtboard) {
copyPath(node, ab)
_radius = node._radius
}
func readRectangle(_ artboard: ActorArtboard, _ reader: StreamReader) {
self.readNode(artboard, reader)
self.width = Double(reader.readFloat32(label: "width"))
self.height = Double(reader.readFloat32(label: "height"))
self._radius = Double(reader.readFloat32(label: "cornerRadius"))
}
}