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 Matrix Actor::GetCurrentWorldMatrix() const
382 return GetImplementation(*this).GetCurrentWorldMatrix();
385 void Actor::SetVisible(bool visible)
387 GetImplementation(*this).SetVisible(visible);
390 bool Actor::IsVisible() const
392 return GetImplementation(*this).IsVisible();
395 void Actor::SetOpacity(float opacity)
397 GetImplementation(*this).SetOpacity(opacity);
400 void Actor::OpacityBy(float relativeOpacity)
402 GetImplementation(*this).OpacityBy(relativeOpacity);
405 float Actor::GetCurrentOpacity() const
407 return GetImplementation(*this).GetCurrentOpacity();
410 void Actor::SetColor(const Vector4& color)
412 GetImplementation(*this).SetColor(color);
415 void Actor::ColorBy(const Vector4& relativeColor)
417 GetImplementation(*this).ColorBy(relativeColor);
420 Vector4 Actor::GetCurrentColor() const
422 return GetImplementation(*this).GetCurrentColor();
425 void Actor::SetColorMode( ColorMode colorMode )
427 GetImplementation(*this).SetColorMode(colorMode);
430 ColorMode Actor::GetColorMode() const
432 return GetImplementation(*this).GetColorMode();
435 Vector4 Actor::GetCurrentWorldColor() const
437 return GetImplementation(*this).GetCurrentWorldColor();
440 void Actor::SetDrawMode( DrawMode::Type drawMode )
442 GetImplementation(*this).SetDrawMode( drawMode );
445 DrawMode::Type Actor::GetDrawMode() const
447 return GetImplementation(*this).GetDrawMode();
450 void Actor::SetSensitive(bool sensitive)
452 GetImplementation(*this).SetSensitive(sensitive);
455 bool Actor::IsSensitive() const
457 return GetImplementation(*this).IsSensitive();
460 bool Actor::ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const
462 return GetImplementation(*this).ScreenToLocal(localX, localY, screenX, screenY);
465 void Actor::SetLeaveRequired(bool required)
467 GetImplementation(*this).SetLeaveRequired(required);
470 bool Actor::GetLeaveRequired() const
472 return GetImplementation(*this).GetLeaveRequired();
475 void Actor::SetKeyboardFocusable( bool focusable )
477 GetImplementation(*this).SetKeyboardFocusable(focusable);
480 bool Actor::IsKeyboardFocusable() const
482 return GetImplementation(*this).IsKeyboardFocusable();
485 Actor::TouchSignalV2& Actor::TouchedSignal()
487 return GetImplementation(*this).TouchedSignal();
490 Actor::HoverSignalV2& Actor::HoveredSignal()
492 return GetImplementation(*this).HoveredSignal();
495 Actor::MouseWheelEventSignalV2& Actor::MouseWheelEventSignal()
497 return GetImplementation(*this).MouseWheelEventSignal();
500 Actor::SetSizeSignalV2& Actor::SetSizeSignal()
502 return GetImplementation(*this).SetSizeSignal();
505 Actor::OnStageSignalV2& Actor::OnStageSignal()
507 return GetImplementation(*this).OnStageSignal();
510 Actor::OffStageSignalV2& Actor::OffStageSignal()
512 return GetImplementation(*this).OffStageSignal();
515 DynamicsBody Actor::EnableDynamics(DynamicsBodyConfig bodyConfig)
517 #ifdef DYNAMICS_SUPPORT
518 Internal::DynamicsBodyConfig& internal = GetImplementation(bodyConfig);
520 Internal::DynamicsBodyPtr body( GetImplementation(*this).EnableDynamics( &internal ) );
522 return DynamicsBody( body.Get() );
524 return DynamicsBody();
528 DynamicsJoint Actor::AddDynamicsJoint( Actor attachedActor, const Vector3& offset )
530 #ifdef DYNAMICS_SUPPORT
531 Internal::ActorPtr internalActor( &GetImplementation(attachedActor) );
532 Internal::DynamicsJointPtr joint( GetImplementation(*this).AddDynamicsJoint( internalActor, offset) );
534 return DynamicsJoint( joint.Get() );
536 return DynamicsJoint();
540 DynamicsJoint Actor::AddDynamicsJoint( Actor attachedActor, const Vector3& offsetA, const Vector3& offsetB )
542 #ifdef DYNAMICS_SUPPORT
543 Internal::ActorPtr internalActor( &GetImplementation(attachedActor) );
544 Internal::DynamicsJointPtr joint( GetImplementation(*this).AddDynamicsJoint( internalActor, offsetA, offsetB) );
546 return DynamicsJoint( joint.Get() );
548 return DynamicsJoint();
552 int Actor::GetNumberOfJoints() const
554 #ifdef DYNAMICS_SUPPORT
555 return GetImplementation(*this).GetNumberOfJoints();
561 DynamicsJoint Actor::GetDynamicsJointByIndex( const int index )
563 #ifdef DYNAMICS_SUPPORT
564 Internal::DynamicsJointPtr joint( GetImplementation(*this).GetDynamicsJointByIndex( index ) );
566 return DynamicsJoint( joint.Get() );
568 return DynamicsJoint();
572 DynamicsJoint Actor::GetDynamicsJoint( Actor attachedActor )
574 #ifdef DYNAMICS_SUPPORT
575 Internal::DynamicsJointPtr joint( GetImplementation(*this).GetDynamicsJoint( &GetImplementation(attachedActor) ) );
577 return DynamicsJoint( joint.Get() );
579 return DynamicsJoint();
583 void Actor::RemoveDynamicsJoint( DynamicsJoint joint )
585 #ifdef DYNAMICS_SUPPORT
586 GetImplementation(*this).RemoveDynamicsJoint( &GetImplementation(joint) );
590 void Actor::DisableDynamics()
592 #ifdef DYNAMICS_SUPPORT
593 GetImplementation(*this).DisableDynamics();
597 DynamicsBody Actor::GetDynamicsBody()
599 #ifdef DYNAMICS_SUPPORT
600 Internal::DynamicsBodyPtr internal(GetImplementation(*this).GetDynamicsBody());
601 return DynamicsBody( internal.Get() );
603 return DynamicsBody();
607 Actor::Actor(Internal::Actor* internal)
608 : Constrainable(internal)
612 void UnparentAndReset( Actor& actor )