Merge "DALi Version 1.0.48" into devel/master
[platform/core/uifw/dali-core.git] / dali / devel-api / dynamics / dynamics-world.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/devel-api/dynamics/dynamics-world.h>
20
21 // INTERNAL HEADERS
22 #include <dali/devel-api/dynamics/dynamics-shape.h>
23 #include <dali/internal/event/actors/actor-impl.h>
24
25 #ifdef DALI_DYNAMICS_SUPPORT
26 #include <dali/internal/event/dynamics/dynamics-body-impl.h>
27 #include <dali/internal/event/dynamics/dynamics-joint-impl.h>
28 #include <dali/internal/event/dynamics/dynamics-world-impl.h>
29 #include <dali/internal/event/dynamics/dynamics-world-config-impl.h>
30 #endif
31
32 namespace Dali
33 {
34
35 #ifndef DALI_DYNAMICS_SUPPORT
36 DynamicsWorld::CollisionSignalType STUB_COLLISION_SIGNAL;
37 #endif
38
39 DynamicsWorld::DynamicsWorld()
40 {
41 }
42
43 DynamicsWorld::~DynamicsWorld()
44 {
45 }
46
47 DynamicsWorld::DynamicsWorld(const DynamicsWorld& handle)
48 : BaseHandle(handle)
49 {
50 }
51
52 DynamicsWorld& DynamicsWorld::operator=(const DynamicsWorld& rhs)
53 {
54   BaseHandle::operator=(rhs);
55   return *this;
56 }
57
58 DynamicsWorld DynamicsWorld::GetInstance( DynamicsWorldConfig configuration )
59 {
60 #ifdef DALI_DYNAMICS_SUPPORT
61   Internal::DynamicsWorldConfigPtr configImpl( &( GetImplementation( configuration ) ) );
62
63   return DynamicsWorld( Internal::DynamicsWorld::GetInstance( configImpl ).Get() );
64 #else
65   return DynamicsWorld();
66 #endif
67 }
68
69 DynamicsWorld DynamicsWorld::Get()
70 {
71 #ifdef DALI_DYNAMICS_SUPPORT
72   Internal::DynamicsWorld* dynamicsWorld = Internal::DynamicsWorld::Get().Get();
73   DALI_ASSERT_ALWAYS( dynamicsWorld && "DynamicsWorld doesn't exist" );
74   return DynamicsWorld( dynamicsWorld );
75 #else
76   return DynamicsWorld();
77 #endif
78 }
79
80 void DynamicsWorld::DestroyInstance()
81 {
82 #ifdef DALI_DYNAMICS_SUPPORT
83   Internal::DynamicsWorld::DestroyInstance();
84 #endif
85 }
86
87 void DynamicsWorld::SetGravity(const Vector3& gravity )
88 {
89 #ifdef DALI_DYNAMICS_SUPPORT
90   GetImplementation(*this).SetGravity(gravity);
91 #endif
92 }
93
94 const Vector3& DynamicsWorld::GetGravity() const
95 {
96 #ifdef DALI_DYNAMICS_SUPPORT
97   return GetImplementation(*this).GetGravity();
98 #else
99   return Vector3::ZERO;
100 #endif
101 }
102
103 int DynamicsWorld::GetDebugDrawMode() const
104 {
105 #ifdef DALI_DYNAMICS_SUPPORT
106   return GetImplementation(*this).GetDebugDrawMode();
107 #else
108   return int();
109 #endif
110 }
111
112 void DynamicsWorld::SetDebugDrawMode(int mode)
113 {
114 #ifdef DALI_DYNAMICS_SUPPORT
115   GetImplementation(*this).SetDebugDrawMode( mode );
116 #endif
117 }
118
119 void DynamicsWorld::SetRootActor(Actor actor)
120 {
121 #ifdef DALI_DYNAMICS_SUPPORT
122   GetImplementation(*this).SetRootActor( &GetImplementation(actor) );
123 #endif
124 }
125
126 Actor DynamicsWorld::GetRootActor() const
127 {
128 #ifdef DALI_DYNAMICS_SUPPORT
129   Internal::ActorPtr actor( GetImplementation(*this).GetRootActor() );
130
131   DALI_ASSERT_DEBUG(actor || "Root Actor has not been set");
132
133   return Actor(actor.Get());
134 #else
135   return Actor();
136 #endif
137 }
138
139 DynamicsWorld::CollisionSignalType& DynamicsWorld::CollisionSignal()
140 {
141 #ifdef DALI_DYNAMICS_SUPPORT
142   return GetImplementation(*this).CollisionSignal();
143 #else
144   return STUB_COLLISION_SIGNAL;
145 #endif
146 }
147
148 DynamicsWorld::DynamicsWorld( Internal::DynamicsWorld* internal )
149 #ifdef DALI_DYNAMICS_SUPPORT
150 : BaseHandle(internal)
151 #else
152 : BaseHandle(NULL)
153 #endif
154 {
155 }
156
157 } // namespace Dali