1 // This file is part of VSTGUI. It is subject to the license terms
2 // in the LICENSE file found in the top-level directory of this
3 // distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
4
5 #include "animationtest.h"
6 #include "base/source/fobject.h"
7 #include "vstgui/lib/animation/animations.h"
8 #include "vstgui/uidescription/delegationcontroller.h"
9
10 using namespace Steinberg;
11 using namespace Steinberg::Vst;
12
13 namespace VSTGUI {
14
15 //------------------------------------------------------------------------
16 FUID AnimationTestProcessor::cid (0xF1306D3E, 0xCF9F432E, 0x8A9B6FC2, 0xC59A3CAF);
17 FUID AnimationTestController::cid (0xCACC9448, 0xA00C47DF, 0xA7CDE656, 0xF3DD9BA1);
18
19 //------------------------------------------------------------------------
20 //------------------------------------------------------------------------
21 //------------------------------------------------------------------------
AnimationTestProcessor()22 AnimationTestProcessor::AnimationTestProcessor ()
23 {
24 setControllerClass (AnimationTestController::cid);
25 }
26
27 //------------------------------------------------------------------------
28 //------------------------------------------------------------------------
29 //------------------------------------------------------------------------
30 class TestAnimationController : public DelegationController, public FObject
31 {
32 public:
33 TestAnimationController (IController* controller, Parameter* switchParameter);
34 ~TestAnimationController ();
35
36 CView* verifyView (CView* view, const UIAttributes& attributes, const IUIDescription* description) override;
37
38 void PLUGIN_API update (FUnknown* changedUnknown, int32 message) override;
39 OBJ_METHODS(TestAnimationController, FObject)
40 protected:
41 Parameter* switchParameter;
42 CView* animationView;
43 CRect originalRect;
44 };
45
46 //------------------------------------------------------------------------
47 class ScaleView : public CViewContainer
48 {
49 public:
50 ScaleView ();
51 CMouseEventResult onMouseEntered (CPoint &where, const CButtonState& buttons) override;
52 CMouseEventResult onMouseExited (CPoint &where, const CButtonState& buttons) override;
53 protected:
54 CRect origRect;
55 };
56
57 //------------------------------------------------------------------------
initialize(FUnknown * context)58 tresult PLUGIN_API AnimationTestController::initialize (FUnknown* context)
59 {
60 tresult res = UIDescriptionBaseController::initialize (context);
61 if (res == kResultTrue)
62 {
63 // add ui parameters
64 StringListParameter* slp = new StringListParameter (USTRING("Animation Switch"), 20000);
65 slp->appendString (USTRING("On"));
66 slp->appendString (USTRING("Off"));
67 uiParameters.addParameter (slp);
68 }
69 return res;
70 }
71
72 //------------------------------------------------------------------------
createView(FIDString name)73 IPlugView* PLUGIN_API AnimationTestController::createView (FIDString name)
74 {
75 if (strcmp (name, ViewType::kEditor) == 0)
76 {
77 return new VST3Editor (this, "view", "AnimationTest.uidesc");
78 }
79 return 0;
80 }
81
82 //------------------------------------------------------------------------
createSubController(const char * name,const IUIDescription * description,VST3Editor * editor)83 IController* AnimationTestController::createSubController (const char* name, const IUIDescription* description, VST3Editor* editor)
84 {
85 if (ConstString (name) == "AnimationController")
86 {
87 return new TestAnimationController (editor, uiParameters.getParameter (20000));
88 }
89 return 0;
90 }
91
92 //------------------------------------------------------------------------
createCustomView(const char * name,const UIAttributes & attributes,const IUIDescription * description,VST3Editor * editor)93 CView* AnimationTestController::createCustomView (const char* name, const UIAttributes& attributes, const IUIDescription* description, VST3Editor* editor)
94 {
95 if (strcmp (name, "ScaleView") == 0)
96 {
97 return new ScaleView;
98 }
99 return 0;
100 }
101
102 //------------------------------------------------------------------------
103 //------------------------------------------------------------------------
104 //------------------------------------------------------------------------
TestAnimationController(IController * controller,Parameter * switchParameter)105 TestAnimationController::TestAnimationController (IController* controller, Parameter* switchParameter)
106 : DelegationController (controller)
107 , switchParameter (switchParameter)
108 , animationView (0)
109 {
110 switchParameter->addDependent (this);
111 }
112
113 //------------------------------------------------------------------------
~TestAnimationController()114 TestAnimationController::~TestAnimationController ()
115 {
116 switchParameter->removeDependent (this);
117 }
118
119 //------------------------------------------------------------------------
verifyView(CView * view,const UIAttributes & attributes,const IUIDescription * description)120 CView* TestAnimationController::verifyView (CView* view, const UIAttributes& attributes, const IUIDescription* description)
121 {
122 view = DelegationController::verifyView (view, attributes, description);
123 if (view)
124 {
125 originalRect = view->getViewSize ();
126 CRect r (originalRect);
127
128 switchParameter->deferUpdate (kChanged);
129 animationView = view;
130 }
131 return view;
132 }
133
134 //------------------------------------------------------------------------
update(FUnknown * changedUnknown,int32 message)135 void PLUGIN_API TestAnimationController::update (FUnknown* changedUnknown, int32 message)
136 {
137 if (message == kChanged)
138 {
139 FUnknownPtr<Parameter> parameter (changedUnknown);
140 if (parameter && animationView && animationView->getFrame ())
141 {
142 Animation::InterpolationTimingFunction* timingFunction = new Animation::InterpolationTimingFunction (200);
143 timingFunction->addPoint (0.5f, 0.2f);
144 int32 value = static_cast<int32> (parameter->toPlain (parameter->getNormalized ()));
145 if (value)
146 {
147 animationView->getFrame ()->getAnimator ()->addAnimation (animationView, "SizeAnimation", new Animation::ViewSizeAnimation (originalRect), timingFunction);
148 }
149 else
150 {
151 CRect r (originalRect);
152 r.bottom += 300;
153 r.right += 80;
154 animationView->getFrame ()->getAnimator ()->addAnimation (animationView, "SizeAnimation", new Animation::ViewSizeAnimation (r), timingFunction);
155 }
156 }
157 }
158 }
159
160 //------------------------------------------------------------------------
ScaleView()161 ScaleView::ScaleView ()
162 :CViewContainer (CRect (0, 0, 0, 0))
163 {
164 setAlphaValue (0.1f);
165 }
166
167 //------------------------------------------------------------------------
onMouseEntered(CPoint & where,const CButtonState & buttons)168 CMouseEventResult ScaleView::onMouseEntered (CPoint &where, const CButtonState& buttons)
169 {
170 if (origRect.isEmpty ())
171 origRect = getViewSize ();
172 CRect r (origRect);
173 r.inset (-40, -15);
174 getFrame ()->getAnimator ()->removeAnimation (this, "AlphaAnimation");
175 getFrame ()->getAnimator ()->removeAnimation (this, "SizeAnimation");
176 getFrame ()->getAnimator ()->addAnimation (this, "AlphaAnimation", new Animation::AlphaValueAnimation (1.f), new Animation::RepeatTimingFunction (new Animation::LinearTimingFunction (300), -1, true));
177 getFrame ()->getAnimator ()->addAnimation (this, "SizeAnimation", new Animation::ViewSizeAnimation (r), new Animation::RepeatTimingFunction (new Animation::LinearTimingFunction (200), -1, true));
178 return CViewContainer::onMouseEntered (where, buttons);
179 }
180
181 //------------------------------------------------------------------------
onMouseExited(CPoint & where,const CButtonState & buttons)182 CMouseEventResult ScaleView::onMouseExited (CPoint &where, const CButtonState& buttons)
183 {
184 getFrame ()->getAnimator ()->addAnimation (this, "AlphaAnimation", new Animation::AlphaValueAnimation (0.1f), new Animation::LinearTimingFunction (100));
185 getFrame ()->getAnimator ()->addAnimation (this, "SizeAnimation", new Animation::ViewSizeAnimation (origRect), new Animation::LinearTimingFunction (100));
186 return CViewContainer::onMouseExited (where, buttons);
187 }
188
189 } // namespace
190
191