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( 5.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 }
48 // This example shows the properties of the arc visual - thickness, startAngle and sweepAngle and animates them.
50 class ArcVisualExample : public ConnectionTracker
54 ArcVisualExample( Application& application )
55 : mApplication( application ),
59 // Connect to the Application's Init signal
60 mApplication.InitSignal().Connect( this, &ArcVisualExample::Create );
63 ~ArcVisualExample() = default;
67 // The Init signal is received once (only) during the Application lifetime
68 void Create( Application& application )
70 // Get a handle to the stage
71 Stage stage = Stage::GetCurrent();
72 stage.SetBackgroundColor( Color::WHITE );
74 mControl = Control::New();
75 mControl.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
76 mControl.SetProperty( Actor::Property::SIZE, Vector2( 200.0f, 200.0f ) );
77 mControl.SetProperty( Control::Property::BACKGROUND, BACKGROUND );
79 stage.Add( mControl );
81 // Respond to a click anywhere on the stage
82 stage.GetRootLayer().TouchSignal().Connect( this, &ArcVisualExample::OnTouch );
84 // Respond to key events
85 stage.KeyEventSignal().Connect( this, &ArcVisualExample::OnKeyEvent );
88 bool OnTouch( Actor actor, const TouchData& touch )
90 if( touch.GetState( 0 ) == PointState::UP )
92 Property::Array array;
93 array.PushBack( Property::Map().Add( "target", "background" )
94 .Add( "property", "startAngle" )
95 .Add( "initialValue", START_ANGLE_INITIAL_VALUE )
96 .Add( "targetValue", START_ANGLE_TARGET_VALUE )
97 .Add( "animator", Property::Map().Add( "duration", ANIMATION_DURATION ) ) );
98 array.PushBack( Property::Map().Add( "target", "background" )
99 .Add( "property", "sweepAngle" )
100 .Add( "initialValue", SWEEP_ANGLE_INITIAL_VALUE )
101 .Add( "targetValue", SWEEP_ANGLE_TARGET_VALUE )
102 .Add( "animator", Property::Map().Add( "duration", ANIMATION_DURATION ) ) );
104 TransitionData transitionData = TransitionData::New( array );
105 Animation animation = DevelControl::CreateTransition( Toolkit::Internal::GetImplementation( mControl ), transitionData );
111 void OnKeyEvent( const KeyEvent& event )
113 if( event.state == KeyEvent::Down )
115 if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) )
123 Application& mApplication;
129 int DALI_EXPORT_API main( int argc, char **argv )
131 Application application = Application::New( &argc, &argv );
132 ArcVisualExample test( application );
133 application.MainLoop();