2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://floralicense.org/license/
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 FUiCtrl_DimmingLayer.cpp
20 * @brief This is the implementation file for _DimmingLayer class.
22 * This file contains the implementation of _DimmingLayer class.
26 #include <FGrpFloatRectangle.h>
28 #include "FUi_Control.h"
29 #include "FUi_ControlManager.h"
30 #include "FUi_Window.h"
31 #include "FUiCtrl_DimmingLayer.h"
32 #include "FUiAnim_ControlVisualElement.h"
33 #include "FUiAnim_RootVisualElement.h"
35 using namespace Tizen::Ui::Controls;
36 using namespace Tizen::Graphics;
37 using namespace Tizen::Ui::Animations;
38 using namespace Tizen::Ui;
47 _DimmingLayer::_DimmingLayer(void)
50 , __pDimmingElement(null)
51 , __oldControlRenderOperation(VisualElement::RENDER_OPERATION_BLEND)
56 _DimmingLayer::~_DimmingLayer(void)
58 if (__pDimmingElement)
60 __pDimmingElement->Destroy();
62 __pDimmingElement = null;
66 VisualElement* pControlVisualElement = __pControl->GetVisualElement();
67 if (pControlVisualElement)
69 pControlVisualElement->SetRenderOperation(__oldControlRenderOperation);
75 _DimmingLayer::Construct(_Control& control)
78 VisualElement* pControlVisualElement = null;
80 __pControl = &control;
82 if (!__pDimmingElement)
84 __pDimmingElement = new (std::nothrow) _ControlVisualElement;
85 SysTryReturnResult(NID_UI, __pDimmingElement, E_OUT_OF_MEMORY, "Memory allocation failed.");
88 r = __pDimmingElement->ConstructControlVisualElement();
89 SysTryCatch(NID_UI, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
91 __pDimmingElement->SetImplicitAnimationEnabled(true);
92 __pDimmingElement->SetName("DimmingLayer");
94 r = __pDimmingElement->SetSurfaceOpaque(false);
95 SysTryCatch(NID_UI, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
97 __pDimmingElement->SetOpacity(0.65f);
99 r = __pDimmingElement->SetBackgroundColor(_Colorf());
100 SysTryCatch(NID_UI, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
102 pControlVisualElement = __pControl->GetVisualElement();
103 if (pControlVisualElement)
105 __oldControlRenderOperation = pControlVisualElement->GetRenderOperation();
106 pControlVisualElement->SetRenderOperation(VisualElement::RENDER_OPERATION_BLEND);
110 SysTryCatch(NID_UI, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
115 __pDimmingElement->Destroy();
120 _DimmingLayer::SetOpacity(float opacity)
122 SysTryReturnResult(NID_UI, __pDimmingElement, E_SYSTEM, "A system error has been occurred.");
124 result r = E_SUCCESS;
126 __pDimmingElement->SetOpacity(opacity);
130 __pDimmingElement->SetSurfaceOpaque(true);
134 __pDimmingElement->SetSurfaceOpaque(false);
137 SysTryReturnResult(NID_UI, !IsFailed(r), E_SYSTEM, "A system error has been occurred.");
143 _DimmingLayer::GetOpacity(void) const
145 SysTryReturnResult(NID_UI, __pDimmingElement, E_SYSTEM, "A system error has been occurred.");
146 return __pDimmingElement->GetOpacity();
150 _DimmingLayer::SetDimmingEnabled(bool enabled)
152 SysTryReturnResult(NID_UI, __pDimmingElement, E_SYSTEM, "A system error has been occurred.");
154 result r = E_SUCCESS;
156 _VisualElement* pControlVisualElement = __pControl->GetVisualElement();
157 SysTryReturnResult(NID_UI, pControlVisualElement, E_SYSTEM, "A system error has been occurred.");
159 __pDimmingElement->SetShowState(enabled);
162 #if !defined(MULTI_WINDOW)
163 VisualElement* pParent = pControlVisualElement->GetParent();
165 _Window* pWindow = __pControl->GetRootWindow();
166 _RootVisualElement* pParent = pWindow->GetRootVisualElement();
170 pParent->InsertChild(*__pDimmingElement, pControlVisualElement, false);
175 #if !defined(MULTI_WINDOW)
176 VisualElement* pParent = pControlVisualElement->GetParent();
178 _Window* pWindow = __pControl->GetRootWindow();
179 _RootVisualElement* pParent = pWindow->GetRootVisualElement();
183 pParent->DetachChild(*__pDimmingElement);
193 _DimmingLayer::GetDimmingEnabled(void) const
199 _DimmingLayer::Rearrange(void)
201 SysTryReturnResult(NID_UI, __pDimmingElement, E_SYSTEM, "A system error has been occurred.");
202 SysTryReturnResult(NID_UI, __pControl, E_SYSTEM, "A system error has been occurred.");
204 result r = E_SUCCESS;
206 Dimension size = _ControlManager::GetInstance()->GetScreenSize();
207 if (__pControl->GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT)
209 __pDimmingElement->SetBounds(Tizen::Graphics::FloatRectangle(0.0f, 0.0f, (float)size.width, (float)size.height));
213 __pDimmingElement->SetBounds(Tizen::Graphics::FloatRectangle(0.0f, 0.0f, (float)size.height, (float)size.width));
219 } // Tizen::Ui::Controls