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_SliderOverlay.cpp
20 * @brief This is the implementation file for the _SliderOverlay class.
23 #include <FBaseSysLog.h>
24 #include <FBaseErrorDefine.h>
25 #include <FGrp_BitmapImpl.h>
26 #include "FUiAnim_VisualElement.h"
27 #include "FUi_ResourceManager.h"
28 #include "FUi_EcoreEvasMgr.h"
29 #include "FUi_EcoreEvas.h"
30 #include "FUiCtrl_SliderOverlay.h"
33 using namespace Tizen::Graphics;
35 namespace Tizen { namespace Ui { namespace Controls
38 _SliderOverlay::_SliderOverlay(void)
39 : __pOverlayBgBitmap(null)
41 , __overlayTextColor(0)
44 , __overlayWidth(-1.0f)
46 Tizen::Ui::Animations::_VisualElement* pBase = GetVisualElement();
50 pBase->SetSurfaceOpaque(false);
54 _SliderOverlay::~_SliderOverlay(void)
56 delete __pOverlayBgBitmap;
57 __pOverlayBgBitmap = null;
61 _SliderOverlay::Construct(_Control& owner)
67 r = CreateRootVisualElement(_WINDOW_TYPE_VE);
68 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
70 SetActivationEnabled(false);
74 r = GET_COLOR_CONFIG(SLIDER::OVERLAY_BG_NORMAL, __overlayBgColor);
75 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
77 r = GET_COLOR_CONFIG(SLIDER::OVERLAY_TEXT_NORMAL, __overlayTextColor);
78 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
81 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
87 _SliderOverlay::SetSliderRect(FloatRectangle& sliderRect, FloatRectangle& sliderTouchRect)
89 __sliderRect = sliderRect;
90 __sliderTouchRect = sliderTouchRect;
96 _SliderOverlay::SetFont(Tizen::Graphics::Font* pFont)
99 __overlayWidth = -1.0f;
104 _SliderOverlay::LoadBitmaps()
106 result r = E_SUCCESS;
108 Bitmap* pBitmap = null;
109 Bitmap* pReplacementBitmap = null;
111 r = GET_BITMAP_CONFIG_N(SLIDER::OVERLAY_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pBitmap);
112 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
114 pReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pBitmap, Color::GetColor(COLOR_ID_MAGENTA), __overlayBgColor);
116 SysTryCatch(NID_UI_CTRL, pReplacementBitmap != null, , r, "[%s] Propagating.", GetErrorMessage(r));
118 delete __pOverlayBgBitmap;
119 __pOverlayBgBitmap = pReplacementBitmap;
134 _SliderOverlay::DrawSliderOverlay(int positionX, int handleWidth, int value)
136 result r = E_SUCCESS;
138 float overlayWidth = 0.0f;
139 float overlayHeight = 0.0f;
140 float overlayBottomMargin = 0.0f;
141 float overlayLeftMargin = 0.0f;
142 int overlayTextSize = 0;
143 float overlayBodyHeight = 0.0f;
144 float overlayY = 0.0f;
145 Point textPoint(0, 0);
146 FloatDimension textDim(0.0f, 0.0f);
148 Bitmap* pBgBitmap = __pOverlayBgBitmap;
150 Tizen::Base::String text;
152 _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
154 r = GET_SHAPE_CONFIG(SLIDER::OVERLAY_MARGIN, orientation, overlayLeftMargin);
155 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
157 r = GET_SHAPE_CONFIG(SLIDER::OVERLAY_HEIGHT, orientation, overlayHeight);
158 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
160 r = GET_SHAPE_CONFIG(SLIDER::OVERLAY_BOTTOM_MARGIN, orientation, overlayBottomMargin);
161 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
163 r = GET_SHAPE_CONFIG(SLIDER::OVERLAY_HEIGHT_WITHOUT_ARROW, orientation, overlayBodyHeight);
164 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
166 r = GET_SHAPE_CONFIG(SLIDER::OVERLAY_TEXT_SIZE, orientation, overlayTextSize);
167 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
169 (_FontImpl::GetInstance(*__pFont))->SetSize(overlayTextSize);
171 if (__overlayWidth == -1.0f)
173 int fixedValue = 999;
174 Tizen::Base::String fixedText;
175 fixedText.Append(fixedValue);
176 __pFont->GetTextExtent(fixedText, fixedText.GetLength(), textDim);
177 __overlayWidth = textDim.width + 2 * overlayLeftMargin;
180 __pFont->GetTextExtent(text, text.GetLength(), textDim);
182 if (text.GetLength() == SLIDER_OVERLAY_SINGLE_DIGIT)
184 r = GET_SHAPE_CONFIG(SLIDER::OVERLAY_WIDTH, orientation, overlayWidth);
185 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
189 overlayWidth = 2 * overlayLeftMargin + textDim.width;
192 if (__sliderTouchRect.y > 0)
194 overlayY = __sliderTouchRect.y;
197 __sliderOverlayRect = FloatRectangle(__sliderRect.x + positionX + (handleWidth - overlayWidth) / 2.0f,
198 __sliderRect.y + overlayY - (overlayHeight + overlayBottomMargin),
199 overlayWidth, overlayHeight);
201 SetBounds(__sliderOverlayRect);
203 // Get canvas & Clear BG
204 Canvas* pCanvas = GetCanvasN();
205 SysTryReturn(NID_UI_CTRL, pCanvas != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred.");
207 pCanvas->SetBackgroundColor(Color(0x00000000));
210 pCanvas->SetFont(*__pFont);
213 FloatRectangle overlayRect = FloatRectangle(0.0f, 0.0f, __sliderOverlayRect.width, __sliderOverlayRect.height);
215 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBgBitmap))
217 r = pCanvas->DrawNinePatchedBitmap(overlayRect, *pBgBitmap);
221 r = pCanvas->DrawBitmap(overlayRect, *pBgBitmap);
223 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
226 __pFont->GetTextExtent(text, text.GetLength(), textDim);
227 textPoint.x = (__sliderOverlayRect.width - textDim.width) / 2;
228 textPoint.y = textPoint.y + ((overlayBodyHeight - textDim.height) / 2);
229 pCanvas->SetForegroundColor(__overlayTextColor);
230 pCanvas->DrawText(textPoint, text);
242 _SliderOverlay::IsActivatedOnOpen(void) const
248 _SliderOverlay::OnAttachedToMainTree(void)
251 return _Window::OnAttachedToMainTree();
255 _SliderOverlay::OnDetachingFromMainTree(void)
257 return _Window::OnDetachingFromMainTree();
261 _SliderOverlay::IsRotationSynchronized(void) const
266 }}} // Tizen::Ui::Controls