mirror of
https://github.com/exyte/Macaw.git
synced 2024-09-21 09:59:10 +03:00
Shape strokeVar animation test
This commit is contained in:
parent
0b7ca9bb50
commit
bbdc28e9ff
@ -9,6 +9,6 @@
|
||||
import Foundation
|
||||
|
||||
|
||||
open class AnimatableVariable<T: Interpolable>: Variable<T> {
|
||||
open class AnimatableVariable<T>: Variable<T> {
|
||||
internal var node: Node?
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
import Foundation
|
||||
|
||||
public protocol DoubleInterpolation: Interpolable {
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
//
|
||||
// FillInterpolation.swift
|
||||
// Pods
|
||||
//
|
||||
// Created by Victor Sukochev on 14/02/2017.
|
||||
//
|
||||
//
|
||||
|
||||
public protocol FillInterpolation: Interpolable {
|
||||
|
||||
}
|
||||
|
||||
extension Fill: FillInterpolation {
|
||||
public func interpolate(_ endValue: Fill, progress: Double) -> Self {
|
||||
return self
|
||||
}
|
||||
}
|
@ -1,5 +1,3 @@
|
||||
import Foundation
|
||||
|
||||
public protocol Interpolable {
|
||||
func interpolate(_ endValue: Self, progress: Double) -> Self
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
public protocol LocusInterpolation: Interpolable {
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
//
|
||||
// StrokeInterpolation.swift
|
||||
// Pods
|
||||
//
|
||||
// Created by Victor Sukochev on 14/02/2017.
|
||||
//
|
||||
//
|
||||
|
||||
public protocol StrokeInterpolation: Interpolable {
|
||||
|
||||
}
|
||||
|
||||
extension Stroke: StrokeInterpolation {
|
||||
public func interpolate(_ endValue: Stroke, progress: Double) -> Self {
|
||||
return self
|
||||
}
|
||||
}
|
@ -40,3 +40,55 @@ class ShapeAnimation: AnimationImpl<Shape> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// public typealias StrokeAnimationDescription = AnimationDescription<Stroke?>
|
||||
|
||||
public extension AnimatableVariable {
|
||||
public func animate<T:Stroke>(from: T? = nil, to: T, during: Double = 1.0, delay: Double = 0.0) {
|
||||
var shape = node as! Shape
|
||||
|
||||
var safeFrom = from
|
||||
if safeFrom == nil {
|
||||
safeFrom = shape.stroke as! T
|
||||
}
|
||||
|
||||
shape.stroke = safeFrom
|
||||
|
||||
let finalShape = Shape(form: shape.form,
|
||||
fill: shape.fill,
|
||||
stroke: to,
|
||||
place: shape.place,
|
||||
opaque: shape.opaque,
|
||||
opacity: shape.opacity,
|
||||
clip: shape.clip,
|
||||
effect: shape.effect,
|
||||
visible: shape.visible,
|
||||
tag: shape.tag)
|
||||
|
||||
let _ = ShapeAnimation(animatedNode: shape, finalValue: finalShape, animationDuration: during, delay: delay, autostart: true)
|
||||
}
|
||||
|
||||
public func animation<T:Stroke>(from: T? = nil, to: T, during: Double = 1.0, delay: Double = 0.0) -> Animation {
|
||||
var shape = node as! Shape
|
||||
|
||||
var safeFrom = from
|
||||
if safeFrom == nil {
|
||||
safeFrom = shape.stroke as! T
|
||||
}
|
||||
|
||||
shape.stroke = safeFrom
|
||||
|
||||
let finalShape = Shape(form: shape.form,
|
||||
fill: shape.fill,
|
||||
stroke: to,
|
||||
place: shape.place,
|
||||
opaque: shape.opaque,
|
||||
opacity: shape.opacity,
|
||||
clip: shape.clip,
|
||||
effect: shape.effect,
|
||||
visible: shape.visible,
|
||||
tag: shape.tag)
|
||||
|
||||
return ShapeAnimation(animatedNode: shape, finalValue: finalShape, animationDuration: during, delay: delay, autostart: false)
|
||||
}
|
||||
}
|
||||
|
@ -8,13 +8,13 @@ open class Shape: Node {
|
||||
set(val) { formVar.value = val }
|
||||
}
|
||||
|
||||
open let fillVar: Variable<Fill?>
|
||||
open let fillVar: AnimatableVariable<Fill?>
|
||||
open var fill: Fill? {
|
||||
get { return fillVar.value }
|
||||
set(val) { fillVar.value = val }
|
||||
}
|
||||
|
||||
open let strokeVar: Variable<Stroke?>
|
||||
open let strokeVar: AnimatableVariable<Stroke?>
|
||||
open var stroke: Stroke? {
|
||||
get { return strokeVar.value }
|
||||
set(val) { strokeVar.value = val }
|
||||
@ -22,8 +22,8 @@ open class Shape: Node {
|
||||
|
||||
public init(form: Locus, fill: Fill? = nil, stroke: Stroke? = nil, place: Transform = Transform.identity, opaque: Bool = true, opacity: Double = 1, clip: Locus? = nil, effect: Effect? = nil, visible: Bool = true, tag: [String] = []) {
|
||||
self.formVar = AnimatableVariable<Locus>(form)
|
||||
self.fillVar = Variable<Fill?>(fill)
|
||||
self.strokeVar = Variable<Stroke?>(stroke)
|
||||
self.fillVar = AnimatableVariable<Fill?>(fill)
|
||||
self.strokeVar = AnimatableVariable<Stroke?>(stroke)
|
||||
super.init(
|
||||
place: place,
|
||||
opaque: opaque,
|
||||
@ -35,6 +35,8 @@ open class Shape: Node {
|
||||
)
|
||||
|
||||
self.formVar.node = self
|
||||
self.strokeVar.node = self
|
||||
self.fillVar.node = self
|
||||
}
|
||||
|
||||
// GENERATED NOT
|
||||
|
Loading…
Reference in New Issue
Block a user