-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Zhirkevich Alexander Y
authored and
Zhirkevich Alexander Y
committed
Jul 30, 2024
1 parent
c972dbf
commit 6ab2e59
Showing
28 changed files
with
582 additions
and
2,035 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...xzhirkevich/compottie/internal/animation/expressions/operations/composition/OpGetShape.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.github.alexzhirkevich.compottie.internal.animation.expressions.operations.composition | ||
|
||
import io.github.alexzhirkevich.compottie.internal.AnimationState | ||
import io.github.alexzhirkevich.compottie.internal.animation.RawProperty | ||
import io.github.alexzhirkevich.compottie.internal.animation.expressions.EvaluationContext | ||
import io.github.alexzhirkevich.compottie.internal.animation.expressions.Expression | ||
import io.github.alexzhirkevich.compottie.internal.layers.ShapeLayer | ||
import io.github.alexzhirkevich.compottie.internal.shapes.GroupShape | ||
import io.github.alexzhirkevich.compottie.internal.shapes.Shape | ||
|
||
internal class OpGetShape( | ||
private val layerOrGroup : Expression, | ||
private val name : Expression | ||
) : OpShapeContext() { | ||
|
||
override fun invoke( | ||
property: RawProperty<Any>, | ||
context: EvaluationContext, | ||
state: AnimationState | ||
): Shape { | ||
val layerOrGroup = layerOrGroup(property, context, state) | ||
val name = (name(property, context, state) as CharSequence).toString() | ||
|
||
val shape = when (layerOrGroup){ | ||
is ShapeLayer -> { | ||
layerOrGroup.shapesByName[name] | ||
} | ||
is GroupShape -> { | ||
layerOrGroup.shapesByName[name] | ||
} | ||
else -> error("Can't get '$name' content of $layerOrGroup") | ||
} | ||
|
||
return checkNotNull(shape){ | ||
"Content '$name' wasn't found" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
...rkevich/compottie/internal/animation/expressions/operations/composition/OpShapeContext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package io.github.alexzhirkevich.compottie.internal.animation.expressions.operations.composition | ||
|
||
import io.github.alexzhirkevich.compottie.internal.animation.AnimatedProperty | ||
import io.github.alexzhirkevich.compottie.internal.animation.expressions.Expression | ||
import io.github.alexzhirkevich.compottie.internal.animation.expressions.ExpressionContext | ||
import io.github.alexzhirkevich.compottie.internal.animation.expressions.Undefined | ||
import io.github.alexzhirkevich.compottie.internal.animation.expressions.argAt | ||
import io.github.alexzhirkevich.compottie.internal.animation.expressions.checkArgs | ||
import io.github.alexzhirkevich.compottie.internal.animation.expressions.operations.unresolvedReference | ||
import io.github.alexzhirkevich.compottie.internal.animation.expressions.operations.value.toExpressionType | ||
import io.github.alexzhirkevich.compottie.internal.shapes.EllipseShape | ||
import io.github.alexzhirkevich.compottie.internal.shapes.FillShape | ||
import io.github.alexzhirkevich.compottie.internal.shapes.PathShape | ||
import io.github.alexzhirkevich.compottie.internal.shapes.RectShape | ||
import io.github.alexzhirkevich.compottie.internal.shapes.Shape | ||
import io.github.alexzhirkevich.compottie.internal.shapes.TransformShape | ||
|
||
internal abstract class OpShapeContext : ExpressionContext<Shape> { | ||
override fun interpret(callable: String?, args: List<Expression>?): Expression? { | ||
return if (args != null) { | ||
when (callable) { | ||
"content" -> { | ||
checkArgs(args, 1, callable) | ||
OpGetShape( | ||
layerOrGroup = this, | ||
name = args.argAt(0) | ||
) | ||
} | ||
|
||
else -> null | ||
} | ||
} else { | ||
when (callable) { | ||
"size" -> OpShapeSize(this) | ||
"position" -> OpShapePosition(this) | ||
"color" -> OpShapeColor(this) | ||
"path" -> OpShapePath(this) | ||
"scale" -> OpTransformShapeProperty(this, TransformShape::scale, callable) | ||
"rotation" -> OpTransformShapeProperty(this, TransformShape::rotation, callable) | ||
"rotationX" -> OpTransformShapeProperty(this, TransformShape::rotationX, callable) | ||
"rotationY" -> OpTransformShapeProperty(this, TransformShape::rotationY, callable) | ||
"rotationZ" -> OpTransformShapeProperty(this, TransformShape::rotationZ, callable) | ||
"skew" -> OpTransformShapeProperty(this, TransformShape::skew, callable) | ||
"skewAxis" -> OpTransformShapeProperty(this, TransformShape::skewAxis, callable) | ||
"opacity" -> OpTransformShapeProperty(this, TransformShape::opacity, callable) | ||
else -> null | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun OpShapeColor( | ||
shape : Expression | ||
) = Expression { property, context, state -> | ||
val shape = shape(property, context, state) | ||
|
||
if (shape is FillShape){ | ||
shape.color.interpolated(state).toExpressionType() | ||
} else { | ||
unresolvedReference("color", shape::class.simpleName) | ||
} | ||
|
||
} | ||
|
||
private fun OpShapeSize( | ||
shape : Expression | ||
) = Expression { property, context, state -> | ||
val size = when (val shape = shape(property, context, state)){ | ||
is EllipseShape -> shape.size | ||
is RectShape -> shape.size | ||
else -> unresolvedReference("size", shape::class.simpleName) | ||
} | ||
size.interpolated(state).toExpressionType() | ||
} | ||
|
||
private fun OpShapePosition( | ||
shape : Expression | ||
) = Expression { property, context, state -> | ||
val position = when (val shape = shape(property, context, state)){ | ||
is EllipseShape -> shape.position | ||
is RectShape -> shape.position | ||
is TransformShape -> shape.position | ||
else -> unresolvedReference("position", shape::class.simpleName) | ||
} | ||
position.interpolated(state).toExpressionType() | ||
} | ||
|
||
private fun OpTransformShapeProperty( | ||
shape: Expression, | ||
property : (TransformShape) -> AnimatedProperty<*>?, | ||
name : String | ||
) = Expression { property, context, state -> | ||
val value = when (val shape = shape(property, context, state)) { | ||
is TransformShape -> property(shape) | ||
else -> unresolvedReference(name, shape::class.simpleName) | ||
} | ||
value?.interpolated(state)?.toExpressionType() ?: Undefined | ||
} | ||
|
||
|
||
private fun OpShapePath( | ||
shape : Expression | ||
) = Expression { property, context, state -> | ||
val shape = shape(property, context, state) | ||
if(shape is PathShape) { | ||
shape.shape.interpolated(state).toExpressionType() | ||
} else { | ||
unresolvedReference("path", shape::class.simpleName) | ||
} | ||
} |
Oops, something went wrong.