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>
33 #include <dali/internal/event/size-negotiation/relayout-controller-impl.h>
44 Internal::ActorPtr internal = Internal::Actor::New();
46 return Actor(internal.Get());
49 Actor Actor::DownCast( BaseHandle handle )
51 return Actor( dynamic_cast<Dali::Internal::Actor*>(handle.GetObjectPtr()) );
58 Actor::Actor(const Actor& copy)
63 Actor& Actor::operator=(const Actor& rhs)
65 BaseHandle::operator=(rhs);
69 const std::string& Actor::GetName() const
71 return GetImplementation(*this).GetName();
74 void Actor::SetName(const std::string& name)
76 GetImplementation(*this).SetName(name);
79 unsigned int Actor::GetId() const
81 return GetImplementation(*this).GetId();
84 bool Actor::IsRoot() const
86 return GetImplementation(*this).IsRoot();
89 bool Actor::OnStage() const
91 return GetImplementation(*this).OnStage();
94 bool Actor::IsLayer() const
96 return GetImplementation(*this).IsLayer();
99 Layer Actor::GetLayer()
101 return GetImplementation(*this).GetLayer();
104 void Actor::Add(Actor actor)
106 GetImplementation(*this).Add(GetImplementation(actor));
109 void Actor::Insert(unsigned int index, Actor actor)
111 GetImplementation(*this).Insert(index, GetImplementation(actor));
114 void Actor::Remove(Actor actor)
116 GetImplementation(*this).Remove(GetImplementation(actor));
119 void Actor::Unparent()
121 GetImplementation(*this).Unparent();
124 unsigned int Actor::GetChildCount() const
126 return GetImplementation(*this).GetChildCount();
129 Actor Actor::GetChildAt(unsigned int index) const
131 return GetImplementation(*this).GetChildAt(index);
134 Actor Actor::FindChildByName(const std::string& actorName)
136 Internal::ActorPtr child = GetImplementation(*this).FindChildByName(actorName);
137 return Actor(child.Get());
140 Actor Actor::FindChildById(const unsigned int id)
142 Internal::ActorPtr child = GetImplementation(*this).FindChildById(id);
143 return Actor(child.Get());
146 Actor Actor::GetParent() const
148 Internal::Actor* parent = GetImplementation(*this).GetParent();
150 return Actor(parent);
153 void Actor::SetParentOrigin(const Vector3& origin)
155 GetImplementation(*this).SetParentOrigin(origin);
158 Vector3 Actor::GetCurrentParentOrigin() const
160 return GetImplementation(*this).GetCurrentParentOrigin();
163 void Actor::SetAnchorPoint(const Vector3& anchorPoint)
165 GetImplementation(*this).SetAnchorPoint(anchorPoint);
168 Vector3 Actor::GetCurrentAnchorPoint() const
170 return GetImplementation(*this).GetCurrentAnchorPoint();
173 void Actor::SetSize(float width, float height)
175 if( IsRelayoutEnabled() )
177 GetImplementation(*this).SetPreferredSize( Vector2( width, height ) );
181 GetImplementation(*this).SetSize(width, height);
185 void Actor::SetSize(float width, float height, float depth)
187 if( IsRelayoutEnabled() )
189 GetImplementation(*this).SetPreferredSize( Vector2( width, height ) );
193 GetImplementation(*this).SetSize(width, height, depth);
197 void Actor::SetSize(const Vector2& size)
199 if( IsRelayoutEnabled() )
201 GetImplementation(*this).SetPreferredSize( size );
205 GetImplementation(*this).SetSize( size );
209 void Actor::SetSize(const Vector3& size)
211 if( IsRelayoutEnabled() )
213 GetImplementation(*this).SetPreferredSize( size.GetVectorXY() );
217 GetImplementation(*this).SetSize( size );
221 Vector3 Actor::GetTargetSize() const
223 return GetImplementation(*this).GetTargetSize();
226 Vector3 Actor::GetCurrentSize() const
228 return GetImplementation(*this).GetCurrentSize();
231 Vector3 Actor::GetNaturalSize() const
233 return GetImplementation(*this).GetNaturalSize();
236 void Actor::SetPosition(float x, float y)
238 GetImplementation(*this).SetPosition(x, y);
241 void Actor::SetPosition(float x, float y, float z)
243 GetImplementation(*this).SetPosition(x, y, z);
246 void Actor::SetPosition(const Vector3& position)
248 GetImplementation(*this).SetPosition(position);
251 void Actor::SetX(float x)
253 GetImplementation(*this).SetX(x);
256 void Actor::SetY(float y)
258 GetImplementation(*this).SetY(y);
261 void Actor::SetZ(float z)
263 GetImplementation(*this).SetZ(z);
266 void Actor::TranslateBy(const Vector3& distance)
268 GetImplementation(*this).TranslateBy(distance);
271 Vector3 Actor::GetCurrentPosition() const
273 return GetImplementation(*this).GetCurrentPosition();
276 Vector3 Actor::GetCurrentWorldPosition() const
278 return GetImplementation(*this).GetCurrentWorldPosition();
281 void Actor::SetPositionInheritanceMode( PositionInheritanceMode mode )
283 GetImplementation(*this).SetPositionInheritanceMode( mode );
286 PositionInheritanceMode Actor::GetPositionInheritanceMode() const
288 return GetImplementation(*this).GetPositionInheritanceMode();
291 void Actor::SetOrientation(const Degree& angle, const Vector3& axis)
293 GetImplementation(*this).SetOrientation(Radian(angle), axis);
296 void Actor::SetOrientation(const Radian& angle, const Vector3& axis)
298 GetImplementation(*this).SetOrientation(angle, axis);
301 void Actor::SetOrientation(const Quaternion& orientation)
303 GetImplementation(*this).SetOrientation(orientation);
306 void Actor::RotateBy(const Degree& angle, const Vector3& axis)
308 GetImplementation(*this).RotateBy(Radian(angle), axis);
311 void Actor::RotateBy(const Radian& angle, const Vector3& axis)
313 GetImplementation(*this).RotateBy(angle, axis);
316 void Actor::RotateBy(const Quaternion& relativeRotation)
318 GetImplementation(*this).RotateBy(relativeRotation);
321 Quaternion Actor::GetCurrentOrientation() const
323 return GetImplementation(*this).GetCurrentOrientation();
326 void Actor::SetInheritOrientation(bool inherit)
328 GetImplementation(*this).SetInheritOrientation(inherit);
331 bool Actor::IsOrientationInherited() const
333 return GetImplementation(*this).IsOrientationInherited();
336 Quaternion Actor::GetCurrentWorldOrientation() const
338 return GetImplementation(*this).GetCurrentWorldOrientation();
341 void Actor::SetScale(float scale)
343 GetImplementation(*this).SetScale(scale);
346 void Actor::SetScale(float scaleX, float scaleY, float scaleZ)
348 GetImplementation(*this).SetScale(scaleX, scaleY, scaleZ);
351 void Actor::SetScale(const Vector3& scale)
353 GetImplementation(*this).SetScale(scale);
356 void Actor::ScaleBy(const Vector3& relativeScale)
358 GetImplementation(*this).ScaleBy(relativeScale);
361 Vector3 Actor::GetCurrentScale() const
363 return GetImplementation(*this).GetCurrentScale();
366 Vector3 Actor::GetCurrentWorldScale() const
368 return GetImplementation(*this).GetCurrentWorldScale();
371 void Actor::SetInheritScale( bool inherit )
373 GetImplementation(*this).SetInheritScale( inherit );
376 bool Actor::IsScaleInherited() const
378 return GetImplementation(*this).IsScaleInherited();
381 void Actor::SetSizeModeFactor(const Vector3& factor)
383 GetImplementation(*this).SetSizeModeFactor(factor);
386 Vector3 Actor::GetSizeModeFactor() const
388 return GetImplementation(*this).GetSizeModeFactor();
391 Matrix Actor::GetCurrentWorldMatrix() const
393 return GetImplementation(*this).GetCurrentWorldMatrix();
396 void Actor::SetVisible(bool visible)
398 GetImplementation(*this).SetVisible(visible);
401 bool Actor::IsVisible() const
403 return GetImplementation(*this).IsVisible();
406 void Actor::SetOpacity(float opacity)
408 GetImplementation(*this).SetOpacity(opacity);
411 float Actor::GetCurrentOpacity() const
413 return GetImplementation(*this).GetCurrentOpacity();
416 void Actor::SetColor(const Vector4& color)
418 GetImplementation(*this).SetColor(color);
421 Vector4 Actor::GetCurrentColor() const
423 return GetImplementation(*this).GetCurrentColor();
426 void Actor::SetColorMode( ColorMode colorMode )
428 GetImplementation(*this).SetColorMode(colorMode);
431 ColorMode Actor::GetColorMode() const
433 return GetImplementation(*this).GetColorMode();
436 Vector4 Actor::GetCurrentWorldColor() const
438 return GetImplementation(*this).GetCurrentWorldColor();
441 void Actor::SetDrawMode( DrawMode::Type drawMode )
443 GetImplementation(*this).SetDrawMode( drawMode );
446 DrawMode::Type Actor::GetDrawMode() const
448 return GetImplementation(*this).GetDrawMode();
451 void Actor::SetSensitive(bool sensitive)
453 GetImplementation(*this).SetSensitive(sensitive);
456 bool Actor::IsSensitive() const
458 return GetImplementation(*this).IsSensitive();
461 bool Actor::ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const
463 return GetImplementation(*this).ScreenToLocal(localX, localY, screenX, screenY);
466 void Actor::SetLeaveRequired(bool required)
468 GetImplementation(*this).SetLeaveRequired(required);
471 bool Actor::GetLeaveRequired() const
473 return GetImplementation(*this).GetLeaveRequired();
476 void Actor::SetKeyboardFocusable( bool focusable )
478 GetImplementation(*this).SetKeyboardFocusable(focusable);
481 bool Actor::IsKeyboardFocusable() const
483 return GetImplementation(*this).IsKeyboardFocusable();
486 void Actor::SetRelayoutEnabled( bool enabled )
488 GetImplementation(*this).SetRelayoutEnabled( enabled );
491 bool Actor::IsRelayoutEnabled() const
493 return GetImplementation(*this).IsRelayoutEnabled();
496 void Actor::SetResizePolicy( ResizePolicy policy, Dimension dimension )
498 GetImplementation(*this).SetResizePolicy( policy, dimension );
501 ResizePolicy Actor::GetResizePolicy( Dimension dimension ) const
503 return GetImplementation(*this).GetResizePolicy( dimension );
506 void Actor::SetSizeScalePolicy( SizeScalePolicy policy )
508 GetImplementation(*this).SetSizeScalePolicy( policy );
511 SizeScalePolicy Actor::GetSizeScalePolicy() const
513 return GetImplementation(*this).GetSizeScalePolicy();
516 float Actor::GetHeightForWidth( float width )
518 return GetImplementation(*this).GetHeightForWidth( width );
521 float Actor::GetWidthForHeight( float height )
523 return GetImplementation(*this).GetWidthForHeight( height );
526 float Actor::GetRelayoutSize( Dimension dimension ) const
528 return GetImplementation(*this).GetRelayoutSize( dimension );
531 void Actor::RelayoutRequestTree()
533 GetImplementation(*this).RelayoutRequestTree();
536 void Actor::PropagateRelayoutFlags()
538 GetImplementation(*this).PropagateRelayoutFlags();
541 void Actor::SetPadding( const Padding& padding )
543 Internal::Actor& impl = GetImplementation(*this);
545 Vector2 widthPadding( padding.left, padding.right );
546 impl.SetPadding( widthPadding, WIDTH );
548 Vector2 heightPadding( padding.bottom, padding.top );
549 impl.SetPadding( heightPadding, HEIGHT );
552 void Actor::GetPadding( Padding& paddingOut ) const
554 const Internal::Actor& impl = GetImplementation(*this);
556 Vector2 widthPadding = impl.GetPadding( WIDTH );
557 Vector2 heightPadding = impl.GetPadding( HEIGHT );
559 paddingOut.left = widthPadding.x;
560 paddingOut.right = widthPadding.y;
561 paddingOut.bottom = heightPadding.x;
562 paddingOut.top = heightPadding.y;
565 void Actor::SetMinimumSize( const Vector2& size )
567 Internal::Actor& impl = GetImplementation(*this);
569 impl.SetMinimumSize( size.x, WIDTH );
570 impl.SetMinimumSize( size.y, HEIGHT );
573 Vector2 Actor::GetMinimumSize()
575 Internal::Actor& impl = GetImplementation(*this);
577 return Vector2( impl.GetMinimumSize( WIDTH ), impl.GetMinimumSize( HEIGHT ) );
580 void Actor::SetMaximumSize( const Vector2& size )
582 Internal::Actor& impl = GetImplementation(*this);
584 impl.SetMaximumSize( size.x, WIDTH );
585 impl.SetMaximumSize( size.y, HEIGHT );
588 Vector2 Actor::GetMaximumSize()
590 Internal::Actor& impl = GetImplementation(*this);
592 return Vector2( impl.GetMaximumSize( WIDTH ), impl.GetMaximumSize( HEIGHT ) );
595 Actor::TouchSignalType& Actor::TouchedSignal()
597 return GetImplementation(*this).TouchedSignal();
600 Actor::HoverSignalType& Actor::HoveredSignal()
602 return GetImplementation(*this).HoveredSignal();
605 Actor::MouseWheelEventSignalType& Actor::MouseWheelEventSignal()
607 return GetImplementation(*this).MouseWheelEventSignal();
610 Actor::OnStageSignalType& Actor::OnStageSignal()
612 return GetImplementation(*this).OnStageSignal();
615 Actor::OffStageSignalType& Actor::OffStageSignal()
617 return GetImplementation(*this).OffStageSignal();
620 Actor::OnRelayoutSignalType& Actor::OnRelayoutSignal()
622 return GetImplementation(*this).OnRelayoutSignal();
625 Actor::Actor(Internal::Actor* internal)
630 void UnparentAndReset( Actor& actor )