Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_PanelPresenter.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                FUiCtrl_PanelPresenter.cpp
20  * @brief       This is the implementation file for the %_PanelPresenter class.
21  *
22  */
23
24 #include <FBaseSysLog.h>
25 #include <FBaseErrorDefine.h>
26 #include <FGrpCanvas.h>
27 #include <FGrp_BitmapImpl.h>
28 #include "FUi_ResourceManager.h"
29 #include "FUiAnim_VisualElement.h"
30 #include "FUiCtrl_PanelPresenter.h"
31 #include "FUiCtrl_Panel.h"
32
33 using namespace Tizen::Graphics;
34 using namespace Tizen::Ui::Animations;
35
36 namespace Tizen { namespace Ui { namespace Controls
37 {
38
39 _PanelPresenter::_PanelPresenter(void)
40         : __pPanel(null)
41 {
42         // Nothing
43 }
44
45 _PanelPresenter::~_PanelPresenter(void)
46 {
47         // Nothing
48 }
49
50 result
51 _PanelPresenter::Initialize(_Panel& panel)
52 {
53         __pPanel = &panel;
54
55         return E_SUCCESS;
56 }
57
58 result
59 _PanelPresenter::Draw(void)
60 {
61         if (__pPanel->GetBackgroundBitmap() == null
62                 && (__pPanel->GetGroupStyle() == GROUP_STYLE_NONE || (__pPanel->GetGroupStyleBitmap() == null && __pPanel->GetGroupStyleBackgroundBitmap() == null)))
63         {
64                 return E_SUCCESS;
65         }
66
67         bool customBackground = false;
68
69         Canvas* pCanvas = __pPanel->GetVisualElement()->GetCanvasN();
70         result r = GetLastResult();
71         SysTryReturn(NID_UI_CTRL, pCanvas != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
72         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
73
74         pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
75
76         r = GetLastResult();
77         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
78
79         r = pCanvas->Clear();
80         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
81
82         DrawGroupStyleBackgroundBitmap(pCanvas);
83         r = GetLastResult();
84         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
85
86         DrawBackgrounBitmap(pCanvas);
87         r = GetLastResult();
88         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
89
90         switch (__pPanel->GetGroupStyle())
91         {
92         case GROUP_STYLE_TOP:
93                 customBackground = IS_CUSTOM_BITMAP(PANEL::GROUPED_TOP_BG_NORMAL);
94                 break;
95         case GROUP_STYLE_MIDDLE:
96                 customBackground = IS_CUSTOM_BITMAP(PANEL::GROUPED_MIDDLE_BG_NORMAL);
97                 break;
98         case GROUP_STYLE_BOTTOM:
99                 customBackground = IS_CUSTOM_BITMAP(PANEL::GROUPED_BOTTOM_BG_NORMAL);
100                 break;
101         case GROUP_STYLE_SINGLE:
102                 customBackground = IS_CUSTOM_BITMAP(PANEL::GROUPED_SINGLE_BG_NORMAL);
103                 break;
104         default:
105                 break;
106         }
107
108         if (!customBackground)
109         {
110                 DrawGroupStyleBitmap(pCanvas);
111                 r = GetLastResult();
112                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
113         }
114
115         // fall throw
116 CATCH:
117         delete pCanvas;
118
119         return r;
120 }
121
122 void
123 _PanelPresenter::DrawBackgrounBitmap(Canvas* pCanvas)
124 {
125         Bitmap* pBackgroundBitmap = __pPanel->GetBackgroundBitmap();
126
127         if (pBackgroundBitmap != null)
128         {
129                 FloatRectangle bounds = __pPanel->GetBoundsF();
130                 bounds.x = 0.0f;
131                 bounds.y = 0.0f;
132
133                 if (!__pPanel->IsBackgroundBitmapStretch())
134                 {
135                         int bitmapWidth = pBackgroundBitmap->GetWidth();
136                         int bitmapHeight = pBackgroundBitmap->GetHeight();
137
138                         switch (__pPanel->GetBackgroundBitmapHorizontalAlign())
139                         {
140                                 case PANEL_BACKGROUND_BITMAP_HORIZONTAL_ALIGN_RIGHT:
141                                         bounds.x = bounds.width - bitmapWidth;
142                                         break;
143                                 case PANEL_BACKGROUND_BITMAP_HORIZONTAL_ALIGN_CENTER:
144                                         bounds.x = (bounds.width / 2.0f) - (bitmapWidth / 2.0f);
145                                         break;
146                                 case PANEL_BACKGROUND_BITMAP_HORIZONTAL_ALIGN_LEFT:
147                                         // fall through
148                                 default:
149                                         break;
150                         }
151
152                         switch (__pPanel->GetBackgroundBitmapVerticalAlign())
153                         {
154                                 case PANEL_BACKGROUND_BITMAP_VERTICAL_ALIGN_BOTTOM:
155                                         bounds.y = bounds.height - bitmapHeight;
156                                         break;
157                                 case PANEL_BACKGROUND_BITMAP_VERTICAL_ALIGN_MIDDLE:
158                                         bounds.y = (bounds.height / 2.0f) - (bitmapHeight / 2.0f);
159                                         break;
160                                 case PANEL_BACKGROUND_BITMAP_VERTICAL_ALIGN_TOP:
161                                         // fall through
162                                 default:
163                                         break;
164                         }
165
166                         bounds.width = bitmapWidth;
167                         bounds.height = bitmapHeight;
168                 }
169
170                 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBackgroundBitmap))
171                 {
172                         result r = pCanvas->DrawNinePatchedBitmap(bounds, *pBackgroundBitmap);
173                         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
174                 }
175                 else
176                 {
177                         result r = pCanvas->DrawBitmap(bounds, *pBackgroundBitmap);
178                         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
179                 }
180         }
181
182 }
183
184 void
185 _PanelPresenter::DrawGroupStyleBitmap(Canvas* pCanvas)
186 {
187         result r = E_SUCCESS;
188
189         Bitmap* pColorReplacedBitmap = null;
190         Bitmap* pGroupStyleBitmap = __pPanel->GetGroupStyleBitmap();
191
192         if (pGroupStyleBitmap != null)
193         {
194                 FloatRectangle bounds = __pPanel->GetBoundsF();
195                 bounds.x = 0.0f;
196                 bounds.y = 0.0f;
197
198                 pColorReplacedBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pGroupStyleBitmap, Color::GetColor(COLOR_ID_MAGENTA), __pPanel->GetBackgroundColor());
199                 if (pColorReplacedBitmap != null)
200                 {
201                         if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pGroupStyleBitmap))
202                         {
203                                 r = pCanvas->DrawNinePatchedBitmap(bounds, *pColorReplacedBitmap);
204                                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
205                         }
206                         else
207                         {
208                                 r = pCanvas->DrawBitmap(bounds, *pColorReplacedBitmap);
209                                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
210                         }
211                 }
212         }
213
214         // fall through
215 CATCH:
216         delete pColorReplacedBitmap;
217
218         SetLastResult(r);
219 }
220
221 void
222 _PanelPresenter::DrawGroupStyleBackgroundBitmap(Tizen::Graphics::Canvas* pCanvas)
223 {
224         result r = E_SUCCESS;
225
226         Bitmap* pColorReplacedBitmap = null;
227         Bitmap* pGroupStyleBackgroundBitmap = __pPanel->GetGroupStyleBackgroundBitmap();
228
229         if (pGroupStyleBackgroundBitmap != null)
230         {
231                 FloatRectangle bounds = __pPanel->GetBoundsF();
232                 bounds.x = 0.0f;
233                 bounds.y = 0.0f;
234
235                 pColorReplacedBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pGroupStyleBackgroundBitmap, Color::GetColor(COLOR_ID_MAGENTA), __pPanel->GetBackgroundColor());
236                 r = GetLastResult();
237                 SysTryCatch(NID_UI_CTRL, pColorReplacedBitmap != null && r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
238
239                 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pGroupStyleBackgroundBitmap))
240                 {
241                         r = pCanvas->DrawNinePatchedBitmap(bounds, *pColorReplacedBitmap);
242                         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
243                 }
244                 else
245                 {
246                         r = pCanvas->DrawBitmap(bounds, *pColorReplacedBitmap);
247                         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
248                 }
249         }
250
251         // fall through
252 CATCH:
253         delete pColorReplacedBitmap;
254
255         SetLastResult(r);
256 }
257
258 }}} // Tizen::Ui::Controls
259