2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0/
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.
19 * @file FUi_DimmingLayer.cpp
20 * @brief This is the implementation file for _DimmingLayer class.
22 * This file contains the implementation of _DimmingLayer class.
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"
33 using namespace Tizen::Graphics;
34 using namespace Tizen::Ui;
35 using namespace Tizen::Ui::Animations;
37 namespace Tizen { namespace Ui
40 _DimmingLayer::_DimmingLayer(void)
43 , __pDimmingElement(null)
44 , __oldControlRenderOperation(VisualElement::RENDER_OPERATION_BLEND)
49 _DimmingLayer::~_DimmingLayer(void)
51 if (__pDimmingElement)
53 __pDimmingElement->Destroy();
55 __pDimmingElement = null;
59 VisualElement* pControlVisualElement = __pControl->GetVisualElement();
60 if (pControlVisualElement)
62 pControlVisualElement->SetRenderOperation(__oldControlRenderOperation);
68 _DimmingLayer::Construct(_Control& control)
71 VisualElement* pControlVisualElement = null;
73 __pControl = &control;
75 if (!__pDimmingElement)
77 __pDimmingElement = new (std::nothrow) _ControlVisualElement;
78 SysTryReturnResult(NID_UI, __pDimmingElement, E_OUT_OF_MEMORY, "Memory allocation failed.");
81 r = __pDimmingElement->ConstructControlVisualElement();
82 SysTryCatch(NID_UI, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
84 __pDimmingElement->SetImplicitAnimationEnabled(true);
85 __pDimmingElement->SetName("DimmingLayer");
87 r = __pDimmingElement->SetSurfaceOpaque(false);
88 SysTryCatch(NID_UI, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
90 __pDimmingElement->SetShowState(true);
91 __pDimmingElement->SetOpacity(0.65f);
93 r = __pDimmingElement->SetBackgroundColor(_Colorf());
94 SysTryCatch(NID_UI, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
96 pControlVisualElement = __pControl->GetVisualElement();
97 if (pControlVisualElement)
99 __oldControlRenderOperation = pControlVisualElement->GetRenderOperation();
100 pControlVisualElement->SetRenderOperation(VisualElement::RENDER_OPERATION_BLEND);
104 SysTryCatch(NID_UI, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
109 __pDimmingElement->Destroy();
114 _DimmingLayer::SetOpacity(float opacity)
116 SysTryReturnResult(NID_UI, __pDimmingElement, E_SYSTEM, "A system error has been occurred.");
118 result r = E_SUCCESS;
120 __pDimmingElement->SetOpacity(opacity);
124 __pDimmingElement->SetSurfaceOpaque(true);
128 __pDimmingElement->SetSurfaceOpaque(false);
131 SysTryReturnResult(NID_UI, !IsFailed(r), E_SYSTEM, "A system error has been occurred.");
137 _DimmingLayer::GetOpacity(void) const
139 SysTryReturnResult(NID_UI, __pDimmingElement, E_SYSTEM, "A system error has been occurred.");
140 return __pDimmingElement->GetOpacity();
144 _DimmingLayer::SetDimmingEnabled(bool enabled)
146 SysTryReturnResult(NID_UI, __pDimmingElement, E_SYSTEM, "A system error has been occurred.");
148 result r = E_SUCCESS;
150 _VisualElement* pControlVisualElement = __pControl->GetVisualElement();
151 SysTryReturnResult(NID_UI, pControlVisualElement, E_SYSTEM, "A system error has been occurred.");
155 _Window* pWindow = __pControl->GetRootWindow();
156 _RootVisualElement* pParent = pWindow->GetRootVisualElement();
159 pParent->InsertChild(*__pDimmingElement, pControlVisualElement, false);
164 _Window* pWindow = __pControl->GetRootWindow();
165 _RootVisualElement* pParent = pWindow->GetRootVisualElement();
168 pParent->DetachChild(*__pDimmingElement);
178 _DimmingLayer::IsDimmingEnabled(void) const
184 _DimmingLayer::Rearrange(void)
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.");
189 result r = E_SUCCESS;
191 FloatDimension size = _ControlManager::GetInstance()->GetScreenSizeF();
192 bool oldValue = __pDimmingElement->IsImplicitAnimationEnabled();
193 __pDimmingElement->SetImplicitAnimationEnabled(false);
194 if (__pControl->GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT)
196 __pDimmingElement->SetBounds(Tizen::Graphics::FloatRectangle(0.0f, 0.0f, size.width, size.height));
200 __pDimmingElement->SetBounds(Tizen::Graphics::FloatRectangle(0.0f, 0.0f, size.height, size.width));
202 __pDimmingElement->SetImplicitAnimationEnabled(oldValue);