2 * Copyright (c) 2017 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.
19 #include <shared/utility.h>
22 #include <dali/dali.h>
23 #include <dali-toolkit/dali-toolkit.h>
24 #include <dali/devel-api/actors/actor-devel.h>
28 using namespace Dali::Toolkit;
30 // This example shows the load-time image scaling and filtering features.
32 class MyTester : public ConnectionTracker
35 MyTester(Application &application) : mApplication(application)
37 // Connect to the Application's Init signal
38 mApplication.InitSignal().Connect(this, &MyTester::Create);
43 // Nothing to do here;
46 void ConnectEventSignal(Control control)
48 control.TouchSignal().Connect(this, &MyTester::OnControlTouch);
50 control.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
51 control.KeyEventSignal().Connect(this, &MyTester::OnControlKeyEvent);
52 control.KeyInputFocusGainedSignal().Connect(this, &MyTester::OnFocusSet);
53 control.KeyInputFocusLostSignal().Connect(this, &MyTester::OnFocusUnSet);
56 // The Init signal is received once (only) during the Application lifetime
57 void Create(Application &application)
59 stage = Stage::GetCurrent();
60 stage.SetBackgroundColor(Color::BLACK);
61 stage.KeyEventSignal().Connect(this, &MyTester::OnKey);
62 stage.TouchSignal().Connect(this, &MyTester::OnTouch);
64 TextLabel rubric = TextLabel::New( "You will need a working internet connection to see the images below");
65 rubric.SetProperty( TextLabel::Property::MULTI_LINE, true );
66 rubric.SetProperty( TextLabel::Property::TEXT_COLOR, Color::WHITE );
67 rubric.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
68 rubric.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
69 rubric.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER );
70 rubric.SetProperty( Actor::Property::ANCHOR_POINT, ParentOrigin::TOP_CENTER );
73 mImageView1 = Toolkit::ImageView::New("http://static.midomi.com/s/s/images/000/000/000/000/293/259/19/520_000000000000293259191500x1500_72dpi_RGB_q70.jpg");
75 mImageView1.SetProperty( Dali::Actor::Property::NAME,"mImageView1");
76 mImageView1.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT);
77 mImageView1.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_CENTER);
78 mImageView1.SetProperty(Actor::Property::POSITION_USES_ANCHOR_POINT, false);
79 mImageView1.SetProperty( Actor::Property::POSITION, Vector2(0, 100));
80 mImageView1.SetBackgroundColor(Vector4(0.0f, 0.0f, 0.0f, 0.0f));
81 stage.Add(mImageView1);
83 mImageView2 = Toolkit::ImageView::New("http://static.midomi.com/s/s/images/000/000/000/000/212/651/88/520_000000000000212651881500x1500_72dpi_RGB_q70.jpg");
84 mImageView2.SetProperty( Dali::Actor::Property::NAME,"mImageView2");
85 mImageView2.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT);
86 mImageView2.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_CENTER);
87 mImageView2.SetProperty(Actor::Property::POSITION_USES_ANCHOR_POINT, false);
88 mImageView2.SetProperty( Actor::Property::POSITION, Vector2(400, 100));
89 mImageView2.SetBackgroundColor(Vector4(0.0f, 0.0f, 0.0f, 0.0f));
90 stage.Add(mImageView2);
92 mImageView3 = Toolkit::ImageView::New("http://static.midomi.com/s/s/images/000/000/000/000/212/353/21/520_000000000000212353211500x1500_72dpi_RGB_q70.jpg");
93 mImageView3.SetProperty( Dali::Actor::Property::NAME,"mImageView3");
94 mImageView3.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT);
95 mImageView3.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_CENTER);
96 mImageView3.SetProperty(Actor::Property::POSITION_USES_ANCHOR_POINT, false);
97 mImageView3.SetProperty( Actor::Property::POSITION, Vector2(0, 400));
98 mImageView3.SetBackgroundColor(Vector4(0.0f, 0.0f, 0.0f, 0.0f));
99 stage.Add(mImageView3);
101 mImageView4 = Toolkit::ImageView::New("http://d2k43l0oslhof9.cloudfront.net/platform/image/contents/vc/20/01/58/20170629100630071189_0bf6b911-a847-cba4-e518-be40fe2f579420170629192203240.jpg");
102 mImageView4.SetProperty( Dali::Actor::Property::NAME,"mImageView4");
103 mImageView4.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT);
104 mImageView4.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_CENTER);
105 mImageView4.SetProperty(Actor::Property::POSITION_USES_ANCHOR_POINT, false);
106 mImageView4.SetProperty( Actor::Property::POSITION, Vector2(400, 400));
107 mImageView4.SetBackgroundColor(Vector4(0.0f, 0.0f, 0.0f, 0.0f));
108 stage.Add(mImageView4);
110 mImageView5 = Toolkit::ImageView::New("http://static.midomi.com/h/images/w/weather_sunny.png");
111 mImageView5.SetProperty( Dali::Actor::Property::NAME,"mImageView5");
112 mImageView4.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT);
113 mImageView5.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_CENTER);
114 mImageView5.SetProperty(Actor::Property::POSITION_USES_ANCHOR_POINT, false);
115 mImageView5.SetProperty( Actor::Property::POSITION, Vector2(800, 100));
116 mImageView5.SetBackgroundColor(Vector4(0.0f, 0.0f, 0.0f, 0.0f));
117 stage.Add(mImageView5);
119 // Tie-in input event handlers:
120 stage.KeyEventSignal().Connect( this, &MyTester::OnKeyEvent );
123 void OnAnimationEnd(Animation &source)
125 std::cout<<"OnAnimationEnd" << std::endl;
128 void OnKeyEvent(const KeyEvent& event)
130 if( event.state == KeyEvent::Down )
132 if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) )
139 void OnKey(const KeyEvent &event)
141 if (event.state == KeyEvent::Down)
143 std::cout<<"Stage key : " << event.keyCode << std::endl;
147 void OnTouch(const TouchData &touch)
149 if (touch.GetState(0) == PointState::DOWN)
151 std::cout<<"Stage touch" << std::endl;
155 bool OnControlKeyEvent(Toolkit::Control control, const KeyEvent &event)
157 if (event.state == KeyEvent::Down)
159 std::cout<<"Control down key : " << control.GetProperty< std::string >( Dali::Actor::Property::NAME ) << ", keyCode : " << event.keyCode << std::endl;
163 std::cout<<"Control up key : " << control.GetProperty< std::string >( Dali::Actor::Property::NAME ) << ", keyCode : " << event.keyCode << std::endl;
168 bool OnControlTouch(Actor actor, const TouchData &touch)
170 if (touch.GetState(0) == PointState::DOWN)
173 std::cout<<"Control touch " << actor.GetProperty< std::string >( Dali::Actor::Property::NAME ) << ", parent " << actor.GetParent().GetProperty< std::string >( Dali::Actor::Property::NAME ) << std::endl;
179 void OnFocusSet(Control control)
181 std::cout<<"OnFocusSet " << control.GetProperty< std::string >( Dali::Actor::Property::NAME ) << std::endl;
184 void OnFocusUnSet(Control control)
186 std::cout<<"OnFocusUnSet " << control.GetProperty< std::string >( Dali::Actor::Property::NAME ) << std::endl;
191 Application &mApplication;
195 ImageView mImageView1;
196 ImageView mImageView2;
197 ImageView mImageView3;
198 ImageView mImageView4;
199 ImageView mImageView5;
201 TextLabel mTextLabel1;
202 TextLabel mTextLabel2;
203 TextField mTextField;
204 TextEditor mTextEditor;
206 Animation mAnimation;
211 int DALI_EXPORT_API main(int argc, char **argv)
213 Application application = Application::New(&argc, &argv, "");
214 MyTester test(application);
215 application.MainLoop();