X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-demo.git;a=blobdiff_plain;f=examples%2Farc-visual%2Farc-visual-example.cpp;h=8ccb78adae08e62025e5e7e1566f3359e418606f;hp=3a1aa9528f03b4d2eb3c4306c5f037d19ef3ff9d;hb=1b19fd140ff139b5854a1a62447faf31b175d8f6;hpb=b26d446b0cb6a316abc3a79d4fc70d0ae1b7994c diff --git a/examples/arc-visual/arc-visual-example.cpp b/examples/arc-visual/arc-visual-example.cpp index 3a1aa95..8ccb78a 100644 --- a/examples/arc-visual/arc-visual-example.cpp +++ b/examples/arc-visual/arc-visual-example.cpp @@ -17,64 +17,52 @@ #include #include -#include -#include +#include #include +#include #include -#include using namespace Dali; using namespace Dali::Toolkit; namespace { - -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( 3.0f ); - -const Property::Value BACKGROUND -{ - { Visual::Property::TYPE, DevelVisual::ARC }, - { Visual::Property::MIX_COLOR, Color::RED }, - { DevelArcVisual::Property::START_ANGLE, 0.0f }, - { DevelArcVisual::Property::SWEEP_ANGLE, 90.0f }, - { DevelArcVisual::Property::CAP, DevelArcVisual::Cap::ROUND }, - { 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 } -}; +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(3.0f); + +const Property::Value BACKGROUND{ + {Visual::Property::TYPE, DevelVisual::ARC}, + {Visual::Property::MIX_COLOR, Color::RED}, + {DevelArcVisual::Property::START_ANGLE, 0.0f}, + {DevelArcVisual::Property::SWEEP_ANGLE, 90.0f}, + {DevelArcVisual::Property::CAP, DevelArcVisual::Cap::ROUND}, + {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 @@ -83,155 +71,151 @@ const Property::Value TRANSITION_SWEEP_ANGLE class ArcVisualExample : public ConnectionTracker { public: - - ArcVisualExample( Application& application ) - : mApplication( application ), - mSelectedPoperty( DevelArcVisual::Property::START_ANGLE ) + ArcVisualExample(Application& application) + : mApplication(application), + mSelectedPoperty(DevelArcVisual::Property::START_ANGLE) { // Connect to the Application's Init signal - mApplication.InitSignal().Connect( this, &ArcVisualExample::Create ); + mApplication.InitSignal().Connect(this, &ArcVisualExample::Create); } ~ArcVisualExample() = default; private: - // The Init signal is received once (only) during the Application lifetime - void Create( Application& application ) + void Create(Application& application) { // Get a handle to the window Window window = application.GetWindow(); - window.SetBackgroundColor( Color::WHITE ); + window.SetBackgroundColor(Color::WHITE); mControl = Control::New(); - mControl.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); - 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.TouchedSignal().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.TouchedSignal().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.TouchedSignal().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.TouchedSignal().Connect( this, &ArcVisualExample::OnButtonTouch ); - window.Add( mPlusTextLabel ); - - 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.TouchedSignal().Connect( this, &ArcVisualExample::OnButtonTouch ); - window.Add( mMinusTextLabel ); + mControl.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + 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.TouchedSignal().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.TouchedSignal().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.TouchedSignal().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.TouchedSignal().Connect(this, &ArcVisualExample::OnButtonTouch); + window.Add(mPlusTextLabel); + + 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.TouchedSignal().Connect(this, &ArcVisualExample::OnButtonTouch); + window.Add(mMinusTextLabel); // Respond to a click anywhere on the window - window.GetRootLayer().TouchedSignal().Connect( this, &ArcVisualExample::OnTouch ); + window.GetRootLayer().TouchedSignal().Connect(this, &ArcVisualExample::OnTouch); // Respond to key events - window.KeyEventSignal().Connect( this, &ArcVisualExample::OnKeyEvent ); + window.KeyEventSignal().Connect(this, &ArcVisualExample::OnKeyEvent); } - bool OnButtonTouch( Actor actor, const TouchEvent& touch ) + bool OnButtonTouch(Actor actor, const TouchEvent& touch) { - if( touch.GetState( 0 ) == PointState::UP ) + if(touch.GetState(0) == PointState::UP) { - Control control = Control::DownCast( actor ); - if( control == mStartAngleLabel ) + Control control = Control::DownCast(actor); + if(control == mStartAngleLabel) { mSelectedPoperty = DevelArcVisual::Property::START_ANGLE; } - else if( control == mSweepAngleLabel ) + else if(control == mSweepAngleLabel) { mSelectedPoperty = DevelArcVisual::Property::SWEEP_ANGLE; } - else if( control == mThicknessLabel ) + else if(control == mThicknessLabel) { mSelectedPoperty = DevelArcVisual::Property::THICKNESS; } - else if( control == mPlusTextLabel ) + else if(control == mPlusTextLabel) { - Property::Map map = mControl.GetProperty< Property::Map >( Control::Property::BACKGROUND ); - Property::Value* value = map.Find( mSelectedPoperty ); - if( value ) + Property::Map map = mControl.GetProperty(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 ) ); + DevelControl::DoAction(mControl, Control::Property::BACKGROUND, DevelArcVisual::Action::UPDATE_PROPERTY, Property::Map().Add(mSelectedPoperty, value->Get() + 5.0f)); } } else { - Property::Map map = mControl.GetProperty< Property::Map >( Control::Property::BACKGROUND ); - Property::Value* value = map.Find( mSelectedPoperty ); - if( value ) + Property::Map map = mControl.GetProperty(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 ) ); + DevelControl::DoAction(mControl, Control::Property::BACKGROUND, DevelArcVisual::Action::UPDATE_PROPERTY, Property::Map().Add(mSelectedPoperty, value->Get() - 5.0f)); } } } return true; } - bool OnTouch( Actor actor, const TouchEvent& touch ) + bool OnTouch(Actor actor, const TouchEvent& touch) { - if( touch.GetState( 0 ) == PointState::UP ) + if(touch.GetState(0) == PointState::UP) { Property::Array array; - array.PushBack( TRANSITION_START_ANGLE ); - array.PushBack( TRANSITION_SWEEP_ANGLE ); + array.PushBack(TRANSITION_START_ANGLE); + array.PushBack(TRANSITION_SWEEP_ANGLE); - TransitionData transitionData = TransitionData::New( array ); - Animation animation = DevelControl::CreateTransition( Toolkit::Internal::GetImplementation( mControl ), transitionData ); + TransitionData transitionData = TransitionData::New(array); + Animation animation = DevelControl::CreateTransition(Toolkit::Internal::GetImplementation(mControl), transitionData); animation.Play(); } return true; } - void OnKeyEvent( const KeyEvent& event ) + void OnKeyEvent(const KeyEvent& event) { - if( event.GetState() == KeyEvent::UP ) + if(event.GetState() == KeyEvent::UP) { - if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) ) + if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK)) { mApplication.Quit(); } @@ -239,20 +223,20 @@ private: } private: - Application& mApplication; - Control mControl; - TextLabel mStartAngleLabel; - TextLabel mSweepAngleLabel; - TextLabel mThicknessLabel; - TextLabel mPlusTextLabel; - TextLabel mMinusTextLabel; + Application& mApplication; + Control mControl; + TextLabel mStartAngleLabel; + TextLabel mSweepAngleLabel; + TextLabel mThicknessLabel; + TextLabel mPlusTextLabel; + TextLabel mMinusTextLabel; Property::Index mSelectedPoperty; }; -int DALI_EXPORT_API main( int argc, char **argv ) +int DALI_EXPORT_API main(int argc, char** argv) { - Application application = Application::New( &argc, &argv ); - ArcVisualExample test( application ); + Application application = Application::New(&argc, &argv); + ArcVisualExample test(application); application.MainLoop(); return 0; }