lottie: support 'direction' in ellipses

This commit is contained in:
Mira Grudzinska 2024-07-09 15:50:25 +02:00 committed by Hermet Park
parent bedaa909ad
commit 8340c1e1d7
2 changed files with 19 additions and 12 deletions

View file

@ -553,7 +553,7 @@ static void _updateRect(LottieGroup* parent, LottieObject** child, float frameNo
} }
static void _appendCircle(Shape* shape, float cx, float cy, float rx, float ry, Matrix* transform) static void _appendCircle(Shape* shape, float cx, float cy, float rx, float ry, Matrix* transform, bool clockwise)
{ {
auto rxKappa = rx * PATH_KAPPA; auto rxKappa = rx * PATH_KAPPA;
auto ryKappa = ry * PATH_KAPPA; auto ryKappa = ry * PATH_KAPPA;
@ -565,13 +565,21 @@ static void _appendCircle(Shape* shape, float cx, float cy, float rx, float ry,
}; };
constexpr int ptsCnt = 13; constexpr int ptsCnt = 13;
Point points[ptsCnt] = { Point points[ptsCnt];
{cx, cy - ry}, //moveTo
{cx + rxKappa, cy - ry}, {cx + rx, cy - ryKappa}, {cx + rx, cy}, //cubicTo if (clockwise) {
{cx + rx, cy + ryKappa}, {cx + rxKappa, cy + ry}, {cx, cy + ry}, //cubicTo points[0] = {cx, cy - ry}; //moveTo
{cx - rxKappa, cy + ry}, {cx - rx, cy + ryKappa}, {cx - rx, cy}, //cubicTo points[1] = {cx + rxKappa, cy - ry}; points[2] = {cx + rx, cy - ryKappa}; points[3] = {cx + rx, cy}; //cubicTo
{cx - rx, cy - ryKappa}, {cx - rxKappa, cy - ry}, {cx, cy - ry} //cubicTo points[4] = {cx + rx, cy + ryKappa}; points[5] = {cx + rxKappa, cy + ry}; points[6] = {cx, cy + ry}; //cubicTo
}; points[7] = {cx - rxKappa, cy + ry}; points[8] = {cx - rx, cy + ryKappa}; points[9] = {cx - rx, cy}; //cubicTo
points[10] = {cx - rx, cy - ryKappa}; points[11] = {cx - rxKappa, cy - ry}; points[12] = {cx, cy - ry}; //cubicTo
} else {
points[0] = {cx, cy - ry}; //moveTo
points[1] = {cx - rxKappa, cy - ry}; points[2] = {cx - rx, cy - ryKappa}; points[3] = {cx - rx, cy}; //cubicTo
points[4] = {cx - rx, cy + ryKappa}; points[5] = {cx - rxKappa, cy + ry}; points[6] = {cx, cy + ry}; //cubicTo
points[7] = {cx + rxKappa, cy + ry}; points[8] = {cx + rx, cy + ryKappa}; points[9] = {cx + rx, cy}; //cubicTo
points[10] = {cx + rx, cy - ryKappa}; points[11] = {cx + rxKappa, cy - ry}; points[12] = {cx, cy - ry}; //cubicTo
}
if (transform) { if (transform) {
for (int i = 0; i < ptsCnt; ++i) { for (int i = 0; i < ptsCnt; ++i) {
@ -592,11 +600,11 @@ static void _updateEllipse(LottieGroup* parent, LottieObject** child, float fram
if (!ctx->repeaters.empty()) { if (!ctx->repeaters.empty()) {
auto path = Shape::gen(); auto path = Shape::gen();
_appendCircle(path.get(), position.x, position.y, size.x * 0.5f, size.y * 0.5f, ctx->transform); _appendCircle(path.get(), position.x, position.y, size.x * 0.5f, size.y * 0.5f, ctx->transform, ellipse->clockwise);
_repeat(parent, std::move(path), ctx); _repeat(parent, std::move(path), ctx);
} else { } else {
_draw(parent, ctx); _draw(parent, ctx);
_appendCircle(ctx->merging, position.x, position.y, size.x * 0.5f, size.y * 0.5f, ctx->transform); _appendCircle(ctx->merging, position.x, position.y, size.x * 0.5f, size.y * 0.5f, ctx->transform, ellipse->clockwise);
} }
} }

View file

@ -1088,8 +1088,7 @@ void LottieParser::parseTimeRemap(LottieLayer* layer)
uint8_t LottieParser::getDirection() uint8_t LottieParser::getDirection()
{ {
auto v = getInt(); if (getInt() == 3) return false;
if (v == 3) return false;
return true; return true;
} }