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 FUiCtrl_PanelPresenter.cpp
20 * @brief This is the implementation file for the %_PanelPresenter class.
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"
33 using namespace Tizen::Graphics;
34 using namespace Tizen::Ui::Animations;
36 namespace Tizen { namespace Ui { namespace Controls
39 _PanelPresenter::_PanelPresenter(void)
45 _PanelPresenter::~_PanelPresenter(void)
51 _PanelPresenter::Initialize(_Panel& panel)
59 _PanelPresenter::Draw(void)
61 if (__pPanel->GetBackgroundBitmap() == null
62 && (__pPanel->GetGroupStyle() == GROUP_STYLE_NONE || (__pPanel->GetGroupStyleBitmap() == null && __pPanel->GetGroupStyleBackgroundBitmap() == null)))
67 bool customBackground = false;
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));
74 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
77 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
80 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
82 DrawGroupStyleBackgroundBitmap(pCanvas);
84 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
86 DrawBackgrounBitmap(pCanvas);
88 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
90 switch (__pPanel->GetGroupStyle())
93 customBackground = IS_CUSTOM_BITMAP(PANEL::GROUPED_TOP_BG_NORMAL);
95 case GROUP_STYLE_MIDDLE:
96 customBackground = IS_CUSTOM_BITMAP(PANEL::GROUPED_MIDDLE_BG_NORMAL);
98 case GROUP_STYLE_BOTTOM:
99 customBackground = IS_CUSTOM_BITMAP(PANEL::GROUPED_BOTTOM_BG_NORMAL);
101 case GROUP_STYLE_SINGLE:
102 customBackground = IS_CUSTOM_BITMAP(PANEL::GROUPED_SINGLE_BG_NORMAL);
108 if (!customBackground)
110 DrawGroupStyleBitmap(pCanvas);
112 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
123 _PanelPresenter::DrawBackgrounBitmap(Canvas* pCanvas)
125 Bitmap* pBackgroundBitmap = __pPanel->GetBackgroundBitmap();
127 if (pBackgroundBitmap != null)
129 FloatRectangle bounds = __pPanel->GetBoundsF();
133 if (!__pPanel->IsBackgroundBitmapStretch())
135 int bitmapWidth = pBackgroundBitmap->GetWidth();
136 int bitmapHeight = pBackgroundBitmap->GetHeight();
138 switch (__pPanel->GetBackgroundBitmapHorizontalAlign())
140 case PANEL_BACKGROUND_BITMAP_HORIZONTAL_ALIGN_RIGHT:
141 bounds.x = bounds.width - bitmapWidth;
143 case PANEL_BACKGROUND_BITMAP_HORIZONTAL_ALIGN_CENTER:
144 bounds.x = (bounds.width / 2.0f) - (bitmapWidth / 2.0f);
146 case PANEL_BACKGROUND_BITMAP_HORIZONTAL_ALIGN_LEFT:
152 switch (__pPanel->GetBackgroundBitmapVerticalAlign())
154 case PANEL_BACKGROUND_BITMAP_VERTICAL_ALIGN_BOTTOM:
155 bounds.y = bounds.height - bitmapHeight;
157 case PANEL_BACKGROUND_BITMAP_VERTICAL_ALIGN_MIDDLE:
158 bounds.y = (bounds.height / 2.0f) - (bitmapHeight / 2.0f);
160 case PANEL_BACKGROUND_BITMAP_VERTICAL_ALIGN_TOP:
166 bounds.width = bitmapWidth;
167 bounds.height = bitmapHeight;
170 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBackgroundBitmap))
172 result r = pCanvas->DrawNinePatchedBitmap(bounds, *pBackgroundBitmap);
173 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
177 result r = pCanvas->DrawBitmap(bounds, *pBackgroundBitmap);
178 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
185 _PanelPresenter::DrawGroupStyleBitmap(Canvas* pCanvas)
187 result r = E_SUCCESS;
189 Bitmap* pColorReplacedBitmap = null;
190 Bitmap* pGroupStyleBitmap = __pPanel->GetGroupStyleBitmap();
192 if (pGroupStyleBitmap != null)
194 FloatRectangle bounds = __pPanel->GetBoundsF();
198 pColorReplacedBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pGroupStyleBitmap, Color::GetColor(COLOR_ID_MAGENTA), __pPanel->GetBackgroundColor());
199 if (pColorReplacedBitmap != null)
201 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pGroupStyleBitmap))
203 r = pCanvas->DrawNinePatchedBitmap(bounds, *pColorReplacedBitmap);
204 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
208 r = pCanvas->DrawBitmap(bounds, *pColorReplacedBitmap);
209 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
216 delete pColorReplacedBitmap;
222 _PanelPresenter::DrawGroupStyleBackgroundBitmap(Tizen::Graphics::Canvas* pCanvas)
224 result r = E_SUCCESS;
226 Bitmap* pColorReplacedBitmap = null;
227 Bitmap* pGroupStyleBackgroundBitmap = __pPanel->GetGroupStyleBackgroundBitmap();
229 if (pGroupStyleBackgroundBitmap != null)
231 FloatRectangle bounds = __pPanel->GetBoundsF();
235 pColorReplacedBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pGroupStyleBackgroundBitmap, Color::GetColor(COLOR_ID_MAGENTA), __pPanel->GetBackgroundColor());
237 SysTryCatch(NID_UI_CTRL, pColorReplacedBitmap != null && r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
239 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pGroupStyleBackgroundBitmap))
241 r = pCanvas->DrawNinePatchedBitmap(bounds, *pColorReplacedBitmap);
242 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
246 r = pCanvas->DrawBitmap(bounds, *pColorReplacedBitmap);
247 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
253 delete pColorReplacedBitmap;
258 }}} // Tizen::Ui::Controls