Changes required after Visual parent-origin & anchor-point defaults change
[platform/core/uifw/dali-demo.git] / examples / visual-transitions / beat-control-impl.h
1 #ifndef DALI_DEMO_INTERNAL_BEAT_CONTROL_IMPL_H
2 #define DALI_DEMO_INTERNAL_BEAT_CONTROL_IMPL_H
3
4 /*
5  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 #include "beat-control.h"
21 #include <dali/public-api/animation/animation.h>
22 #include <dali-toolkit/public-api/controls/control-impl.h>
23 #include <dali-toolkit/devel-api/align-enums.h>
24 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
25 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
26
27 namespace Demo
28 {
29
30 namespace Internal // To use TypeRegistry, handle and body classes need the same name
31 {
32
33 class BeatControl : public Dali::Toolkit::Internal::Control
34 {
35 public:
36   /**
37    * Instantiate a new BeatControl object
38    */
39   static Demo::BeatControl New();
40   BeatControl();
41   ~BeatControl();
42
43 public: // API
44   void StartBounceAnimation();
45
46   void StartXAnimation();
47
48   void StartYAnimation();
49
50   void StartFadeAnimation();
51
52 public:  // Properties
53   /**
54    * Called when a property of an object of this type is set.
55    * @param[in] object The object whose property is set.
56    * @param[in] index The property index.
57    * @param[in] value The new property value.
58    */
59   static void SetProperty( Dali::BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value );
60
61   /**
62    * Called to retrieve a property of an object of this type.
63    * @param[in] object The object whose property is to be retrieved.
64    * @param[in] index The property index.
65    * @return The current value of the property.
66    */
67   static Dali::Property::Value GetProperty( Dali::BaseObject* object, Dali::Property::Index propertyIndex );
68
69 private: // From Control
70   /**
71    * @copydoc Toolkit::Control::OnInitialize()
72    */
73   virtual void OnInitialize();
74
75   /**
76    * @copydoc Toolkit::Control::OnStageConnect()
77    */
78   virtual void OnStageConnection( int depth );
79
80   /**
81    * @copydoc Toolkit::Control::OnStageDisconnection()
82    */
83   virtual void OnStageDisconnection();
84
85   /**
86    * @copydoc Toolkit::Control::OnSizeSet()
87    */
88   virtual void OnSizeSet( const Dali::Vector3& targetSize );
89
90   /**
91    * @copydoc Toolkit::Control::OnRelayout()
92    */
93   virtual void OnRelayout( const Dali::Vector2& targetSize, Dali::RelayoutContainer& container );
94   /**
95    * @copydoc Toolkit::Control::GetNaturalSize
96    */
97   virtual Dali::Vector3 GetNaturalSize();
98
99   /**
100    * @copydoc Toolkit::Control::OnStyleChange
101    */
102   virtual void OnStyleChange( Dali::Toolkit::StyleManager styleManager, Dali::StyleChange::Type change );
103
104 private:
105   void OnBounceAnimationFinished( Dali::Animation& handle );
106   void OnXAnimationFinished( Dali::Animation& src );
107   void OnYAnimationFinished( Dali::Animation& src );
108   void OnFadeAnimationFinished( Dali::Animation& src );
109
110   /**
111    * Relayout the visuals as a result of size negotiation
112    */
113   void RelayoutVisuals( const Dali::Vector2& targetSize );
114
115 private:
116   //undefined
117   BeatControl( const BeatControl& );
118   BeatControl& operator=( const BeatControl& );
119
120 private:
121   // Implementation details
122   Dali::Toolkit::Visual::Base mVisual;
123   Dali::Toolkit::TransitionData mBounceTransition;
124   Dali::Toolkit::TransitionData mLeftTransition;
125   Dali::Toolkit::TransitionData mUpTransition;
126   Dali::Toolkit::TransitionData mFadeTransition;
127   Dali::Animation mAnimation;
128   Dali::Animation mXAnimation;
129   Dali::Animation mYAnimation;
130   Dali::Animation mFadeAnimation;
131   Dali::Vector2 mTransformSize;
132   Dali::Toolkit::Align::Type mTransformOrigin;
133   Dali::Toolkit::Align::Type mTransformAnchorPoint;
134   int mAnimationPlaying;
135 };
136
137 } // Internal
138
139 inline Internal::BeatControl& GetImpl( Demo::BeatControl& handle )
140 {
141   DALI_ASSERT_ALWAYS( handle );
142   Dali::RefObject& object = handle.GetImplementation();
143   return static_cast<Internal::BeatControl&>(object);
144 }
145
146 inline const Internal::BeatControl& GetImpl( const Demo::BeatControl& handle )
147 {
148   DALI_ASSERT_ALWAYS( handle );
149   const Dali::RefObject& object = handle.GetImplementation();
150   return static_cast<const Internal::BeatControl&>(object);
151 }
152
153 } // Demo
154
155 #endif //  DALI_DEMO_BEAT_CONTROL_IMPL_H