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/dali.h>
20 #include <dali/devel-api/actors/actor-devel.h>
21 #include <shared/utility.h>
26 using namespace Dali::Toolkit;
28 // This example shows the load-time image scaling and filtering features.
30 class MyTester : public ConnectionTracker
33 MyTester(Application& application)
34 : mApplication(application)
36 // Connect to the Application's Init signal
37 mApplication.InitSignal().Connect(this, &MyTester::Create);
42 // Nothing to do here;
45 void ConnectEventSignal(Control control)
47 control.TouchedSignal().Connect(this, &MyTester::OnControlTouch);
49 control.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
50 control.KeyEventSignal().Connect(this, &MyTester::OnControlKeyEvent);
51 control.KeyInputFocusGainedSignal().Connect(this, &MyTester::OnFocusSet);
52 control.KeyInputFocusLostSignal().Connect(this, &MyTester::OnFocusUnSet);
55 // The Init signal is received once (only) during the Application lifetime
56 void Create(Application& application)
58 mWindow = application.GetWindow();
59 mWindow.SetBackgroundColor(Color::BLACK);
60 mWindow.KeyEventSignal().Connect(this, &MyTester::OnKey);
61 mWindow.TouchedSignal().Connect(this, &MyTester::OnTouch);
63 TextLabel rubric = TextLabel::New("You will need a working internet connection to see the images below");
64 rubric.SetProperty(TextLabel::Property::MULTI_LINE, true);
65 rubric.SetProperty(TextLabel::Property::TEXT_COLOR, Color::WHITE);
66 rubric.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
67 rubric.SetResizePolicy(ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT);
68 rubric.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER);
69 rubric.SetProperty(Actor::Property::ANCHOR_POINT, ParentOrigin::TOP_CENTER);
72 mImageView1 = Toolkit::ImageView::New("http://static.midomi.com/s/s/images/000/000/000/000/293/259/19/520_000000000000293259191500x1500_72dpi_RGB_q70.jpg");
74 mImageView1.SetProperty(Dali::Actor::Property::NAME, "mImageView1");
75 mImageView1.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
76 mImageView1.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER);
77 mImageView1.SetProperty(Actor::Property::POSITION_USES_ANCHOR_POINT, false);
78 mImageView1.SetProperty(Actor::Property::POSITION, Vector2(0, 100));
79 mImageView1.SetBackgroundColor(Vector4(0.0f, 0.0f, 0.0f, 0.0f));
80 mWindow.Add(mImageView1);
82 mImageView2 = Toolkit::ImageView::New("http://static.midomi.com/s/s/images/000/000/000/000/212/651/88/520_000000000000212651881500x1500_72dpi_RGB_q70.jpg");
83 mImageView2.SetProperty(Dali::Actor::Property::NAME, "mImageView2");
84 mImageView2.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
85 mImageView2.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER);
86 mImageView2.SetProperty(Actor::Property::POSITION_USES_ANCHOR_POINT, false);
87 mImageView2.SetProperty(Actor::Property::POSITION, Vector2(400, 100));
88 mImageView2.SetBackgroundColor(Vector4(0.0f, 0.0f, 0.0f, 0.0f));
89 mWindow.Add(mImageView2);
91 mImageView3 = Toolkit::ImageView::New("http://static.midomi.com/s/s/images/000/000/000/000/212/353/21/520_000000000000212353211500x1500_72dpi_RGB_q70.jpg");
92 mImageView3.SetProperty(Dali::Actor::Property::NAME, "mImageView3");
93 mImageView3.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
94 mImageView3.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER);
95 mImageView3.SetProperty(Actor::Property::POSITION_USES_ANCHOR_POINT, false);
96 mImageView3.SetProperty(Actor::Property::POSITION, Vector2(0, 400));
97 mImageView3.SetBackgroundColor(Vector4(0.0f, 0.0f, 0.0f, 0.0f));
98 mWindow.Add(mImageView3);
100 mImageView4 = Toolkit::ImageView::New("http://d2k43l0oslhof9.cloudfront.net/platform/image/contents/vc/20/01/58/20170629100630071189_0bf6b911-a847-cba4-e518-be40fe2f579420170629192203240.jpg");
101 mImageView4.SetProperty(Dali::Actor::Property::NAME, "mImageView4");
102 mImageView4.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
103 mImageView4.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER);
104 mImageView4.SetProperty(Actor::Property::POSITION_USES_ANCHOR_POINT, false);
105 mImageView4.SetProperty(Actor::Property::POSITION, Vector2(400, 400));
106 mImageView4.SetBackgroundColor(Vector4(0.0f, 0.0f, 0.0f, 0.0f));
107 mWindow.Add(mImageView4);
109 mImageView5 = Toolkit::ImageView::New("http://static.midomi.com/h/images/w/weather_sunny.png");
110 mImageView5.SetProperty(Dali::Actor::Property::NAME, "mImageView5");
111 mImageView4.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
112 mImageView5.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER);
113 mImageView5.SetProperty(Actor::Property::POSITION_USES_ANCHOR_POINT, false);
114 mImageView5.SetProperty(Actor::Property::POSITION, Vector2(800, 100));
115 mImageView5.SetBackgroundColor(Vector4(0.0f, 0.0f, 0.0f, 0.0f));
116 mWindow.Add(mImageView5);
118 // Tie-in input event handlers:
119 mWindow.KeyEventSignal().Connect(this, &MyTester::OnKeyEvent);
122 void OnAnimationEnd(Animation& source)
124 std::cout << "OnAnimationEnd" << std::endl;
127 void OnKeyEvent(const KeyEvent& event)
129 if(event.GetState() == KeyEvent::DOWN)
131 if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK))
138 void OnKey(const KeyEvent& event)
140 if(event.GetState() == KeyEvent::DOWN)
142 std::cout << "Window key : " << event.GetKeyCode() << std::endl;
146 void OnTouch(const TouchEvent& touch)
148 if(touch.GetState(0) == PointState::DOWN)
150 std::cout << "Window touch" << std::endl;
154 bool OnControlKeyEvent(Toolkit::Control control, const KeyEvent& event)
156 if(event.GetState() == KeyEvent::DOWN)
158 std::cout << "Control down key : " << control.GetProperty<std::string>(Dali::Actor::Property::NAME) << ", keyCode : " << event.GetKeyCode() << std::endl;
162 std::cout << "Control up key : " << control.GetProperty<std::string>(Dali::Actor::Property::NAME) << ", keyCode : " << event.GetKeyCode() << std::endl;
167 bool OnControlTouch(Actor actor, const TouchEvent& touch)
169 if(touch.GetState(0) == PointState::DOWN)
171 std::cout << "Control touch " << actor.GetProperty<std::string>(Dali::Actor::Property::NAME) << ", parent " << actor.GetParent().GetProperty<std::string>(Dali::Actor::Property::NAME) << std::endl;
177 void OnFocusSet(Control control)
179 std::cout << "OnFocusSet " << control.GetProperty<std::string>(Dali::Actor::Property::NAME) << std::endl;
182 void OnFocusUnSet(Control control)
184 std::cout << "OnFocusUnSet " << control.GetProperty<std::string>(Dali::Actor::Property::NAME) << std::endl;
189 Application& mApplication;
193 ImageView mImageView1;
194 ImageView mImageView2;
195 ImageView mImageView3;
196 ImageView mImageView4;
197 ImageView mImageView5;
199 TextLabel mTextLabel1;
200 TextLabel mTextLabel2;
201 TextField mTextField;
202 TextEditor mTextEditor;
204 Animation mAnimation;
208 int DALI_EXPORT_API main(int argc, char** argv)
210 Application application = Application::New(&argc, &argv, "");
211 MyTester test(application);
212 application.MainLoop();