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>
55 Internal::ActorPtr internal = Internal::Actor::New();
57 return Actor(internal.Get());
60 Actor Actor::DownCast( BaseHandle handle )
62 return Actor( dynamic_cast<Dali::Internal::Actor*>(handle.GetObjectPtr()) );
69 Actor::Actor(const Actor& copy)
74 Actor& Actor::operator=(const Actor& rhs)
76 BaseHandle::operator=(rhs);
80 const std::string& Actor::GetName() const
82 return GetImplementation(*this).GetName();
85 void Actor::SetName(const std::string& name)
87 GetImplementation(*this).SetName(name);
90 unsigned int Actor::GetId() const
92 return GetImplementation(*this).GetId();
95 bool Actor::IsRoot() const
97 return GetImplementation(*this).IsRoot();
100 bool Actor::OnStage() const
102 return GetImplementation(*this).OnStage();
105 bool Actor::IsLayer() const
107 return GetImplementation(*this).IsLayer();
110 Layer Actor::GetLayer()
112 return GetImplementation(*this).GetLayer();
115 void Actor::Add(Actor actor)
117 GetImplementation(*this).Add(GetImplementation(actor));
120 void Actor::Insert(unsigned int index, Actor actor)
122 GetImplementation(*this).Insert(index, GetImplementation(actor));
125 void Actor::Remove(Actor actor)
127 GetImplementation(*this).Remove(GetImplementation(actor));
130 void Actor::Unparent()
132 GetImplementation(*this).Unparent();
135 unsigned int Actor::GetChildCount() const
137 return GetImplementation(*this).GetChildCount();
140 Actor Actor::GetChildAt(unsigned int index) const
142 return GetImplementation(*this).GetChildAt(index);
145 Actor Actor::FindChildByName(const std::string& actorName)
147 Internal::ActorPtr child = GetImplementation(*this).FindChildByName(actorName);
148 return Actor(child.Get());
151 Actor Actor::FindChildByAlias(const std::string& actorAlias)
153 Actor child = GetImplementation(*this).FindChildByAlias(actorAlias);
157 Actor Actor::FindChildById(const unsigned int id)
159 Internal::ActorPtr child = GetImplementation(*this).FindChildById(id);
160 return Actor(child.Get());
163 Actor Actor::GetParent() const
165 Internal::Actor* parent = GetImplementation(*this).GetParent();
167 return Actor(parent);
170 void Actor::SetParentOrigin(const Vector3& origin)
172 GetImplementation(*this).SetParentOrigin(origin);
175 Vector3 Actor::GetCurrentParentOrigin() const
177 return GetImplementation(*this).GetCurrentParentOrigin();
180 void Actor::SetAnchorPoint(const Vector3& anchorPoint)
182 GetImplementation(*this).SetAnchorPoint(anchorPoint);
185 Vector3 Actor::GetCurrentAnchorPoint() const
187 return GetImplementation(*this).GetCurrentAnchorPoint();
190 void Actor::SetSize(float width, float height)
192 GetImplementation(*this).SetSize(width, height);
195 void Actor::SetSize(float width, float height, float depth)
197 GetImplementation(*this).SetSize(width, height, depth);
200 void Actor::SetSize(const Vector2& size)
202 GetImplementation(*this).SetSize(size);
205 void Actor::SetSize(const Vector3& size)
207 GetImplementation(*this).SetSize(size);
210 Vector3 Actor::GetSize() const
212 return GetImplementation(*this).GetSize();
215 Vector3 Actor::GetCurrentSize() const
217 return GetImplementation(*this).GetCurrentSize();
220 Vector3 Actor::GetNaturalSize() const
222 return GetImplementation(*this).GetNaturalSize();
225 void Actor::SetPosition(float x, float y)
227 GetImplementation(*this).SetPosition(x, y);
230 void Actor::SetPosition(float x, float y, float z)
232 GetImplementation(*this).SetPosition(x, y, z);
235 void Actor::SetPosition(const Vector3& position)
237 GetImplementation(*this).SetPosition(position);
240 void Actor::SetX(float x)
242 GetImplementation(*this).SetX(x);
245 void Actor::SetY(float y)
247 GetImplementation(*this).SetY(y);
250 void Actor::SetZ(float z)
252 GetImplementation(*this).SetZ(z);
255 void Actor::MoveBy(const Vector3& distance)
257 GetImplementation(*this).MoveBy(distance);
260 Vector3 Actor::GetCurrentPosition() const
262 return GetImplementation(*this).GetCurrentPosition();
265 Vector3 Actor::GetCurrentWorldPosition() const
267 return GetImplementation(*this).GetCurrentWorldPosition();
270 void Actor::SetPositionInheritanceMode( PositionInheritanceMode mode )
272 GetImplementation(*this).SetPositionInheritanceMode( mode );
275 PositionInheritanceMode Actor::GetPositionInheritanceMode() const
277 return GetImplementation(*this).GetPositionInheritanceMode();
280 void Actor::SetRotation(const Degree& angle, const Vector3& axis)
282 GetImplementation(*this).SetRotation(Radian(angle), axis);
285 void Actor::SetRotation(const Radian& angle, const Vector3& axis)
287 GetImplementation(*this).SetRotation(angle, axis);
290 void Actor::SetRotation(const Quaternion& rotation)
292 GetImplementation(*this).SetRotation(rotation);
295 void Actor::RotateBy(const Degree& angle, const Vector3& axis)
297 GetImplementation(*this).RotateBy(Radian(angle), axis);
300 void Actor::RotateBy(const Radian& angle, const Vector3& axis)
302 GetImplementation(*this).RotateBy(angle, axis);
305 void Actor::RotateBy(const Quaternion& relativeRotation)
307 GetImplementation(*this).RotateBy(relativeRotation);
310 Quaternion Actor::GetCurrentRotation() const
312 return GetImplementation(*this).GetCurrentRotation();
315 void Actor::SetInheritRotation(bool inherit)
317 GetImplementation(*this).SetInheritRotation(inherit);
320 bool Actor::IsRotationInherited() const
322 return GetImplementation(*this).IsRotationInherited();
325 Quaternion Actor::GetCurrentWorldRotation() const
327 return GetImplementation(*this).GetCurrentWorldRotation();
330 void Actor::SetScale(float scale)
332 GetImplementation(*this).SetScale(scale);
335 void Actor::SetScale(float scaleX, float scaleY, float scaleZ)
337 GetImplementation(*this).SetScale(scaleX, scaleY, scaleZ);
340 void Actor::SetScale(const Vector3& scale)
342 GetImplementation(*this).SetScale(scale);
345 void Actor::ScaleBy(const Vector3& relativeScale)
347 GetImplementation(*this).ScaleBy(relativeScale);
350 Vector3 Actor::GetCurrentScale() const
352 return GetImplementation(*this).GetCurrentScale();
355 Vector3 Actor::GetCurrentWorldScale() const
357 return GetImplementation(*this).GetCurrentWorldScale();
360 void Actor::SetInheritScale( bool inherit )
362 GetImplementation(*this).SetInheritScale( inherit );
365 bool Actor::IsScaleInherited() const
367 return GetImplementation(*this).IsScaleInherited();
370 void Actor::SetSizeMode(SizeMode mode)
372 GetImplementation(*this).SetSizeMode(mode);
375 SizeMode Actor::GetSizeMode() const
377 return GetImplementation(*this).GetSizeMode();
380 void Actor::SetSizeModeFactor(const Vector3& factor)
382 GetImplementation(*this).SetSizeModeFactor(factor);
385 Vector3 Actor::GetSizeModeFactor() const
387 return GetImplementation(*this).GetSizeModeFactor();
390 Matrix Actor::GetCurrentWorldMatrix() const
392 return GetImplementation(*this).GetCurrentWorldMatrix();
395 void Actor::SetVisible(bool visible)
397 GetImplementation(*this).SetVisible(visible);
400 bool Actor::IsVisible() const
402 return GetImplementation(*this).IsVisible();
405 void Actor::SetOpacity(float opacity)
407 GetImplementation(*this).SetOpacity(opacity);
410 void Actor::OpacityBy(float relativeOpacity)
412 GetImplementation(*this).OpacityBy(relativeOpacity);
415 float Actor::GetCurrentOpacity() const
417 return GetImplementation(*this).GetCurrentOpacity();
420 void Actor::SetColor(const Vector4& color)
422 GetImplementation(*this).SetColor(color);
425 void Actor::ColorBy(const Vector4& relativeColor)
427 GetImplementation(*this).ColorBy(relativeColor);
430 Vector4 Actor::GetCurrentColor() const
432 return GetImplementation(*this).GetCurrentColor();
435 void Actor::SetColorMode( ColorMode colorMode )
437 GetImplementation(*this).SetColorMode(colorMode);
440 ColorMode Actor::GetColorMode() const
442 return GetImplementation(*this).GetColorMode();
445 Vector4 Actor::GetCurrentWorldColor() const
447 return GetImplementation(*this).GetCurrentWorldColor();
450 void Actor::SetDrawMode( DrawMode::Type drawMode )
452 GetImplementation(*this).SetDrawMode( drawMode );
455 DrawMode::Type Actor::GetDrawMode() const
457 return GetImplementation(*this).GetDrawMode();
460 void Actor::SetSensitive(bool sensitive)
462 GetImplementation(*this).SetSensitive(sensitive);
465 bool Actor::IsSensitive() const
467 return GetImplementation(*this).IsSensitive();
470 bool Actor::ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const
472 return GetImplementation(*this).ScreenToLocal(localX, localY, screenX, screenY);
475 void Actor::SetLeaveRequired(bool required)
477 GetImplementation(*this).SetLeaveRequired(required);
480 bool Actor::GetLeaveRequired() const
482 return GetImplementation(*this).GetLeaveRequired();
485 void Actor::SetKeyboardFocusable( bool focusable )
487 GetImplementation(*this).SetKeyboardFocusable(focusable);
490 bool Actor::IsKeyboardFocusable() const
492 return GetImplementation(*this).IsKeyboardFocusable();
495 Actor::TouchSignalType& Actor::TouchedSignal()
497 return GetImplementation(*this).TouchedSignal();
500 Actor::HoverSignalType& Actor::HoveredSignal()
502 return GetImplementation(*this).HoveredSignal();
505 Actor::MouseWheelEventSignalType& Actor::MouseWheelEventSignal()
507 return GetImplementation(*this).MouseWheelEventSignal();
510 Actor::OnStageSignalType& Actor::OnStageSignal()
512 return GetImplementation(*this).OnStageSignal();
515 Actor::OffStageSignalType& Actor::OffStageSignal()
517 return GetImplementation(*this).OffStageSignal();
520 DynamicsBody Actor::EnableDynamics(DynamicsBodyConfig bodyConfig)
522 #ifdef DYNAMICS_SUPPORT
523 Internal::DynamicsBodyConfig& internal = GetImplementation(bodyConfig);
525 Internal::DynamicsBodyPtr body( GetImplementation(*this).EnableDynamics( &internal ) );
527 return DynamicsBody( body.Get() );
529 return DynamicsBody();
533 DynamicsJoint Actor::AddDynamicsJoint( Actor attachedActor, const Vector3& offset )
535 #ifdef DYNAMICS_SUPPORT
536 Internal::ActorPtr internalActor( &GetImplementation(attachedActor) );
537 Internal::DynamicsJointPtr joint( GetImplementation(*this).AddDynamicsJoint( internalActor, offset) );
539 return DynamicsJoint( joint.Get() );
541 return DynamicsJoint();
545 DynamicsJoint Actor::AddDynamicsJoint( Actor attachedActor, const Vector3& offsetA, const Vector3& offsetB )
547 #ifdef DYNAMICS_SUPPORT
548 Internal::ActorPtr internalActor( &GetImplementation(attachedActor) );
549 Internal::DynamicsJointPtr joint( GetImplementation(*this).AddDynamicsJoint( internalActor, offsetA, offsetB) );
551 return DynamicsJoint( joint.Get() );
553 return DynamicsJoint();
557 int Actor::GetNumberOfJoints() const
559 #ifdef DYNAMICS_SUPPORT
560 return GetImplementation(*this).GetNumberOfJoints();
566 DynamicsJoint Actor::GetDynamicsJointByIndex( const int index )
568 #ifdef DYNAMICS_SUPPORT
569 Internal::DynamicsJointPtr joint( GetImplementation(*this).GetDynamicsJointByIndex( index ) );
571 return DynamicsJoint( joint.Get() );
573 return DynamicsJoint();
577 DynamicsJoint Actor::GetDynamicsJoint( Actor attachedActor )
579 #ifdef DYNAMICS_SUPPORT
580 Internal::DynamicsJointPtr joint( GetImplementation(*this).GetDynamicsJoint( &GetImplementation(attachedActor) ) );
582 return DynamicsJoint( joint.Get() );
584 return DynamicsJoint();
588 void Actor::RemoveDynamicsJoint( DynamicsJoint joint )
590 #ifdef DYNAMICS_SUPPORT
591 GetImplementation(*this).RemoveDynamicsJoint( &GetImplementation(joint) );
595 void Actor::DisableDynamics()
597 #ifdef DYNAMICS_SUPPORT
598 GetImplementation(*this).DisableDynamics();
602 DynamicsBody Actor::GetDynamicsBody()
604 #ifdef DYNAMICS_SUPPORT
605 Internal::DynamicsBodyPtr internal(GetImplementation(*this).GetDynamicsBody());
606 return DynamicsBody( internal.Get() );
608 return DynamicsBody();
612 Actor::Actor(Internal::Actor* internal)
613 : Constrainable(internal)
617 void UnparentAndReset( Actor& actor )