2 * Copyright (c) 2014 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 <dali/public-api/actors/actor.h>
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>
29 #include <dali/internal/event/actors/actor-impl.h>
30 #include <dali/internal/event/actors/layer-impl.h>
31 #include <dali/internal/event/actors/renderer-impl.h>
32 #include <dali/internal/event/actor-attachments/actor-attachment-impl.h>
33 #include <dali/internal/event/animation/constraint-impl.h>
35 #include <dali/public-api/dynamics/dynamics-body.h>
36 #include <dali/public-api/dynamics/dynamics-joint.h>
37 #include <dali/public-api/dynamics/dynamics-body-config.h>
39 #ifdef DYNAMICS_SUPPORT
40 #include <dali/internal/event/dynamics/dynamics-declarations.h>
41 #include <dali/internal/event/dynamics/dynamics-body-config-impl.h>
42 #include <dali/internal/event/dynamics/dynamics-body-impl.h>
43 #include <dali/internal/event/dynamics/dynamics-joint-impl.h>
44 #include <dali/internal/event/dynamics/dynamics-world-impl.h>
56 Internal::ActorPtr internal = Internal::Actor::New();
58 return Actor(internal.Get());
61 Actor Actor::DownCast( BaseHandle handle )
63 return Actor( dynamic_cast<Dali::Internal::Actor*>(handle.GetObjectPtr()) );
70 Actor::Actor(const Actor& copy)
75 Actor& Actor::operator=(const Actor& rhs)
77 BaseHandle::operator=(rhs);
81 const std::string& Actor::GetName() const
83 return GetImplementation(*this).GetName();
86 void Actor::SetName(const std::string& name)
88 GetImplementation(*this).SetName(name);
91 unsigned int Actor::GetId() const
93 return GetImplementation(*this).GetId();
96 bool Actor::IsRoot() const
98 return GetImplementation(*this).IsRoot();
101 bool Actor::OnStage() const
103 return GetImplementation(*this).OnStage();
106 bool Actor::IsLayer() const
108 return GetImplementation(*this).IsLayer();
111 Layer Actor::GetLayer()
113 return GetImplementation(*this).GetLayer();
116 void Actor::Add(Actor actor)
118 GetImplementation(*this).Add(GetImplementation(actor));
121 void Actor::Insert(unsigned int index, Actor actor)
123 GetImplementation(*this).Insert(index, GetImplementation(actor));
126 void Actor::Remove(Actor actor)
128 GetImplementation(*this).Remove(GetImplementation(actor));
131 void Actor::Unparent()
133 GetImplementation(*this).Unparent();
136 unsigned int Actor::GetChildCount() const
138 return GetImplementation(*this).GetChildCount();
141 Actor Actor::GetChildAt(unsigned int index) const
143 return GetImplementation(*this).GetChildAt(index);
146 Actor Actor::FindChildByName(const std::string& actorName)
148 Internal::ActorPtr child = GetImplementation(*this).FindChildByName(actorName);
149 return Actor(child.Get());
152 Actor Actor::FindChildByAlias(const std::string& actorAlias)
154 Actor child = GetImplementation(*this).FindChildByAlias(actorAlias);
158 Actor Actor::FindChildById(const unsigned int id)
160 Internal::ActorPtr child = GetImplementation(*this).FindChildById(id);
161 return Actor(child.Get());
164 Actor Actor::GetParent() const
166 Internal::Actor* parent = GetImplementation(*this).GetParent();
168 return Actor(parent);
171 void Actor::SetParentOrigin(const Vector3& origin)
173 GetImplementation(*this).SetParentOrigin(origin);
176 Vector3 Actor::GetCurrentParentOrigin() const
178 return GetImplementation(*this).GetCurrentParentOrigin();
181 void Actor::SetAnchorPoint(const Vector3& anchorPoint)
183 GetImplementation(*this).SetAnchorPoint(anchorPoint);
186 Vector3 Actor::GetCurrentAnchorPoint() const
188 return GetImplementation(*this).GetCurrentAnchorPoint();
191 void Actor::SetSize(float width, float height)
193 GetImplementation(*this).SetSize(width, height);
196 void Actor::SetSize(float width, float height, float depth)
198 GetImplementation(*this).SetSize(width, height, depth);
201 void Actor::SetSize(const Vector2& size)
203 GetImplementation(*this).SetSize(size);
206 void Actor::SetSize(const Vector3& size)
208 GetImplementation(*this).SetSize(size);
211 Vector3 Actor::GetSize() const
213 return GetImplementation(*this).GetSize();
216 Vector3 Actor::GetCurrentSize() const
218 return GetImplementation(*this).GetCurrentSize();
221 Vector3 Actor::GetNaturalSize() const
223 return GetImplementation(*this).GetNaturalSize();
226 void Actor::SetPosition(float x, float y)
228 GetImplementation(*this).SetPosition(x, y);
231 void Actor::SetPosition(float x, float y, float z)
233 GetImplementation(*this).SetPosition(x, y, z);
236 void Actor::SetPosition(const Vector3& position)
238 GetImplementation(*this).SetPosition(position);
241 void Actor::SetX(float x)
243 GetImplementation(*this).SetX(x);
246 void Actor::SetY(float y)
248 GetImplementation(*this).SetY(y);
251 void Actor::SetZ(float z)
253 GetImplementation(*this).SetZ(z);
256 void Actor::MoveBy(const Vector3& distance)
258 GetImplementation(*this).MoveBy(distance);
261 Vector3 Actor::GetCurrentPosition() const
263 return GetImplementation(*this).GetCurrentPosition();
266 Vector3 Actor::GetCurrentWorldPosition() const
268 return GetImplementation(*this).GetCurrentWorldPosition();
271 void Actor::SetPositionInheritanceMode( PositionInheritanceMode mode )
273 GetImplementation(*this).SetPositionInheritanceMode( mode );
276 PositionInheritanceMode Actor::GetPositionInheritanceMode() const
278 return GetImplementation(*this).GetPositionInheritanceMode();
281 void Actor::SetRotation(const Degree& angle, const Vector3& axis)
283 GetImplementation(*this).SetRotation(Radian(angle), axis);
286 void Actor::SetRotation(const Radian& angle, const Vector3& axis)
288 GetImplementation(*this).SetRotation(angle, axis);
291 void Actor::SetRotation(const Quaternion& rotation)
293 GetImplementation(*this).SetRotation(rotation);
296 void Actor::RotateBy(const Degree& angle, const Vector3& axis)
298 GetImplementation(*this).RotateBy(Radian(angle), axis);
301 void Actor::RotateBy(const Radian& angle, const Vector3& axis)
303 GetImplementation(*this).RotateBy(angle, axis);
306 void Actor::RotateBy(const Quaternion& relativeRotation)
308 GetImplementation(*this).RotateBy(relativeRotation);
311 Quaternion Actor::GetCurrentRotation() const
313 return GetImplementation(*this).GetCurrentRotation();
316 void Actor::SetInheritRotation(bool inherit)
318 GetImplementation(*this).SetInheritRotation(inherit);
321 bool Actor::IsRotationInherited() const
323 return GetImplementation(*this).IsRotationInherited();
326 Quaternion Actor::GetCurrentWorldRotation() const
328 return GetImplementation(*this).GetCurrentWorldRotation();
331 void Actor::SetScale(float scale)
333 GetImplementation(*this).SetScale(scale);
336 void Actor::SetScale(float scaleX, float scaleY, float scaleZ)
338 GetImplementation(*this).SetScale(scaleX, scaleY, scaleZ);
341 void Actor::SetScale(const Vector3& scale)
343 GetImplementation(*this).SetScale(scale);
346 void Actor::ScaleBy(const Vector3& relativeScale)
348 GetImplementation(*this).ScaleBy(relativeScale);
351 Vector3 Actor::GetCurrentScale() const
353 return GetImplementation(*this).GetCurrentScale();
356 Vector3 Actor::GetCurrentWorldScale() const
358 return GetImplementation(*this).GetCurrentWorldScale();
361 void Actor::SetInheritScale( bool inherit )
363 GetImplementation(*this).SetInheritScale( inherit );
366 bool Actor::IsScaleInherited() const
368 return GetImplementation(*this).IsScaleInherited();
371 void Actor::SetSizeMode(SizeMode mode)
373 GetImplementation(*this).SetSizeMode(mode);
376 SizeMode Actor::GetSizeMode() const
378 return GetImplementation(*this).GetSizeMode();
381 void Actor::SetSizeModeFactor(const Vector3& factor)
383 GetImplementation(*this).SetSizeModeFactor(factor);
386 Vector3 Actor::GetSizeModeFactor() const
388 return GetImplementation(*this).GetSizeModeFactor();
391 Matrix Actor::GetCurrentWorldMatrix() const
393 return GetImplementation(*this).GetCurrentWorldMatrix();
396 void Actor::SetVisible(bool visible)
398 GetImplementation(*this).SetVisible(visible);
401 bool Actor::IsVisible() const
403 return GetImplementation(*this).IsVisible();
406 void Actor::SetOpacity(float opacity)
408 GetImplementation(*this).SetOpacity(opacity);
411 void Actor::OpacityBy(float relativeOpacity)
413 GetImplementation(*this).OpacityBy(relativeOpacity);
416 float Actor::GetCurrentOpacity() const
418 return GetImplementation(*this).GetCurrentOpacity();
421 void Actor::SetColor(const Vector4& color)
423 GetImplementation(*this).SetColor(color);
426 void Actor::ColorBy(const Vector4& relativeColor)
428 GetImplementation(*this).ColorBy(relativeColor);
431 Vector4 Actor::GetCurrentColor() const
433 return GetImplementation(*this).GetCurrentColor();
436 void Actor::SetColorMode( ColorMode colorMode )
438 GetImplementation(*this).SetColorMode(colorMode);
441 ColorMode Actor::GetColorMode() const
443 return GetImplementation(*this).GetColorMode();
446 Vector4 Actor::GetCurrentWorldColor() const
448 return GetImplementation(*this).GetCurrentWorldColor();
451 void Actor::SetDrawMode( DrawMode::Type drawMode )
453 GetImplementation(*this).SetDrawMode( drawMode );
456 DrawMode::Type Actor::GetDrawMode() const
458 return GetImplementation(*this).GetDrawMode();
461 void Actor::SetSensitive(bool sensitive)
463 GetImplementation(*this).SetSensitive(sensitive);
466 bool Actor::IsSensitive() const
468 return GetImplementation(*this).IsSensitive();
471 bool Actor::ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const
473 return GetImplementation(*this).ScreenToLocal(localX, localY, screenX, screenY);
476 void Actor::SetLeaveRequired(bool required)
478 GetImplementation(*this).SetLeaveRequired(required);
481 bool Actor::GetLeaveRequired() const
483 return GetImplementation(*this).GetLeaveRequired();
486 void Actor::SetKeyboardFocusable( bool focusable )
488 GetImplementation(*this).SetKeyboardFocusable(focusable);
491 bool Actor::IsKeyboardFocusable() const
493 return GetImplementation(*this).IsKeyboardFocusable();
496 Actor::TouchSignalType& Actor::TouchedSignal()
498 return GetImplementation(*this).TouchedSignal();
501 Actor::HoverSignalType& Actor::HoveredSignal()
503 return GetImplementation(*this).HoveredSignal();
506 Actor::MouseWheelEventSignalType& Actor::MouseWheelEventSignal()
508 return GetImplementation(*this).MouseWheelEventSignal();
511 Actor::OnStageSignalType& Actor::OnStageSignal()
513 return GetImplementation(*this).OnStageSignal();
516 Actor::OffStageSignalType& Actor::OffStageSignal()
518 return GetImplementation(*this).OffStageSignal();
521 unsigned int Actor::AddRenderer( Renderer& renderer )
523 return GetImplementation(*this).AddRenderer( GetImplementation( renderer ) );
526 unsigned int Actor::GetRendererCount() const
528 return GetImplementation(*this).GetRendererCount();
531 Renderer Actor::GetRendererAt( unsigned int index )
533 return Renderer( &GetImplementation(*this).GetRendererAt( index ) );
536 void Actor::RemoveRenderer( Renderer& renderer )
538 GetImplementation(*this).RemoveRenderer( GetImplementation( renderer ) );
541 void Actor::RemoveRenderer( unsigned int index )
543 GetImplementation(*this).RemoveRenderer( index );
546 DynamicsBody Actor::EnableDynamics(DynamicsBodyConfig bodyConfig)
548 #ifdef DYNAMICS_SUPPORT
549 Internal::DynamicsBodyConfig& internal = GetImplementation(bodyConfig);
551 Internal::DynamicsBodyPtr body( GetImplementation(*this).EnableDynamics( &internal ) );
553 return DynamicsBody( body.Get() );
555 return DynamicsBody();
559 DynamicsJoint Actor::AddDynamicsJoint( Actor attachedActor, const Vector3& offset )
561 #ifdef DYNAMICS_SUPPORT
562 Internal::ActorPtr internalActor( &GetImplementation(attachedActor) );
563 Internal::DynamicsJointPtr joint( GetImplementation(*this).AddDynamicsJoint( internalActor, offset) );
565 return DynamicsJoint( joint.Get() );
567 return DynamicsJoint();
571 DynamicsJoint Actor::AddDynamicsJoint( Actor attachedActor, const Vector3& offsetA, const Vector3& offsetB )
573 #ifdef DYNAMICS_SUPPORT
574 Internal::ActorPtr internalActor( &GetImplementation(attachedActor) );
575 Internal::DynamicsJointPtr joint( GetImplementation(*this).AddDynamicsJoint( internalActor, offsetA, offsetB) );
577 return DynamicsJoint( joint.Get() );
579 return DynamicsJoint();
583 int Actor::GetNumberOfJoints() const
585 #ifdef DYNAMICS_SUPPORT
586 return GetImplementation(*this).GetNumberOfJoints();
592 DynamicsJoint Actor::GetDynamicsJointByIndex( const int index )
594 #ifdef DYNAMICS_SUPPORT
595 Internal::DynamicsJointPtr joint( GetImplementation(*this).GetDynamicsJointByIndex( index ) );
597 return DynamicsJoint( joint.Get() );
599 return DynamicsJoint();
603 DynamicsJoint Actor::GetDynamicsJoint( Actor attachedActor )
605 #ifdef DYNAMICS_SUPPORT
606 Internal::DynamicsJointPtr joint( GetImplementation(*this).GetDynamicsJoint( &GetImplementation(attachedActor) ) );
608 return DynamicsJoint( joint.Get() );
610 return DynamicsJoint();
614 void Actor::RemoveDynamicsJoint( DynamicsJoint joint )
616 #ifdef DYNAMICS_SUPPORT
617 GetImplementation(*this).RemoveDynamicsJoint( &GetImplementation(joint) );
621 void Actor::DisableDynamics()
623 #ifdef DYNAMICS_SUPPORT
624 GetImplementation(*this).DisableDynamics();
628 DynamicsBody Actor::GetDynamicsBody()
630 #ifdef DYNAMICS_SUPPORT
631 Internal::DynamicsBodyPtr internal(GetImplementation(*this).GetDynamicsBody());
632 return DynamicsBody( internal.Get() );
634 return DynamicsBody();
638 Actor::Actor(Internal::Actor* internal)
643 void UnparentAndReset( Actor& actor )