Further Setter/Getter public API removal from Dali::Actor
[platform/core/uifw/dali-demo.git] / examples / arc-visual / arc-visual-example.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
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>
23
24 using namespace Dali;
25 using namespace Dali::Toolkit;
26
27 namespace
28 {
29
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 );
35
36 const Property::Value BACKGROUND
37 {
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 }
44 };
45
46 } // namespace
47
48 // This example shows the properties of the arc visual - thickness, startAngle and sweepAngle and animates them.
49 //
50 class ArcVisualExample : public ConnectionTracker
51 {
52 public:
53
54   ArcVisualExample( Application& application )
55   : mApplication( application ),
56     mStartAngle( 0.0f ),
57     mSweepAngle( 0.0f )
58   {
59     // Connect to the Application's Init signal
60     mApplication.InitSignal().Connect( this, &ArcVisualExample::Create );
61   }
62
63   ~ArcVisualExample() = default;
64
65 private:
66
67   // The Init signal is received once (only) during the Application lifetime
68   void Create( Application& application )
69   {
70     // Get a handle to the stage
71     Stage stage = Stage::GetCurrent();
72     stage.SetBackgroundColor( Color::WHITE );
73
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 );
78
79     stage.Add( mControl );
80
81     // Respond to a click anywhere on the stage
82     stage.GetRootLayer().TouchSignal().Connect( this, &ArcVisualExample::OnTouch );
83
84     // Respond to key events
85     stage.KeyEventSignal().Connect( this, &ArcVisualExample::OnKeyEvent );
86   }
87
88   bool OnTouch( Actor actor, const TouchData& touch )
89   {
90     if( touch.GetState( 0 ) == PointState::UP )
91     {
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 ) ) );
103
104       TransitionData transitionData = TransitionData::New( array );
105       Animation animation = DevelControl::CreateTransition( Toolkit::Internal::GetImplementation( mControl ), transitionData );
106       animation.Play();
107     }
108     return true;
109   }
110
111   void OnKeyEvent( const KeyEvent& event )
112   {
113     if( event.state == KeyEvent::Down )
114     {
115       if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) )
116       {
117         mApplication.Quit();
118       }
119     }
120   }
121
122 private:
123   Application&  mApplication;
124   Control mControl;
125   float mStartAngle;
126   float mSweepAngle;
127 };
128
129 int DALI_EXPORT_API main( int argc, char **argv )
130 {
131   Application application = Application::New( &argc, &argv );
132   ArcVisualExample test( application );
133   application.MainLoop();
134   return 0;
135 }