Actor's Transformation API Cleanup
[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::TranslateBy(const Vector3& distance)
250 {
251   GetImplementation(*this).TranslateBy(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::SetOrientation(const Degree& angle, const Vector3& axis)
275 {
276   GetImplementation(*this).SetOrientation(Radian(angle), axis);
277 }
278
279 void Actor::SetOrientation(const Radian& angle, const Vector3& axis)
280 {
281   GetImplementation(*this).SetOrientation(angle, axis);
282 }
283
284 void Actor::SetOrientation(const Quaternion& orientation)
285 {
286   GetImplementation(*this).SetOrientation(orientation);
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::GetCurrentOrientation() const
305 {
306   return GetImplementation(*this).GetCurrentOrientation();
307 }
308
309 void Actor::SetInheritOrientation(bool inherit)
310 {
311   GetImplementation(*this).SetInheritOrientation(inherit);
312 }
313
314 bool Actor::IsOrientationInherited() const
315 {
316   return GetImplementation(*this).IsOrientationInherited();
317 }
318
319 Quaternion Actor::GetCurrentWorldOrientation() const
320 {
321   return GetImplementation(*this).GetCurrentWorldOrientation();
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 float Actor::GetCurrentOpacity() const
405 {
406   return GetImplementation(*this).GetCurrentOpacity();
407 }
408
409 void Actor::SetColor(const Vector4& color)
410 {
411   GetImplementation(*this).SetColor(color);
412 }
413
414 Vector4 Actor::GetCurrentColor() const
415 {
416   return GetImplementation(*this).GetCurrentColor();
417 }
418
419 void Actor::SetColorMode( ColorMode colorMode )
420 {
421   GetImplementation(*this).SetColorMode(colorMode);
422 }
423
424 ColorMode Actor::GetColorMode() const
425 {
426   return GetImplementation(*this).GetColorMode();
427 }
428
429 Vector4 Actor::GetCurrentWorldColor() const
430 {
431   return GetImplementation(*this).GetCurrentWorldColor();
432 }
433
434 void Actor::SetDrawMode( DrawMode::Type drawMode )
435 {
436   GetImplementation(*this).SetDrawMode( drawMode );
437 }
438
439 DrawMode::Type Actor::GetDrawMode() const
440 {
441   return GetImplementation(*this).GetDrawMode();
442 }
443
444 void Actor::SetSensitive(bool sensitive)
445 {
446   GetImplementation(*this).SetSensitive(sensitive);
447 }
448
449 bool Actor::IsSensitive() const
450 {
451   return GetImplementation(*this).IsSensitive();
452 }
453
454 bool Actor::ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const
455 {
456   return GetImplementation(*this).ScreenToLocal(localX, localY, screenX, screenY);
457 }
458
459 void Actor::SetLeaveRequired(bool required)
460 {
461   GetImplementation(*this).SetLeaveRequired(required);
462 }
463
464 bool Actor::GetLeaveRequired() const
465 {
466   return GetImplementation(*this).GetLeaveRequired();
467 }
468
469 void Actor::SetKeyboardFocusable( bool focusable )
470 {
471   GetImplementation(*this).SetKeyboardFocusable(focusable);
472 }
473
474 bool Actor::IsKeyboardFocusable() const
475 {
476   return GetImplementation(*this).IsKeyboardFocusable();
477 }
478
479 Actor::TouchSignalType& Actor::TouchedSignal()
480 {
481   return GetImplementation(*this).TouchedSignal();
482 }
483
484 Actor::HoverSignalType& Actor::HoveredSignal()
485 {
486   return GetImplementation(*this).HoveredSignal();
487 }
488
489 Actor::MouseWheelEventSignalType& Actor::MouseWheelEventSignal()
490 {
491   return GetImplementation(*this).MouseWheelEventSignal();
492 }
493
494 Actor::OnStageSignalType& Actor::OnStageSignal()
495 {
496   return GetImplementation(*this).OnStageSignal();
497 }
498
499 Actor::OffStageSignalType& Actor::OffStageSignal()
500 {
501   return GetImplementation(*this).OffStageSignal();
502 }
503
504 DynamicsBody Actor::EnableDynamics(DynamicsBodyConfig bodyConfig)
505 {
506 #ifdef DYNAMICS_SUPPORT
507   Internal::DynamicsBodyConfig& internal = GetImplementation(bodyConfig);
508
509   Internal::DynamicsBodyPtr body( GetImplementation(*this).EnableDynamics( &internal ) );
510
511   return DynamicsBody( body.Get() );
512 #else
513   return DynamicsBody();
514 #endif
515 }
516
517 DynamicsJoint Actor::AddDynamicsJoint( Actor attachedActor, const Vector3& offset )
518 {
519 #ifdef DYNAMICS_SUPPORT
520   Internal::ActorPtr internalActor( &GetImplementation(attachedActor) );
521   Internal::DynamicsJointPtr joint( GetImplementation(*this).AddDynamicsJoint( internalActor, offset) );
522
523   return DynamicsJoint( joint.Get() );
524 #else
525   return DynamicsJoint();
526 #endif
527 }
528
529 DynamicsJoint Actor::AddDynamicsJoint( Actor attachedActor, const Vector3& offsetA, const Vector3& offsetB )
530 {
531 #ifdef DYNAMICS_SUPPORT
532   Internal::ActorPtr internalActor( &GetImplementation(attachedActor) );
533   Internal::DynamicsJointPtr joint( GetImplementation(*this).AddDynamicsJoint( internalActor, offsetA, offsetB) );
534
535   return DynamicsJoint( joint.Get() );
536 #else
537   return DynamicsJoint();
538 #endif
539 }
540
541 int Actor::GetNumberOfJoints() const
542 {
543 #ifdef DYNAMICS_SUPPORT
544   return GetImplementation(*this).GetNumberOfJoints();
545 #else
546   return int();
547 #endif
548 }
549
550 DynamicsJoint Actor::GetDynamicsJointByIndex( const int index )
551 {
552 #ifdef DYNAMICS_SUPPORT
553   Internal::DynamicsJointPtr joint( GetImplementation(*this).GetDynamicsJointByIndex( index ) );
554
555   return DynamicsJoint( joint.Get() );
556 #else
557   return DynamicsJoint();
558 #endif
559 }
560
561 DynamicsJoint Actor::GetDynamicsJoint( Actor attachedActor )
562 {
563 #ifdef DYNAMICS_SUPPORT
564   Internal::DynamicsJointPtr joint( GetImplementation(*this).GetDynamicsJoint( &GetImplementation(attachedActor) ) );
565
566   return DynamicsJoint( joint.Get() );
567 #else
568   return DynamicsJoint();
569 #endif
570 }
571
572 void Actor::RemoveDynamicsJoint( DynamicsJoint joint )
573 {
574 #ifdef DYNAMICS_SUPPORT
575   GetImplementation(*this).RemoveDynamicsJoint( &GetImplementation(joint) );
576 #endif
577 }
578
579 void Actor::DisableDynamics()
580 {
581 #ifdef DYNAMICS_SUPPORT
582   GetImplementation(*this).DisableDynamics();
583 #endif
584 }
585
586 DynamicsBody Actor::GetDynamicsBody()
587 {
588 #ifdef DYNAMICS_SUPPORT
589   Internal::DynamicsBodyPtr internal(GetImplementation(*this).GetDynamicsBody());
590   return DynamicsBody( internal.Get() );
591 #else
592   return DynamicsBody();
593 #endif
594 }
595
596 Actor::Actor(Internal::Actor* internal)
597 : Handle(internal)
598 {
599 }
600
601 void UnparentAndReset( Actor& actor )
602 {
603   if( actor )
604   {
605     actor.Unparent();
606     actor.Reset();
607   }
608 }
609
610 } // namespace Dali