[dali_1.0.36] Merge branch 'tizen'
[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/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::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   if( IsRelayoutEnabled() )
176   {
177     GetImplementation(*this).SetPreferredSize( Vector2( width, height ) );
178   }
179   else
180   {
181     GetImplementation(*this).SetSize(width, height);
182   }
183 }
184
185 void Actor::SetSize(float width, float height, float depth)
186 {
187   if( IsRelayoutEnabled() )
188   {
189     GetImplementation(*this).SetPreferredSize( Vector2( width, height ) );
190   }
191   else
192   {
193     GetImplementation(*this).SetSize(width, height, depth);
194   }
195 }
196
197 void Actor::SetSize(const Vector2& size)
198 {
199   if( IsRelayoutEnabled() )
200   {
201     GetImplementation(*this).SetPreferredSize( size );
202   }
203   else
204   {
205     GetImplementation(*this).SetSize( size );
206   }
207 }
208
209 void Actor::SetSize(const Vector3& size)
210 {
211   if( IsRelayoutEnabled() )
212   {
213     GetImplementation(*this).SetPreferredSize( size.GetVectorXY() );
214   }
215   else
216   {
217     GetImplementation(*this).SetSize( size );
218   }
219 }
220
221 Vector3 Actor::GetTargetSize() const
222 {
223   return GetImplementation(*this).GetTargetSize();
224 }
225
226 Vector3 Actor::GetCurrentSize() const
227 {
228   return GetImplementation(*this).GetCurrentSize();
229 }
230
231 Vector3 Actor::GetNaturalSize() const
232 {
233   return GetImplementation(*this).GetNaturalSize();
234 }
235
236 void Actor::SetPosition(float x, float y)
237 {
238   GetImplementation(*this).SetPosition(x, y);
239 }
240
241 void Actor::SetPosition(float x, float y, float z)
242 {
243   GetImplementation(*this).SetPosition(x, y, z);
244 }
245
246 void Actor::SetPosition(const Vector3& position)
247 {
248   GetImplementation(*this).SetPosition(position);
249 }
250
251 void Actor::SetX(float x)
252 {
253   GetImplementation(*this).SetX(x);
254 }
255
256 void Actor::SetY(float y)
257 {
258   GetImplementation(*this).SetY(y);
259 }
260
261 void Actor::SetZ(float z)
262 {
263   GetImplementation(*this).SetZ(z);
264 }
265
266 void Actor::TranslateBy(const Vector3& distance)
267 {
268   GetImplementation(*this).TranslateBy(distance);
269 }
270
271 Vector3 Actor::GetCurrentPosition() const
272 {
273   return GetImplementation(*this).GetCurrentPosition();
274 }
275
276 Vector3 Actor::GetCurrentWorldPosition() const
277 {
278   return GetImplementation(*this).GetCurrentWorldPosition();
279 }
280
281 void Actor::SetPositionInheritanceMode( PositionInheritanceMode mode )
282 {
283   GetImplementation(*this).SetPositionInheritanceMode( mode );
284 }
285
286 PositionInheritanceMode Actor::GetPositionInheritanceMode() const
287 {
288   return GetImplementation(*this).GetPositionInheritanceMode();
289 }
290
291 void Actor::SetOrientation(const Degree& angle, const Vector3& axis)
292 {
293   GetImplementation(*this).SetOrientation(Radian(angle), axis);
294 }
295
296 void Actor::SetOrientation(const Radian& angle, const Vector3& axis)
297 {
298   GetImplementation(*this).SetOrientation(angle, axis);
299 }
300
301 void Actor::SetOrientation(const Quaternion& orientation)
302 {
303   GetImplementation(*this).SetOrientation(orientation);
304 }
305
306 void Actor::RotateBy(const Degree& angle, const Vector3& axis)
307 {
308   GetImplementation(*this).RotateBy(Radian(angle), axis);
309 }
310
311 void Actor::RotateBy(const Radian& angle, const Vector3& axis)
312 {
313   GetImplementation(*this).RotateBy(angle, axis);
314 }
315
316 void Actor::RotateBy(const Quaternion& relativeRotation)
317 {
318   GetImplementation(*this).RotateBy(relativeRotation);
319 }
320
321 Quaternion Actor::GetCurrentOrientation() const
322 {
323   return GetImplementation(*this).GetCurrentOrientation();
324 }
325
326 void Actor::SetInheritOrientation(bool inherit)
327 {
328   GetImplementation(*this).SetInheritOrientation(inherit);
329 }
330
331 bool Actor::IsOrientationInherited() const
332 {
333   return GetImplementation(*this).IsOrientationInherited();
334 }
335
336 Quaternion Actor::GetCurrentWorldOrientation() const
337 {
338   return GetImplementation(*this).GetCurrentWorldOrientation();
339 }
340
341 void Actor::SetScale(float scale)
342 {
343   GetImplementation(*this).SetScale(scale);
344 }
345
346 void Actor::SetScale(float scaleX, float scaleY, float scaleZ)
347 {
348   GetImplementation(*this).SetScale(scaleX, scaleY, scaleZ);
349 }
350
351 void Actor::SetScale(const Vector3& scale)
352 {
353   GetImplementation(*this).SetScale(scale);
354 }
355
356 void Actor::ScaleBy(const Vector3& relativeScale)
357 {
358   GetImplementation(*this).ScaleBy(relativeScale);
359 }
360
361 Vector3 Actor::GetCurrentScale() const
362 {
363   return GetImplementation(*this).GetCurrentScale();
364 }
365
366 Vector3 Actor::GetCurrentWorldScale() const
367 {
368   return GetImplementation(*this).GetCurrentWorldScale();
369 }
370
371 void Actor::SetInheritScale( bool inherit )
372 {
373   GetImplementation(*this).SetInheritScale( inherit );
374 }
375
376 bool Actor::IsScaleInherited() const
377 {
378   return GetImplementation(*this).IsScaleInherited();
379 }
380
381 void Actor::SetSizeModeFactor(const Vector3& factor)
382 {
383   GetImplementation(*this).SetSizeModeFactor(factor);
384 }
385
386 Vector3 Actor::GetSizeModeFactor() const
387 {
388   return GetImplementation(*this).GetSizeModeFactor();
389 }
390
391 Matrix Actor::GetCurrentWorldMatrix() const
392 {
393   return GetImplementation(*this).GetCurrentWorldMatrix();
394 }
395
396 void Actor::SetVisible(bool visible)
397 {
398   GetImplementation(*this).SetVisible(visible);
399 }
400
401 bool Actor::IsVisible() const
402 {
403   return GetImplementation(*this).IsVisible();
404 }
405
406 void Actor::SetOpacity(float opacity)
407 {
408   GetImplementation(*this).SetOpacity(opacity);
409 }
410
411 float Actor::GetCurrentOpacity() const
412 {
413   return GetImplementation(*this).GetCurrentOpacity();
414 }
415
416 void Actor::SetColor(const Vector4& color)
417 {
418   GetImplementation(*this).SetColor(color);
419 }
420
421 Vector4 Actor::GetCurrentColor() const
422 {
423   return GetImplementation(*this).GetCurrentColor();
424 }
425
426 void Actor::SetColorMode( ColorMode colorMode )
427 {
428   GetImplementation(*this).SetColorMode(colorMode);
429 }
430
431 ColorMode Actor::GetColorMode() const
432 {
433   return GetImplementation(*this).GetColorMode();
434 }
435
436 Vector4 Actor::GetCurrentWorldColor() const
437 {
438   return GetImplementation(*this).GetCurrentWorldColor();
439 }
440
441 void Actor::SetDrawMode( DrawMode::Type drawMode )
442 {
443   GetImplementation(*this).SetDrawMode( drawMode );
444 }
445
446 DrawMode::Type Actor::GetDrawMode() const
447 {
448   return GetImplementation(*this).GetDrawMode();
449 }
450
451 void Actor::SetSensitive(bool sensitive)
452 {
453   GetImplementation(*this).SetSensitive(sensitive);
454 }
455
456 bool Actor::IsSensitive() const
457 {
458   return GetImplementation(*this).IsSensitive();
459 }
460
461 bool Actor::ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const
462 {
463   return GetImplementation(*this).ScreenToLocal(localX, localY, screenX, screenY);
464 }
465
466 void Actor::SetLeaveRequired(bool required)
467 {
468   GetImplementation(*this).SetLeaveRequired(required);
469 }
470
471 bool Actor::GetLeaveRequired() const
472 {
473   return GetImplementation(*this).GetLeaveRequired();
474 }
475
476 void Actor::SetKeyboardFocusable( bool focusable )
477 {
478   GetImplementation(*this).SetKeyboardFocusable(focusable);
479 }
480
481 bool Actor::IsKeyboardFocusable() const
482 {
483   return GetImplementation(*this).IsKeyboardFocusable();
484 }
485
486 void Actor::SetRelayoutEnabled( bool enabled )
487 {
488   GetImplementation(*this).SetRelayoutEnabled( enabled );
489 }
490
491 bool Actor::IsRelayoutEnabled() const
492 {
493   return GetImplementation(*this).IsRelayoutEnabled();
494 }
495
496 void Actor::SetResizePolicy( ResizePolicy policy, Dimension dimension )
497 {
498   GetImplementation(*this).SetResizePolicy( policy, dimension );
499 }
500
501 ResizePolicy Actor::GetResizePolicy( Dimension dimension ) const
502 {
503   return GetImplementation(*this).GetResizePolicy( dimension );
504 }
505
506 void Actor::SetSizeScalePolicy( SizeScalePolicy policy )
507 {
508   GetImplementation(*this).SetSizeScalePolicy( policy );
509 }
510
511 SizeScalePolicy Actor::GetSizeScalePolicy() const
512 {
513   return GetImplementation(*this).GetSizeScalePolicy();
514 }
515
516 float Actor::GetHeightForWidth( float width )
517 {
518   return GetImplementation(*this).GetHeightForWidth( width );
519 }
520
521 float Actor::GetWidthForHeight( float height )
522 {
523   return GetImplementation(*this).GetWidthForHeight( height );
524 }
525
526 float Actor::GetRelayoutSize( Dimension dimension ) const
527 {
528   return GetImplementation(*this).GetRelayoutSize( dimension );
529 }
530
531 void Actor::RelayoutRequestTree()
532 {
533   GetImplementation(*this).RelayoutRequestTree();
534 }
535
536 void Actor::PropagateRelayoutFlags()
537 {
538   GetImplementation(*this).PropagateRelayoutFlags();
539 }
540
541 void Actor::SetPadding( const Padding& padding )
542 {
543   Internal::Actor& impl = GetImplementation(*this);
544
545   Vector2 widthPadding( padding.left, padding.right );
546   impl.SetPadding( widthPadding, WIDTH );
547
548   Vector2 heightPadding( padding.bottom, padding.top );
549   impl.SetPadding( heightPadding, HEIGHT );
550 }
551
552 void Actor::GetPadding( Padding& paddingOut ) const
553 {
554   const Internal::Actor& impl = GetImplementation(*this);
555
556   Vector2 widthPadding = impl.GetPadding( WIDTH );
557   Vector2 heightPadding = impl.GetPadding( HEIGHT );
558
559   paddingOut.left = widthPadding.x;
560   paddingOut.right = widthPadding.y;
561   paddingOut.bottom = heightPadding.x;
562   paddingOut.top = heightPadding.y;
563 }
564
565 void Actor::SetMinimumSize( const Vector2& size )
566 {
567   Internal::Actor& impl = GetImplementation(*this);
568
569   impl.SetMinimumSize( size.x, WIDTH );
570   impl.SetMinimumSize( size.y, HEIGHT );
571 }
572
573 Vector2 Actor::GetMinimumSize()
574 {
575   Internal::Actor& impl = GetImplementation(*this);
576
577   return Vector2( impl.GetMinimumSize( WIDTH ), impl.GetMinimumSize( HEIGHT ) );
578 }
579
580 void Actor::SetMaximumSize( const Vector2& size )
581 {
582   Internal::Actor& impl = GetImplementation(*this);
583
584   impl.SetMaximumSize( size.x, WIDTH );
585   impl.SetMaximumSize( size.y, HEIGHT );
586 }
587
588 Vector2 Actor::GetMaximumSize()
589 {
590   Internal::Actor& impl = GetImplementation(*this);
591
592   return Vector2( impl.GetMaximumSize( WIDTH ), impl.GetMaximumSize( HEIGHT ) );
593 }
594
595 Actor::TouchSignalType& Actor::TouchedSignal()
596 {
597   return GetImplementation(*this).TouchedSignal();
598 }
599
600 Actor::HoverSignalType& Actor::HoveredSignal()
601 {
602   return GetImplementation(*this).HoveredSignal();
603 }
604
605 Actor::MouseWheelEventSignalType& Actor::MouseWheelEventSignal()
606 {
607   return GetImplementation(*this).MouseWheelEventSignal();
608 }
609
610 Actor::OnStageSignalType& Actor::OnStageSignal()
611 {
612   return GetImplementation(*this).OnStageSignal();
613 }
614
615 Actor::OffStageSignalType& Actor::OffStageSignal()
616 {
617   return GetImplementation(*this).OffStageSignal();
618 }
619
620 Actor::OnRelayoutSignalType& Actor::OnRelayoutSignal()
621 {
622   return GetImplementation(*this).OnRelayoutSignal();
623 }
624
625 Actor::Actor(Internal::Actor* internal)
626 : Handle(internal)
627 {
628 }
629
630 void UnparentAndReset( Actor& actor )
631 {
632   if( actor )
633   {
634     actor.Unparent();
635     actor.Reset();
636   }
637 }
638
639 } // namespace Dali