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/actor-attachments/actor-attachment-impl.h>
32 #include <dali/internal/event/animation/constraint-impl.h>
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>
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>
49 const char* const Actor::SIGNAL_TOUCHED = "touched";
50 const char* const Actor::SIGNAL_HOVERED = "hovered";
51 const char* const Actor::SIGNAL_MOUSE_WHEEL_EVENT = "mouse-wheel-event";
52 const char* const Actor::SIGNAL_ON_STAGE = "on-stage";
53 const char* const Actor::SIGNAL_OFF_STAGE = "off-stage";
55 const char* const Actor::ACTION_SHOW = "show";
56 const char* const Actor::ACTION_HIDE = "hide";
64 Internal::ActorPtr internal = Internal::Actor::New();
66 return Actor(internal.Get());
69 Actor Actor::DownCast( BaseHandle handle )
71 return Actor( dynamic_cast<Dali::Internal::Actor*>(handle.GetObjectPtr()) );
78 Actor::Actor(const Actor& copy)
83 Actor& Actor::operator=(const Actor& rhs)
85 BaseHandle::operator=(rhs);
89 const std::string& Actor::GetName() const
91 return GetImplementation(*this).GetName();
94 void Actor::SetName(const std::string& name)
96 GetImplementation(*this).SetName(name);
99 unsigned int Actor::GetId() const
101 return GetImplementation(*this).GetId();
104 bool Actor::IsRoot() const
106 return GetImplementation(*this).IsRoot();
109 bool Actor::OnStage() const
111 return GetImplementation(*this).OnStage();
114 bool Actor::IsLayer() const
116 return GetImplementation(*this).IsLayer();
119 Layer Actor::GetLayer()
121 return GetImplementation(*this).GetLayer();
124 void Actor::Add(Actor actor)
126 GetImplementation(*this).Add(GetImplementation(actor));
129 void Actor::Insert(unsigned int index, Actor actor)
131 GetImplementation(*this).Insert(index, GetImplementation(actor));
134 void Actor::Remove(Actor actor)
136 GetImplementation(*this).Remove(GetImplementation(actor));
139 void Actor::Unparent()
141 GetImplementation(*this).Unparent();
144 unsigned int Actor::GetChildCount() const
146 return GetImplementation(*this).GetChildCount();
149 Actor Actor::GetChildAt(unsigned int index) const
151 return GetImplementation(*this).GetChildAt(index);
154 Actor Actor::FindChildByName(const std::string& actorName)
156 Internal::ActorPtr child = GetImplementation(*this).FindChildByName(actorName);
157 return Actor(child.Get());
160 Actor Actor::FindChildByAlias(const std::string& actorAlias)
162 Actor child = GetImplementation(*this).FindChildByAlias(actorAlias);
166 Actor Actor::FindChildById(const unsigned int id)
168 Internal::ActorPtr child = GetImplementation(*this).FindChildById(id);
169 return Actor(child.Get());
172 Actor Actor::GetParent() const
174 Internal::Actor* parent = GetImplementation(*this).GetParent();
176 return Actor(parent);
179 void Actor::SetParentOrigin(const Vector3& origin)
181 GetImplementation(*this).SetParentOrigin(origin);
184 Vector3 Actor::GetCurrentParentOrigin() const
186 return GetImplementation(*this).GetCurrentParentOrigin();
189 void Actor::SetAnchorPoint(const Vector3& anchorPoint)
191 GetImplementation(*this).SetAnchorPoint(anchorPoint);
194 Vector3 Actor::GetCurrentAnchorPoint() const
196 return GetImplementation(*this).GetCurrentAnchorPoint();
199 void Actor::SetSize(float width, float height)
201 GetImplementation(*this).SetSize(width, height);
204 void Actor::SetSize(float width, float height, float depth)
206 GetImplementation(*this).SetSize(width, height, depth);
209 void Actor::SetSize(const Vector2& size)
211 GetImplementation(*this).SetSize(size);
214 void Actor::SetSize(const Vector3& size)
216 GetImplementation(*this).SetSize(size);
219 Vector3 Actor::GetSize() const
221 return GetImplementation(*this).GetSize();
224 Vector3 Actor::GetCurrentSize() const
226 return GetImplementation(*this).GetCurrentSize();
229 Vector3 Actor::GetNaturalSize() const
231 return GetImplementation(*this).GetNaturalSize();
234 void Actor::SetPosition(float x, float y)
236 GetImplementation(*this).SetPosition(x, y);
239 void Actor::SetPosition(float x, float y, float z)
241 GetImplementation(*this).SetPosition(x, y, z);
244 void Actor::SetPosition(const Vector3& position)
246 GetImplementation(*this).SetPosition(position);
249 void Actor::SetX(float x)
251 GetImplementation(*this).SetX(x);
254 void Actor::SetY(float y)
256 GetImplementation(*this).SetY(y);
259 void Actor::SetZ(float z)
261 GetImplementation(*this).SetZ(z);
264 void Actor::MoveBy(const Vector3& distance)
266 GetImplementation(*this).MoveBy(distance);
269 Vector3 Actor::GetCurrentPosition() const
271 return GetImplementation(*this).GetCurrentPosition();
274 Vector3 Actor::GetCurrentWorldPosition() const
276 return GetImplementation(*this).GetCurrentWorldPosition();
279 void Actor::SetPositionInheritanceMode( PositionInheritanceMode mode )
281 GetImplementation(*this).SetPositionInheritanceMode( mode );
284 PositionInheritanceMode Actor::GetPositionInheritanceMode() const
286 return GetImplementation(*this).GetPositionInheritanceMode();
289 void Actor::SetRotation(const Degree& angle, const Vector3& axis)
291 GetImplementation(*this).SetRotation(Radian(angle), axis);
294 void Actor::SetRotation(const Radian& angle, const Vector3& axis)
296 GetImplementation(*this).SetRotation(angle, axis);
299 void Actor::SetRotation(const Quaternion& rotation)
301 GetImplementation(*this).SetRotation(rotation);
304 void Actor::RotateBy(const Degree& angle, const Vector3& axis)
306 GetImplementation(*this).RotateBy(Radian(angle), axis);
309 void Actor::RotateBy(const Radian& angle, const Vector3& axis)
311 GetImplementation(*this).RotateBy(angle, axis);
314 void Actor::RotateBy(const Quaternion& relativeRotation)
316 GetImplementation(*this).RotateBy(relativeRotation);
319 Quaternion Actor::GetCurrentRotation() const
321 return GetImplementation(*this).GetCurrentRotation();
324 void Actor::SetInheritRotation(bool inherit)
326 GetImplementation(*this).SetInheritRotation(inherit);
329 bool Actor::IsRotationInherited() const
331 return GetImplementation(*this).IsRotationInherited();
334 Quaternion Actor::GetCurrentWorldRotation() const
336 return GetImplementation(*this).GetCurrentWorldRotation();
339 void Actor::SetScale(float scale)
341 GetImplementation(*this).SetScale(scale);
344 void Actor::SetScale(float scaleX, float scaleY, float scaleZ)
346 GetImplementation(*this).SetScale(scaleX, scaleY, scaleZ);
349 void Actor::SetScale(const Vector3& scale)
351 GetImplementation(*this).SetScale(scale);
354 void Actor::ScaleBy(const Vector3& relativeScale)
356 GetImplementation(*this).ScaleBy(relativeScale);
359 Vector3 Actor::GetCurrentScale() const
361 return GetImplementation(*this).GetCurrentScale();
364 Vector3 Actor::GetCurrentWorldScale() const
366 return GetImplementation(*this).GetCurrentWorldScale();
369 void Actor::SetInheritScale( bool inherit )
371 GetImplementation(*this).SetInheritScale( inherit );
374 bool Actor::IsScaleInherited() const
376 return GetImplementation(*this).IsScaleInherited();
379 void Actor::SetSizeMode(SizeMode mode)
381 GetImplementation(*this).SetSizeMode(mode);
384 SizeMode Actor::GetSizeMode() const
386 return GetImplementation(*this).GetSizeMode();
389 void Actor::SetSizeModeFactor(const Vector3& factor)
391 GetImplementation(*this).SetSizeModeFactor(factor);
394 Vector3 Actor::GetSizeModeFactor() const
396 return GetImplementation(*this).GetSizeModeFactor();
399 Matrix Actor::GetCurrentWorldMatrix() const
401 return GetImplementation(*this).GetCurrentWorldMatrix();
404 void Actor::SetVisible(bool visible)
406 GetImplementation(*this).SetVisible(visible);
409 bool Actor::IsVisible() const
411 return GetImplementation(*this).IsVisible();
414 void Actor::SetOpacity(float opacity)
416 GetImplementation(*this).SetOpacity(opacity);
419 void Actor::OpacityBy(float relativeOpacity)
421 GetImplementation(*this).OpacityBy(relativeOpacity);
424 float Actor::GetCurrentOpacity() const
426 return GetImplementation(*this).GetCurrentOpacity();
429 void Actor::SetColor(const Vector4& color)
431 GetImplementation(*this).SetColor(color);
434 void Actor::ColorBy(const Vector4& relativeColor)
436 GetImplementation(*this).ColorBy(relativeColor);
439 Vector4 Actor::GetCurrentColor() const
441 return GetImplementation(*this).GetCurrentColor();
444 void Actor::SetColorMode( ColorMode colorMode )
446 GetImplementation(*this).SetColorMode(colorMode);
449 ColorMode Actor::GetColorMode() const
451 return GetImplementation(*this).GetColorMode();
454 Vector4 Actor::GetCurrentWorldColor() const
456 return GetImplementation(*this).GetCurrentWorldColor();
459 void Actor::SetDrawMode( DrawMode::Type drawMode )
461 GetImplementation(*this).SetDrawMode( drawMode );
464 DrawMode::Type Actor::GetDrawMode() const
466 return GetImplementation(*this).GetDrawMode();
469 void Actor::SetSensitive(bool sensitive)
471 GetImplementation(*this).SetSensitive(sensitive);
474 bool Actor::IsSensitive() const
476 return GetImplementation(*this).IsSensitive();
479 bool Actor::ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const
481 return GetImplementation(*this).ScreenToLocal(localX, localY, screenX, screenY);
484 void Actor::SetLeaveRequired(bool required)
486 GetImplementation(*this).SetLeaveRequired(required);
489 bool Actor::GetLeaveRequired() const
491 return GetImplementation(*this).GetLeaveRequired();
494 void Actor::SetKeyboardFocusable( bool focusable )
496 GetImplementation(*this).SetKeyboardFocusable(focusable);
499 bool Actor::IsKeyboardFocusable() const
501 return GetImplementation(*this).IsKeyboardFocusable();
504 Actor::TouchSignalType& Actor::TouchedSignal()
506 return GetImplementation(*this).TouchedSignal();
509 Actor::HoverSignalType& Actor::HoveredSignal()
511 return GetImplementation(*this).HoveredSignal();
514 Actor::MouseWheelEventSignalType& Actor::MouseWheelEventSignal()
516 return GetImplementation(*this).MouseWheelEventSignal();
519 Actor::OnStageSignalType& Actor::OnStageSignal()
521 return GetImplementation(*this).OnStageSignal();
524 Actor::OffStageSignalType& Actor::OffStageSignal()
526 return GetImplementation(*this).OffStageSignal();
529 DynamicsBody Actor::EnableDynamics(DynamicsBodyConfig bodyConfig)
531 #ifdef DYNAMICS_SUPPORT
532 Internal::DynamicsBodyConfig& internal = GetImplementation(bodyConfig);
534 Internal::DynamicsBodyPtr body( GetImplementation(*this).EnableDynamics( &internal ) );
536 return DynamicsBody( body.Get() );
538 return DynamicsBody();
542 DynamicsJoint Actor::AddDynamicsJoint( Actor attachedActor, const Vector3& offset )
544 #ifdef DYNAMICS_SUPPORT
545 Internal::ActorPtr internalActor( &GetImplementation(attachedActor) );
546 Internal::DynamicsJointPtr joint( GetImplementation(*this).AddDynamicsJoint( internalActor, offset) );
548 return DynamicsJoint( joint.Get() );
550 return DynamicsJoint();
554 DynamicsJoint Actor::AddDynamicsJoint( Actor attachedActor, const Vector3& offsetA, const Vector3& offsetB )
556 #ifdef DYNAMICS_SUPPORT
557 Internal::ActorPtr internalActor( &GetImplementation(attachedActor) );
558 Internal::DynamicsJointPtr joint( GetImplementation(*this).AddDynamicsJoint( internalActor, offsetA, offsetB) );
560 return DynamicsJoint( joint.Get() );
562 return DynamicsJoint();
566 int Actor::GetNumberOfJoints() const
568 #ifdef DYNAMICS_SUPPORT
569 return GetImplementation(*this).GetNumberOfJoints();
575 DynamicsJoint Actor::GetDynamicsJointByIndex( const int index )
577 #ifdef DYNAMICS_SUPPORT
578 Internal::DynamicsJointPtr joint( GetImplementation(*this).GetDynamicsJointByIndex( index ) );
580 return DynamicsJoint( joint.Get() );
582 return DynamicsJoint();
586 DynamicsJoint Actor::GetDynamicsJoint( Actor attachedActor )
588 #ifdef DYNAMICS_SUPPORT
589 Internal::DynamicsJointPtr joint( GetImplementation(*this).GetDynamicsJoint( &GetImplementation(attachedActor) ) );
591 return DynamicsJoint( joint.Get() );
593 return DynamicsJoint();
597 void Actor::RemoveDynamicsJoint( DynamicsJoint joint )
599 #ifdef DYNAMICS_SUPPORT
600 GetImplementation(*this).RemoveDynamicsJoint( &GetImplementation(joint) );
604 void Actor::DisableDynamics()
606 #ifdef DYNAMICS_SUPPORT
607 GetImplementation(*this).DisableDynamics();
611 DynamicsBody Actor::GetDynamicsBody()
613 #ifdef DYNAMICS_SUPPORT
614 Internal::DynamicsBodyPtr internal(GetImplementation(*this).GetDynamicsBody());
615 return DynamicsBody( internal.Get() );
617 return DynamicsBody();
621 Actor::Actor(Internal::Actor* internal)
622 : Constrainable(internal)
626 void UnparentAndReset( Actor& actor )