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 const std::string& Actor::GetName() const
84 return GetImplementation(*this).GetName();
87 void Actor::SetName(const std::string& name)
89 GetImplementation(*this).SetName(name);
92 unsigned int Actor::GetId() const
94 return GetImplementation(*this).GetId();
97 bool Actor::IsRoot() const
99 return GetImplementation(*this).IsRoot();
102 bool Actor::OnStage() const
104 return GetImplementation(*this).OnStage();
107 bool Actor::IsLayer() const
109 return GetImplementation(*this).IsLayer();
112 Layer Actor::GetLayer()
114 return GetImplementation(*this).GetLayer();
117 void Actor::Add(Actor actor)
119 GetImplementation(*this).Add(GetImplementation(actor));
122 void Actor::Remove(Actor actor)
124 GetImplementation(*this).Remove(GetImplementation(actor));
127 void Actor::Unparent()
129 GetImplementation(*this).Unparent();
132 unsigned int Actor::GetChildCount() const
134 return GetImplementation(*this).GetChildCount();
137 Actor Actor::GetChildAt(unsigned int index) const
139 return GetImplementation(*this).GetChildAt(index);
142 Actor Actor::FindChildByName(const std::string& actorName)
144 Internal::ActorPtr child = GetImplementation(*this).FindChildByName(actorName);
145 return Actor(child.Get());
148 Actor Actor::FindChildByAlias(const std::string& actorAlias)
150 Actor child = GetImplementation(*this).FindChildByAlias(actorAlias);
154 Actor Actor::FindChildById(const unsigned int id)
156 Internal::ActorPtr child = GetImplementation(*this).FindChildById(id);
157 return Actor(child.Get());
160 Actor Actor::GetParent() const
162 Internal::Actor* parent = GetImplementation(*this).GetParent();
164 return Actor(parent);
167 void Actor::SetParentOrigin(const Vector3& origin)
169 GetImplementation(*this).SetParentOrigin(origin);
172 Vector3 Actor::GetCurrentParentOrigin() const
174 return GetImplementation(*this).GetCurrentParentOrigin();
177 void Actor::SetAnchorPoint(const Vector3& anchorPoint)
179 GetImplementation(*this).SetAnchorPoint(anchorPoint);
182 Vector3 Actor::GetCurrentAnchorPoint() const
184 return GetImplementation(*this).GetCurrentAnchorPoint();
187 void Actor::SetSize(float width, float height)
189 GetImplementation(*this).SetSize(width, height);
192 void Actor::SetSize(float width, float height, float depth)
194 GetImplementation(*this).SetSize(width, height, depth);
197 void Actor::SetSize(const Vector2& size)
199 GetImplementation(*this).SetSize(size);
202 void Actor::SetSize(const Vector3& size)
204 GetImplementation(*this).SetSize(size);
207 Vector3 Actor::GetCurrentSize() const
209 return GetImplementation(*this).GetCurrentSize();
212 void Actor::SetPosition(float x, float y)
214 GetImplementation(*this).SetPosition(x, y);
217 void Actor::SetPosition(float x, float y, float z)
219 GetImplementation(*this).SetPosition(x, y, z);
222 void Actor::SetPosition(const Vector3& position)
224 GetImplementation(*this).SetPosition(position);
227 void Actor::SetX(float x)
229 GetImplementation(*this).SetX(x);
232 void Actor::SetY(float y)
234 GetImplementation(*this).SetY(y);
237 void Actor::SetZ(float z)
239 GetImplementation(*this).SetZ(z);
242 void Actor::MoveBy(const Vector3& distance)
244 GetImplementation(*this).MoveBy(distance);
247 Vector3 Actor::GetCurrentPosition() const
249 return GetImplementation(*this).GetCurrentPosition();
252 Vector3 Actor::GetCurrentWorldPosition() const
254 return GetImplementation(*this).GetCurrentWorldPosition();
257 void Actor::SetPositionInheritanceMode( PositionInheritanceMode mode )
259 GetImplementation(*this).SetPositionInheritanceMode( mode );
262 PositionInheritanceMode Actor::GetPositionInheritanceMode() const
264 return GetImplementation(*this).GetPositionInheritanceMode();
267 void Actor::SetRotation(const Degree& angle, const Vector3& axis)
269 GetImplementation(*this).SetRotation(Radian(angle), axis);
272 void Actor::SetRotation(const Radian& angle, const Vector3& axis)
274 GetImplementation(*this).SetRotation(angle, axis);
277 void Actor::SetRotation(const Quaternion& rotation)
279 GetImplementation(*this).SetRotation(rotation);
282 void Actor::RotateBy(const Degree& angle, const Vector3& axis)
284 GetImplementation(*this).RotateBy(Radian(angle), axis);
287 void Actor::RotateBy(const Radian& angle, const Vector3& axis)
289 GetImplementation(*this).RotateBy(angle, axis);
292 void Actor::RotateBy(const Quaternion& relativeRotation)
294 GetImplementation(*this).RotateBy(relativeRotation);
297 Quaternion Actor::GetCurrentRotation() const
299 return GetImplementation(*this).GetCurrentRotation();
302 void Actor::SetInheritRotation(bool inherit)
304 GetImplementation(*this).SetInheritRotation(inherit);
307 bool Actor::IsRotationInherited() const
309 return GetImplementation(*this).IsRotationInherited();
312 Quaternion Actor::GetCurrentWorldRotation() const
314 return GetImplementation(*this).GetCurrentWorldRotation();
317 void Actor::SetScale(float scale)
319 GetImplementation(*this).SetScale(scale);
322 void Actor::SetScale(float scaleX, float scaleY, float scaleZ)
324 GetImplementation(*this).SetScale(scaleX, scaleY, scaleZ);
327 void Actor::SetScale(const Vector3& scale)
329 GetImplementation(*this).SetScale(scale);
332 void Actor::ScaleBy(const Vector3& relativeScale)
334 GetImplementation(*this).ScaleBy(relativeScale);
337 Vector3 Actor::GetCurrentScale() const
339 return GetImplementation(*this).GetCurrentScale();
342 Vector3 Actor::GetCurrentWorldScale() const
344 return GetImplementation(*this).GetCurrentWorldScale();
347 void Actor::SetInheritScale( bool inherit )
349 GetImplementation(*this).SetInheritScale( inherit );
352 bool Actor::IsScaleInherited() const
354 return GetImplementation(*this).IsScaleInherited();
357 Matrix Actor::GetCurrentWorldMatrix() const
359 return GetImplementation(*this).GetCurrentWorldMatrix();
362 void Actor::SetVisible(bool visible)
364 GetImplementation(*this).SetVisible(visible);
367 bool Actor::IsVisible() const
369 return GetImplementation(*this).IsVisible();
372 void Actor::SetOpacity(float opacity)
374 GetImplementation(*this).SetOpacity(opacity);
377 void Actor::OpacityBy(float relativeOpacity)
379 GetImplementation(*this).OpacityBy(relativeOpacity);
382 float Actor::GetCurrentOpacity() const
384 return GetImplementation(*this).GetCurrentOpacity();
387 void Actor::SetColor(const Vector4& color)
389 GetImplementation(*this).SetColor(color);
392 void Actor::ColorBy(const Vector4& relativeColor)
394 GetImplementation(*this).ColorBy(relativeColor);
397 Vector4 Actor::GetCurrentColor() const
399 return GetImplementation(*this).GetCurrentColor();
402 void Actor::SetColorMode( ColorMode colorMode )
404 GetImplementation(*this).SetColorMode(colorMode);
407 ColorMode Actor::GetColorMode() const
409 return GetImplementation(*this).GetColorMode();
412 Vector4 Actor::GetCurrentWorldColor() const
414 return GetImplementation(*this).GetCurrentWorldColor();
417 void Actor::SetInheritShaderEffect(bool inherit)
419 GetImplementation(*this).SetInheritShaderEffect(inherit);
422 bool Actor::GetInheritShaderEffect() const
424 return GetImplementation(*this).GetInheritShaderEffect();
427 void Actor::SetShaderEffect(ShaderEffect effect)
429 GetImplementation(*this).SetShaderEffect(GetImplementation(effect));
432 ShaderEffect Actor::GetShaderEffect() const
434 Internal::ShaderEffectPtr internal = GetImplementation(*this).GetShaderEffect();
436 return ShaderEffect(internal.Get());
439 void Actor::RemoveShaderEffect()
441 GetImplementation(*this).RemoveShaderEffect();
444 void Actor::SetDrawMode( DrawMode::Type drawMode )
446 GetImplementation(*this).SetDrawMode( drawMode );
449 DrawMode::Type Actor::GetDrawMode() const
451 return GetImplementation(*this).GetDrawMode();
454 void Actor::SetSensitive(bool sensitive)
456 GetImplementation(*this).SetSensitive(sensitive);
459 bool Actor::IsSensitive() const
461 return GetImplementation(*this).IsSensitive();
464 bool Actor::ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const
466 return GetImplementation(*this).ScreenToLocal(localX, localY, screenX, screenY);
469 void Actor::SetLeaveRequired(bool required)
471 GetImplementation(*this).SetLeaveRequired(required);
474 bool Actor::GetLeaveRequired() const
476 return GetImplementation(*this).GetLeaveRequired();
479 void Actor::SetKeyboardFocusable( bool focusable )
481 GetImplementation(*this).SetKeyboardFocusable(focusable);
484 bool Actor::IsKeyboardFocusable() const
486 return GetImplementation(*this).IsKeyboardFocusable();
489 Actor::TouchSignalV2& Actor::TouchedSignal()
491 return GetImplementation(*this).TouchedSignal();
494 Actor::MouseWheelEventSignalV2& Actor::MouseWheelEventSignal()
496 return GetImplementation(*this).MouseWheelEventSignal();
499 Actor::SetSizeSignalV2& Actor::SetSizeSignal()
501 return GetImplementation(*this).SetSizeSignal();
504 Actor::OnStageSignalV2& Actor::OnStageSignal()
506 return GetImplementation(*this).OnStageSignal();
509 Actor::OffStageSignalV2& Actor::OffStageSignal()
511 return GetImplementation(*this).OffStageSignal();
514 DynamicsBody Actor::EnableDynamics(DynamicsBodyConfig bodyConfig)
516 #ifdef DYNAMICS_SUPPORT
517 Internal::DynamicsBodyConfig& internal = GetImplementation(bodyConfig);
519 Internal::DynamicsBodyPtr body( GetImplementation(*this).EnableDynamics( &internal ) );
521 return DynamicsBody( body.Get() );
523 return DynamicsBody();
527 DynamicsJoint Actor::AddDynamicsJoint( Actor attachedActor, const Vector3& offset )
529 #ifdef DYNAMICS_SUPPORT
530 Internal::ActorPtr internalActor( &GetImplementation(attachedActor) );
531 Internal::DynamicsJointPtr joint( GetImplementation(*this).AddDynamicsJoint( internalActor, offset) );
533 return DynamicsJoint( joint.Get() );
535 return DynamicsJoint();
539 DynamicsJoint Actor::AddDynamicsJoint( Actor attachedActor, const Vector3& offsetA, const Vector3& offsetB )
541 #ifdef DYNAMICS_SUPPORT
542 Internal::ActorPtr internalActor( &GetImplementation(attachedActor) );
543 Internal::DynamicsJointPtr joint( GetImplementation(*this).AddDynamicsJoint( internalActor, offsetA, offsetB) );
545 return DynamicsJoint( joint.Get() );
547 return DynamicsJoint();
551 const int Actor::GetNumberOfJoints() const
553 #ifdef DYNAMICS_SUPPORT
554 return GetImplementation(*this).GetNumberOfJoints();
560 DynamicsJoint Actor::GetDynamicsJointByIndex( const int index )
562 #ifdef DYNAMICS_SUPPORT
563 Internal::DynamicsJointPtr joint( GetImplementation(*this).GetDynamicsJointByIndex( index ) );
565 return DynamicsJoint( joint.Get() );
567 return DynamicsJoint();
571 DynamicsJoint Actor::GetDynamicsJoint( Actor attachedActor )
573 #ifdef DYNAMICS_SUPPORT
574 Internal::DynamicsJointPtr joint( GetImplementation(*this).GetDynamicsJoint( &GetImplementation(attachedActor) ) );
576 return DynamicsJoint( joint.Get() );
578 return DynamicsJoint();
582 void Actor::RemoveDynamicsJoint( DynamicsJoint joint )
584 #ifdef DYNAMICS_SUPPORT
585 GetImplementation(*this).RemoveDynamicsJoint( &GetImplementation(joint) );
589 void Actor::DisableDynamics()
591 #ifdef DYNAMICS_SUPPORT
592 GetImplementation(*this).DisableDynamics();
596 DynamicsBody Actor::GetDynamicsBody()
598 #ifdef DYNAMICS_SUPPORT
599 Internal::DynamicsBodyPtr internal(GetImplementation(*this).GetDynamicsBody());
600 return DynamicsBody( internal.Get() );
602 return DynamicsBody();
606 Actor::Actor(Internal::Actor* internal)
607 : Constrainable(internal)
611 void UnparentAndReset( Actor& actor )