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/visuals/arc-visual-actions-devel.h>
23 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
24 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
27 using namespace Dali::Toolkit;
32 const float START_ANGLE_INITIAL_VALUE( 0.0f );
33 const float START_ANGLE_TARGET_VALUE( 360.0f );
34 const float SWEEP_ANGLE_INITIAL_VALUE( 90.0f );
35 const float SWEEP_ANGLE_TARGET_VALUE( 360.0f );
36 const float ANIMATION_DURATION( 3.0f );
38 const Property::Value BACKGROUND
40 { Visual::Property::TYPE, DevelVisual::ARC },
41 { Visual::Property::MIX_COLOR, Color::RED },
42 { DevelArcVisual::Property::START_ANGLE, 0.0f },
43 { DevelArcVisual::Property::SWEEP_ANGLE, 90.0f },
44 { DevelArcVisual::Property::CAP, DevelArcVisual::Cap::ROUND },
45 { DevelArcVisual::Property::THICKNESS, 20.0f }
48 const Property::Value TEXT_BACKGROUND
50 { Visual::Property::TYPE, Visual::COLOR },
51 { ColorVisual::Property::MIX_COLOR, Vector4( 0.8f, 0.8f, 0.8f, 1.0f ) },
52 { DevelVisual::Property::CORNER_RADIUS, 0.5f },
53 { DevelVisual::Property::CORNER_RADIUS_POLICY, Toolkit::Visual::Transform::Policy::RELATIVE }
56 const Property::Value TRANSITION_ANIMATOR
58 { "timePeriod", Property::Map().Add( "duration", ANIMATION_DURATION ) }
61 const Property::Value TRANSITION_START_ANGLE
63 { "target", "background" },
64 { "property", "startAngle" },
65 { "initialValue", START_ANGLE_INITIAL_VALUE },
66 { "targetValue", START_ANGLE_TARGET_VALUE },
67 { "animator", TRANSITION_ANIMATOR }
70 const Property::Value TRANSITION_SWEEP_ANGLE
72 { "target", "background" },
73 { "property", "sweepAngle" },
74 { "initialValue", SWEEP_ANGLE_INITIAL_VALUE },
75 { "targetValue", SWEEP_ANGLE_TARGET_VALUE },
76 { "animator", TRANSITION_ANIMATOR }
81 // This example shows the properties of the arc visual - thickness, startAngle and sweepAngle and animates them.
83 class ArcVisualExample : public ConnectionTracker
87 ArcVisualExample( Application& application )
88 : mApplication( application ),
89 mSelectedPoperty( DevelArcVisual::Property::START_ANGLE )
91 // Connect to the Application's Init signal
92 mApplication.InitSignal().Connect( this, &ArcVisualExample::Create );
95 ~ArcVisualExample() = default;
99 // The Init signal is received once (only) during the Application lifetime
100 void Create( Application& application )
102 // Get a handle to the window
103 Window window = application.GetWindow();
104 window.SetBackgroundColor( Color::WHITE );
106 mControl = Control::New();
107 mControl.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
108 mControl.SetProperty( Actor::Property::SIZE, Vector2( 300.0f, 300.0f ) );
109 mControl.SetProperty( Control::Property::BACKGROUND, BACKGROUND );
110 window.Add( mControl );
112 mStartAngleLabel = TextLabel::New( "1" );
113 mStartAngleLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
114 mStartAngleLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT );
115 mStartAngleLabel.SetProperty( Actor::Property::POSITION, Vector2( -30.0f, -10.0f ) );
116 mStartAngleLabel.SetProperty( Control::Property::BACKGROUND, TEXT_BACKGROUND );
117 mStartAngleLabel.SetProperty( Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE );
118 mStartAngleLabel.SetProperty( Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE );
119 mStartAngleLabel.SetProperty( Control::Property::PADDING, Extents( 20.0f, 20.0f, 10.0f, 10.0f ) );
120 mStartAngleLabel.TouchSignal().Connect( this, &ArcVisualExample::OnButtonTouch );
121 window.Add( mStartAngleLabel );
123 mSweepAngleLabel = TextLabel::New( "2" );
124 mSweepAngleLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
125 mSweepAngleLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER );
126 mSweepAngleLabel.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, -10.0f ) );
127 mSweepAngleLabel.SetProperty( Control::Property::BACKGROUND, TEXT_BACKGROUND );
128 mSweepAngleLabel.SetProperty( Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE );
129 mSweepAngleLabel.SetProperty( Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE );
130 mSweepAngleLabel.SetProperty( Control::Property::PADDING, Extents( 20.0f, 20.0f, 10.0f, 10.0f ) );
131 mSweepAngleLabel.TouchSignal().Connect( this, &ArcVisualExample::OnButtonTouch );
132 window.Add( mSweepAngleLabel );
134 mThicknessLabel = TextLabel::New( "3" );
135 mThicknessLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
136 mThicknessLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_LEFT );
137 mThicknessLabel.SetProperty( Actor::Property::POSITION, Vector2( 30.0f, -10.0f ) );
138 mThicknessLabel.SetProperty( Control::Property::BACKGROUND, TEXT_BACKGROUND );
139 mThicknessLabel.SetProperty( Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE );
140 mThicknessLabel.SetProperty( Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE );
141 mThicknessLabel.SetProperty( Control::Property::PADDING, Extents( 20.0f, 20.0f, 10.0f, 10.0f ) );
142 mThicknessLabel.TouchSignal().Connect( this, &ArcVisualExample::OnButtonTouch );
143 window.Add( mThicknessLabel );
145 mPlusTextLabel = TextLabel::New( "+" );
146 mPlusTextLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
147 mPlusTextLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
148 mPlusTextLabel.SetProperty( Actor::Property::POSITION, Vector2( 20.0f, 10.0f ) );
149 mPlusTextLabel.SetProperty( Control::Property::BACKGROUND, TEXT_BACKGROUND );
150 mPlusTextLabel.SetProperty( Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE );
151 mPlusTextLabel.SetProperty( Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE );
152 mPlusTextLabel.SetProperty( Control::Property::PADDING, Extents( 20.0f, 20.0f, 10.0f, 10.0f ) );
153 mPlusTextLabel.TouchSignal().Connect( this, &ArcVisualExample::OnButtonTouch );
154 window.Add( mPlusTextLabel );
156 mMinusTextLabel = TextLabel::New( "-" );
157 mMinusTextLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
158 mMinusTextLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT );
159 mMinusTextLabel.SetProperty( Actor::Property::POSITION, Vector2( -20.0f, 10.0f ) );
160 mMinusTextLabel.SetProperty( Control::Property::BACKGROUND, TEXT_BACKGROUND );
161 mMinusTextLabel.SetProperty( Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE );
162 mMinusTextLabel.SetProperty( Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE );
163 mMinusTextLabel.SetProperty( Control::Property::PADDING, Extents( 25.0f, 25.0f, 10.0f, 10.0f ) );
164 mMinusTextLabel.TouchSignal().Connect( this, &ArcVisualExample::OnButtonTouch );
165 window.Add( mMinusTextLabel );
167 // Respond to a click anywhere on the window
168 window.GetRootLayer().TouchSignal().Connect( this, &ArcVisualExample::OnTouch );
170 // Respond to key events
171 window.KeyEventSignal().Connect( this, &ArcVisualExample::OnKeyEvent );
174 bool OnButtonTouch( Actor actor, const TouchData& touch )
176 if( touch.GetState( 0 ) == PointState::UP )
178 Control control = Control::DownCast( actor );
179 if( control == mStartAngleLabel )
181 mSelectedPoperty = DevelArcVisual::Property::START_ANGLE;
183 else if( control == mSweepAngleLabel )
185 mSelectedPoperty = DevelArcVisual::Property::SWEEP_ANGLE;
187 else if( control == mThicknessLabel )
189 mSelectedPoperty = DevelArcVisual::Property::THICKNESS;
191 else if( control == mPlusTextLabel )
193 Property::Map map = mControl.GetProperty< Property::Map >( Control::Property::BACKGROUND );
194 Property::Value* value = map.Find( mSelectedPoperty );
197 DevelControl::DoAction( mControl, Control::Property::BACKGROUND, DevelArcVisual::Action::UPDATE_PROPERTY,
198 Property::Map().Add( mSelectedPoperty, value->Get< float >() + 5.0f ) );
203 Property::Map map = mControl.GetProperty< Property::Map >( Control::Property::BACKGROUND );
204 Property::Value* value = map.Find( mSelectedPoperty );
207 DevelControl::DoAction( mControl, Control::Property::BACKGROUND, DevelArcVisual::Action::UPDATE_PROPERTY,
208 Property::Map().Add( mSelectedPoperty, value->Get< float >() - 5.0f ) );
215 bool OnTouch( Actor actor, const TouchData& touch )
217 if( touch.GetState( 0 ) == PointState::UP )
219 Property::Array array;
220 array.PushBack( TRANSITION_START_ANGLE );
221 array.PushBack( TRANSITION_SWEEP_ANGLE );
223 TransitionData transitionData = TransitionData::New( array );
224 Animation animation = DevelControl::CreateTransition( Toolkit::Internal::GetImplementation( mControl ), transitionData );
230 void OnKeyEvent( const KeyEvent& event )
232 if( event.state == KeyEvent::Up )
234 if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
242 Application& mApplication;
244 TextLabel mStartAngleLabel;
245 TextLabel mSweepAngleLabel;
246 TextLabel mThicknessLabel;
247 TextLabel mPlusTextLabel;
248 TextLabel mMinusTextLabel;
249 Property::Index mSelectedPoperty;
252 int DALI_EXPORT_API main( int argc, char **argv )
254 Application application = Application::New( &argc, &argv );
255 ArcVisualExample test( application );
256 application.MainLoop();