Swiftgram/example/lottieview.h
Hermet Park 0a325b079e Put samsung copyright header to all our own source code.
Change-Id: I3cebcfef827425d16092ee7a26c39f7733572eb7
2018-12-26 19:18:29 +09:00

109 lines
3.2 KiB
C++

/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
*
* Licensed under the Flora License, Version 1.1 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://floralicense.org/license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef LOTTIEVIEW_H
#define LOTTIEVIEW_H
#ifndef EFL_BETA_API_SUPPORT
#define EFL_BETA_API_SUPPORT
#endif
#ifndef EFL_EO_API_SUPPORT
#define EFL_EO_API_SUPPORT
#endif
#include <Eo.h>
#include <Efl.h>
#include <Evas.h>
#include <Ecore.h>
#include <Ecore_Evas.h>
#include "lottieanimation.h"
#include "lottieanimation_capi.h"
#include<future>
class LottieView
{
public:
enum class RepeatMode {
Restart,
Reverse
};
LottieView(Evas *evas, bool renderMode = true, bool asyncRender = true);
~LottieView();
Evas_Object *getImage();
void setSize(int w, int h);
void setPos(int x, int y);
void setFilePath(const char *filePath);
void loadFromData(const std::string &jsonData, const std::string &key);
void show();
void hide();
void loop(bool loop);
void setSpeed(float speed) { mSpeed = speed;}
void setRepeatCount(int count);
void setRepeatMode(LottieView::RepeatMode mode);
float getFrameRate() const { return mFrameRate; }
long getTotalFrame() const { return mTotalFrame; }
public:
void seek(float pos);
float getPos();
void finished();
void play();
void pause();
void stop();
void render();
void initializeBufferObject(Evas *evas);
private:
void createVgNode(LOTNode *node, Efl_VG *root);
void update(const std::vector<LOTNode *> &);
void updateTree(const LOTLayerNode *);
void update(const LOTLayerNode *, Efl_VG *parent);
void restart();
public:
int mw;
int mh;
Evas *mEvas;
Efl_VG *mRoot;
Evas_Object *mVg;
int mRepeatCount;
LottieView::RepeatMode mRepeatMode;
std::unique_ptr<lottie::Animation> mPlayer;
size_t mCurFrame{UINT_MAX};
Ecore_Animator *mAnimator{nullptr};
bool mLoop;
int mCurCount;
bool mReverse;
bool mPalying;
Evas_Object *mImage;
float mSpeed;
bool mRenderMode;
bool mAsyncRender;
bool mDirty;
float mStartPos;
float mPos;
float mFrameRate;
long mTotalFrame;
std::future<lottie::Surface> mRenderTask;
};
class LottieViewCApi
{
public:
private:
Evas *mEvas;
Lottie_Animation *mAnimation;
};
#endif //LOTTIEVIEW_H