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::FindChildById(const unsigned int id)
153 Internal::ActorPtr child = GetImplementation(*this).FindChildById(id);
154 return Actor(child.Get());
157 Actor Actor::GetParent() const
159 Internal::Actor* parent = GetImplementation(*this).GetParent();
161 return Actor(parent);
164 void Actor::SetParentOrigin(const Vector3& origin)
166 GetImplementation(*this).SetParentOrigin(origin);
169 Vector3 Actor::GetCurrentParentOrigin() const
171 return GetImplementation(*this).GetCurrentParentOrigin();
174 void Actor::SetAnchorPoint(const Vector3& anchorPoint)
176 GetImplementation(*this).SetAnchorPoint(anchorPoint);
179 Vector3 Actor::GetCurrentAnchorPoint() const
181 return GetImplementation(*this).GetCurrentAnchorPoint();
184 void Actor::SetSize(float width, float height)
186 GetImplementation(*this).SetSize(width, height);
189 void Actor::SetSize(float width, float height, float depth)
191 GetImplementation(*this).SetSize(width, height, depth);
194 void Actor::SetSize(const Vector2& size)
196 GetImplementation(*this).SetSize(size);
199 void Actor::SetSize(const Vector3& size)
201 GetImplementation(*this).SetSize(size);
204 Vector3 Actor::GetSize() const
206 return GetImplementation(*this).GetSize();
209 Vector3 Actor::GetCurrentSize() const
211 return GetImplementation(*this).GetCurrentSize();
214 Vector3 Actor::GetNaturalSize() const
216 return GetImplementation(*this).GetNaturalSize();
219 void Actor::SetPosition(float x, float y)
221 GetImplementation(*this).SetPosition(x, y);
224 void Actor::SetPosition(float x, float y, float z)
226 GetImplementation(*this).SetPosition(x, y, z);
229 void Actor::SetPosition(const Vector3& position)
231 GetImplementation(*this).SetPosition(position);
234 void Actor::SetX(float x)
236 GetImplementation(*this).SetX(x);
239 void Actor::SetY(float y)
241 GetImplementation(*this).SetY(y);
244 void Actor::SetZ(float z)
246 GetImplementation(*this).SetZ(z);
249 void Actor::MoveBy(const Vector3& distance)
251 GetImplementation(*this).MoveBy(distance);
254 Vector3 Actor::GetCurrentPosition() const
256 return GetImplementation(*this).GetCurrentPosition();
259 Vector3 Actor::GetCurrentWorldPosition() const
261 return GetImplementation(*this).GetCurrentWorldPosition();
264 void Actor::SetPositionInheritanceMode( PositionInheritanceMode mode )
266 GetImplementation(*this).SetPositionInheritanceMode( mode );
269 PositionInheritanceMode Actor::GetPositionInheritanceMode() const
271 return GetImplementation(*this).GetPositionInheritanceMode();
274 void Actor::SetRotation(const Degree& angle, const Vector3& axis)
276 GetImplementation(*this).SetRotation(Radian(angle), axis);
279 void Actor::SetRotation(const Radian& angle, const Vector3& axis)
281 GetImplementation(*this).SetRotation(angle, axis);
284 void Actor::SetRotation(const Quaternion& rotation)
286 GetImplementation(*this).SetRotation(rotation);
289 void Actor::RotateBy(const Degree& angle, const Vector3& axis)
291 GetImplementation(*this).RotateBy(Radian(angle), axis);
294 void Actor::RotateBy(const Radian& angle, const Vector3& axis)
296 GetImplementation(*this).RotateBy(angle, axis);
299 void Actor::RotateBy(const Quaternion& relativeRotation)
301 GetImplementation(*this).RotateBy(relativeRotation);
304 Quaternion Actor::GetCurrentRotation() const
306 return GetImplementation(*this).GetCurrentRotation();
309 void Actor::SetInheritRotation(bool inherit)
311 GetImplementation(*this).SetInheritRotation(inherit);
314 bool Actor::IsRotationInherited() const
316 return GetImplementation(*this).IsRotationInherited();
319 Quaternion Actor::GetCurrentWorldRotation() const
321 return GetImplementation(*this).GetCurrentWorldRotation();
324 void Actor::SetScale(float scale)
326 GetImplementation(*this).SetScale(scale);
329 void Actor::SetScale(float scaleX, float scaleY, float scaleZ)
331 GetImplementation(*this).SetScale(scaleX, scaleY, scaleZ);
334 void Actor::SetScale(const Vector3& scale)
336 GetImplementation(*this).SetScale(scale);
339 void Actor::ScaleBy(const Vector3& relativeScale)
341 GetImplementation(*this).ScaleBy(relativeScale);
344 Vector3 Actor::GetCurrentScale() const
346 return GetImplementation(*this).GetCurrentScale();
349 Vector3 Actor::GetCurrentWorldScale() const
351 return GetImplementation(*this).GetCurrentWorldScale();
354 void Actor::SetInheritScale( bool inherit )
356 GetImplementation(*this).SetInheritScale( inherit );
359 bool Actor::IsScaleInherited() const
361 return GetImplementation(*this).IsScaleInherited();
364 void Actor::SetSizeMode(SizeMode mode)
366 GetImplementation(*this).SetSizeMode(mode);
369 SizeMode Actor::GetSizeMode() const
371 return GetImplementation(*this).GetSizeMode();
374 void Actor::SetSizeModeFactor(const Vector3& factor)
376 GetImplementation(*this).SetSizeModeFactor(factor);
379 Vector3 Actor::GetSizeModeFactor() const
381 return GetImplementation(*this).GetSizeModeFactor();
384 Matrix Actor::GetCurrentWorldMatrix() const
386 return GetImplementation(*this).GetCurrentWorldMatrix();
389 void Actor::SetVisible(bool visible)
391 GetImplementation(*this).SetVisible(visible);
394 bool Actor::IsVisible() const
396 return GetImplementation(*this).IsVisible();
399 void Actor::SetOpacity(float opacity)
401 GetImplementation(*this).SetOpacity(opacity);
404 void Actor::OpacityBy(float relativeOpacity)
406 GetImplementation(*this).OpacityBy(relativeOpacity);
409 float Actor::GetCurrentOpacity() const
411 return GetImplementation(*this).GetCurrentOpacity();
414 void Actor::SetColor(const Vector4& color)
416 GetImplementation(*this).SetColor(color);
419 void Actor::ColorBy(const Vector4& relativeColor)
421 GetImplementation(*this).ColorBy(relativeColor);
424 Vector4 Actor::GetCurrentColor() const
426 return GetImplementation(*this).GetCurrentColor();
429 void Actor::SetColorMode( ColorMode colorMode )
431 GetImplementation(*this).SetColorMode(colorMode);
434 ColorMode Actor::GetColorMode() const
436 return GetImplementation(*this).GetColorMode();
439 Vector4 Actor::GetCurrentWorldColor() const
441 return GetImplementation(*this).GetCurrentWorldColor();
444 void Actor::SetDrawMode( DrawMode::Type drawMode )
446 GetImplementation(*this).SetDrawMode( drawMode );
449 DrawMode::Type Actor::GetDrawMode() const
451 return GetImplementation(*this).GetDrawMode();
454 void Actor::SetSensitive(bool sensitive)
456 GetImplementation(*this).SetSensitive(sensitive);
459 bool Actor::IsSensitive() const
461 return GetImplementation(*this).IsSensitive();
464 bool Actor::ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const
466 return GetImplementation(*this).ScreenToLocal(localX, localY, screenX, screenY);
469 void Actor::SetLeaveRequired(bool required)
471 GetImplementation(*this).SetLeaveRequired(required);
474 bool Actor::GetLeaveRequired() const
476 return GetImplementation(*this).GetLeaveRequired();
479 void Actor::SetKeyboardFocusable( bool focusable )
481 GetImplementation(*this).SetKeyboardFocusable(focusable);
484 bool Actor::IsKeyboardFocusable() const
486 return GetImplementation(*this).IsKeyboardFocusable();
489 Actor::TouchSignalType& Actor::TouchedSignal()
491 return GetImplementation(*this).TouchedSignal();
494 Actor::HoverSignalType& Actor::HoveredSignal()
496 return GetImplementation(*this).HoveredSignal();
499 Actor::MouseWheelEventSignalType& Actor::MouseWheelEventSignal()
501 return GetImplementation(*this).MouseWheelEventSignal();
504 Actor::OnStageSignalType& Actor::OnStageSignal()
506 return GetImplementation(*this).OnStageSignal();
509 Actor::OffStageSignalType& Actor::OffStageSignal()
511 return GetImplementation(*this).OffStageSignal();
514 DynamicsBody Actor::EnableDynamics(DynamicsBodyConfig bodyConfig)
516 #ifdef DYNAMICS_SUPPORT
517 Internal::DynamicsBodyConfig& internal = GetImplementation(bodyConfig);
519 Internal::DynamicsBodyPtr body( GetImplementation(*this).EnableDynamics( &internal ) );
521 return DynamicsBody( body.Get() );
523 return DynamicsBody();
527 DynamicsJoint Actor::AddDynamicsJoint( Actor attachedActor, const Vector3& offset )
529 #ifdef DYNAMICS_SUPPORT
530 Internal::ActorPtr internalActor( &GetImplementation(attachedActor) );
531 Internal::DynamicsJointPtr joint( GetImplementation(*this).AddDynamicsJoint( internalActor, offset) );
533 return DynamicsJoint( joint.Get() );
535 return DynamicsJoint();
539 DynamicsJoint Actor::AddDynamicsJoint( Actor attachedActor, const Vector3& offsetA, const Vector3& offsetB )
541 #ifdef DYNAMICS_SUPPORT
542 Internal::ActorPtr internalActor( &GetImplementation(attachedActor) );
543 Internal::DynamicsJointPtr joint( GetImplementation(*this).AddDynamicsJoint( internalActor, offsetA, offsetB) );
545 return DynamicsJoint( joint.Get() );
547 return DynamicsJoint();
551 int Actor::GetNumberOfJoints() const
553 #ifdef DYNAMICS_SUPPORT
554 return GetImplementation(*this).GetNumberOfJoints();
560 DynamicsJoint Actor::GetDynamicsJointByIndex( const int index )
562 #ifdef DYNAMICS_SUPPORT
563 Internal::DynamicsJointPtr joint( GetImplementation(*this).GetDynamicsJointByIndex( index ) );
565 return DynamicsJoint( joint.Get() );
567 return DynamicsJoint();
571 DynamicsJoint Actor::GetDynamicsJoint( Actor attachedActor )
573 #ifdef DYNAMICS_SUPPORT
574 Internal::DynamicsJointPtr joint( GetImplementation(*this).GetDynamicsJoint( &GetImplementation(attachedActor) ) );
576 return DynamicsJoint( joint.Get() );
578 return DynamicsJoint();
582 void Actor::RemoveDynamicsJoint( DynamicsJoint joint )
584 #ifdef DYNAMICS_SUPPORT
585 GetImplementation(*this).RemoveDynamicsJoint( &GetImplementation(joint) );
589 void Actor::DisableDynamics()
591 #ifdef DYNAMICS_SUPPORT
592 GetImplementation(*this).DisableDynamics();
596 DynamicsBody Actor::GetDynamicsBody()
598 #ifdef DYNAMICS_SUPPORT
599 Internal::DynamicsBodyPtr internal(GetImplementation(*this).GetDynamicsBody());
600 return DynamicsBody( internal.Get() );
602 return DynamicsBody();
606 Actor::Actor(Internal::Actor* internal)
611 void UnparentAndReset( Actor& actor )