13 #ifndef IGRAPHICS_SKIA 14 #error This IControl only works with the Skia graphics backend 22 #ifndef IGRAPHICS_SKIA 23 #error ISkLottieControl requires the IGRAPHICS_SKIA backend 28 #include "modules/skottie/include/Skottie.h" 31 BEGIN_IGRAPHICS_NAMESPACE
49 DoDraw(SkSize::Make(mRECT.
W(), mRECT.
H()), pCanvas);
52 void DoDraw(SkSize size, SkCanvas* canvas)
54 if (size.width() != mSize.width() || size.height() != mSize.height())
57 if (mAnimationSize.width() > 0 && mAnimationSize.height() > 0)
59 float scale = std::min(size.width() / mAnimationSize.width(),
60 size.height() / mAnimationSize.height());
61 mMatrix.setScaleTranslate( scale, scale,
62 (size.width() - mAnimationSize.width() * scale) * 0.5f,
63 (size.height() - mAnimationSize.height() * scale) * 0.5f);
71 canvas->concat(mMatrix);
72 mAnimation->render(canvas);
75 void LoadFile(
const char* path)
77 skottie::Animation::Builder builder;
78 mAnimation = builder.makeFromFile(path);
82 mAnimationSize = mAnimation->size();
88 mAnimation->seekFrameTime((pCaller->
GetAnimationDuration().count() / 1000.) * progress,
nullptr);
91 pCaller->OnEndAnimation();
92 }, mAnimation->duration() * 1000.);
97 mAnimationSize = {0, 0};
101 void LoadData(
const void* data,
size_t length)
103 skottie::Animation::Builder builder;
104 mAnimation = builder.make((
const char*) data, (
size_t)length);
106 mAnimationSize = mAnimation ? mAnimation->size() : SkSize{0, 0};
111 mAnimation->seekFrameTime((pCaller->
GetAnimationDuration().count() / 1000.) * progress,
nullptr);
114 pCaller->OnEndAnimation();
115 }, mAnimation->duration() * 1000.);
123 WDL_String path {
"~/Desktop"};
125 LoadFile(file.Get());
132 sk_sp<skottie::Animation> mAnimation;
134 SkSize mAnimationSize;
138 END_IGRAPHICS_NAMESPACE
The lowest level base class of an IGraphics control.
Used to manage a rectangular area, independent of draw class/platform.
Used to manage mouse modifiers i.e.
void OnMouseDown(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse down event on this control.
IControl * SetActionFunction(IActionFunction actionFunc)
Set an Action Function for this control.
This file contains the base IControl implementation, along with some base classes for specific types ...
void Draw(IGraphics &g) override
Draw the control to the graphics context.
double GetAnimationProgress() const
Get the progress in a control's animation, in the range 0-1.
virtual void PromptForFile(WDL_String &fileName, WDL_String &path, EFileAction action=EFileAction::Open, const char *extensions=0)=0
Create a platform file prompt dialog to choose a file/directory path for opening/saving a file/direct...
IControl(const IRECT &bounds, int paramIdx=kNoParameter, IActionFunction actionFunc=nullptr)
Constructor.
The lowest level base class of an IGraphics context.
void SetAnimation(IAnimationFunction func)
Set the animation function.
IAnimationFunction GetAnimationFunction()
Get the control's animation function, if it exists.
virtual void * GetDrawContext()=0
Gets a void pointer to underlying drawing context, for the IGraphics backend See draw class implement...
Milliseconds GetAnimationDuration() const
Get the duration of animations applied to the control.
A control that hosts a Lottie animation, via Skia's Skottie module https://skia.org/user/modules/skot...
virtual void SetDirty(bool triggerAction=true, int valIdx=kNoValIdx)
Mark the control as dirty, i.e.