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.
18 * @file FUiCtrl_SliderPresenter.cpp
19 * @brief This is the implementation file for the _SliderPresenter class.
22 #include <FBaseSysLog.h>
23 #include <FBaseErrorDefine.h>
24 #include <FGrp_BitmapImpl.h>
25 #include <FGrp_FontImpl.h>
26 #include <FGrp_TextTextObject.h>
27 #include <FGrp_TextTextSimple.h>
28 #include "FUi_UiTouchEvent.h"
29 #include "FUi_ResourceManager.h"
30 #include "FUiAnim_VisualElement.h"
31 #include "FUiCtrl_Slider.h"
32 #include "FUiCtrl_SliderModel.h"
33 #include "FUiCtrl_SliderOverlay.h"
35 #include "FUiCtrl_SliderPresenter.h"
37 using namespace Tizen::Graphics;
38 using namespace Tizen::Base;
39 using namespace Tizen::Ui::Animations;
40 using namespace Tizen::Graphics::_Text;
42 namespace Tizen { namespace Ui { namespace Controls
45 _SliderPresenter::_SliderPresenter(void)
47 , __pSliderModel(null)
48 , __pSliderOverlay(null)
49 , __pResourceBgTopBitmap(null)
50 , __pResourceBgMiddleBitmap(null)
51 , __pResourceBgBottomBitmap(null)
52 , __pResourceBgSingleBitmap(null)
53 , __pBgTopBitmap(null)
54 , __pBgMiddleBitmap(null)
55 , __pBgBottomBitmap(null)
56 , __pBgSingleBitmap(null)
57 , __pBgGrpStyleNoneBitmap(null)
58 , __pBgTopEffectBitmap(null)
59 , __pBgMiddleEffectBitmap(null)
60 , __pBgBottomEffectBitmap(null)
61 , __pBgSingleEffectBitmap(null)
62 , __pResourceBarBitmap(null)
63 , __pBarResourceEffectBitmap(null)
64 , __pBarBgResourceEffectBitmap(null)
65 , __pBarColorReplacementBitmap(null)
66 , __pBarBgColorReplacementBitmap(null)
67 , __pHandleNormalBitmap(null)
68 , __pHandlePressedBitmap(null)
69 , __pHandleDisabledBitmap(null)
70 , __pHandleHighlightedBitmap(null)
71 , __pHandleNormalEffectBitmap(null)
72 , __pHandlePressedEffectBitmap(null)
73 , __pHandleDisabledEffectBitmap(null)
74 , __pHandleHighlightedEffectBitmap(null)
75 , __currentBarColor(0)
78 , __pTitleTextObject(null)
81 , __isSliderPressed(false)
82 , __isNeedToBeUpdated(true)
83 , __isBubblingBlocked(false)
84 , __isResourceLoaded(false)
85 , __isCustomHandle(false)
86 , __isCustomPressedTextColor(false)
87 , __groupStyle(GROUP_STYLE_NONE)
92 _SliderPresenter::~_SliderPresenter(void)
94 delete __pSliderModel;
95 __pSliderModel = null;
97 delete __pSliderOverlay;
98 __pSliderOverlay = null;
100 delete __pResourceBgTopBitmap;
101 __pResourceBgTopBitmap = null;
103 delete __pResourceBgMiddleBitmap;
104 __pResourceBgMiddleBitmap = null;
106 delete __pResourceBgBottomBitmap;
107 __pResourceBgBottomBitmap = null;
109 delete __pResourceBgSingleBitmap;
110 __pResourceBgSingleBitmap = null;
112 delete __pBgTopBitmap;
113 __pBgTopBitmap = null;
115 delete __pBgMiddleBitmap;
116 __pBgMiddleBitmap = null;
118 delete __pBgBottomBitmap;
119 __pBgBottomBitmap = null;
121 delete __pBgSingleBitmap;
122 __pBgSingleBitmap = null;
124 delete __pBgGrpStyleNoneBitmap;
125 __pBgGrpStyleNoneBitmap = null;
127 delete __pBgTopEffectBitmap;
128 __pBgTopEffectBitmap = null;
130 delete __pBgMiddleEffectBitmap;
131 __pBgMiddleEffectBitmap = null;
133 delete __pBgBottomEffectBitmap;
134 __pBgBottomEffectBitmap = null;
136 delete __pBgSingleEffectBitmap;
137 __pBgSingleEffectBitmap = null;
139 delete __pResourceBarBitmap;
140 __pResourceBarBitmap = null;
142 delete __pBarResourceEffectBitmap;
143 __pBarResourceEffectBitmap = null;
145 delete __pBarBgResourceEffectBitmap;
146 __pBarBgResourceEffectBitmap = null;
148 delete __pBarColorReplacementBitmap;
149 __pBarColorReplacementBitmap = null;
151 delete __pBarBgColorReplacementBitmap;
152 __pBarBgColorReplacementBitmap = null;
154 delete __pHandleNormalBitmap;
155 __pHandleNormalBitmap = null;
157 delete __pHandlePressedBitmap;
158 __pHandlePressedBitmap = null;
160 delete __pHandleDisabledBitmap;
161 __pHandleDisabledBitmap = null;
163 delete __pHandleHighlightedBitmap;
164 __pHandleHighlightedBitmap = null;
166 delete __pHandleNormalEffectBitmap;
167 __pHandleNormalEffectBitmap = null;
169 delete __pHandlePressedEffectBitmap;
170 __pHandlePressedEffectBitmap = null;
172 delete __pHandleDisabledEffectBitmap;
173 __pHandleDisabledEffectBitmap = null;
175 delete __pHandleHighlightedEffectBitmap;
176 __pHandleHighlightedEffectBitmap = null;
178 delete __pTitleTextObject;
179 __pTitleTextObject = null;
184 _SliderPresenter::CreateInstanceN(const _Slider& slider)
186 result r = E_SUCCESS;
188 _SliderPresenter* pSliderPresenter = new (std::nothrow) _SliderPresenter;
189 SysTryReturn(NID_UI_CTRL, pSliderPresenter != null, null, E_OUT_OF_MEMORY,
190 "[E_OUT_OF_MEMORY] Memory allocation failed.");
192 pSliderPresenter->__pSlider = const_cast <_Slider*>(&slider);
193 SysTryCatch(NID_UI_CTRL, pSliderPresenter->__pSlider != null, , E_SYSTEM,
194 "[E_SYSTEM] A system error has occurred. The Slider control core is null.");
196 pSliderPresenter->__pSliderModel = new (std::nothrow) _SliderModel;
197 SysTryCatch(NID_UI_CTRL, pSliderPresenter->__pSliderModel != null, , E_OUT_OF_MEMORY,
198 "[E_OUT_OF_MEMORY] Memory allocation failed.");
200 if (pSliderPresenter->__pSlider->GetStyle() & _SLIDER_STYLE_OVERLAY)
202 pSliderPresenter->__pSliderOverlay = new (std::nothrow) _SliderOverlay;
203 SysTryCatch(NID_UI_CTRL, pSliderPresenter->__pSliderOverlay != null, , E_OUT_OF_MEMORY,
204 "[E_OUT_OF_MEMORY] Memory allocation failed.");
206 r = pSliderPresenter->__pSliderOverlay->Construct();
207 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
210 return pSliderPresenter;
213 delete pSliderPresenter;
214 pSliderPresenter = null;
220 _SliderPresenter::Resize(void)
222 result r = E_SUCCESS;
225 int barLeftMargin = 0;
226 int barRightMargin = 0;
229 int iconSideMargin = 0;
231 int minimumHeight = 0;
232 int minimumWidth = 0;
234 int iconRightMargin = 0;
235 Rectangle titleTextBounds;
237 _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
239 if (__isResourceLoaded == false)
242 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
243 __isResourceLoaded = true;
245 r = GET_SHAPE_CONFIG(SLIDER::HANDLE_ONE_DIGIT_TEXT_SIZE, orientation, __fontSize);
246 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
248 __pFont = __pSlider->GetFallbackFont();
250 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
252 r = GET_COLOR_CONFIG(SLIDER::HANDLE_NUMBER_TEXT_NORMAL, __handleTextColor);
253 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
255 r = GET_COLOR_CONFIG(SLIDER::HANDLE_NUMBER_TEXT_DISABLED, __handleTextDisabledColor);
256 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
258 __handleTextPressedColor = __handleTextColor;
259 __handleTextHighlightedColor = __handleTextColor;
264 r = GET_SHAPE_CONFIG(SLIDER::BAR_HEIGHT, orientation, barHeight);
265 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
267 r = GET_SHAPE_CONFIG(SLIDER::BAR_LEFT_MARGIN, orientation, barLeftMargin);
268 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
270 barRightMargin = barLeftMargin;
272 r = GET_SHAPE_CONFIG(SLIDER::ICON_WIDTH, orientation, iconWidth);
273 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
276 if (!__isCustomHandle)
278 r = GET_SHAPE_CONFIG(SLIDER::HANDLE_OFFSET, orientation, offset);
279 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
281 r = GET_SHAPE_CONFIG(SLIDER::HANDLE_WIDTH, orientation, __handleRect.width);
282 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
284 r = GET_SHAPE_CONFIG(SLIDER::HANDLE_HEIGHT, orientation, __handleRect.height);
285 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
287 __rect = Rectangle(0, 0, __pSlider->GetBounds().width, __pSlider->GetBounds().height);
289 r = GET_SHAPE_CONFIG(SLIDER::BAR_TOP_MARGIN, orientation, topMargin);
290 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
292 r = GET_SHAPE_CONFIG(SLIDER::ICON_RIGHT_MARGIN, orientation, iconRightMargin);
293 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
295 if ((__pSlider->GetIcon(ICON_POSITION_LEFT) != null) || (__pSlider->GetIcon(ICON_POSITION_RIGHT) != null))
297 r = GET_SHAPE_CONFIG(SLIDER::MINIMUM_SIZE_WITH_ICON, orientation, minimumWidth);
298 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
300 if (__rect.width < minimumWidth)
302 __rect.width = minimumWidth;
307 r = GET_SHAPE_CONFIG(SLIDER::MINIMUM_SIZE_WITHOUT_ICON, orientation, minimumWidth);
308 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
310 if (__rect.width < minimumWidth)
311 __rect.width = minimumWidth;
314 if (__pSlider->GetStyle() & _SLIDER_STYLE_TITLE_TEXT)
316 r = GET_SHAPE_CONFIG(SLIDER::TITLE_TEXT_SIZE, orientation, minimumHeight);
317 minimumHeight = minimumHeight + (2 * topMargin) + barHeight;
318 if (__rect.height < minimumHeight )
319 __rect.height = minimumHeight;
323 minimumHeight = (2 * topMargin) + barHeight;
324 if (__rect.height < minimumHeight)
325 __rect.height = minimumHeight;
328 if (__pSlider->GetStyle() & _SLIDER_STYLE_TITLE_TEXT)
330 titleTextBounds = GetTitleTextBounds();
331 sliderY = titleTextBounds.y + titleTextBounds.height;
332 __touchRect = Rectangle(barLeftMargin - offset, sliderY + (__rect.height - (sliderY + __handleRect.height)) / 2,
333 __rect.width - (barLeftMargin + barRightMargin) + (2 * offset), __handleRect.height);
337 __touchRect = Rectangle(barLeftMargin - offset, (__rect.height - __handleRect.height) / 2,
338 (__rect.width - (barLeftMargin + barRightMargin)) + (2 * offset), __handleRect.height);
341 if (__pSlider->GetIcon(ICON_POSITION_LEFT) != null)
343 __touchRect.x = __touchRect.x + iconWidth + iconRightMargin;
344 __touchRect.width = __touchRect.width - (iconWidth + iconRightMargin);
347 if (__pSlider->GetIcon(ICON_POSITION_RIGHT) != null)
349 __touchRect.width = __touchRect.width - (iconWidth + iconSideMargin + iconRightMargin);
352 __barBgRect = Rectangle(__touchRect.x + offset, __touchRect.y +
353 ((__handleRect.height - barHeight) / 2), __touchRect.width - (2 * offset), barHeight);
355 Rectangle absBounds = __pSlider->GetAbsoluteBounds();
356 __pSliderOverlay->SetSliderRect(absBounds, __touchRect);
362 _SliderPresenter::LoadBitmap(void)
364 result r = E_SUCCESS;
367 Bitmap* pBitmap = null;
368 Bitmap* pNormalBitmap = null;
369 Bitmap* pPressedBitmap = null;
370 Bitmap* pDisabledBitmap = null;
371 Bitmap* pHighlightedBitmap = null;
372 Bitmap* pReplacementBitmap = null;
374 Color handleNormalColor;
375 Color handlePressedColor;
376 Color handleDisabledColor;
377 Color handleHighlightedColor;
379 r = GET_COLOR_CONFIG(SLIDER::BG_OTHERS_NORMAL, __currentBgColor);
380 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
382 r = GET_COLOR_CONFIG(SLIDER::BG_DEFAULT_NORMAL, __currentGrpStyleNoneColor);
383 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
385 r = GET_COLOR_CONFIG(SLIDER::BAR_NORMAL, __currentBarColor);
386 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
388 r = GET_COLOR_CONFIG(SLIDER::BAR_BG_NORMAL, barBgColor);
389 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
391 r = GET_COLOR_CONFIG(SLIDER::HANDLE_BG_NORMAL, handleNormalColor);
392 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
394 r = GET_COLOR_CONFIG(SLIDER::HANDLE_BG_PRESSED, handlePressedColor);
395 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
397 r = GET_COLOR_CONFIG(SLIDER::HANDLE_BG_DISABLED, handleDisabledColor);
398 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
400 r = GET_COLOR_CONFIG(SLIDER::HANDLE_BG_HIGHLIGHTED, handleHighlightedColor);
401 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
403 // for GROUP_STYLE_TOP
404 r = GET_BITMAP_CONFIG_N(SLIDER::GROUP_TOP_BG, BITMAP_PIXEL_FORMAT_ARGB8888, __pResourceBgTopBitmap);
405 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Propagating.");
407 __pBgTopBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pResourceBgTopBitmap,Color::GetColor(COLOR_ID_MAGENTA), __currentBgColor);
409 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
411 r = GET_BITMAP_CONFIG_N(SLIDER::GROUP_TOP_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pBgTopEffectBitmap);
412 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
415 // for GROUP_STYLE_MIDDLE
416 r = GET_BITMAP_CONFIG_N(SLIDER::GROUP_MIDDLE_BG, BITMAP_PIXEL_FORMAT_ARGB8888, __pResourceBgMiddleBitmap);
417 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
419 __pBgMiddleBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pResourceBgMiddleBitmap,Color::GetColor(COLOR_ID_MAGENTA), __currentBgColor);
421 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
423 r = GET_BITMAP_CONFIG_N(SLIDER::GROUP_MIDDLE_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pBgMiddleEffectBitmap);
424 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
427 // for GROUP_STYLE_BOTTOM
428 r = GET_BITMAP_CONFIG_N(SLIDER::GROUP_BOTTOM_BG, BITMAP_PIXEL_FORMAT_ARGB8888, __pResourceBgBottomBitmap);
429 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
431 __pBgBottomBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pResourceBgBottomBitmap,Color::GetColor(COLOR_ID_MAGENTA), __currentBgColor);
433 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
435 r = GET_BITMAP_CONFIG_N(SLIDER::GROUP_BOTTOM_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pBgBottomEffectBitmap);
436 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
438 // for GROUP_STYLE_SINGLE and GROUP_STYLE_NONE
439 r = GET_BITMAP_CONFIG_N(SLIDER::GROUP_SINGLE_BG, BITMAP_PIXEL_FORMAT_ARGB8888, __pResourceBgSingleBitmap);
440 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
442 __pBgSingleBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pResourceBgSingleBitmap, Color::GetColor(COLOR_ID_MAGENTA), __currentBgColor);
444 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
446 __pBgGrpStyleNoneBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pResourceBgSingleBitmap, Color::GetColor(COLOR_ID_MAGENTA), __currentGrpStyleNoneColor);
448 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
451 r = GET_BITMAP_CONFIG_N(SLIDER::GROUP_SINGLE_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pBgSingleEffectBitmap);
452 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
454 opacity = __currentBgColor.GetAlpha();
456 __pBgTopBitmap->SetAlphaConstant(opacity);
457 __pBgMiddleBitmap->SetAlphaConstant(opacity);
458 __pBgBottomBitmap->SetAlphaConstant(opacity);
459 __pBgSingleBitmap->SetAlphaConstant(opacity);
460 __pBgGrpStyleNoneBitmap->SetAlphaConstant(__currentGrpStyleNoneColor.GetAlpha());
463 __pBgTopEffectBitmap->SetAlphaConstant(opacity);
464 __pBgMiddleEffectBitmap->SetAlphaConstant(opacity);
465 __pBgBottomEffectBitmap->SetAlphaConstant(opacity);
466 __pBgSingleEffectBitmap->SetAlphaConstant(opacity);
470 r = GET_BITMAP_CONFIG_N(SLIDER::BAR_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pResourceBarBitmap);
471 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
473 __pBarBgColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pResourceBarBitmap,Color::GetColor(COLOR_ID_MAGENTA), barBgColor);
475 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
477 delete __pResourceBarBitmap;
478 __pResourceBarBitmap = null;
480 r = GET_BITMAP_CONFIG_N(SLIDER::BAR_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pResourceBarBitmap);
481 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
483 __pBarColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pResourceBarBitmap,Color::GetColor(COLOR_ID_MAGENTA), __currentBarColor);
485 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
487 r = GET_BITMAP_CONFIG_N(SLIDER::BAR_BG_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pBarBgResourceEffectBitmap);
488 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
490 r = GET_BITMAP_CONFIG_N(SLIDER::BAR_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pBarResourceEffectBitmap);
491 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
493 opacity = __currentBarColor.GetAlpha();
494 __pBarColorReplacementBitmap->SetAlphaConstant(opacity);
497 r = GET_BITMAP_CONFIG_N(SLIDER::HANDLE_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pNormalBitmap);
498 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
500 if (__pHandleNormalBitmap == null)
502 pReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pNormalBitmap, Color::GetColor(COLOR_ID_MAGENTA), handleNormalColor);
504 SysTryCatch(NID_UI_CTRL, (pReplacementBitmap != null), , r, "[%s] Propagating.", GetErrorMessage(r));
506 __pHandleNormalBitmap = pReplacementBitmap;
509 r = GET_BITMAP_CONFIG_N(SLIDER::HANDLE_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pPressedBitmap);
510 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
512 if (__pHandlePressedBitmap == null)
514 pReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pPressedBitmap, Color::GetColor(COLOR_ID_MAGENTA), handlePressedColor);
516 SysTryCatch(NID_UI_CTRL, (pReplacementBitmap != null), , r, "[%s] Propagating.", GetErrorMessage(r));
518 __pHandlePressedBitmap = pReplacementBitmap;
521 r = GET_BITMAP_CONFIG_N(SLIDER::HANDLE_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pDisabledBitmap);
522 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
524 if (__pHandleDisabledBitmap == null)
526 pReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pDisabledBitmap, Color::GetColor(COLOR_ID_MAGENTA), handleDisabledColor);
528 SysTryCatch(NID_UI_CTRL, (pReplacementBitmap != null), , r, "[%s] Propagating.", GetErrorMessage(r));
530 __pHandleDisabledBitmap = pReplacementBitmap;
533 r = GET_BITMAP_CONFIG_N(SLIDER::HANDLE_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pHighlightedBitmap);
534 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
536 if (__pHandleHighlightedBitmap == null)
538 pReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pHighlightedBitmap, Color::GetColor(COLOR_ID_MAGENTA), handleHighlightedColor);
540 SysTryCatch(NID_UI_CTRL, (pReplacementBitmap != null), , r, "[%s] Propagating.", GetErrorMessage(r));
542 __pHandleHighlightedBitmap = pReplacementBitmap;
545 if (__pHandleNormalEffectBitmap == null)
547 r = GET_BITMAP_CONFIG_N(SLIDER::HANDLE_BG_EFFECT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pBitmap);
548 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
550 __pHandleNormalEffectBitmap = pBitmap;
553 if (__pHandlePressedEffectBitmap == null)
555 r = GET_BITMAP_CONFIG_N(SLIDER::HANDLE_BG_EFFECT_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, pBitmap);
556 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
558 __pHandlePressedEffectBitmap = pBitmap;
561 if (__pHandleDisabledEffectBitmap == null)
563 r = GET_BITMAP_CONFIG_N(SLIDER::HANDLE_BG_EFFECT_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, pBitmap);
564 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
566 __pHandleDisabledEffectBitmap = pBitmap;
569 if (__pHandleHighlightedEffectBitmap == null)
571 r = GET_BITMAP_CONFIG_N(SLIDER::HANDLE_BG_EFFECT_HIGHLIGHTED, BITMAP_PIXEL_FORMAT_ARGB8888, pBitmap);
572 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
574 __pHandleHighlightedEffectBitmap = pBitmap;
577 delete pNormalBitmap;
578 delete pPressedBitmap;
579 delete pDisabledBitmap;
580 delete pHighlightedBitmap;
586 delete pNormalBitmap;
587 delete pPressedBitmap;
588 delete pDisabledBitmap;
589 delete pHighlightedBitmap;
593 delete __pResourceBgTopBitmap;
594 __pResourceBgTopBitmap = null;
596 delete __pResourceBgMiddleBitmap;
597 __pResourceBgMiddleBitmap = null;
599 delete __pResourceBgBottomBitmap;
600 __pResourceBgBottomBitmap = null;
602 delete __pResourceBgSingleBitmap;
603 __pResourceBgSingleBitmap = null;
605 delete __pBgTopBitmap;
606 __pBgTopBitmap = null;
608 delete __pBgMiddleBitmap;
609 __pBgMiddleBitmap = null;
611 delete __pBgBottomBitmap;
612 __pBgBottomBitmap = null;
614 delete __pBgSingleBitmap;
615 __pBgSingleBitmap = null;
617 delete __pBgGrpStyleNoneBitmap;
618 __pBgGrpStyleNoneBitmap = null;
620 delete __pBgTopEffectBitmap;
621 __pBgTopEffectBitmap = null;
623 delete __pBgMiddleEffectBitmap;
624 __pBgMiddleEffectBitmap = null;
626 delete __pBgBottomEffectBitmap;
627 __pBgBottomEffectBitmap = null;
629 delete __pBgSingleEffectBitmap;
630 __pBgSingleEffectBitmap = null;
632 delete __pResourceBarBitmap;
633 __pResourceBarBitmap = null;
635 delete __pBarResourceEffectBitmap;
636 __pBarResourceEffectBitmap = null;
638 delete __pBarBgResourceEffectBitmap;
639 __pBarBgResourceEffectBitmap = null;
641 delete __pBarColorReplacementBitmap;
642 __pBarColorReplacementBitmap = null;
644 delete __pBarBgColorReplacementBitmap;
645 __pBarBgColorReplacementBitmap = null;
647 delete __pHandleNormalBitmap;
648 __pHandleNormalBitmap = null;
650 delete __pHandlePressedBitmap;
651 __pHandlePressedBitmap = null;
653 delete __pHandleDisabledBitmap;
654 __pHandleDisabledBitmap = null;
656 delete __pHandleHighlightedBitmap;
657 __pHandleHighlightedBitmap = null;
659 delete __pHandleNormalEffectBitmap;
660 __pHandleNormalEffectBitmap = null;
662 delete __pHandlePressedEffectBitmap;
663 __pHandlePressedEffectBitmap = null;
665 delete __pHandleDisabledEffectBitmap;
666 __pHandleDisabledEffectBitmap = null;
668 delete __pHandleHighlightedEffectBitmap;
669 __pHandleHighlightedEffectBitmap = null;
675 _SliderPresenter::CalculateSliderValue(int positionX, int offsetX)
677 int minValue = __pSliderModel->GetMinValue();
678 int maxValue = __pSliderModel->GetMaxValue();
680 if (positionX <= __touchRect.x + offsetX)
687 if (positionX >= (__touchRect.x + __touchRect.width) - offsetX)
689 __sliderX = __barBgRect.width - __handleRect.width;
690 __handleX = __touchRect.width - __handleRect.width;
694 if ((maxValue - minValue) == 0)
699 __sliderX = positionX - (__barBgRect.x + offsetX);
700 __handleX = positionX - (__touchRect.x + offsetX);
702 __handleRect.x = __touchRect.x + __handleX;
703 __handleRect.y = __touchRect.y;
705 if (__handleRect.x < __touchRect.x )
707 __handleRect.x = __touchRect.x;
710 if (__handleRect.x + __handleRect.width > __touchRect.x + __touchRect.width )
712 __handleRect.x = __touchRect.x + __touchRect.width - __handleRect.width;
715 return minValue + (int) ((float) (__handleX * (maxValue - minValue)) / (float)(__touchRect.width - __handleRect.width) + 0.5); // current value = current width * range / bar bg width
719 _SliderPresenter::Draw(void)
721 if (__isNeedToBeUpdated == true)
730 _SliderPresenter::DrawSlider(void)
732 result r = E_SUCCESS;
734 Rectangle titleTextBounds;
736 int style = __pSlider->GetStyle();
738 Canvas* pCanvas = __pSlider->GetCanvasN();
739 SysTryReturn(NID_UI_CTRL, pCanvas != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] System error occurred.");
741 if (__isNeedToBeUpdated == true)
743 r = DrawBackground(*pCanvas);
744 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
746 r = DrawIcon(*pCanvas);
747 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
749 if (style & _SLIDER_STYLE_TITLE_TEXT)
751 r = DrawTitleText(*pCanvas);
752 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
755 __isNeedToBeUpdated = false;
758 if (style & _SLIDER_STYLE_TITLE_TEXT)
760 titleTextBounds = GetTitleTextBounds();
761 sliderY = titleTextBounds.y + titleTextBounds.height;
764 if(sliderY < __rect.height)
766 r = DrawSliderBar(*pCanvas);
767 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
769 if (__isSliderPressed == true)
771 if (style & _SLIDER_STYLE_OVERLAY)
773 r = DrawSliderOverlay(__pSliderModel->GetValue());
774 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
778 r = DrawSliderBarNumber(__pSliderModel->GetValue());
779 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
784 r = DrawSliderBarNumber(__pSliderModel->GetValue());
785 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
802 _SliderPresenter::DrawBackground(Canvas& canvas)
804 Bitmap* pBgBitmap = null;
805 Bitmap* pBgEffectBitmap = null;
806 Bitmap* pBgGroupBitmap = null;
809 result r = E_SUCCESS;
810 canvas.SetBackgroundColor(Color(0x00000000));
813 if (!(__pSlider->GetStyle() & _SLIDER_STYLE_NO_BG))
815 switch (__groupStyle)
817 case GROUP_STYLE_TOP:
818 pBgEffectBitmap = __pBgTopEffectBitmap;
819 if (__pSlider->GetColor() == __currentBgColor)
821 pBgBitmap = __pBgTopBitmap;
825 pBgGroupBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pResourceBgTopBitmap, Color::GetColor(COLOR_ID_MAGENTA), __pSlider->GetColor());
829 SysLog(NID_UI_CTRL, "[%s] Propagating.", GetErrorMessage(r));
834 delete __pBgTopBitmap;
835 __pBgTopBitmap = null;
836 __pBgTopBitmap = pBgGroupBitmap;
838 pBgBitmap = pBgGroupBitmap;
839 opacity = __pSlider->GetColor().GetAlpha();
840 pBgBitmap->SetAlphaConstant(opacity);
841 __currentBgColor = __pSlider->GetColor();
846 case GROUP_STYLE_MIDDLE:
847 pBgEffectBitmap = __pBgMiddleEffectBitmap;
848 if (__pSlider->GetColor() == __currentBgColor)
850 pBgBitmap = __pBgMiddleBitmap;
854 pBgGroupBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pResourceBgMiddleBitmap, Color::GetColor(COLOR_ID_MAGENTA), __pSlider->GetColor());
858 SysLog(NID_UI_CTRL, "[%s] Propagating.", GetErrorMessage(r));
863 delete __pBgMiddleBitmap;
864 __pBgMiddleBitmap = null;
865 __pBgMiddleBitmap = pBgGroupBitmap;
867 pBgBitmap = __pBgMiddleBitmap;
868 opacity = __pSlider->GetColor().GetAlpha();
869 pBgBitmap->SetAlphaConstant(opacity);
870 __currentBgColor = __pSlider->GetColor();
875 case GROUP_STYLE_BOTTOM:
876 pBgEffectBitmap = __pBgBottomEffectBitmap;
877 if (__pSlider->GetColor() == __currentBgColor)
879 pBgBitmap = __pBgBottomBitmap;
883 pBgGroupBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pResourceBgBottomBitmap, Color::GetColor(COLOR_ID_MAGENTA), __pSlider->GetColor());
887 SysLog(NID_UI_CTRL, "[%s] Propagating.", GetErrorMessage(r));
892 delete __pBgBottomBitmap;
893 __pBgBottomBitmap = null;
894 __pBgBottomBitmap = pBgGroupBitmap;
896 pBgBitmap = __pBgBottomBitmap;
897 opacity = __pSlider->GetColor().GetAlpha();
898 pBgBitmap->SetAlphaConstant(opacity);
899 __currentBgColor = __pSlider->GetColor();
904 case GROUP_STYLE_SINGLE:
905 pBgEffectBitmap = __pBgSingleEffectBitmap;
906 if (__pSlider->GetColor() == __currentBgColor)
908 pBgBitmap = __pBgSingleBitmap;
912 pBgGroupBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pResourceBgSingleBitmap, Color::GetColor(COLOR_ID_MAGENTA), __pSlider->GetColor());
916 SysLog(NID_UI_CTRL, "[%s] Propagating.", GetErrorMessage(r));
922 delete __pBgSingleBitmap;
923 __pBgSingleBitmap = null;
924 __pBgSingleBitmap = pBgGroupBitmap;
926 pBgBitmap = __pBgSingleBitmap;
927 opacity = __pSlider->GetColor().GetAlpha();
928 pBgBitmap->SetAlphaConstant(opacity);
929 __currentBgColor = __pSlider->GetColor();
934 case GROUP_STYLE_NONE:
937 if (__pSlider->GetColor() == __currentBgColor)
939 pBgBitmap = __pBgGrpStyleNoneBitmap;
943 pBgGroupBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pResourceBgSingleBitmap, Color::GetColor(COLOR_ID_MAGENTA), __pSlider->GetColor());
947 SysLog(NID_UI_CTRL, "[%s] Propagating.", GetErrorMessage(r));
952 delete __pBgGrpStyleNoneBitmap;
953 __pBgGrpStyleNoneBitmap = null;
954 __pBgGrpStyleNoneBitmap = pBgGroupBitmap;
956 pBgBitmap = __pBgGrpStyleNoneBitmap;
957 opacity = __pSlider->GetColor().GetAlpha();
958 pBgBitmap->SetAlphaConstant(opacity);
959 __currentBgColor = __pSlider->GetColor();
965 DrawBitmap(canvas, __rect, pBgBitmap);
966 if ( __groupStyle != GROUP_STYLE_NONE)
968 DrawBitmap(canvas, __rect, pBgEffectBitmap);
975 _SliderPresenter::DrawSliderBar(Canvas& canvas)
977 result r = E_SUCCESS;
978 int bitmapHeight = 0;
980 int bitmapPositionX = 0;
981 int bitmapPositionY = 0;
984 Bitmap* pReplacementBitmap = null;
985 Bitmap* pHandleBitmap = null;
986 Bitmap* pHandleEffectBitmap = null;
988 _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
990 r = GET_SHAPE_CONFIG(SLIDER::HANDLE_OFFSET, orientation, offset);
991 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
993 if (__pSlider->IsEnabled() == false) // disabled
995 pHandleBitmap = __pHandleDisabledBitmap;
996 pHandleEffectBitmap = __pHandleDisabledEffectBitmap;
997 if(__isSliderPressed == true)
999 __isSliderPressed = false;
1000 if (__pSlider->GetStyle() & _SLIDER_STYLE_OVERLAY)
1002 __pSliderOverlay->Close();
1006 else if (__isSliderPressed == true) // pressed
1008 pHandleBitmap = __pHandlePressedBitmap;
1009 pHandleEffectBitmap = __pHandlePressedEffectBitmap;
1011 else if (__pSlider->IsFocused() == true)
1013 pHandleBitmap = __pHandleHighlightedBitmap;
1014 pHandleEffectBitmap = __pHandleHighlightedEffectBitmap;
1016 else //(__isSliderPressed == false) // normal state
1018 pHandleBitmap = __pHandleNormalBitmap;
1019 pHandleEffectBitmap = __pHandleNormalEffectBitmap;
1022 int minValue = __pSliderModel->GetMinValue();
1023 int maxValue = __pSliderModel->GetMaxValue();
1025 __barRect = Rectangle(__barBgRect.x, __barBgRect.y, __sliderX, __barBgRect.height);
1027 if (__isSliderPressed == false && (maxValue - minValue) != 0)
1029 __barRect.width = ((__barBgRect.width - __handleRect.width) * (__pSliderModel->GetValue() - minValue)) / (maxValue - minValue);
1030 __handleX = ((__touchRect.width - __handleRect.width) * (__pSliderModel->GetValue() - minValue)) / (maxValue - minValue);
1033 if (__pSlider->GetBarColor() != __currentBarColor)
1035 pReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pResourceBarBitmap, Color::GetColor(COLOR_ID_MAGENTA), __pSlider->GetBarColor());
1036 r = GetLastResult();
1037 SysTryReturn(NID_UI_CTRL, (pReplacementBitmap != null), r, r, "[%s] Propagating.", GetErrorMessage(r));
1039 delete __pBarColorReplacementBitmap;
1040 __pBarColorReplacementBitmap = null;
1042 __pBarColorReplacementBitmap = pReplacementBitmap;
1043 __currentBarColor = __pSlider->GetBarColor();
1046 // Redrawing twice is required because, when slider is disabled we are applying alpha channel to the bar
1047 // which will show the previously drawn portion.
1049 __pBarBgColorReplacementBitmap->SetAlphaConstant(0xFF);
1050 __pBarColorReplacementBitmap->SetAlphaConstant(0xFF);
1052 DrawBitmap(canvas, __barBgRect, __pBarBgColorReplacementBitmap);
1053 DrawBitmap(canvas, __barBgRect, __pBarBgResourceEffectBitmap);
1056 if (__pSlider->IsEnabled() == false) // disabled
1058 __pBarBgColorReplacementBitmap->SetAlphaConstant(0x4C);
1059 __pBarColorReplacementBitmap->SetAlphaConstant(0x4C);
1063 opacity = __pSlider->GetBarColor().GetAlpha();
1064 __pBarBgColorReplacementBitmap->SetAlphaConstant(opacity);
1065 __pBarColorReplacementBitmap->SetAlphaConstant(opacity);
1068 DrawBitmap(canvas, __barBgRect, __pBarBgColorReplacementBitmap);
1069 DrawBitmap(canvas, __barBgRect, __pBarBgResourceEffectBitmap);
1071 DrawBitmap(canvas, Rectangle(__barRect.x, __barRect.y, (__barRect.width + __handleRect.width / 2), __barRect.height), __pBarColorReplacementBitmap);
1072 DrawBitmap(canvas, Rectangle(__barRect.x, __barRect.y, (__barRect.width + __handleRect.width / 2), __barRect.height), __pBarResourceEffectBitmap);
1074 __handleRect.x = __touchRect.x + __handleX;
1075 __handleRect.y = __touchRect.y;
1077 if (__handleRect.x < __touchRect.x )
1079 __handleRect.x = __touchRect.x;
1082 if (__handleRect.x + __handleRect.width > __touchRect.x + __touchRect.width )
1084 __handleRect.x = __touchRect.x + __touchRect.width - __handleRect.width;
1087 Canvas* pHandleCanvas = __pSlider->GetHandleCanvasN();
1088 r = GetLastResult();
1089 SysTryReturn(NID_UI_CTRL, pHandleCanvas != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
1091 pHandleCanvas->SetBackgroundColor(0x00000000);
1092 pHandleCanvas->Clear();
1094 if (pHandleEffectBitmap != null) // drawing the default bitmap
1096 r = DrawBitmap(*pHandleCanvas, Rectangle(0, 0, __handleRect.width, __handleRect.height), pHandleBitmap);
1097 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1099 r = DrawBitmap(*pHandleCanvas, Rectangle(0, 0, __handleRect.width, __handleRect.height), pHandleEffectBitmap);
1100 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1104 bitmapWidth = pHandleBitmap->GetWidth();
1105 bitmapHeight = pHandleBitmap->GetHeight();
1107 if (pHandleBitmap->IsNinePatchedBitmap() == false)
1109 // to clip the center portion of the larger bitmap.
1110 if( bitmapWidth > __handleRect.width )
1112 bitmapPositionX = (bitmapWidth / 2) - (__handleRect.width / 2);
1113 bitmapWidth = __handleRect.width;
1116 if( bitmapHeight > __handleRect.height )
1118 bitmapPositionY = (bitmapHeight / 2) - (__handleRect.height / 2);
1119 bitmapHeight = __handleRect.height;
1122 r = pHandleCanvas->DrawBitmap(Rectangle(0, 0, __handleRect.width, __handleRect.height), *pHandleBitmap, Rectangle(bitmapPositionX, bitmapPositionY, bitmapWidth, bitmapHeight));
1126 r = pHandleCanvas->DrawNinePatchedBitmap(Rectangle(0, 0, __handleRect.width, __handleRect.height), *pHandleBitmap);
1128 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1131 r = __pSlider->UpdateHandle(__handleRect);
1134 SysLogException(NID_UI_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
1137 delete pHandleCanvas;
1138 pHandleCanvas = null;
1143 delete pHandleCanvas;
1144 pHandleCanvas = null;
1150 _SliderPresenter::DrawSliderBarNumber(int value)
1152 result r = E_SUCCESS;
1153 int handleNumberSize = 0;
1156 int valueLength = 0;
1157 _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
1159 if (__pSlider->IsEnabled() == false) // disabled
1161 textColor = __handleTextDisabledColor;
1163 else if (__pSlider->IsFocused() == true)
1165 textColor = __handleTextHighlightedColor;
1167 else if ((__isSliderPressed == true) && !(__pSlider->GetStyle() & _SLIDER_STYLE_OVERLAY))
1169 if(!__isCustomPressedTextColor)
1171 r = GET_COLOR_CONFIG(SLIDER::OVERLAY_TEXT_NORMAL, __handleTextPressedColor);
1172 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1174 textColor = __handleTextPressedColor;
1178 textColor = __handleTextColor;
1181 Dimension textDim(0, 0);
1183 valueLength = text.GetLength();
1185 if (valueLength == SLIDER_HANDLE_THREE_DIGIT)
1187 r = GET_SHAPE_CONFIG(SLIDER::HANDLE_THREE_DIGIT_TEXT_SIZE, orientation, handleNumberSize);
1188 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1190 else if (valueLength == SLIDER_HANDLE_TWO_DIGIT)
1192 r = GET_SHAPE_CONFIG(SLIDER::HANDLE_TWO_DIGIT_TEXT_SIZE, orientation, handleNumberSize);
1193 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1197 r = GET_SHAPE_CONFIG(SLIDER::HANDLE_ONE_DIGIT_TEXT_SIZE, orientation, handleNumberSize);
1198 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1201 (_FontImpl::GetInstance(*__pFont))->SetSize(handleNumberSize);
1203 Canvas* pHandleCanvas = __pSlider->GetHandleCanvasN();
1204 r = GetLastResult();
1205 SysTryReturn(NID_UI_CTRL, pHandleCanvas != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
1207 pHandleCanvas->SetFont(*__pFont);
1208 __pFont->GetTextExtent(text, valueLength, textDim);
1211 textPoint.x = (__handleRect.width - textDim.width) / 2;
1212 textPoint.y = (__handleRect.height - textDim.height) / 2;
1214 pHandleCanvas->SetForegroundColor(textColor);
1215 pHandleCanvas->DrawText(textPoint, text);
1217 delete pHandleCanvas;
1218 pHandleCanvas = null;
1224 _SliderPresenter::DrawTitleText(Canvas& canvas)
1226 result r = E_SUCCESS;
1228 TextSimple* pSimpleTitleText = null;
1229 int titleTextSize = 0;
1230 int titleLength = 0;
1231 Rectangle titleTextBounds;
1232 _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
1234 titleLength = __pSlider->GetTitleText().GetLength();
1235 SysTryReturn(NID_UI_CTRL, titleLength != 0, E_SUCCESS, E_SUCCESS, "Title text is empty");
1237 r = GET_SHAPE_CONFIG(SLIDER::TITLE_TEXT_SIZE, orientation, titleTextSize);
1238 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1240 (_FontImpl::GetInstance(*__pFont))->SetSize(titleTextSize);
1242 titleTextBounds = GetTitleTextBounds();
1244 if (__pTitleTextObject == null)
1246 __pTitleTextObject = new (std::nothrow) TextObject();
1247 SysTryReturn(NID_UI_CTRL, __pTitleTextObject != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1248 __pTitleTextObject->Construct();
1251 pSimpleTitleText = new (std::nothrow) TextSimple(const_cast<wchar_t*>(__pSlider->GetTitleText().GetPointer()), __pSlider->GetTitleText().GetLength());
1253 __pTitleTextObject->RemoveAll();
1254 __pTitleTextObject->AppendElement(*pSimpleTitleText);
1255 __pTitleTextObject->SetForegroundColor(__pSlider->GetTitleTextColor(), 0, __pTitleTextObject->GetTextLength());
1256 __pTitleTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
1257 __pTitleTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
1258 __pTitleTextObject->SetBounds(GetTitleTextBounds());
1259 __pTitleTextObject->Compose();
1261 __pTitleTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT | TEXT_OBJECT_ALIGNMENT_MIDDLE);
1262 __pTitleTextObject->SetFont(__pFont, 0, __pTitleTextObject->GetTextLength());
1263 __pTitleTextObject->Draw(*_CanvasImpl::GetInstance(canvas));
1269 _SliderPresenter::DrawIcon(Canvas& canvas)
1271 result r = E_SUCCESS;
1273 Bitmap* pLeftBitmap = __pSlider->GetIcon(ICON_POSITION_LEFT);
1274 Bitmap* pRightBitmap = __pSlider->GetIcon(ICON_POSITION_RIGHT);
1276 if (pLeftBitmap != null)
1278 r = DrawBitmap(canvas, GetIconBounds(ICON_POSITION_LEFT), pLeftBitmap);
1279 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1282 if (pRightBitmap != null)
1284 r = DrawBitmap(canvas, GetIconBounds(ICON_POSITION_RIGHT), pRightBitmap);
1285 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1292 _SliderPresenter::DrawSliderOverlay(int value)
1294 result r = E_SUCCESS;
1296 Rectangle absBounds = __pSlider->GetAbsoluteBounds();
1297 r = __pSliderOverlay->SetSliderRect(absBounds, __touchRect);
1298 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1300 r = __pSliderOverlay->DrawSliderOverlay(__touchRect.x + __handleX, __handleRect.width, value);
1301 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1307 _SliderPresenter::DrawBitmap(Canvas& canvas, const Rectangle& bounds, Bitmap* pBitmap)
1309 result r = E_SUCCESS;
1311 if (pBitmap->IsNinePatchedBitmap())
1313 r = canvas.DrawNinePatchedBitmap(bounds, *pBitmap);
1314 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
1318 r = canvas.DrawBitmap(bounds, *pBitmap);
1319 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
1326 _SliderPresenter::GetTitleTextBounds(void) const
1328 Rectangle titleTextBounds;
1331 result r = E_SUCCESS;
1332 _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
1334 r = GET_SHAPE_CONFIG(SLIDER::TITLE_TEXT_POSITION_X, orientation, titleTextBounds.x);
1335 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, Rectangle(), r, "[%s] Propagating.", GetErrorMessage(r));
1337 r = GET_SHAPE_CONFIG(SLIDER::TITLE_TEXT_POSITION_Y, orientation, titleTextBounds.y);
1338 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, Rectangle(), r, "[%s] Propagating.", GetErrorMessage(r));
1340 r = GET_SHAPE_CONFIG(SLIDER::BAR_TOP_MARGIN, orientation, topMargin);
1341 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, Rectangle(), r, "[%s] Propagating.", GetErrorMessage(r));
1343 titleTextBounds.y = titleTextBounds.y + topMargin;
1345 r = GET_SHAPE_CONFIG(SLIDER::TITLE_TEXT_HEIGHT, orientation, titleTextBounds.height);
1346 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, Rectangle(), r, "[%s] Propagating.", GetErrorMessage(r));
1348 titleTextBounds.width = __pSlider->GetBounds().width - titleTextBounds.x;
1350 return titleTextBounds;
1354 _SliderPresenter::GetTouchBounds(void) const
1360 _SliderPresenter::GetIconBounds(IconPosition iconPosition) const
1362 result r = E_SUCCESS;
1364 Rectangle iconBounds;
1365 int iconSideMargin = 0;
1368 _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
1370 r = GET_SHAPE_CONFIG(SLIDER::ICON_WIDTH, orientation, iconBounds.width);
1371 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, Rectangle(), r, "[%s] Propagating.", GetErrorMessage(r));
1373 r = GET_SHAPE_CONFIG(SLIDER::ICON_HEIGHT, orientation, iconBounds.height);
1374 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, Rectangle(), r, "[%s] Propagating.", GetErrorMessage(r));
1376 r = GET_SHAPE_CONFIG(SLIDER::ICON_LEFT_MARGIN, orientation, iconSideMargin);
1377 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, Rectangle(), r, "[%s] Propagating.", GetErrorMessage(r));
1379 r = GET_SHAPE_CONFIG(SLIDER::BAR_HEIGHT, orientation, barHeight);;
1380 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, Rectangle(), r, "[%s] Propagating.", GetErrorMessage(r));
1382 iconBounds.y = __barBgRect.y + ((barHeight - iconBounds.height) / 2);
1384 if (iconPosition == ICON_POSITION_LEFT)
1386 iconBounds.x = iconSideMargin;
1390 iconBounds.x = __rect.width - (iconSideMargin + iconBounds.width);
1397 _SliderPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
1399 if (__pSlider != &source)
1404 Point point = touchinfo.GetCurrentPosition();
1406 __isBubblingBlocked = false;
1408 if (__pSlider->IsEnabled() == true && __handleRect.Contains(point) == true)
1410 int candidateValue = CalculateSliderValue(point.x, point.x - __handleRect.x);
1412 __pSliderModel->SetValue(candidateValue);
1413 __pSlider->SetAccessibilityElementValue();
1415 __isSliderPressed = true;
1416 __isBubblingBlocked = true;
1418 if (__pSlider->GetStyle() & _SLIDER_STYLE_OVERLAY)
1420 __pSliderOverlay->Open(false);
1423 __pSlider->Invalidate();
1426 return __isBubblingBlocked;
1430 _SliderPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
1432 if (__pSlider != &source)
1437 Point point = touchinfo.GetCurrentPosition();
1438 bool isBubblingBlocked = __isBubblingBlocked;
1440 if (__isSliderPressed == true)
1442 __isSliderPressed = false;
1444 int candidateValue = CalculateSliderValue(point.x, point.x - __handleRect.x);
1446 __pSliderModel->SetValue(candidateValue);
1447 __pSlider->SetAccessibilityElementValue();
1448 __pSlider->Invalidate();
1450 if (__pSlider->GetStyle() & _SLIDER_STYLE_OVERLAY)
1452 __pSliderOverlay->Close();
1455 // Adjustment Event Fire
1456 _AdjustmentEvent* pAdjustmentEvent = dynamic_cast <_AdjustmentEvent*>(__pSlider->GetAdjustmentEvent());
1457 if (pAdjustmentEvent != null)
1459 Tizen::Base::Runtime::IEventArg* pEventArg = _AdjustmentEvent::CreateAdjustmentEventArgN(candidateValue);
1460 result r = GetLastResult();
1461 SysTryReturn(NID_UI_CTRL, pEventArg != null, true, r, "[%s] Propagating.", GetErrorMessage(r));
1463 pAdjustmentEvent->Fire(*pEventArg);
1467 return isBubblingBlocked;
1471 _SliderPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1473 if (__pSlider != &source)
1478 Point point = touchinfo.GetCurrentPosition();
1479 bool isBubblingBlocked = __isBubblingBlocked;
1481 if (__isSliderPressed == false)
1486 if (__pSlider->IsEnabled() == false)
1488 __isSliderPressed = false;
1492 int handleHalfWidth = __handleRect.width / 2;
1493 int oldValue = __pSliderModel->GetValue();
1494 int candidateValue = CalculateSliderValue(point.x, handleHalfWidth);
1496 __pSliderModel->SetValue(candidateValue);
1497 __pSlider->SetAccessibilityElementValue();
1499 __pSlider->Invalidate();
1501 if (oldValue != candidateValue)
1503 // Slider Event Fire
1504 _SliderEvent* pSliderEvent = dynamic_cast <_SliderEvent*>(__pSlider->GetSliderEvent());
1505 if (pSliderEvent != null)
1507 Tizen::Base::Runtime::IEventArg* pEventArg = _SliderEvent::CreateSliderEventArgN(candidateValue);
1508 result r = GetLastResult();
1509 SysTryReturn(NID_UI_CTRL, pEventArg != null, true, r, "[%s] Propagating.", GetErrorMessage(r));
1511 pSliderEvent->Fire(*pEventArg);
1515 return isBubblingBlocked;
1519 _SliderPresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
1521 return OnTouchReleased(source, touchinfo);
1525 _SliderPresenter::OnBoundsChanged(void)
1527 __isNeedToBeUpdated = true;
1534 _SliderPresenter::OnFontChanged(Font* pFont)
1537 __isNeedToBeUpdated = true;
1539 if(__pSliderOverlay != null)
1540 __pSliderOverlay->SetFont(pFont);
1546 _SliderPresenter::OnFontInfoRequested(unsigned long& style, int& size)
1548 style = FONT_STYLE_BOLD;
1554 _SliderPresenter::SetMinValue(int minValue)
1556 __pSliderModel->SetMinValue(minValue);
1558 if (__pSliderModel->GetValue() < minValue)
1560 __pSliderModel->SetValue(minValue);
1567 _SliderPresenter::SetMaxValue(int maxValue)
1569 __pSliderModel->SetMaxValue(maxValue);
1571 if (__pSliderModel->GetValue() > maxValue)
1573 __pSliderModel->SetValue(maxValue);
1580 _SliderPresenter::GetMinValue(void) const
1582 return __pSliderModel->GetMinValue();
1586 _SliderPresenter::GetMaxValue(void) const
1588 return __pSliderModel->GetMaxValue();
1592 _SliderPresenter::SetValue(int value)
1594 SysTryReturnVoidResult(NID_UI_CTRL, __isSliderPressed == false, E_SYSTEM, "[E_SYSTEM] Failed to set value of slider.");
1596 int minValue = __pSliderModel->GetMinValue();
1597 int maxValue = __pSliderModel->GetMaxValue();
1599 if (value > maxValue)
1603 else if (value < minValue)
1608 __pSliderModel->SetValue(value);
1614 _SliderPresenter::GetValue(void) const
1616 return __pSliderModel->GetValue();
1620 _SliderPresenter::SetNeedUpdate(void)
1622 __isNeedToBeUpdated = true;
1627 _SliderPresenter::SetGroupStyle(GroupStyle groupStyle)
1629 __groupStyle = groupStyle;
1634 _SliderPresenter::SetThumbBitmap(SliderThumbStatus status, const Bitmap& bitmap)
1636 Bitmap* pThumbBitmap = null;
1637 result r = E_SUCCESS;
1639 pThumbBitmap = _BitmapImpl::CloneN(bitmap);
1641 r = GetLastResult();
1642 SysTryReturn(NID_UI_CTRL, pThumbBitmap != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
1646 case SLIDER_THUMB_STATUS_PRESSED:
1648 delete __pHandlePressedEffectBitmap;
1649 __pHandlePressedEffectBitmap = null;
1651 delete __pHandlePressedBitmap;
1652 __pHandlePressedBitmap = pThumbBitmap;
1655 case SLIDER_THUMB_STATUS_DISABLED:
1657 delete __pHandleDisabledEffectBitmap;
1658 __pHandleDisabledEffectBitmap = null;
1660 delete __pHandleDisabledBitmap;
1661 __pHandleDisabledBitmap = pThumbBitmap;
1664 case SLIDER_THUMB_STATUS_HIGHLIGHTED:
1666 delete __pHandleHighlightedEffectBitmap;
1667 __pHandleHighlightedEffectBitmap = null;
1669 delete __pHandleHighlightedEffectBitmap;
1670 __pHandleHighlightedEffectBitmap = pThumbBitmap;
1673 case SLIDER_THUMB_STATUS_NORMAL:
1677 delete __pHandleNormalEffectBitmap;
1678 __pHandleNormalEffectBitmap = null;
1680 delete __pHandleNormalBitmap;
1681 __pHandleNormalBitmap = pThumbBitmap;
1683 __handleRect.width = __pHandleNormalBitmap->GetWidth();
1684 __handleRect.height = __pHandleNormalBitmap->GetHeight();
1686 _VisualElement* pHandle = __pSlider->GetHandle();
1687 pHandle->SetBounds(FloatRectangle(__handleRect.x, __handleRect.y, __handleRect.width, __handleRect.height));
1689 __isCustomHandle = true;
1699 _SliderPresenter::SetThumbTextColor(SliderThumbStatus status, const Color& color)
1703 case SLIDER_THUMB_STATUS_PRESSED:
1704 __handleTextPressedColor = color;
1705 __isCustomPressedTextColor = true;
1708 case SLIDER_THUMB_STATUS_DISABLED:
1709 __handleTextDisabledColor = color;
1712 case SLIDER_THUMB_STATUS_HIGHLIGHTED:
1713 __handleTextHighlightedColor = color;
1716 case SLIDER_THUMB_STATUS_NORMAL:
1719 __handleTextColor = color;
1726 }}} // Tizen::Ui::Controls