mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-15 12:34:30 +00:00
lottie: code refactoring
Access its type from a property instance, through coherent data structure.
This commit is contained in:
parent
2b3930b46d
commit
fc61fc42c2
3 changed files with 19 additions and 17 deletions
|
@ -317,7 +317,7 @@ static void _buildLayer(jerry_value_t context, float frameNo, LottieLayer* layer
|
||||||
|
|
||||||
static jerry_value_t _value(float frameNo, LottieExpression* exp)
|
static jerry_value_t _value(float frameNo, LottieExpression* exp)
|
||||||
{
|
{
|
||||||
switch (exp->type) {
|
switch (exp->property->type) {
|
||||||
case LottieProperty::Type::Point: {
|
case LottieProperty::Type::Point: {
|
||||||
auto value = jerry_object();
|
auto value = jerry_object();
|
||||||
auto pos = (*static_cast<LottiePoint*>(exp->property))(frameNo);
|
auto pos = (*static_cast<LottiePoint*>(exp->property))(frameNo);
|
||||||
|
@ -352,7 +352,7 @@ static jerry_value_t _value(float frameNo, LottieExpression* exp)
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
TVGERR("LOTTIE", "Non supported type for value? = %d", (int) exp->type);
|
TVGERR("LOTTIE", "Non supported type for value? = %d", (int) exp->property->type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return jerry_undefined();
|
return jerry_undefined();
|
||||||
|
@ -735,7 +735,7 @@ static jerry_value_t _velocityAtTime(const jerry_call_info_t* info, const jerry_
|
||||||
Point cur, prv;
|
Point cur, prv;
|
||||||
|
|
||||||
//compute the velocity
|
//compute the velocity
|
||||||
switch (exp->type) {
|
switch (exp->property->type) {
|
||||||
case LottieProperty::Type::Point: {
|
case LottieProperty::Type::Point: {
|
||||||
prv = (*static_cast<LottiePoint*>(exp->property))(pframe);
|
prv = (*static_cast<LottiePoint*>(exp->property))(pframe);
|
||||||
cur = (*static_cast<LottiePoint*>(exp->property))(cframe);
|
cur = (*static_cast<LottiePoint*>(exp->property))(cframe);
|
||||||
|
@ -779,7 +779,7 @@ static jerry_value_t _speedAtTime(const jerry_call_info_t* info, const jerry_val
|
||||||
Point cur, prv;
|
Point cur, prv;
|
||||||
|
|
||||||
//compute the velocity
|
//compute the velocity
|
||||||
switch (exp->type) {
|
switch (exp->property->type) {
|
||||||
case LottieProperty::Type::Point: {
|
case LottieProperty::Type::Point: {
|
||||||
prv = (*static_cast<LottiePoint*>(exp->property))(pframe);
|
prv = (*static_cast<LottiePoint*>(exp->property))(pframe);
|
||||||
cur = (*static_cast<LottiePoint*>(exp->property))(cframe);
|
cur = (*static_cast<LottiePoint*>(exp->property))(cframe);
|
||||||
|
@ -1307,7 +1307,7 @@ jerry_value_t LottieExpressions::evaluate(float frameNo, LottieExpression* exp)
|
||||||
jerry_object_set_native_ptr(thisProperty, nullptr, exp->property);
|
jerry_object_set_native_ptr(thisProperty, nullptr, exp->property);
|
||||||
_buildProperty(frameNo, global, exp);
|
_buildProperty(frameNo, global, exp);
|
||||||
|
|
||||||
if (exp->type == LottieProperty::Type::PathSet) _buildPath(thisProperty, exp);
|
if (exp->property->type == LottieProperty::Type::PathSet) _buildPath(thisProperty, exp);
|
||||||
if (exp->object->type == LottieObject::Transform) _buildTransform(global, frameNo, static_cast<LottieTransform*>(exp->object));
|
if (exp->object->type == LottieObject::Transform) _buildTransform(global, frameNo, static_cast<LottieTransform*>(exp->object));
|
||||||
|
|
||||||
//evaluate the code
|
//evaluate the code
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
#define KEY_AS(name) !strcmp(key, name)
|
#define KEY_AS(name) !strcmp(key, name)
|
||||||
|
|
||||||
|
|
||||||
static LottieExpression* _expression(char* code, LottieComposition* comp, LottieLayer* layer, LottieObject* object, LottieProperty* property, LottieProperty::Type type)
|
static LottieExpression* _expression(char* code, LottieComposition* comp, LottieLayer* layer, LottieObject* object, LottieProperty* property)
|
||||||
{
|
{
|
||||||
if (!comp->expressions) comp->expressions = true;
|
if (!comp->expressions) comp->expressions = true;
|
||||||
|
|
||||||
|
@ -44,7 +44,6 @@ static LottieExpression* _expression(char* code, LottieComposition* comp, Lottie
|
||||||
inst->layer = layer;
|
inst->layer = layer;
|
||||||
inst->object = object;
|
inst->object = object;
|
||||||
inst->property = property;
|
inst->property = property;
|
||||||
inst->type = type;
|
|
||||||
inst->enabled = true;
|
inst->enabled = true;
|
||||||
|
|
||||||
return inst;
|
return inst;
|
||||||
|
@ -509,14 +508,14 @@ void LottieParser::parseProperty(T& prop, LottieObject* obj)
|
||||||
for (auto slot = comp->slots.begin(); slot < comp->slots.end(); ++slot) {
|
for (auto slot = comp->slots.begin(); slot < comp->slots.end(); ++slot) {
|
||||||
if (strcmp((*slot)->sid, sid)) continue;
|
if (strcmp((*slot)->sid, sid)) continue;
|
||||||
(*slot)->pairs.push({obj});
|
(*slot)->pairs.push({obj});
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
comp->slots.push(new LottieSlot(sid, obj, type));
|
comp->slots.push(new LottieSlot(sid, obj, type));
|
||||||
} else if (!strcmp(key, "x")) {
|
} else if (KEY_AS("x")) {
|
||||||
prop.exp = _expression(getStringCopy(), comp, context.layer, context.parent, &prop, type);
|
prop.exp = _expression(getStringCopy(), comp, context.layer, context.parent, &prop);
|
||||||
}
|
} else skip(key);
|
||||||
else skip(key);
|
|
||||||
}
|
}
|
||||||
|
prop.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -603,9 +602,10 @@ LottieTransform* LottieParser::parseTransform(bool ddd)
|
||||||
//check separateCoord to figure out whether "x(expression)" / "x(coord)"
|
//check separateCoord to figure out whether "x(expression)" / "x(coord)"
|
||||||
else if (transform->coords && KEY_AS("x")) parseProperty<LottieProperty::Type::Float>(transform->coords->x);
|
else if (transform->coords && KEY_AS("x")) parseProperty<LottieProperty::Type::Float>(transform->coords->x);
|
||||||
else if (transform->coords && KEY_AS("y")) parseProperty<LottieProperty::Type::Float>(transform->coords->y);
|
else if (transform->coords && KEY_AS("y")) parseProperty<LottieProperty::Type::Float>(transform->coords->y);
|
||||||
else if (KEY_AS("x")) transform->position.exp = _expression(getStringCopy(), comp, context.layer, context.parent, &transform->position, LottieProperty::Type::Position);
|
else if (KEY_AS("x")) transform->position.exp = _expression(getStringCopy(), comp, context.layer, context.parent, &transform->position);
|
||||||
else skip(key);
|
else skip(key);
|
||||||
}
|
}
|
||||||
|
transform->position.type = LottieProperty::Type::Position;
|
||||||
}
|
}
|
||||||
else if (KEY_AS("a")) parseProperty<LottieProperty::Type::Point>(transform->anchor);
|
else if (KEY_AS("a")) parseProperty<LottieProperty::Type::Point>(transform->anchor);
|
||||||
else if (KEY_AS("s")) parseProperty<LottieProperty::Type::Point>(transform->scale);
|
else if (KEY_AS("s")) parseProperty<LottieProperty::Type::Point>(transform->scale);
|
||||||
|
@ -696,10 +696,11 @@ void LottieParser::getPathSet(LottiePathSet& path)
|
||||||
} else {
|
} else {
|
||||||
getValue(path.value);
|
getValue(path.value);
|
||||||
}
|
}
|
||||||
} else if (!strcmp(key, "x")) {
|
} else if (KEY_AS("x")) {
|
||||||
path.exp = _expression(getStringCopy(), comp, context.layer, context.parent, &path, LottieProperty::Type::PathSet);
|
path.exp = _expression(getStringCopy(), comp, context.layer, context.parent, &path);
|
||||||
} else skip(key);
|
} else skip(key);
|
||||||
}
|
}
|
||||||
|
path.type = LottieProperty::Type::PathSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -176,9 +176,11 @@ struct LottieVectorFrame
|
||||||
struct LottieProperty
|
struct LottieProperty
|
||||||
{
|
{
|
||||||
enum class Type : uint8_t { Point = 0, Float, Opacity, Color, PathSet, ColorStop, Position, TextDoc, Invalid };
|
enum class Type : uint8_t { Point = 0, Float, Opacity, Color, PathSet, ColorStop, Position, TextDoc, Invalid };
|
||||||
virtual ~LottieProperty() {}
|
|
||||||
|
|
||||||
LottieExpression* exp = nullptr;
|
LottieExpression* exp = nullptr;
|
||||||
|
Type type;
|
||||||
|
|
||||||
|
virtual ~LottieProperty() {}
|
||||||
|
|
||||||
//TODO: Apply common bodies?
|
//TODO: Apply common bodies?
|
||||||
virtual uint32_t frameCnt() = 0;
|
virtual uint32_t frameCnt() = 0;
|
||||||
|
@ -196,7 +198,6 @@ struct LottieExpression
|
||||||
LottieLayer* layer;
|
LottieLayer* layer;
|
||||||
LottieObject* object;
|
LottieObject* object;
|
||||||
LottieProperty* property;
|
LottieProperty* property;
|
||||||
LottieProperty::Type type;
|
|
||||||
|
|
||||||
bool enabled;
|
bool enabled;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue