bb0ed9afaf489346ecd9f255d9ebf51018b08ef1
[platform/core/uifw/dali-demo.git] / examples / transitions / shadow-button-impl.h
1 #ifndef DALI_DEMO_INTERNAL_SHADOW_BUTTON_IMPL_H
2 #define DALI_DEMO_INTERNAL_SHADOW_BUTTON_IMPL_H
3
4 /*
5  * Copyright (c) 2020 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 "shadow-button.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 ShadowButton : public Dali::Toolkit::Internal::Control
33 {
34 public:
35   /**
36    * Instantiate a new ShadowButton object
37    */
38   static Demo::ShadowButton New();
39   ShadowButton();
40   ~ShadowButton();
41
42 public: // API
43   /**
44    * @brief Set the button to be active or inactive.
45    *
46    * The button will perform a transition if there is a state change.
47    * @param[in] active The active state
48    */
49   void SetActiveState( bool active );
50
51   /**
52    * Get the active state
53    * @return the active state
54    */
55   bool GetActiveState();
56
57   /**
58    * Set the check state
59    * @param[in] checkState The state of the checkbox
60    */
61   void SetCheckState( bool checkState );
62
63   /**
64    * Get the check state
65    * @return the check state
66    */
67   bool GetCheckState();
68
69 public:  // Properties
70   /**
71    * Called when a property of an object of this type is set.
72    * @param[in] object The object whose property is set.
73    * @param[in] index The property index.
74    * @param[in] value The new property value.
75    */
76   static void SetProperty( Dali::BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value );
77
78   /**
79    * Called to retrieve a property of an object of this type.
80    * @param[in] object The object whose property is to be retrieved.
81    * @param[in] index The property index.
82    * @return The current value of the property.
83    */
84   static Dali::Property::Value GetProperty( Dali::BaseObject* object, Dali::Property::Index propertyIndex );
85
86 private: // From Control
87   /**
88    * @copydoc Toolkit::Button::OnInitialize()
89    */
90   virtual void OnInitialize();
91
92   /**
93    * @copydoc Toolkit::Button::OnSceneConnection()
94    */
95   virtual void OnSceneConnection( int depth );
96
97   /**
98    * @copydoc Toolkit::Button::OnSceneDisconnection()
99    */
100   virtual void OnSceneDisconnection();
101
102   /**
103    * @copydoc Toolkit::Button::OnSizeSet()
104    */
105   virtual void OnSizeSet( const Dali::Vector3& targetSize );
106
107   /**
108    * @copydoc Toolkit::Button::OnRelayout()
109    */
110   virtual void OnRelayout( const Dali::Vector2& targetSize, Dali::RelayoutContainer& container );
111   /**
112    * @copydoc Toolkit::Button::GetNaturalSize
113    */
114   virtual Dali::Vector3 GetNaturalSize();
115
116   /**
117    * @copydoc Toolkit::Button::OnStyleChange
118    */
119   virtual void OnStyleChange( Dali::Toolkit::StyleManager styleManager, Dali::StyleChange::Type change );
120
121 private:
122   struct Transition
123   {
124     Dali::Property::Index mTransitionId;
125     Dali::Toolkit::TransitionData mTransitionData;
126     Dali::Animation mAnimation;
127     bool mPlaying;
128
129     Transition( Dali::Property::Index index, Dali::Toolkit::TransitionData transitionData )
130     : mTransitionId( index ),
131       mTransitionData( transitionData ),
132       mPlaying(false)
133     {
134     }
135   private:
136     Transition();
137   };
138
139   typedef std::vector<Transition> Transitions;
140
141   struct Transform
142   {
143     Dali::Property::Index mTransformId;
144     Dali::Property::Map   mTransform;
145
146     Transform( Dali::Property::Index index, Dali::Property::Map& map )
147     : mTransformId(index),
148       mTransform( map )
149     {
150     }
151   };
152   typedef std::vector<Transform> Transforms;
153
154 private:
155   void StartTransition( Dali::Property::Index transitionId );
156
157   void OnTransitionFinished( Dali::Animation& handle );
158
159   Transitions::iterator FindTransition( Dali::Property::Index index );
160
161   Transforms::iterator FindTransform( Dali::Property::Index index );
162
163   /**
164    * Relayout the visuals as a result of size negotiation using
165    * the transforms provided in the stylesheet
166    */
167   void RelayoutVisuals( const Dali::Vector2& targetSize );
168
169   /**
170    * Relayout the visuals as a result of size negotiation using
171    * programmatically generated transforms
172    */
173   void RelayoutVisualsManually( const Dali::Vector2& targetSize );
174
175   void ResetVisual( Dali::Property::Index        index,
176                     Dali::Toolkit::Visual::Base& visual,
177                     const Dali::Property::Value& value );
178
179   void ResetTransition( Dali::Property::Index        index,
180                         const Dali::Property::Value& value );
181
182   void StoreTargetLayouts( Dali::Toolkit::TransitionData transitionData );
183
184 private:
185   // undefined
186   ShadowButton( const ShadowButton& );
187   ShadowButton& operator=( const ShadowButton& );
188
189 private:
190   // Data
191   Dali::Toolkit::Visual::Base mBackgroundVisual;
192   Dali::Toolkit::Visual::Base mCheckboxBgVisual;
193   Dali::Toolkit::Visual::Base mCheckboxFgVisual;
194   Dali::Toolkit::Visual::Base mLabelVisual;
195
196   Transitions mTransitions;
197   Transforms  mTransforms;
198   bool        mCheckState;
199   bool        mActiveState;
200 };
201
202 } // Internal
203
204 inline Internal::ShadowButton& GetImpl( Demo::ShadowButton& handle )
205 {
206   DALI_ASSERT_ALWAYS( handle );
207   Dali::RefObject& object = handle.GetImplementation();
208   return static_cast<Internal::ShadowButton&>(object);
209 }
210
211 inline const Internal::ShadowButton& GetImpl( const Demo::ShadowButton& handle )
212 {
213   DALI_ASSERT_ALWAYS( handle );
214   const Dali::RefObject& object = handle.GetImplementation();
215   return static_cast<const Internal::ShadowButton&>(object);
216 }
217
218 } // Demo
219
220 #endif //  DALI_DEMO_SHADOW_BUTTON_IMPL_H