14#error This IControl only works with the Skia graphics backend
23#error ISkLottieControl requires the IGRAPHICS_SKIA backend
28#include "modules/skottie/include/Skottie.h"
31BEGIN_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 fileName, path {
"~/Desktop"};
126 [
this](
const WDL_String& fileName,
const WDL_String& path) {
127 if (fileName.GetLength())
128 LoadFile(fileName.Get());
137 sk_sp<skottie::Animation> mAnimation;
139 SkSize mAnimationSize;
143END_IGRAPHICS_NAMESPACE
This file contains the base IControl implementation, along with some base classes for specific types ...
The lowest level base class of an IGraphics control.
Milliseconds GetAnimationDuration() const
Get the duration of animations applied to the control.
double GetAnimationProgress() const
Get the progress in a control's animation, in the range 0-1.
IAnimationFunction GetAnimationFunction()
Get the control's animation function, if it exists.
virtual void SetDirty(bool triggerAction=true, int valIdx=kNoValIdx)
Mark the control as dirty, i.e.
IControl * SetActionFunction(IActionFunction actionFunc)
Set an Action Function for this control.
void SetAnimation(IAnimationFunction func)
Set the animation function.
The lowest level base class of an IGraphics context.
virtual void * GetDrawContext()=0
Gets a void pointer to underlying drawing context, for the IGraphics backend See draw class implement...
virtual void PromptForFile(WDL_String &fileName, WDL_String &path, EFileAction action=EFileAction::Open, const char *ext="", IFileDialogCompletionHandlerFunc completionHandler=nullptr)=0
Create a platform file prompt dialog to choose a path for opening/saving a single file.
A control that hosts a Lottie animation, via Skia's Skottie module https://skia.org/user/modules/skot...
void OnMouseDown(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse down event on this control.
void Draw(IGraphics &g) override
Draw the control to the graphics context.
Used to manage mouse modifiers i.e.
Used to manage a rectangular area, independent of draw class/platform.