2 * Copyright (c) 2021 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/visual-factory/transition-data.h>
21 #include <dali-toolkit/devel-api/visuals/arc-visual-actions-devel.h>
22 #include <dali-toolkit/devel-api/visuals/arc-visual-properties-devel.h>
23 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
26 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{
37 {Visual::Property::TYPE, DevelVisual::ARC},
38 {Visual::Property::MIX_COLOR, Color::RED},
39 {DevelArcVisual::Property::START_ANGLE, 0.0f},
40 {DevelArcVisual::Property::SWEEP_ANGLE, 90.0f},
41 {DevelArcVisual::Property::CAP, DevelArcVisual::Cap::ROUND},
42 {DevelArcVisual::Property::THICKNESS, 20.0f}};
44 const Property::Value TEXT_BACKGROUND{
45 {Visual::Property::TYPE, Visual::COLOR},
46 {ColorVisual::Property::MIX_COLOR, Vector4(0.8f, 0.8f, 0.8f, 1.0f)},
47 {DevelVisual::Property::CORNER_RADIUS, 0.5f},
48 {DevelVisual::Property::CORNER_RADIUS_POLICY, Toolkit::Visual::Transform::Policy::RELATIVE}};
52 // This example shows the properties of the arc visual - thickness, startAngle and sweepAngle and animates them.
54 class ArcVisualExample : public ConnectionTracker
57 ArcVisualExample(Application& application)
58 : mApplication(application),
59 mSelectedPoperty(DevelArcVisual::Property::START_ANGLE)
61 // Connect to the Application's Init signal
62 mApplication.InitSignal().Connect(this, &ArcVisualExample::Create);
65 ~ArcVisualExample() = default;
68 // The Init signal is received once (only) during the Application lifetime
69 void Create(Application& application)
71 // Get a handle to the window
72 Window window = application.GetWindow();
73 window.SetBackgroundColor(Color::WHITE);
75 mControl = Control::New();
76 mControl.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
77 mControl.SetProperty(Actor::Property::SIZE, Vector2(300.0f, 300.0f));
78 mControl.SetProperty(Control::Property::BACKGROUND, BACKGROUND);
81 mStartAngleLabel = TextLabel::New("1");
82 mStartAngleLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
83 mStartAngleLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT);
84 mStartAngleLabel.SetProperty(Actor::Property::POSITION, Vector2(-30.0f, -10.0f));
85 mStartAngleLabel.SetProperty(Control::Property::BACKGROUND, TEXT_BACKGROUND);
86 mStartAngleLabel.SetProperty(Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE);
87 mStartAngleLabel.SetProperty(Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE);
88 mStartAngleLabel.SetProperty(Control::Property::PADDING, Extents(20.0f, 20.0f, 10.0f, 10.0f));
89 mStartAngleLabel.TouchedSignal().Connect(this, &ArcVisualExample::OnButtonTouch);
90 window.Add(mStartAngleLabel);
92 mSweepAngleLabel = TextLabel::New("2");
93 mSweepAngleLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
94 mSweepAngleLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER);
95 mSweepAngleLabel.SetProperty(Actor::Property::POSITION, Vector2(0.0f, -10.0f));
96 mSweepAngleLabel.SetProperty(Control::Property::BACKGROUND, TEXT_BACKGROUND);
97 mSweepAngleLabel.SetProperty(Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE);
98 mSweepAngleLabel.SetProperty(Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE);
99 mSweepAngleLabel.SetProperty(Control::Property::PADDING, Extents(20.0f, 20.0f, 10.0f, 10.0f));
100 mSweepAngleLabel.TouchedSignal().Connect(this, &ArcVisualExample::OnButtonTouch);
101 window.Add(mSweepAngleLabel);
103 mThicknessLabel = TextLabel::New("3");
104 mThicknessLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
105 mThicknessLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_LEFT);
106 mThicknessLabel.SetProperty(Actor::Property::POSITION, Vector2(30.0f, -10.0f));
107 mThicknessLabel.SetProperty(Control::Property::BACKGROUND, TEXT_BACKGROUND);
108 mThicknessLabel.SetProperty(Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE);
109 mThicknessLabel.SetProperty(Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE);
110 mThicknessLabel.SetProperty(Control::Property::PADDING, Extents(20.0f, 20.0f, 10.0f, 10.0f));
111 mThicknessLabel.TouchedSignal().Connect(this, &ArcVisualExample::OnButtonTouch);
112 window.Add(mThicknessLabel);
114 mPlusTextLabel = TextLabel::New("+");
115 mPlusTextLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
116 mPlusTextLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
117 mPlusTextLabel.SetProperty(Actor::Property::POSITION, Vector2(20.0f, 10.0f));
118 mPlusTextLabel.SetProperty(Control::Property::BACKGROUND, TEXT_BACKGROUND);
119 mPlusTextLabel.SetProperty(Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE);
120 mPlusTextLabel.SetProperty(Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE);
121 mPlusTextLabel.SetProperty(Control::Property::PADDING, Extents(20.0f, 20.0f, 10.0f, 10.0f));
122 mPlusTextLabel.TouchedSignal().Connect(this, &ArcVisualExample::OnButtonTouch);
123 window.Add(mPlusTextLabel);
125 mMinusTextLabel = TextLabel::New("-");
126 mMinusTextLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
127 mMinusTextLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT);
128 mMinusTextLabel.SetProperty(Actor::Property::POSITION, Vector2(-20.0f, 10.0f));
129 mMinusTextLabel.SetProperty(Control::Property::BACKGROUND, TEXT_BACKGROUND);
130 mMinusTextLabel.SetProperty(Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE);
131 mMinusTextLabel.SetProperty(Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE);
132 mMinusTextLabel.SetProperty(Control::Property::PADDING, Extents(25.0f, 25.0f, 10.0f, 10.0f));
133 mMinusTextLabel.TouchedSignal().Connect(this, &ArcVisualExample::OnButtonTouch);
134 window.Add(mMinusTextLabel);
136 // Respond to a click anywhere on the window
137 window.GetRootLayer().TouchedSignal().Connect(this, &ArcVisualExample::OnTouch);
139 // Respond to key events
140 window.KeyEventSignal().Connect(this, &ArcVisualExample::OnKeyEvent);
143 bool OnButtonTouch(Actor actor, const TouchEvent& touch)
145 if(touch.GetState(0) == PointState::UP)
147 Control control = Control::DownCast(actor);
148 if(control == mStartAngleLabel)
150 mSelectedPoperty = DevelArcVisual::Property::START_ANGLE;
152 else if(control == mSweepAngleLabel)
154 mSelectedPoperty = DevelArcVisual::Property::SWEEP_ANGLE;
156 else if(control == mThicknessLabel)
158 mSelectedPoperty = DevelArcVisual::Property::THICKNESS;
160 else if(control == mPlusTextLabel)
162 Property::Map map = mControl.GetProperty<Property::Map>(Control::Property::BACKGROUND);
163 Property::Value* value = map.Find(mSelectedPoperty);
166 DevelControl::DoAction(mControl, Control::Property::BACKGROUND, DevelArcVisual::Action::UPDATE_PROPERTY, Property::Map().Add(mSelectedPoperty, value->Get<float>() + 5.0f));
171 Property::Map map = mControl.GetProperty<Property::Map>(Control::Property::BACKGROUND);
172 Property::Value* value = map.Find(mSelectedPoperty);
175 DevelControl::DoAction(mControl, Control::Property::BACKGROUND, DevelArcVisual::Action::UPDATE_PROPERTY, Property::Map().Add(mSelectedPoperty, value->Get<float>() - 5.0f));
182 bool OnTouch(Actor actor, const TouchEvent& touch)
184 if(touch.GetState(0) == PointState::UP)
186 DevelControl::DoAction(mControl,
187 Control::Property::BACKGROUND,
188 DevelArcVisual::Action::UPDATE_PROPERTY,
190 .Add(DevelArcVisual::Property::START_ANGLE, START_ANGLE_INITIAL_VALUE)
191 .Add(DevelArcVisual::Property::SWEEP_ANGLE, SWEEP_ANGLE_INITIAL_VALUE));
193 Animation animation = Animation::New(ANIMATION_DURATION);
194 animation.AnimateTo(DevelControl::GetVisualProperty(mControl, Control::Property::BACKGROUND, DevelArcVisual::Property::START_ANGLE), START_ANGLE_TARGET_VALUE);
195 animation.AnimateTo(DevelControl::GetVisualProperty(mControl, Control::Property::BACKGROUND, DevelArcVisual::Property::SWEEP_ANGLE), SWEEP_ANGLE_TARGET_VALUE);
201 void OnKeyEvent(const KeyEvent& event)
203 if(event.GetState() == KeyEvent::UP)
205 if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK))
213 Application& mApplication;
215 TextLabel mStartAngleLabel;
216 TextLabel mSweepAngleLabel;
217 TextLabel mThicknessLabel;
218 TextLabel mPlusTextLabel;
219 TextLabel mMinusTextLabel;
220 Property::Index mSelectedPoperty;
223 int DALI_EXPORT_API main(int argc, char** argv)
225 Application application = Application::New(&argc, &argv);
226 ArcVisualExample test(application);
227 application.MainLoop();