modify license, permission and remove ^M char
[platform/framework/native/uifw.git] / src / ui / FUi_DimmingLayer.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0/
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        FUi_DimmingLayer.cpp
20  * @brief       This is the implementation file for _DimmingLayer class.
21  *
22  * This file contains the implementation of _DimmingLayer class.
23  */
24
25 #include <FGrpFloatRectangle.h>
26 #include "FUi_Control.h"
27 #include "FUi_ControlManager.h"
28 #include "FUi_Window.h"
29 #include "FUi_DimmingLayer.h"
30 #include "FUiAnim_ControlVisualElement.h"
31 #include "FUiAnim_RootVisualElement.h"
32
33 using namespace Tizen::Graphics;
34 using namespace Tizen::Ui;
35 using namespace Tizen::Ui::Animations;
36
37 namespace Tizen { namespace Ui
38 {
39
40 _DimmingLayer::_DimmingLayer(void)
41         : __enabled(false)
42         , __pControl(null)
43         , __pDimmingElement(null)
44         , __oldControlRenderOperation(VisualElement::RENDER_OPERATION_BLEND)
45 {
46
47 }
48
49 _DimmingLayer::~_DimmingLayer(void)
50 {
51         if (__pDimmingElement)
52         {
53                 __pDimmingElement->Destroy();
54         }
55         __pDimmingElement = null;
56
57         if (__pControl)
58         {
59                 VisualElement* pControlVisualElement = __pControl->GetVisualElement();
60                 if (pControlVisualElement)
61                 {
62                         pControlVisualElement->SetRenderOperation(__oldControlRenderOperation);
63                 }
64         }
65 }
66
67 result
68 _DimmingLayer::Construct(_Control& control)
69 {
70         result r = E_SUCCESS;
71         VisualElement* pControlVisualElement = null;
72
73         __pControl = &control;
74
75         if (!__pDimmingElement)
76         {
77                 __pDimmingElement = new (std::nothrow) _ControlVisualElement;
78                 SysTryReturnResult(NID_UI, __pDimmingElement, E_OUT_OF_MEMORY, "Memory allocation failed.");
79         }
80
81         r = __pDimmingElement->ConstructControlVisualElement();
82         SysTryCatch(NID_UI, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
83
84         __pDimmingElement->SetImplicitAnimationEnabled(true);
85         __pDimmingElement->SetName("DimmingLayer");
86
87         r = __pDimmingElement->SetSurfaceOpaque(false);
88         SysTryCatch(NID_UI, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
89
90         __pDimmingElement->SetShowState(true);
91         __pDimmingElement->SetOpacity(0.65f);
92
93         r = __pDimmingElement->SetBackgroundColor(_Colorf());
94         SysTryCatch(NID_UI, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
95
96         pControlVisualElement = __pControl->GetVisualElement();
97         if (pControlVisualElement)
98         {
99                 __oldControlRenderOperation = pControlVisualElement->GetRenderOperation();
100                 pControlVisualElement->SetRenderOperation(VisualElement::RENDER_OPERATION_BLEND);
101         }
102
103         r = Rearrange();
104         SysTryCatch(NID_UI, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
105
106         return r;
107
108 CATCH:
109         __pDimmingElement->Destroy();
110         return E_SYSTEM;
111 }
112
113 result
114 _DimmingLayer::SetOpacity(float opacity)
115 {
116         SysTryReturnResult(NID_UI, __pDimmingElement, E_SYSTEM, "A system error has been occurred.");
117
118         result r = E_SUCCESS;
119
120         __pDimmingElement->SetOpacity(opacity);
121
122         if (opacity >= 1.0f)
123         {
124                 __pDimmingElement->SetSurfaceOpaque(true);
125         }
126         else
127         {
128                 __pDimmingElement->SetSurfaceOpaque(false);
129         }
130
131         SysTryReturnResult(NID_UI, !IsFailed(r), E_SYSTEM, "A system error has been occurred.");
132
133         return r;
134 }
135
136 float
137 _DimmingLayer::GetOpacity(void) const
138 {
139         SysTryReturnResult(NID_UI, __pDimmingElement, E_SYSTEM, "A system error has been occurred.");
140         return __pDimmingElement->GetOpacity();
141 }
142
143 result
144 _DimmingLayer::SetDimmingEnabled(bool enabled)
145 {
146         SysTryReturnResult(NID_UI, __pDimmingElement, E_SYSTEM, "A system error has been occurred.");
147
148         result r = E_SUCCESS;
149
150         _VisualElement* pControlVisualElement = __pControl->GetVisualElement();
151         SysTryReturnResult(NID_UI, pControlVisualElement, E_SYSTEM, "A system error has been occurred.");
152
153         if (enabled)
154         {
155                 _Window* pWindow = __pControl->GetRootWindow();
156                 _RootVisualElement* pParent = pWindow->GetRootVisualElement();
157                 if (pParent)
158                 {
159                         pParent->InsertChild(*__pDimmingElement, pControlVisualElement, false);
160                 }
161         }
162         else
163         {
164                 _Window* pWindow = __pControl->GetRootWindow();
165                 _RootVisualElement* pParent = pWindow->GetRootVisualElement();
166                 if (pParent)
167                 {
168                         pParent->DetachChild(*__pDimmingElement);
169                 }
170         }
171
172         __enabled = enabled;
173
174         return r;
175 }
176
177 bool
178 _DimmingLayer::IsDimmingEnabled(void) const
179 {
180         return __enabled;
181 }
182
183 result
184 _DimmingLayer::Rearrange(void)
185 {
186         SysTryReturnResult(NID_UI, __pDimmingElement, E_SYSTEM, "A system error has been occurred.");
187         SysTryReturnResult(NID_UI, __pControl, E_SYSTEM, "A system error has been occurred.");
188
189         result r = E_SUCCESS;
190
191         FloatDimension size = _ControlManager::GetInstance()->GetScreenSizeF();
192         bool oldValue = __pDimmingElement->IsImplicitAnimationEnabled();
193         __pDimmingElement->SetImplicitAnimationEnabled(false);
194         if (__pControl->GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT)
195         {
196                 __pDimmingElement->SetBounds(Tizen::Graphics::FloatRectangle(0.0f, 0.0f, size.width, size.height));
197         }
198         else
199         {
200                 __pDimmingElement->SetBounds(Tizen::Graphics::FloatRectangle(0.0f, 0.0f, size.height, size.width));
201         }
202         __pDimmingElement->SetImplicitAnimationEnabled(oldValue);
203
204         return r;
205 }
206
207 }}   // Tizen::Ui