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::TranslateBy(const Vector3& distance)
251 GetImplementation(*this).TranslateBy(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::SetOrientation(const Degree& angle, const Vector3& axis)
276 GetImplementation(*this).SetOrientation(Radian(angle), axis);
279 void Actor::SetOrientation(const Radian& angle, const Vector3& axis)
281 GetImplementation(*this).SetOrientation(angle, axis);
284 void Actor::SetOrientation(const Quaternion& orientation)
286 GetImplementation(*this).SetOrientation(orientation);
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::GetCurrentOrientation() const
306 return GetImplementation(*this).GetCurrentOrientation();
309 void Actor::SetInheritOrientation(bool inherit)
311 GetImplementation(*this).SetInheritOrientation(inherit);
314 bool Actor::IsOrientationInherited() const
316 return GetImplementation(*this).IsOrientationInherited();
319 Quaternion Actor::GetCurrentWorldOrientation() const
321 return GetImplementation(*this).GetCurrentWorldOrientation();
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 float Actor::GetCurrentOpacity() const
406 return GetImplementation(*this).GetCurrentOpacity();
409 void Actor::SetColor(const Vector4& color)
411 GetImplementation(*this).SetColor(color);
414 Vector4 Actor::GetCurrentColor() const
416 return GetImplementation(*this).GetCurrentColor();
419 void Actor::SetColorMode( ColorMode colorMode )
421 GetImplementation(*this).SetColorMode(colorMode);
424 ColorMode Actor::GetColorMode() const
426 return GetImplementation(*this).GetColorMode();
429 Vector4 Actor::GetCurrentWorldColor() const
431 return GetImplementation(*this).GetCurrentWorldColor();
434 void Actor::SetDrawMode( DrawMode::Type drawMode )
436 GetImplementation(*this).SetDrawMode( drawMode );
439 DrawMode::Type Actor::GetDrawMode() const
441 return GetImplementation(*this).GetDrawMode();
444 void Actor::SetSensitive(bool sensitive)
446 GetImplementation(*this).SetSensitive(sensitive);
449 bool Actor::IsSensitive() const
451 return GetImplementation(*this).IsSensitive();
454 bool Actor::ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const
456 return GetImplementation(*this).ScreenToLocal(localX, localY, screenX, screenY);
459 void Actor::SetLeaveRequired(bool required)
461 GetImplementation(*this).SetLeaveRequired(required);
464 bool Actor::GetLeaveRequired() const
466 return GetImplementation(*this).GetLeaveRequired();
469 void Actor::SetKeyboardFocusable( bool focusable )
471 GetImplementation(*this).SetKeyboardFocusable(focusable);
474 bool Actor::IsKeyboardFocusable() const
476 return GetImplementation(*this).IsKeyboardFocusable();
479 Actor::TouchSignalType& Actor::TouchedSignal()
481 return GetImplementation(*this).TouchedSignal();
484 Actor::HoverSignalType& Actor::HoveredSignal()
486 return GetImplementation(*this).HoveredSignal();
489 Actor::MouseWheelEventSignalType& Actor::MouseWheelEventSignal()
491 return GetImplementation(*this).MouseWheelEventSignal();
494 Actor::OnStageSignalType& Actor::OnStageSignal()
496 return GetImplementation(*this).OnStageSignal();
499 Actor::OffStageSignalType& Actor::OffStageSignal()
501 return GetImplementation(*this).OffStageSignal();
504 DynamicsBody Actor::EnableDynamics(DynamicsBodyConfig bodyConfig)
506 #ifdef DYNAMICS_SUPPORT
507 Internal::DynamicsBodyConfig& internal = GetImplementation(bodyConfig);
509 Internal::DynamicsBodyPtr body( GetImplementation(*this).EnableDynamics( &internal ) );
511 return DynamicsBody( body.Get() );
513 return DynamicsBody();
517 DynamicsJoint Actor::AddDynamicsJoint( Actor attachedActor, const Vector3& offset )
519 #ifdef DYNAMICS_SUPPORT
520 Internal::ActorPtr internalActor( &GetImplementation(attachedActor) );
521 Internal::DynamicsJointPtr joint( GetImplementation(*this).AddDynamicsJoint( internalActor, offset) );
523 return DynamicsJoint( joint.Get() );
525 return DynamicsJoint();
529 DynamicsJoint Actor::AddDynamicsJoint( Actor attachedActor, const Vector3& offsetA, const Vector3& offsetB )
531 #ifdef DYNAMICS_SUPPORT
532 Internal::ActorPtr internalActor( &GetImplementation(attachedActor) );
533 Internal::DynamicsJointPtr joint( GetImplementation(*this).AddDynamicsJoint( internalActor, offsetA, offsetB) );
535 return DynamicsJoint( joint.Get() );
537 return DynamicsJoint();
541 int Actor::GetNumberOfJoints() const
543 #ifdef DYNAMICS_SUPPORT
544 return GetImplementation(*this).GetNumberOfJoints();
550 DynamicsJoint Actor::GetDynamicsJointByIndex( const int index )
552 #ifdef DYNAMICS_SUPPORT
553 Internal::DynamicsJointPtr joint( GetImplementation(*this).GetDynamicsJointByIndex( index ) );
555 return DynamicsJoint( joint.Get() );
557 return DynamicsJoint();
561 DynamicsJoint Actor::GetDynamicsJoint( Actor attachedActor )
563 #ifdef DYNAMICS_SUPPORT
564 Internal::DynamicsJointPtr joint( GetImplementation(*this).GetDynamicsJoint( &GetImplementation(attachedActor) ) );
566 return DynamicsJoint( joint.Get() );
568 return DynamicsJoint();
572 void Actor::RemoveDynamicsJoint( DynamicsJoint joint )
574 #ifdef DYNAMICS_SUPPORT
575 GetImplementation(*this).RemoveDynamicsJoint( &GetImplementation(joint) );
579 void Actor::DisableDynamics()
581 #ifdef DYNAMICS_SUPPORT
582 GetImplementation(*this).DisableDynamics();
586 DynamicsBody Actor::GetDynamicsBody()
588 #ifdef DYNAMICS_SUPPORT
589 Internal::DynamicsBodyPtr internal(GetImplementation(*this).GetDynamicsBody());
590 return DynamicsBody( internal.Get() );
592 return DynamicsBody();
596 Actor::Actor(Internal::Actor* internal)
601 void UnparentAndReset( Actor& actor )