Change Visual depth index API from float to int
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / progress-bar / progress-bar-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_PROGRESS_BAR_H
2 #define DALI_TOOLKIT_INTERNAL_PROGRESS_BAR_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
21
22 // INTERNAL INCLUDES
23 #include <dali-toolkit/public-api/controls/control-impl.h>
24 #include <dali/public-api/animation/animation.h>
25 #include <dali-toolkit/devel-api/controls/progress-bar/progress-bar.h>
26 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
27
28 namespace Dali
29 {
30
31 namespace Toolkit
32 {
33
34 namespace Internal
35 {
36
37 class ProgressBar;
38
39 typedef Dali::IntrusivePtr< ProgressBar > ProgressBarPtr;
40
41 /**
42  * @copydoc Toolkit::ProgressBar
43  */
44 class ProgressBar : public Control
45 {
46 public:
47
48   /**
49    * Create a new ProgressBar.
50    *
51    * @return A public handle to the newly allocated ProgressBar.
52    */
53   static Dali::Toolkit::ProgressBar New();
54
55 public:
56
57   // Properties
58
59   /**
60    * Set the value of the ProgressBar
61    *
62    * @param[in] value The value to set. Will be clamped to [lowerBound .. upperBound]
63    */
64   void SetProgressValue( float value );
65
66   /**
67    * Get the value of the ProgressBar
68    *
69    * @return The current value of the ProgressBar
70    */
71   float GetProgressValue() const;
72
73   /**
74    * Set the secondary progress value of the ProgressBar
75    *
76    * @param[in] value The secondary progress value to set. Will be clamped to [lowerBound .. upperBound]
77    */
78   void SetSecondaryProgressValue( float value );
79
80   /**
81    * Get the secondary progress value of the ProgressBar
82    *
83    * @return The current secondary progress value of the ProgressBar
84    */
85   float GetSecondaryProgressValue() const;
86
87   /**
88    * Set the indeterminate state of the ProgressBar
89    *
90    * @param[in] value The value to set.
91    */
92   void SetIndeterminate( bool value );
93
94   /**
95    * Get the indeterminate state value of the ProgressBar
96    *
97    * @return The current determined state of the ProgressBar
98    */
99   bool GetIndeterminate() const;
100
101   /**
102    * Set the indeterminate visual transition of the ProgressBar
103    *
104    * @param[in] Transition data map to set.
105    */
106   void SetIndeterminateVisualTransition( Property::Map transtion );
107
108   /**
109    * Get the indeterminate visual transition data map of the ProgressBar
110    *
111    * @return The current indeterminate visual transition data map of the ProgressBar
112    */
113   Property::Map GetIndeterminateVisualTransition() const;
114
115   /**
116    * Play the indeterminate visual transition
117    */
118   void PlayIndeterminateVisualTransition();
119
120 public:
121   //Signals
122
123   /**
124    * @copydoc toolkit::progressbar::valuechangedsignal()
125    */
126   Toolkit::ProgressBar::ValueChangedSignalType& ValueChangedSignal();
127
128
129   /**
130    * Connects a callback function with the object's signals.
131    * @param[in] object The object providing the signal.
132    * @param[in] tracker Used to disconnect the signal.
133    * @param[in] signalName The signal to connect to.
134    * @param[in] functor A newly allocated FunctorDelegate.
135    * @return True if the signal was connected.
136    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
137    */
138   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName,
139                                FunctorDelegate* functor );
140
141   // Properties
142
143   /**
144    * Called when a property of an object of this type is set.
145    * @param[in] object The object whose property is set.
146    * @param[in] index The property index.
147    * @param[in] value The new property value.
148    */
149   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
150
151   /**
152    * Called to retrieve a property of an object of this type.
153    * @param[in] object The object whose property is to be retrieved.
154    * @param[in] index The property index.
155    * @return The current value of the property.
156    */
157   static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
158
159 protected:
160
161   /**
162    * Construct a new ProgressBar.
163    */
164   ProgressBar();
165
166   /**
167    * A reference counted object may only be deleted by calling Unreference()
168    */
169   virtual ~ProgressBar();
170
171   /**
172    * @copydoc CustomActorImpl::OnRelayout()
173    */
174   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
175
176   /**
177    * @copydoc CustomActorImpl::GetNaturalSize()
178    */
179   virtual Vector3 GetNaturalSize();
180
181 private:
182
183   /**
184    * Domain is a from/to pair
185    */
186   struct Domain
187   {
188     Vector2 from;
189     Vector2 to;
190
191     Domain()
192     {
193     }
194     Domain( Vector2 fromVal, Vector2 toVal )
195         : from( fromVal ), to( toVal )
196     {
197     }
198   };
199
200 private:
201
202   /**
203    * @copydoc Toolkit::Control::OnInitialize()
204    */
205   virtual void OnInitialize();
206
207   /**
208    * Get the range of the valid values the ProgressBar handle can move between
209    *
210    * @param[in] currentSize The current size of the ProgressBar
211    * @return The range as a domain pair
212    */
213   Domain CalcDomain( const Vector2& currentSize );
214
215   /**
216    * Set indeterminate visual transition animation
217    */
218   void SetIndeterminateVisualTransition( Toolkit::TransitionData transtion );
219
220   /**
221    * Convert value to transition data
222    */
223   Toolkit::TransitionData ConvertPropertyToTransition( const Property::Value& value );
224
225   /**
226    * Update progress bar label when progress value is changed
227    */
228   void CreateVisualsForComponent( Property::Index index, const Property::Value& value, const int visualDepth );
229
230   /**
231    * Update progress bar label when progress value is changed
232    */
233   bool GetPropertyMapForVisual( Property::Index visualIndex, Property::Map& retreivedMap ) const;
234
235   /**
236    * Check if we should start animating
237    */
238   virtual void OnStageConnection( int depth );
239
240 private:
241
242   // Undefined
243   ProgressBar( const ProgressBar& );
244
245   // Undefined
246   ProgressBar& operator=( const ProgressBar& rhs );
247
248 private:
249
250   Domain mDomain;                                                     ///< Current domain of the handle
251
252   Animation mIndeterminateVisualAni;                                  ///< Animation for indetrminate visual. Transition animation.
253   Toolkit::ProgressBar::ValueChangedSignalType mValueChangedSignal;   ///< Signal emitted when the value is changed
254
255   Toolkit::TransitionData mIndeterminateVisualTransition;             ///< Transition data map for mIndeterminateVisualAni
256   float mProgressValue;                                               ///< Current value of ProgressBar
257   float mSecondaryProgressValue;                                      ///< Current loading value of ProgressBar
258   bool mIndeterminate;                                                ///< Whether the progress state is determined or not
259 };
260
261 } // namespace Internal
262
263 // Helpers for public-api forwarding methods
264
265 inline Toolkit::Internal::ProgressBar& GetImpl( Toolkit::ProgressBar& pub )
266 {
267   DALI_ASSERT_ALWAYS( pub );
268
269   Dali::RefObject& handle = pub.GetImplementation();
270
271   return static_cast< Toolkit::Internal::ProgressBar& >( handle );
272 }
273
274 inline const Toolkit::Internal::ProgressBar& GetImpl( const Toolkit::ProgressBar& pub )
275 {
276   DALI_ASSERT_ALWAYS( pub );
277
278   const Dali::RefObject& handle = pub.GetImplementation();
279
280   return static_cast< const Toolkit::Internal::ProgressBar& >( handle );
281 }
282
283 } // namespace Toolkit
284
285 } // namespace Dali
286
287 #endif // DALI_TOOLKIT_INTERNAL_PROGRESS_BAR_H