int UtcDaliStageAssignmentOperatorP(void) { TestApplication application; const Stage stage = Stage::GetCurrent(); Stage copyStage = stage; DALI_TEST_CHECK( copyStage ); DALI_TEST_CHECK( copyStage.GetRootLayer() == stage.GetRootLayer() ); END_TEST; }
int UtcDaliStageRemoveN3(void) { TestApplication application; Stage stage = Stage::GetCurrent(); // Initially we have a default layer DALI_TEST_EQUALS( stage.GetLayerCount(), 1u, TEST_LOCATION ); // Check we cannot remove the root layer from the stage. Layer layer = stage.GetRootLayer(); bool asserted = true; try { stage.Remove( layer ); } catch( Dali::DaliException& e ) { DALI_TEST_PRINT_ASSERT( e ); DALI_TEST_ASSERT( e, "this != &child && \"Cannot remove actor from itself\"", TEST_LOCATION ); asserted = true; } DALI_TEST_CHECK( asserted ); DALI_TEST_EQUALS( stage.GetLayerCount(), 1u, TEST_LOCATION ); END_TEST; }
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; }
int UtcDaliStageCopyConstructorP(void) { TestApplication application; Stage stage = Stage::GetCurrent(); Stage copyStage( stage ); DALI_TEST_CHECK( copyStage ); DALI_TEST_CHECK( copyStage.GetRootLayer() == stage.GetRootLayer() ); END_TEST; }
int UtcDaliStageGetRootLayerP(void) { TestApplication application; Stage stage = Stage::GetCurrent(); Layer layer = stage.GetLayer( 0 ); DALI_TEST_CHECK( layer ); // Check that GetRootLayer() correctly retreived layer 0. DALI_TEST_CHECK( stage.GetRootLayer() == layer ); END_TEST; }
int UtcDaliStageGetRootLayerN(void) { TestApplication application; Stage stage = Stage::GetCurrent(); Layer rootLayer = stage.GetLayer( 0 ); DALI_TEST_CHECK( rootLayer ); DALI_TEST_CHECK( stage.GetRootLayer() == rootLayer ); // Create a new layer and attempt to lower it below the root layer. Layer layer = Layer::New(); stage.Add( layer ); layer.LowerToBottom(); // Check that GetRootLayer still retrieves the same original layer. DALI_TEST_CHECK( stage.GetRootLayer() == rootLayer ); // Check modifying the root layer is also blocked. rootLayer.RaiseToTop(); DALI_TEST_CHECK( stage.GetRootLayer() == rootLayer ); END_TEST; }
// The Init signal is received once (only) during the Application lifetime void Create( Application& application ) { //std::cout << "HelloWorldController::Create" << std::endl; // Get a handle to the stage Stage stage = Stage::GetCurrent(); //ImageActor bgActor = ImageActor::New(CreateBitmapImage(480, 800)); Control bgActor = Control::New(); bgActor.SetSize(64 * STAGE_COL, 64 * STAGE_ROW); //bgActor.SetBackgroundColor(Vector4(.125f, .125f, .125f, 1.f)); bgActor.SetBackgroundColor(Vector4(1.f, 1.f, 1.f, 1.f)); bgActor.SetParentOrigin(ParentOrigin::CENTER); bgActor.SetAnchorPoint(AnchorPoint::CENTER); bgActor.SetZ(0.1f); //stage.Add(bgActor); ResourceImage spriteImage = ResourceImage::New(PUYO_IMAGE); // background { ResourceImage image = ResourceImage::New(BACKGROUND_IMAGE); ImageActor actor = ImageActor::New(image); actor.SetParentOrigin(ParentOrigin::BOTTOM_LEFT); actor.SetAnchorPoint(AnchorPoint::BOTTOM_LEFT); stage.Add(actor); } // sprites { ImageActor actor[STAGE_COL * STAGE_ROW]; for (int i = 0; i < STAGE_ROW; i++) { for (int j = 0; j < STAGE_COL; j++) { actor[i * STAGE_COL + j] = ImageActor::New(spriteImage, PUYO_OFFSET[int(Random::Range(0.f, NUM_PUYO))]); actor[i * STAGE_COL + j].SetParentOrigin(ParentOrigin::BOTTOM_LEFT); actor[i * STAGE_COL + j].SetAnchorPoint(AnchorPoint::BOTTOM_LEFT); actor[i * STAGE_COL + j].SetX(i * 60.f); actor[i * STAGE_COL + j].SetY(j * -1.f * 60.f); actor[i * STAGE_COL + j].SetZ(0.1f); stage.Add(actor[i * STAGE_COL + j]); } } #if 0 Animation anim = Animation::New(1.f); for (int i = 0; i < STAGE_ROW; i++) { for (int j = 0; j < STAGE_COL; j++) { anim.MoveBy(actor[i * STAGE_COL + j], Vector3(0.f, j * _(7), 0.1f), AlphaFunctions::Bounce); anim.Resize(actor[i * STAGE_COL + j], _(32), _(25), AlphaFunctions::Bounce); anim.SetLooping(true); } } anim.Play(); #endif } { ImageActor actor = ImageActor::New(spriteImage, ImageActor::PixelArea(0, 224, 64, 64)); actor.SetParentOrigin(ParentOrigin::CENTER); actor.SetAnchorPoint(AnchorPoint::CENTER); actor.SetSize(_(32), _(32)); actor.SetZ(0.1f); //stage.Add(actor); } // Respond to a click anywhere on the stage stage.GetRootLayer().TouchedSignal().Connect( this, &HelloWorldController::OnTouch ); }
/** * @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 ); }