Formatting API
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / controls / super-blur-view / super-blur-view.h
1 #ifndef DALI_TOOLKIT_SUPER_BLUR_VIEW_H
2 #define DALI_TOOLKIT_SUPER_BLUR_VIEW_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
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/rendering/texture.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/public-api/controls/control.h>
26
27 namespace Dali
28 {
29 namespace Toolkit
30 {
31 namespace Internal DALI_INTERNAL
32 {
33 class SuperBlurView;
34 }
35
36 /**
37  * @brief SuperBlurView accepts an image as input, and displays/animates it with various blur strength.
38  * Usage example:-
39  *
40  *  // initialise\n
41  *  SuperBlurView blurView = SuperBlurView::New( blurLevels );\n
42  *  blurView.SetProperty( Actor::Property::SIZE, size );  // it is important to set the display size before set the input image!!
43  *  Stage::GetCurrent().Add(blurView);\n
44  *
45  *  // Set the input image
46  *  blurView.SetProperty( SuperBlurView::Property::IMAGE_URL, url );\n
47  *
48  *  // animate the strength of the blur - this can fade between no blur and full blur. .\n
49  *  Animation blurAnimation = Animation::New( ... );\n
50  *  blurAnimation.AnimateTo( Property( blurView, blurView.GetBlurStrengthPropertyIndex() ), ... );\n
51  *  blurAnimation.Play();\n
52  */
53 class DALI_TOOLKIT_API SuperBlurView : public Control
54 {
55 public:
56   /**
57    * @brief The start and end property ranges for this control.
58    */
59   enum PropertyRange
60   {
61     PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
62     PROPERTY_END_INDEX   = PROPERTY_START_INDEX + 1000 ///< Reserve property indices
63   };
64
65   /**
66    * @brief An enumeration of properties belonging to the SuperBlurView class.
67    */
68   struct Property
69   {
70     enum
71     {
72       IMAGE_URL = PROPERTY_START_INDEX, ///< name "imageUrl",    @see SetTexture,    type String
73     };
74   };
75
76   /**
77    * @brief Signal type for notifications.
78    */
79   typedef Signal<void(SuperBlurView source)> SuperBlurViewSignal;
80
81   /**
82    * @brief Creates an empty SuperBlurView handle.
83    */
84   SuperBlurView();
85
86   /**
87    * @brief Create an initialized SuperBlurView.
88    *
89    * @param[in] blurLevels The final blur strength level. It decides how many filtering passes are used to create the group of blurred textures.
90    * @return A handle to a newly allocated Dali resource
91    */
92   static SuperBlurView New(unsigned int blurLevels);
93
94   /**
95    * @brief Copy constructor.
96    *
97    * Creates another handle that points to the same real object.
98    * @param[in] handle the handle to copy from
99    */
100   SuperBlurView(const SuperBlurView& handle);
101
102   /**
103    * @brief Assignment operator.
104    *
105    * Changes this handle to point to another real object.
106    * @param[in] rhs the handle to copy from
107    * @return a reference to this
108    */
109   SuperBlurView& operator=(const SuperBlurView& rhs);
110
111   /**
112    * @brief Destructor
113    *
114    * This is non-virtual since derived Handle types must not contain data or virtual methods.
115    */
116   ~SuperBlurView();
117
118   /**
119    * @brief Downcast an Object handle to SuperBlurView.
120    *
121    * If handle points to a SuperBlurView, the downcast produces valid handle.
122    * If not, the returned handle is left uninitialized.
123    * @param[in] handle Handle to an object
124    * @return handle to a SuperBlurView or an uninitialized handle
125    */
126   static SuperBlurView DownCast(BaseHandle handle);
127
128   /**
129    * @brief Sets a custom texture to be blurred.
130    *
131    * @param[in] texture The texture that the user wishes to blur
132    */
133   void SetTexture(Texture texture);
134
135   /**
136    * @brief Get the index of the property that can be used to fade the blur in / out.
137    *
138    * This is the overall strength of the blur.
139    * User can use this to animate the blur. A value of 0.0 is zero blur and 1.0 is full blur. Default is 0.0.
140    * @return Index of the property that can be used to fade the blur in / out
141    */
142   Dali::Property::Index GetBlurStrengthPropertyIndex() const;
143
144   /**
145    * @brief Set the blur strength to display the texture.
146    *
147    * @param[in] blurStrength The blur strength used to display the texture.
148    */
149   void SetBlurStrength(float blurStrength);
150
151   /**
152    * @brief Get the current blur strength.
153    *
154    * @return The current blur strength
155    */
156   float GetCurrentBlurStrength() const;
157
158   /**
159    * @brief Connect to this signal to be notified when the all the blurs have completed.
160    *
161    * @return The BlurFinished signal
162    */
163   SuperBlurViewSignal& BlurFinishedSignal();
164
165   /**
166    * @brief Get the blurred texture.
167    *
168    * Should wait for the BlurFinishedSignal before calling this method.
169    * @param[in] level Indicate which blurred texture to get, must be a value between 1 and  blurLevels
170    * @return The level-th blurred texture
171    */
172   Texture GetBlurredTexture(unsigned int level);
173
174 public: // Not intended for application developers
175   /**
176    * @brief Creates a handle using the Toolkit::Internal implementation.
177    *
178    * @param[in]  implementation  The Control implementation.
179    */
180   DALI_INTERNAL SuperBlurView(Internal::SuperBlurView& implementation);
181
182   /**
183    * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
184    *
185    * @param[in]  internal  A pointer to the internal CustomActor.
186    */
187   explicit DALI_INTERNAL SuperBlurView(Dali::Internal::CustomActor* internal);
188 };
189
190 } // namespace Toolkit
191
192 } // namespace Dali
193
194 #endif /* DALI_TOOLKIT_SUPER_BLUR_VIEW_H */