Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / effects / renderer / engine-model / FUiEffects_RendererEngineModelGroup.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file                FUiEffects_RendererEngineModelGroup.cpp
20  * @brief               This file contains implementation of Group class
21  *
22  */
23
24 #include <renderer/engine-model/FUiEffects_RendererEngineModelNode.h>
25 #include <renderer/engine-model/FUiEffects_RendererEngineModelGroup.h>
26
27 namespace Tizen { namespace Ui { namespace Effects { namespace _Renderer { namespace EngineModel
28 {
29
30 Group::Group(void)
31         : Node()
32         , _invalidBoundBox(true)
33         , _children()
34 {
35
36 }
37
38 Group::~Group(void)
39 {
40         const ChildrenListSizeType len = _children.size();
41         for (ChildrenListSizeType i = 0; len > i; ++i)
42         {
43                 _children[i]->RemoveFromParent(this);
44         }
45 }
46
47 void
48 Group::Visit(Visitor& v)
49 {
50         v.OnGroup(*this);
51         return;
52 }
53
54 bool
55 Group::AddChild(NodePtr pChild)
56 {
57         if (!pChild->AttachedToParent(this))
58         {
59                 return false;
60         }
61
62         _children.push_back(pChild);
63         InvalidateBoundBox();
64         return true;
65 }
66
67 bool
68 Group::RemoveChild(NodePtr pChild)
69 {
70         const ChildrenListSizeType len = _children.size();
71         for (ChildrenListSizeType i = 0; len > i; ++i)
72         {
73                 if (pChild == _children[i])
74                 {
75                         InternalRemoveChild(i);
76                         return true;
77                 }
78         }
79
80         return false;
81 }
82
83 bool
84 Group::RemoveChild(ChildrenListSizeType index)
85 {
86         if (index >= _children.size())
87         {
88                 return false;
89         }
90         InternalRemoveChild(index);
91         return true;
92 }
93
94 void
95 Group::Clear(void)
96 {
97         for (ChildrenListType::iterator it = _children.begin(); it != _children.end(); ++it)
98         {
99                 (*it)->RemoveFromParent(this);
100         }
101         _children.clear();
102         InvalidateBoundBox();
103         return;
104 }
105
106 void
107 Group::InternalRemoveChild(ChildrenListSizeType index)
108 {
109         const ChildrenListSizeType len = _children.size();
110         NodePtr current = _children[index];
111         std::swap(_children[index], _children[len - 1]);
112         current->RemoveFromParent(this);
113         InvalidateBoundBox();
114         return;
115 }
116
117 void
118 Group::InvalidateBoundBox(void)
119 {
120         if (_boundBox.invalid)
121         {
122                 return;
123         }
124         _boundBox.invalid = true;
125         TouchParentBoundBox();
126         return;
127 }
128
129 const Aabb&
130 Group::GetBoundBox(void)
131 {
132         if (_boundBox.invalid)
133         {
134                 ValidateBoundBox();
135         }
136         return _boundBox.value;
137 }
138
139 void
140 Group::SetWorld(const Math::Matrix4f& arg)
141 {
142         Node::SetWorld(arg);
143         const ChildrenListSizeType len = _children.size();
144         for (ChildrenListSizeType i = 0; len > i; ++i)
145         {
146                 _children[i]->ParentMoved(this);
147         }
148         return;
149 }
150
151 void
152 Group::SetLocal(const Math::Matrix4f& arg)
153 {
154         Node::SetLocal(arg);
155         const ChildrenListSizeType len = _children.size();
156         for (ChildrenListSizeType i = 0; len > i; ++i)
157         {
158                 _children[i]->ParentMoved(this);
159         }
160         return;
161 }
162
163 void
164 Group::ValidateBoundBox(void)
165 {
166         _boundBox.value.Identity();
167
168         const ChildrenListSizeType len = _children.size();
169         for (ChildrenListSizeType i = 0; len > i; ++i)
170         {
171                 _boundBox.value.Extend(_children[i]->GetBoundBoxInParentSpace());
172         }
173         _boundBox.invalid = false;
174         return;
175 }
176
177 bool
178 Group::AttachedToParent(Group* pParent)
179 {
180         if (!Node::AttachedToParent(pParent))
181         {
182                 return false;
183         }
184
185         const ChildrenListSizeType len = _children.size();
186         for (ChildrenListSizeType i = 0; len > i; ++i)
187         {
188                 _children[i]->ParentMoved(this);
189         }
190         return true;
191 }
192
193 bool
194 Group::RemoveFromParent(Group* pParent)
195 {
196         if (!Node::RemoveFromParent(pParent))
197         {
198                 return false;
199         }
200
201         const ChildrenListSizeType len = _children.size();
202         for (ChildrenListSizeType i = 0; len > i; ++i)
203         {
204                 _children[i]->ParentMoved(this);
205         }
206         return true;
207 }
208
209 void
210 Group::ParentMoved(Group* pParent)
211 {
212         if (_worldTransform.invalid)
213         {
214                 return;
215         }
216         Node::ParentMoved(pParent);
217         const ChildrenListSizeType len = _children.size();
218         for (ChildrenListSizeType i = 0; len > i; ++i)
219         {
220                 _children[i]->ParentMoved(this);
221         }
222 }
223
224 Group::ChildrenListSizeType
225 Group::ChildrenCount(void)
226 {
227         return _children.size();
228 }
229
230 NodePtr
231 Group::GetChild(ChildrenListSizeType index)
232 {
233         return _children[index];
234 }
235
236 }}}}} //Tizen::Ui::Effects::_Renderer::EngineModel