2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <dali-toolkit/dali-toolkit.h>
19 #include <dali-toolkit/devel-api/controls/control-devel.h>
20 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
21 #include <dali-toolkit/devel-api/visuals/arc-visual-properties-devel.h>
22 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
25 using namespace Dali::Toolkit;
30 const float START_ANGLE_INITIAL_VALUE( 0.0f );
31 const float START_ANGLE_TARGET_VALUE( 360.0f );
32 const float SWEEP_ANGLE_INITIAL_VALUE( 90.0f );
33 const float SWEEP_ANGLE_TARGET_VALUE( 360.0f );
34 const float ANIMATION_DURATION( 3.0f );
36 const Property::Value BACKGROUND
38 { Visual::Property::TYPE, DevelVisual::ARC },
39 { Visual::Property::MIX_COLOR, Color::RED },
40 { DevelArcVisual::Property::START_ANGLE, 0.0f },
41 { DevelArcVisual::Property::SWEEP_ANGLE, 90.0f },
42 { DevelArcVisual::Property::CAP, DevelArcVisual::Cap::ROUND },
43 { DevelArcVisual::Property::THICKNESS, 20.0f }
46 const Property::Value TRANSITION_ANIMATOR
48 { "timePeriod", Property::Map().Add( "duration", ANIMATION_DURATION ) }
51 const Property::Value TRANSITION_START_ANGLE
53 { "target", "background" },
54 { "property", "startAngle" },
55 { "initialValue", START_ANGLE_INITIAL_VALUE },
56 { "targetValue", START_ANGLE_TARGET_VALUE },
57 { "animator", TRANSITION_ANIMATOR }
60 const Property::Value TRANSITION_SWEEP_ANGLE
62 { "target", "background" },
63 { "property", "sweepAngle" },
64 { "initialValue", SWEEP_ANGLE_INITIAL_VALUE },
65 { "targetValue", SWEEP_ANGLE_TARGET_VALUE },
66 { "animator", TRANSITION_ANIMATOR }
71 // This example shows the properties of the arc visual - thickness, startAngle and sweepAngle and animates them.
73 class ArcVisualExample : public ConnectionTracker
77 ArcVisualExample( Application& application )
78 : mApplication( application ),
82 // Connect to the Application's Init signal
83 mApplication.InitSignal().Connect( this, &ArcVisualExample::Create );
86 ~ArcVisualExample() = default;
90 // The Init signal is received once (only) during the Application lifetime
91 void Create( Application& application )
93 // Get a handle to the stage
94 Stage stage = Stage::GetCurrent();
95 stage.SetBackgroundColor( Color::WHITE );
97 mControl = Control::New();
98 mControl.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
99 mControl.SetProperty( Actor::Property::SIZE, Vector2( 200.0f, 200.0f ) );
100 mControl.SetProperty( Control::Property::BACKGROUND, BACKGROUND );
102 stage.Add( mControl );
104 // Respond to a click anywhere on the stage
105 stage.GetRootLayer().TouchSignal().Connect( this, &ArcVisualExample::OnTouch );
107 // Respond to key events
108 stage.KeyEventSignal().Connect( this, &ArcVisualExample::OnKeyEvent );
111 bool OnTouch( Actor actor, const TouchData& touch )
113 if( touch.GetState( 0 ) == PointState::UP )
115 Property::Array array;
116 array.PushBack( TRANSITION_START_ANGLE );
117 array.PushBack( TRANSITION_SWEEP_ANGLE );
119 TransitionData transitionData = TransitionData::New( array );
120 Animation animation = DevelControl::CreateTransition( Toolkit::Internal::GetImplementation( mControl ), transitionData );
126 void OnKeyEvent( const KeyEvent& event )
128 if( event.state == KeyEvent::Down )
130 if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) )
138 Application& mApplication;
144 int DALI_EXPORT_API main( int argc, char **argv )
146 Application application = Application::New( &argc, &argv );
147 ArcVisualExample test( application );
148 application.MainLoop();