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