iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
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{
25public:
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
75private:
76 IRECT mStartRect, mEndRect, mDrawnRect;
77 IColor mStartColor, mEndColor, mDrawnColor;
78};
This file contains the base IControl implementation, along with some base classes for specific types ...
The lowest level base class of an IGraphics control.
Definition: IControl.h:49
bool mMouseIsOver
if mGraphics::mHandleMouseOver = true, this will be true when the mouse is over control.
Definition: IControl.h:560
double GetAnimationProgress() const
Get the progress in a control's animation, in the range 0-1.
Definition: IControl.cpp:431
IControl * SetTooltip(const char *str)
Set a tooltip for the control.
Definition: IControl.h:216
virtual void SetDirty(bool triggerAction=true, int valIdx=kNoValIdx)
Mark the control as dirty, i.e.
Definition: IControl.cpp:198
IControl * SetActionFunction(IActionFunction actionFunc)
Set an Action Function for this control.
Definition: IControl.h:206
void SetAnimation(IAnimationFunction func)
Set the animation function.
Definition: IControl.h:492
The lowest level base class of an IGraphics context.
Definition: IGraphics.h:86
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:670
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:2539
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:2569
Control to test animation.
void Draw(IGraphics &g) override
Draw the control to the graphics context.
void OnMouseDown(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse down event on this control.
Used to manage color data, independent of draw class/platform.
static IColor LinearInterpolateBetween(const IColor &start, const IColor &dest, float progress)
Helper function to linear interpolate between two IColors.
static IColor GetRandomColor(bool randomAlpha=false)
Get a random IColor.
Used to manage mouse modifiers i.e.
Used to manage a rectangular area, independent of draw class/platform.
static IRECT LinearInterpolateBetween(const IRECT &start, const IRECT &dest, float progress)
Get a rectangle that is a linear interpolation between start and dest
IRECT GetRandomSubRect() const