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_SET_SIZE = "set-size";
53 const char* const Actor::SIGNAL_ON_STAGE = "on-stage";
54 const char* const Actor::SIGNAL_OFF_STAGE = "off-stage";
56 const char* const Actor::ACTION_SHOW = "show";
57 const char* const Actor::ACTION_HIDE = "hide";
65 Internal::ActorPtr internal = Internal::Actor::New();
67 return Actor(internal.Get());
70 Actor Actor::DownCast( BaseHandle handle )
72 return Actor( dynamic_cast<Dali::Internal::Actor*>(handle.GetObjectPtr()) );
79 Actor::Actor(const Actor& copy)
84 Actor& Actor::operator=(const Actor& rhs)
86 BaseHandle::operator=(rhs);
90 const std::string& Actor::GetName() const
92 return GetImplementation(*this).GetName();
95 void Actor::SetName(const std::string& name)
97 GetImplementation(*this).SetName(name);
100 unsigned int Actor::GetId() const
102 return GetImplementation(*this).GetId();
105 bool Actor::IsRoot() const
107 return GetImplementation(*this).IsRoot();
110 bool Actor::OnStage() const
112 return GetImplementation(*this).OnStage();
115 bool Actor::IsLayer() const
117 return GetImplementation(*this).IsLayer();
120 Layer Actor::GetLayer()
122 return GetImplementation(*this).GetLayer();
125 void Actor::Add(Actor actor)
127 GetImplementation(*this).Add(GetImplementation(actor));
130 void Actor::Insert(unsigned int index, Actor actor)
132 GetImplementation(*this).Insert(index, GetImplementation(actor));
135 void Actor::Remove(Actor actor)
137 GetImplementation(*this).Remove(GetImplementation(actor));
140 void Actor::Unparent()
142 GetImplementation(*this).Unparent();
145 unsigned int Actor::GetChildCount() const
147 return GetImplementation(*this).GetChildCount();
150 Actor Actor::GetChildAt(unsigned int index) const
152 return GetImplementation(*this).GetChildAt(index);
155 Actor Actor::FindChildByName(const std::string& actorName)
157 Internal::ActorPtr child = GetImplementation(*this).FindChildByName(actorName);
158 return Actor(child.Get());
161 Actor Actor::FindChildByAlias(const std::string& actorAlias)
163 Actor child = GetImplementation(*this).FindChildByAlias(actorAlias);
167 Actor Actor::FindChildById(const unsigned int id)
169 Internal::ActorPtr child = GetImplementation(*this).FindChildById(id);
170 return Actor(child.Get());
173 Actor Actor::GetParent() const
175 Internal::Actor* parent = GetImplementation(*this).GetParent();
177 return Actor(parent);
180 void Actor::SetParentOrigin(const Vector3& origin)
182 GetImplementation(*this).SetParentOrigin(origin);
185 Vector3 Actor::GetCurrentParentOrigin() const
187 return GetImplementation(*this).GetCurrentParentOrigin();
190 void Actor::SetAnchorPoint(const Vector3& anchorPoint)
192 GetImplementation(*this).SetAnchorPoint(anchorPoint);
195 Vector3 Actor::GetCurrentAnchorPoint() const
197 return GetImplementation(*this).GetCurrentAnchorPoint();
200 void Actor::SetSize(float width, float height)
202 GetImplementation(*this).SetSize(width, height);
205 void Actor::SetSize(float width, float height, float depth)
207 GetImplementation(*this).SetSize(width, height, depth);
210 void Actor::SetSize(const Vector2& size)
212 GetImplementation(*this).SetSize(size);
215 void Actor::SetSize(const Vector3& size)
217 GetImplementation(*this).SetSize(size);
220 Vector3 Actor::GetSize() const
222 return GetImplementation(*this).GetSize();
225 Vector3 Actor::GetCurrentSize() const
227 return GetImplementation(*this).GetCurrentSize();
230 Vector3 Actor::GetNaturalSize() const
232 return GetImplementation(*this).GetNaturalSize();
235 void Actor::SetPosition(float x, float y)
237 GetImplementation(*this).SetPosition(x, y);
240 void Actor::SetPosition(float x, float y, float z)
242 GetImplementation(*this).SetPosition(x, y, z);
245 void Actor::SetPosition(const Vector3& position)
247 GetImplementation(*this).SetPosition(position);
250 void Actor::SetX(float x)
252 GetImplementation(*this).SetX(x);
255 void Actor::SetY(float y)
257 GetImplementation(*this).SetY(y);
260 void Actor::SetZ(float z)
262 GetImplementation(*this).SetZ(z);
265 void Actor::MoveBy(const Vector3& distance)
267 GetImplementation(*this).MoveBy(distance);
270 Vector3 Actor::GetCurrentPosition() const
272 return GetImplementation(*this).GetCurrentPosition();
275 Vector3 Actor::GetCurrentWorldPosition() const
277 return GetImplementation(*this).GetCurrentWorldPosition();
280 void Actor::SetPositionInheritanceMode( PositionInheritanceMode mode )
282 GetImplementation(*this).SetPositionInheritanceMode( mode );
285 PositionInheritanceMode Actor::GetPositionInheritanceMode() const
287 return GetImplementation(*this).GetPositionInheritanceMode();
290 void Actor::SetRotation(const Degree& angle, const Vector3& axis)
292 GetImplementation(*this).SetRotation(Radian(angle), axis);
295 void Actor::SetRotation(const Radian& angle, const Vector3& axis)
297 GetImplementation(*this).SetRotation(angle, axis);
300 void Actor::SetRotation(const Quaternion& rotation)
302 GetImplementation(*this).SetRotation(rotation);
305 void Actor::RotateBy(const Degree& angle, const Vector3& axis)
307 GetImplementation(*this).RotateBy(Radian(angle), axis);
310 void Actor::RotateBy(const Radian& angle, const Vector3& axis)
312 GetImplementation(*this).RotateBy(angle, axis);
315 void Actor::RotateBy(const Quaternion& relativeRotation)
317 GetImplementation(*this).RotateBy(relativeRotation);
320 Quaternion Actor::GetCurrentRotation() const
322 return GetImplementation(*this).GetCurrentRotation();
325 void Actor::SetInheritRotation(bool inherit)
327 GetImplementation(*this).SetInheritRotation(inherit);
330 bool Actor::IsRotationInherited() const
332 return GetImplementation(*this).IsRotationInherited();
335 Quaternion Actor::GetCurrentWorldRotation() const
337 return GetImplementation(*this).GetCurrentWorldRotation();
340 void Actor::SetScale(float scale)
342 GetImplementation(*this).SetScale(scale);
345 void Actor::SetScale(float scaleX, float scaleY, float scaleZ)
347 GetImplementation(*this).SetScale(scaleX, scaleY, scaleZ);
350 void Actor::SetScale(const Vector3& scale)
352 GetImplementation(*this).SetScale(scale);
355 void Actor::ScaleBy(const Vector3& relativeScale)
357 GetImplementation(*this).ScaleBy(relativeScale);
360 Vector3 Actor::GetCurrentScale() const
362 return GetImplementation(*this).GetCurrentScale();
365 Vector3 Actor::GetCurrentWorldScale() const
367 return GetImplementation(*this).GetCurrentWorldScale();
370 void Actor::SetInheritScale( bool inherit )
372 GetImplementation(*this).SetInheritScale( inherit );
375 bool Actor::IsScaleInherited() const
377 return GetImplementation(*this).IsScaleInherited();
380 void Actor::SetSizeMode(SizeMode mode)
382 GetImplementation(*this).SetSizeMode(mode);
385 SizeMode Actor::GetSizeMode() const
387 return GetImplementation(*this).GetSizeMode();
390 void Actor::SetSizeModeFactor(const Vector3& factor)
392 GetImplementation(*this).SetSizeModeFactor(factor);
395 Vector3 Actor::GetSizeModeFactor() const
397 return GetImplementation(*this).GetSizeModeFactor();
400 Matrix Actor::GetCurrentWorldMatrix() const
402 return GetImplementation(*this).GetCurrentWorldMatrix();
405 void Actor::SetVisible(bool visible)
407 GetImplementation(*this).SetVisible(visible);
410 bool Actor::IsVisible() const
412 return GetImplementation(*this).IsVisible();
415 void Actor::SetOpacity(float opacity)
417 GetImplementation(*this).SetOpacity(opacity);
420 void Actor::OpacityBy(float relativeOpacity)
422 GetImplementation(*this).OpacityBy(relativeOpacity);
425 float Actor::GetCurrentOpacity() const
427 return GetImplementation(*this).GetCurrentOpacity();
430 void Actor::SetColor(const Vector4& color)
432 GetImplementation(*this).SetColor(color);
435 void Actor::ColorBy(const Vector4& relativeColor)
437 GetImplementation(*this).ColorBy(relativeColor);
440 Vector4 Actor::GetCurrentColor() const
442 return GetImplementation(*this).GetCurrentColor();
445 void Actor::SetColorMode( ColorMode colorMode )
447 GetImplementation(*this).SetColorMode(colorMode);
450 ColorMode Actor::GetColorMode() const
452 return GetImplementation(*this).GetColorMode();
455 Vector4 Actor::GetCurrentWorldColor() const
457 return GetImplementation(*this).GetCurrentWorldColor();
460 void Actor::SetDrawMode( DrawMode::Type drawMode )
462 GetImplementation(*this).SetDrawMode( drawMode );
465 DrawMode::Type Actor::GetDrawMode() const
467 return GetImplementation(*this).GetDrawMode();
470 void Actor::SetSensitive(bool sensitive)
472 GetImplementation(*this).SetSensitive(sensitive);
475 bool Actor::IsSensitive() const
477 return GetImplementation(*this).IsSensitive();
480 bool Actor::ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const
482 return GetImplementation(*this).ScreenToLocal(localX, localY, screenX, screenY);
485 void Actor::SetLeaveRequired(bool required)
487 GetImplementation(*this).SetLeaveRequired(required);
490 bool Actor::GetLeaveRequired() const
492 return GetImplementation(*this).GetLeaveRequired();
495 void Actor::SetKeyboardFocusable( bool focusable )
497 GetImplementation(*this).SetKeyboardFocusable(focusable);
500 bool Actor::IsKeyboardFocusable() const
502 return GetImplementation(*this).IsKeyboardFocusable();
505 Actor::TouchSignalType& Actor::TouchedSignal()
507 return GetImplementation(*this).TouchedSignal();
510 Actor::HoverSignalType& Actor::HoveredSignal()
512 return GetImplementation(*this).HoveredSignal();
515 Actor::MouseWheelEventSignalType& Actor::MouseWheelEventSignal()
517 return GetImplementation(*this).MouseWheelEventSignal();
520 Actor::SetSizeSignalType& Actor::SetSizeSignal()
522 return GetImplementation(*this).SetSizeSignal();
525 Actor::OnStageSignalType& Actor::OnStageSignal()
527 return GetImplementation(*this).OnStageSignal();
530 Actor::OffStageSignalType& Actor::OffStageSignal()
532 return GetImplementation(*this).OffStageSignal();
535 DynamicsBody Actor::EnableDynamics(DynamicsBodyConfig bodyConfig)
537 #ifdef DYNAMICS_SUPPORT
538 Internal::DynamicsBodyConfig& internal = GetImplementation(bodyConfig);
540 Internal::DynamicsBodyPtr body( GetImplementation(*this).EnableDynamics( &internal ) );
542 return DynamicsBody( body.Get() );
544 return DynamicsBody();
548 DynamicsJoint Actor::AddDynamicsJoint( Actor attachedActor, const Vector3& offset )
550 #ifdef DYNAMICS_SUPPORT
551 Internal::ActorPtr internalActor( &GetImplementation(attachedActor) );
552 Internal::DynamicsJointPtr joint( GetImplementation(*this).AddDynamicsJoint( internalActor, offset) );
554 return DynamicsJoint( joint.Get() );
556 return DynamicsJoint();
560 DynamicsJoint Actor::AddDynamicsJoint( Actor attachedActor, const Vector3& offsetA, const Vector3& offsetB )
562 #ifdef DYNAMICS_SUPPORT
563 Internal::ActorPtr internalActor( &GetImplementation(attachedActor) );
564 Internal::DynamicsJointPtr joint( GetImplementation(*this).AddDynamicsJoint( internalActor, offsetA, offsetB) );
566 return DynamicsJoint( joint.Get() );
568 return DynamicsJoint();
572 int Actor::GetNumberOfJoints() const
574 #ifdef DYNAMICS_SUPPORT
575 return GetImplementation(*this).GetNumberOfJoints();
581 DynamicsJoint Actor::GetDynamicsJointByIndex( const int index )
583 #ifdef DYNAMICS_SUPPORT
584 Internal::DynamicsJointPtr joint( GetImplementation(*this).GetDynamicsJointByIndex( index ) );
586 return DynamicsJoint( joint.Get() );
588 return DynamicsJoint();
592 DynamicsJoint Actor::GetDynamicsJoint( Actor attachedActor )
594 #ifdef DYNAMICS_SUPPORT
595 Internal::DynamicsJointPtr joint( GetImplementation(*this).GetDynamicsJoint( &GetImplementation(attachedActor) ) );
597 return DynamicsJoint( joint.Get() );
599 return DynamicsJoint();
603 void Actor::RemoveDynamicsJoint( DynamicsJoint joint )
605 #ifdef DYNAMICS_SUPPORT
606 GetImplementation(*this).RemoveDynamicsJoint( &GetImplementation(joint) );
610 void Actor::DisableDynamics()
612 #ifdef DYNAMICS_SUPPORT
613 GetImplementation(*this).DisableDynamics();
617 DynamicsBody Actor::GetDynamicsBody()
619 #ifdef DYNAMICS_SUPPORT
620 Internal::DynamicsBodyPtr internal(GetImplementation(*this).GetDynamicsBody());
621 return DynamicsBody( internal.Get() );
623 return DynamicsBody();
627 Actor::Actor(Internal::Actor* internal)
628 : Constrainable(internal)
632 void UnparentAndReset( Actor& actor )