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 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::SetSizeModeFactor(const Vector3& factor)
355 GetImplementation(*this).SetSizeModeFactor(factor);
358 Vector3 Actor::GetSizeModeFactor() const
360 return GetImplementation(*this).GetSizeModeFactor();
363 Matrix Actor::GetCurrentWorldMatrix() const
365 return GetImplementation(*this).GetCurrentWorldMatrix();
368 void Actor::SetVisible(bool visible)
370 GetImplementation(*this).SetVisible(visible);
373 bool Actor::IsVisible() const
375 return GetImplementation(*this).IsVisible();
378 void Actor::SetOpacity(float opacity)
380 GetImplementation(*this).SetOpacity(opacity);
383 float Actor::GetCurrentOpacity() const
385 return GetImplementation(*this).GetCurrentOpacity();
388 void Actor::SetColor(const Vector4& color)
390 GetImplementation(*this).SetColor(color);
393 Vector4 Actor::GetCurrentColor() const
395 return GetImplementation(*this).GetCurrentColor();
398 void Actor::SetColorMode( ColorMode colorMode )
400 GetImplementation(*this).SetColorMode(colorMode);
403 ColorMode Actor::GetColorMode() const
405 return GetImplementation(*this).GetColorMode();
408 Vector4 Actor::GetCurrentWorldColor() const
410 return GetImplementation(*this).GetCurrentWorldColor();
413 void Actor::SetDrawMode( DrawMode::Type drawMode )
415 GetImplementation(*this).SetDrawMode( drawMode );
418 DrawMode::Type Actor::GetDrawMode() const
420 return GetImplementation(*this).GetDrawMode();
423 void Actor::SetSensitive(bool sensitive)
425 GetImplementation(*this).SetSensitive(sensitive);
428 bool Actor::IsSensitive() const
430 return GetImplementation(*this).IsSensitive();
433 bool Actor::ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const
435 return GetImplementation(*this).ScreenToLocal(localX, localY, screenX, screenY);
438 void Actor::SetLeaveRequired(bool required)
440 GetImplementation(*this).SetLeaveRequired(required);
443 bool Actor::GetLeaveRequired() const
445 return GetImplementation(*this).GetLeaveRequired();
448 void Actor::SetKeyboardFocusable( bool focusable )
450 GetImplementation(*this).SetKeyboardFocusable(focusable);
453 bool Actor::IsKeyboardFocusable() const
455 return GetImplementation(*this).IsKeyboardFocusable();
458 void Actor::SetRelayoutEnabled( bool enabled )
460 GetImplementation(*this).SetRelayoutEnabled( enabled );
463 bool Actor::IsRelayoutEnabled() const
465 return GetImplementation(*this).IsRelayoutEnabled();
468 void Actor::SetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
470 GetImplementation(*this).SetResizePolicy( policy, dimension );
473 ResizePolicy::Type Actor::GetResizePolicy( Dimension::Type dimension ) const
475 return GetImplementation(*this).GetResizePolicy( dimension );
478 void Actor::SetSizeScalePolicy( SizeScalePolicy::Type policy )
480 GetImplementation(*this).SetSizeScalePolicy( policy );
483 SizeScalePolicy::Type Actor::GetSizeScalePolicy() const
485 return GetImplementation(*this).GetSizeScalePolicy();
488 float Actor::GetHeightForWidth( float width )
490 return GetImplementation(*this).GetHeightForWidth( width );
493 float Actor::GetWidthForHeight( float height )
495 return GetImplementation(*this).GetWidthForHeight( height );
498 float Actor::GetRelayoutSize( Dimension::Type dimension ) const
500 return GetImplementation(*this).GetRelayoutSize( dimension );
503 void Actor::RelayoutRequestTree()
505 GetImplementation(*this).RelayoutRequestTree();
508 void Actor::PropagateRelayoutFlags()
510 GetImplementation(*this).PropagateRelayoutFlags();
513 void Actor::SetPadding( const Padding& padding )
515 Internal::Actor& impl = GetImplementation(*this);
517 Vector2 widthPadding( padding.left, padding.right );
518 impl.SetPadding( widthPadding, Dimension::WIDTH );
520 Vector2 heightPadding( padding.bottom, padding.top );
521 impl.SetPadding( heightPadding, Dimension::HEIGHT );
524 void Actor::GetPadding( Padding& paddingOut ) const
526 const Internal::Actor& impl = GetImplementation(*this);
528 Vector2 widthPadding = impl.GetPadding( Dimension::WIDTH );
529 Vector2 heightPadding = impl.GetPadding( Dimension::HEIGHT );
531 paddingOut.left = widthPadding.x;
532 paddingOut.right = widthPadding.y;
533 paddingOut.bottom = heightPadding.x;
534 paddingOut.top = heightPadding.y;
537 void Actor::SetMinimumSize( const Vector2& size )
539 Internal::Actor& impl = GetImplementation(*this);
541 impl.SetMinimumSize( size.x, Dimension::WIDTH );
542 impl.SetMinimumSize( size.y, Dimension::HEIGHT );
545 Vector2 Actor::GetMinimumSize()
547 Internal::Actor& impl = GetImplementation(*this);
549 return Vector2( impl.GetMinimumSize( Dimension::WIDTH ), impl.GetMinimumSize( Dimension::HEIGHT ) );
552 void Actor::SetMaximumSize( const Vector2& size )
554 Internal::Actor& impl = GetImplementation(*this);
556 impl.SetMaximumSize( size.x, Dimension::WIDTH );
557 impl.SetMaximumSize( size.y, Dimension::HEIGHT );
560 Vector2 Actor::GetMaximumSize()
562 Internal::Actor& impl = GetImplementation(*this);
564 return Vector2( impl.GetMaximumSize( Dimension::WIDTH ), impl.GetMaximumSize( Dimension::HEIGHT ) );
567 Actor::TouchSignalType& Actor::TouchedSignal()
569 return GetImplementation(*this).TouchedSignal();
572 Actor::HoverSignalType& Actor::HoveredSignal()
574 return GetImplementation(*this).HoveredSignal();
577 Actor::MouseWheelEventSignalType& Actor::MouseWheelEventSignal()
579 return GetImplementation(*this).MouseWheelEventSignal();
582 Actor::OnStageSignalType& Actor::OnStageSignal()
584 return GetImplementation(*this).OnStageSignal();
587 Actor::OffStageSignalType& Actor::OffStageSignal()
589 return GetImplementation(*this).OffStageSignal();
592 Actor::OnRelayoutSignalType& Actor::OnRelayoutSignal()
594 return GetImplementation(*this).OnRelayoutSignal();
597 Actor::Actor(Internal::Actor* internal)
602 void UnparentAndReset( Actor& actor )