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/animation/constraint-impl.h>
32 #include <dali/internal/event/size-negotiation/relayout-controller-impl.h>
43 Internal::ActorPtr internal = Internal::Actor::New();
45 return Actor(internal.Get());
48 Actor Actor::DownCast( BaseHandle handle )
50 return Actor( dynamic_cast<Dali::Internal::Actor*>(handle.GetObjectPtr()) );
57 Actor::Actor(const Actor& copy)
62 Actor& Actor::operator=(const Actor& rhs)
64 BaseHandle::operator=(rhs);
68 const std::string& Actor::GetName() const
70 return GetImplementation(*this).GetName();
73 void Actor::SetName(const std::string& name)
75 GetImplementation(*this).SetName(name);
78 unsigned int Actor::GetId() const
80 return GetImplementation(*this).GetId();
83 bool Actor::IsRoot() const
85 return GetImplementation(*this).IsRoot();
88 bool Actor::OnStage() const
90 return GetImplementation(*this).OnStage();
93 bool Actor::IsLayer() const
95 return GetImplementation(*this).IsLayer();
98 Layer Actor::GetLayer()
100 return GetImplementation(*this).GetLayer();
103 void Actor::Add(Actor actor)
105 GetImplementation(*this).Add(GetImplementation(actor));
108 void Actor::Remove(Actor actor)
110 GetImplementation(*this).Remove(GetImplementation(actor));
113 void Actor::Unparent()
115 GetImplementation(*this).Unparent();
118 unsigned int Actor::GetChildCount() const
120 return GetImplementation(*this).GetChildCount();
123 Actor Actor::GetChildAt(unsigned int index) const
125 Internal::ActorPtr child = GetImplementation(*this).GetChildAt( index );
126 return Actor( child.Get() );
129 Actor Actor::FindChildByName(const std::string& actorName)
131 Internal::ActorPtr child = GetImplementation(*this).FindChildByName( actorName );
132 return Actor( child.Get() );
135 Actor Actor::FindChildById(const unsigned int id)
137 Internal::ActorPtr child = GetImplementation(*this).FindChildById( id );
138 return Actor( child.Get() );
141 Actor Actor::GetParent() const
143 Internal::Actor* parent = GetImplementation(*this).GetParent();
145 return Actor(parent);
148 void Actor::SetParentOrigin(const Vector3& origin)
150 GetImplementation(*this).SetParentOrigin(origin);
153 Vector3 Actor::GetCurrentParentOrigin() const
155 return GetImplementation(*this).GetCurrentParentOrigin();
158 void Actor::SetAnchorPoint(const Vector3& anchorPoint)
160 GetImplementation(*this).SetAnchorPoint(anchorPoint);
163 Vector3 Actor::GetCurrentAnchorPoint() const
165 return GetImplementation(*this).GetCurrentAnchorPoint();
168 void Actor::SetSize(float width, float height)
170 GetImplementation(*this).SetSize(width, height);
173 void Actor::SetSize(float width, float height, float depth)
175 GetImplementation(*this).SetSize(width, height, depth);
178 void Actor::SetSize(const Vector2& size)
180 GetImplementation(*this).SetSize( size );
183 void Actor::SetSize(const Vector3& size)
185 GetImplementation(*this).SetSize( size );
188 Vector3 Actor::GetTargetSize() const
190 return GetImplementation(*this).GetTargetSize();
193 Vector3 Actor::GetCurrentSize() const
195 return GetImplementation(*this).GetCurrentSize();
198 Vector3 Actor::GetNaturalSize() const
200 return GetImplementation(*this).GetNaturalSize();
203 void Actor::SetPosition(float x, float y)
205 GetImplementation(*this).SetPosition(x, y);
208 void Actor::SetPosition(float x, float y, float z)
210 GetImplementation(*this).SetPosition(x, y, z);
213 void Actor::SetPosition(const Vector3& position)
215 GetImplementation(*this).SetPosition(position);
218 void Actor::SetX(float x)
220 GetImplementation(*this).SetX(x);
223 void Actor::SetY(float y)
225 GetImplementation(*this).SetY(y);
228 void Actor::SetZ(float z)
230 GetImplementation(*this).SetZ(z);
233 void Actor::TranslateBy(const Vector3& distance)
235 GetImplementation(*this).TranslateBy(distance);
238 Vector3 Actor::GetCurrentPosition() const
240 return GetImplementation(*this).GetCurrentPosition();
243 Vector3 Actor::GetCurrentWorldPosition() const
245 return GetImplementation(*this).GetCurrentWorldPosition();
248 void Actor::SetPositionInheritanceMode( PositionInheritanceMode mode )
250 GetImplementation(*this).SetPositionInheritanceMode( mode );
253 PositionInheritanceMode Actor::GetPositionInheritanceMode() const
255 return GetImplementation(*this).GetPositionInheritanceMode();
258 void Actor::SetOrientation(const Radian& angle, const Vector3& axis)
260 GetImplementation(*this).SetOrientation(angle, axis);
263 void Actor::SetOrientation(const Quaternion& orientation)
265 GetImplementation(*this).SetOrientation(orientation);
268 void Actor::RotateBy(const Radian& angle, const Vector3& axis)
270 GetImplementation(*this).RotateBy(angle, axis);
273 void Actor::RotateBy(const Quaternion& relativeRotation)
275 GetImplementation(*this).RotateBy(relativeRotation);
278 Quaternion Actor::GetCurrentOrientation() const
280 return GetImplementation(*this).GetCurrentOrientation();
283 void Actor::SetInheritOrientation(bool inherit)
285 GetImplementation(*this).SetInheritOrientation(inherit);
288 bool Actor::IsOrientationInherited() const
290 return GetImplementation(*this).IsOrientationInherited();
293 Quaternion Actor::GetCurrentWorldOrientation() const
295 return GetImplementation(*this).GetCurrentWorldOrientation();
298 void Actor::SetScale(float scale)
300 GetImplementation(*this).SetScale(scale);
303 void Actor::SetScale(float scaleX, float scaleY, float scaleZ)
305 GetImplementation(*this).SetScale(scaleX, scaleY, scaleZ);
308 void Actor::SetScale(const Vector3& scale)
310 GetImplementation(*this).SetScale(scale);
313 void Actor::ScaleBy(const Vector3& relativeScale)
315 GetImplementation(*this).ScaleBy(relativeScale);
318 Vector3 Actor::GetCurrentScale() const
320 return GetImplementation(*this).GetCurrentScale();
323 Vector3 Actor::GetCurrentWorldScale() const
325 return GetImplementation(*this).GetCurrentWorldScale();
328 void Actor::SetInheritScale( bool inherit )
330 GetImplementation(*this).SetInheritScale( inherit );
333 bool Actor::IsScaleInherited() const
335 return GetImplementation(*this).IsScaleInherited();
338 void Actor::SetSizeModeFactor(const Vector3& factor)
340 GetImplementation(*this).SetSizeModeFactor(factor);
343 Vector3 Actor::GetSizeModeFactor() const
345 return GetImplementation(*this).GetSizeModeFactor();
348 Matrix Actor::GetCurrentWorldMatrix() const
350 return GetImplementation(*this).GetCurrentWorldMatrix();
353 void Actor::SetVisible(bool visible)
355 GetImplementation(*this).SetVisible(visible);
358 bool Actor::IsVisible() const
360 return GetImplementation(*this).IsVisible();
363 void Actor::SetOpacity(float opacity)
365 GetImplementation(*this).SetOpacity(opacity);
368 float Actor::GetCurrentOpacity() const
370 return GetImplementation(*this).GetCurrentOpacity();
373 void Actor::SetColor(const Vector4& color)
375 GetImplementation(*this).SetColor(color);
378 Vector4 Actor::GetCurrentColor() const
380 return GetImplementation(*this).GetCurrentColor();
383 void Actor::SetColorMode( ColorMode colorMode )
385 GetImplementation(*this).SetColorMode(colorMode);
388 ColorMode Actor::GetColorMode() const
390 return GetImplementation(*this).GetColorMode();
393 Vector4 Actor::GetCurrentWorldColor() const
395 return GetImplementation(*this).GetCurrentWorldColor();
398 void Actor::SetDrawMode( DrawMode::Type drawMode )
400 GetImplementation(*this).SetDrawMode( drawMode );
403 DrawMode::Type Actor::GetDrawMode() const
405 return GetImplementation(*this).GetDrawMode();
408 void Actor::SetSensitive(bool sensitive)
410 GetImplementation(*this).SetSensitive(sensitive);
413 bool Actor::IsSensitive() const
415 return GetImplementation(*this).IsSensitive();
418 bool Actor::ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const
420 return GetImplementation(*this).ScreenToLocal(localX, localY, screenX, screenY);
423 void Actor::SetLeaveRequired(bool required)
425 GetImplementation(*this).SetLeaveRequired(required);
428 bool Actor::GetLeaveRequired() const
430 return GetImplementation(*this).GetLeaveRequired();
433 void Actor::SetKeyboardFocusable( bool focusable )
435 GetImplementation(*this).SetKeyboardFocusable(focusable);
438 bool Actor::IsKeyboardFocusable() const
440 return GetImplementation(*this).IsKeyboardFocusable();
443 void Actor::SetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
445 GetImplementation(*this).SetResizePolicy( policy, dimension );
448 ResizePolicy::Type Actor::GetResizePolicy( Dimension::Type dimension ) const
450 return GetImplementation(*this).GetResizePolicy( dimension );
453 void Actor::SetSizeScalePolicy( SizeScalePolicy::Type policy )
455 GetImplementation(*this).SetSizeScalePolicy( policy );
458 SizeScalePolicy::Type Actor::GetSizeScalePolicy() const
460 return GetImplementation(*this).GetSizeScalePolicy();
463 float Actor::GetHeightForWidth( float width )
465 return GetImplementation(*this).GetHeightForWidth( width );
468 float Actor::GetWidthForHeight( float height )
470 return GetImplementation(*this).GetWidthForHeight( height );
473 float Actor::GetRelayoutSize( Dimension::Type dimension ) const
475 return GetImplementation(*this).GetRelayoutSize( dimension );
478 void Actor::SetPadding( const Padding& padding )
480 Internal::Actor& impl = GetImplementation(*this);
482 Vector2 widthPadding( padding.left, padding.right );
483 impl.SetPadding( widthPadding, Dimension::WIDTH );
485 Vector2 heightPadding( padding.bottom, padding.top );
486 impl.SetPadding( heightPadding, Dimension::HEIGHT );
489 void Actor::GetPadding( Padding& paddingOut ) const
491 const Internal::Actor& impl = GetImplementation(*this);
493 Vector2 widthPadding = impl.GetPadding( Dimension::WIDTH );
494 Vector2 heightPadding = impl.GetPadding( Dimension::HEIGHT );
496 paddingOut.left = widthPadding.x;
497 paddingOut.right = widthPadding.y;
498 paddingOut.bottom = heightPadding.x;
499 paddingOut.top = heightPadding.y;
502 void Actor::SetMinimumSize( const Vector2& size )
504 Internal::Actor& impl = GetImplementation(*this);
506 impl.SetMinimumSize( size.x, Dimension::WIDTH );
507 impl.SetMinimumSize( size.y, Dimension::HEIGHT );
510 Vector2 Actor::GetMinimumSize()
512 Internal::Actor& impl = GetImplementation(*this);
514 return Vector2( impl.GetMinimumSize( Dimension::WIDTH ), impl.GetMinimumSize( Dimension::HEIGHT ) );
517 void Actor::SetMaximumSize( const Vector2& size )
519 Internal::Actor& impl = GetImplementation(*this);
521 impl.SetMaximumSize( size.x, Dimension::WIDTH );
522 impl.SetMaximumSize( size.y, Dimension::HEIGHT );
525 Vector2 Actor::GetMaximumSize()
527 Internal::Actor& impl = GetImplementation(*this);
529 return Vector2( impl.GetMaximumSize( Dimension::WIDTH ), impl.GetMaximumSize( Dimension::HEIGHT ) );
532 int Actor::GetHierarchyDepth()
534 return GetImplementation(*this).GetHierarchyDepth();
537 Actor::TouchSignalType& Actor::TouchedSignal()
539 return GetImplementation(*this).TouchedSignal();
542 Actor::TouchDataSignalType& Actor::TouchSignal()
544 return GetImplementation( *this ).TouchSignal();
547 Actor::HoverSignalType& Actor::HoveredSignal()
549 return GetImplementation(*this).HoveredSignal();
552 Actor::WheelEventSignalType& Actor::WheelEventSignal()
554 return GetImplementation(*this).WheelEventSignal();
557 Actor::OnStageSignalType& Actor::OnStageSignal()
559 return GetImplementation(*this).OnStageSignal();
562 Actor::OffStageSignalType& Actor::OffStageSignal()
564 return GetImplementation(*this).OffStageSignal();
567 unsigned int Actor::AddRenderer( Renderer& renderer )
569 return GetImplementation(*this).AddRenderer( GetImplementation( renderer ) );
572 unsigned int Actor::GetRendererCount() const
574 return GetImplementation(*this).GetRendererCount();
577 Renderer Actor::GetRendererAt( unsigned int index )
579 Internal::RendererPtr renderer = GetImplementation(*this).GetRendererAt( index );
580 return Renderer( renderer.Get() );
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)