Changed indicator bg color.
[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 <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"
37
38 using namespace Tizen::Graphics;
39 using namespace Tizen::Ui;
40 using namespace Tizen::Ui::Controls;
41 using namespace Tizen::Ui::Animations;
42
43 namespace Tizen { namespace Ui
44 {
45
46 _DimmingLayer::_DimmingLayer(void)
47         : __enabled(false)
48         , __pControl(null)
49         , __pDimmingElement(null)
50         , __oldControlRenderOperation(VisualElement::RENDER_OPERATION_BLEND)
51 {
52
53 }
54
55 _DimmingLayer::~_DimmingLayer(void)
56 {
57         if (__pDimmingElement)
58         {
59                 __pDimmingElement->Destroy();
60         }
61         __pDimmingElement = null;
62
63         if (__pControl)
64         {
65                 VisualElement* pControlVisualElement = __pControl->GetVisualElement();
66                 if (pControlVisualElement)
67                 {
68                         pControlVisualElement->SetRenderOperation(__oldControlRenderOperation);
69                 }
70         }
71 }
72
73 result
74 _DimmingLayer::Construct(_Control& control)
75 {
76         result r = E_SUCCESS;
77         VisualElement* pControlVisualElement = null;
78
79         __pControl = &control;
80
81         if (!__pDimmingElement)
82         {
83                 __pDimmingElement = new (std::nothrow) _ControlVisualElement;
84                 SysTryReturnResult(NID_UI, __pDimmingElement, E_OUT_OF_MEMORY, "Memory allocation failed.");
85         }
86
87         r = __pDimmingElement->ConstructControlVisualElement();
88         SysTryCatch(NID_UI, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
89
90         __pDimmingElement->SetImplicitAnimationEnabled(true);
91         __pDimmingElement->SetName("DimmingLayer");
92
93         r = __pDimmingElement->SetSurfaceOpaque(false);
94         SysTryCatch(NID_UI, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
95
96         __pDimmingElement->SetShowState(true);
97         //__pDimmingElement->SetOpacity(0.65f);
98
99         r = __pDimmingElement->SetBackgroundColor(_Colorf());
100         SysTryCatch(NID_UI, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
101
102         pControlVisualElement = __pControl->GetVisualElement();
103         if (pControlVisualElement)
104         {
105                 __oldControlRenderOperation = pControlVisualElement->GetRenderOperation();
106                 pControlVisualElement->SetRenderOperation(VisualElement::RENDER_OPERATION_BLEND);
107         }
108
109         r = Rearrange();
110         SysTryCatch(NID_UI, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
111
112         return r;
113
114 CATCH:
115         __pDimmingElement->Destroy();
116         return E_SYSTEM;
117 }
118
119 result
120 _DimmingLayer::SetOpacity(float opacity)
121 {
122         SysTryReturnResult(NID_UI, __pDimmingElement, E_SYSTEM, "A system error has been occurred.");
123
124         result r = E_SUCCESS;
125
126         __pDimmingElement->SetOpacity(opacity);
127
128         if (opacity >= 1.0f)
129         {
130                 __pDimmingElement->SetSurfaceOpaque(true);
131         }
132         else
133         {
134                 __pDimmingElement->SetSurfaceOpaque(false);
135         }
136
137         SysTryReturnResult(NID_UI, !IsFailed(r), E_SYSTEM, "A system error has been occurred.");
138
139         return r;
140 }
141
142 float
143 _DimmingLayer::GetOpacity(void) const
144 {
145         SysTryReturnResult(NID_UI, __pDimmingElement, E_SYSTEM, "A system error has been occurred.");
146         return __pDimmingElement->GetOpacity();
147 }
148
149 result
150 _DimmingLayer::SetDimmingEnabled(bool enabled)
151 {
152         SysTryReturnResult(NID_UI, __pDimmingElement, E_SYSTEM, "A system error has been occurred.");
153
154         result r = E_SUCCESS;
155
156         FloatDimension size = _ControlManager::GetInstance()->GetScreenSizeF();
157
158         _Popup* pPopup = dynamic_cast<_Popup*>(__pControl);
159         _Indicator* pIndicator = null;
160         if (pPopup)
161         {
162                 pIndicator = pPopup->GetIndicator();
163         }
164
165         _VisualElement* pControlVisualElement = __pControl->GetVisualElement();
166         SysTryReturnResult(NID_UI, pControlVisualElement, E_SYSTEM, "A system error has been occurred.");
167
168         if (enabled)
169         {
170                 _Window* pWindow = __pControl->GetRootWindow();
171                 _RootVisualElement* pParent = pWindow->GetRootVisualElement();
172                 if (pParent)
173                 {
174                         pParent->InsertChild(*__pDimmingElement, pControlVisualElement, false);
175                 }
176                 r = __pDimmingElement->AttachChild(*pIndicator);
177                 _VisualElementImpl* pImpl = _VisualElementImpl::GetInstance(*pIndicator);
178
179                 r = pImpl->SetZOrderGroup(_ControlVisualElement::Z_ORDER_GROUP_CONTROL + 4);
180
181                 DrawBackgroundBitmap();
182         }
183         else
184         {
185                 r = __pDimmingElement->DetachChild(*pIndicator);
186                 _Window* pWindow = __pControl->GetRootWindow();
187                 _RootVisualElement* pParent = pWindow->GetRootVisualElement();
188                 if (pParent)
189                 {
190                         pParent->DetachChild(*__pDimmingElement);
191                 }
192         }
193
194         __enabled = enabled;
195
196         return r;
197 }
198
199 bool
200 _DimmingLayer::IsDimmingEnabled(void) const
201 {
202         return __enabled;
203 }
204
205 result
206 _DimmingLayer::Rearrange(void)
207 {
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.");
210
211         result r = E_SUCCESS;
212
213         FloatDimension size = _ControlManager::GetInstance()->GetScreenSizeF();
214         bool oldValue = __pDimmingElement->IsImplicitAnimationEnabled();
215         __pDimmingElement->SetImplicitAnimationEnabled(false);
216         if (__pControl->GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT)
217         {
218                 __pDimmingElement->SetBounds(Tizen::Graphics::FloatRectangle(0.0f, 0.0f, size.width, size.height));
219         }
220         else
221         {
222                 __pDimmingElement->SetBounds(Tizen::Graphics::FloatRectangle(0.0f, 0.0f, size.height, size.width));
223         }
224
225         __pDimmingElement->SetImplicitAnimationEnabled(oldValue);
226
227         return r;
228 }
229
230 result
231 _DimmingLayer::DrawBackgroundBitmap(void)
232 {
233         result r = E_SUCCESS;
234
235         const FloatDimension size = _ControlManager::GetInstance()->GetScreenSizeF();
236
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));
242
243         String imagePath = L"";
244         if (__pControl->GetOrientation() == _CONTROL_ORIENTATION_PORTRAIT)
245         {
246                 if (pPortraitBitmap)
247                 {
248                         imagePath = _BitmapImpl::GetInstance(*pPortraitBitmap)->GetFileName();
249                 }
250         }
251         else
252         {
253                 if (pLandscapeBitmap)
254                 {
255                         imagePath = _BitmapImpl::GetInstance(*pLandscapeBitmap)->GetFileName();
256                 }
257         }
258
259         if (__pDimmingElement)
260         {
261                 __pDimmingElement->SetImageSource(imagePath);
262         }
263
264         delete pPortraitBitmap;
265         delete pLandscapeBitmap;
266
267         return r;
268 }
269
270 }}   // Tizen::Ui
271