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