mirror of
https://github.com/exyte/Macaw.git
synced 2024-09-11 05:05:23 +03:00
Merge pull request #725 from f3dm76/fix/shape-animation
Fix stroke+fill color animations
This commit is contained in:
commit
130875b268
@ -26,7 +26,9 @@ func addShapeAnimation(_ animation: BasicAnimation, _ context: AnimationContext,
|
|||||||
let transactionsDisabled = CATransaction.disableActions()
|
let transactionsDisabled = CATransaction.disableActions()
|
||||||
CATransaction.setDisableActions(true)
|
CATransaction.setDisableActions(true)
|
||||||
|
|
||||||
let fromShape = shapeAnimation.getVFunc()(0.0)
|
guard let fromShape = SceneUtils.copyNode(shapeAnimation.getVFunc()(0.0)) as? Shape else {
|
||||||
|
return
|
||||||
|
}
|
||||||
let toShape = shapeAnimation.getVFunc()(animation.autoreverses ? 0.5 : 1.0)
|
let toShape = shapeAnimation.getVFunc()(animation.autoreverses ? 0.5 : 1.0)
|
||||||
let duration = animation.autoreverses ? animation.getDuration() / 2.0 : animation.getDuration()
|
let duration = animation.autoreverses ? animation.getDuration() / 2.0 : animation.getDuration()
|
||||||
|
|
||||||
@ -54,16 +56,28 @@ func addShapeAnimation(_ animation: BasicAnimation, _ context: AnimationContext,
|
|||||||
animation.progress = animation.manualStop ? 0.0 : 1.0
|
animation.progress = animation.manualStop ? 0.0 : 1.0
|
||||||
|
|
||||||
if !animation.autoreverses && finished {
|
if !animation.autoreverses && finished {
|
||||||
|
if fromShape.form != toShape.form {
|
||||||
shape.form = toShape.form
|
shape.form = toShape.form
|
||||||
|
}
|
||||||
|
if fromShape.stroke != toShape.stroke {
|
||||||
shape.stroke = toShape.stroke
|
shape.stroke = toShape.stroke
|
||||||
|
}
|
||||||
|
if fromShape.fill != toShape.fill {
|
||||||
shape.fill = toShape.fill
|
shape.fill = toShape.fill
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if !finished {
|
if !finished {
|
||||||
animation.progress = 0.0
|
animation.progress = 0.0
|
||||||
shape.form = fromShape.form
|
if fromShape.form != toShape.form {
|
||||||
shape.stroke = fromShape.stroke
|
shape.form = toShape.form
|
||||||
shape.fill = fromShape.fill
|
}
|
||||||
|
if fromShape.stroke != toShape.stroke {
|
||||||
|
shape.stroke = toShape.stroke
|
||||||
|
}
|
||||||
|
if fromShape.fill != toShape.fill {
|
||||||
|
shape.fill = toShape.fill
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer.freeLayer()
|
renderer.freeLayer()
|
||||||
|
@ -4,7 +4,7 @@ open class Fill: Equatable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func equals<T>(other: T) -> Bool where T: Fill {
|
func equals<T>(other: T) -> Bool where T: Fill {
|
||||||
fatalError("Equals can't be realised for Fill")
|
fatalError("Equals can't be implemented for Fill")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
open class Stroke {
|
open class Stroke: Equatable {
|
||||||
|
|
||||||
public let fill: Fill
|
public let fill: Fill
|
||||||
public let width: Double
|
public let width: Double
|
||||||
@ -18,3 +18,13 @@ open class Stroke {
|
|||||||
self.offset = offset
|
self.offset = offset
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func ==<T> (lhs: T, rhs: T) -> Bool where T: Stroke {
|
||||||
|
return lhs.fill == rhs.fill
|
||||||
|
&& lhs.width == rhs.width
|
||||||
|
&& lhs.cap == rhs.cap
|
||||||
|
&& lhs.join == rhs.join
|
||||||
|
&& lhs.miterLimit == rhs.miterLimit
|
||||||
|
&& lhs.dashes == rhs.dashes
|
||||||
|
&& lhs.offset == rhs.offset
|
||||||
|
}
|
||||||
|
@ -45,4 +45,13 @@ open class Arc: Locus {
|
|||||||
|
|
||||||
return PathBuilder(segment: PathSegment(type: .M, data: [x1, y1])).A(rx, ry, 0.0, largeArcFlag, sweepFlag, x2, y2).build()
|
return PathBuilder(segment: PathSegment(type: .M, data: [x1, y1])).A(rx, ry, 0.0, largeArcFlag, sweepFlag, x2, y2).build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func equals<T>(other: T) -> Bool where T: Locus {
|
||||||
|
guard let other = other as? Arc else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return ellipse == other.ellipse
|
||||||
|
&& shift == other.shift
|
||||||
|
&& extent == other.extent
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,4 +25,13 @@ open class Circle: Locus {
|
|||||||
override open func toPath() -> Path {
|
override open func toPath() -> Path {
|
||||||
return MoveTo(x: cx, y: cy).m(-r, 0).a(r, r, 0.0, true, false, r * 2.0, 0.0).a(r, r, 0.0, true, false, -(r * 2.0), 0.0).build()
|
return MoveTo(x: cx, y: cy).m(-r, 0).a(r, r, 0.0, true, false, r * 2.0, 0.0).a(r, r, 0.0, true, false, -(r * 2.0), 0.0).build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func equals<T>(other: T) -> Bool where T: Locus {
|
||||||
|
guard let other = other as? Circle else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return cx == other.cx
|
||||||
|
&& cy == other.cy
|
||||||
|
&& r == other.r
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,4 +23,14 @@ open class Ellipse: Locus {
|
|||||||
open func arc(shift: Double, extent: Double) -> Arc {
|
open func arc(shift: Double, extent: Double) -> Arc {
|
||||||
return Arc(ellipse: self, shift: shift, extent: extent)
|
return Arc(ellipse: self, shift: shift, extent: extent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func equals<T>(other: T) -> Bool where T: Locus {
|
||||||
|
guard let other = other as? Ellipse else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return cx == other.cx
|
||||||
|
&& cy == other.cy
|
||||||
|
&& rx == other.rx
|
||||||
|
&& ry == other.ry
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,4 +26,14 @@ open class Line: Locus {
|
|||||||
override open func toPath() -> Path {
|
override open func toPath() -> Path {
|
||||||
return MoveTo(x: x1, y: y1).lineTo(x: x2, y: y2).build()
|
return MoveTo(x: x1, y: y1).lineTo(x: x2, y: y2).build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func equals<T>(other: T) -> Bool where T: Locus {
|
||||||
|
guard let other = other as? Line else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return x1 == other.x1
|
||||||
|
&& y1 == other.y1
|
||||||
|
&& x2 == other.x2
|
||||||
|
&& y2 == other.y2
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
open class Locus {
|
open class Locus: Equatable {
|
||||||
|
|
||||||
public init() {
|
public init() {
|
||||||
}
|
}
|
||||||
@ -38,4 +38,13 @@ open class Locus {
|
|||||||
open func toPath() -> Path {
|
open func toPath() -> Path {
|
||||||
fatalError("Unsupported locus: \(self)")
|
fatalError("Unsupported locus: \(self)")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func equals<T>(other: T) -> Bool where T: Locus {
|
||||||
|
fatalError("Equals can't be implemented for Locus")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public func ==<T> (lhs: T, rhs: T) -> Bool where T: Locus {
|
||||||
|
return type(of: lhs) == type(of: rhs)
|
||||||
|
&& lhs.equals(other: rhs)
|
||||||
}
|
}
|
||||||
|
@ -19,4 +19,12 @@ open class Path: Locus {
|
|||||||
override open func toPath() -> Path {
|
override open func toPath() -> Path {
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func equals<T>(other: T) -> Bool where T: Locus {
|
||||||
|
guard let other = other as? Path else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return segments == other.segments
|
||||||
|
&& fillRule == other.fillRule
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
open class PathSegment {
|
open class PathSegment: Equatable {
|
||||||
|
|
||||||
public let type: PathSegmentType
|
public let type: PathSegmentType
|
||||||
public let data: [Double]
|
public let data: [Double]
|
||||||
@ -18,4 +18,9 @@ open class PathSegment {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static func == (lhs: PathSegment, rhs: PathSegment) -> Bool {
|
||||||
|
return lhs.type == rhs.type
|
||||||
|
&& lhs.data == rhs.data
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,13 +38,17 @@ open class Point: Locus {
|
|||||||
override open func toPath() -> Path {
|
override open func toPath() -> Path {
|
||||||
return MoveTo(x: x, y: y).lineTo(x: x, y: y).build()
|
return MoveTo(x: x, y: y).lineTo(x: x, y: y).build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func equals<T>(other: T) -> Bool where T: Locus {
|
||||||
|
guard let other = other as? Point else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return x == other.y
|
||||||
|
&& y == other.y
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Point: Equatable {
|
extension Point {
|
||||||
public static func == (lhs: Point, rhs: Point) -> Bool {
|
|
||||||
return lhs.x == rhs.x
|
|
||||||
&& lhs.y == rhs.y
|
|
||||||
}
|
|
||||||
|
|
||||||
public static func - (lhs: Point, rhs: Point) -> Size {
|
public static func - (lhs: Point, rhs: Point) -> Size {
|
||||||
return Size(w: lhs.x - rhs.x, h: lhs.y - rhs.y)
|
return Size(w: lhs.x - rhs.x, h: lhs.y - rhs.y)
|
||||||
|
@ -60,4 +60,11 @@ open class Polygon: Locus {
|
|||||||
}
|
}
|
||||||
return pb.close().build()
|
return pb.close().build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func equals<T>(other: T) -> Bool where T: Locus {
|
||||||
|
guard let other = other as? Polygon else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return points == other.points
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,4 +60,11 @@ open class Polyline: Locus {
|
|||||||
}
|
}
|
||||||
return pb.build()
|
return pb.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func equals<T>(other: T) -> Bool where T: Locus {
|
||||||
|
guard let other = other as? Polyline else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return points == other.points
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,13 +73,14 @@ open class Rect: Locus {
|
|||||||
override open func toPath() -> Path {
|
override open func toPath() -> Path {
|
||||||
return MoveTo(x: x, y: y).lineTo(x: x, y: y + h).lineTo(x: x + w, y: y + h).lineTo(x: x + w, y: y).close().build()
|
return MoveTo(x: x, y: y).lineTo(x: x, y: y + h).lineTo(x: x + w, y: y + h).lineTo(x: x + w, y: y).close().build()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
extension Rect {
|
override func equals<T>(other: T) -> Bool where T: Locus {
|
||||||
public static func == (lhs: Rect, rhs: Rect) -> Bool {
|
guard let other = other as? Rect else {
|
||||||
return lhs.x == rhs.x
|
return false
|
||||||
&& lhs.y == rhs.y
|
}
|
||||||
&& lhs.w == rhs.w
|
return x == other.y
|
||||||
&& lhs.h == rhs.h
|
&& y == other.y
|
||||||
|
&& w == other.w
|
||||||
|
&& h == other.h
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,4 +13,13 @@ open class RoundRect: Locus {
|
|||||||
override open func bounds() -> Rect {
|
override open func bounds() -> Rect {
|
||||||
return rect
|
return rect
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func equals<T>(other: T) -> Bool where T: Locus {
|
||||||
|
guard let other = other as? RoundRect else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return rect == other.rect
|
||||||
|
&& rx == other.rx
|
||||||
|
&& ry == other.ry
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,4 +18,12 @@ open class TransformedLocus: Locus {
|
|||||||
open override func bounds() -> Rect {
|
open override func bounds() -> Rect {
|
||||||
return locus.bounds().applying(transform)
|
return locus.bounds().applying(transform)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func equals<T>(other: T) -> Bool where T: Locus {
|
||||||
|
guard let other = other as? TransformedLocus else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return locus == other.locus
|
||||||
|
&& transform == other.transform
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user