Skip to content

Commit

Permalink
rlottie: added support of lambda expression in setValue.
Browse files Browse the repository at this point in the history
  • Loading branch information
smohantty committed May 13, 2019
1 parent 231e82d commit 323b07c
Show file tree
Hide file tree
Showing 6 changed files with 263 additions and 54 deletions.
9 changes: 8 additions & 1 deletion example/demo.cpp
Expand Up @@ -50,7 +50,14 @@ main(void)
LottieView *view = new LottieView(app->evas());
view->setFilePath(filePath.c_str());
if (view->player()) {
view->player()->setValue<rlottie::Property::FillColor>("**", rlottie::Color(0, 1, 0));
view->player()->setValue<rlottie::Property::FillColor>("**",
[](const rlottie::FrameInfo& info) {
if (info.curFrame() < 15 )
return rlottie::Color(0, 1, 0);
else {
return rlottie::Color(1, 0, 0);
}
});
}
view->setPos(0, 0);
view->setSize(800, 800);
Expand Down
41 changes: 33 additions & 8 deletions inc/rlottie.h
Expand Up @@ -52,22 +52,42 @@ struct LOTLayerNode;
namespace rlottie {

struct Color {
Color(){}
Color(float r, float g , float b):mr(r), mg(g), mb(b){}
public:
float mr{0}, mg{0}, mb{0};
Color() = default;
Color(float r, float g , float b):_r(r), _g(g), _b(b){}
float r() const {return _r;}
float g() const {return _g;}
float b() const {return _b;}
private:
float _r{0};
float _g{0};
float _b{0};
};

struct Size {
Size(float w, float h):mw(w), mh(h){}
Size() = default;
Size(float w, float h):_w(w), _h(h){}
float w() const {return _w;}
float h() const {return _h;}
private:
float mw{0} , mh{0};
float _w{0};
float _h{0};
};

struct Point {
Point(float x, float y):mx(x), my(y){}
Point() = default;
Point(float x, float y):_x(x), _y(y){}
float x() const {return _x;}
float y() const {return _y;}
private:
float _x{0};
float _y{0};
};

struct FrameInfo {
FrameInfo(uint32_t frame): _frameNo(frame){}
uint32_t curFrame() const {return _frameNo;}
private:
float mx{0} , my{0};
uint32_t _frameNo;
};

enum class Property {
Expand Down Expand Up @@ -409,6 +429,11 @@ class LOT_EXPORT Animation {
void setValue(Float_Type, Property, const std::string &, float);
void setValue(Size_Type, Property, const std::string &, Size);
void setValue(Point_Type, Property, const std::string &, Point);

void setValue(Color_Type, Property, const std::string &, std::function<Color(const FrameInfo &)> &&);
void setValue(Float_Type, Property, const std::string &, std::function<float(const FrameInfo &)> &&);
void setValue(Size_Type, Property, const std::string &, std::function<Size(const FrameInfo &)> &&);
void setValue(Point_Type, Property, const std::string &, std::function<Point(const FrameInfo &)> &&);
/**
* @brief default constructor
*
Expand Down
34 changes: 31 additions & 3 deletions src/lottie/lottieanimation.cpp
Expand Up @@ -318,26 +318,54 @@ void Animation::setValue(Color_Type,Property prop,
const std::string &keypath,
Color value)
{
d->setValue(keypath, LOTVariant(prop, value));
d->setValue(keypath, LOTVariant(prop, [value](const FrameInfo &){ return value;}));
}

void Animation::setValue(Float_Type, Property prop,
const std::string &keypath,
float value)
{
d->setValue(keypath, LOTVariant(prop, value));
d->setValue(keypath, LOTVariant(prop, [value](const FrameInfo &){ return value;}));
}

void Animation::setValue(Size_Type,Property prop,
const std::string &keypath,
Size value)
{
d->setValue(keypath, LOTVariant(prop, value));
d->setValue(keypath, LOTVariant(prop, [value](const FrameInfo &){ return value;}));
}

void Animation::setValue(Point_Type, Property prop,
const std::string &keypath,
Point value)
{
d->setValue(keypath, LOTVariant(prop, [value](const FrameInfo &){ return value;}));
}

void Animation::setValue(Color_Type,Property prop,
const std::string &keypath,
std::function<Color(const FrameInfo &)> && value)
{
d->setValue(keypath, LOTVariant(prop, value));
}

void Animation::setValue(Float_Type, Property prop,
const std::string &keypath,
std::function<float(const FrameInfo &)> && value)
{
d->setValue(keypath, LOTVariant(prop, value));
}

void Animation::setValue(Size_Type,Property prop,
const std::string &keypath,
std::function<Size(const FrameInfo &)> && value)
{
d->setValue(keypath, LOTVariant(prop, value));
}

void Animation::setValue(Point_Type, Property prop,
const std::string &keypath,
std::function<Point(const FrameInfo &)> && value)
{
d->setValue(keypath, LOTVariant(prop, value));
}
Expand Down
2 changes: 1 addition & 1 deletion src/lottie/lottieitem.cpp
Expand Up @@ -73,7 +73,7 @@ bool strokeProp(rlottie::Property prop)
}

LOTCompItem::LOTCompItem(LOTModel *model)
: mRootModel(model), mUpdateViewBox(false), mCurFrameNo(-1)
: mUpdateViewBox(false), mCurFrameNo(-1)
{
mCompData = model->mRoot.get();
mRootLayer = createLayerItem(mCompData->mRootLayer.get());
Expand Down
2 changes: 0 additions & 2 deletions src/lottie/lottieitem.h
Expand Up @@ -62,7 +62,6 @@ class LOTCompItem
private:
VMatrix mScaleMatrix;
VSize mViewSize;
LOTModel *mRootModel;
LOTCompositionData *mCompData;
std::unique_ptr<LOTLayerItem> mRootLayer;
bool mUpdateViewBox;
Expand Down Expand Up @@ -441,7 +440,6 @@ class LOTStrokeItem : public LOTPaintDataItem
bool resolveKeyPath(LOTKeyPath &keyPath, uint depth, LOTVariant &value) final;
private:
LOTProxyModel<LOTStrokeData> mModel;
LOTStrokeData *mData{nullptr};
VColor mColor;
float mWidth{0};
float mDashArray[6];
Expand Down

0 comments on commit 323b07c

Please sign in to comment.