Example of transitions of each visual type.
[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) 2016 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/visual-factory/visual-base.h>
24 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
25
26 namespace Demo
27 {
28
29 namespace Internal // To use TypeRegistry, handle and body classes need the same name
30 {
31
32 class BeatControl : public Dali::Toolkit::Internal::Control
33 {
34 public:
35   /**
36    * Instantiate a new BeatControl object
37    */
38   static Demo::BeatControl New();
39   BeatControl();
40   ~BeatControl();
41
42 public: // API
43   void StartBounceAnimation();
44
45   void StartXAnimation();
46
47   void StartYAnimation();
48
49   void StartFadeAnimation();
50
51 public:  // Properties
52   /**
53    * Called when a property of an object of this type is set.
54    * @param[in] object The object whose property is set.
55    * @param[in] index The property index.
56    * @param[in] value The new property value.
57    */
58   static void SetProperty( Dali::BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value );
59
60   /**
61    * Called to retrieve a property of an object of this type.
62    * @param[in] object The object whose property is to be retrieved.
63    * @param[in] index The property index.
64    * @return The current value of the property.
65    */
66   static Dali::Property::Value GetProperty( Dali::BaseObject* object, Dali::Property::Index propertyIndex );
67
68 private: // From Control
69   /**
70    * @copydoc Toolkit::Control::OnInitialize()
71    */
72   virtual void OnInitialize();
73
74   /**
75    * @copydoc Toolkit::Control::OnStageConnect()
76    */
77   virtual void OnStageConnection( int depth );
78
79   /**
80    * @copydoc Toolkit::Control::OnStageDisconnection()
81    */
82   virtual void OnStageDisconnection();
83
84   /**
85    * @copydoc Toolkit::Control::OnSizeSet()
86    */
87   virtual void OnSizeSet( const Dali::Vector3& targetSize );
88
89   /**
90    * @copydoc Toolkit::Control::OnRelayout()
91    */
92   virtual void OnRelayout( const Dali::Vector2& targetSize, Dali::RelayoutContainer& container );
93   /**
94    * @copydoc Toolkit::Control::GetNaturalSize
95    */
96   virtual Dali::Vector3 GetNaturalSize();
97
98   /**
99    * @copydoc Toolkit::Control::OnStyleChange
100    */
101   virtual void OnStyleChange( Dali::Toolkit::StyleManager styleManager, Dali::StyleChange::Type change );
102
103 private:
104   void OnBounceAnimationFinished( Dali::Animation& handle );
105   void OnXAnimationFinished( Dali::Animation& src );
106   void OnYAnimationFinished( Dali::Animation& src );
107   void OnFadeAnimationFinished( Dali::Animation& src );
108
109   /**
110    * Relayout the visuals as a result of size negotiation
111    */
112   void RelayoutVisuals( const Dali::Vector2& targetSize );
113
114 private:
115   //undefined
116   BeatControl( const BeatControl& );
117   BeatControl& operator=( const BeatControl& );
118
119 private:
120   // Implementation details
121   Dali::Toolkit::Visual::Base mVisual;
122   Dali::Toolkit::TransitionData mBounceTransition;
123   Dali::Toolkit::TransitionData mLeftTransition;
124   Dali::Toolkit::TransitionData mUpTransition;
125   Dali::Toolkit::TransitionData mFadeTransition;
126   Dali::Animation mAnimation;
127   Dali::Animation mXAnimation;
128   Dali::Animation mYAnimation;
129   Dali::Animation mFadeAnimation;
130   Dali::Vector2 mTransformSize;
131   int mAnimationPlaying;
132 };
133
134 } // Internal
135
136 inline Internal::BeatControl& GetImpl( Demo::BeatControl& handle )
137 {
138   DALI_ASSERT_ALWAYS( handle );
139   Dali::RefObject& object = handle.GetImplementation();
140   return static_cast<Internal::BeatControl&>(object);
141 }
142
143 inline const Internal::BeatControl& GetImpl( const Demo::BeatControl& handle )
144 {
145   DALI_ASSERT_ALWAYS( handle );
146   const Dali::RefObject& object = handle.GetImplementation();
147   return static_cast<const Internal::BeatControl&>(object);
148 }
149
150 } // Demo
151
152 #endif //  DALI_DEMO_BEAT_CONTROL_IMPL_H