2 * Copyright (c) 2015 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/radian.h>
26 #include <dali/public-api/math/vector2.h>
28 #include <dali/internal/event/actors/actor-impl.h>
29 #include <dali/internal/event/actors/layer-impl.h>
30 #include <dali/internal/event/rendering/renderer-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 Internal::ActorPtr child = GetImplementation(*this).GetChildAt( index );
132 return Actor( child.Get() );
135 Actor Actor::FindChildByName(const std::string& actorName)
137 Internal::ActorPtr child = GetImplementation(*this).FindChildByName( actorName );
138 return Actor( child.Get() );
141 Actor Actor::FindChildById(const unsigned int id)
143 Internal::ActorPtr child = GetImplementation(*this).FindChildById( id );
144 return Actor( child.Get() );
147 Actor Actor::GetParent() const
149 Internal::Actor* parent = GetImplementation(*this).GetParent();
151 return Actor(parent);
154 void Actor::SetParentOrigin(const Vector3& origin)
156 GetImplementation(*this).SetParentOrigin(origin);
159 Vector3 Actor::GetCurrentParentOrigin() const
161 return GetImplementation(*this).GetCurrentParentOrigin();
164 void Actor::SetAnchorPoint(const Vector3& anchorPoint)
166 GetImplementation(*this).SetAnchorPoint(anchorPoint);
169 Vector3 Actor::GetCurrentAnchorPoint() const
171 return GetImplementation(*this).GetCurrentAnchorPoint();
174 void Actor::SetSize(float width, float height)
176 GetImplementation(*this).SetSize(width, height);
179 void Actor::SetSize(float width, float height, float depth)
181 GetImplementation(*this).SetSize(width, height, depth);
184 void Actor::SetSize(const Vector2& size)
186 GetImplementation(*this).SetSize( size );
189 void Actor::SetSize(const Vector3& size)
191 GetImplementation(*this).SetSize( size );
194 Vector3 Actor::GetTargetSize() const
196 return GetImplementation(*this).GetTargetSize();
199 Vector3 Actor::GetCurrentSize() const
201 return GetImplementation(*this).GetCurrentSize();
204 Vector3 Actor::GetNaturalSize() const
206 return GetImplementation(*this).GetNaturalSize();
209 void Actor::SetPosition(float x, float y)
211 GetImplementation(*this).SetPosition(x, y);
214 void Actor::SetPosition(float x, float y, float z)
216 GetImplementation(*this).SetPosition(x, y, z);
219 void Actor::SetPosition(const Vector3& position)
221 GetImplementation(*this).SetPosition(position);
224 void Actor::SetX(float x)
226 GetImplementation(*this).SetX(x);
229 void Actor::SetY(float y)
231 GetImplementation(*this).SetY(y);
234 void Actor::SetZ(float z)
236 GetImplementation(*this).SetZ(z);
239 void Actor::TranslateBy(const Vector3& distance)
241 GetImplementation(*this).TranslateBy(distance);
244 Vector3 Actor::GetCurrentPosition() const
246 return GetImplementation(*this).GetCurrentPosition();
249 Vector3 Actor::GetCurrentWorldPosition() const
251 return GetImplementation(*this).GetCurrentWorldPosition();
254 void Actor::SetPositionInheritanceMode( PositionInheritanceMode mode )
256 GetImplementation(*this).SetPositionInheritanceMode( mode );
259 PositionInheritanceMode Actor::GetPositionInheritanceMode() const
261 return GetImplementation(*this).GetPositionInheritanceMode();
264 void Actor::SetOrientation(const Radian& angle, const Vector3& axis)
266 GetImplementation(*this).SetOrientation(angle, axis);
269 void Actor::SetOrientation(const Quaternion& orientation)
271 GetImplementation(*this).SetOrientation(orientation);
274 void Actor::RotateBy(const Radian& angle, const Vector3& axis)
276 GetImplementation(*this).RotateBy(angle, axis);
279 void Actor::RotateBy(const Quaternion& relativeRotation)
281 GetImplementation(*this).RotateBy(relativeRotation);
284 Quaternion Actor::GetCurrentOrientation() const
286 return GetImplementation(*this).GetCurrentOrientation();
289 void Actor::SetInheritOrientation(bool inherit)
291 GetImplementation(*this).SetInheritOrientation(inherit);
294 bool Actor::IsOrientationInherited() const
296 return GetImplementation(*this).IsOrientationInherited();
299 Quaternion Actor::GetCurrentWorldOrientation() const
301 return GetImplementation(*this).GetCurrentWorldOrientation();
304 void Actor::SetScale(float scale)
306 GetImplementation(*this).SetScale(scale);
309 void Actor::SetScale(float scaleX, float scaleY, float scaleZ)
311 GetImplementation(*this).SetScale(scaleX, scaleY, scaleZ);
314 void Actor::SetScale(const Vector3& scale)
316 GetImplementation(*this).SetScale(scale);
319 void Actor::ScaleBy(const Vector3& relativeScale)
321 GetImplementation(*this).ScaleBy(relativeScale);
324 Vector3 Actor::GetCurrentScale() const
326 return GetImplementation(*this).GetCurrentScale();
329 Vector3 Actor::GetCurrentWorldScale() const
331 return GetImplementation(*this).GetCurrentWorldScale();
334 void Actor::SetInheritScale( bool inherit )
336 GetImplementation(*this).SetInheritScale( inherit );
339 bool Actor::IsScaleInherited() const
341 return GetImplementation(*this).IsScaleInherited();
344 void Actor::SetSizeModeFactor(const Vector3& factor)
346 GetImplementation(*this).SetSizeModeFactor(factor);
349 Vector3 Actor::GetSizeModeFactor() const
351 return GetImplementation(*this).GetSizeModeFactor();
354 Matrix Actor::GetCurrentWorldMatrix() const
356 return GetImplementation(*this).GetCurrentWorldMatrix();
359 void Actor::SetVisible(bool visible)
361 GetImplementation(*this).SetVisible(visible);
364 bool Actor::IsVisible() const
366 return GetImplementation(*this).IsVisible();
369 void Actor::SetOpacity(float opacity)
371 GetImplementation(*this).SetOpacity(opacity);
374 float Actor::GetCurrentOpacity() const
376 return GetImplementation(*this).GetCurrentOpacity();
379 void Actor::SetColor(const Vector4& color)
381 GetImplementation(*this).SetColor(color);
384 Vector4 Actor::GetCurrentColor() const
386 return GetImplementation(*this).GetCurrentColor();
389 void Actor::SetColorMode( ColorMode colorMode )
391 GetImplementation(*this).SetColorMode(colorMode);
394 ColorMode Actor::GetColorMode() const
396 return GetImplementation(*this).GetColorMode();
399 Vector4 Actor::GetCurrentWorldColor() const
401 return GetImplementation(*this).GetCurrentWorldColor();
404 void Actor::SetDrawMode( DrawMode::Type drawMode )
406 GetImplementation(*this).SetDrawMode( drawMode );
409 DrawMode::Type Actor::GetDrawMode() const
411 return GetImplementation(*this).GetDrawMode();
414 void Actor::SetSensitive(bool sensitive)
416 GetImplementation(*this).SetSensitive(sensitive);
419 bool Actor::IsSensitive() const
421 return GetImplementation(*this).IsSensitive();
424 bool Actor::ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const
426 return GetImplementation(*this).ScreenToLocal(localX, localY, screenX, screenY);
429 void Actor::SetLeaveRequired(bool required)
431 GetImplementation(*this).SetLeaveRequired(required);
434 bool Actor::GetLeaveRequired() const
436 return GetImplementation(*this).GetLeaveRequired();
439 void Actor::SetKeyboardFocusable( bool focusable )
441 GetImplementation(*this).SetKeyboardFocusable(focusable);
444 bool Actor::IsKeyboardFocusable() const
446 return GetImplementation(*this).IsKeyboardFocusable();
449 void Actor::SetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
451 GetImplementation(*this).SetResizePolicy( policy, dimension );
454 ResizePolicy::Type Actor::GetResizePolicy( Dimension::Type dimension ) const
456 return GetImplementation(*this).GetResizePolicy( dimension );
459 void Actor::SetSizeScalePolicy( SizeScalePolicy::Type policy )
461 GetImplementation(*this).SetSizeScalePolicy( policy );
464 SizeScalePolicy::Type Actor::GetSizeScalePolicy() const
466 return GetImplementation(*this).GetSizeScalePolicy();
469 float Actor::GetHeightForWidth( float width )
471 return GetImplementation(*this).GetHeightForWidth( width );
474 float Actor::GetWidthForHeight( float height )
476 return GetImplementation(*this).GetWidthForHeight( height );
479 float Actor::GetRelayoutSize( Dimension::Type dimension ) const
481 return GetImplementation(*this).GetRelayoutSize( dimension );
484 void Actor::SetPadding( const Padding& padding )
486 Internal::Actor& impl = GetImplementation(*this);
488 Vector2 widthPadding( padding.left, padding.right );
489 impl.SetPadding( widthPadding, Dimension::WIDTH );
491 Vector2 heightPadding( padding.bottom, padding.top );
492 impl.SetPadding( heightPadding, Dimension::HEIGHT );
495 void Actor::GetPadding( Padding& paddingOut ) const
497 const Internal::Actor& impl = GetImplementation(*this);
499 Vector2 widthPadding = impl.GetPadding( Dimension::WIDTH );
500 Vector2 heightPadding = impl.GetPadding( Dimension::HEIGHT );
502 paddingOut.left = widthPadding.x;
503 paddingOut.right = widthPadding.y;
504 paddingOut.bottom = heightPadding.x;
505 paddingOut.top = heightPadding.y;
508 void Actor::SetMinimumSize( const Vector2& size )
510 Internal::Actor& impl = GetImplementation(*this);
512 impl.SetMinimumSize( size.x, Dimension::WIDTH );
513 impl.SetMinimumSize( size.y, Dimension::HEIGHT );
516 Vector2 Actor::GetMinimumSize()
518 Internal::Actor& impl = GetImplementation(*this);
520 return Vector2( impl.GetMinimumSize( Dimension::WIDTH ), impl.GetMinimumSize( Dimension::HEIGHT ) );
523 void Actor::SetMaximumSize( const Vector2& size )
525 Internal::Actor& impl = GetImplementation(*this);
527 impl.SetMaximumSize( size.x, Dimension::WIDTH );
528 impl.SetMaximumSize( size.y, Dimension::HEIGHT );
531 Vector2 Actor::GetMaximumSize()
533 Internal::Actor& impl = GetImplementation(*this);
535 return Vector2( impl.GetMaximumSize( Dimension::WIDTH ), impl.GetMaximumSize( Dimension::HEIGHT ) );
538 int Actor::GetHierarchyDepth()
540 return GetImplementation(*this).GetHierarchyDepth();
543 Actor::TouchSignalType& Actor::TouchedSignal()
545 return GetImplementation(*this).TouchedSignal();
548 Actor::HoverSignalType& Actor::HoveredSignal()
550 return GetImplementation(*this).HoveredSignal();
553 Actor::WheelEventSignalType& Actor::WheelEventSignal()
555 return GetImplementation(*this).WheelEventSignal();
558 Actor::OnStageSignalType& Actor::OnStageSignal()
560 return GetImplementation(*this).OnStageSignal();
563 Actor::OffStageSignalType& Actor::OffStageSignal()
565 return GetImplementation(*this).OffStageSignal();
568 unsigned int Actor::AddRenderer( Renderer& renderer )
570 return GetImplementation(*this).AddRenderer( GetImplementation( renderer ) );
573 unsigned int Actor::GetRendererCount() const
575 return GetImplementation(*this).GetRendererCount();
578 Renderer Actor::GetRendererAt( unsigned int index )
580 return Renderer( &GetImplementation(*this).GetRendererAt( index ) );
583 void Actor::RemoveRenderer( Renderer& renderer )
585 GetImplementation(*this).RemoveRenderer( GetImplementation( renderer ) );
588 void Actor::RemoveRenderer( unsigned int index )
590 GetImplementation(*this).RemoveRenderer( index );
593 Actor::OnRelayoutSignalType& Actor::OnRelayoutSignal()
595 return GetImplementation(*this).OnRelayoutSignal();
598 Actor::Actor(Internal::Actor* internal)