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/actors/renderer-impl.h>
32 #include <dali/internal/event/actor-attachments/actor-attachment-impl.h>
33 #include <dali/internal/event/animation/constraint-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 GetImplementation(*this).SetSize(width, height);
178 void Actor::SetSize(float width, float height, float depth)
180 GetImplementation(*this).SetSize(width, height, depth);
183 void Actor::SetSize(const Vector2& size)
185 GetImplementation(*this).SetSize(size);
188 void Actor::SetSize(const Vector3& size)
190 GetImplementation(*this).SetSize(size);
193 Vector3 Actor::GetTargetSize() const
195 return GetImplementation(*this).GetTargetSize();
198 Vector3 Actor::GetCurrentSize() const
200 return GetImplementation(*this).GetCurrentSize();
203 Vector3 Actor::GetNaturalSize() const
205 return GetImplementation(*this).GetNaturalSize();
208 void Actor::SetPosition(float x, float y)
210 GetImplementation(*this).SetPosition(x, y);
213 void Actor::SetPosition(float x, float y, float z)
215 GetImplementation(*this).SetPosition(x, y, z);
218 void Actor::SetPosition(const Vector3& position)
220 GetImplementation(*this).SetPosition(position);
223 void Actor::SetX(float x)
225 GetImplementation(*this).SetX(x);
228 void Actor::SetY(float y)
230 GetImplementation(*this).SetY(y);
233 void Actor::SetZ(float z)
235 GetImplementation(*this).SetZ(z);
238 void Actor::TranslateBy(const Vector3& distance)
240 GetImplementation(*this).TranslateBy(distance);
243 Vector3 Actor::GetCurrentPosition() const
245 return GetImplementation(*this).GetCurrentPosition();
248 Vector3 Actor::GetCurrentWorldPosition() const
250 return GetImplementation(*this).GetCurrentWorldPosition();
253 void Actor::SetPositionInheritanceMode( PositionInheritanceMode mode )
255 GetImplementation(*this).SetPositionInheritanceMode( mode );
258 PositionInheritanceMode Actor::GetPositionInheritanceMode() const
260 return GetImplementation(*this).GetPositionInheritanceMode();
263 void Actor::SetOrientation(const Degree& angle, const Vector3& axis)
265 GetImplementation(*this).SetOrientation(Radian(angle), axis);
268 void Actor::SetOrientation(const Radian& angle, const Vector3& axis)
270 GetImplementation(*this).SetOrientation(angle, axis);
273 void Actor::SetOrientation(const Quaternion& orientation)
275 GetImplementation(*this).SetOrientation(orientation);
278 void Actor::RotateBy(const Degree& angle, const Vector3& axis)
280 GetImplementation(*this).RotateBy(Radian(angle), axis);
283 void Actor::RotateBy(const Radian& angle, const Vector3& axis)
285 GetImplementation(*this).RotateBy(angle, axis);
288 void Actor::RotateBy(const Quaternion& relativeRotation)
290 GetImplementation(*this).RotateBy(relativeRotation);
293 Quaternion Actor::GetCurrentOrientation() const
295 return GetImplementation(*this).GetCurrentOrientation();
298 void Actor::SetInheritOrientation(bool inherit)
300 GetImplementation(*this).SetInheritOrientation(inherit);
303 bool Actor::IsOrientationInherited() const
305 return GetImplementation(*this).IsOrientationInherited();
308 Quaternion Actor::GetCurrentWorldOrientation() const
310 return GetImplementation(*this).GetCurrentWorldOrientation();
313 void Actor::SetScale(float scale)
315 GetImplementation(*this).SetScale(scale);
318 void Actor::SetScale(float scaleX, float scaleY, float scaleZ)
320 GetImplementation(*this).SetScale(scaleX, scaleY, scaleZ);
323 void Actor::SetScale(const Vector3& scale)
325 GetImplementation(*this).SetScale(scale);
328 void Actor::ScaleBy(const Vector3& relativeScale)
330 GetImplementation(*this).ScaleBy(relativeScale);
333 Vector3 Actor::GetCurrentScale() const
335 return GetImplementation(*this).GetCurrentScale();
338 Vector3 Actor::GetCurrentWorldScale() const
340 return GetImplementation(*this).GetCurrentWorldScale();
343 void Actor::SetInheritScale( bool inherit )
345 GetImplementation(*this).SetInheritScale( inherit );
348 bool Actor::IsScaleInherited() const
350 return GetImplementation(*this).IsScaleInherited();
353 void Actor::SetSizeMode(SizeMode mode)
355 GetImplementation(*this).SetSizeMode(mode);
358 SizeMode Actor::GetSizeMode() const
360 return GetImplementation(*this).GetSizeMode();
363 void Actor::SetSizeModeFactor(const Vector3& factor)
365 GetImplementation(*this).SetSizeModeFactor(factor);
368 Vector3 Actor::GetSizeModeFactor() const
370 return GetImplementation(*this).GetSizeModeFactor();
373 Matrix Actor::GetCurrentWorldMatrix() const
375 return GetImplementation(*this).GetCurrentWorldMatrix();
378 void Actor::SetVisible(bool visible)
380 GetImplementation(*this).SetVisible(visible);
383 bool Actor::IsVisible() const
385 return GetImplementation(*this).IsVisible();
388 void Actor::SetOpacity(float opacity)
390 GetImplementation(*this).SetOpacity(opacity);
393 float Actor::GetCurrentOpacity() const
395 return GetImplementation(*this).GetCurrentOpacity();
398 void Actor::SetColor(const Vector4& color)
400 GetImplementation(*this).SetColor(color);
403 Vector4 Actor::GetCurrentColor() const
405 return GetImplementation(*this).GetCurrentColor();
408 void Actor::SetColorMode( ColorMode colorMode )
410 GetImplementation(*this).SetColorMode(colorMode);
413 ColorMode Actor::GetColorMode() const
415 return GetImplementation(*this).GetColorMode();
418 Vector4 Actor::GetCurrentWorldColor() const
420 return GetImplementation(*this).GetCurrentWorldColor();
423 void Actor::SetDrawMode( DrawMode::Type drawMode )
425 GetImplementation(*this).SetDrawMode( drawMode );
428 DrawMode::Type Actor::GetDrawMode() const
430 return GetImplementation(*this).GetDrawMode();
433 void Actor::SetSensitive(bool sensitive)
435 GetImplementation(*this).SetSensitive(sensitive);
438 bool Actor::IsSensitive() const
440 return GetImplementation(*this).IsSensitive();
443 bool Actor::ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const
445 return GetImplementation(*this).ScreenToLocal(localX, localY, screenX, screenY);
448 void Actor::SetLeaveRequired(bool required)
450 GetImplementation(*this).SetLeaveRequired(required);
453 bool Actor::GetLeaveRequired() const
455 return GetImplementation(*this).GetLeaveRequired();
458 void Actor::SetKeyboardFocusable( bool focusable )
460 GetImplementation(*this).SetKeyboardFocusable(focusable);
463 bool Actor::IsKeyboardFocusable() const
465 return GetImplementation(*this).IsKeyboardFocusable();
468 void Actor::SetRelayoutEnabled( bool enabled )
470 GetImplementation(*this).SetRelayoutEnabled( enabled );
473 bool Actor::IsRelayoutEnabled() const
475 return GetImplementation(*this).IsRelayoutEnabled();
478 void Actor::SetResizePolicy( ResizePolicy policy, Dimension dimension )
480 GetImplementation(*this).SetResizePolicy( policy, dimension );
483 ResizePolicy Actor::GetResizePolicy( Dimension dimension ) const
485 return GetImplementation(*this).GetResizePolicy( dimension );
488 void Actor::SetSizeScalePolicy( SizeScalePolicy policy )
490 GetImplementation(*this).SetSizeScalePolicy( policy );
493 SizeScalePolicy Actor::GetSizeScalePolicy() const
495 return GetImplementation(*this).GetSizeScalePolicy();
498 void Actor::SetDimensionDependency( Dimension dimension, Dimension dependency )
500 GetImplementation(*this).SetDimensionDependency( dimension, dependency );
503 Dimension Actor::GetDimensionDependency( Dimension dimension )
505 return GetImplementation(*this).GetDimensionDependency( dimension );
508 float Actor::GetHeightForWidth( float width )
510 return GetImplementation(*this).GetHeightForWidth( width );
513 float Actor::GetWidthForHeight( float height )
515 return GetImplementation(*this).GetWidthForHeight( height );
518 float Actor::GetRelayoutSize( Dimension dimension ) const
520 return GetImplementation(*this).GetRelayoutSize( dimension );
523 void Actor::RelayoutRequestTree()
525 GetImplementation(*this).RelayoutRequestTree();
528 void Actor::PropagateRelayoutFlags()
530 GetImplementation(*this).PropagateRelayoutFlags();
533 void Actor::SetPadding( const Padding& padding )
535 Internal::Actor& impl = GetImplementation(*this);
537 Vector2 widthPadding( padding.left, padding.right );
538 impl.SetPadding( widthPadding, WIDTH );
540 Vector2 heightPadding( padding.bottom, padding.top );
541 impl.SetPadding( heightPadding, HEIGHT );
544 void Actor::GetPadding( Padding& paddingOut ) const
546 const Internal::Actor& impl = GetImplementation(*this);
548 Vector2 widthPadding = impl.GetPadding( WIDTH );
549 Vector2 heightPadding = impl.GetPadding( HEIGHT );
551 paddingOut.left = widthPadding.x;
552 paddingOut.right = widthPadding.y;
553 paddingOut.bottom = heightPadding.x;
554 paddingOut.top = heightPadding.y;
557 void Actor::SetPreferredSize( const Vector2& size )
559 GetImplementation(*this).SetPreferredSize( size );
562 Vector2 Actor::GetPreferredSize() const
564 return GetImplementation(*this).GetPreferredSize();
567 void Actor::SetMinimumSize( const Vector2& size )
569 Internal::Actor& impl = GetImplementation(*this);
571 impl.SetMinimumSize( size.x, WIDTH );
572 impl.SetMinimumSize( size.y, HEIGHT );
575 Vector2 Actor::GetMinimumSize()
577 Internal::Actor& impl = GetImplementation(*this);
579 return Vector2( impl.GetMinimumSize( WIDTH ), impl.GetMinimumSize( HEIGHT ) );
582 void Actor::SetMaximumSize( const Vector2& size )
584 Internal::Actor& impl = GetImplementation(*this);
586 impl.SetMaximumSize( size.x, WIDTH );
587 impl.SetMaximumSize( size.y, HEIGHT );
590 Vector2 Actor::GetMaximumSize()
592 Internal::Actor& impl = GetImplementation(*this);
594 return Vector2( impl.GetMaximumSize( WIDTH ), impl.GetMaximumSize( HEIGHT ) );
597 Actor::TouchSignalType& Actor::TouchedSignal()
599 return GetImplementation(*this).TouchedSignal();
602 Actor::HoverSignalType& Actor::HoveredSignal()
604 return GetImplementation(*this).HoveredSignal();
607 Actor::MouseWheelEventSignalType& Actor::MouseWheelEventSignal()
609 return GetImplementation(*this).MouseWheelEventSignal();
612 Actor::OnStageSignalType& Actor::OnStageSignal()
614 return GetImplementation(*this).OnStageSignal();
617 Actor::OffStageSignalType& Actor::OffStageSignal()
619 return GetImplementation(*this).OffStageSignal();
622 unsigned int Actor::AddRenderer( Renderer& renderer )
624 return GetImplementation(*this).AddRenderer( GetImplementation( renderer ) );
627 unsigned int Actor::GetRendererCount() const
629 return GetImplementation(*this).GetRendererCount();
632 Renderer Actor::GetRendererAt( unsigned int index )
634 return Renderer( &GetImplementation(*this).GetRendererAt( index ) );
637 void Actor::RemoveRenderer( Renderer& renderer )
639 GetImplementation(*this).RemoveRenderer( GetImplementation( renderer ) );
642 void Actor::RemoveRenderer( unsigned int index )
644 GetImplementation(*this).RemoveRenderer( index );
647 Actor::OnRelayoutSignalType& Actor::OnRelayoutSignal()
649 return GetImplementation(*this).OnRelayoutSignal();
652 Actor::Actor(Internal::Actor* internal)
657 void UnparentAndReset( Actor& actor )