Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / effects / renderer / engine-model / FUiEffects_RendererEngineModelDrawable.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_RendererEngineModelDrawable.cpp
20  * @brief               This file contains implementation of Drawable class
21  *
22  */
23
24 #include <renderer/engine-model/FUiEffects_RendererEngineModelDrawable.h>
25 #include <renderer/engine-model/FUiEffects_RendererEngineModelGeometry.h>
26 #include <renderer/engine-model/FUiEffects_RendererEngineModelMaterial.h>
27
28 namespace Tizen { namespace Ui { namespace Effects { namespace _Renderer { namespace EngineModel
29 {
30
31 Drawable::Drawable(void)
32 {
33 }
34
35 Drawable::~Drawable(void)
36 {
37         if (_pCache)
38         {
39                 _pCache->Die();
40         }
41 }
42
43 void
44 Drawable::SetGeometry(GeometryPtr pGeom)
45 {
46         if (_pGeometry)
47         {
48                 _pGeometry->RemovedFromDrawable(this);
49         }
50         _pGeometry = pGeom;
51
52         if (_pGeometry)
53         {
54                 _pGeometry->AttachedToDrawable(this);
55         }
56         TouchParentBoundBox();
57         InvalidateCache();
58         return;
59 }
60
61 GeometryPtr
62 Drawable::GetGeometry(void)
63 {
64         return _pGeometry;
65 }
66
67 void
68 Drawable::SetMaterial(MaterialPtr pMat)
69 {
70         if (_pMaterial)
71         {
72                 _pMaterial->RemovedFromDrawable(this);
73         }
74         _pMaterial = pMat;
75
76         if (_pMaterial)
77         {
78                 _pMaterial->AttachedToDrawable(this);
79         }
80         InvalidateCache();
81         return;
82 }
83
84 MaterialPtr
85 Drawable::GetMaterial(void)
86 {
87         return _pMaterial;
88 }
89
90 void
91 Drawable::InvalidateCache(void)
92 {
93         if (_pCache)
94         {
95                 _pCache->Invalidate();
96         }
97         return;
98 }
99
100 void
101 Drawable::ValidateBoundBox(void)
102 {
103         if (_pGeometry)
104         {
105                 _boundBox.value = _pGeometry->GetBoundBox();
106         }
107         else
108         {
109                 _boundBox.value.Identity();
110         }
111
112         _boundBox.invalid = false;
113         return;
114 }
115
116 const Aabb&
117 Drawable::GetBoundBox(void)
118 {
119         if (_boundBox.invalid)
120         {
121                 ValidateBoundBox();
122         }
123         return _boundBox.value;
124 }
125
126 CachePtr
127 Drawable::GetCache(void)
128 {
129         return _pCache;
130 }
131
132 void
133 Drawable::SetCache(CachePtr pCache)
134 {
135         if (_pCache)
136         {
137                 _pCache->Die();
138         }
139         _pCache = pCache;
140         return;
141 }
142
143 void
144 Drawable::InvalidateBoundBox(void)
145 {
146         return;
147 }
148
149 }}}}} //Tizen::Ui::Effects::_Renderer::EngineModel