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