mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 05:33:36 +00:00
lottie: clarify shape direction.
There are only two options clockwise or counter-clockwise.
This commit is contained in:
parent
6025635712
commit
22bab117a3
3 changed files with 16 additions and 17 deletions
|
@ -447,7 +447,7 @@ static void _repeat(LottieGroup* parent, unique_ptr<Shape> path, RenderContext*
|
|||
}
|
||||
|
||||
|
||||
static void _appendRect(Shape* shape, float x, float y, float w, float h, float r, float direction, Matrix* transform)
|
||||
static void _appendRect(Shape* shape, float x, float y, float w, float h, float r, Matrix* transform, bool clockwise)
|
||||
{
|
||||
//sharp rect
|
||||
if (tvg::zero(r)) {
|
||||
|
@ -457,7 +457,7 @@ static void _appendRect(Shape* shape, float x, float y, float w, float h, float
|
|||
};
|
||||
|
||||
Point points[4];
|
||||
if (direction == 0) {
|
||||
if (clockwise) {
|
||||
points[0] = {x + w, y};
|
||||
points[1] = {x + w, y + h};
|
||||
points[2] = {x, y + h};
|
||||
|
@ -488,7 +488,7 @@ static void _appendRect(Shape* shape, float x, float y, float w, float h, float
|
|||
|
||||
constexpr int ptsCnt = 17;
|
||||
Point points[ptsCnt];
|
||||
if (direction == 0) {
|
||||
if (clockwise) {
|
||||
commands[0] = PathCommand::MoveTo; commands[1] = PathCommand::LineTo; commands[2] = PathCommand::CubicTo;
|
||||
commands[3] = PathCommand::LineTo; commands[4] = PathCommand::CubicTo;commands[5] = PathCommand::LineTo;
|
||||
commands[6] = PathCommand::CubicTo; commands[7] = PathCommand::LineTo; commands[8] = PathCommand::CubicTo;
|
||||
|
@ -505,7 +505,7 @@ static void _appendRect(Shape* shape, float x, float y, float w, float h, float
|
|||
points[14] = {x + w - rx + hrx, y}; points[15] = {x + w, y + ry - hry}; points[16] = {x + w, y + ry}; //cubicTo
|
||||
} else {
|
||||
commands[0] = PathCommand::MoveTo; commands[1] = PathCommand::CubicTo; commands[2] = PathCommand::LineTo;
|
||||
commands[3] = PathCommand::CubicTo; commands[4] = PathCommand::LineTo;commands[5] = PathCommand::CubicTo;
|
||||
commands[3] = PathCommand::CubicTo; commands[4] = PathCommand::LineTo; commands[5] = PathCommand::CubicTo;
|
||||
commands[6] = PathCommand::LineTo; commands[7] = PathCommand::CubicTo; commands[8] = PathCommand::LineTo;
|
||||
commands[9] = PathCommand::Close;
|
||||
|
||||
|
@ -544,11 +544,11 @@ static void _updateRect(LottieGroup* parent, LottieObject** child, float frameNo
|
|||
|
||||
if (!ctx->repeaters.empty()) {
|
||||
auto path = Shape::gen();
|
||||
_appendRect(path.get(), position.x - size.x * 0.5f, position.y - size.y * 0.5f, size.x, size.y, roundness, rect->direction, ctx->transform);
|
||||
_appendRect(path.get(), position.x - size.x * 0.5f, position.y - size.y * 0.5f, size.x, size.y, roundness, ctx->transform, rect->clockwise);
|
||||
_repeat(parent, std::move(path), ctx);
|
||||
} else {
|
||||
_draw(parent, ctx);
|
||||
_appendRect(ctx->merging, position.x - size.x * 0.5f, position.y - size.y * 0.5f, size.x, size.y, roundness, rect->direction, ctx->transform);
|
||||
_appendRect(ctx->merging, position.x - size.x * 0.5f, position.y - size.y * 0.5f, size.x, size.y, roundness, ctx->transform, rect->clockwise);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -698,7 +698,7 @@ static void _updateStar(LottieGroup* parent, LottiePolyStar* star, Matrix* trans
|
|||
auto partialPointAmount = ptsCnt - floorf(ptsCnt);
|
||||
auto longSegment = false;
|
||||
auto numPoints = size_t(ceilf(ptsCnt) * 2);
|
||||
auto direction = (star->direction == 0) ? 1.0f : -1.0f;
|
||||
auto direction = star->clockwise ? 1.0f : -1.0f;
|
||||
auto hasRoundness = false;
|
||||
bool roundedCorner = (roundness > ROUNDNESS_EPSILON) && (tvg::zero(innerRoundness) || tvg::zero(outerRoundness));
|
||||
//TODO: we can use PathCommand / PathCoord directly.
|
||||
|
@ -808,7 +808,7 @@ static void _updatePolygon(LottieGroup* parent, LottiePolyStar* star, Matrix* tr
|
|||
|
||||
auto angle = deg2rad(-90.0f);
|
||||
auto anglePerPoint = 2.0f * MATH_PI / float(ptsCnt);
|
||||
auto direction = (star->direction == 0) ? 1.0f : -1.0f;
|
||||
auto direction = star->clockwise ? 1.0f : -1.0f;
|
||||
auto hasRoundness = false;
|
||||
auto x = radius * cosf(angle);
|
||||
auto y = radius * sinf(angle);
|
||||
|
|
|
@ -268,7 +268,7 @@ struct LottieTrimpath : LottieObject
|
|||
struct LottieShape : LottieObject
|
||||
{
|
||||
virtual ~LottieShape() {}
|
||||
uint8_t direction = 0; //0: clockwise, 2: counter-clockwise, 3: xor(?)
|
||||
bool clockwise = true; //clockwise or counter-clockwise
|
||||
|
||||
bool mergeable() override
|
||||
{
|
||||
|
|
|
@ -543,7 +543,7 @@ LottieRect* LottieParser::parseRect()
|
|||
else if (KEY_AS("s")) parseProperty<LottieProperty::Type::Point>(rect->size);
|
||||
else if (KEY_AS("p")) parseProperty<LottieProperty::Type::Position>(rect->position);
|
||||
else if (KEY_AS("r")) parseProperty<LottieProperty::Type::Float>(rect->radius);
|
||||
else if (KEY_AS("d")) rect->direction = getDirection();
|
||||
else if (KEY_AS("d")) rect->clockwise = getDirection();
|
||||
else skip(key);
|
||||
}
|
||||
rect->prepare();
|
||||
|
@ -561,7 +561,7 @@ LottieEllipse* LottieParser::parseEllipse()
|
|||
if (parseCommon(ellipse, key)) continue;
|
||||
else if (KEY_AS("p")) parseProperty<LottieProperty::Type::Position>(ellipse->position);
|
||||
else if (KEY_AS("s")) parseProperty<LottieProperty::Type::Point>(ellipse->size);
|
||||
else if (KEY_AS("d")) ellipse->direction = getDirection();
|
||||
else if (KEY_AS("d")) ellipse->clockwise = getDirection();
|
||||
else skip(key);
|
||||
}
|
||||
ellipse->prepare();
|
||||
|
@ -698,7 +698,7 @@ LottiePath* LottieParser::parsePath()
|
|||
while (auto key = nextObjectKey()) {
|
||||
if (parseCommon(path, key)) continue;
|
||||
else if (KEY_AS("ks")) getPathSet(path->pathset);
|
||||
else if (KEY_AS("d")) path->direction = getDirection();
|
||||
else if (KEY_AS("d")) path->clockwise = getDirection();
|
||||
else skip(key);
|
||||
}
|
||||
path->prepare();
|
||||
|
@ -722,7 +722,7 @@ LottiePolyStar* LottieParser::parsePolyStar()
|
|||
else if (KEY_AS("os")) parseProperty<LottieProperty::Type::Float>(star->outerRoundness);
|
||||
else if (KEY_AS("r")) parseProperty<LottieProperty::Type::Float>(star->rotation);
|
||||
else if (KEY_AS("sy")) star->type = (LottiePolyStar::Type) getInt();
|
||||
else if (KEY_AS("d")) star->direction = getDirection();
|
||||
else if (KEY_AS("d")) star->clockwise = getDirection();
|
||||
else skip(key);
|
||||
}
|
||||
star->prepare();
|
||||
|
@ -1089,12 +1089,11 @@ void LottieParser::parseTimeRemap(LottieLayer* layer)
|
|||
uint8_t LottieParser::getDirection()
|
||||
{
|
||||
auto v = getInt();
|
||||
if (v == 1) return 0;
|
||||
if (v == 2) return 3;
|
||||
if (v == 3) return 2;
|
||||
return 0;
|
||||
if (v == 3) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void LottieParser::parseShapes(Array<LottieObject*>& parent)
|
||||
{
|
||||
enterArray();
|
||||
|
|
Loading…
Add table
Reference in a new issue