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 <FGrp_BitmapImpl.h>
27 #include "FUi_Control.h"
28 #include "FUi_ControlManager.h"
29 #include "FUi_Window.h"
30 #include "FUi_DimmingLayer.h"
31 #include "FUi_ResourceManager.h"
32 #include "FUiAnim_ControlVisualElement.h"
33 #include "FUiAnim_RootVisualElement.h"
34 #include "FUiAnim_VisualElementImpl.h"
35 #include "FUiCtrl_Indicator.h"
36 #include "FUiCtrl_Popup.h"
38 using namespace Tizen::Graphics;
39 using namespace Tizen::Ui;
40 using namespace Tizen::Ui::Controls;
41 using namespace Tizen::Ui::Animations;
43 namespace Tizen { namespace Ui
46 _DimmingLayer::_DimmingLayer(void)
49 , __pDimmingElement(null)
50 , __oldControlRenderOperation(VisualElement::RENDER_OPERATION_BLEND)
55 _DimmingLayer::~_DimmingLayer(void)
57 if (__pDimmingElement)
59 __pDimmingElement->Destroy();
61 __pDimmingElement = null;
65 VisualElement* pControlVisualElement = __pControl->GetVisualElement();
66 if (pControlVisualElement)
68 pControlVisualElement->SetRenderOperation(__oldControlRenderOperation);
74 _DimmingLayer::Construct(_Control& control)
77 VisualElement* pControlVisualElement = null;
79 __pControl = &control;
81 if (!__pDimmingElement)
83 __pDimmingElement = new (std::nothrow) _ControlVisualElement;
84 SysTryReturnResult(NID_UI, __pDimmingElement, E_OUT_OF_MEMORY, "Memory allocation failed.");
87 r = __pDimmingElement->ConstructControlVisualElement();
88 SysTryCatch(NID_UI, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
90 __pDimmingElement->SetImplicitAnimationEnabled(true);
91 __pDimmingElement->SetName("DimmingLayer");
93 r = __pDimmingElement->SetSurfaceOpaque(false);
94 SysTryCatch(NID_UI, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
96 __pDimmingElement->SetShowState(true);
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 FloatDimension size = _ControlManager::GetInstance()->GetScreenSizeF();
158 _Popup* pPopup = dynamic_cast<_Popup*>(__pControl);
159 _Indicator* pIndicator = null;
162 pIndicator = pPopup->GetIndicator();
165 _VisualElement* pControlVisualElement = __pControl->GetVisualElement();
166 SysTryReturnResult(NID_UI, pControlVisualElement, E_SYSTEM, "A system error has been occurred.");
170 _Window* pWindow = __pControl->GetRootWindow();
171 _RootVisualElement* pParent = pWindow->GetRootVisualElement();
174 pParent->InsertChild(*__pDimmingElement, pControlVisualElement, false);
176 r = __pDimmingElement->AttachChild(*pIndicator);
177 _VisualElementImpl* pImpl = _VisualElementImpl::GetInstance(*pIndicator);
179 r = pImpl->SetZOrderGroup(_ControlVisualElement::Z_ORDER_GROUP_CONTROL + 4);
181 DrawBackgroundBitmap();
185 r = __pDimmingElement->DetachChild(*pIndicator);
186 _Window* pWindow = __pControl->GetRootWindow();
187 _RootVisualElement* pParent = pWindow->GetRootVisualElement();
190 pParent->DetachChild(*__pDimmingElement);
200 _DimmingLayer::IsDimmingEnabled(void) const
206 _DimmingLayer::Rearrange(void)
208 SysTryReturnResult(NID_UI, __pDimmingElement, E_SYSTEM, "A system error has been occurred.");
209 SysTryReturnResult(NID_UI, __pControl, E_SYSTEM, "A system error has been occurred.");
211 result r = E_SUCCESS;
213 FloatDimension size = _ControlManager::GetInstance()->GetScreenSizeF();
214 bool oldValue = __pDimmingElement->IsImplicitAnimationEnabled();
215 __pDimmingElement->SetImplicitAnimationEnabled(false);
216 if (__pControl->GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT)
218 __pDimmingElement->SetBounds(Tizen::Graphics::FloatRectangle(0.0f, 0.0f, size.width, size.height));
222 __pDimmingElement->SetBounds(Tizen::Graphics::FloatRectangle(0.0f, 0.0f, size.height, size.width));
225 __pDimmingElement->SetImplicitAnimationEnabled(oldValue);
231 _DimmingLayer::DrawBackgroundBitmap(void)
233 result r = E_SUCCESS;
235 const FloatDimension size = _ControlManager::GetInstance()->GetScreenSizeF();
237 Bitmap* pPortraitBitmap = null;
238 Bitmap* pLandscapeBitmap = null;
239 r = GET_BITMAP_CONFIG_N(DIMMINGLAYER::BG_PORTRAIT, BITMAP_PIXEL_FORMAT_ARGB8888, pPortraitBitmap);
240 r = GET_BITMAP_CONFIG_N(DIMMINGLAYER::BG_LANDSCAPE, BITMAP_PIXEL_FORMAT_ARGB8888, pLandscapeBitmap);
241 SysTryReturnResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
243 String imagePath = L"";
244 if (__pControl->GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT)
248 imagePath = _BitmapImpl::GetInstance(*pPortraitBitmap)->GetFileName();
253 if (pLandscapeBitmap)
255 imagePath = _BitmapImpl::GetInstance(*pLandscapeBitmap)->GetFileName();
259 if (__pDimmingElement)
261 __pDimmingElement->SetImageSource(imagePath);
264 delete pPortraitBitmap;
265 delete pLandscapeBitmap;