[dali_2.3.20] Merge branch 'devel/master'
[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) 2022 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 Move constructor.
113    *
114    * Creates another handle that points to the same real object.
115    * @param[in] handle the handle to move from
116    */
117   SuperBlurView(SuperBlurView&& handle);
118
119   /**
120    * @brief Move assignment operator.
121    *
122    * Changes this handle to point to another real object.
123    * @param[in] rhs the handle to move from
124    * @return a reference to this
125    */
126   SuperBlurView& operator=(SuperBlurView&& rhs);
127
128   /**
129    * @brief Destructor
130    *
131    * This is non-virtual since derived Handle types must not contain data or virtual methods.
132    */
133   ~SuperBlurView();
134
135   /**
136    * @brief Downcast an Object handle to SuperBlurView.
137    *
138    * If handle points to a SuperBlurView, the downcast produces valid handle.
139    * If not, the returned handle is left uninitialized.
140    * @param[in] handle Handle to an object
141    * @return handle to a SuperBlurView or an uninitialized handle
142    */
143   static SuperBlurView DownCast(BaseHandle handle);
144
145   /**
146    * @brief Sets a custom texture to be blurred.
147    *
148    * @param[in] texture The texture that the user wishes to blur
149    */
150   void SetTexture(Texture texture);
151
152   /**
153    * @brief Get the index of the property that can be used to fade the blur in / out.
154    *
155    * This is the overall strength of the blur.
156    * 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.
157    * @return Index of the property that can be used to fade the blur in / out
158    */
159   Dali::Property::Index GetBlurStrengthPropertyIndex() const;
160
161   /**
162    * @brief Set the blur strength to display the texture.
163    *
164    * @param[in] blurStrength The blur strength used to display the texture.
165    */
166   void SetBlurStrength(float blurStrength);
167
168   /**
169    * @brief Get the current blur strength.
170    *
171    * @return The current blur strength
172    */
173   float GetCurrentBlurStrength() const;
174
175   /**
176    * @brief Connect to this signal to be notified when the all the blurs have completed.
177    *
178    * @return The BlurFinished signal
179    */
180   SuperBlurViewSignal& BlurFinishedSignal();
181
182   /**
183    * @brief Get the blurred texture.
184    *
185    * Should wait for the BlurFinishedSignal before calling this method.
186    * @param[in] level Indicate which blurred texture to get, must be a value between 1 and  blurLevels
187    * @return The level-th blurred texture
188    */
189   Texture GetBlurredTexture(unsigned int level);
190
191 public: // Not intended for application developers
192   /**
193    * @brief Creates a handle using the Toolkit::Internal implementation.
194    *
195    * @param[in]  implementation  The Control implementation.
196    */
197   DALI_INTERNAL SuperBlurView(Internal::SuperBlurView& implementation);
198
199   /**
200    * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
201    *
202    * @param[in]  internal  A pointer to the internal CustomActor.
203    */
204   explicit DALI_INTERNAL SuperBlurView(Dali::Internal::CustomActor* internal);
205 };
206
207 } // namespace Toolkit
208
209 } // namespace Dali
210
211 #endif /* DALI_TOOLKIT_SUPER_BLUR_VIEW_H */