int UtcDaliHitTestAlgorithmStencil(void) { TestApplication application; tet_infoline("Testing Dali::HitTestAlgorithm with a stencil"); Stage stage = Stage::GetCurrent(); Actor rootLayer = stage.GetRootLayer(); rootLayer.SetName( "RootLayer" ); // Create a layer Layer layer = Layer::New(); layer.SetAnchorPoint( AnchorPoint::TOP_LEFT ); layer.SetParentOrigin( ParentOrigin::TOP_LEFT ); layer.SetName( "layer" ); stage.Add( layer ); // Create a stencil and add that to the layer Actor stencil = ImageActor::New(Dali::BitmapImage::WHITE() ); stencil.SetAnchorPoint( AnchorPoint::TOP_LEFT ); stencil.SetParentOrigin( ParentOrigin::TOP_LEFT ); stencil.SetSize( 50.0f, 50.0f ); stencil.SetDrawMode( DrawMode::STENCIL ); stencil.SetName( "stencil" ); layer.Add( stencil ); // Create an actor and add that to the layer Actor layerHitActor = Actor::New(); layerHitActor.SetSize( 100.0f, 100.0f ); layerHitActor.SetAnchorPoint( AnchorPoint::TOP_LEFT ); layerHitActor.SetParentOrigin( ParentOrigin::TOP_LEFT ); layerHitActor.SetName( "layerHitActor" ); layer.Add( layerHitActor ); // Render and notify application.SendNotification(); application.Render(); // Hit within stencil and actor { HitTestAlgorithm::Results results; HitTest(stage, Vector2( 10.0f, 10.0f ), results, &DefaultIsActorTouchableFunction); DALI_TEST_CHECK( results.actor == layerHitActor ); tet_printf( "Hit: %s\n", ( results.actor ? results.actor.GetName().c_str() : "NULL" ) ); } // Hit within actor but outside of stencil, should hit the root-layer { HitTestAlgorithm::Results results; HitTest(stage, Vector2( 60.0f, 60.0f ), results, &DefaultIsActorTouchableFunction); DALI_TEST_CHECK( results.actor == rootLayer ); tet_printf( "Hit: %s\n", ( results.actor ? results.actor.GetName().c_str() : "NULL" ) ); } END_TEST; }
bool CubeTransitionApp::OnEffectButtonClicked( Toolkit::Button button ) { mContent.Remove( mCurrentEffect ); if(mCurrentEffect == mCubeWaveEffect) { mCurrentEffect = mCubeCrossEffect; mTitle.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_CROSS) ); mEffectChangeButton.SetUnselectedImage( EFFECT_CROSS_IMAGE ); mEffectChangeButton.SetSelectedImage( EFFECT_CROSS_IMAGE_SELECTED ); } else if(mCurrentEffect == mCubeCrossEffect) { mCurrentEffect = mCubeFoldEffect; mTitle.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_FOLD) ); mEffectChangeButton.SetUnselectedImage( EFFECT_FOLD_IMAGE ); mEffectChangeButton.SetSelectedImage( EFFECT_FOLD_IMAGE_SELECTED ); } else { mCurrentEffect = mCubeWaveEffect; mTitle.SetProperty( TextLabel::Property::TEXT, std::string(APPLICATION_TITLE_WAVE) ); mEffectChangeButton.SetUnselectedImage( EFFECT_WAVE_IMAGE ); mEffectChangeButton.SetSelectedImage( EFFECT_WAVE_IMAGE_SELECTED ); } mContent.Add( mCurrentEffect ); // Set the current image to cube transition effect // only need to set at beginning or change from another effect mCurrentEffect.SetCurrentImage( mCurrentImage ); return true; }
void DissolveEffectApp::OnInit( Application& application ) { Stage::GetCurrent().KeyEventSignal().Connect(this, &DissolveEffectApp::OnKeyEvent); // Creates a default view with a default tool bar, the view is added to the stage. mContent = DemoHelper::CreateView( application, mView,mToolBar, "", TOOLBAR_IMAGE, "" ); // Add an effect-changing button on the right of the tool bar. mEffectChangeButton = Toolkit::PushButton::New(); mEffectChangeButton.SetProperty( Toolkit::Button::Property::UNSELECTED_STATE_IMAGE, EFFECT_HIGHP_IMAGE ); mEffectChangeButton.SetProperty( Toolkit::Button::Property::SELECTED_STATE_IMAGE, EFFECT_HIGHP_IMAGE_SELECTED ); mEffectChangeButton.ClickedSignal().Connect( this, &DissolveEffectApp::OnEffectButtonClicked ); mToolBar.AddControl( mEffectChangeButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); // Add title to the tool bar. mTitleActor = DemoHelper::CreateToolBarLabel( APPLICATION_TITLE_HIGHP ); mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HorizontalCenter ); // Add an slide-show button on the right of the title mPlayStopButton = Toolkit::PushButton::New(); mPlayStopButton.SetProperty( Toolkit::Button::Property::UNSELECTED_STATE_IMAGE, PLAY_ICON ); mPlayStopButton.SetProperty( Toolkit::Button::Property::SELECTED_STATE_IMAGE, PLAY_ICON_SELECTED ); mPlayStopButton.ClickedSignal().Connect( this, &DissolveEffectApp::OnSildeshowButtonClicked ); mToolBar.AddControl( mPlayStopButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalCenter, DemoHelper::DEFAULT_PLAY_PADDING ); // use pan gesture to detect the cursor or finger movement mPanGestureDetector = PanGestureDetector::New(); mPanGestureDetector.DetectedSignal().Connect( this, &DissolveEffectApp::OnPanGesture ); mViewTimer = Timer::New( VIEWINGTIME ); mViewTimer.TickSignal().Connect( this, &DissolveEffectApp::OnTimerTick ); mTimerReady = true; // Set size to stage size to avoid seeing a black border on transition mParent = Actor::New(); mParent.SetSize( Stage::GetCurrent().GetSize() ); mParent.SetParentOrigin( ParentOrigin::CENTER ); mContent.Add( mParent ); // show the first image mCurrentImage = CreateStageFillingImageView( IMAGES[mIndex] ); mCurrentImage.SetParentOrigin( ParentOrigin::CENTER ); mCurrentImage.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); mCurrentImage.SetSizeScalePolicy( SizeScalePolicy::FIT_WITH_ASPECT_RATIO ); mParent.Add( mCurrentImage ); mPanGestureDetector.Attach( mCurrentImage ); mDissolveEffect = Dali::Toolkit::CreateDissolveEffect( mUseHighPrecision ); Property::Map emptyShaderMap; mEmptyEffect.Insert( "shader", emptyShaderMap ); }
void EffectsViewApp::OnAppInitialize( Application& application ) { // The Init signal is received once (only) during the Application lifetime Stage stage = Stage::GetCurrent(); stage.KeyEventSignal().Connect(this, &EffectsViewApp::OnKeyEvent); stage.SetBackgroundColor( Color::WHITE ); mStageSize = stage.GetSize(); // Creates a default view with a default tool bar. // The view is added to the stage. mContents = DemoHelper::CreateView( application, mView, mToolBar, "", TOOLBAR_IMAGE, "" ); // Creates view change button. Toolkit::PushButton viewButton = Toolkit::PushButton::New(); viewButton.SetUnselectedImage( VIEW_SWAP_IMAGE ); viewButton.SetSelectedImage( VIEW_SWAP_SELECTED_IMAGE ); // Connects the view change button clicked signal to the OnView method. viewButton.ClickedSignal().Connect( this, &EffectsViewApp::ChangeEffectSize ); mToolBar.AddControl( viewButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); Vector2 effectsViewSize( mStageSize.width, mStageSize.height * 0.25f ); mDropShadowView = CreateEffectsView( EffectsView::DROP_SHADOW, effectsViewSize, mEffectSize ); mDropShadowView.SetParentOrigin( ParentOrigin::CENTER ); mDropShadowView.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); mDropShadowView.SetZ( -mStageSize.height * 0.1f ); mContents.Add( mDropShadowView ); mEmbossView = CreateEffectsView( EffectsView::EMBOSS, effectsViewSize, mEffectSize ); mEmbossView.SetParentOrigin( ParentOrigin::CENTER ); mEmbossView.SetAnchorPoint( AnchorPoint::TOP_CENTER ); mEmbossView.SetZ( mStageSize.height * 0.1f ); mContents.Add( mEmbossView ); SetTitle( mEffectSize ); }
void Magnifier::SetFrameVisibility(bool visible) { if(visible && !mFrameLayer) { Actor self(Self()); Layer mFrameLayer = Layer::New(); mFrameLayer.SetParentOrigin( ParentOrigin::CENTER ); Stage::GetCurrent().Add(mFrameLayer); Image image = Image::New( DEFAULT_FRAME_IMAGE_PATH ); ImageActor frame = ImageActor::New( image ); frame.SetDrawMode(DrawMode::OVERLAY); frame.SetStyle( ImageActor::STYLE_NINE_PATCH ); frame.SetNinePatchBorder( Vector4::ONE * IMAGE_BORDER_INDENT ); mFrameLayer.Add(frame); // Apply position constraint to the frame Constraint constraint = Constraint::New<Vector3>( Actor::POSITION, Source( self, Actor::WORLD_POSITION ), EqualToConstraint() ); frame.ApplyConstraint(constraint); // Apply scale constraint to the frame constraint = Constraint::New<Vector3>( Actor::SCALE, Source( self, Actor::SCALE ), EqualToConstraint() ); frame.ApplyConstraint(constraint); Source(self, Actor::SCALE), // Apply size constraint to the the frame constraint = Constraint::New<Vector3>(Actor::SIZE, Source(self, Actor::SIZE), ImageBorderSizeConstraint()); frame.ApplyConstraint(constraint); } else if(!visible && mFrameLayer) { Stage::GetCurrent().Remove(mFrameLayer); mFrameLayer.Reset(); } }
void CubeTransitionApp::OnInit( Application& application ) { Stage::GetCurrent().KeyEventSignal().Connect(this, &CubeTransitionApp::OnKeyEvent); // Creates a default view with a default tool bar, the view is added to the stage. mContent = DemoHelper::CreateView( application, mView, mToolBar, "", TOOLBAR_IMAGE, "" ); mContent.SetBehavior( Layer::LAYER_3D ); // Add an effect-changing button on the right of the tool bar. mEffectChangeButton = Toolkit::PushButton::New(); mEffectChangeButton.SetUnselectedImage( EFFECT_WAVE_IMAGE ); mEffectChangeButton.SetSelectedImage( EFFECT_WAVE_IMAGE_SELECTED ); mEffectChangeButton.ClickedSignal().Connect( this, &CubeTransitionApp::OnEffectButtonClicked ); mToolBar.AddControl( mEffectChangeButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING ); // Add title to the tool bar. mTitle = DemoHelper::CreateToolBarLabel( APPLICATION_TITLE_WAVE ); mToolBar.AddControl( mTitle, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Toolkit::Alignment::HorizontalCenter ); //Add an slideshow icon on the right of the title mSlideshowButton = Toolkit::PushButton::New(); mSlideshowButton.SetUnselectedImage( SLIDE_SHOW_START_ICON ); mSlideshowButton.SetSelectedImage( SLIDE_SHOW_START_ICON_SELECTED ); mSlideshowButton.ClickedSignal().Connect( this, &CubeTransitionApp::OnSildeshowButtonClicked ); mToolBar.AddControl( mSlideshowButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalCenter, DemoHelper::DEFAULT_PLAY_PADDING ); // Set size to stage size to avoid seeing a black border on transition mViewSize = Stage::GetCurrent().GetSize(); // show the first image mCurrentImage = LoadStageFillingImage( IMAGES[mIndex] ); //use small cubes mCubeWaveEffect = Toolkit::CubeTransitionWaveEffect::New( NUM_ROWS_WAVE, NUM_COLUMNS_WAVE ); mCubeWaveEffect.SetTransitionDuration( ANIMATION_DURATION_WAVE ); mCubeWaveEffect.SetCubeDisplacement( CUBE_DISPLACEMENT_WAVE ); mCubeWaveEffect.TransitionCompletedSignal().Connect(this, &CubeTransitionApp::OnTransitionCompleted); mCubeWaveEffect.SetSize( mViewSize ); mCubeWaveEffect.SetPositionInheritanceMode( USE_PARENT_POSITION ); mCubeWaveEffect.SetCurrentImage( mCurrentImage ); // use big cubes mCubeCrossEffect = Toolkit::CubeTransitionCrossEffect::New(NUM_ROWS_CROSS, NUM_COLUMNS_CROSS ); mCubeCrossEffect.SetTransitionDuration( ANIMATION_DURATION_CROSS ); mCubeCrossEffect.SetCubeDisplacement( CUBE_DISPLACEMENT_CROSS ); mCubeCrossEffect.TransitionCompletedSignal().Connect(this, &CubeTransitionApp::OnTransitionCompleted); mCubeCrossEffect.SetSize( mViewSize ); mCubeCrossEffect.SetPositionInheritanceMode( USE_PARENT_POSITION ); mCubeCrossEffect.SetCurrentImage( mCurrentImage ); mCubeFoldEffect = Toolkit::CubeTransitionFoldEffect::New( NUM_ROWS_FOLD, NUM_COLUMNS_FOLD ); mCubeFoldEffect.SetTransitionDuration( ANIMATION_DURATION_FOLD ); mCubeFoldEffect.TransitionCompletedSignal().Connect(this, &CubeTransitionApp::OnTransitionCompleted); mCubeFoldEffect.SetSize( mViewSize ); mCubeFoldEffect.SetPositionInheritanceMode( USE_PARENT_POSITION ); mCubeFoldEffect.SetCurrentImage( mCurrentImage ); mViewTimer = Timer::New( VIEWINGTIME ); mViewTimer.TickSignal().Connect( this, &CubeTransitionApp::OnTimerTick ); mCurrentEffect = mCubeWaveEffect; mContent.Add( mCurrentEffect ); // use pan gesture to detect the cursor or finger movement mPanGestureDetector = PanGestureDetector::New(); mPanGestureDetector.DetectedSignal().Connect( this, &CubeTransitionApp::OnPanGesture ); mPanGestureDetector.Attach( mContent ); }
/** * Invoked upon creation of application * @param[in] application The application instance */ void Create( Application& application ) { Stage::GetCurrent().KeyEventSignal().Connect(this, &ExampleController::OnKeyEvent); mStageSize = Stage::GetCurrent().GetSize(); // The Init signal is received once (only) during the Application lifetime // Hide the indicator bar application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE ); // Creates a default view with a default tool bar. // The view is added to the stage. Toolkit::ToolBar toolBar; mContent = DemoHelper::CreateView( application, mView, toolBar, BACKGROUND_IMAGE, TOOLBAR_IMAGE, APPLICATION_TITLE ); mContent.SetLeaveRequired(true); mContent.TouchSignal().Connect( this, &ExampleController::OnTouched ); // Create magnifier (controlled by human touch) Layer overlay = Layer::New(); overlay.SetSensitive(false); overlay.SetParentOrigin( ParentOrigin::CENTER ); overlay.SetSize(mStageSize); Stage::GetCurrent().Add(overlay); mMagnifier = Toolkit::Magnifier::New(); mMagnifier.SetSourceActor( mView ); mMagnifier.SetSize( MAGNIFIER_SIZE * mStageSize.width ); // Size of magnifier is in relation to stage width mMagnifier.SetProperty( Toolkit::Magnifier::Property::MAGNIFICATION_FACTOR, MAGNIFICATION_FACTOR ); mMagnifier.SetScale(Vector3::ZERO); overlay.Add( mMagnifier ); // Apply constraint to animate the position of the magnifier. Constraint constraint = Constraint::New<Vector3>( mMagnifier, Actor::Property::POSITION, ConfinementConstraint(Vector3( 0.5f, 0.5f, 0.0f ), Vector2::ONE * MAGNIFIER_INDENT, Vector2::ONE * MAGNIFIER_INDENT) ); constraint.AddSource( LocalSource(Actor::Property::SIZE) ); constraint.AddSource( LocalSource(Actor::Property::PARENT_ORIGIN) ); constraint.AddSource( LocalSource(Actor::Property::ANCHOR_POINT) ); constraint.AddSource( ParentSource(Actor::Property::SIZE) ); constraint.SetRemoveAction(Constraint::Discard); constraint.Apply(); // Create bouncing magnifier automatically bounces around screen. mBouncingMagnifier = Toolkit::Magnifier::New(); mBouncingMagnifier.SetSourceActor( mView ); mBouncingMagnifier.SetSize( MAGNIFIER_SIZE * mStageSize.width ); // Size of magnifier is in relation to stage width mBouncingMagnifier.SetProperty( Toolkit::Magnifier::Property::MAGNIFICATION_FACTOR, MAGNIFICATION_FACTOR ); overlay.Add( mBouncingMagnifier ); mAnimationTimeProperty = mBouncingMagnifier.RegisterProperty("animationTime", 0.0f); ContinueAnimation(); // Apply constraint to animate the position of the magnifier. constraint = Constraint::New<Vector3>( mBouncingMagnifier, Actor::Property::POSITION, MagnifierPathConstraint(mStageSize, mStageSize * 0.5f) ); constraint.AddSource( LocalSource(Actor::Property::SIZE) ); constraint.AddSource( LocalSource(mAnimationTimeProperty) ); constraint.Apply(); // Apply constraint to animate the source of the magnifier. constraint = Constraint::New<Vector3>( mBouncingMagnifier, Toolkit::Magnifier::Property::SOURCE_POSITION, MagnifierPathConstraint(mStageSize) ); constraint.AddSource( LocalSource(Actor::Property::SIZE) ); constraint.AddSource( LocalSource(mAnimationTimeProperty) ); constraint.Apply(); }
/** * @brief This is the main scene setup method for this demo. * This is called via the Init signal which is received once (only) during the Application lifetime. * @param[in] application The DALi application object */ void Create( Application& application ) { Stage stage = Stage::GetCurrent(); // Creates a default view with a default tool-bar. // The view is added to the stage. Toolkit::ToolBar toolBar; Layer toolBarLayer = DemoHelper::CreateView( application, mView, toolBar, BACKGROUND_IMAGE, TOOLBAR_IMAGE, APPLICATION_TITLE ); stage.Add( toolBarLayer ); // Layer to hold the 3D scene. Layer layer = Layer::New(); layer.SetAnchorPoint( AnchorPoint::CENTER ); // Set the parent origin to a small percentage below the center (so the demo will scale for different resolutions). layer.SetParentOrigin( Vector3( 0.5f, 0.58f, 0.5f ) ); layer.SetBehavior( Layer::LAYER_2D ); layer.SetDepthTestDisabled( false ); stage.Add( layer ); // Main cube: // Make the demo scalable with different resolutions by basing // the cube size on a percentage of the stage size. float scaleSize( std::min( stage.GetSize().width, stage.GetSize().height ) ); float cubeWidth( scaleSize * CUBE_WIDTH_SCALE ); Vector3 cubeSize( cubeWidth, cubeWidth, cubeWidth ); // Create the geometry for the cube, and the texture. Geometry cubeGeometry = CreateCubeVertices( Vector3::ONE, false ); TextureSet cubeTextureSet = CreateTextureSet( CUBE_TEXTURE ); // Create the cube object and add it. // Note: The cube is anchored around its base for animation purposes, so the position can be zero. mCubes[ MAIN_CUBE ] = CreateMainCubeObject( cubeGeometry, cubeSize, cubeTextureSet ); layer.Add( mCubes[ MAIN_CUBE ] ); // Floor: float floorWidth( scaleSize * FLOOR_DIMENSION_SCALE.x ); Vector3 floorSize( floorWidth, scaleSize * FLOOR_DIMENSION_SCALE.y, floorWidth ); // Create the floor object using the cube geometry with a new size, and add it. Actor floorObject( CreateFloorObject( cubeGeometry, floorSize ) ); layer.Add( floorObject ); // Stencil: Vector3 planeSize( floorWidth, floorWidth, 0.0f ); // Create the stencil plane object, and add it. Actor stencilPlaneObject( CreateStencilPlaneObject( planeSize ) ); layer.Add( stencilPlaneObject ); // Reflection cube: // Create the reflection cube object and add it. // Note: The cube is anchored around its base for animation purposes, so the position can be zero. mCubes[ REFLECTION_CUBE ] = CreateReflectionCubeObject( cubeSize, cubeTextureSet ); layer.Add( mCubes[ REFLECTION_CUBE ] ); // Rotate the layer so we can see some of the top of the cube for a more 3D effect. layer.SetProperty( Actor::Property::ORIENTATION, Quaternion( Degree( -24.0f ), Degree( 0.0f ), Degree( 0.0f ) ) ); // Set up the rotation on the Y axis. mRotationAnimation = Animation::New( ANIMATION_ROTATION_DURATION ); float fullRotation = 360.0f; mRotationAnimation.AnimateBy( Property( mCubes[ MAIN_CUBE ], Actor::Property::ORIENTATION ), Quaternion( Degree( 0.0f ), Degree( fullRotation ), Degree( 0.0f ) ) ); mRotationAnimation.AnimateBy( Property( floorObject, Actor::Property::ORIENTATION ), Quaternion( Degree( 0.0f ), Degree( fullRotation ), Degree( 0.0f ) ) ); // Note the stencil is pre-rotated by 90 degrees on X, so we rotate relatively on its Z axis for an equivalent Y rotation. mRotationAnimation.AnimateBy( Property( stencilPlaneObject, Actor::Property::ORIENTATION ), Quaternion( Degree( 0.0f ), Degree( 0.0f ), Degree( fullRotation ) ) ); mRotationAnimation.AnimateBy( Property( mCubes[ REFLECTION_CUBE ], Actor::Property::ORIENTATION ), Quaternion( Degree( 0.0f ), Degree( fullRotation ), Degree( 0.0f ) ) ); mRotationAnimation.SetLooping( true ); // Set up the cube bouncing animation. float totalTime = ANIMATION_BOUNCE_TOTAL_TIME; float deformationTime = ANIMATION_BOUNCE_DEFORMATION_TIME; // Percentage based amounts allows the bounce and deformation to scale for different resolution screens. float deformationAmount = ANIMATION_BOUNCE_DEFORMATION_PERCENT / 100.0f; float heightChange = ( cubeSize.y * ANIMATION_BOUNCE_HEIGHT_PERCENT ) / 100.0f; // Animation pre-calculations: float halfTime = totalTime / 2.0f; float halfDeformationTime = deformationTime / 2.0f; // First position the cubes at the top of the animation cycle. mCubes[ MAIN_CUBE ].SetProperty( Actor::Property::POSITION_Y, -heightChange ); mCubes[ REFLECTION_CUBE ].SetProperty( Actor::Property::POSITION_Y, heightChange ); mBounceAnimation = Animation::New( totalTime ); // The animations for the main and reflected cubes are almost identical, so we combine the code to do both. for( int cube = 0; cube < 2; ++cube ) { // If iterating on the reflection cube, adjust the heightChange variable so the below code can be reused. if( cube == 1 ) { heightChange = -heightChange; } // 1st TimePeriod: Start moving down with increasing speed, until it is time to distort the cube due to impact. mBounceAnimation.AnimateBy( Property( mCubes[ cube ], Actor::Property::POSITION_Y ), heightChange, AlphaFunction::EASE_IN_SQUARE, TimePeriod( 0.0f, halfTime - halfDeformationTime ) ); // 2nd TimePeriod: The cube is touching the floor, start deforming it - then un-deform it again. mBounceAnimation.AnimateBy( Property( mCubes[ cube ], Actor::Property::SCALE_X ), deformationAmount, AlphaFunction::BOUNCE, TimePeriod( halfTime - halfDeformationTime, deformationTime ) ); mBounceAnimation.AnimateBy( Property( mCubes[ cube ], Actor::Property::SCALE_Z ), deformationAmount, AlphaFunction::BOUNCE, TimePeriod( halfTime - halfDeformationTime, deformationTime ) ); mBounceAnimation.AnimateBy( Property( mCubes[ cube ], Actor::Property::SCALE_Y ), -deformationAmount, AlphaFunction::BOUNCE, TimePeriod( halfTime - halfDeformationTime, deformationTime ) ); // 3rd TimePeriod: Start moving up with decreasing speed, until at the apex of the animation. mBounceAnimation.AnimateBy( Property( mCubes[ cube ], Actor::Property::POSITION_Y ), -heightChange, AlphaFunction::EASE_OUT_SQUARE, TimePeriod( halfTime + halfDeformationTime, halfTime - halfDeformationTime ) ); } mBounceAnimation.SetLooping( true ); // Start the animations. mRotationAnimation.Play(); mBounceAnimation.Play(); // Respond to a click anywhere on the stage stage.GetRootLayer().TouchSignal().Connect( this, &RendererStencilExample::OnTouch ); // Connect signals to allow Back and Escape to exit. stage.KeyEventSignal().Connect( this, &RendererStencilExample::OnKeyEvent ); }
void Magnifier::Initialize() { Actor self = Self(); mPropertySourcePosition = self.RegisterProperty( Toolkit::Magnifier::SOURCE_POSITION_PROPERTY_NAME, Vector3::ZERO ); Vector2 stageSize(Stage::GetCurrent().GetSize()); Layer dummyLayer = Layer::New(); Stage().GetCurrent().Add(dummyLayer); dummyLayer.SetParentOrigin(ParentOrigin::CENTER); // NOTE: // sourceActor is a dummy delegate actor that takes the source property position, // and generates a WORLD_POSITION, which is 1 frame behind the source property. // This way the constraints for determining the camera position (source) and those // for determining viewport position use the same 1 frame old values. // A simple i) CameraPos = f(B), ii) B = f(A) set of constraints wont suffice as // although CameraPos will use B, which is A's previous value. The constraint will // not realise that B is still dirty as far as constraint (i) is concerned. // Perhaps this is a bug in the way the constraint system factors into what is dirty // and what is not. mSourceActor = Actor::New(); dummyLayer.Add(mSourceActor); mSourceActor.SetParentOrigin(ParentOrigin::CENTER); Constraint constraint = Constraint::New<Vector3>( Actor::POSITION, Source( self, mPropertySourcePosition ), EqualToConstraint() ); mSourceActor.ApplyConstraint(constraint); // create the render task this will render content on top of everything // based on camera source position. InitializeRenderTask(); // set up some constraints to: // i) reposition (dest) frame actor based on magnifier actor's world position (this is 1 frame delayed) // ii) reposition and resize (dest) the render task's viewport based on magnifier actor's world position (1 frame delayed) & size. // iii) reposition (source) camera actor based on magnifier source actor's world position (this is 1 frame delayed) // Apply constraint to camera's position // Position our camera at the same distance from its target as the default camera is. // The camera position doesn't affect how we render, just what we render (due to near and far clip planes) // NOTE: We can't interrogate the default camera's position as it is not known initially (takes 1 frame // for value to update). // But we can determine the initial position using the same formula: // distance = stage.height * 0.5 / tan(FOV * 0.5) RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList(); RenderTask renderTask = taskList.GetTask(0u); float fov = renderTask.GetCameraActor().GetFieldOfView(); mDefaultCameraDistance = (stageSize.height * 0.5f) / tanf(fov * 0.5f); // Use a 1 frame delayed source position to determine the camera actor's position. // This is necessary as the viewport is determined by the Magnifier's Actor's World position (which is computed // at the end of the update cycle i.e. after constraints have been applied.) //Property::Index propertySourcePositionDelayed = mCameraActor.RegisterProperty("delayed-source-position", Vector3::ZERO); constraint = Constraint::New<Vector3>( Actor::POSITION, Source( mSourceActor, Actor::WORLD_POSITION ), CameraActorPositionConstraint(stageSize, mDefaultCameraDistance) ); mCameraActor.ApplyConstraint(constraint); // Apply constraint to render-task viewport position constraint = Constraint::New<Vector2>( RenderTask::VIEWPORT_POSITION, Source( self, Actor::WORLD_POSITION ),//mPropertySourcePosition ), Source( self, Actor::SIZE ), Source( self, Actor::WORLD_SCALE), RenderTaskViewportPositionConstraint(stageSize) ); mTask.ApplyConstraint(constraint); // Apply constraint to render-task viewport position constraint = Constraint::New<Vector2>( RenderTask::VIEWPORT_SIZE, Source( self, Actor::SIZE ), Source( self, Actor::WORLD_SCALE), RenderTaskViewportSizeConstraint() ); mTask.ApplyConstraint(constraint); }