Merge "ItemView: Fade off overshoot indicator when moving in opposite direction"...
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / shadow-view / shadow-view-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_SHADOW_VIEW_H__
2 #define __DALI_TOOLKIT_INTERNAL_SHADOW_VIEW_H__
3
4 /*
5  * Copyright (c) 2014 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 <sstream>
23 #include <cmath>
24 #include <dali/public-api/actors/camera-actor.h>
25 #include <dali/public-api/animation/constraints.h>
26 #include <dali/public-api/render-tasks/render-task.h>
27 #include <dali/public-api/shader-effects/shader-effect.h>
28 #include <dali/public-api/object/property-map.h>
29
30 // INTERNAL INCLUDES
31 #include <dali-toolkit/devel-api/controls/shadow-view/shadow-view.h>
32 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
33 #include <dali-toolkit/public-api/controls/control-impl.h>
34 #include <dali-toolkit/internal/filters/blur-two-pass-filter.h>
35
36 namespace Dali
37 {
38
39 namespace Toolkit
40 {
41
42 class ShadowView;
43
44 namespace Internal
45 {
46
47 /**
48  * ShadowView implementation class
49  */
50 class ShadowView : public Control
51 {
52 public:
53
54   /**
55    * @copydoc Dali::Toolkit::ShadowView::ShadowView
56    */
57   ShadowView();
58
59   /**
60    * @copydoc Dali::Toolkit::ShadowView::ShadowView
61    */
62   ShadowView(float downsampleWidthScale, float downsampleHeightScale);
63
64   /**
65    * @copydoc Dali::Toolkit::ShadowView::~ShadowView
66    */
67   virtual ~ShadowView();
68
69   /**
70    * @copydoc Dali::Toolkit::ShadowView::New(float downsampleWidthScale, float downsampleHeightScale)
71    */
72   static Dali::Toolkit::ShadowView New(float downsampleWidthScale, float downsampleHeightScale);
73
74   /**
75    * @copydoc Dali::Toolkit::ShadowView::Add(Actor child)
76    */
77   void Add(Actor child);
78
79   /**
80    * @copydoc Dali::Toolkit::ShadowView::Remove(Actor child)
81    */
82   void Remove(Actor child);
83
84   /**
85    * @copydoc Dali::Toolkit::ShadowView::SetShadowPlaneBackground(Actor shadowPlaneBackground)
86    */
87   void SetShadowPlaneBackground(Actor shadowPlaneBackground);
88
89   /**
90    * @copydoc Dali::Toolkit::ShadowView::SetPointLight(Actor pointLight)
91    */
92   void SetPointLight(Actor pointLight);
93
94   /**
95    * @copydoc Dali::Toolkit::ShadowView::SetPointLightFieldOfView(float fieldOfView)
96    */
97   void SetPointLightFieldOfView(float fieldOfView);
98
99   /**
100    * @copydoc Dali::Toolkit::ShadowView::SetShadowColor(Vector4 color)
101    */
102   void SetShadowColor(Vector4 color);
103
104   /**
105    * @copydoc Dali::Toolkit::ShadowView::Activate()
106    */
107   void Activate();
108
109   /**
110    * @copydoc Dali::Toolkit::ShadowView::Deactivate()
111    */
112   void Deactivate();
113
114   /**
115    * @copydoc Dali::Toolkit::ShadowView::GetBlurStrengthPropertyIndex()
116    */
117   Property::Index GetBlurStrengthPropertyIndex() const {return mBlurStrengthPropertyIndex;}
118
119   /**
120    * @copydoc Dali::Toolkit::ShadowView::GetShadowColorPropertyIndex()
121    */
122   Property::Index GetShadowColorPropertyIndex() const {return mShadowColorPropertyIndex;}
123
124   void SetShaderConstants();
125
126 private:
127
128   virtual void OnInitialize();
129   virtual void OnSizeSet(const Vector3& targetSize);
130
131   /**
132    * Constrain the camera actor to the position of the point light, pointing
133    * at the center of the shadow plane.
134    */
135   void ConstrainCamera();
136
137   void CreateRenderTasks();
138   void RemoveRenderTasks();
139   void CreateBlurFilter();
140
141 private:
142   Toolkit::ImageView mShadowPlane; // Shadow renders into this actor
143   Actor mShadowPlaneBg; // mShadowPlane renders directly in front of this actor
144   Actor mPointLight;  // Shadow is cast from this point light
145
146   /////////////////////////////////////////////////////////////
147   FrameBufferImage mSceneFromLightRenderTarget;  // for rendering normal scene seen from light to texture instead of the screen
148
149   FrameBufferImage mOutputImage;
150
151   Actor mChildrenRoot; // Subtree for all user added child actors that should be rendered normally
152   Actor mBlurRootActor; // Root actor for blur filter processing
153   RenderTask mRenderSceneTask;
154
155   CameraActor mCameraActor; // Constrained to same position as mPointLight and pointing at mShadowPlane
156
157   Property::Map mShadowRenderShader;
158   BlurTwoPassFilter mBlurFilter;
159
160   Vector4 mCachedShadowColor;                               ///< Cached Shadow color.
161   Vector4 mCachedBackgroundColor;                           ///< Cached Shadow background color (same as shadow color but with alpha at 0.0)
162
163   /////////////////////////////////////////////////////////////
164   // Properties that can be animated
165   Property::Index mBlurStrengthPropertyIndex;
166   Property::Index mShadowColorPropertyIndex;
167   float mDownsampleWidthScale;
168   float mDownsampleHeightScale;
169
170 private:
171
172   // Undefined copy constructor.
173   ShadowView( const ShadowView& );
174
175   // Undefined assignment operator.
176   ShadowView& operator=( const ShadowView& );
177 };
178
179 } // namespace Internal
180
181
182 // Helpers for public-api forwarding methods
183 inline Toolkit::Internal::ShadowView& GetImpl( Toolkit::ShadowView& obj )
184 {
185   DALI_ASSERT_ALWAYS(obj);
186   Dali::RefObject& handle = obj.GetImplementation();
187   return static_cast<Toolkit::Internal::ShadowView&>(handle);
188 }
189
190 inline const Toolkit::Internal::ShadowView& GetImpl( const Toolkit::ShadowView& obj )
191 {
192   DALI_ASSERT_ALWAYS(obj);
193   const Dali::RefObject& handle = obj.GetImplementation();
194   return static_cast<const Toolkit::Internal::ShadowView&>(handle);
195 }
196
197
198 } // namespace Toolkit
199
200 } // namespace Dali
201
202 #endif // __DALI_TOOLKIT_INTERNAL_SHADOW_VIEW_H__