mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 21:53:41 +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
|
//sharp rect
|
||||||
if (tvg::zero(r)) {
|
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];
|
Point points[4];
|
||||||
if (direction == 0) {
|
if (clockwise) {
|
||||||
points[0] = {x + w, y};
|
points[0] = {x + w, y};
|
||||||
points[1] = {x + w, y + h};
|
points[1] = {x + w, y + h};
|
||||||
points[2] = {x, 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;
|
constexpr int ptsCnt = 17;
|
||||||
Point points[ptsCnt];
|
Point points[ptsCnt];
|
||||||
if (direction == 0) {
|
if (clockwise) {
|
||||||
commands[0] = PathCommand::MoveTo; commands[1] = PathCommand::LineTo; commands[2] = PathCommand::CubicTo;
|
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[3] = PathCommand::LineTo; commands[4] = PathCommand::CubicTo;commands[5] = PathCommand::LineTo;
|
||||||
commands[6] = PathCommand::CubicTo; commands[7] = PathCommand::LineTo; commands[8] = PathCommand::CubicTo;
|
commands[6] = PathCommand::CubicTo; commands[7] = PathCommand::LineTo; commands[8] = PathCommand::CubicTo;
|
||||||
|
@ -544,11 +544,11 @@ static void _updateRect(LottieGroup* parent, LottieObject** child, float frameNo
|
||||||
|
|
||||||
if (!ctx->repeaters.empty()) {
|
if (!ctx->repeaters.empty()) {
|
||||||
auto path = Shape::gen();
|
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);
|
_repeat(parent, std::move(path), ctx);
|
||||||
} else {
|
} else {
|
||||||
_draw(parent, ctx);
|
_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 partialPointAmount = ptsCnt - floorf(ptsCnt);
|
||||||
auto longSegment = false;
|
auto longSegment = false;
|
||||||
auto numPoints = size_t(ceilf(ptsCnt) * 2);
|
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;
|
auto hasRoundness = false;
|
||||||
bool roundedCorner = (roundness > ROUNDNESS_EPSILON) && (tvg::zero(innerRoundness) || tvg::zero(outerRoundness));
|
bool roundedCorner = (roundness > ROUNDNESS_EPSILON) && (tvg::zero(innerRoundness) || tvg::zero(outerRoundness));
|
||||||
//TODO: we can use PathCommand / PathCoord directly.
|
//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 angle = deg2rad(-90.0f);
|
||||||
auto anglePerPoint = 2.0f * MATH_PI / float(ptsCnt);
|
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 hasRoundness = false;
|
||||||
auto x = radius * cosf(angle);
|
auto x = radius * cosf(angle);
|
||||||
auto y = radius * sinf(angle);
|
auto y = radius * sinf(angle);
|
||||||
|
|
|
@ -268,7 +268,7 @@ struct LottieTrimpath : LottieObject
|
||||||
struct LottieShape : LottieObject
|
struct LottieShape : LottieObject
|
||||||
{
|
{
|
||||||
virtual ~LottieShape() {}
|
virtual ~LottieShape() {}
|
||||||
uint8_t direction = 0; //0: clockwise, 2: counter-clockwise, 3: xor(?)
|
bool clockwise = true; //clockwise or counter-clockwise
|
||||||
|
|
||||||
bool mergeable() override
|
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("s")) parseProperty<LottieProperty::Type::Point>(rect->size);
|
||||||
else if (KEY_AS("p")) parseProperty<LottieProperty::Type::Position>(rect->position);
|
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("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);
|
else skip(key);
|
||||||
}
|
}
|
||||||
rect->prepare();
|
rect->prepare();
|
||||||
|
@ -561,7 +561,7 @@ LottieEllipse* LottieParser::parseEllipse()
|
||||||
if (parseCommon(ellipse, key)) continue;
|
if (parseCommon(ellipse, key)) continue;
|
||||||
else if (KEY_AS("p")) parseProperty<LottieProperty::Type::Position>(ellipse->position);
|
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("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);
|
else skip(key);
|
||||||
}
|
}
|
||||||
ellipse->prepare();
|
ellipse->prepare();
|
||||||
|
@ -698,7 +698,7 @@ LottiePath* LottieParser::parsePath()
|
||||||
while (auto key = nextObjectKey()) {
|
while (auto key = nextObjectKey()) {
|
||||||
if (parseCommon(path, key)) continue;
|
if (parseCommon(path, key)) continue;
|
||||||
else if (KEY_AS("ks")) getPathSet(path->pathset);
|
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);
|
else skip(key);
|
||||||
}
|
}
|
||||||
path->prepare();
|
path->prepare();
|
||||||
|
@ -722,7 +722,7 @@ LottiePolyStar* LottieParser::parsePolyStar()
|
||||||
else if (KEY_AS("os")) parseProperty<LottieProperty::Type::Float>(star->outerRoundness);
|
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("r")) parseProperty<LottieProperty::Type::Float>(star->rotation);
|
||||||
else if (KEY_AS("sy")) star->type = (LottiePolyStar::Type) getInt();
|
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);
|
else skip(key);
|
||||||
}
|
}
|
||||||
star->prepare();
|
star->prepare();
|
||||||
|
@ -1089,12 +1089,11 @@ void LottieParser::parseTimeRemap(LottieLayer* layer)
|
||||||
uint8_t LottieParser::getDirection()
|
uint8_t LottieParser::getDirection()
|
||||||
{
|
{
|
||||||
auto v = getInt();
|
auto v = getInt();
|
||||||
if (v == 1) return 0;
|
if (v == 3) return false;
|
||||||
if (v == 2) return 3;
|
return true;
|
||||||
if (v == 3) return 2;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LottieParser::parseShapes(Array<LottieObject*>& parent)
|
void LottieParser::parseShapes(Array<LottieObject*>& parent)
|
||||||
{
|
{
|
||||||
enterArray();
|
enterArray();
|
||||||
|
|
Loading…
Add table
Reference in a new issue