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/actors/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 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 Radian& angle, const Vector3& axis)
265 GetImplementation(*this).SetOrientation(angle, axis);
268 void Actor::SetOrientation(const Quaternion& orientation)
270 GetImplementation(*this).SetOrientation(orientation);
273 void Actor::RotateBy(const Radian& angle, const Vector3& axis)
275 GetImplementation(*this).RotateBy(angle, axis);
278 void Actor::RotateBy(const Quaternion& relativeRotation)
280 GetImplementation(*this).RotateBy(relativeRotation);
283 Quaternion Actor::GetCurrentOrientation() const
285 return GetImplementation(*this).GetCurrentOrientation();
288 void Actor::SetInheritOrientation(bool inherit)
290 GetImplementation(*this).SetInheritOrientation(inherit);
293 bool Actor::IsOrientationInherited() const
295 return GetImplementation(*this).IsOrientationInherited();
298 Quaternion Actor::GetCurrentWorldOrientation() const
300 return GetImplementation(*this).GetCurrentWorldOrientation();
303 void Actor::SetScale(float scale)
305 GetImplementation(*this).SetScale(scale);
308 void Actor::SetScale(float scaleX, float scaleY, float scaleZ)
310 GetImplementation(*this).SetScale(scaleX, scaleY, scaleZ);
313 void Actor::SetScale(const Vector3& scale)
315 GetImplementation(*this).SetScale(scale);
318 void Actor::ScaleBy(const Vector3& relativeScale)
320 GetImplementation(*this).ScaleBy(relativeScale);
323 Vector3 Actor::GetCurrentScale() const
325 return GetImplementation(*this).GetCurrentScale();
328 Vector3 Actor::GetCurrentWorldScale() const
330 return GetImplementation(*this).GetCurrentWorldScale();
333 void Actor::SetInheritScale( bool inherit )
335 GetImplementation(*this).SetInheritScale( inherit );
338 bool Actor::IsScaleInherited() const
340 return GetImplementation(*this).IsScaleInherited();
343 void Actor::SetSizeModeFactor(const Vector3& factor)
345 GetImplementation(*this).SetSizeModeFactor(factor);
348 Vector3 Actor::GetSizeModeFactor() const
350 return GetImplementation(*this).GetSizeModeFactor();
353 Matrix Actor::GetCurrentWorldMatrix() const
355 return GetImplementation(*this).GetCurrentWorldMatrix();
358 void Actor::SetVisible(bool visible)
360 GetImplementation(*this).SetVisible(visible);
363 bool Actor::IsVisible() const
365 return GetImplementation(*this).IsVisible();
368 void Actor::SetOpacity(float opacity)
370 GetImplementation(*this).SetOpacity(opacity);
373 float Actor::GetCurrentOpacity() const
375 return GetImplementation(*this).GetCurrentOpacity();
378 void Actor::SetColor(const Vector4& color)
380 GetImplementation(*this).SetColor(color);
383 Vector4 Actor::GetCurrentColor() const
385 return GetImplementation(*this).GetCurrentColor();
388 void Actor::SetColorMode( ColorMode colorMode )
390 GetImplementation(*this).SetColorMode(colorMode);
393 ColorMode Actor::GetColorMode() const
395 return GetImplementation(*this).GetColorMode();
398 Vector4 Actor::GetCurrentWorldColor() const
400 return GetImplementation(*this).GetCurrentWorldColor();
403 void Actor::SetDrawMode( DrawMode::Type drawMode )
405 GetImplementation(*this).SetDrawMode( drawMode );
408 DrawMode::Type Actor::GetDrawMode() const
410 return GetImplementation(*this).GetDrawMode();
413 void Actor::SetSensitive(bool sensitive)
415 GetImplementation(*this).SetSensitive(sensitive);
418 bool Actor::IsSensitive() const
420 return GetImplementation(*this).IsSensitive();
423 bool Actor::ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const
425 return GetImplementation(*this).ScreenToLocal(localX, localY, screenX, screenY);
428 void Actor::SetLeaveRequired(bool required)
430 GetImplementation(*this).SetLeaveRequired(required);
433 bool Actor::GetLeaveRequired() const
435 return GetImplementation(*this).GetLeaveRequired();
438 void Actor::SetKeyboardFocusable( bool focusable )
440 GetImplementation(*this).SetKeyboardFocusable(focusable);
443 bool Actor::IsKeyboardFocusable() const
445 return GetImplementation(*this).IsKeyboardFocusable();
448 void Actor::SetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
450 GetImplementation(*this).SetResizePolicy( policy, dimension );
453 ResizePolicy::Type Actor::GetResizePolicy( Dimension::Type dimension ) const
455 return GetImplementation(*this).GetResizePolicy( dimension );
458 void Actor::SetSizeScalePolicy( SizeScalePolicy::Type policy )
460 GetImplementation(*this).SetSizeScalePolicy( policy );
463 SizeScalePolicy::Type Actor::GetSizeScalePolicy() const
465 return GetImplementation(*this).GetSizeScalePolicy();
468 float Actor::GetHeightForWidth( float width )
470 return GetImplementation(*this).GetHeightForWidth( width );
473 float Actor::GetWidthForHeight( float height )
475 return GetImplementation(*this).GetWidthForHeight( height );
478 float Actor::GetRelayoutSize( Dimension::Type dimension ) const
480 return GetImplementation(*this).GetRelayoutSize( dimension );
483 void Actor::SetPadding( const Padding& padding )
485 Internal::Actor& impl = GetImplementation(*this);
487 Vector2 widthPadding( padding.left, padding.right );
488 impl.SetPadding( widthPadding, Dimension::WIDTH );
490 Vector2 heightPadding( padding.bottom, padding.top );
491 impl.SetPadding( heightPadding, Dimension::HEIGHT );
494 void Actor::GetPadding( Padding& paddingOut ) const
496 const Internal::Actor& impl = GetImplementation(*this);
498 Vector2 widthPadding = impl.GetPadding( Dimension::WIDTH );
499 Vector2 heightPadding = impl.GetPadding( Dimension::HEIGHT );
501 paddingOut.left = widthPadding.x;
502 paddingOut.right = widthPadding.y;
503 paddingOut.bottom = heightPadding.x;
504 paddingOut.top = heightPadding.y;
507 void Actor::SetMinimumSize( const Vector2& size )
509 Internal::Actor& impl = GetImplementation(*this);
511 impl.SetMinimumSize( size.x, Dimension::WIDTH );
512 impl.SetMinimumSize( size.y, Dimension::HEIGHT );
515 Vector2 Actor::GetMinimumSize()
517 Internal::Actor& impl = GetImplementation(*this);
519 return Vector2( impl.GetMinimumSize( Dimension::WIDTH ), impl.GetMinimumSize( Dimension::HEIGHT ) );
522 void Actor::SetMaximumSize( const Vector2& size )
524 Internal::Actor& impl = GetImplementation(*this);
526 impl.SetMaximumSize( size.x, Dimension::WIDTH );
527 impl.SetMaximumSize( size.y, Dimension::HEIGHT );
530 Vector2 Actor::GetMaximumSize()
532 Internal::Actor& impl = GetImplementation(*this);
534 return Vector2( impl.GetMaximumSize( Dimension::WIDTH ), impl.GetMaximumSize( Dimension::HEIGHT ) );
537 Actor::TouchSignalType& Actor::TouchedSignal()
539 return GetImplementation(*this).TouchedSignal();
542 Actor::HoverSignalType& Actor::HoveredSignal()
544 return GetImplementation(*this).HoveredSignal();
547 Actor::WheelEventSignalType& Actor::WheelEventSignal()
549 return GetImplementation(*this).WheelEventSignal();
552 Actor::OnStageSignalType& Actor::OnStageSignal()
554 return GetImplementation(*this).OnStageSignal();
557 Actor::OffStageSignalType& Actor::OffStageSignal()
559 return GetImplementation(*this).OffStageSignal();
562 unsigned int Actor::AddRenderer( Renderer& renderer )
564 return GetImplementation(*this).AddRenderer( GetImplementation( renderer ) );
567 unsigned int Actor::GetRendererCount() const
569 return GetImplementation(*this).GetRendererCount();
572 Renderer Actor::GetRendererAt( unsigned int index )
574 return Renderer( &GetImplementation(*this).GetRendererAt( index ) );
577 void Actor::RemoveRenderer( Renderer& renderer )
579 GetImplementation(*this).RemoveRenderer( GetImplementation( renderer ) );
582 void Actor::RemoveRenderer( unsigned int index )
584 GetImplementation(*this).RemoveRenderer( index );
587 Actor::OnRelayoutSignalType& Actor::OnRelayoutSignal()
589 return GetImplementation(*this).OnRelayoutSignal();
592 Actor::Actor(Internal::Actor* internal)
597 void UnparentAndReset( Actor& actor )