[dali_1.9.13] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / public-api / actors / actor.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/public-api/actors/actor.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/actors/layer.h>
23 #include <dali/public-api/animation/constraint.h>
24 #include <dali/public-api/common/dali-common.h>
25 #include <dali/public-api/math/radian.h>
26 #include <dali/public-api/math/vector2.h>
27
28 #include <dali/internal/event/actors/actor-impl.h>
29 #include <dali/internal/event/actors/layer-impl.h>
30 #include <dali/internal/event/rendering/renderer-impl.h>
31 #include <dali/internal/event/animation/constraint-impl.h>
32 #include <dali/internal/event/size-negotiation/relayout-controller-impl.h>
33
34 namespace Dali
35 {
36
37 Actor::Actor()
38 {
39 }
40
41 Actor Actor::New()
42 {
43   Internal::ActorPtr internal = Internal::Actor::New();
44
45   return Actor(internal.Get());
46 }
47
48 Actor Actor::DownCast( BaseHandle handle )
49 {
50   return Actor( dynamic_cast<Dali::Internal::Actor*>(handle.GetObjectPtr()) );
51 }
52
53 Actor::~Actor()
54 {
55 }
56
57 Actor::Actor(const Actor& copy)
58 : Handle(copy)
59 {
60 }
61
62 Actor& Actor::operator=(const Actor& rhs)
63 {
64   BaseHandle::operator=(rhs);
65   return *this;
66 }
67
68 uint32_t Actor::GetId() const
69 {
70   return GetImplementation(*this).GetId();
71 }
72
73 bool Actor::IsRoot() const
74 {
75   return GetImplementation(*this).IsRoot();
76 }
77
78 bool Actor::OnStage() const
79 {
80   return GetImplementation(*this).OnStage();
81 }
82
83 bool Actor::IsLayer() const
84 {
85   return GetImplementation(*this).IsLayer();
86 }
87
88 Layer Actor::GetLayer()
89 {
90   return GetImplementation(*this).GetLayer();
91 }
92
93 void Actor::Add(Actor actor)
94 {
95   GetImplementation(*this).Add(GetImplementation(actor));
96 }
97
98 void Actor::Remove(Actor actor)
99 {
100   GetImplementation(*this).Remove(GetImplementation(actor));
101 }
102
103 void Actor::Unparent()
104 {
105   GetImplementation(*this).Unparent();
106 }
107
108 uint32_t Actor::GetChildCount() const
109 {
110   return GetImplementation(*this).GetChildCount();
111 }
112
113 Actor Actor::GetChildAt( uint32_t index ) const
114 {
115   Internal::ActorPtr child = GetImplementation(*this).GetChildAt( index );
116   return Actor( child.Get() );
117 }
118
119 Actor Actor::FindChildByName(const std::string& actorName)
120 {
121   Internal::ActorPtr child = GetImplementation(*this).FindChildByName( actorName );
122   return Actor( child.Get() );
123 }
124
125 Actor Actor::FindChildById( const uint32_t id )
126 {
127   Internal::ActorPtr child = GetImplementation(*this).FindChildById( id );
128   return Actor( child.Get() );
129 }
130
131 Actor Actor::GetParent() const
132 {
133   Internal::Actor* parent = GetImplementation(*this).GetParent();
134
135   return Actor(parent);
136 }
137
138 void Actor::SetSize(float width, float height)
139 {
140   GetImplementation(*this).SetSize(width, height);
141 }
142
143 void Actor::SetSize(float width, float height, float depth)
144 {
145   GetImplementation(*this).SetSize(width, height, depth);
146 }
147
148 void Actor::SetSize(const Vector2& size)
149 {
150   GetImplementation(*this).SetSize( size );
151 }
152
153 void Actor::SetSize(const Vector3& size)
154 {
155   GetImplementation(*this).SetSize( size );
156 }
157
158 Vector3 Actor::GetTargetSize() const
159 {
160   return GetImplementation(*this).GetTargetSize();
161 }
162
163 Vector3 Actor::GetNaturalSize() const
164 {
165   return GetImplementation(*this).GetNaturalSize();
166 }
167
168 void Actor::SetPosition(float x, float y)
169 {
170   GetImplementation(*this).SetPosition(x, y);
171 }
172
173 void Actor::SetPosition(float x, float y, float z)
174 {
175   GetImplementation(*this).SetPosition(x, y, z);
176 }
177
178 void Actor::SetPosition(const Vector3& position)
179 {
180   GetImplementation(*this).SetPosition(position);
181 }
182
183 void Actor::SetX(float x)
184 {
185   GetImplementation(*this).SetX(x);
186 }
187
188 void Actor::SetY(float y)
189 {
190   GetImplementation(*this).SetY(y);
191 }
192
193 void Actor::SetZ(float z)
194 {
195   GetImplementation(*this).SetZ(z);
196 }
197
198 void Actor::TranslateBy(const Vector3& distance)
199 {
200   GetImplementation(*this).TranslateBy(distance);
201 }
202
203 void Actor::SetOrientation(const Radian& angle, const Vector3& axis)
204 {
205   GetImplementation(*this).SetOrientation(angle, axis);
206 }
207
208 void Actor::SetOrientation(const Quaternion& orientation)
209 {
210   GetImplementation(*this).SetOrientation(orientation);
211 }
212
213 void Actor::RotateBy(const Radian& angle, const Vector3& axis)
214 {
215   GetImplementation(*this).RotateBy(angle, axis);
216 }
217
218 void Actor::RotateBy(const Quaternion& relativeRotation)
219 {
220   GetImplementation(*this).RotateBy(relativeRotation);
221 }
222
223 void Actor::SetScale(float scale)
224 {
225   GetImplementation(*this).SetScale(scale);
226 }
227
228 void Actor::SetScale(float scaleX, float scaleY, float scaleZ)
229 {
230   GetImplementation(*this).SetScale(scaleX, scaleY, scaleZ);
231 }
232
233 void Actor::SetScale(const Vector3& scale)
234 {
235   GetImplementation(*this).SetScale(scale);
236 }
237
238 void Actor::ScaleBy(const Vector3& relativeScale)
239 {
240   GetImplementation(*this).ScaleBy(relativeScale);
241 }
242
243 void Actor::SetSizeModeFactor(const Vector3& factor)
244 {
245   GetImplementation(*this).SetSizeModeFactor(factor);
246 }
247
248 Vector3 Actor::GetSizeModeFactor() const
249 {
250   return GetImplementation(*this).GetSizeModeFactor();
251 }
252
253 void Actor::SetColorMode( ColorMode colorMode )
254 {
255   GetImplementation(*this).SetColorMode(colorMode);
256 }
257
258 ColorMode Actor::GetColorMode() const
259 {
260   return GetImplementation(*this).GetColorMode();
261 }
262
263 void Actor::SetDrawMode( DrawMode::Type drawMode )
264 {
265   GetImplementation(*this).SetDrawMode( drawMode );
266 }
267
268 DrawMode::Type Actor::GetDrawMode() const
269 {
270   return GetImplementation(*this).GetDrawMode();
271 }
272
273 bool Actor::ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const
274 {
275   return GetImplementation(*this).ScreenToLocal(localX, localY, screenX, screenY);
276 }
277
278 void Actor::SetKeyboardFocusable( bool focusable )
279 {
280   GetImplementation(*this).SetKeyboardFocusable(focusable);
281 }
282
283 bool Actor::IsKeyboardFocusable() const
284 {
285   return GetImplementation(*this).IsKeyboardFocusable();
286 }
287
288 void Actor::Raise()
289 {
290   GetImplementation( *this ).Raise();
291 }
292
293 void Actor::Lower()
294 {
295   GetImplementation( *this ).Lower();
296 }
297
298 void Actor::RaiseToTop()
299 {
300   GetImplementation( *this ).RaiseToTop();
301 }
302
303 void Actor::LowerToBottom()
304 {
305   GetImplementation( *this ).LowerToBottom();
306 }
307
308 void Actor::RaiseAbove( Actor target )
309 {
310   GetImplementation( *this ).RaiseAbove( GetImplementation( target ) );
311 }
312
313 void Actor::LowerBelow( Actor target )
314 {
315   GetImplementation( *this ).LowerBelow( GetImplementation( target ) );
316 }
317
318 void Actor::SetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
319 {
320   GetImplementation(*this).SetResizePolicy( policy, dimension );
321 }
322
323 ResizePolicy::Type Actor::GetResizePolicy( Dimension::Type dimension ) const
324 {
325   return GetImplementation(*this).GetResizePolicy( dimension );
326 }
327
328 void Actor::SetSizeScalePolicy( SizeScalePolicy::Type policy )
329 {
330   GetImplementation(*this).SetSizeScalePolicy( policy );
331 }
332
333 SizeScalePolicy::Type Actor::GetSizeScalePolicy() const
334 {
335   return GetImplementation(*this).GetSizeScalePolicy();
336 }
337
338 float Actor::GetHeightForWidth( float width )
339 {
340   return GetImplementation(*this).GetHeightForWidth( width );
341 }
342
343 float Actor::GetWidthForHeight( float height )
344 {
345   return GetImplementation(*this).GetWidthForHeight( height );
346 }
347
348 float Actor::GetRelayoutSize( Dimension::Type dimension ) const
349 {
350   return GetImplementation(*this).GetRelayoutSize( dimension );
351 }
352
353 void Actor::SetPadding( const Padding& padding )
354 {
355   Internal::Actor& impl = GetImplementation(*this);
356
357   Vector2 widthPadding( padding.left, padding.right );
358   impl.SetPadding( widthPadding, Dimension::WIDTH );
359
360   Vector2 heightPadding( padding.bottom, padding.top );
361   impl.SetPadding( heightPadding, Dimension::HEIGHT );
362 }
363
364 void Actor::GetPadding( Padding& paddingOut ) const
365 {
366   const Internal::Actor& impl = GetImplementation(*this);
367
368   Vector2 widthPadding = impl.GetPadding( Dimension::WIDTH );
369   Vector2 heightPadding = impl.GetPadding( Dimension::HEIGHT );
370
371   paddingOut.left = widthPadding.x;
372   paddingOut.right = widthPadding.y;
373   paddingOut.bottom = heightPadding.x;
374   paddingOut.top = heightPadding.y;
375 }
376
377 int32_t Actor::GetHierarchyDepth()
378 {
379   return GetImplementation(*this).GetHierarchyDepth();
380 }
381
382 Actor::TouchSignalType& Actor::TouchedSignal()
383 {
384   DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: TouchedSignal() is deprecated and will be removed from next release. Use TouchSignal() instead.\n" );
385
386   return GetImplementation(*this).TouchedSignal();
387 }
388
389 Actor::TouchDataSignalType& Actor::TouchSignal()
390 {
391   return GetImplementation( *this ).TouchSignal();
392 }
393
394 Actor::HoverSignalType& Actor::HoveredSignal()
395 {
396   return GetImplementation(*this).HoveredSignal();
397 }
398
399 Actor::WheelEventSignalType& Actor::WheelEventSignal()
400 {
401   return GetImplementation(*this).WheelEventSignal();
402 }
403
404 Actor::OnStageSignalType& Actor::OnStageSignal()
405 {
406   return GetImplementation(*this).OnStageSignal();
407 }
408
409 Actor::OffStageSignalType& Actor::OffStageSignal()
410 {
411   return GetImplementation(*this).OffStageSignal();
412 }
413
414 uint32_t Actor::AddRenderer( Renderer& renderer )
415 {
416   return GetImplementation(*this).AddRenderer( GetImplementation( renderer ) );
417 }
418
419 uint32_t Actor::GetRendererCount() const
420 {
421   return GetImplementation(*this).GetRendererCount();
422 }
423
424 Renderer Actor::GetRendererAt( uint32_t index )
425 {
426   Internal::RendererPtr renderer = GetImplementation(*this).GetRendererAt( index );
427   return Renderer( renderer.Get() );
428 }
429
430 void Actor::RemoveRenderer( Renderer& renderer )
431 {
432   GetImplementation(*this).RemoveRenderer( GetImplementation( renderer ) );
433 }
434
435 void Actor::RemoveRenderer( uint32_t index )
436 {
437   GetImplementation(*this).RemoveRenderer( index );
438 }
439
440 Actor::OnRelayoutSignalType& Actor::OnRelayoutSignal()
441 {
442   return GetImplementation(*this).OnRelayoutSignal();
443 }
444
445 Actor::LayoutDirectionChangedSignalType& Actor::LayoutDirectionChangedSignal()
446 {
447   return GetImplementation( *this ).LayoutDirectionChangedSignal();
448 }
449
450 Actor::Actor(Internal::Actor* internal)
451 : Handle(internal)
452 {
453 }
454
455 } // namespace Dali