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/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}};
50 const Property::Value TRANSITION_ANIMATOR{
51 {"timePeriod", Property::Map().Add("duration", ANIMATION_DURATION)}};
53 const Property::Value TRANSITION_START_ANGLE{
54 {"target", "background"},
55 {"property", "startAngle"},
56 {"initialValue", START_ANGLE_INITIAL_VALUE},
57 {"targetValue", START_ANGLE_TARGET_VALUE},
58 {"animator", TRANSITION_ANIMATOR}};
60 const Property::Value TRANSITION_SWEEP_ANGLE{
61 {"target", "background"},
62 {"property", "sweepAngle"},
63 {"initialValue", SWEEP_ANGLE_INITIAL_VALUE},
64 {"targetValue", SWEEP_ANGLE_TARGET_VALUE},
65 {"animator", TRANSITION_ANIMATOR}};
69 // This example shows the properties of the arc visual - thickness, startAngle and sweepAngle and animates them.
71 class ArcVisualExample : public ConnectionTracker
74 ArcVisualExample(Application& application)
75 : mApplication(application),
76 mSelectedPoperty(DevelArcVisual::Property::START_ANGLE)
78 // Connect to the Application's Init signal
79 mApplication.InitSignal().Connect(this, &ArcVisualExample::Create);
82 ~ArcVisualExample() = default;
85 // The Init signal is received once (only) during the Application lifetime
86 void Create(Application& application)
88 // Get a handle to the window
89 Window window = application.GetWindow();
90 window.SetBackgroundColor(Color::WHITE);
92 mControl = Control::New();
93 mControl.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
94 mControl.SetProperty(Actor::Property::SIZE, Vector2(300.0f, 300.0f));
95 mControl.SetProperty(Control::Property::BACKGROUND, BACKGROUND);
98 mStartAngleLabel = TextLabel::New("1");
99 mStartAngleLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
100 mStartAngleLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_RIGHT);
101 mStartAngleLabel.SetProperty(Actor::Property::POSITION, Vector2(-30.0f, -10.0f));
102 mStartAngleLabel.SetProperty(Control::Property::BACKGROUND, TEXT_BACKGROUND);
103 mStartAngleLabel.SetProperty(Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE);
104 mStartAngleLabel.SetProperty(Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE);
105 mStartAngleLabel.SetProperty(Control::Property::PADDING, Extents(20.0f, 20.0f, 10.0f, 10.0f));
106 mStartAngleLabel.TouchedSignal().Connect(this, &ArcVisualExample::OnButtonTouch);
107 window.Add(mStartAngleLabel);
109 mSweepAngleLabel = TextLabel::New("2");
110 mSweepAngleLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
111 mSweepAngleLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_CENTER);
112 mSweepAngleLabel.SetProperty(Actor::Property::POSITION, Vector2(0.0f, -10.0f));
113 mSweepAngleLabel.SetProperty(Control::Property::BACKGROUND, TEXT_BACKGROUND);
114 mSweepAngleLabel.SetProperty(Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE);
115 mSweepAngleLabel.SetProperty(Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE);
116 mSweepAngleLabel.SetProperty(Control::Property::PADDING, Extents(20.0f, 20.0f, 10.0f, 10.0f));
117 mSweepAngleLabel.TouchedSignal().Connect(this, &ArcVisualExample::OnButtonTouch);
118 window.Add(mSweepAngleLabel);
120 mThicknessLabel = TextLabel::New("3");
121 mThicknessLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
122 mThicknessLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::BOTTOM_LEFT);
123 mThicknessLabel.SetProperty(Actor::Property::POSITION, Vector2(30.0f, -10.0f));
124 mThicknessLabel.SetProperty(Control::Property::BACKGROUND, TEXT_BACKGROUND);
125 mThicknessLabel.SetProperty(Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE);
126 mThicknessLabel.SetProperty(Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE);
127 mThicknessLabel.SetProperty(Control::Property::PADDING, Extents(20.0f, 20.0f, 10.0f, 10.0f));
128 mThicknessLabel.TouchedSignal().Connect(this, &ArcVisualExample::OnButtonTouch);
129 window.Add(mThicknessLabel);
131 mPlusTextLabel = TextLabel::New("+");
132 mPlusTextLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
133 mPlusTextLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
134 mPlusTextLabel.SetProperty(Actor::Property::POSITION, Vector2(20.0f, 10.0f));
135 mPlusTextLabel.SetProperty(Control::Property::BACKGROUND, TEXT_BACKGROUND);
136 mPlusTextLabel.SetProperty(Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE);
137 mPlusTextLabel.SetProperty(Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE);
138 mPlusTextLabel.SetProperty(Control::Property::PADDING, Extents(20.0f, 20.0f, 10.0f, 10.0f));
139 mPlusTextLabel.TouchedSignal().Connect(this, &ArcVisualExample::OnButtonTouch);
140 window.Add(mPlusTextLabel);
142 mMinusTextLabel = TextLabel::New("-");
143 mMinusTextLabel.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
144 mMinusTextLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_RIGHT);
145 mMinusTextLabel.SetProperty(Actor::Property::POSITION, Vector2(-20.0f, 10.0f));
146 mMinusTextLabel.SetProperty(Control::Property::BACKGROUND, TEXT_BACKGROUND);
147 mMinusTextLabel.SetProperty(Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE);
148 mMinusTextLabel.SetProperty(Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE);
149 mMinusTextLabel.SetProperty(Control::Property::PADDING, Extents(25.0f, 25.0f, 10.0f, 10.0f));
150 mMinusTextLabel.TouchedSignal().Connect(this, &ArcVisualExample::OnButtonTouch);
151 window.Add(mMinusTextLabel);
153 // Respond to a click anywhere on the window
154 window.GetRootLayer().TouchedSignal().Connect(this, &ArcVisualExample::OnTouch);
156 // Respond to key events
157 window.KeyEventSignal().Connect(this, &ArcVisualExample::OnKeyEvent);
160 bool OnButtonTouch(Actor actor, const TouchEvent& touch)
162 if(touch.GetState(0) == PointState::UP)
164 Control control = Control::DownCast(actor);
165 if(control == mStartAngleLabel)
167 mSelectedPoperty = DevelArcVisual::Property::START_ANGLE;
169 else if(control == mSweepAngleLabel)
171 mSelectedPoperty = DevelArcVisual::Property::SWEEP_ANGLE;
173 else if(control == mThicknessLabel)
175 mSelectedPoperty = DevelArcVisual::Property::THICKNESS;
177 else if(control == mPlusTextLabel)
179 Property::Map map = mControl.GetProperty<Property::Map>(Control::Property::BACKGROUND);
180 Property::Value* value = map.Find(mSelectedPoperty);
183 DevelControl::DoAction(mControl, Control::Property::BACKGROUND, DevelArcVisual::Action::UPDATE_PROPERTY, Property::Map().Add(mSelectedPoperty, value->Get<float>() + 5.0f));
188 Property::Map map = mControl.GetProperty<Property::Map>(Control::Property::BACKGROUND);
189 Property::Value* value = map.Find(mSelectedPoperty);
192 DevelControl::DoAction(mControl, Control::Property::BACKGROUND, DevelArcVisual::Action::UPDATE_PROPERTY, Property::Map().Add(mSelectedPoperty, value->Get<float>() - 5.0f));
199 bool OnTouch(Actor actor, const TouchEvent& touch)
201 if(touch.GetState(0) == PointState::UP)
203 Property::Array array;
204 array.PushBack(TRANSITION_START_ANGLE);
205 array.PushBack(TRANSITION_SWEEP_ANGLE);
207 TransitionData transitionData = TransitionData::New(array);
208 Animation animation = DevelControl::CreateTransition(Toolkit::Internal::GetImplementation(mControl), transitionData);
214 void OnKeyEvent(const KeyEvent& event)
216 if(event.GetState() == KeyEvent::UP)
218 if(IsKey(event, DALI_KEY_ESCAPE) || IsKey(event, DALI_KEY_BACK))
226 Application& mApplication;
228 TextLabel mStartAngleLabel;
229 TextLabel mSweepAngleLabel;
230 TextLabel mThicknessLabel;
231 TextLabel mPlusTextLabel;
232 TextLabel mMinusTextLabel;
233 Property::Index mSelectedPoperty;
236 int DALI_EXPORT_API main(int argc, char** argv)
238 Application application = Application::New(&argc, &argv);
239 ArcVisualExample test(application);
240 application.MainLoop();