lottie/expressions: added a missing polystar property build.

This commit is contained in:
Hermet Park 2024-07-18 15:10:03 +09:00 committed by Hermet Park
parent e4fb0ec383
commit 0b66cd422e
3 changed files with 74 additions and 34 deletions

View file

@ -26,8 +26,8 @@
/* ThorVG Drawing Contents */ /* ThorVG Drawing Contents */
/************************************************************************/ /************************************************************************/
#define NUM_PER_ROW 3 #define NUM_PER_ROW 4
#define NUM_PER_COL 3 #define NUM_PER_COL 4
struct UserExample : tvgexam::Example struct UserExample : tvgexam::Example
{ {

File diff suppressed because one or more lines are too long

View file

@ -38,6 +38,7 @@ struct ExpContent
float frameNo; float frameNo;
}; };
static jerry_value_t _content(const jerry_call_info_t* info, const jerry_value_t args[], const jerry_length_t argsCnt);
//reserved expressions specifiers //reserved expressions specifiers
static const char* EXP_NAME = "name"; static const char* EXP_NAME = "name";
@ -130,6 +131,73 @@ static void _buildTransform(jerry_value_t context, LottieTransform* transform)
} }
static jerry_value_t _buildGroup(LottieGroup* group, ExpContent* data)
{
auto obj = jerry_function_external(_content);
//attach a transform
for (auto c = group->children.begin(); c < group->children.end(); ++c) {
if ((*c)->type == LottieObject::Type::Transform) {
_buildTransform(obj, static_cast<LottieTransform*>(*c));
break;
}
}
auto data2 = (ExpContent*)malloc(sizeof(ExpContent));
data2->obj = group;
data2->frameNo = data->frameNo;
jerry_object_set_native_ptr(obj, &freeCb, data2);
jerry_object_set_sz(obj, EXP_CONTENT, obj);
return obj;
}
static jerry_value_t _buildPolystar(LottiePolyStar* polystar, ExpContent* data)
{
auto obj = jerry_object();
auto position = jerry_object();
jerry_object_set_native_ptr(position, nullptr, &polystar->position);
jerry_object_set_sz(obj, "position", position);
jerry_value_free(position);
auto innerRadius = jerry_number(polystar->innerRadius(data->frameNo));
jerry_object_set_sz(obj, "innerRadius", innerRadius);
jerry_value_free(innerRadius);
auto outerRadius = jerry_number(polystar->outerRadius(data->frameNo));
jerry_object_set_sz(obj, "outerRadius", outerRadius);
jerry_value_free(outerRadius);
auto innerRoundness = jerry_number(polystar->innerRoundness(data->frameNo));
jerry_object_set_sz(obj, "innerRoundness", innerRoundness);
jerry_value_free(innerRoundness);
auto outerRoundness = jerry_number(polystar->outerRoundness(data->frameNo));
jerry_object_set_sz(obj, "outerRoundness", outerRoundness);
jerry_value_free(outerRoundness);
auto rotation = jerry_number(polystar->rotation(data->frameNo));
jerry_object_set_sz(obj, "rotation", rotation);
jerry_value_free(rotation);
auto ptsCnt = jerry_number(polystar->ptsCnt(data->frameNo));
jerry_object_set_sz(obj, "points", ptsCnt);
jerry_value_free(ptsCnt);
return obj;
}
static jerry_value_t _buildTrimpath(LottieTrimpath* trimpath, ExpContent* data)
{
jerry_value_t obj = jerry_object();
auto start = jerry_number(trimpath->start(data->frameNo));
jerry_object_set_sz(obj, "start", start);
jerry_value_free(start);
auto end = jerry_number(trimpath->end(data->frameNo));
jerry_object_set_sz(obj, "end", end);
jerry_value_free(end);
auto offset = jerry_number(trimpath->offset(data->frameNo));
jerry_object_set_sz(obj, "offset", end);
jerry_value_free(offset);
return obj;
}
static void _buildLayer(jerry_value_t context, LottieLayer* layer, LottieComposition* comp) static void _buildLayer(jerry_value_t context, LottieLayer* layer, LottieComposition* comp)
{ {
auto width = jerry_number(layer->w); auto width = jerry_number(layer->w);
@ -554,44 +622,15 @@ static jerry_value_t _content(const jerry_call_info_t* info, const jerry_value_t
//find the a path property(sh) in the group layer? //find the a path property(sh) in the group layer?
switch (target->type) { switch (target->type) {
case LottieObject::Group: { case LottieObject::Group: return _buildGroup(static_cast<LottieGroup*>(target), data);
auto group = static_cast<LottieGroup*>(target);
auto obj = jerry_function_external(_content);
//attach a transform
for (auto c = group->children.begin(); c < group->children.end(); ++c) {
if ((*c)->type == LottieObject::Type::Transform) {
_buildTransform(obj, static_cast<LottieTransform*>(*c));
break;
}
}
auto data2 = (ExpContent*)malloc(sizeof(ExpContent));
data2->obj = group;
data2->frameNo = data->frameNo;
jerry_object_set_native_ptr(obj, &freeCb, data2);
jerry_object_set_sz(obj, EXP_CONTENT, obj);
return obj;
}
case LottieObject::Path: { case LottieObject::Path: {
jerry_value_t obj = jerry_object(); jerry_value_t obj = jerry_object();
jerry_object_set_native_ptr(obj, nullptr, &static_cast<LottiePath*>(target)->pathset); jerry_object_set_native_ptr(obj, nullptr, &static_cast<LottiePath*>(target)->pathset);
jerry_object_set_sz(obj, "path", obj); jerry_object_set_sz(obj, "path", obj);
return obj; return obj;
} }
case LottieObject::Trimpath: { case LottieObject::Polystar: return _buildPolystar(static_cast<LottiePolyStar*>(target), data);
auto trimpath = static_cast<LottieTrimpath*>(target); case LottieObject::Trimpath: return _buildTrimpath(static_cast<LottieTrimpath*>(target), data);
jerry_value_t obj = jerry_object();
auto start = jerry_number(trimpath->start(data->frameNo));
jerry_object_set_sz(obj, "start", start);
jerry_value_free(start);
auto end = jerry_number(trimpath->end(data->frameNo));
jerry_object_set_sz(obj, "end", end);
jerry_value_free(end);
auto offset = jerry_number(trimpath->offset(data->frameNo));
jerry_object_set_sz(obj, "offset", end);
jerry_value_free(offset);
return obj;
}
default: break; default: break;
} }
return jerry_undefined(); return jerry_undefined();