1 #ifndef __DALI_TOOLKIT_INTERNAL_CUBE_TRANSITION_EFFECT_H__
2 #define __DALI_TOOLKIT_INTERNAL_CUBE_TRANSITION_EFFECT_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 // Licensed under the Flora License, Version 1.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
11 // http://floralicense.org/license/
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.
23 #include <dali/dali.h>
24 #include <dali-toolkit/public-api/transition-effects/cube-transition-effect.h>
32 class CubeTransitionEffect;
38 * Create a image with size of viewAreaSize
39 * with the effect image as its center part and (0,0,0,1) at other parts
41 class FullAreaImageCreator : public ShaderEffect
47 * Create an uninitialized FullAreaImageCreator
48 * this can be initialized with FullAreaImageCreator::New()
50 FullAreaImageCreator(){}
55 virtual ~FullAreaImageCreator(){}
58 * Create an initialized FullAreaImageCreator.
59 * @return A handle to a newly allocated Dali resource.
61 static FullAreaImageCreator New()
63 std::string vertexShader(
64 "uniform vec4 uRegion; \n"
67 " gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\n"
68 " vTexCoord.s = (aTexCoord.s - uRegion.s) / uRegion.p;"
69 " vTexCoord.t = ( 1.0 - aTexCoord.t - uRegion.t) / uRegion.q;"
73 std::string fragmentShader(
74 "uniform vec4 uRegion; \n"
77 " if( vTexCoord.s > 0.0 && vTexCoord.s < 1.0 && vTexCoord.t > 0.0 && vTexCoord.t < 1.0) \n"
79 " gl_FragColor = texture2D( sEffect, vTexCoord ) * uColor ; \n"
83 " gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 ); \n"
88 ShaderEffect shaderEffectCustom = ShaderEffect::New(vertexShader, fragmentShader);
89 FullAreaImageCreator handle( shaderEffectCustom );
95 * Set up the position and size of the effect texture
96 * @param[in] viewArea the size of full-area image to create
97 * @param[in] size the size of effect texture
99 void SetRegionSize( const Vector2& viewArea, const Vector2& size )
101 Vector2 sizeRatio( std::min(1.f, size.x / viewArea.x), std::min(1.f, size.y / viewArea.y) );
102 Vector4 region( (1.f-sizeRatio.x)*0.5f,
103 (1.f-sizeRatio.y)*0.5f,
106 SetUniform( "uRegion", region );
111 FullAreaImageCreator( ShaderEffect handle )
112 : ShaderEffect( handle )
120 * CubeTransitionEffect implementation class
122 class CubeTransitionEffect : public Dali::BaseObject, public ConnectionTracker
130 ~CubeTransitionEffect();
133 * @copydoc Toolkit::CubeTransitionEffect::SetTransitionDuration
135 void SetTransitionDuration( float duration );
138 * @copydoc Toolkit::CubeTransitionEffect::GetTransitionDuration
140 float GetTransitionDuration() const;
143 * @copydoc Toolkit::CubeTransitionEffect::SetCubeDisplacement
145 void SetCubeDisplacement( float displacement );
148 * @copydoc Toolkit::CubeTransitionEffect::GetCubeDisplacement
150 float GetCubeDisplacement() const;
153 * @copydoc Toolkit::CubeTransitionEffect::GetRoot
158 * @copydoc Toolkit::CubeTransitionEffect::IsTransiting
163 * @copydoc Toolkit::CubeTransitionEffect::SetFirstImage
165 void SetCurrentImage(ImageActor imageActor);
168 * @copydoc Toolkit::CubeTransitionEffect::SetTargetImage
170 void SetTargetImage(ImageActor imageActor);
173 * @copydoc Toolkit::CubeTransitionEffect::StartTransition(bool)
175 void StartTransition( bool toNextImage = true );
178 * @copydoc Toolkit::CubeTransitionEffect::StartTransition(Vector2, Vector2)
180 void StartTransition( Vector2 panPosition, Vector2 panDisplacement );
183 * @copydoc Toolkit::CubeTransitionEffect::PauseTransition()
185 void PauseTransition();
188 * @copydoc Toolkit::CubeTransitionEffect::ResumeTransition()
190 void ResumeTransition();
193 * @copydoc Toolkit::CubeTransitionEffect::StopTransition()
195 void StopTransition();
200 * @copydoc Toolkit::CubeTransitionEffect::TransitionCompletedSignal()
202 Toolkit::CubeTransitionEffect::TransitionCompletedSignalV2& TransitionCompletedSignal();
207 * Construct a new CubeTransitionEffect object
208 * Called in the constructor of subclasses
209 * @param[in] numRows How many rows of cubes
210 * @param[in] numColumns How many columns of cubes
211 * @param[in] viewAreaSize The size of view area for this transition effect
213 CubeTransitionEffect( unsigned int numRows, unsigned int numColumns, Size viewAreaSize );
216 * Initialization steps: creating a layer, two groups of tiles,
217 * and one group of actors (cubes) serving as parents of every two tiles (one from each image).
224 * Create an image actor to serve as a face of the cube
225 * @param[in] image The image to display.
226 * @param[in] color The color to set to the actor
227 * @return The tile actor created
229 ImageActor CreateTile( Image image, const Vector4& color );
232 * Set Image content to tiles
233 * As only when the image ready, can we get correct image attributes
234 * so inside this function, the process needs to be passed to callBack of image resource loading succeed.
235 * @param[in] imageActor The imageActor whose image content will be set to the tiles
237 void SetImage(ImageActor imageActor);
240 * Callback function of image resource loading succeed
241 * Set image and pixelArea to tiles
242 * @param[in] image The image content of the imageActor for transition
244 void OnImageLoaded(Image image);
247 * Callback function of transition animation finished
248 * Hide transition layer, show current imageActor, and set isAnimating flag to false
249 * @param[in] source The cube transition animation
251 void OnTransitionFinished(Animation& source);
254 * This method is called after the CubeTransitionEffect has been initialized. Derived classes should do
255 * any second phase initialization by overriding this method.
257 virtual void OnInitialize() { }
260 * This method is called after the a new transition is activated.
261 * Derived classes should do any specialized transition process by overriding this method.
262 * @param[in] panPosition The press down position of panGesture
263 * @param[in] panDisplacement The displacement vector of panGesture
265 virtual void OnStartTransition( Vector2 panPosition, Vector2 panDisplacement ) {}
268 * This method is called when the transition is forced stop in the middle of animation.
269 * Derived classed should set the rotation status of the cubes to the same as the final state when the animation is finished completely.
270 * So that the next transition would be started correctly.
272 virtual void OnStopTransition() {}
277 unsigned int mNumRows;
278 unsigned int mNumColumns;
280 ActorContainer mBoxes;
281 std::vector< ImageActor > mTiles[2];
286 ImageActor mCurrentImage;
287 unsigned int mContainerIndex; //have the value 0 or 1, refer to mTiles[0] or mTiles[1]
289 bool mChangeTurningDirection;
290 bool mIsToNextImage; //if true, cubes rotate counter-clockwise; else clockwise
291 bool mIsImageLoading;
293 float mAnimationDuration;
294 Animation mAnimation;
298 float mCubeDisplacement;
300 bool mFirstTransition;
302 RenderTask mOffScreenTask;
303 FrameBufferImage mOffScreenBuffer[2];
304 ImageActor mEmptyImage;
305 FullAreaImageCreator mFullImageCreator;
306 unsigned int mBufferIndex;
308 static const Vector4 FULL_BRIGHTNESS;
309 static const Vector4 HALF_BRIGHTNESS;
313 Toolkit::CubeTransitionEffect::TransitionCompletedSignalV2 mTransitionCompletedSignalV2;
317 } // namespace Internal
319 // Helpers for public-api forwarding methods
321 inline Internal::CubeTransitionEffect& GetImpl(Dali::Toolkit::CubeTransitionEffect& obj)
323 DALI_ASSERT_ALWAYS(obj);
325 Dali::BaseObject& handle = obj.GetBaseObject();
327 return static_cast<Internal::CubeTransitionEffect&>(handle);
330 inline const Internal::CubeTransitionEffect& GetImpl(const Dali::Toolkit::CubeTransitionEffect& obj)
332 DALI_ASSERT_ALWAYS(obj);
334 const Dali::BaseObject& handle = obj.GetBaseObject();
336 return static_cast<const Internal::CubeTransitionEffect&>(handle);
339 } // namespace Toolkit
343 #endif /* __DALI_TOOLKIT_INTERNAL_CUBE_TRANSITION_EFFECT_H__ */