X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;ds=sidebyside;f=examples%2Farc-visual%2Farc-visual-example.cpp;h=708f7d557eb790536a9913d09d3e1e4f627be7e0;hb=c70446e9b125ae8bb236b4cbc3fd3f8b548459cd;hp=a397ba38b3f925e1448db0f60758b9e7a2232fc1;hpb=cc86309efaef5f77c85ece1199f95e08534e4a32;p=platform%2Fcore%2Fuifw%2Fdali-demo.git diff --git a/examples/arc-visual/arc-visual-example.cpp b/examples/arc-visual/arc-visual-example.cpp index a397ba3..708f7d5 100644 --- a/examples/arc-visual/arc-visual-example.cpp +++ b/examples/arc-visual/arc-visual-example.cpp @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include using namespace Dali; @@ -31,7 +33,7 @@ const float START_ANGLE_INITIAL_VALUE( 0.0f ); const float START_ANGLE_TARGET_VALUE( 360.0f ); const float SWEEP_ANGLE_INITIAL_VALUE( 90.0f ); const float SWEEP_ANGLE_TARGET_VALUE( 360.0f ); -const float ANIMATION_DURATION( 5.0f ); +const float ANIMATION_DURATION( 3.0f ); const Property::Value BACKGROUND { @@ -43,6 +45,37 @@ const Property::Value BACKGROUND { DevelArcVisual::Property::THICKNESS, 20.0f } }; +const Property::Value TEXT_BACKGROUND +{ + { Visual::Property::TYPE, Visual::COLOR }, + { ColorVisual::Property::MIX_COLOR, Vector4( 0.8f, 0.8f, 0.8f, 1.0f ) }, + { DevelVisual::Property::CORNER_RADIUS, 0.5f }, + { DevelVisual::Property::CORNER_RADIUS_POLICY, Toolkit::Visual::Transform::Policy::RELATIVE } +}; + +const Property::Value TRANSITION_ANIMATOR +{ + { "timePeriod", Property::Map().Add( "duration", ANIMATION_DURATION ) } +}; + +const Property::Value TRANSITION_START_ANGLE +{ + { "target", "background" }, + { "property", "startAngle" }, + { "initialValue", START_ANGLE_INITIAL_VALUE }, + { "targetValue", START_ANGLE_TARGET_VALUE }, + { "animator", TRANSITION_ANIMATOR } +}; + +const Property::Value TRANSITION_SWEEP_ANGLE +{ + { "target", "background" }, + { "property", "sweepAngle" }, + { "initialValue", SWEEP_ANGLE_INITIAL_VALUE }, + { "targetValue", SWEEP_ANGLE_TARGET_VALUE }, + { "animator", TRANSITION_ANIMATOR } +}; + } // namespace // This example shows the properties of the arc visual - thickness, startAngle and sweepAngle and animates them. @@ -53,8 +86,7 @@ public: ArcVisualExample( Application& application ) : mApplication( application ), - mStartAngle( 0.0f ), - mSweepAngle( 0.0f ) + mSelectedPoperty( DevelArcVisual::Property::START_ANGLE ) { // Connect to the Application's Init signal mApplication.InitSignal().Connect( this, &ArcVisualExample::Create ); @@ -67,39 +99,126 @@ private: // The Init signal is received once (only) during the Application lifetime void Create( Application& application ) { - // Get a handle to the stage - Stage stage = Stage::GetCurrent(); - stage.SetBackgroundColor( Color::WHITE ); + // Get a handle to the window + Window window = application.GetWindow(); + window.SetBackgroundColor( Color::WHITE ); mControl = Control::New(); mControl.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - mControl.SetSize( 200.0f, 200.0f ); + mControl.SetProperty( Actor::Property::SIZE, Vector2( 300.0f, 300.0f ) ); mControl.SetProperty( Control::Property::BACKGROUND, BACKGROUND ); + window.Add( mControl ); + + mStartAngleLabel = TextLabel::New( "1" ); + mStartAngleLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + mStartAngleLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT ); + mStartAngleLabel.SetProperty( Actor::Property::POSITION, Vector2( -30.0f, -10.0f ) ); + mStartAngleLabel.SetProperty( Control::Property::BACKGROUND, TEXT_BACKGROUND ); + mStartAngleLabel.SetProperty( Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE ); + mStartAngleLabel.SetProperty( Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE ); + mStartAngleLabel.SetProperty( Control::Property::PADDING, Extents( 20.0f, 20.0f, 10.0f, 10.0f ) ); + mStartAngleLabel.TouchSignal().Connect( this, &ArcVisualExample::OnButtonTouch ); + window.Add( mStartAngleLabel ); + + mSweepAngleLabel = TextLabel::New( "2" ); + mSweepAngleLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + mSweepAngleLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER ); + mSweepAngleLabel.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, -10.0f ) ); + mSweepAngleLabel.SetProperty( Control::Property::BACKGROUND, TEXT_BACKGROUND ); + mSweepAngleLabel.SetProperty( Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE ); + mSweepAngleLabel.SetProperty( Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE ); + mSweepAngleLabel.SetProperty( Control::Property::PADDING, Extents( 20.0f, 20.0f, 10.0f, 10.0f ) ); + mSweepAngleLabel.TouchSignal().Connect( this, &ArcVisualExample::OnButtonTouch ); + window.Add( mSweepAngleLabel ); + + mThicknessLabel = TextLabel::New( "3" ); + mThicknessLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + mThicknessLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_LEFT ); + mThicknessLabel.SetProperty( Actor::Property::POSITION, Vector2( 30.0f, -10.0f ) ); + mThicknessLabel.SetProperty( Control::Property::BACKGROUND, TEXT_BACKGROUND ); + mThicknessLabel.SetProperty( Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE ); + mThicknessLabel.SetProperty( Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE ); + mThicknessLabel.SetProperty( Control::Property::PADDING, Extents( 20.0f, 20.0f, 10.0f, 10.0f ) ); + mThicknessLabel.TouchSignal().Connect( this, &ArcVisualExample::OnButtonTouch ); + window.Add( mThicknessLabel ); + + mPlusTextLabel = TextLabel::New( "+" ); + mPlusTextLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + mPlusTextLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + mPlusTextLabel.SetProperty( Actor::Property::POSITION, Vector2( 20.0f, 10.0f ) ); + mPlusTextLabel.SetProperty( Control::Property::BACKGROUND, TEXT_BACKGROUND ); + mPlusTextLabel.SetProperty( Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE ); + mPlusTextLabel.SetProperty( Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE ); + mPlusTextLabel.SetProperty( Control::Property::PADDING, Extents( 20.0f, 20.0f, 10.0f, 10.0f ) ); + mPlusTextLabel.TouchSignal().Connect( this, &ArcVisualExample::OnButtonTouch ); + window.Add( mPlusTextLabel ); - stage.Add( mControl ); + mMinusTextLabel = TextLabel::New( "-" ); + mMinusTextLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); + mMinusTextLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT ); + mMinusTextLabel.SetProperty( Actor::Property::POSITION, Vector2( -20.0f, 10.0f ) ); + mMinusTextLabel.SetProperty( Control::Property::BACKGROUND, TEXT_BACKGROUND ); + mMinusTextLabel.SetProperty( Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE ); + mMinusTextLabel.SetProperty( Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE ); + mMinusTextLabel.SetProperty( Control::Property::PADDING, Extents( 25.0f, 25.0f, 10.0f, 10.0f ) ); + mMinusTextLabel.TouchSignal().Connect( this, &ArcVisualExample::OnButtonTouch ); + window.Add( mMinusTextLabel ); - // Respond to a click anywhere on the stage - stage.GetRootLayer().TouchSignal().Connect( this, &ArcVisualExample::OnTouch ); + // Respond to a click anywhere on the window + window.GetRootLayer().TouchSignal().Connect( this, &ArcVisualExample::OnTouch ); // Respond to key events - stage.KeyEventSignal().Connect( this, &ArcVisualExample::OnKeyEvent ); + window.KeyEventSignal().Connect( this, &ArcVisualExample::OnKeyEvent ); + } + + bool OnButtonTouch( Actor actor, const TouchEvent& touch ) + { + if( touch.GetState( 0 ) == PointState::UP ) + { + Control control = Control::DownCast( actor ); + if( control == mStartAngleLabel ) + { + mSelectedPoperty = DevelArcVisual::Property::START_ANGLE; + } + else if( control == mSweepAngleLabel ) + { + mSelectedPoperty = DevelArcVisual::Property::SWEEP_ANGLE; + } + else if( control == mThicknessLabel ) + { + mSelectedPoperty = DevelArcVisual::Property::THICKNESS; + } + else if( control == mPlusTextLabel ) + { + Property::Map map = mControl.GetProperty< Property::Map >( Control::Property::BACKGROUND ); + Property::Value* value = map.Find( mSelectedPoperty ); + if( value ) + { + DevelControl::DoAction( mControl, Control::Property::BACKGROUND, DevelArcVisual::Action::UPDATE_PROPERTY, + Property::Map().Add( mSelectedPoperty, value->Get< float >() + 5.0f ) ); + } + } + else + { + Property::Map map = mControl.GetProperty< Property::Map >( Control::Property::BACKGROUND ); + Property::Value* value = map.Find( mSelectedPoperty ); + if( value ) + { + DevelControl::DoAction( mControl, Control::Property::BACKGROUND, DevelArcVisual::Action::UPDATE_PROPERTY, + Property::Map().Add( mSelectedPoperty, value->Get< float >() - 5.0f ) ); + } + } + } + return true; } - bool OnTouch( Actor actor, const TouchData& touch ) + bool OnTouch( Actor actor, const TouchEvent& touch ) { if( touch.GetState( 0 ) == PointState::UP ) { Property::Array array; - array.PushBack( Property::Map().Add( "target", "background" ) - .Add( "property", "startAngle" ) - .Add( "initialValue", START_ANGLE_INITIAL_VALUE ) - .Add( "targetValue", START_ANGLE_TARGET_VALUE ) - .Add( "animator", Property::Map().Add( "duration", ANIMATION_DURATION ) ) ); - array.PushBack( Property::Map().Add( "target", "background" ) - .Add( "property", "sweepAngle" ) - .Add( "initialValue", SWEEP_ANGLE_INITIAL_VALUE ) - .Add( "targetValue", SWEEP_ANGLE_TARGET_VALUE ) - .Add( "animator", Property::Map().Add( "duration", ANIMATION_DURATION ) ) ); + array.PushBack( TRANSITION_START_ANGLE ); + array.PushBack( TRANSITION_SWEEP_ANGLE ); TransitionData transitionData = TransitionData::New( array ); Animation animation = DevelControl::CreateTransition( Toolkit::Internal::GetImplementation( mControl ), transitionData ); @@ -110,9 +229,9 @@ private: void OnKeyEvent( const KeyEvent& event ) { - if( event.state == KeyEvent::Down ) + if( event.GetState() == KeyEvent::UP ) { - if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) { mApplication.Quit(); } @@ -122,8 +241,12 @@ private: private: Application& mApplication; Control mControl; - float mStartAngle; - float mSweepAngle; + TextLabel mStartAngleLabel; + TextLabel mSweepAngleLabel; + TextLabel mThicknessLabel; + TextLabel mPlusTextLabel; + TextLabel mMinusTextLabel; + Property::Index mSelectedPoperty; }; int DALI_EXPORT_API main( int argc, char **argv )