Merge "Remove unused FindActorByAlias" into tizen
[platform/core/uifw/dali-core.git] / dali / public-api / actors / actor.cpp
1 /*
2  * Copyright (c) 2014 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/degree.h>
26 #include <dali/public-api/math/radian.h>
27 #include <dali/public-api/math/vector2.h>
28
29 #include <dali/internal/event/actors/actor-impl.h>
30 #include <dali/internal/event/actors/layer-impl.h>
31 #include <dali/internal/event/actor-attachments/actor-attachment-impl.h>
32 #include <dali/internal/event/animation/constraint-impl.h>
33
34 #include <dali/public-api/dynamics/dynamics-body.h>
35 #include <dali/public-api/dynamics/dynamics-joint.h>
36 #include <dali/public-api/dynamics/dynamics-body-config.h>
37
38 #ifdef DYNAMICS_SUPPORT
39 #include <dali/internal/event/dynamics/dynamics-declarations.h>
40 #include <dali/internal/event/dynamics/dynamics-body-config-impl.h>
41 #include <dali/internal/event/dynamics/dynamics-body-impl.h>
42 #include <dali/internal/event/dynamics/dynamics-joint-impl.h>
43 #include <dali/internal/event/dynamics/dynamics-world-impl.h>
44 #endif
45
46 namespace Dali
47 {
48
49 Actor::Actor()
50 {
51 }
52
53 Actor Actor::New()
54 {
55   Internal::ActorPtr internal = Internal::Actor::New();
56
57   return Actor(internal.Get());
58 }
59
60 Actor Actor::DownCast( BaseHandle handle )
61 {
62   return Actor( dynamic_cast<Dali::Internal::Actor*>(handle.GetObjectPtr()) );
63 }
64
65 Actor::~Actor()
66 {
67 }
68
69 Actor::Actor(const Actor& copy)
70 : Handle(copy)
71 {
72 }
73
74 Actor& Actor::operator=(const Actor& rhs)
75 {
76   BaseHandle::operator=(rhs);
77   return *this;
78 }
79
80 const std::string& Actor::GetName() const
81 {
82   return GetImplementation(*this).GetName();
83 }
84
85 void Actor::SetName(const std::string& name)
86 {
87   GetImplementation(*this).SetName(name);
88 }
89
90 unsigned int Actor::GetId() const
91 {
92   return GetImplementation(*this).GetId();
93 }
94
95 bool Actor::IsRoot() const
96 {
97   return GetImplementation(*this).IsRoot();
98 }
99
100 bool Actor::OnStage() const
101 {
102   return GetImplementation(*this).OnStage();
103 }
104
105 bool Actor::IsLayer() const
106 {
107   return GetImplementation(*this).IsLayer();
108 }
109
110 Layer Actor::GetLayer()
111 {
112   return GetImplementation(*this).GetLayer();
113 }
114
115 void Actor::Add(Actor actor)
116 {
117   GetImplementation(*this).Add(GetImplementation(actor));
118 }
119
120 void Actor::Insert(unsigned int index, Actor actor)
121 {
122   GetImplementation(*this).Insert(index, GetImplementation(actor));
123 }
124
125 void Actor::Remove(Actor actor)
126 {
127   GetImplementation(*this).Remove(GetImplementation(actor));
128 }
129
130 void Actor::Unparent()
131 {
132   GetImplementation(*this).Unparent();
133 }
134
135 unsigned int Actor::GetChildCount() const
136 {
137   return GetImplementation(*this).GetChildCount();
138 }
139
140 Actor Actor::GetChildAt(unsigned int index) const
141 {
142   return GetImplementation(*this).GetChildAt(index);
143 }
144
145 Actor Actor::FindChildByName(const std::string& actorName)
146 {
147   Internal::ActorPtr child = GetImplementation(*this).FindChildByName(actorName);
148   return Actor(child.Get());
149 }
150
151 Actor Actor::FindChildById(const unsigned int id)
152 {
153   Internal::ActorPtr child = GetImplementation(*this).FindChildById(id);
154   return Actor(child.Get());
155 }
156
157 Actor Actor::GetParent() const
158 {
159   Internal::Actor* parent = GetImplementation(*this).GetParent();
160
161   return Actor(parent);
162 }
163
164 void Actor::SetParentOrigin(const Vector3& origin)
165 {
166   GetImplementation(*this).SetParentOrigin(origin);
167 }
168
169 Vector3 Actor::GetCurrentParentOrigin() const
170 {
171   return GetImplementation(*this).GetCurrentParentOrigin();
172 }
173
174 void Actor::SetAnchorPoint(const Vector3& anchorPoint)
175 {
176   GetImplementation(*this).SetAnchorPoint(anchorPoint);
177 }
178
179 Vector3 Actor::GetCurrentAnchorPoint() const
180 {
181   return GetImplementation(*this).GetCurrentAnchorPoint();
182 }
183
184 void Actor::SetSize(float width, float height)
185 {
186   GetImplementation(*this).SetSize(width, height);
187 }
188
189 void Actor::SetSize(float width, float height, float depth)
190 {
191   GetImplementation(*this).SetSize(width, height, depth);
192 }
193
194 void Actor::SetSize(const Vector2& size)
195 {
196   GetImplementation(*this).SetSize(size);
197 }
198
199 void Actor::SetSize(const Vector3& size)
200 {
201   GetImplementation(*this).SetSize(size);
202 }
203
204 Vector3 Actor::GetSize() const
205 {
206   return GetImplementation(*this).GetSize();
207 }
208
209 Vector3 Actor::GetCurrentSize() const
210 {
211   return GetImplementation(*this).GetCurrentSize();
212 }
213
214 Vector3 Actor::GetNaturalSize() const
215 {
216   return GetImplementation(*this).GetNaturalSize();
217 }
218
219 void Actor::SetPosition(float x, float y)
220 {
221   GetImplementation(*this).SetPosition(x, y);
222 }
223
224 void Actor::SetPosition(float x, float y, float z)
225 {
226   GetImplementation(*this).SetPosition(x, y, z);
227 }
228
229 void Actor::SetPosition(const Vector3& position)
230 {
231   GetImplementation(*this).SetPosition(position);
232 }
233
234 void Actor::SetX(float x)
235 {
236   GetImplementation(*this).SetX(x);
237 }
238
239 void Actor::SetY(float y)
240 {
241   GetImplementation(*this).SetY(y);
242 }
243
244 void Actor::SetZ(float z)
245 {
246   GetImplementation(*this).SetZ(z);
247 }
248
249 void Actor::MoveBy(const Vector3& distance)
250 {
251   GetImplementation(*this).MoveBy(distance);
252 }
253
254 Vector3 Actor::GetCurrentPosition() const
255 {
256   return GetImplementation(*this).GetCurrentPosition();
257 }
258
259 Vector3 Actor::GetCurrentWorldPosition() const
260 {
261   return GetImplementation(*this).GetCurrentWorldPosition();
262 }
263
264 void Actor::SetPositionInheritanceMode( PositionInheritanceMode mode )
265 {
266   GetImplementation(*this).SetPositionInheritanceMode( mode );
267 }
268
269 PositionInheritanceMode Actor::GetPositionInheritanceMode() const
270 {
271   return GetImplementation(*this).GetPositionInheritanceMode();
272 }
273
274 void Actor::SetRotation(const Degree& angle, const Vector3& axis)
275 {
276   GetImplementation(*this).SetRotation(Radian(angle), axis);
277 }
278
279 void Actor::SetRotation(const Radian& angle, const Vector3& axis)
280 {
281   GetImplementation(*this).SetRotation(angle, axis);
282 }
283
284 void Actor::SetRotation(const Quaternion& rotation)
285 {
286   GetImplementation(*this).SetRotation(rotation);
287 }
288
289 void Actor::RotateBy(const Degree& angle, const Vector3& axis)
290 {
291   GetImplementation(*this).RotateBy(Radian(angle), axis);
292 }
293
294 void Actor::RotateBy(const Radian& angle, const Vector3& axis)
295 {
296   GetImplementation(*this).RotateBy(angle, axis);
297 }
298
299 void Actor::RotateBy(const Quaternion& relativeRotation)
300 {
301   GetImplementation(*this).RotateBy(relativeRotation);
302 }
303
304 Quaternion Actor::GetCurrentRotation() const
305 {
306   return GetImplementation(*this).GetCurrentRotation();
307 }
308
309 void Actor::SetInheritRotation(bool inherit)
310 {
311   GetImplementation(*this).SetInheritRotation(inherit);
312 }
313
314 bool Actor::IsRotationInherited() const
315 {
316   return GetImplementation(*this).IsRotationInherited();
317 }
318
319 Quaternion Actor::GetCurrentWorldRotation() const
320 {
321   return GetImplementation(*this).GetCurrentWorldRotation();
322 }
323
324 void Actor::SetScale(float scale)
325 {
326   GetImplementation(*this).SetScale(scale);
327 }
328
329 void Actor::SetScale(float scaleX, float scaleY, float scaleZ)
330 {
331   GetImplementation(*this).SetScale(scaleX, scaleY, scaleZ);
332 }
333
334 void Actor::SetScale(const Vector3& scale)
335 {
336   GetImplementation(*this).SetScale(scale);
337 }
338
339 void Actor::ScaleBy(const Vector3& relativeScale)
340 {
341   GetImplementation(*this).ScaleBy(relativeScale);
342 }
343
344 Vector3 Actor::GetCurrentScale() const
345 {
346   return GetImplementation(*this).GetCurrentScale();
347 }
348
349 Vector3 Actor::GetCurrentWorldScale() const
350 {
351   return GetImplementation(*this).GetCurrentWorldScale();
352 }
353
354 void Actor::SetInheritScale( bool inherit )
355 {
356   GetImplementation(*this).SetInheritScale( inherit );
357 }
358
359 bool Actor::IsScaleInherited() const
360 {
361   return GetImplementation(*this).IsScaleInherited();
362 }
363
364 void Actor::SetSizeMode(SizeMode mode)
365 {
366   GetImplementation(*this).SetSizeMode(mode);
367 }
368
369 SizeMode Actor::GetSizeMode() const
370 {
371   return GetImplementation(*this).GetSizeMode();
372 }
373
374 void Actor::SetSizeModeFactor(const Vector3& factor)
375 {
376   GetImplementation(*this).SetSizeModeFactor(factor);
377 }
378
379 Vector3 Actor::GetSizeModeFactor() const
380 {
381   return GetImplementation(*this).GetSizeModeFactor();
382 }
383
384 Matrix Actor::GetCurrentWorldMatrix() const
385 {
386   return GetImplementation(*this).GetCurrentWorldMatrix();
387 }
388
389 void Actor::SetVisible(bool visible)
390 {
391   GetImplementation(*this).SetVisible(visible);
392 }
393
394 bool Actor::IsVisible() const
395 {
396   return GetImplementation(*this).IsVisible();
397 }
398
399 void Actor::SetOpacity(float opacity)
400 {
401   GetImplementation(*this).SetOpacity(opacity);
402 }
403
404 void Actor::OpacityBy(float relativeOpacity)
405 {
406   GetImplementation(*this).OpacityBy(relativeOpacity);
407 }
408
409 float Actor::GetCurrentOpacity() const
410 {
411   return GetImplementation(*this).GetCurrentOpacity();
412 }
413
414 void Actor::SetColor(const Vector4& color)
415 {
416   GetImplementation(*this).SetColor(color);
417 }
418
419 void Actor::ColorBy(const Vector4& relativeColor)
420 {
421   GetImplementation(*this).ColorBy(relativeColor);
422 }
423
424 Vector4 Actor::GetCurrentColor() const
425 {
426   return GetImplementation(*this).GetCurrentColor();
427 }
428
429 void Actor::SetColorMode( ColorMode colorMode )
430 {
431   GetImplementation(*this).SetColorMode(colorMode);
432 }
433
434 ColorMode Actor::GetColorMode() const
435 {
436   return GetImplementation(*this).GetColorMode();
437 }
438
439 Vector4 Actor::GetCurrentWorldColor() const
440 {
441   return GetImplementation(*this).GetCurrentWorldColor();
442 }
443
444 void Actor::SetDrawMode( DrawMode::Type drawMode )
445 {
446   GetImplementation(*this).SetDrawMode( drawMode );
447 }
448
449 DrawMode::Type Actor::GetDrawMode() const
450 {
451   return GetImplementation(*this).GetDrawMode();
452 }
453
454 void Actor::SetSensitive(bool sensitive)
455 {
456   GetImplementation(*this).SetSensitive(sensitive);
457 }
458
459 bool Actor::IsSensitive() const
460 {
461   return GetImplementation(*this).IsSensitive();
462 }
463
464 bool Actor::ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const
465 {
466   return GetImplementation(*this).ScreenToLocal(localX, localY, screenX, screenY);
467 }
468
469 void Actor::SetLeaveRequired(bool required)
470 {
471   GetImplementation(*this).SetLeaveRequired(required);
472 }
473
474 bool Actor::GetLeaveRequired() const
475 {
476   return GetImplementation(*this).GetLeaveRequired();
477 }
478
479 void Actor::SetKeyboardFocusable( bool focusable )
480 {
481   GetImplementation(*this).SetKeyboardFocusable(focusable);
482 }
483
484 bool Actor::IsKeyboardFocusable() const
485 {
486   return GetImplementation(*this).IsKeyboardFocusable();
487 }
488
489 Actor::TouchSignalType& Actor::TouchedSignal()
490 {
491   return GetImplementation(*this).TouchedSignal();
492 }
493
494 Actor::HoverSignalType& Actor::HoveredSignal()
495 {
496   return GetImplementation(*this).HoveredSignal();
497 }
498
499 Actor::MouseWheelEventSignalType& Actor::MouseWheelEventSignal()
500 {
501   return GetImplementation(*this).MouseWheelEventSignal();
502 }
503
504 Actor::OnStageSignalType& Actor::OnStageSignal()
505 {
506   return GetImplementation(*this).OnStageSignal();
507 }
508
509 Actor::OffStageSignalType& Actor::OffStageSignal()
510 {
511   return GetImplementation(*this).OffStageSignal();
512 }
513
514 DynamicsBody Actor::EnableDynamics(DynamicsBodyConfig bodyConfig)
515 {
516 #ifdef DYNAMICS_SUPPORT
517   Internal::DynamicsBodyConfig& internal = GetImplementation(bodyConfig);
518
519   Internal::DynamicsBodyPtr body( GetImplementation(*this).EnableDynamics( &internal ) );
520
521   return DynamicsBody( body.Get() );
522 #else
523   return DynamicsBody();
524 #endif
525 }
526
527 DynamicsJoint Actor::AddDynamicsJoint( Actor attachedActor, const Vector3& offset )
528 {
529 #ifdef DYNAMICS_SUPPORT
530   Internal::ActorPtr internalActor( &GetImplementation(attachedActor) );
531   Internal::DynamicsJointPtr joint( GetImplementation(*this).AddDynamicsJoint( internalActor, offset) );
532
533   return DynamicsJoint( joint.Get() );
534 #else
535   return DynamicsJoint();
536 #endif
537 }
538
539 DynamicsJoint Actor::AddDynamicsJoint( Actor attachedActor, const Vector3& offsetA, const Vector3& offsetB )
540 {
541 #ifdef DYNAMICS_SUPPORT
542   Internal::ActorPtr internalActor( &GetImplementation(attachedActor) );
543   Internal::DynamicsJointPtr joint( GetImplementation(*this).AddDynamicsJoint( internalActor, offsetA, offsetB) );
544
545   return DynamicsJoint( joint.Get() );
546 #else
547   return DynamicsJoint();
548 #endif
549 }
550
551 int Actor::GetNumberOfJoints() const
552 {
553 #ifdef DYNAMICS_SUPPORT
554   return GetImplementation(*this).GetNumberOfJoints();
555 #else
556   return int();
557 #endif
558 }
559
560 DynamicsJoint Actor::GetDynamicsJointByIndex( const int index )
561 {
562 #ifdef DYNAMICS_SUPPORT
563   Internal::DynamicsJointPtr joint( GetImplementation(*this).GetDynamicsJointByIndex( index ) );
564
565   return DynamicsJoint( joint.Get() );
566 #else
567   return DynamicsJoint();
568 #endif
569 }
570
571 DynamicsJoint Actor::GetDynamicsJoint( Actor attachedActor )
572 {
573 #ifdef DYNAMICS_SUPPORT
574   Internal::DynamicsJointPtr joint( GetImplementation(*this).GetDynamicsJoint( &GetImplementation(attachedActor) ) );
575
576   return DynamicsJoint( joint.Get() );
577 #else
578   return DynamicsJoint();
579 #endif
580 }
581
582 void Actor::RemoveDynamicsJoint( DynamicsJoint joint )
583 {
584 #ifdef DYNAMICS_SUPPORT
585   GetImplementation(*this).RemoveDynamicsJoint( &GetImplementation(joint) );
586 #endif
587 }
588
589 void Actor::DisableDynamics()
590 {
591 #ifdef DYNAMICS_SUPPORT
592   GetImplementation(*this).DisableDynamics();
593 #endif
594 }
595
596 DynamicsBody Actor::GetDynamicsBody()
597 {
598 #ifdef DYNAMICS_SUPPORT
599   Internal::DynamicsBodyPtr internal(GetImplementation(*this).GetDynamicsBody());
600   return DynamicsBody( internal.Get() );
601 #else
602   return DynamicsBody();
603 #endif
604 }
605
606 Actor::Actor(Internal::Actor* internal)
607 : Handle(internal)
608 {
609 }
610
611 void UnparentAndReset( Actor& actor )
612 {
613   if( actor )
614   {
615     actor.Unparent();
616     actor.Reset();
617   }
618 }
619
620 } // namespace Dali