Merge branch 'tizen' of platform/core/uifw/dali-core into devel/new_mesh
[platform/core/uifw/dali-core.git] / dali / public-api / actors / actor.cpp
1 /*
2  * Copyright (c) 2014 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/degree.h>
26 #include <dali/public-api/math/radian.h>
27 #include <dali/public-api/math/vector2.h>
28
29 #include <dali/internal/event/actors/actor-impl.h>
30 #include <dali/internal/event/actors/layer-impl.h>
31 #include <dali/internal/event/actors/renderer-impl.h>
32 #include <dali/internal/event/actor-attachments/actor-attachment-impl.h>
33 #include <dali/internal/event/animation/constraint-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::Insert(unsigned int index, Actor actor)
110 {
111   GetImplementation(*this).Insert(index, GetImplementation(actor));
112 }
113
114 void Actor::Remove(Actor actor)
115 {
116   GetImplementation(*this).Remove(GetImplementation(actor));
117 }
118
119 void Actor::Unparent()
120 {
121   GetImplementation(*this).Unparent();
122 }
123
124 unsigned int Actor::GetChildCount() const
125 {
126   return GetImplementation(*this).GetChildCount();
127 }
128
129 Actor Actor::GetChildAt(unsigned int index) const
130 {
131   return GetImplementation(*this).GetChildAt(index);
132 }
133
134 Actor Actor::FindChildByName(const std::string& actorName)
135 {
136   Internal::ActorPtr child = GetImplementation(*this).FindChildByName(actorName);
137   return Actor(child.Get());
138 }
139
140 Actor Actor::FindChildById(const unsigned int id)
141 {
142   Internal::ActorPtr child = GetImplementation(*this).FindChildById(id);
143   return Actor(child.Get());
144 }
145
146 Actor Actor::GetParent() const
147 {
148   Internal::Actor* parent = GetImplementation(*this).GetParent();
149
150   return Actor(parent);
151 }
152
153 void Actor::SetParentOrigin(const Vector3& origin)
154 {
155   GetImplementation(*this).SetParentOrigin(origin);
156 }
157
158 Vector3 Actor::GetCurrentParentOrigin() const
159 {
160   return GetImplementation(*this).GetCurrentParentOrigin();
161 }
162
163 void Actor::SetAnchorPoint(const Vector3& anchorPoint)
164 {
165   GetImplementation(*this).SetAnchorPoint(anchorPoint);
166 }
167
168 Vector3 Actor::GetCurrentAnchorPoint() const
169 {
170   return GetImplementation(*this).GetCurrentAnchorPoint();
171 }
172
173 void Actor::SetSize(float width, float height)
174 {
175   GetImplementation(*this).SetSize(width, height);
176 }
177
178 void Actor::SetSize(float width, float height, float depth)
179 {
180   GetImplementation(*this).SetSize(width, height, depth);
181 }
182
183 void Actor::SetSize(const Vector2& size)
184 {
185   GetImplementation(*this).SetSize(size);
186 }
187
188 void Actor::SetSize(const Vector3& size)
189 {
190   GetImplementation(*this).SetSize(size);
191 }
192
193 Vector3 Actor::GetTargetSize() const
194 {
195   return GetImplementation(*this).GetTargetSize();
196 }
197
198 Vector3 Actor::GetCurrentSize() const
199 {
200   return GetImplementation(*this).GetCurrentSize();
201 }
202
203 Vector3 Actor::GetNaturalSize() const
204 {
205   return GetImplementation(*this).GetNaturalSize();
206 }
207
208 void Actor::SetPosition(float x, float y)
209 {
210   GetImplementation(*this).SetPosition(x, y);
211 }
212
213 void Actor::SetPosition(float x, float y, float z)
214 {
215   GetImplementation(*this).SetPosition(x, y, z);
216 }
217
218 void Actor::SetPosition(const Vector3& position)
219 {
220   GetImplementation(*this).SetPosition(position);
221 }
222
223 void Actor::SetX(float x)
224 {
225   GetImplementation(*this).SetX(x);
226 }
227
228 void Actor::SetY(float y)
229 {
230   GetImplementation(*this).SetY(y);
231 }
232
233 void Actor::SetZ(float z)
234 {
235   GetImplementation(*this).SetZ(z);
236 }
237
238 void Actor::TranslateBy(const Vector3& distance)
239 {
240   GetImplementation(*this).TranslateBy(distance);
241 }
242
243 Vector3 Actor::GetCurrentPosition() const
244 {
245   return GetImplementation(*this).GetCurrentPosition();
246 }
247
248 Vector3 Actor::GetCurrentWorldPosition() const
249 {
250   return GetImplementation(*this).GetCurrentWorldPosition();
251 }
252
253 void Actor::SetPositionInheritanceMode( PositionInheritanceMode mode )
254 {
255   GetImplementation(*this).SetPositionInheritanceMode( mode );
256 }
257
258 PositionInheritanceMode Actor::GetPositionInheritanceMode() const
259 {
260   return GetImplementation(*this).GetPositionInheritanceMode();
261 }
262
263 void Actor::SetOrientation(const Degree& angle, const Vector3& axis)
264 {
265   GetImplementation(*this).SetOrientation(Radian(angle), axis);
266 }
267
268 void Actor::SetOrientation(const Radian& angle, const Vector3& axis)
269 {
270   GetImplementation(*this).SetOrientation(angle, axis);
271 }
272
273 void Actor::SetOrientation(const Quaternion& orientation)
274 {
275   GetImplementation(*this).SetOrientation(orientation);
276 }
277
278 void Actor::RotateBy(const Degree& angle, const Vector3& axis)
279 {
280   GetImplementation(*this).RotateBy(Radian(angle), axis);
281 }
282
283 void Actor::RotateBy(const Radian& angle, const Vector3& axis)
284 {
285   GetImplementation(*this).RotateBy(angle, axis);
286 }
287
288 void Actor::RotateBy(const Quaternion& relativeRotation)
289 {
290   GetImplementation(*this).RotateBy(relativeRotation);
291 }
292
293 Quaternion Actor::GetCurrentOrientation() const
294 {
295   return GetImplementation(*this).GetCurrentOrientation();
296 }
297
298 void Actor::SetInheritOrientation(bool inherit)
299 {
300   GetImplementation(*this).SetInheritOrientation(inherit);
301 }
302
303 bool Actor::IsOrientationInherited() const
304 {
305   return GetImplementation(*this).IsOrientationInherited();
306 }
307
308 Quaternion Actor::GetCurrentWorldOrientation() const
309 {
310   return GetImplementation(*this).GetCurrentWorldOrientation();
311 }
312
313 void Actor::SetScale(float scale)
314 {
315   GetImplementation(*this).SetScale(scale);
316 }
317
318 void Actor::SetScale(float scaleX, float scaleY, float scaleZ)
319 {
320   GetImplementation(*this).SetScale(scaleX, scaleY, scaleZ);
321 }
322
323 void Actor::SetScale(const Vector3& scale)
324 {
325   GetImplementation(*this).SetScale(scale);
326 }
327
328 void Actor::ScaleBy(const Vector3& relativeScale)
329 {
330   GetImplementation(*this).ScaleBy(relativeScale);
331 }
332
333 Vector3 Actor::GetCurrentScale() const
334 {
335   return GetImplementation(*this).GetCurrentScale();
336 }
337
338 Vector3 Actor::GetCurrentWorldScale() const
339 {
340   return GetImplementation(*this).GetCurrentWorldScale();
341 }
342
343 void Actor::SetInheritScale( bool inherit )
344 {
345   GetImplementation(*this).SetInheritScale( inherit );
346 }
347
348 bool Actor::IsScaleInherited() const
349 {
350   return GetImplementation(*this).IsScaleInherited();
351 }
352
353 void Actor::SetSizeMode(SizeMode mode)
354 {
355   GetImplementation(*this).SetSizeMode(mode);
356 }
357
358 SizeMode Actor::GetSizeMode() const
359 {
360   return GetImplementation(*this).GetSizeMode();
361 }
362
363 void Actor::SetSizeModeFactor(const Vector3& factor)
364 {
365   GetImplementation(*this).SetSizeModeFactor(factor);
366 }
367
368 Vector3 Actor::GetSizeModeFactor() const
369 {
370   return GetImplementation(*this).GetSizeModeFactor();
371 }
372
373 Matrix Actor::GetCurrentWorldMatrix() const
374 {
375   return GetImplementation(*this).GetCurrentWorldMatrix();
376 }
377
378 void Actor::SetVisible(bool visible)
379 {
380   GetImplementation(*this).SetVisible(visible);
381 }
382
383 bool Actor::IsVisible() const
384 {
385   return GetImplementation(*this).IsVisible();
386 }
387
388 void Actor::SetOpacity(float opacity)
389 {
390   GetImplementation(*this).SetOpacity(opacity);
391 }
392
393 float Actor::GetCurrentOpacity() const
394 {
395   return GetImplementation(*this).GetCurrentOpacity();
396 }
397
398 void Actor::SetColor(const Vector4& color)
399 {
400   GetImplementation(*this).SetColor(color);
401 }
402
403 Vector4 Actor::GetCurrentColor() const
404 {
405   return GetImplementation(*this).GetCurrentColor();
406 }
407
408 void Actor::SetColorMode( ColorMode colorMode )
409 {
410   GetImplementation(*this).SetColorMode(colorMode);
411 }
412
413 ColorMode Actor::GetColorMode() const
414 {
415   return GetImplementation(*this).GetColorMode();
416 }
417
418 Vector4 Actor::GetCurrentWorldColor() const
419 {
420   return GetImplementation(*this).GetCurrentWorldColor();
421 }
422
423 void Actor::SetDrawMode( DrawMode::Type drawMode )
424 {
425   GetImplementation(*this).SetDrawMode( drawMode );
426 }
427
428 DrawMode::Type Actor::GetDrawMode() const
429 {
430   return GetImplementation(*this).GetDrawMode();
431 }
432
433 void Actor::SetSensitive(bool sensitive)
434 {
435   GetImplementation(*this).SetSensitive(sensitive);
436 }
437
438 bool Actor::IsSensitive() const
439 {
440   return GetImplementation(*this).IsSensitive();
441 }
442
443 bool Actor::ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const
444 {
445   return GetImplementation(*this).ScreenToLocal(localX, localY, screenX, screenY);
446 }
447
448 void Actor::SetLeaveRequired(bool required)
449 {
450   GetImplementation(*this).SetLeaveRequired(required);
451 }
452
453 bool Actor::GetLeaveRequired() const
454 {
455   return GetImplementation(*this).GetLeaveRequired();
456 }
457
458 void Actor::SetKeyboardFocusable( bool focusable )
459 {
460   GetImplementation(*this).SetKeyboardFocusable(focusable);
461 }
462
463 bool Actor::IsKeyboardFocusable() const
464 {
465   return GetImplementation(*this).IsKeyboardFocusable();
466 }
467
468 void Actor::SetRelayoutEnabled( bool enabled )
469 {
470   GetImplementation(*this).SetRelayoutEnabled( enabled );
471 }
472
473 bool Actor::IsRelayoutEnabled() const
474 {
475   return GetImplementation(*this).IsRelayoutEnabled();
476 }
477
478 void Actor::SetResizePolicy( ResizePolicy policy, Dimension dimension )
479 {
480   GetImplementation(*this).SetResizePolicy( policy, dimension );
481 }
482
483 ResizePolicy Actor::GetResizePolicy( Dimension dimension ) const
484 {
485   return GetImplementation(*this).GetResizePolicy( dimension );
486 }
487
488 void Actor::SetSizeScalePolicy( SizeScalePolicy policy )
489 {
490   GetImplementation(*this).SetSizeScalePolicy( policy );
491 }
492
493 SizeScalePolicy Actor::GetSizeScalePolicy() const
494 {
495   return GetImplementation(*this).GetSizeScalePolicy();
496 }
497
498 void Actor::SetDimensionDependency( Dimension dimension, Dimension dependency )
499 {
500   GetImplementation(*this).SetDimensionDependency( dimension, dependency );
501 }
502
503 Dimension Actor::GetDimensionDependency( Dimension dimension )
504 {
505   return GetImplementation(*this).GetDimensionDependency( dimension );
506 }
507
508 float Actor::GetHeightForWidth( float width )
509 {
510   return GetImplementation(*this).GetHeightForWidth( width );
511 }
512
513 float Actor::GetWidthForHeight( float height )
514 {
515   return GetImplementation(*this).GetWidthForHeight( height );
516 }
517
518 float Actor::GetRelayoutSize( Dimension dimension ) const
519 {
520   return GetImplementation(*this).GetRelayoutSize( dimension );
521 }
522
523 void Actor::RelayoutRequestTree()
524 {
525   GetImplementation(*this).RelayoutRequestTree();
526 }
527
528 void Actor::PropagateRelayoutFlags()
529 {
530   GetImplementation(*this).PropagateRelayoutFlags();
531 }
532
533 void Actor::SetPadding( const Padding& padding )
534 {
535   Internal::Actor& impl = GetImplementation(*this);
536
537   Vector2 widthPadding( padding.left, padding.right );
538   impl.SetPadding( widthPadding, WIDTH );
539
540   Vector2 heightPadding( padding.bottom, padding.top );
541   impl.SetPadding( heightPadding, HEIGHT );
542 }
543
544 void Actor::GetPadding( Padding& paddingOut ) const
545 {
546   const Internal::Actor& impl = GetImplementation(*this);
547
548   Vector2 widthPadding = impl.GetPadding( WIDTH );
549   Vector2 heightPadding = impl.GetPadding( HEIGHT );
550
551   paddingOut.left = widthPadding.x;
552   paddingOut.right = widthPadding.y;
553   paddingOut.bottom = heightPadding.x;
554   paddingOut.top = heightPadding.y;
555 }
556
557 void Actor::SetPreferredSize( const Vector2& size )
558 {
559   GetImplementation(*this).SetPreferredSize( size );
560 }
561
562 Vector2 Actor::GetPreferredSize() const
563 {
564   return GetImplementation(*this).GetPreferredSize();
565 }
566
567 void Actor::SetMinimumSize( const Vector2& size )
568 {
569   Internal::Actor& impl = GetImplementation(*this);
570
571   impl.SetMinimumSize( size.x, WIDTH );
572   impl.SetMinimumSize( size.y, HEIGHT );
573 }
574
575 Vector2 Actor::GetMinimumSize()
576 {
577   Internal::Actor& impl = GetImplementation(*this);
578
579   return Vector2( impl.GetMinimumSize( WIDTH ), impl.GetMinimumSize( HEIGHT ) );
580 }
581
582 void Actor::SetMaximumSize( const Vector2& size )
583 {
584   Internal::Actor& impl = GetImplementation(*this);
585
586   impl.SetMaximumSize( size.x, WIDTH );
587   impl.SetMaximumSize( size.y, HEIGHT );
588 }
589
590 Vector2 Actor::GetMaximumSize()
591 {
592   Internal::Actor& impl = GetImplementation(*this);
593
594   return Vector2( impl.GetMaximumSize( WIDTH ), impl.GetMaximumSize( HEIGHT ) );
595 }
596
597 Actor::TouchSignalType& Actor::TouchedSignal()
598 {
599   return GetImplementation(*this).TouchedSignal();
600 }
601
602 Actor::HoverSignalType& Actor::HoveredSignal()
603 {
604   return GetImplementation(*this).HoveredSignal();
605 }
606
607 Actor::MouseWheelEventSignalType& Actor::MouseWheelEventSignal()
608 {
609   return GetImplementation(*this).MouseWheelEventSignal();
610 }
611
612 Actor::OnStageSignalType& Actor::OnStageSignal()
613 {
614   return GetImplementation(*this).OnStageSignal();
615 }
616
617 Actor::OffStageSignalType& Actor::OffStageSignal()
618 {
619   return GetImplementation(*this).OffStageSignal();
620 }
621
622 unsigned int Actor::AddRenderer( Renderer& renderer )
623 {
624   return GetImplementation(*this).AddRenderer( GetImplementation( renderer ) );
625 }
626
627 unsigned int Actor::GetRendererCount() const
628 {
629   return GetImplementation(*this).GetRendererCount();
630 }
631
632 Renderer Actor::GetRendererAt( unsigned int index )
633 {
634   return Renderer( &GetImplementation(*this).GetRendererAt( index ) );
635 }
636
637 void Actor::RemoveRenderer( Renderer& renderer )
638 {
639   GetImplementation(*this).RemoveRenderer( GetImplementation( renderer ) );
640 }
641
642 void Actor::RemoveRenderer( unsigned int index )
643 {
644   GetImplementation(*this).RemoveRenderer( index );
645 }
646
647 Actor::OnRelayoutSignalType& Actor::OnRelayoutSignal()
648 {
649   return GetImplementation(*this).OnRelayoutSignal();
650 }
651
652 Actor::Actor(Internal::Actor* internal)
653 : Handle(internal)
654 {
655 }
656
657 void UnparentAndReset( Actor& actor )
658 {
659   if( actor )
660   {
661     actor.Unparent();
662     actor.Reset();
663   }
664 }
665
666 } // namespace Dali