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.
24 #include <dali/dali.h>
25 #include <dali-toolkit/public-api/transition-effects/cube-transition-effect.h>
33 class CubeTransitionEffect;
39 * Create a image with size of viewAreaSize
40 * with the effect image as its center part and (0,0,0,1) at other parts
42 class FullAreaImageCreator : public ShaderEffect
48 * Create an uninitialized FullAreaImageCreator
49 * this can be initialized with FullAreaImageCreator::New()
51 FullAreaImageCreator(){}
56 * This is non-virtual since derived Handle types must not contain data or virtual methods.
58 ~FullAreaImageCreator(){}
61 * Create an initialized FullAreaImageCreator.
62 * @return A handle to a newly allocated Dali resource.
64 static FullAreaImageCreator New()
66 std::string vertexShader(
67 "uniform vec4 uRegion; \n"
70 " gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\n"
71 " vTexCoord.s = (aTexCoord.s - uRegion.s) / uRegion.p;"
72 " vTexCoord.t = ( 1.0 - aTexCoord.t - uRegion.t) / uRegion.q;"
76 std::string fragmentShader(
77 "uniform vec4 uRegion; \n"
80 " if( vTexCoord.s > 0.0 && vTexCoord.s < 1.0 && vTexCoord.t > 0.0 && vTexCoord.t < 1.0) \n"
82 " gl_FragColor = texture2D( sEffect, vTexCoord ) * uColor ; \n"
86 " gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 ); \n"
91 ShaderEffect shaderEffectCustom = ShaderEffect::New(vertexShader, fragmentShader);
92 FullAreaImageCreator handle( shaderEffectCustom );
98 * Set up the position and size of the effect texture
99 * @param[in] viewArea the size of full-area image to create
100 * @param[in] size the size of effect texture
102 void SetRegionSize( const Vector2& viewArea, const Vector2& size )
104 Vector2 sizeRatio( std::min(1.f, size.x / viewArea.x), std::min(1.f, size.y / viewArea.y) );
105 Vector4 region( (1.f-sizeRatio.x)*0.5f,
106 (1.f-sizeRatio.y)*0.5f,
109 SetUniform( "uRegion", region );
114 FullAreaImageCreator( ShaderEffect handle )
115 : ShaderEffect( handle )
123 * CubeTransitionEffect implementation class
125 class CubeTransitionEffect : public Dali::BaseObject, public ConnectionTracker
133 ~CubeTransitionEffect();
136 * @copydoc Toolkit::CubeTransitionEffect::SetTransitionDuration
138 void SetTransitionDuration( float duration );
141 * @copydoc Toolkit::CubeTransitionEffect::GetTransitionDuration
143 float GetTransitionDuration() const;
146 * @copydoc Toolkit::CubeTransitionEffect::SetCubeDisplacement
148 void SetCubeDisplacement( float displacement );
151 * @copydoc Toolkit::CubeTransitionEffect::GetCubeDisplacement
153 float GetCubeDisplacement() const;
156 * @copydoc Toolkit::CubeTransitionEffect::GetRoot
161 * @copydoc Toolkit::CubeTransitionEffect::IsTransiting
166 * @copydoc Toolkit::CubeTransitionEffect::SetFirstImage
168 void SetCurrentImage(ImageActor imageActor);
171 * @copydoc Toolkit::CubeTransitionEffect::SetTargetImage
173 void SetTargetImage(ImageActor imageActor);
176 * @copydoc Toolkit::CubeTransitionEffect::StartTransition(bool)
178 void StartTransition( bool toNextImage = true );
181 * @copydoc Toolkit::CubeTransitionEffect::StartTransition(Vector2, Vector2)
183 void StartTransition( Vector2 panPosition, Vector2 panDisplacement );
186 * @copydoc Toolkit::CubeTransitionEffect::PauseTransition()
188 void PauseTransition();
191 * @copydoc Toolkit::CubeTransitionEffect::ResumeTransition()
193 void ResumeTransition();
196 * @copydoc Toolkit::CubeTransitionEffect::StopTransition()
198 void StopTransition();
203 * @copydoc Toolkit::CubeTransitionEffect::TransitionCompletedSignal()
205 Toolkit::CubeTransitionEffect::TransitionCompletedSignalV2& TransitionCompletedSignal();
210 * Construct a new CubeTransitionEffect object
211 * Called in the constructor of subclasses
212 * @param[in] numRows How many rows of cubes
213 * @param[in] numColumns How many columns of cubes
214 * @param[in] viewAreaSize The size of view area for this transition effect
216 CubeTransitionEffect( unsigned int numRows, unsigned int numColumns, Size viewAreaSize );
219 * Initialization steps: creating a layer, two groups of tiles,
220 * and one group of actors (cubes) serving as parents of every two tiles (one from each image).
227 * Create an image actor to serve as a face of the cube
228 * @param[in] image The image to display.
229 * @param[in] color The color to set to the actor
230 * @return The tile actor created
232 ImageActor CreateTile( Image image, const Vector4& color );
235 * Set Image content to tiles
236 * As only when the image ready, can we get correct image attributes
237 * so inside this function, the process needs to be passed to callBack of image resource loading succeed.
238 * @param[in] imageActor The imageActor whose image content will be set to the tiles
240 void SetImage(ImageActor imageActor);
243 * Callback function of image resource loading succeed
244 * Set image and pixelArea to tiles
245 * @param[in] image The image content of the imageActor for transition
247 void OnImageLoaded(Image image);
250 * Callback function of transition animation finished
251 * Hide transition layer, show current imageActor, and set isAnimating flag to false
252 * @param[in] source The cube transition animation
254 void OnTransitionFinished(Animation& source);
257 * This method is called after the CubeTransitionEffect has been initialized. Derived classes should do
258 * any second phase initialization by overriding this method.
260 virtual void OnInitialize() { }
263 * This method is called after the a new transition is activated.
264 * Derived classes should do any specialized transition process by overriding this method.
265 * @param[in] panPosition The press down position of panGesture
266 * @param[in] panDisplacement The displacement vector of panGesture
268 virtual void OnStartTransition( Vector2 panPosition, Vector2 panDisplacement ) {}
271 * This method is called when the transition is forced stop in the middle of animation.
272 * Derived classed should set the rotation status of the cubes to the same as the final state when the animation is finished completely.
273 * So that the next transition would be started correctly.
275 virtual void OnStopTransition() {}
280 unsigned int mNumRows;
281 unsigned int mNumColumns;
283 ActorContainer mBoxes;
284 std::vector< ImageActor > mTiles[2];
289 ImageActor mCurrentImage;
290 unsigned int mContainerIndex; //have the value 0 or 1, refer to mTiles[0] or mTiles[1]
292 bool mChangeTurningDirection;
293 bool mIsToNextImage; //if true, cubes rotate counter-clockwise; else clockwise
294 bool mIsImageLoading;
296 float mAnimationDuration;
297 Animation mAnimation;
301 float mCubeDisplacement;
303 bool mFirstTransition;
305 RenderTask mOffScreenTask;
306 FrameBufferImage mOffScreenBuffer[2];
307 ImageActor mEmptyImage;
308 FullAreaImageCreator mFullImageCreator;
309 unsigned int mBufferIndex;
311 static const Vector4 FULL_BRIGHTNESS;
312 static const Vector4 HALF_BRIGHTNESS;
316 Toolkit::CubeTransitionEffect::TransitionCompletedSignalV2 mTransitionCompletedSignalV2;
320 } // namespace Internal
322 // Helpers for public-api forwarding methods
324 inline Internal::CubeTransitionEffect& GetImpl(Dali::Toolkit::CubeTransitionEffect& obj)
326 DALI_ASSERT_ALWAYS(obj);
328 Dali::BaseObject& handle = obj.GetBaseObject();
330 return static_cast<Internal::CubeTransitionEffect&>(handle);
333 inline const Internal::CubeTransitionEffect& GetImpl(const Dali::Toolkit::CubeTransitionEffect& obj)
335 DALI_ASSERT_ALWAYS(obj);
337 const Dali::BaseObject& handle = obj.GetBaseObject();
339 return static_cast<const Internal::CubeTransitionEffect&>(handle);
342 } // namespace Toolkit
346 #endif /* __DALI_TOOLKIT_INTERNAL_CUBE_TRANSITION_EFFECT_H__ */