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_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 "FUiAnim_VisualElement.h"
29 #include "FUi_ResourceManager.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 Canvas* pCanvas = __pPanel->GetVisualElement()->GetCanvasN();
68 result r = GetLastResult();
69 SysTryReturn(NID_UI_CTRL, pCanvas != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
70 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
72 if (__pPanel->GetGroupStyle() == GROUP_STYLE_NONE)
74 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
78 Color panelGroupBackgroundColor;
79 GET_COLOR_CONFIG(Panel::BG_NORMAL, panelGroupBackgroundColor);
80 pCanvas->SetBackgroundColor(panelGroupBackgroundColor);
83 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
86 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
88 DrawGroupStyleBackgroundBitmap(pCanvas);
90 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
92 DrawBackgrounBitmap(pCanvas);
94 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
96 DrawGroupStyleBitmap(pCanvas);
98 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
108 _PanelPresenter::DrawBackgrounBitmap(Canvas* pCanvas)
110 Bitmap* pBackgroundBitmap = __pPanel->GetBackgroundBitmap();
112 if (pBackgroundBitmap != null)
114 Rectangle bounds = __pPanel->GetBounds();
118 if (!__pPanel->IsBackgroundBitmapStretch())
120 int bitmapWidth = pBackgroundBitmap->GetWidth();
121 int bitmapHeight = pBackgroundBitmap->GetHeight();
123 switch (__pPanel->GetBackgroundBitmapHorizontalAlign())
125 case PANEL_BACKGROUND_BITMAP_HORIZONTAL_ALIGN_RIGHT:
126 bounds.x = bounds.width - bitmapWidth;
128 case PANEL_BACKGROUND_BITMAP_HORIZONTAL_ALIGN_CENTER:
129 bounds.x = (bounds.width / 2) - (bitmapWidth / 2);
131 case PANEL_BACKGROUND_BITMAP_HORIZONTAL_ALIGN_LEFT:
137 switch (__pPanel->GetBackgroundBitmapVerticalAlign())
139 case PANEL_BACKGROUND_BITMAP_VERTICAL_ALIGN_BOTTOM:
140 bounds.y = bounds.height - bitmapHeight;
142 case PANEL_BACKGROUND_BITMAP_VERTICAL_ALIGN_MIDDLE:
143 bounds.y = (bounds.height / 2) - (bitmapHeight / 2);
145 case PANEL_BACKGROUND_BITMAP_VERTICAL_ALIGN_TOP:
151 bounds.width = bitmapWidth;
152 bounds.height = bitmapHeight;
155 if (pBackgroundBitmap->IsNinePatchedBitmap())
157 result r = pCanvas->DrawNinePatchedBitmap(bounds, *pBackgroundBitmap);
158 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
162 result r = pCanvas->DrawBitmap(bounds, *pBackgroundBitmap);
163 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
170 _PanelPresenter::DrawGroupStyleBitmap(Canvas* pCanvas)
172 result r = E_SUCCESS;
174 Bitmap* pColorReplacedBitmap = null;
175 Bitmap* pGroupStyleBitmap = __pPanel->GetGroupStyleBitmap();
177 if (pGroupStyleBitmap != null)
179 Rectangle bounds = __pPanel->GetBounds();
183 pColorReplacedBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pGroupStyleBitmap, Color::GetColor(COLOR_ID_MAGENTA), __pPanel->GetBackgroundColor());
184 if (pColorReplacedBitmap != null)
186 if (pGroupStyleBitmap->IsNinePatchedBitmap())
188 r = pCanvas->DrawNinePatchedBitmap(bounds, *pColorReplacedBitmap);
189 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
193 r = pCanvas->DrawBitmap(bounds, *pColorReplacedBitmap);
194 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
201 delete pColorReplacedBitmap;
207 _PanelPresenter::DrawGroupStyleBackgroundBitmap(Tizen::Graphics::Canvas* pCanvas)
209 result r = E_SUCCESS;
211 Bitmap* pColorReplacedBitmap = null;
212 Bitmap* pGroupStyleBackgroundBitmap = __pPanel->GetGroupStyleBackgroundBitmap();
214 if (pGroupStyleBackgroundBitmap != null)
216 Rectangle bounds = __pPanel->GetBounds();
220 pColorReplacedBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pGroupStyleBackgroundBitmap, Color::GetColor(COLOR_ID_MAGENTA), __pPanel->GetBackgroundColor());
222 SysTryCatch(NID_UI_CTRL, pColorReplacedBitmap != null && r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
224 if (pGroupStyleBackgroundBitmap->IsNinePatchedBitmap())
226 r = pCanvas->DrawNinePatchedBitmap(bounds, *pColorReplacedBitmap);
227 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
231 r = pCanvas->DrawBitmap(bounds, *pColorReplacedBitmap);
232 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
238 delete pColorReplacedBitmap;
243 }}} // Tizen::Ui::Controls