iPlug2 - C++ Audio Plug-in Framework
TestAnimationControl.h
Go to the documentation of this file.
1 /*
2  ==============================================================================
3 
4  This file is part of the iPlug 2 library. Copyright (C) the iPlug 2 developers.
5 
6  See LICENSE.txt for more info.
7 
8  ==============================================================================
9 */
10 
11 #pragma once
12 
18 #include "IControl.h"
19 #include "Easing.h"
20 
24 {
25 public:
26  TestAnimationControl(const IRECT& bounds)
27  : IControl(bounds, kNoParameter)
28  {
29  SetTooltip("TestAnimationControl");
30 
31  SetActionFunction([&](IControl* pCaller) {
32 
33  SetAnimation([&](IControl* pCaller) {
34  auto progress = static_cast<float>(pCaller->GetAnimationProgress());
35 
36  if(progress > 1.f) {
37  pCaller->OnEndAnimation();
38  return;
39  }
40 
41  mDrawnRect = IRECT::LinearInterpolateBetween(mStartRect, mEndRect, EaseQuadraticIn(progress));
42  mDrawnColor = IColor::LinearInterpolateBetween(mStartColor, mEndColor, progress);
43  },
44  1000);
45  });
46 
47  mStartRect = mDrawnRect = mRECT.GetRandomSubRect();
48  mEndRect = mRECT.GetRandomSubRect();
49  mStartColor = mDrawnColor = IColor::GetRandomColor();
50  mEndColor = IColor::GetRandomColor();
51  }
52 
53  void Draw(IGraphics& g) override
54  {
55  g.DrawDottedRect(COLOR_BLACK, mRECT);
56  g.FillRect(mMouseIsOver ? COLOR_TRANSLUCENT : COLOR_TRANSPARENT, mRECT);
57  g.FillRect(mDrawnColor, mDrawnRect);
58  g.DrawText(mText, "Click to animate", mRECT);
59  }
60 
61  void OnMouseDown(float x, float y, const IMouseMod& mod) override
62  {
63  mEndRect = mRECT.GetRandomSubRect();
64  mEndColor = IColor::GetRandomColor();
65 
66  SetDirty(true);
67  }
68 
69  void OnEndAnimation() override
70  {
71  mStartRect = mEndRect;
72  IControl::OnEndAnimation();
73  }
74 
75 private:
76  IRECT mStartRect, mEndRect, mDrawnRect;
77  IColor mStartColor, mEndColor, mDrawnColor;
78 };
The lowest level base class of an IGraphics control.
Definition: IControl.h:42
Used to manage a rectangular area, independent of draw class/platform.
virtual void DrawDottedRect(const IColor &color, const IRECT &bounds, const IBlend *pBlend=0, float thickness=1.f, float dashLen=2.f)
Draw a dotted rectangle to the graphics context.
Definition: IGraphics.cpp:2517
Used to manage mouse modifiers i.e.
bool mMouseIsOver
if mGraphics::mHandleMouseOver = true, this will be true when the mouse is over control.
Definition: IControl.h:545
IControl * SetActionFunction(IActionFunction actionFunc)
Set an Action Function for this control.
Definition: IControl.h:201
void SetTooltip(const char *str)
Set a tooltip for the control.
Definition: IControl.h:210
Used to manage color data, independent of draw class/platform.
void DrawText(const IText &text, const char *str, const IRECT &bounds, const IBlend *pBlend=0)
Draw some text to the graphics context in a specific rectangle.
Definition: IGraphics.cpp:631
This file contains the base IControl implementation, along with some base classes for specific types ...
double GetAnimationProgress() const
Get the progress in a control&#39;s animation, in the range 0-1.
Definition: IControl.cpp:429
IControl(const IRECT &bounds, int paramIdx=kNoParameter, IActionFunction actionFunc=nullptr)
Constructor.
Definition: IControl.cpp:81
static IRECT LinearInterpolateBetween(const IRECT &start, const IRECT &dest, float progress)
Get a rectangle that is a linear interpolation between start and dest
The lowest level base class of an IGraphics context.
Definition: IGraphics.h:86
void SetAnimation(IAnimationFunction func)
Set the animation function.
Definition: IControl.h:477
static IColor LinearInterpolateBetween(const IColor &start, const IColor &dest, float progress)
Helper function to linear interpolate between two IColors.
virtual void FillRect(const IColor &color, const IRECT &bounds, const IBlend *pBlend=0)
Fill a rectangular region of the graphics context with a color.
Definition: IGraphics.cpp:2547
void Draw(IGraphics &g) override
Draw the control to the graphics context.
static IColor GetRandomColor(bool randomAlpha=false)
Get a random IColor.
IRECT GetRandomSubRect() const
void OnMouseDown(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse down event on this control.
Control to test animation.
virtual void SetDirty(bool triggerAction=true, int valIdx=kNoValIdx)
Mark the control as dirty, i.e.
Definition: IControl.cpp:196