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>
51 const char* const Actor::SIGNAL_TOUCHED = "touched";
52 const char* const Actor::SIGNAL_HOVERED = "hovered";
53 const char* const Actor::SIGNAL_MOUSE_WHEEL_EVENT = "mouse-wheel-event";
54 const char* const Actor::SIGNAL_SET_SIZE = "set-size";
55 const char* const Actor::SIGNAL_ON_STAGE = "on-stage";
56 const char* const Actor::SIGNAL_OFF_STAGE = "off-stage";
58 const char* const Actor::ACTION_SHOW = "show";
59 const char* const Actor::ACTION_HIDE = "hide";
67 Internal::ActorPtr internal = Internal::Actor::New();
69 return Actor(internal.Get());
72 Actor Actor::DownCast( BaseHandle handle )
74 return Actor( dynamic_cast<Dali::Internal::Actor*>(handle.GetObjectPtr()) );
81 Actor::Actor(const Actor& copy)
86 Actor& Actor::operator=(const Actor& rhs)
88 BaseHandle::operator=(rhs);
92 const std::string& Actor::GetName() const
94 return GetImplementation(*this).GetName();
97 void Actor::SetName(const std::string& name)
99 GetImplementation(*this).SetName(name);
102 unsigned int Actor::GetId() const
104 return GetImplementation(*this).GetId();
107 bool Actor::IsRoot() const
109 return GetImplementation(*this).IsRoot();
112 bool Actor::OnStage() const
114 return GetImplementation(*this).OnStage();
117 bool Actor::IsLayer() const
119 return GetImplementation(*this).IsLayer();
122 Layer Actor::GetLayer()
124 return GetImplementation(*this).GetLayer();
127 void Actor::Add(Actor actor)
129 GetImplementation(*this).Add(GetImplementation(actor));
132 void Actor::Insert(unsigned int index, Actor actor)
134 GetImplementation(*this).Insert(index, GetImplementation(actor));
137 void Actor::Remove(Actor actor)
139 GetImplementation(*this).Remove(GetImplementation(actor));
142 void Actor::Unparent()
144 GetImplementation(*this).Unparent();
147 unsigned int Actor::GetChildCount() const
149 return GetImplementation(*this).GetChildCount();
152 Actor Actor::GetChildAt(unsigned int index) const
154 return GetImplementation(*this).GetChildAt(index);
157 Actor Actor::FindChildByName(const std::string& actorName)
159 Internal::ActorPtr child = GetImplementation(*this).FindChildByName(actorName);
160 return Actor(child.Get());
163 Actor Actor::FindChildByAlias(const std::string& actorAlias)
165 Actor child = GetImplementation(*this).FindChildByAlias(actorAlias);
169 Actor Actor::FindChildById(const unsigned int id)
171 Internal::ActorPtr child = GetImplementation(*this).FindChildById(id);
172 return Actor(child.Get());
175 Actor Actor::GetParent() const
177 Internal::Actor* parent = GetImplementation(*this).GetParent();
179 return Actor(parent);
182 void Actor::SetParentOrigin(const Vector3& origin)
184 GetImplementation(*this).SetParentOrigin(origin);
187 Vector3 Actor::GetCurrentParentOrigin() const
189 return GetImplementation(*this).GetCurrentParentOrigin();
192 void Actor::SetAnchorPoint(const Vector3& anchorPoint)
194 GetImplementation(*this).SetAnchorPoint(anchorPoint);
197 Vector3 Actor::GetCurrentAnchorPoint() const
199 return GetImplementation(*this).GetCurrentAnchorPoint();
202 void Actor::SetSize(float width, float height)
204 GetImplementation(*this).SetSize(width, height);
207 void Actor::SetSize(float width, float height, float depth)
209 GetImplementation(*this).SetSize(width, height, depth);
212 void Actor::SetSize(const Vector2& size)
214 GetImplementation(*this).SetSize(size);
217 void Actor::SetSize(const Vector3& size)
219 GetImplementation(*this).SetSize(size);
222 Vector3 Actor::GetSize() const
224 return GetImplementation(*this).GetSize();
227 Vector3 Actor::GetCurrentSize() const
229 return GetImplementation(*this).GetCurrentSize();
232 Vector3 Actor::GetNaturalSize() const
234 return GetImplementation(*this).GetNaturalSize();
237 void Actor::SetPosition(float x, float y)
239 GetImplementation(*this).SetPosition(x, y);
242 void Actor::SetPosition(float x, float y, float z)
244 GetImplementation(*this).SetPosition(x, y, z);
247 void Actor::SetPosition(const Vector3& position)
249 GetImplementation(*this).SetPosition(position);
252 void Actor::SetX(float x)
254 GetImplementation(*this).SetX(x);
257 void Actor::SetY(float y)
259 GetImplementation(*this).SetY(y);
262 void Actor::SetZ(float z)
264 GetImplementation(*this).SetZ(z);
267 void Actor::MoveBy(const Vector3& distance)
269 GetImplementation(*this).MoveBy(distance);
272 Vector3 Actor::GetCurrentPosition() const
274 return GetImplementation(*this).GetCurrentPosition();
277 Vector3 Actor::GetCurrentWorldPosition() const
279 return GetImplementation(*this).GetCurrentWorldPosition();
282 void Actor::SetPositionInheritanceMode( PositionInheritanceMode mode )
284 GetImplementation(*this).SetPositionInheritanceMode( mode );
287 PositionInheritanceMode Actor::GetPositionInheritanceMode() const
289 return GetImplementation(*this).GetPositionInheritanceMode();
292 void Actor::SetRotation(const Degree& angle, const Vector3& axis)
294 GetImplementation(*this).SetRotation(Radian(angle), axis);
297 void Actor::SetRotation(const Radian& angle, const Vector3& axis)
299 GetImplementation(*this).SetRotation(angle, axis);
302 void Actor::SetRotation(const Quaternion& rotation)
304 GetImplementation(*this).SetRotation(rotation);
307 void Actor::RotateBy(const Degree& angle, const Vector3& axis)
309 GetImplementation(*this).RotateBy(Radian(angle), axis);
312 void Actor::RotateBy(const Radian& angle, const Vector3& axis)
314 GetImplementation(*this).RotateBy(angle, axis);
317 void Actor::RotateBy(const Quaternion& relativeRotation)
319 GetImplementation(*this).RotateBy(relativeRotation);
322 Quaternion Actor::GetCurrentRotation() const
324 return GetImplementation(*this).GetCurrentRotation();
327 void Actor::SetInheritRotation(bool inherit)
329 GetImplementation(*this).SetInheritRotation(inherit);
332 bool Actor::IsRotationInherited() const
334 return GetImplementation(*this).IsRotationInherited();
337 Quaternion Actor::GetCurrentWorldRotation() const
339 return GetImplementation(*this).GetCurrentWorldRotation();
342 void Actor::SetScale(float scale)
344 GetImplementation(*this).SetScale(scale);
347 void Actor::SetScale(float scaleX, float scaleY, float scaleZ)
349 GetImplementation(*this).SetScale(scaleX, scaleY, scaleZ);
352 void Actor::SetScale(const Vector3& scale)
354 GetImplementation(*this).SetScale(scale);
357 void Actor::ScaleBy(const Vector3& relativeScale)
359 GetImplementation(*this).ScaleBy(relativeScale);
362 Vector3 Actor::GetCurrentScale() const
364 return GetImplementation(*this).GetCurrentScale();
367 Vector3 Actor::GetCurrentWorldScale() const
369 return GetImplementation(*this).GetCurrentWorldScale();
372 void Actor::SetInheritScale( bool inherit )
374 GetImplementation(*this).SetInheritScale( inherit );
377 bool Actor::IsScaleInherited() const
379 return GetImplementation(*this).IsScaleInherited();
382 Matrix Actor::GetCurrentWorldMatrix() const
384 return GetImplementation(*this).GetCurrentWorldMatrix();
387 void Actor::SetVisible(bool visible)
389 GetImplementation(*this).SetVisible(visible);
392 bool Actor::IsVisible() const
394 return GetImplementation(*this).IsVisible();
397 void Actor::SetOpacity(float opacity)
399 GetImplementation(*this).SetOpacity(opacity);
402 void Actor::OpacityBy(float relativeOpacity)
404 GetImplementation(*this).OpacityBy(relativeOpacity);
407 float Actor::GetCurrentOpacity() const
409 return GetImplementation(*this).GetCurrentOpacity();
412 void Actor::SetColor(const Vector4& color)
414 GetImplementation(*this).SetColor(color);
417 void Actor::ColorBy(const Vector4& relativeColor)
419 GetImplementation(*this).ColorBy(relativeColor);
422 Vector4 Actor::GetCurrentColor() const
424 return GetImplementation(*this).GetCurrentColor();
427 void Actor::SetColorMode( ColorMode colorMode )
429 GetImplementation(*this).SetColorMode(colorMode);
432 ColorMode Actor::GetColorMode() const
434 return GetImplementation(*this).GetColorMode();
437 Vector4 Actor::GetCurrentWorldColor() const
439 return GetImplementation(*this).GetCurrentWorldColor();
442 void Actor::SetDrawMode( DrawMode::Type drawMode )
444 GetImplementation(*this).SetDrawMode( drawMode );
447 DrawMode::Type Actor::GetDrawMode() const
449 return GetImplementation(*this).GetDrawMode();
452 void Actor::SetSensitive(bool sensitive)
454 GetImplementation(*this).SetSensitive(sensitive);
457 bool Actor::IsSensitive() const
459 return GetImplementation(*this).IsSensitive();
462 bool Actor::ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const
464 return GetImplementation(*this).ScreenToLocal(localX, localY, screenX, screenY);
467 void Actor::SetLeaveRequired(bool required)
469 GetImplementation(*this).SetLeaveRequired(required);
472 bool Actor::GetLeaveRequired() const
474 return GetImplementation(*this).GetLeaveRequired();
477 void Actor::SetKeyboardFocusable( bool focusable )
479 GetImplementation(*this).SetKeyboardFocusable(focusable);
482 bool Actor::IsKeyboardFocusable() const
484 return GetImplementation(*this).IsKeyboardFocusable();
487 Actor::TouchSignalV2& Actor::TouchedSignal()
489 return GetImplementation(*this).TouchedSignal();
492 Actor::HoverSignalV2& Actor::HoveredSignal()
494 return GetImplementation(*this).HoveredSignal();
497 Actor::MouseWheelEventSignalV2& Actor::MouseWheelEventSignal()
499 return GetImplementation(*this).MouseWheelEventSignal();
502 Actor::SetSizeSignalV2& Actor::SetSizeSignal()
504 return GetImplementation(*this).SetSizeSignal();
507 Actor::OnStageSignalV2& Actor::OnStageSignal()
509 return GetImplementation(*this).OnStageSignal();
512 Actor::OffStageSignalV2& Actor::OffStageSignal()
514 return GetImplementation(*this).OffStageSignal();
517 DynamicsBody Actor::EnableDynamics(DynamicsBodyConfig bodyConfig)
519 #ifdef DYNAMICS_SUPPORT
520 Internal::DynamicsBodyConfig& internal = GetImplementation(bodyConfig);
522 Internal::DynamicsBodyPtr body( GetImplementation(*this).EnableDynamics( &internal ) );
524 return DynamicsBody( body.Get() );
526 return DynamicsBody();
530 DynamicsJoint Actor::AddDynamicsJoint( Actor attachedActor, const Vector3& offset )
532 #ifdef DYNAMICS_SUPPORT
533 Internal::ActorPtr internalActor( &GetImplementation(attachedActor) );
534 Internal::DynamicsJointPtr joint( GetImplementation(*this).AddDynamicsJoint( internalActor, offset) );
536 return DynamicsJoint( joint.Get() );
538 return DynamicsJoint();
542 DynamicsJoint Actor::AddDynamicsJoint( Actor attachedActor, const Vector3& offsetA, const Vector3& offsetB )
544 #ifdef DYNAMICS_SUPPORT
545 Internal::ActorPtr internalActor( &GetImplementation(attachedActor) );
546 Internal::DynamicsJointPtr joint( GetImplementation(*this).AddDynamicsJoint( internalActor, offsetA, offsetB) );
548 return DynamicsJoint( joint.Get() );
550 return DynamicsJoint();
554 const int Actor::GetNumberOfJoints() const
556 #ifdef DYNAMICS_SUPPORT
557 return GetImplementation(*this).GetNumberOfJoints();
563 DynamicsJoint Actor::GetDynamicsJointByIndex( const int index )
565 #ifdef DYNAMICS_SUPPORT
566 Internal::DynamicsJointPtr joint( GetImplementation(*this).GetDynamicsJointByIndex( index ) );
568 return DynamicsJoint( joint.Get() );
570 return DynamicsJoint();
574 DynamicsJoint Actor::GetDynamicsJoint( Actor attachedActor )
576 #ifdef DYNAMICS_SUPPORT
577 Internal::DynamicsJointPtr joint( GetImplementation(*this).GetDynamicsJoint( &GetImplementation(attachedActor) ) );
579 return DynamicsJoint( joint.Get() );
581 return DynamicsJoint();
585 void Actor::RemoveDynamicsJoint( DynamicsJoint joint )
587 #ifdef DYNAMICS_SUPPORT
588 GetImplementation(*this).RemoveDynamicsJoint( &GetImplementation(joint) );
592 void Actor::DisableDynamics()
594 #ifdef DYNAMICS_SUPPORT
595 GetImplementation(*this).DisableDynamics();
599 DynamicsBody Actor::GetDynamicsBody()
601 #ifdef DYNAMICS_SUPPORT
602 Internal::DynamicsBodyPtr internal(GetImplementation(*this).GetDynamicsBody());
603 return DynamicsBody( internal.Get() );
605 return DynamicsBody();
609 Actor::Actor(Internal::Actor* internal)
610 : Constrainable(internal)
614 void UnparentAndReset( Actor& actor )