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