2 * Copyright (c) 2020 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 uint32_t Actor::GetId() const
70 return GetImplementation(*this).GetId();
73 bool Actor::IsRoot() const
75 return GetImplementation(*this).IsRoot();
78 bool Actor::OnStage() const
80 return GetImplementation(*this).OnStage();
83 bool Actor::IsLayer() const
85 return GetImplementation(*this).IsLayer();
88 Layer Actor::GetLayer()
90 return GetImplementation(*this).GetLayer();
93 void Actor::Add(Actor actor)
95 GetImplementation(*this).Add(GetImplementation(actor));
98 void Actor::Remove(Actor actor)
100 GetImplementation(*this).Remove(GetImplementation(actor));
103 void Actor::Unparent()
105 GetImplementation(*this).Unparent();
108 uint32_t Actor::GetChildCount() const
110 return GetImplementation(*this).GetChildCount();
113 Actor Actor::GetChildAt( uint32_t index ) const
115 Internal::ActorPtr child = GetImplementation(*this).GetChildAt( index );
116 return Actor( child.Get() );
119 Actor Actor::FindChildByName(const std::string& actorName)
121 Internal::ActorPtr child = GetImplementation(*this).FindChildByName( actorName );
122 return Actor( child.Get() );
125 Actor Actor::FindChildById( const uint32_t id )
127 Internal::ActorPtr child = GetImplementation(*this).FindChildById( id );
128 return Actor( child.Get() );
131 Actor Actor::GetParent() const
133 Internal::Actor* parent = GetImplementation(*this).GetParent();
135 return Actor(parent);
138 void Actor::SetSize(float width, float height)
140 GetImplementation(*this).SetSize(width, height);
143 void Actor::SetSize(float width, float height, float depth)
145 GetImplementation(*this).SetSize(width, height, depth);
148 void Actor::SetSize(const Vector2& size)
150 GetImplementation(*this).SetSize( size );
153 void Actor::SetSize(const Vector3& size)
155 GetImplementation(*this).SetSize( size );
158 Vector3 Actor::GetTargetSize() const
160 return GetImplementation(*this).GetTargetSize();
163 Vector3 Actor::GetNaturalSize() const
165 return GetImplementation(*this).GetNaturalSize();
168 void Actor::SetPosition(float x, float y)
170 GetImplementation(*this).SetPosition(x, y);
173 void Actor::SetPosition(float x, float y, float z)
175 GetImplementation(*this).SetPosition(x, y, z);
178 void Actor::SetPosition(const Vector3& position)
180 GetImplementation(*this).SetPosition(position);
183 void Actor::SetX(float x)
185 GetImplementation(*this).SetX(x);
188 void Actor::SetY(float y)
190 GetImplementation(*this).SetY(y);
193 void Actor::SetZ(float z)
195 GetImplementation(*this).SetZ(z);
198 void Actor::TranslateBy(const Vector3& distance)
200 GetImplementation(*this).TranslateBy(distance);
203 void Actor::SetOrientation(const Radian& angle, const Vector3& axis)
205 GetImplementation(*this).SetOrientation(angle, axis);
208 void Actor::SetOrientation(const Quaternion& orientation)
210 GetImplementation(*this).SetOrientation(orientation);
213 void Actor::RotateBy(const Radian& angle, const Vector3& axis)
215 GetImplementation(*this).RotateBy(angle, axis);
218 void Actor::RotateBy(const Quaternion& relativeRotation)
220 GetImplementation(*this).RotateBy(relativeRotation);
223 void Actor::SetScale(float scale)
225 GetImplementation(*this).SetScale(scale);
228 void Actor::SetScale(float scaleX, float scaleY, float scaleZ)
230 GetImplementation(*this).SetScale(scaleX, scaleY, scaleZ);
233 void Actor::SetScale(const Vector3& scale)
235 GetImplementation(*this).SetScale(scale);
238 void Actor::ScaleBy(const Vector3& relativeScale)
240 GetImplementation(*this).ScaleBy(relativeScale);
243 void Actor::SetSizeModeFactor(const Vector3& factor)
245 GetImplementation(*this).SetSizeModeFactor(factor);
248 Vector3 Actor::GetSizeModeFactor() const
250 return GetImplementation(*this).GetSizeModeFactor();
253 void Actor::SetColorMode( ColorMode colorMode )
255 GetImplementation(*this).SetColorMode(colorMode);
258 ColorMode Actor::GetColorMode() const
260 return GetImplementation(*this).GetColorMode();
263 void Actor::SetDrawMode( DrawMode::Type drawMode )
265 GetImplementation(*this).SetDrawMode( drawMode );
268 DrawMode::Type Actor::GetDrawMode() const
270 return GetImplementation(*this).GetDrawMode();
273 bool Actor::ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const
275 return GetImplementation(*this).ScreenToLocal(localX, localY, screenX, screenY);
278 void Actor::SetKeyboardFocusable( bool focusable )
280 GetImplementation(*this).SetKeyboardFocusable(focusable);
283 bool Actor::IsKeyboardFocusable() const
285 return GetImplementation(*this).IsKeyboardFocusable();
290 GetImplementation( *this ).Raise();
295 GetImplementation( *this ).Lower();
298 void Actor::RaiseToTop()
300 GetImplementation( *this ).RaiseToTop();
303 void Actor::LowerToBottom()
305 GetImplementation( *this ).LowerToBottom();
308 void Actor::RaiseAbove( Actor target )
310 GetImplementation( *this ).RaiseAbove( GetImplementation( target ) );
313 void Actor::LowerBelow( Actor target )
315 GetImplementation( *this ).LowerBelow( GetImplementation( target ) );
318 void Actor::SetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
320 GetImplementation(*this).SetResizePolicy( policy, dimension );
323 ResizePolicy::Type Actor::GetResizePolicy( Dimension::Type dimension ) const
325 return GetImplementation(*this).GetResizePolicy( dimension );
328 void Actor::SetSizeScalePolicy( SizeScalePolicy::Type policy )
330 GetImplementation(*this).SetSizeScalePolicy( policy );
333 SizeScalePolicy::Type Actor::GetSizeScalePolicy() const
335 return GetImplementation(*this).GetSizeScalePolicy();
338 float Actor::GetHeightForWidth( float width )
340 return GetImplementation(*this).GetHeightForWidth( width );
343 float Actor::GetWidthForHeight( float height )
345 return GetImplementation(*this).GetWidthForHeight( height );
348 float Actor::GetRelayoutSize( Dimension::Type dimension ) const
350 return GetImplementation(*this).GetRelayoutSize( dimension );
353 void Actor::SetPadding( const Padding& padding )
355 Internal::Actor& impl = GetImplementation(*this);
357 Vector2 widthPadding( padding.left, padding.right );
358 impl.SetPadding( widthPadding, Dimension::WIDTH );
360 Vector2 heightPadding( padding.bottom, padding.top );
361 impl.SetPadding( heightPadding, Dimension::HEIGHT );
364 void Actor::GetPadding( Padding& paddingOut ) const
366 const Internal::Actor& impl = GetImplementation(*this);
368 Vector2 widthPadding = impl.GetPadding( Dimension::WIDTH );
369 Vector2 heightPadding = impl.GetPadding( Dimension::HEIGHT );
371 paddingOut.left = widthPadding.x;
372 paddingOut.right = widthPadding.y;
373 paddingOut.bottom = heightPadding.x;
374 paddingOut.top = heightPadding.y;
377 int32_t Actor::GetHierarchyDepth()
379 return GetImplementation(*this).GetHierarchyDepth();
382 Actor::TouchSignalType& Actor::TouchedSignal()
384 DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: TouchedSignal() is deprecated and will be removed from next release. Use TouchSignal() instead.\n" );
386 return GetImplementation(*this).TouchedSignal();
389 Actor::TouchDataSignalType& Actor::TouchSignal()
391 return GetImplementation( *this ).TouchSignal();
394 Actor::HoverSignalType& Actor::HoveredSignal()
396 return GetImplementation(*this).HoveredSignal();
399 Actor::WheelEventSignalType& Actor::WheelEventSignal()
401 return GetImplementation(*this).WheelEventSignal();
404 Actor::OnStageSignalType& Actor::OnStageSignal()
406 return GetImplementation(*this).OnStageSignal();
409 Actor::OffStageSignalType& Actor::OffStageSignal()
411 return GetImplementation(*this).OffStageSignal();
414 uint32_t Actor::AddRenderer( Renderer& renderer )
416 return GetImplementation(*this).AddRenderer( GetImplementation( renderer ) );
419 uint32_t Actor::GetRendererCount() const
421 return GetImplementation(*this).GetRendererCount();
424 Renderer Actor::GetRendererAt( uint32_t index )
426 Internal::RendererPtr renderer = GetImplementation(*this).GetRendererAt( index );
427 return Renderer( renderer.Get() );
430 void Actor::RemoveRenderer( Renderer& renderer )
432 GetImplementation(*this).RemoveRenderer( GetImplementation( renderer ) );
435 void Actor::RemoveRenderer( uint32_t index )
437 GetImplementation(*this).RemoveRenderer( index );
440 Actor::OnRelayoutSignalType& Actor::OnRelayoutSignal()
442 return GetImplementation(*this).OnRelayoutSignal();
445 Actor::LayoutDirectionChangedSignalType& Actor::LayoutDirectionChangedSignal()
447 return GetImplementation( *this ).LayoutDirectionChangedSignal();
450 Actor::Actor(Internal::Actor* internal)