rlottie: Refactor transformation matrix of proxymodel submit/tizen/20200303.214157
authorJunsuChoi <jsuya.choi@samsung.com>
Fri, 14 Feb 2020 06:42:06 +0000 (15:42 +0900)
committerJongmin Lee <jm105.lee@samsung.com>
Tue, 3 Mar 2020 21:27:18 +0000 (06:27 +0900)
Move value calculation given by property to proxy model
And add more sample to the demo.

example/demo.cpp
src/lottie/lottieitem.cpp
src/lottie/lottieproxymodel.h

index c6b4cbc..33a6fff 100644 (file)
@@ -35,6 +35,7 @@ public:
         Demo5(app, filePath);
         Demo6(app, filePath);
         Demo7(app, filePath);
+        Demo8(app, filePath);
     }
     void Demo1(EvasApp *app, std::string &filePath) {
         /* Fill Color */
@@ -176,6 +177,40 @@ public:
         view7->loop(true);
         view7->setRepeatMode(LottieView::RepeatMode::Reverse);
     }
+    void Demo8(EvasApp *app, std::string &filePath) {
+        /* Transform + color */
+        view8.reset(new LottieView(app->evas()));
+        view8->setFilePath(filePath.c_str());
+        if (view8->player()) {
+            view8->player()->setValue<rlottie::Property::TrRotation>("Shape Layer 1.Ellipse 1",
+                [](const rlottie::FrameInfo& info) {
+                          return info.curFrame() * 20;
+                 });
+            view8->player()->setValue<rlottie::Property::TrScale>("Shape Layer 1.Ellipse 1",
+                [](const rlottie::FrameInfo& info) {
+                          return rlottie::Size(50, 100 - info.curFrame());
+                 });
+            view8->player()->setValue<rlottie::Property::TrPosition>("Shape Layer 1.Ellipse 1",
+                [](const rlottie::FrameInfo& info) {
+                          return rlottie::Point(-20 + (double)info.curFrame()/2.0,
+                                                -20 + (double)info.curFrame()/2.0);
+                 });
+            view8->player()->setValue<rlottie::Property::FillColor>("Shape Layer 1.Ellipse 1.Fill 1",
+                [](const rlottie::FrameInfo& info) {
+                     if (info.curFrame() < 60 )
+                         return rlottie::Color(0, 0, 1);
+                     else {
+                         return rlottie::Color(1, 0, 0);
+                     }
+                 });
+        }
+        view8->setPos(2100, 0);
+        view8->setSize(300, 300);
+        view8->show();
+        view8->play();
+        view8->loop(true);
+        view8->setRepeatMode(LottieView::RepeatMode::Reverse);
+    }
 private:
     std::unique_ptr<LottieView>  view1;
     std::unique_ptr<LottieView>  view2;
@@ -184,6 +219,7 @@ private:
     std::unique_ptr<LottieView>  view5;
     std::unique_ptr<LottieView>  view6;
     std::unique_ptr<LottieView>  view7;
+    std::unique_ptr<LottieView>  view8;
 };
 
 static void
@@ -196,7 +232,7 @@ onExitCb(void *data, void */*extra*/)
 int
 main(void)
 {
-   EvasApp *app = new EvasApp(2100, 300);
+   EvasApp *app = new EvasApp(2400, 300);
    app->setup();
 
    std::string filePath = DEMO_DIR;
index e7f9303..95e3953 100644 (file)
@@ -912,25 +912,9 @@ void LOTContentGroupItem::update(int frameNo, const VMatrix &parentMatrix,
     float alpha;
 
     if (mModel.hasModel() && mModel.transform()) {
-        VMatrix m = mModel.transform()->matrix(frameNo);
-        m *= parentMatrix;
-
-        if (mModel.filter().hasFilter(rlottie::Property::TrScale)){
-             auto sz = mModel.scale(frameNo);
-             m.scale(sz.width() / 100.0, sz.height() / 100.0);
-             newFlag |= DirtyFlagBit::Matrix;
-        }
-        if (mModel.filter().hasFilter(rlottie::Property::TrRotation)){
-             float r = mModel.rotate(frameNo);
-             m.rotate(r);
-             newFlag |= DirtyFlagBit::Matrix;
-        }
-        if (mModel.filter().hasFilter(rlottie::Property::TrPosition)){
-             auto ps = mModel.position(frameNo);
-             m.translate(ps.x(), ps.y());
-             newFlag |= DirtyFlagBit::Matrix;
-        }
+        VMatrix m = mModel.matrix(frameNo);
 
+        m *= parentMatrix;
         if (!(flag & DirtyFlagBit::Matrix) && !mModel.transform()->isStatic() &&
             (m != mMatrix)) {
             newFlag |= DirtyFlagBit::Matrix;
index ab33884..9a6a3f9 100644 (file)
@@ -355,27 +355,21 @@ public:
     LOTFilter& filter() {return mFilter;}
     const char* name() const {return _modelData->name();}
     LOTTransformData* transform() const { return _modelData->mTransform; }
-    VPointF position(int frame) const
-    {
-        if (mFilter.hasFilter(rlottie::Property::TrPosition)) {
-            return mFilter.point(rlottie::Property::TrPosition, frame);
-        }
-        return VPointF(_modelData->mTransform->matrix(frame).m_tx(), _modelData->mTransform->matrix(frame).m_ty());
-    }
-    VSize scale(int frame) const
+    VMatrix matrix(int frame) const
     {
+        VMatrix mS, mR, mT;
         if (mFilter.hasFilter(rlottie::Property::TrScale)) {
-            return mFilter.scale(rlottie::Property::TrScale, frame);
+            VSize s = mFilter.scale(rlottie::Property::TrScale, frame);
+            mS.scale(s.width() / 100.0, s.height() / 100.0);
         }
-        return VSize(_modelData->mTransform->matrix(frame).m_11() * 100.0,
-                       _modelData->mTransform->matrix(frame).m_22() * 100.0);
-    }
-    float rotate(int frame) const
-    {
         if (mFilter.hasFilter(rlottie::Property::TrRotation)) {
-            return mFilter.value(rlottie::Property::TrRotation, frame);
+            mR.rotate(mFilter.value(rlottie::Property::TrRotation, frame));
+        }
+        if (mFilter.hasFilter(rlottie::Property::TrPosition)) {
+            mT.translate(mFilter.point(rlottie::Property::TrPosition, frame));
         }
-        return atan2(_modelData->mTransform->matrix(frame).m_21(), _modelData->mTransform->matrix(frame).m_11());
+
+        return _modelData->mTransform->matrix(frame) * mS * mR * mT;
     }
 private:
     LOTGroupData               *_modelData;