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 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/animation/animation.h>
23 #include <dali/public-api/images/bitmap-image.h>
24 #include <dali/public-api/images/frame-buffer-image.h>
25 #include <dali/public-api/object/base-object.h>
26 #include <dali/public-api/render-tasks/render-task.h>
27 #include <dali/public-api/shader-effects/shader-effect.h>
30 #include <dali-toolkit/public-api/transition-effects/cube-transition-effect.h>
38 class CubeTransitionEffect;
44 * Create a image with size of viewAreaSize
45 * with the effect image as its center part and (0,0,0,1) at other parts
47 class FullAreaImageCreator : public ShaderEffect
53 * Create an uninitialized FullAreaImageCreator
54 * this can be initialized with FullAreaImageCreator::New()
56 FullAreaImageCreator(){}
61 * This is non-virtual since derived Handle types must not contain data or virtual methods.
63 ~FullAreaImageCreator(){}
66 * Create an initialized FullAreaImageCreator.
67 * @return A handle to a newly allocated Dali resource.
69 static FullAreaImageCreator New()
71 std::string vertexShader(
72 "uniform mediump vec4 uRegion; \n"
75 " gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\n"
76 " vTexCoord.s = (aTexCoord.s - uRegion.s) / uRegion.p;"
77 " vTexCoord.t = ( 1.0 - aTexCoord.t - uRegion.t) / uRegion.q;"
81 std::string fragmentShader(
82 "uniform mediump vec4 uRegion; \n"
85 " if( vTexCoord.s > 0.0 && vTexCoord.s < 1.0 && vTexCoord.t > 0.0 && vTexCoord.t < 1.0) \n"
87 " gl_FragColor = texture2D( sEffect, vTexCoord ) * uColor ; \n"
91 " gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 ); \n"
96 ShaderEffect shaderEffectCustom = ShaderEffect::New(vertexShader, fragmentShader);
97 FullAreaImageCreator handle( shaderEffectCustom );
103 * Set up the position and size of the effect texture
104 * @param[in] viewArea the size of full-area image to create
105 * @param[in] size the size of effect texture
107 void SetRegionSize( const Vector2& viewArea, const Vector2& size )
109 Vector2 sizeRatio( std::min(1.f, size.x / viewArea.x), std::min(1.f, size.y / viewArea.y) );
110 Vector4 region( (1.f-sizeRatio.x)*0.5f,
111 (1.f-sizeRatio.y)*0.5f,
114 SetUniform( "uRegion", region );
119 FullAreaImageCreator( ShaderEffect handle )
120 : ShaderEffect( handle )
128 * CubeTransitionEffect implementation class
130 class CubeTransitionEffect : public Dali::BaseObject, public ConnectionTracker
138 ~CubeTransitionEffect();
141 * @copydoc Toolkit::CubeTransitionEffect::SetTransitionDuration
143 void SetTransitionDuration( float duration );
146 * @copydoc Toolkit::CubeTransitionEffect::GetTransitionDuration
148 float GetTransitionDuration() const;
151 * @copydoc Toolkit::CubeTransitionEffect::SetCubeDisplacement
153 void SetCubeDisplacement( float displacement );
156 * @copydoc Toolkit::CubeTransitionEffect::GetCubeDisplacement
158 float GetCubeDisplacement() const;
161 * @copydoc Toolkit::CubeTransitionEffect::GetRoot
166 * @copydoc Toolkit::CubeTransitionEffect::IsTransiting
171 * @copydoc Toolkit::CubeTransitionEffect::SetFirstImage
173 void SetCurrentImage(ImageActor imageActor);
176 * @copydoc Toolkit::CubeTransitionEffect::SetTargetImage
178 void SetTargetImage(ImageActor imageActor);
181 * @copydoc Toolkit::CubeTransitionEffect::StartTransition(bool)
183 void StartTransition( bool toNextImage = true );
186 * @copydoc Toolkit::CubeTransitionEffect::StartTransition(Vector2, Vector2)
188 void StartTransition( Vector2 panPosition, Vector2 panDisplacement );
191 * @copydoc Toolkit::CubeTransitionEffect::PauseTransition()
193 void PauseTransition();
196 * @copydoc Toolkit::CubeTransitionEffect::ResumeTransition()
198 void ResumeTransition();
201 * @copydoc Toolkit::CubeTransitionEffect::StopTransition()
203 void StopTransition();
208 * @copydoc Toolkit::CubeTransitionEffect::TransitionCompletedSignal()
210 Toolkit::CubeTransitionEffect::TransitionCompletedSignalV2& TransitionCompletedSignal();
215 * Construct a new CubeTransitionEffect object
216 * Called in the constructor of subclasses
217 * @param[in] numRows How many rows of cubes
218 * @param[in] numColumns How many columns of cubes
219 * @param[in] viewAreaSize The size of view area for this transition effect
221 CubeTransitionEffect( unsigned int numRows, unsigned int numColumns, Size viewAreaSize );
224 * Initialization steps: creating a layer, two groups of tiles,
225 * and one group of actors (cubes) serving as parents of every two tiles (one from each image).
232 * Create an image actor to serve as a face of the cube
233 * @param[in] image The image to display.
234 * @param[in] color The color to set to the actor
235 * @return The tile actor created
237 ImageActor CreateTile( Image image, const Vector4& color );
240 * Set Image content to tiles
241 * As only when the image ready, can we get correct image attributes
242 * so inside this function, the process needs to be passed to callBack of image resource loading succeed.
243 * @param[in] imageActor The imageActor whose image content will be set to the tiles
245 void SetImage(ImageActor imageActor);
248 * Callback function of image resource loading succeed
249 * Set image and pixelArea to tiles
250 * @param[in] image The image content of the imageActor for transition
252 void OnImageLoaded(Image image);
255 * Callback function of transition animation finished
256 * Hide transition layer, show current imageActor, and set isAnimating flag to false
257 * @param[in] source The cube transition animation
259 void OnTransitionFinished(Animation& source);
262 * This method is called after the CubeTransitionEffect has been initialized. Derived classes should do
263 * any second phase initialization by overriding this method.
265 virtual void OnInitialize() { }
268 * This method is called after the a new transition is activated.
269 * Derived classes should do any specialized transition process by overriding this method.
270 * @param[in] panPosition The press down position of panGesture
271 * @param[in] panDisplacement The displacement vector of panGesture
273 virtual void OnStartTransition( Vector2 panPosition, Vector2 panDisplacement ) {}
276 * This method is called when the transition is forced stop in the middle of animation.
277 * Derived classed should set the rotation status of the cubes to the same as the final state when the animation is finished completely.
278 * So that the next transition would be started correctly.
280 virtual void OnStopTransition() {}
285 unsigned int mNumRows;
286 unsigned int mNumColumns;
288 ActorContainer mBoxes;
289 std::vector< ImageActor > mTiles[2];
294 ImageActor mCurrentImage;
295 unsigned int mContainerIndex; //have the value 0 or 1, refer to mTiles[0] or mTiles[1]
297 bool mChangeTurningDirection;
298 bool mIsToNextImage; //if true, cubes rotate counter-clockwise; else clockwise
299 bool mIsImageLoading;
301 float mAnimationDuration;
302 Animation mAnimation;
306 float mCubeDisplacement;
308 bool mFirstTransition;
310 RenderTask mOffScreenTask;
311 FrameBufferImage mOffScreenBuffer[2];
312 ImageActor mEmptyImage;
313 FullAreaImageCreator mFullImageCreator;
314 unsigned int mBufferIndex;
316 static const Vector4 FULL_BRIGHTNESS;
317 static const Vector4 HALF_BRIGHTNESS;
321 Toolkit::CubeTransitionEffect::TransitionCompletedSignalV2 mTransitionCompletedSignalV2;
325 } // namespace Internal
327 // Helpers for public-api forwarding methods
329 inline Internal::CubeTransitionEffect& GetImpl(Dali::Toolkit::CubeTransitionEffect& obj)
331 DALI_ASSERT_ALWAYS(obj);
333 Dali::BaseObject& handle = obj.GetBaseObject();
335 return static_cast<Internal::CubeTransitionEffect&>(handle);
338 inline const Internal::CubeTransitionEffect& GetImpl(const Dali::Toolkit::CubeTransitionEffect& obj)
340 DALI_ASSERT_ALWAYS(obj);
342 const Dali::BaseObject& handle = obj.GetBaseObject();
344 return static_cast<const Internal::CubeTransitionEffect&>(handle);
347 } // namespace Toolkit
351 #endif /* __DALI_TOOLKIT_INTERNAL_CUBE_TRANSITION_EFFECT_H__ */