X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Fblocks%2Fblocks-example.cpp;h=e22260df2c8ed96b5a3bfacce48e197c43bb378a;hb=00d626babc4777951e1b75a6f9ee90e502940c38;hp=c9c336af0f650818901b12a4c971e68c77b45e4f;hpb=46e6a0e92784c860b2b5425e34941c6574dd8062;p=platform%2Fcore%2Fuifw%2Fdali-demo.git diff --git a/examples/blocks/blocks-example.cpp b/examples/blocks/blocks-example.cpp index c9c336a..e22260d 100644 --- a/examples/blocks/blocks-example.cpp +++ b/examples/blocks/blocks-example.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -214,7 +214,29 @@ public: */ ExampleController( Application& application ) : mApplication( application ), - mView() + mView(), + mContentLayer(), + mBall(), + mBallStartPosition(), + mBallVelocity(), + mBallAnimation(), + mPaddle(), + mPaddleImage(), + mPaddleHandle(), + mPaddleHitMargin(), + mWobbleAnimation(), + mWobbleProperty( Property::INVALID_INDEX ), + mLevelContainer(), + mBrickImageMap(), + mDragAnimation(), + mDragActor(), + mRelativeDragPoint(), + mDestroyAnimationMap(), + mPaddleFullSize(), + mLevel( 0 ), + mLives( TOTAL_LIVES ), + mBrickCount( 0 ) + { // Connect to the Application's Init and orientation changed signal mApplication.InitSignal().Connect(this, &ExampleController::Create); @@ -228,6 +250,9 @@ public: { Stage::GetCurrent().KeyEventSignal().Connect(this, &ExampleController::OnKeyEvent); + // 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; @@ -289,8 +314,8 @@ private: mPaddle.SetPosition( stageSize * Vector3( PADDLE_START_POSITION ) ); mContentLayer.Add(mPaddle); - mPaddle.TouchedSignal().Connect(this, &ExampleController::OnTouchPaddle); - mContentLayer.TouchedSignal().Connect(this, &ExampleController::OnTouchLayer); + mPaddle.TouchSignal().Connect(this, &ExampleController::OnTouchPaddle); + mContentLayer.TouchSignal().Connect(this, &ExampleController::OnTouchLayer); const float margin(BALL_SIZE.width * stageSize.width * 0.5f); @@ -362,6 +387,17 @@ private: mBrickCount = 0; + if( mBrickImageMap.Empty() ) + { + Vector2 stageSize(Stage::GetCurrent().GetSize()); + const Vector2 brickSize(BRICK_SIZE * Vector2(stageSize.x, stageSize.x)); + + mBrickImageMap["desiredWidth"] = static_cast( brickSize.width ); + mBrickImageMap["desiredHeight"] = static_cast( brickSize.height ); + mBrickImageMap["fittingMode"] = "SCALE_TO_FILL"; + mBrickImageMap["samplingMode"] = "BOX_THEN_LINEAR"; + } + switch(level%TOTAL_LEVELS) { case 0: @@ -519,14 +555,11 @@ private: */ Actor CreateBrick( const Vector2& position, int type ) { - Vector2 stageSize(Stage::GetCurrent().GetSize()); - const Vector2 brickSize(BRICK_SIZE * Vector2(stageSize.x, stageSize.x)); - - Image img = ResourceImage::New( BRICK_IMAGE_PATH[type], Dali::ImageDimensions( 128, 64 ), Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR ); - ImageView brick = ImageView::New(img); + mBrickImageMap["url"] = BRICK_IMAGE_PATH[type]; + ImageView brick = ImageView::New(); + brick.SetProperty( ImageView::Property::IMAGE, mBrickImageMap ); brick.SetParentOrigin(ParentOrigin::TOP_LEFT); brick.SetAnchorPoint(AnchorPoint::CENTER); - brick.SetSize( brickSize ); brick.SetPosition( Vector3( position ) ); // Add a constraint on the brick between it and the ball generating a collision-property @@ -579,15 +612,15 @@ private: * @param[in] actor The actor touched * @param[in] event The touch event */ - bool OnTouchPaddle(Actor actor, const TouchEvent& event) + bool OnTouchPaddle(Actor actor, const TouchData& event) { if(event.GetPointCount()>0) { - const TouchPoint& point = event.GetPoint(0); - if(point.state==TouchPoint::Down) // Commence dragging + if( event.GetState( 0 ) == PointState::DOWN ) // Commence dragging { // Get point where user touched paddle (relative to paddle's center) - mRelativeDragPoint = Vector3(point.screen.x, point.screen.y, 0.0f); + Vector2 screenPoint = event.GetScreenPosition( 0 ); + mRelativeDragPoint = screenPoint; mRelativeDragPoint -= actor.GetCurrentPosition(); mDragActor = actor; @@ -605,17 +638,16 @@ private: * @param[in] actor The actor touched * @param[in] event The touch event */ - bool OnTouchLayer(Actor actor, const TouchEvent& event) + bool OnTouchLayer(Actor actor, const TouchData& event) { if(event.GetPointCount()>0) { - const TouchPoint& point = event.GetPoint(0); if(mDragActor) { - Vector3 position(point.screen.x, point.screen.y, 0.0f); + Vector3 position( event.GetScreenPosition( 0 ) ); mPaddle.SetPosition( position - mRelativeDragPoint ); - if(point.state==TouchPoint::Up) // Stop dragging + if( event.GetState( 0 ) == PointState::UP ) // Stop dragging { mDragAnimation = Animation::New(0.25f); mDragAnimation.AnimateTo( Property(mDragActor, Actor::Property::SCALE), Vector3(1.0f, 1.0f, 1.0f), AlphaFunction::EASE_IN); @@ -710,7 +742,7 @@ private: void OnHitPaddle(PropertyNotification& source) { Actor delegate = Actor::DownCast(source.GetTarget()); - Vector3 collisionVector = delegate.GetProperty(source.GetTargetProperty()); + Vector3 collisionVector = delegate.GetCurrentProperty< Vector3 >( source.GetTargetProperty() ); Vector3 ballRelativePosition(mBall.GetCurrentPosition() - mPaddle.GetCurrentPosition()); ballRelativePosition.Normalize(); @@ -745,7 +777,7 @@ private: void OnHitBrick(PropertyNotification& source) { Actor brick = Actor::DownCast(source.GetTarget()); - Vector3 collisionVector = brick.GetProperty(source.GetTargetProperty()); + Vector3 collisionVector = brick.GetCurrentProperty< Vector3 >( source.GetTargetProperty() ); const float normalVelocity = fabsf(mBallVelocity.Dot(collisionVector)); mBallVelocity += collisionVector * normalVelocity * 2.0f; @@ -816,6 +848,7 @@ private: Animation mWobbleAnimation; ///< Paddle's animation when hit (wobbles) Property::Index mWobbleProperty; ///< The wobble property (generated from animation) Actor mLevelContainer; ///< The level container (contains bricks) + Property::Map mBrickImageMap; ///< The property map used to load the brick // actor - dragging functionality @@ -836,7 +869,7 @@ void RunTest(Application& app) app.MainLoop(); } -int main(int argc, char **argv) +int DALI_EXPORT_API main(int argc, char **argv) { Application app = Application::New(&argc, &argv, DEMO_THEME_PATH);