Allow multiple renderers per Actor and sharing renderers between actors
[platform/core/uifw/dali-core.git] / dali / public-api / actors / actor.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/public-api/actors/actor.h>
20
21 // INTERNAL INCLUDES
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>
27
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/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>
34
35 namespace Dali
36 {
37
38 Actor::Actor()
39 {
40 }
41
42 Actor Actor::New()
43 {
44   Internal::ActorPtr internal = Internal::Actor::New();
45
46   return Actor(internal.Get());
47 }
48
49 Actor Actor::DownCast( BaseHandle handle )
50 {
51   return Actor( dynamic_cast<Dali::Internal::Actor*>(handle.GetObjectPtr()) );
52 }
53
54 Actor::~Actor()
55 {
56 }
57
58 Actor::Actor(const Actor& copy)
59 : Handle(copy)
60 {
61 }
62
63 Actor& Actor::operator=(const Actor& rhs)
64 {
65   BaseHandle::operator=(rhs);
66   return *this;
67 }
68
69 const std::string& Actor::GetName() const
70 {
71   return GetImplementation(*this).GetName();
72 }
73
74 void Actor::SetName(const std::string& name)
75 {
76   GetImplementation(*this).SetName(name);
77 }
78
79 unsigned int Actor::GetId() const
80 {
81   return GetImplementation(*this).GetId();
82 }
83
84 bool Actor::IsRoot() const
85 {
86   return GetImplementation(*this).IsRoot();
87 }
88
89 bool Actor::OnStage() const
90 {
91   return GetImplementation(*this).OnStage();
92 }
93
94 bool Actor::IsLayer() const
95 {
96   return GetImplementation(*this).IsLayer();
97 }
98
99 Layer Actor::GetLayer()
100 {
101   return GetImplementation(*this).GetLayer();
102 }
103
104 void Actor::Add(Actor actor)
105 {
106   GetImplementation(*this).Add(GetImplementation(actor));
107 }
108
109 void Actor::Remove(Actor actor)
110 {
111   GetImplementation(*this).Remove(GetImplementation(actor));
112 }
113
114 void Actor::Unparent()
115 {
116   GetImplementation(*this).Unparent();
117 }
118
119 unsigned int Actor::GetChildCount() const
120 {
121   return GetImplementation(*this).GetChildCount();
122 }
123
124 Actor Actor::GetChildAt(unsigned int index) const
125 {
126   Internal::ActorPtr child = GetImplementation(*this).GetChildAt( index );
127   return Actor( child.Get() );
128 }
129
130 Actor Actor::FindChildByName(const std::string& actorName)
131 {
132   Internal::ActorPtr child = GetImplementation(*this).FindChildByName( actorName );
133   return Actor( child.Get() );
134 }
135
136 Actor Actor::FindChildById(const unsigned int id)
137 {
138   Internal::ActorPtr child = GetImplementation(*this).FindChildById( id );
139   return Actor( child.Get() );
140 }
141
142 Actor Actor::GetParent() const
143 {
144   Internal::Actor* parent = GetImplementation(*this).GetParent();
145
146   return Actor(parent);
147 }
148
149 void Actor::SetParentOrigin(const Vector3& origin)
150 {
151   GetImplementation(*this).SetParentOrigin(origin);
152 }
153
154 Vector3 Actor::GetCurrentParentOrigin() const
155 {
156   return GetImplementation(*this).GetCurrentParentOrigin();
157 }
158
159 void Actor::SetAnchorPoint(const Vector3& anchorPoint)
160 {
161   GetImplementation(*this).SetAnchorPoint(anchorPoint);
162 }
163
164 Vector3 Actor::GetCurrentAnchorPoint() const
165 {
166   return GetImplementation(*this).GetCurrentAnchorPoint();
167 }
168
169 void Actor::SetSize(float width, float height)
170 {
171   GetImplementation(*this).SetSize(width, height);
172 }
173
174 void Actor::SetSize(float width, float height, float depth)
175 {
176   GetImplementation(*this).SetSize(width, height, depth);
177 }
178
179 void Actor::SetSize(const Vector2& size)
180 {
181   GetImplementation(*this).SetSize( size );
182 }
183
184 void Actor::SetSize(const Vector3& size)
185 {
186   GetImplementation(*this).SetSize( size );
187 }
188
189 Vector3 Actor::GetTargetSize() const
190 {
191   return GetImplementation(*this).GetTargetSize();
192 }
193
194 Vector3 Actor::GetCurrentSize() const
195 {
196   return GetImplementation(*this).GetCurrentSize();
197 }
198
199 Vector3 Actor::GetNaturalSize() const
200 {
201   return GetImplementation(*this).GetNaturalSize();
202 }
203
204 void Actor::SetPosition(float x, float y)
205 {
206   GetImplementation(*this).SetPosition(x, y);
207 }
208
209 void Actor::SetPosition(float x, float y, float z)
210 {
211   GetImplementation(*this).SetPosition(x, y, z);
212 }
213
214 void Actor::SetPosition(const Vector3& position)
215 {
216   GetImplementation(*this).SetPosition(position);
217 }
218
219 void Actor::SetX(float x)
220 {
221   GetImplementation(*this).SetX(x);
222 }
223
224 void Actor::SetY(float y)
225 {
226   GetImplementation(*this).SetY(y);
227 }
228
229 void Actor::SetZ(float z)
230 {
231   GetImplementation(*this).SetZ(z);
232 }
233
234 void Actor::TranslateBy(const Vector3& distance)
235 {
236   GetImplementation(*this).TranslateBy(distance);
237 }
238
239 Vector3 Actor::GetCurrentPosition() const
240 {
241   return GetImplementation(*this).GetCurrentPosition();
242 }
243
244 Vector3 Actor::GetCurrentWorldPosition() const
245 {
246   return GetImplementation(*this).GetCurrentWorldPosition();
247 }
248
249 void Actor::SetPositionInheritanceMode( PositionInheritanceMode mode )
250 {
251   GetImplementation(*this).SetPositionInheritanceMode( mode );
252 }
253
254 PositionInheritanceMode Actor::GetPositionInheritanceMode() const
255 {
256   return GetImplementation(*this).GetPositionInheritanceMode();
257 }
258
259 void Actor::SetOrientation(const Radian& angle, const Vector3& axis)
260 {
261   GetImplementation(*this).SetOrientation(angle, axis);
262 }
263
264 void Actor::SetOrientation(const Quaternion& orientation)
265 {
266   GetImplementation(*this).SetOrientation(orientation);
267 }
268
269 void Actor::RotateBy(const Radian& angle, const Vector3& axis)
270 {
271   GetImplementation(*this).RotateBy(angle, axis);
272 }
273
274 void Actor::RotateBy(const Quaternion& relativeRotation)
275 {
276   GetImplementation(*this).RotateBy(relativeRotation);
277 }
278
279 Quaternion Actor::GetCurrentOrientation() const
280 {
281   return GetImplementation(*this).GetCurrentOrientation();
282 }
283
284 void Actor::SetInheritOrientation(bool inherit)
285 {
286   GetImplementation(*this).SetInheritOrientation(inherit);
287 }
288
289 bool Actor::IsOrientationInherited() const
290 {
291   return GetImplementation(*this).IsOrientationInherited();
292 }
293
294 Quaternion Actor::GetCurrentWorldOrientation() const
295 {
296   return GetImplementation(*this).GetCurrentWorldOrientation();
297 }
298
299 void Actor::SetScale(float scale)
300 {
301   GetImplementation(*this).SetScale(scale);
302 }
303
304 void Actor::SetScale(float scaleX, float scaleY, float scaleZ)
305 {
306   GetImplementation(*this).SetScale(scaleX, scaleY, scaleZ);
307 }
308
309 void Actor::SetScale(const Vector3& scale)
310 {
311   GetImplementation(*this).SetScale(scale);
312 }
313
314 void Actor::ScaleBy(const Vector3& relativeScale)
315 {
316   GetImplementation(*this).ScaleBy(relativeScale);
317 }
318
319 Vector3 Actor::GetCurrentScale() const
320 {
321   return GetImplementation(*this).GetCurrentScale();
322 }
323
324 Vector3 Actor::GetCurrentWorldScale() const
325 {
326   return GetImplementation(*this).GetCurrentWorldScale();
327 }
328
329 void Actor::SetInheritScale( bool inherit )
330 {
331   GetImplementation(*this).SetInheritScale( inherit );
332 }
333
334 bool Actor::IsScaleInherited() const
335 {
336   return GetImplementation(*this).IsScaleInherited();
337 }
338
339 void Actor::SetSizeModeFactor(const Vector3& factor)
340 {
341   GetImplementation(*this).SetSizeModeFactor(factor);
342 }
343
344 Vector3 Actor::GetSizeModeFactor() const
345 {
346   return GetImplementation(*this).GetSizeModeFactor();
347 }
348
349 Matrix Actor::GetCurrentWorldMatrix() const
350 {
351   return GetImplementation(*this).GetCurrentWorldMatrix();
352 }
353
354 void Actor::SetVisible(bool visible)
355 {
356   GetImplementation(*this).SetVisible(visible);
357 }
358
359 bool Actor::IsVisible() const
360 {
361   return GetImplementation(*this).IsVisible();
362 }
363
364 void Actor::SetOpacity(float opacity)
365 {
366   GetImplementation(*this).SetOpacity(opacity);
367 }
368
369 float Actor::GetCurrentOpacity() const
370 {
371   return GetImplementation(*this).GetCurrentOpacity();
372 }
373
374 void Actor::SetColor(const Vector4& color)
375 {
376   GetImplementation(*this).SetColor(color);
377 }
378
379 Vector4 Actor::GetCurrentColor() const
380 {
381   return GetImplementation(*this).GetCurrentColor();
382 }
383
384 void Actor::SetColorMode( ColorMode colorMode )
385 {
386   GetImplementation(*this).SetColorMode(colorMode);
387 }
388
389 ColorMode Actor::GetColorMode() const
390 {
391   return GetImplementation(*this).GetColorMode();
392 }
393
394 Vector4 Actor::GetCurrentWorldColor() const
395 {
396   return GetImplementation(*this).GetCurrentWorldColor();
397 }
398
399 void Actor::SetDrawMode( DrawMode::Type drawMode )
400 {
401   GetImplementation(*this).SetDrawMode( drawMode );
402 }
403
404 DrawMode::Type Actor::GetDrawMode() const
405 {
406   return GetImplementation(*this).GetDrawMode();
407 }
408
409 void Actor::SetSensitive(bool sensitive)
410 {
411   GetImplementation(*this).SetSensitive(sensitive);
412 }
413
414 bool Actor::IsSensitive() const
415 {
416   return GetImplementation(*this).IsSensitive();
417 }
418
419 bool Actor::ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const
420 {
421   return GetImplementation(*this).ScreenToLocal(localX, localY, screenX, screenY);
422 }
423
424 void Actor::SetLeaveRequired(bool required)
425 {
426   GetImplementation(*this).SetLeaveRequired(required);
427 }
428
429 bool Actor::GetLeaveRequired() const
430 {
431   return GetImplementation(*this).GetLeaveRequired();
432 }
433
434 void Actor::SetKeyboardFocusable( bool focusable )
435 {
436   GetImplementation(*this).SetKeyboardFocusable(focusable);
437 }
438
439 bool Actor::IsKeyboardFocusable() const
440 {
441   return GetImplementation(*this).IsKeyboardFocusable();
442 }
443
444 void Actor::SetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension )
445 {
446   GetImplementation(*this).SetResizePolicy( policy, dimension );
447 }
448
449 ResizePolicy::Type Actor::GetResizePolicy( Dimension::Type dimension ) const
450 {
451   return GetImplementation(*this).GetResizePolicy( dimension );
452 }
453
454 void Actor::SetSizeScalePolicy( SizeScalePolicy::Type policy )
455 {
456   GetImplementation(*this).SetSizeScalePolicy( policy );
457 }
458
459 SizeScalePolicy::Type Actor::GetSizeScalePolicy() const
460 {
461   return GetImplementation(*this).GetSizeScalePolicy();
462 }
463
464 float Actor::GetHeightForWidth( float width )
465 {
466   return GetImplementation(*this).GetHeightForWidth( width );
467 }
468
469 float Actor::GetWidthForHeight( float height )
470 {
471   return GetImplementation(*this).GetWidthForHeight( height );
472 }
473
474 float Actor::GetRelayoutSize( Dimension::Type dimension ) const
475 {
476   return GetImplementation(*this).GetRelayoutSize( dimension );
477 }
478
479 void Actor::SetPadding( const Padding& padding )
480 {
481   Internal::Actor& impl = GetImplementation(*this);
482
483   Vector2 widthPadding( padding.left, padding.right );
484   impl.SetPadding( widthPadding, Dimension::WIDTH );
485
486   Vector2 heightPadding( padding.bottom, padding.top );
487   impl.SetPadding( heightPadding, Dimension::HEIGHT );
488 }
489
490 void Actor::GetPadding( Padding& paddingOut ) const
491 {
492   const Internal::Actor& impl = GetImplementation(*this);
493
494   Vector2 widthPadding = impl.GetPadding( Dimension::WIDTH );
495   Vector2 heightPadding = impl.GetPadding( Dimension::HEIGHT );
496
497   paddingOut.left = widthPadding.x;
498   paddingOut.right = widthPadding.y;
499   paddingOut.bottom = heightPadding.x;
500   paddingOut.top = heightPadding.y;
501 }
502
503 void Actor::SetMinimumSize( const Vector2& size )
504 {
505   Internal::Actor& impl = GetImplementation(*this);
506
507   impl.SetMinimumSize( size.x, Dimension::WIDTH );
508   impl.SetMinimumSize( size.y, Dimension::HEIGHT );
509 }
510
511 Vector2 Actor::GetMinimumSize()
512 {
513   Internal::Actor& impl = GetImplementation(*this);
514
515   return Vector2( impl.GetMinimumSize( Dimension::WIDTH ), impl.GetMinimumSize( Dimension::HEIGHT ) );
516 }
517
518 void Actor::SetMaximumSize( const Vector2& size )
519 {
520   Internal::Actor& impl = GetImplementation(*this);
521
522   impl.SetMaximumSize( size.x, Dimension::WIDTH );
523   impl.SetMaximumSize( size.y, Dimension::HEIGHT );
524 }
525
526 Vector2 Actor::GetMaximumSize()
527 {
528   Internal::Actor& impl = GetImplementation(*this);
529
530   return Vector2( impl.GetMaximumSize( Dimension::WIDTH ), impl.GetMaximumSize( Dimension::HEIGHT ) );
531 }
532
533 int Actor::GetHierarchyDepth()
534 {
535   return GetImplementation(*this).GetHierarchyDepth();
536 }
537
538 Actor::TouchSignalType& Actor::TouchedSignal()
539 {
540   return GetImplementation(*this).TouchedSignal();
541 }
542
543 Actor::HoverSignalType& Actor::HoveredSignal()
544 {
545   return GetImplementation(*this).HoveredSignal();
546 }
547
548 Actor::WheelEventSignalType& Actor::WheelEventSignal()
549 {
550   return GetImplementation(*this).WheelEventSignal();
551 }
552
553 Actor::OnStageSignalType& Actor::OnStageSignal()
554 {
555   return GetImplementation(*this).OnStageSignal();
556 }
557
558 Actor::OffStageSignalType& Actor::OffStageSignal()
559 {
560   return GetImplementation(*this).OffStageSignal();
561 }
562
563 unsigned int Actor::AddRenderer( Renderer& renderer )
564 {
565   return GetImplementation(*this).AddRenderer( GetImplementation( renderer ) );
566 }
567
568 unsigned int Actor::GetRendererCount() const
569 {
570   return GetImplementation(*this).GetRendererCount();
571 }
572
573 Renderer Actor::GetRendererAt( unsigned int index )
574 {
575   Internal::RendererPtr renderer = GetImplementation(*this).GetRendererAt( index );
576   return Renderer( renderer.Get() );
577 }
578
579 void Actor::RemoveRenderer( Renderer& renderer )
580 {
581   GetImplementation(*this).RemoveRenderer( GetImplementation( renderer ) );
582 }
583
584 void Actor::RemoveRenderer( unsigned int index )
585 {
586   GetImplementation(*this).RemoveRenderer( index );
587 }
588
589 Actor::OnRelayoutSignalType& Actor::OnRelayoutSignal()
590 {
591   return GetImplementation(*this).OnRelayoutSignal();
592 }
593
594 Actor::Actor(Internal::Actor* internal)
595 : Handle(internal)
596 {
597 }
598
599 } // namespace Dali