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/shader-effects/shader-effect.h>
26 #include <dali/public-api/math/degree.h>
27 #include <dali/public-api/math/radian.h>
28 #include <dali/public-api/math/vector2.h>
30 #include <dali/internal/event/actors/actor-impl.h>
31 #include <dali/internal/event/actors/layer-impl.h>
32 #include <dali/internal/event/actor-attachments/actor-attachment-impl.h>
33 #include <dali/internal/event/animation/constraint-impl.h>
34 #include <dali/internal/event/effects/shader-effect-impl.h>
36 #include <dali/public-api/dynamics/dynamics-body.h>
37 #include <dali/public-api/dynamics/dynamics-joint.h>
38 #include <dali/public-api/dynamics/dynamics-body-config.h>
40 #ifdef DYNAMICS_SUPPORT
41 #include <dali/internal/event/dynamics/dynamics-declarations.h>
42 #include <dali/internal/event/dynamics/dynamics-body-config-impl.h>
43 #include <dali/internal/event/dynamics/dynamics-body-impl.h>
44 #include <dali/internal/event/dynamics/dynamics-joint-impl.h>
45 #include <dali/internal/event/dynamics/dynamics-world-impl.h>
53 const char* const Actor::SIGNAL_TOUCHED = "touched";
54 const char* const Actor::SIGNAL_MOUSE_WHEEL_EVENT = "mouse-wheel-event";
55 const char* const Actor::SIGNAL_SET_SIZE = "set-size";
56 const char* const Actor::SIGNAL_ON_STAGE = "on-stage";
57 const char* const Actor::SIGNAL_OFF_STAGE = "off-stage";
59 const char* const Actor::ACTION_SHOW = "show";
60 const char* const Actor::ACTION_HIDE = "hide";
68 Internal::ActorPtr internal = Internal::Actor::New();
70 return Actor(internal.Get());
73 Actor Actor::DownCast( BaseHandle handle )
75 return Actor( dynamic_cast<Dali::Internal::Actor*>(handle.GetObjectPtr()) );
82 Actor::Actor(const Actor& copy)
87 Actor& Actor::operator=(const Actor& rhs)
89 BaseHandle::operator=(rhs);
93 Actor& Actor::operator=(BaseHandle::NullType* rhs)
95 DALI_ASSERT_ALWAYS( (rhs == NULL) && "Can only assign NULL pointer to handle");
100 const std::string& Actor::GetName() const
102 return GetImplementation(*this).GetName();
105 void Actor::SetName(const std::string& name)
107 GetImplementation(*this).SetName(name);
110 unsigned int Actor::GetId() const
112 return GetImplementation(*this).GetId();
115 bool Actor::IsRoot() const
117 return GetImplementation(*this).IsRoot();
120 bool Actor::OnStage() const
122 return GetImplementation(*this).OnStage();
125 bool Actor::IsLayer() const
127 return GetImplementation(*this).IsLayer();
130 Layer Actor::GetLayer()
132 return GetImplementation(*this).GetLayer();
135 void Actor::Add(Actor actor)
137 GetImplementation(*this).Add(GetImplementation(actor));
140 void Actor::Remove(Actor actor)
142 GetImplementation(*this).Remove(GetImplementation(actor));
145 void Actor::Unparent()
147 GetImplementation(*this).Unparent();
150 unsigned int Actor::GetChildCount() const
152 return GetImplementation(*this).GetChildCount();
155 Actor Actor::GetChildAt(unsigned int index) const
157 return GetImplementation(*this).GetChildAt(index);
160 Actor Actor::FindChildByName(const std::string& actorName)
162 Internal::ActorPtr child = GetImplementation(*this).FindChildByName(actorName);
163 return Actor(child.Get());
166 Actor Actor::FindChildByAlias(const std::string& actorAlias)
168 Actor child = GetImplementation(*this).FindChildByAlias(actorAlias);
172 Actor Actor::FindChildById(const unsigned int id)
174 Internal::ActorPtr child = GetImplementation(*this).FindChildById(id);
175 return Actor(child.Get());
178 Actor Actor::GetParent() const
180 Internal::Actor* parent = GetImplementation(*this).GetParent();
182 return Actor(parent);
185 void Actor::SetParentOrigin(const Vector3& origin)
187 GetImplementation(*this).SetParentOrigin(origin);
190 Vector3 Actor::GetCurrentParentOrigin() const
192 return GetImplementation(*this).GetCurrentParentOrigin();
195 void Actor::SetAnchorPoint(const Vector3& anchorPoint)
197 GetImplementation(*this).SetAnchorPoint(anchorPoint);
200 Vector3 Actor::GetCurrentAnchorPoint() const
202 return GetImplementation(*this).GetCurrentAnchorPoint();
205 void Actor::SetSize(float width, float height)
207 GetImplementation(*this).SetSize(width, height);
210 void Actor::SetSize(float width, float height, float depth)
212 GetImplementation(*this).SetSize(width, height, depth);
215 void Actor::SetSize(const Vector2& size)
217 GetImplementation(*this).SetSize(size);
220 void Actor::SetSize(const Vector3& size)
222 GetImplementation(*this).SetSize(size);
225 Vector3 Actor::GetCurrentSize() const
227 return GetImplementation(*this).GetCurrentSize();
230 void Actor::SetPosition(float x, float y)
232 GetImplementation(*this).SetPosition(x, y);
235 void Actor::SetPosition(float x, float y, float z)
237 GetImplementation(*this).SetPosition(x, y, z);
240 void Actor::SetPosition(const Vector3& position)
242 GetImplementation(*this).SetPosition(position);
245 void Actor::SetX(float x)
247 GetImplementation(*this).SetX(x);
250 void Actor::SetY(float y)
252 GetImplementation(*this).SetY(y);
255 void Actor::SetZ(float z)
257 GetImplementation(*this).SetZ(z);
260 void Actor::MoveBy(const Vector3& distance)
262 GetImplementation(*this).MoveBy(distance);
265 Vector3 Actor::GetCurrentPosition() const
267 return GetImplementation(*this).GetCurrentPosition();
270 Vector3 Actor::GetCurrentWorldPosition() const
272 return GetImplementation(*this).GetCurrentWorldPosition();
275 void Actor::SetPositionInheritanceMode( PositionInheritanceMode mode )
277 GetImplementation(*this).SetPositionInheritanceMode( mode );
280 PositionInheritanceMode Actor::GetPositionInheritanceMode() const
282 return GetImplementation(*this).GetPositionInheritanceMode();
285 void Actor::SetRotation(const Degree& angle, const Vector3& axis)
287 GetImplementation(*this).SetRotation(Radian(angle), axis);
290 void Actor::SetRotation(const Radian& angle, const Vector3& axis)
292 GetImplementation(*this).SetRotation(angle, axis);
295 void Actor::SetRotation(const Quaternion& rotation)
297 GetImplementation(*this).SetRotation(rotation);
300 void Actor::RotateBy(const Degree& angle, const Vector3& axis)
302 GetImplementation(*this).RotateBy(Radian(angle), axis);
305 void Actor::RotateBy(const Radian& angle, const Vector3& axis)
307 GetImplementation(*this).RotateBy(angle, axis);
310 void Actor::RotateBy(const Quaternion& relativeRotation)
312 GetImplementation(*this).RotateBy(relativeRotation);
315 Quaternion Actor::GetCurrentRotation() const
317 return GetImplementation(*this).GetCurrentRotation();
320 void Actor::SetInheritRotation(bool inherit)
322 GetImplementation(*this).SetInheritRotation(inherit);
325 bool Actor::IsRotationInherited() const
327 return GetImplementation(*this).IsRotationInherited();
330 Quaternion Actor::GetCurrentWorldRotation() const
332 return GetImplementation(*this).GetCurrentWorldRotation();
335 void Actor::SetScale(float scale)
337 GetImplementation(*this).SetScale(scale);
340 void Actor::SetScale(float scaleX, float scaleY, float scaleZ)
342 GetImplementation(*this).SetScale(scaleX, scaleY, scaleZ);
345 void Actor::SetScale(const Vector3& scale)
347 GetImplementation(*this).SetScale(scale);
350 void Actor::ScaleBy(const Vector3& relativeScale)
352 GetImplementation(*this).ScaleBy(relativeScale);
355 Vector3 Actor::GetCurrentScale() const
357 return GetImplementation(*this).GetCurrentScale();
360 Vector3 Actor::GetCurrentWorldScale() const
362 return GetImplementation(*this).GetCurrentWorldScale();
365 void Actor::SetInheritScale( bool inherit )
367 GetImplementation(*this).SetInheritScale( inherit );
370 bool Actor::IsScaleInherited() const
372 return GetImplementation(*this).IsScaleInherited();
375 Matrix Actor::GetCurrentWorldMatrix() const
377 return GetImplementation(*this).GetCurrentWorldMatrix();
380 void Actor::SetVisible(bool visible)
382 GetImplementation(*this).SetVisible(visible);
385 bool Actor::IsVisible() const
387 return GetImplementation(*this).IsVisible();
390 void Actor::SetOpacity(float opacity)
392 GetImplementation(*this).SetOpacity(opacity);
395 void Actor::OpacityBy(float relativeOpacity)
397 GetImplementation(*this).OpacityBy(relativeOpacity);
400 float Actor::GetCurrentOpacity() const
402 return GetImplementation(*this).GetCurrentOpacity();
405 void Actor::SetColor(const Vector4& color)
407 GetImplementation(*this).SetColor(color);
410 void Actor::ColorBy(const Vector4& relativeColor)
412 GetImplementation(*this).ColorBy(relativeColor);
415 Vector4 Actor::GetCurrentColor() const
417 return GetImplementation(*this).GetCurrentColor();
420 void Actor::SetColorMode( ColorMode colorMode )
422 GetImplementation(*this).SetColorMode(colorMode);
425 ColorMode Actor::GetColorMode() const
427 return GetImplementation(*this).GetColorMode();
430 Vector4 Actor::GetCurrentWorldColor() const
432 return GetImplementation(*this).GetCurrentWorldColor();
435 void Actor::SetInheritShaderEffect(bool inherit)
437 // TODO remove this API
441 bool Actor::GetInheritShaderEffect() const
443 // TODO remove this API
448 void Actor::SetShaderEffect(ShaderEffect effect)
450 // TODO remove this API
451 GetImplementation(*this).SetShaderEffect(GetImplementation(effect));
454 ShaderEffect Actor::GetShaderEffect() const
456 // TODO remove this API
457 return ShaderEffect();
460 void Actor::RemoveShaderEffect()
462 // TODO remove this API
463 GetImplementation(*this).RemoveShaderEffect();
466 void Actor::SetDrawMode( DrawMode::Type drawMode )
468 GetImplementation(*this).SetDrawMode( drawMode );
471 DrawMode::Type Actor::GetDrawMode() const
473 return GetImplementation(*this).GetDrawMode();
476 void Actor::SetSensitive(bool sensitive)
478 GetImplementation(*this).SetSensitive(sensitive);
481 bool Actor::IsSensitive() const
483 return GetImplementation(*this).IsSensitive();
486 bool Actor::ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const
488 return GetImplementation(*this).ScreenToLocal(localX, localY, screenX, screenY);
491 void Actor::SetLeaveRequired(bool required)
493 GetImplementation(*this).SetLeaveRequired(required);
496 bool Actor::GetLeaveRequired() const
498 return GetImplementation(*this).GetLeaveRequired();
501 void Actor::SetKeyboardFocusable( bool focusable )
503 GetImplementation(*this).SetKeyboardFocusable(focusable);
506 bool Actor::IsKeyboardFocusable() const
508 return GetImplementation(*this).IsKeyboardFocusable();
511 Actor::TouchSignalV2& Actor::TouchedSignal()
513 return GetImplementation(*this).TouchedSignal();
516 Actor::MouseWheelEventSignalV2& Actor::MouseWheelEventSignal()
518 return GetImplementation(*this).MouseWheelEventSignal();
521 Actor::SetSizeSignalV2& Actor::SetSizeSignal()
523 return GetImplementation(*this).SetSizeSignal();
526 Actor::OnStageSignalV2& Actor::OnStageSignal()
528 return GetImplementation(*this).OnStageSignal();
531 Actor::OffStageSignalV2& Actor::OffStageSignal()
533 return GetImplementation(*this).OffStageSignal();
536 DynamicsBody Actor::EnableDynamics(DynamicsBodyConfig bodyConfig)
538 #ifdef DYNAMICS_SUPPORT
539 Internal::DynamicsBodyConfig& internal = GetImplementation(bodyConfig);
541 Internal::DynamicsBodyPtr body( GetImplementation(*this).EnableDynamics( &internal ) );
543 return DynamicsBody( body.Get() );
545 return DynamicsBody();
549 DynamicsJoint Actor::AddDynamicsJoint( Actor attachedActor, const Vector3& offset )
551 #ifdef DYNAMICS_SUPPORT
552 Internal::ActorPtr internalActor( &GetImplementation(attachedActor) );
553 Internal::DynamicsJointPtr joint( GetImplementation(*this).AddDynamicsJoint( internalActor, offset) );
555 return DynamicsJoint( joint.Get() );
557 return DynamicsJoint();
561 DynamicsJoint Actor::AddDynamicsJoint( Actor attachedActor, const Vector3& offsetA, const Vector3& offsetB )
563 #ifdef DYNAMICS_SUPPORT
564 Internal::ActorPtr internalActor( &GetImplementation(attachedActor) );
565 Internal::DynamicsJointPtr joint( GetImplementation(*this).AddDynamicsJoint( internalActor, offsetA, offsetB) );
567 return DynamicsJoint( joint.Get() );
569 return DynamicsJoint();
573 const int Actor::GetNumberOfJoints() const
575 #ifdef DYNAMICS_SUPPORT
576 return GetImplementation(*this).GetNumberOfJoints();
582 DynamicsJoint Actor::GetDynamicsJointByIndex( const int index )
584 #ifdef DYNAMICS_SUPPORT
585 Internal::DynamicsJointPtr joint( GetImplementation(*this).GetDynamicsJointByIndex( index ) );
587 return DynamicsJoint( joint.Get() );
589 return DynamicsJoint();
593 DynamicsJoint Actor::GetDynamicsJoint( Actor attachedActor )
595 #ifdef DYNAMICS_SUPPORT
596 Internal::DynamicsJointPtr joint( GetImplementation(*this).GetDynamicsJoint( &GetImplementation(attachedActor) ) );
598 return DynamicsJoint( joint.Get() );
600 return DynamicsJoint();
604 void Actor::RemoveDynamicsJoint( DynamicsJoint joint )
606 #ifdef DYNAMICS_SUPPORT
607 GetImplementation(*this).RemoveDynamicsJoint( &GetImplementation(joint) );
611 void Actor::DisableDynamics()
613 #ifdef DYNAMICS_SUPPORT
614 GetImplementation(*this).DisableDynamics();
618 DynamicsBody Actor::GetDynamicsBody()
620 #ifdef DYNAMICS_SUPPORT
621 Internal::DynamicsBodyPtr internal(GetImplementation(*this).GetDynamicsBody());
622 return DynamicsBody( internal.Get() );
624 return DynamicsBody();
628 Actor::Actor(Internal::Actor* internal)
629 : Constrainable(internal)
633 void UnparentAndReset( Actor& actor )