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_MOUSE_WHEEL_EVENT = "mouse-wheel-event";
53 const char* const Actor::SIGNAL_SET_SIZE = "set-size";
54 const char* const Actor::SIGNAL_ON_STAGE = "on-stage";
55 const char* const Actor::SIGNAL_OFF_STAGE = "off-stage";
57 const char* const Actor::ACTION_SHOW = "show";
58 const char* const Actor::ACTION_HIDE = "hide";
66 Internal::ActorPtr internal = Internal::Actor::New();
68 return Actor(internal.Get());
71 Actor Actor::DownCast( BaseHandle handle )
73 return Actor( dynamic_cast<Dali::Internal::Actor*>(handle.GetObjectPtr()) );
80 Actor::Actor(const Actor& copy)
85 Actor& Actor::operator=(const Actor& rhs)
87 BaseHandle::operator=(rhs);
91 Actor& Actor::operator=(BaseHandle::NullType* rhs)
93 DALI_ASSERT_ALWAYS( (rhs == NULL) && "Can only assign NULL pointer to handle");
98 const std::string& Actor::GetName() const
100 return GetImplementation(*this).GetName();
103 void Actor::SetName(const std::string& name)
105 GetImplementation(*this).SetName(name);
108 unsigned int Actor::GetId() const
110 return GetImplementation(*this).GetId();
113 bool Actor::IsRoot() const
115 return GetImplementation(*this).IsRoot();
118 bool Actor::OnStage() const
120 return GetImplementation(*this).OnStage();
123 bool Actor::IsLayer() const
125 return GetImplementation(*this).IsLayer();
128 Layer Actor::GetLayer()
130 return GetImplementation(*this).GetLayer();
133 void Actor::Add(Actor actor)
135 GetImplementation(*this).Add(GetImplementation(actor));
138 void Actor::Insert(unsigned int index, Actor actor)
140 GetImplementation(*this).Insert(index, GetImplementation(actor));
143 void Actor::Remove(Actor actor)
145 GetImplementation(*this).Remove(GetImplementation(actor));
148 void Actor::Unparent()
150 GetImplementation(*this).Unparent();
153 unsigned int Actor::GetChildCount() const
155 return GetImplementation(*this).GetChildCount();
158 Actor Actor::GetChildAt(unsigned int index) const
160 return GetImplementation(*this).GetChildAt(index);
163 Actor Actor::FindChildByName(const std::string& actorName)
165 Internal::ActorPtr child = GetImplementation(*this).FindChildByName(actorName);
166 return Actor(child.Get());
169 Actor Actor::FindChildByAlias(const std::string& actorAlias)
171 Actor child = GetImplementation(*this).FindChildByAlias(actorAlias);
175 Actor Actor::FindChildById(const unsigned int id)
177 Internal::ActorPtr child = GetImplementation(*this).FindChildById(id);
178 return Actor(child.Get());
181 Actor Actor::GetParent() const
183 Internal::Actor* parent = GetImplementation(*this).GetParent();
185 return Actor(parent);
188 void Actor::SetParentOrigin(const Vector3& origin)
190 GetImplementation(*this).SetParentOrigin(origin);
193 Vector3 Actor::GetCurrentParentOrigin() const
195 return GetImplementation(*this).GetCurrentParentOrigin();
198 void Actor::SetAnchorPoint(const Vector3& anchorPoint)
200 GetImplementation(*this).SetAnchorPoint(anchorPoint);
203 Vector3 Actor::GetCurrentAnchorPoint() const
205 return GetImplementation(*this).GetCurrentAnchorPoint();
208 void Actor::SetSize(float width, float height)
210 GetImplementation(*this).SetSize(width, height);
213 void Actor::SetSize(float width, float height, float depth)
215 GetImplementation(*this).SetSize(width, height, depth);
218 void Actor::SetSize(const Vector2& size)
220 GetImplementation(*this).SetSize(size);
223 void Actor::SetSize(const Vector3& size)
225 GetImplementation(*this).SetSize(size);
228 Vector3 Actor::GetSize() const
230 return GetImplementation(*this).GetSize();
233 Vector3 Actor::GetCurrentSize() const
235 return GetImplementation(*this).GetCurrentSize();
238 Vector3 Actor::GetNaturalSize() const
240 return GetImplementation(*this).GetNaturalSize();
243 void Actor::SetPosition(float x, float y)
245 GetImplementation(*this).SetPosition(x, y);
248 void Actor::SetPosition(float x, float y, float z)
250 GetImplementation(*this).SetPosition(x, y, z);
253 void Actor::SetPosition(const Vector3& position)
255 GetImplementation(*this).SetPosition(position);
258 void Actor::SetX(float x)
260 GetImplementation(*this).SetX(x);
263 void Actor::SetY(float y)
265 GetImplementation(*this).SetY(y);
268 void Actor::SetZ(float z)
270 GetImplementation(*this).SetZ(z);
273 void Actor::MoveBy(const Vector3& distance)
275 GetImplementation(*this).MoveBy(distance);
278 Vector3 Actor::GetCurrentPosition() const
280 return GetImplementation(*this).GetCurrentPosition();
283 Vector3 Actor::GetCurrentWorldPosition() const
285 return GetImplementation(*this).GetCurrentWorldPosition();
288 void Actor::SetPositionInheritanceMode( PositionInheritanceMode mode )
290 GetImplementation(*this).SetPositionInheritanceMode( mode );
293 PositionInheritanceMode Actor::GetPositionInheritanceMode() const
295 return GetImplementation(*this).GetPositionInheritanceMode();
298 void Actor::SetRotation(const Degree& angle, const Vector3& axis)
300 GetImplementation(*this).SetRotation(Radian(angle), axis);
303 void Actor::SetRotation(const Radian& angle, const Vector3& axis)
305 GetImplementation(*this).SetRotation(angle, axis);
308 void Actor::SetRotation(const Quaternion& rotation)
310 GetImplementation(*this).SetRotation(rotation);
313 void Actor::RotateBy(const Degree& angle, const Vector3& axis)
315 GetImplementation(*this).RotateBy(Radian(angle), axis);
318 void Actor::RotateBy(const Radian& angle, const Vector3& axis)
320 GetImplementation(*this).RotateBy(angle, axis);
323 void Actor::RotateBy(const Quaternion& relativeRotation)
325 GetImplementation(*this).RotateBy(relativeRotation);
328 Quaternion Actor::GetCurrentRotation() const
330 return GetImplementation(*this).GetCurrentRotation();
333 void Actor::SetInheritRotation(bool inherit)
335 GetImplementation(*this).SetInheritRotation(inherit);
338 bool Actor::IsRotationInherited() const
340 return GetImplementation(*this).IsRotationInherited();
343 Quaternion Actor::GetCurrentWorldRotation() const
345 return GetImplementation(*this).GetCurrentWorldRotation();
348 void Actor::SetScale(float scale)
350 GetImplementation(*this).SetScale(scale);
353 void Actor::SetScale(float scaleX, float scaleY, float scaleZ)
355 GetImplementation(*this).SetScale(scaleX, scaleY, scaleZ);
358 void Actor::SetScale(const Vector3& scale)
360 GetImplementation(*this).SetScale(scale);
363 void Actor::ScaleBy(const Vector3& relativeScale)
365 GetImplementation(*this).ScaleBy(relativeScale);
368 Vector3 Actor::GetCurrentScale() const
370 return GetImplementation(*this).GetCurrentScale();
373 Vector3 Actor::GetCurrentWorldScale() const
375 return GetImplementation(*this).GetCurrentWorldScale();
378 void Actor::SetInheritScale( bool inherit )
380 GetImplementation(*this).SetInheritScale( inherit );
383 bool Actor::IsScaleInherited() const
385 return GetImplementation(*this).IsScaleInherited();
388 Matrix Actor::GetCurrentWorldMatrix() const
390 return GetImplementation(*this).GetCurrentWorldMatrix();
393 void Actor::SetVisible(bool visible)
395 GetImplementation(*this).SetVisible(visible);
398 bool Actor::IsVisible() const
400 return GetImplementation(*this).IsVisible();
403 void Actor::SetOpacity(float opacity)
405 GetImplementation(*this).SetOpacity(opacity);
408 void Actor::OpacityBy(float relativeOpacity)
410 GetImplementation(*this).OpacityBy(relativeOpacity);
413 float Actor::GetCurrentOpacity() const
415 return GetImplementation(*this).GetCurrentOpacity();
418 void Actor::SetColor(const Vector4& color)
420 GetImplementation(*this).SetColor(color);
423 void Actor::ColorBy(const Vector4& relativeColor)
425 GetImplementation(*this).ColorBy(relativeColor);
428 Vector4 Actor::GetCurrentColor() const
430 return GetImplementation(*this).GetCurrentColor();
433 void Actor::SetColorMode( ColorMode colorMode )
435 GetImplementation(*this).SetColorMode(colorMode);
438 ColorMode Actor::GetColorMode() const
440 return GetImplementation(*this).GetColorMode();
443 Vector4 Actor::GetCurrentWorldColor() const
445 return GetImplementation(*this).GetCurrentWorldColor();
448 void Actor::SetDrawMode( DrawMode::Type drawMode )
450 GetImplementation(*this).SetDrawMode( drawMode );
453 DrawMode::Type Actor::GetDrawMode() const
455 return GetImplementation(*this).GetDrawMode();
458 void Actor::SetSensitive(bool sensitive)
460 GetImplementation(*this).SetSensitive(sensitive);
463 bool Actor::IsSensitive() const
465 return GetImplementation(*this).IsSensitive();
468 bool Actor::ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const
470 return GetImplementation(*this).ScreenToLocal(localX, localY, screenX, screenY);
473 void Actor::SetLeaveRequired(bool required)
475 GetImplementation(*this).SetLeaveRequired(required);
478 bool Actor::GetLeaveRequired() const
480 return GetImplementation(*this).GetLeaveRequired();
483 void Actor::SetKeyboardFocusable( bool focusable )
485 GetImplementation(*this).SetKeyboardFocusable(focusable);
488 bool Actor::IsKeyboardFocusable() const
490 return GetImplementation(*this).IsKeyboardFocusable();
493 Actor::TouchSignalV2& Actor::TouchedSignal()
495 return GetImplementation(*this).TouchedSignal();
498 Actor::MouseWheelEventSignalV2& Actor::MouseWheelEventSignal()
500 return GetImplementation(*this).MouseWheelEventSignal();
503 Actor::SetSizeSignalV2& Actor::SetSizeSignal()
505 return GetImplementation(*this).SetSizeSignal();
508 Actor::OnStageSignalV2& Actor::OnStageSignal()
510 return GetImplementation(*this).OnStageSignal();
513 Actor::OffStageSignalV2& Actor::OffStageSignal()
515 return GetImplementation(*this).OffStageSignal();
518 DynamicsBody Actor::EnableDynamics(DynamicsBodyConfig bodyConfig)
520 #ifdef DYNAMICS_SUPPORT
521 Internal::DynamicsBodyConfig& internal = GetImplementation(bodyConfig);
523 Internal::DynamicsBodyPtr body( GetImplementation(*this).EnableDynamics( &internal ) );
525 return DynamicsBody( body.Get() );
527 return DynamicsBody();
531 DynamicsJoint Actor::AddDynamicsJoint( Actor attachedActor, const Vector3& offset )
533 #ifdef DYNAMICS_SUPPORT
534 Internal::ActorPtr internalActor( &GetImplementation(attachedActor) );
535 Internal::DynamicsJointPtr joint( GetImplementation(*this).AddDynamicsJoint( internalActor, offset) );
537 return DynamicsJoint( joint.Get() );
539 return DynamicsJoint();
543 DynamicsJoint Actor::AddDynamicsJoint( Actor attachedActor, const Vector3& offsetA, const Vector3& offsetB )
545 #ifdef DYNAMICS_SUPPORT
546 Internal::ActorPtr internalActor( &GetImplementation(attachedActor) );
547 Internal::DynamicsJointPtr joint( GetImplementation(*this).AddDynamicsJoint( internalActor, offsetA, offsetB) );
549 return DynamicsJoint( joint.Get() );
551 return DynamicsJoint();
555 const int Actor::GetNumberOfJoints() const
557 #ifdef DYNAMICS_SUPPORT
558 return GetImplementation(*this).GetNumberOfJoints();
564 DynamicsJoint Actor::GetDynamicsJointByIndex( const int index )
566 #ifdef DYNAMICS_SUPPORT
567 Internal::DynamicsJointPtr joint( GetImplementation(*this).GetDynamicsJointByIndex( index ) );
569 return DynamicsJoint( joint.Get() );
571 return DynamicsJoint();
575 DynamicsJoint Actor::GetDynamicsJoint( Actor attachedActor )
577 #ifdef DYNAMICS_SUPPORT
578 Internal::DynamicsJointPtr joint( GetImplementation(*this).GetDynamicsJoint( &GetImplementation(attachedActor) ) );
580 return DynamicsJoint( joint.Get() );
582 return DynamicsJoint();
586 void Actor::RemoveDynamicsJoint( DynamicsJoint joint )
588 #ifdef DYNAMICS_SUPPORT
589 GetImplementation(*this).RemoveDynamicsJoint( &GetImplementation(joint) );
593 void Actor::DisableDynamics()
595 #ifdef DYNAMICS_SUPPORT
596 GetImplementation(*this).DisableDynamics();
600 DynamicsBody Actor::GetDynamicsBody()
602 #ifdef DYNAMICS_SUPPORT
603 Internal::DynamicsBodyPtr internal(GetImplementation(*this).GetDynamicsBody());
604 return DynamicsBody( internal.Get() );
606 return DynamicsBody();
610 Actor::Actor(Internal::Actor* internal)
611 : Constrainable(internal)
615 void UnparentAndReset( Actor& actor )