Merge "Merge Handle & Constrainable" 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::FindChildByAlias(const std::string& actorAlias)
152 {
153   Actor child = GetImplementation(*this).FindChildByAlias(actorAlias);
154   return child;
155 }
156
157 Actor Actor::FindChildById(const unsigned int id)
158 {
159   Internal::ActorPtr child = GetImplementation(*this).FindChildById(id);
160   return Actor(child.Get());
161 }
162
163 Actor Actor::GetParent() const
164 {
165   Internal::Actor* parent = GetImplementation(*this).GetParent();
166
167   return Actor(parent);
168 }
169
170 void Actor::SetParentOrigin(const Vector3& origin)
171 {
172   GetImplementation(*this).SetParentOrigin(origin);
173 }
174
175 Vector3 Actor::GetCurrentParentOrigin() const
176 {
177   return GetImplementation(*this).GetCurrentParentOrigin();
178 }
179
180 void Actor::SetAnchorPoint(const Vector3& anchorPoint)
181 {
182   GetImplementation(*this).SetAnchorPoint(anchorPoint);
183 }
184
185 Vector3 Actor::GetCurrentAnchorPoint() const
186 {
187   return GetImplementation(*this).GetCurrentAnchorPoint();
188 }
189
190 void Actor::SetSize(float width, float height)
191 {
192   GetImplementation(*this).SetSize(width, height);
193 }
194
195 void Actor::SetSize(float width, float height, float depth)
196 {
197   GetImplementation(*this).SetSize(width, height, depth);
198 }
199
200 void Actor::SetSize(const Vector2& size)
201 {
202   GetImplementation(*this).SetSize(size);
203 }
204
205 void Actor::SetSize(const Vector3& size)
206 {
207   GetImplementation(*this).SetSize(size);
208 }
209
210 Vector3 Actor::GetSize() const
211 {
212   return GetImplementation(*this).GetSize();
213 }
214
215 Vector3 Actor::GetCurrentSize() const
216 {
217   return GetImplementation(*this).GetCurrentSize();
218 }
219
220 Vector3 Actor::GetNaturalSize() const
221 {
222   return GetImplementation(*this).GetNaturalSize();
223 }
224
225 void Actor::SetPosition(float x, float y)
226 {
227   GetImplementation(*this).SetPosition(x, y);
228 }
229
230 void Actor::SetPosition(float x, float y, float z)
231 {
232   GetImplementation(*this).SetPosition(x, y, z);
233 }
234
235 void Actor::SetPosition(const Vector3& position)
236 {
237   GetImplementation(*this).SetPosition(position);
238 }
239
240 void Actor::SetX(float x)
241 {
242   GetImplementation(*this).SetX(x);
243 }
244
245 void Actor::SetY(float y)
246 {
247   GetImplementation(*this).SetY(y);
248 }
249
250 void Actor::SetZ(float z)
251 {
252   GetImplementation(*this).SetZ(z);
253 }
254
255 void Actor::MoveBy(const Vector3& distance)
256 {
257   GetImplementation(*this).MoveBy(distance);
258 }
259
260 Vector3 Actor::GetCurrentPosition() const
261 {
262   return GetImplementation(*this).GetCurrentPosition();
263 }
264
265 Vector3 Actor::GetCurrentWorldPosition() const
266 {
267   return GetImplementation(*this).GetCurrentWorldPosition();
268 }
269
270 void Actor::SetPositionInheritanceMode( PositionInheritanceMode mode )
271 {
272   GetImplementation(*this).SetPositionInheritanceMode( mode );
273 }
274
275 PositionInheritanceMode Actor::GetPositionInheritanceMode() const
276 {
277   return GetImplementation(*this).GetPositionInheritanceMode();
278 }
279
280 void Actor::SetRotation(const Degree& angle, const Vector3& axis)
281 {
282   GetImplementation(*this).SetRotation(Radian(angle), axis);
283 }
284
285 void Actor::SetRotation(const Radian& angle, const Vector3& axis)
286 {
287   GetImplementation(*this).SetRotation(angle, axis);
288 }
289
290 void Actor::SetRotation(const Quaternion& rotation)
291 {
292   GetImplementation(*this).SetRotation(rotation);
293 }
294
295 void Actor::RotateBy(const Degree& angle, const Vector3& axis)
296 {
297   GetImplementation(*this).RotateBy(Radian(angle), axis);
298 }
299
300 void Actor::RotateBy(const Radian& angle, const Vector3& axis)
301 {
302   GetImplementation(*this).RotateBy(angle, axis);
303 }
304
305 void Actor::RotateBy(const Quaternion& relativeRotation)
306 {
307   GetImplementation(*this).RotateBy(relativeRotation);
308 }
309
310 Quaternion Actor::GetCurrentRotation() const
311 {
312   return GetImplementation(*this).GetCurrentRotation();
313 }
314
315 void Actor::SetInheritRotation(bool inherit)
316 {
317   GetImplementation(*this).SetInheritRotation(inherit);
318 }
319
320 bool Actor::IsRotationInherited() const
321 {
322   return GetImplementation(*this).IsRotationInherited();
323 }
324
325 Quaternion Actor::GetCurrentWorldRotation() const
326 {
327   return GetImplementation(*this).GetCurrentWorldRotation();
328 }
329
330 void Actor::SetScale(float scale)
331 {
332   GetImplementation(*this).SetScale(scale);
333 }
334
335 void Actor::SetScale(float scaleX, float scaleY, float scaleZ)
336 {
337   GetImplementation(*this).SetScale(scaleX, scaleY, scaleZ);
338 }
339
340 void Actor::SetScale(const Vector3& scale)
341 {
342   GetImplementation(*this).SetScale(scale);
343 }
344
345 void Actor::ScaleBy(const Vector3& relativeScale)
346 {
347   GetImplementation(*this).ScaleBy(relativeScale);
348 }
349
350 Vector3 Actor::GetCurrentScale() const
351 {
352   return GetImplementation(*this).GetCurrentScale();
353 }
354
355 Vector3 Actor::GetCurrentWorldScale() const
356 {
357   return GetImplementation(*this).GetCurrentWorldScale();
358 }
359
360 void Actor::SetInheritScale( bool inherit )
361 {
362   GetImplementation(*this).SetInheritScale( inherit );
363 }
364
365 bool Actor::IsScaleInherited() const
366 {
367   return GetImplementation(*this).IsScaleInherited();
368 }
369
370 void Actor::SetSizeMode(SizeMode mode)
371 {
372   GetImplementation(*this).SetSizeMode(mode);
373 }
374
375 SizeMode Actor::GetSizeMode() const
376 {
377   return GetImplementation(*this).GetSizeMode();
378 }
379
380 void Actor::SetSizeModeFactor(const Vector3& factor)
381 {
382   GetImplementation(*this).SetSizeModeFactor(factor);
383 }
384
385 Vector3 Actor::GetSizeModeFactor() const
386 {
387   return GetImplementation(*this).GetSizeModeFactor();
388 }
389
390 Matrix Actor::GetCurrentWorldMatrix() const
391 {
392   return GetImplementation(*this).GetCurrentWorldMatrix();
393 }
394
395 void Actor::SetVisible(bool visible)
396 {
397   GetImplementation(*this).SetVisible(visible);
398 }
399
400 bool Actor::IsVisible() const
401 {
402   return GetImplementation(*this).IsVisible();
403 }
404
405 void Actor::SetOpacity(float opacity)
406 {
407   GetImplementation(*this).SetOpacity(opacity);
408 }
409
410 void Actor::OpacityBy(float relativeOpacity)
411 {
412   GetImplementation(*this).OpacityBy(relativeOpacity);
413 }
414
415 float Actor::GetCurrentOpacity() const
416 {
417   return GetImplementation(*this).GetCurrentOpacity();
418 }
419
420 void Actor::SetColor(const Vector4& color)
421 {
422   GetImplementation(*this).SetColor(color);
423 }
424
425 void Actor::ColorBy(const Vector4& relativeColor)
426 {
427   GetImplementation(*this).ColorBy(relativeColor);
428 }
429
430 Vector4 Actor::GetCurrentColor() const
431 {
432   return GetImplementation(*this).GetCurrentColor();
433 }
434
435 void Actor::SetColorMode( ColorMode colorMode )
436 {
437   GetImplementation(*this).SetColorMode(colorMode);
438 }
439
440 ColorMode Actor::GetColorMode() const
441 {
442   return GetImplementation(*this).GetColorMode();
443 }
444
445 Vector4 Actor::GetCurrentWorldColor() const
446 {
447   return GetImplementation(*this).GetCurrentWorldColor();
448 }
449
450 void Actor::SetDrawMode( DrawMode::Type drawMode )
451 {
452   GetImplementation(*this).SetDrawMode( drawMode );
453 }
454
455 DrawMode::Type Actor::GetDrawMode() const
456 {
457   return GetImplementation(*this).GetDrawMode();
458 }
459
460 void Actor::SetSensitive(bool sensitive)
461 {
462   GetImplementation(*this).SetSensitive(sensitive);
463 }
464
465 bool Actor::IsSensitive() const
466 {
467   return GetImplementation(*this).IsSensitive();
468 }
469
470 bool Actor::ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const
471 {
472   return GetImplementation(*this).ScreenToLocal(localX, localY, screenX, screenY);
473 }
474
475 void Actor::SetLeaveRequired(bool required)
476 {
477   GetImplementation(*this).SetLeaveRequired(required);
478 }
479
480 bool Actor::GetLeaveRequired() const
481 {
482   return GetImplementation(*this).GetLeaveRequired();
483 }
484
485 void Actor::SetKeyboardFocusable( bool focusable )
486 {
487   GetImplementation(*this).SetKeyboardFocusable(focusable);
488 }
489
490 bool Actor::IsKeyboardFocusable() const
491 {
492   return GetImplementation(*this).IsKeyboardFocusable();
493 }
494
495 Actor::TouchSignalType& Actor::TouchedSignal()
496 {
497   return GetImplementation(*this).TouchedSignal();
498 }
499
500 Actor::HoverSignalType& Actor::HoveredSignal()
501 {
502   return GetImplementation(*this).HoveredSignal();
503 }
504
505 Actor::MouseWheelEventSignalType& Actor::MouseWheelEventSignal()
506 {
507   return GetImplementation(*this).MouseWheelEventSignal();
508 }
509
510 Actor::OnStageSignalType& Actor::OnStageSignal()
511 {
512   return GetImplementation(*this).OnStageSignal();
513 }
514
515 Actor::OffStageSignalType& Actor::OffStageSignal()
516 {
517   return GetImplementation(*this).OffStageSignal();
518 }
519
520 DynamicsBody Actor::EnableDynamics(DynamicsBodyConfig bodyConfig)
521 {
522 #ifdef DYNAMICS_SUPPORT
523   Internal::DynamicsBodyConfig& internal = GetImplementation(bodyConfig);
524
525   Internal::DynamicsBodyPtr body( GetImplementation(*this).EnableDynamics( &internal ) );
526
527   return DynamicsBody( body.Get() );
528 #else
529   return DynamicsBody();
530 #endif
531 }
532
533 DynamicsJoint Actor::AddDynamicsJoint( Actor attachedActor, const Vector3& offset )
534 {
535 #ifdef DYNAMICS_SUPPORT
536   Internal::ActorPtr internalActor( &GetImplementation(attachedActor) );
537   Internal::DynamicsJointPtr joint( GetImplementation(*this).AddDynamicsJoint( internalActor, offset) );
538
539   return DynamicsJoint( joint.Get() );
540 #else
541   return DynamicsJoint();
542 #endif
543 }
544
545 DynamicsJoint Actor::AddDynamicsJoint( Actor attachedActor, const Vector3& offsetA, const Vector3& offsetB )
546 {
547 #ifdef DYNAMICS_SUPPORT
548   Internal::ActorPtr internalActor( &GetImplementation(attachedActor) );
549   Internal::DynamicsJointPtr joint( GetImplementation(*this).AddDynamicsJoint( internalActor, offsetA, offsetB) );
550
551   return DynamicsJoint( joint.Get() );
552 #else
553   return DynamicsJoint();
554 #endif
555 }
556
557 int Actor::GetNumberOfJoints() const
558 {
559 #ifdef DYNAMICS_SUPPORT
560   return GetImplementation(*this).GetNumberOfJoints();
561 #else
562   return int();
563 #endif
564 }
565
566 DynamicsJoint Actor::GetDynamicsJointByIndex( const int index )
567 {
568 #ifdef DYNAMICS_SUPPORT
569   Internal::DynamicsJointPtr joint( GetImplementation(*this).GetDynamicsJointByIndex( index ) );
570
571   return DynamicsJoint( joint.Get() );
572 #else
573   return DynamicsJoint();
574 #endif
575 }
576
577 DynamicsJoint Actor::GetDynamicsJoint( Actor attachedActor )
578 {
579 #ifdef DYNAMICS_SUPPORT
580   Internal::DynamicsJointPtr joint( GetImplementation(*this).GetDynamicsJoint( &GetImplementation(attachedActor) ) );
581
582   return DynamicsJoint( joint.Get() );
583 #else
584   return DynamicsJoint();
585 #endif
586 }
587
588 void Actor::RemoveDynamicsJoint( DynamicsJoint joint )
589 {
590 #ifdef DYNAMICS_SUPPORT
591   GetImplementation(*this).RemoveDynamicsJoint( &GetImplementation(joint) );
592 #endif
593 }
594
595 void Actor::DisableDynamics()
596 {
597 #ifdef DYNAMICS_SUPPORT
598   GetImplementation(*this).DisableDynamics();
599 #endif
600 }
601
602 DynamicsBody Actor::GetDynamicsBody()
603 {
604 #ifdef DYNAMICS_SUPPORT
605   Internal::DynamicsBodyPtr internal(GetImplementation(*this).GetDynamicsBody());
606   return DynamicsBody( internal.Get() );
607 #else
608   return DynamicsBody();
609 #endif
610 }
611
612 Actor::Actor(Internal::Actor* internal)
613 : Handle(internal)
614 {
615 }
616
617 void UnparentAndReset( Actor& actor )
618 {
619   if( actor )
620   {
621     actor.Unparent();
622     actor.Reset();
623   }
624 }
625
626 } // namespace Dali