Fixing JIRA issue N_SE-36442.
authorkishorekumar Dachinamoorthy <kishore.d@samsung.com>
Wed, 3 Jul 2013 09:07:03 +0000 (14:37 +0530)
committerkishorekumar Dachinamoorthy <kishore.d@samsung.com>
Wed, 3 Jul 2013 14:53:05 +0000 (20:23 +0530)
Change-Id: If1f726531feca7ee9d6212589e28225af402121b

src/ui/controls/FUiCtrl_SliderPresenter.cpp
src/ui/inc/FUiCtrl_SliderPresenter.h

index 89c3ead..aceb42e 100644 (file)
@@ -82,10 +82,11 @@ _SliderPresenter::_SliderPresenter(void)
        , __currentBgColor(0)
        , __pFont(null)
        , __pTitleTextObject(null)
-       , __sliderX(0)
        , __handleX(0)
        , __prevSliderValue(0)
+       , __handleOffset(0)
        , __isSliderPressed(false)
+       , __isSetValue(true)
        , __isFocusModeStateChanged(false)
        , __isNeedToBeUpdated(true)
        , __isResourceLoaded(false)
@@ -248,7 +249,6 @@ _SliderPresenter::Resize(void)
        float sliderY = 0.0f;
        float iconWidth = 0.0f;
        float iconSideMargin = 0.0f;
-       float offset = 0.0f;
        float minimumHeight = 0.0f;
        float minimumWidth = 0.0f;
        float iconRightMargin = 0.0f;
@@ -295,7 +295,7 @@ _SliderPresenter::Resize(void)
 
        if (!__isCustomHandle)
        {
-               r = GET_SHAPE_CONFIG(SLIDER::HANDLE_OFFSET, orientation, offset);
+               r = GET_SHAPE_CONFIG(SLIDER::HANDLE_OFFSET, orientation, __handleOffset);
                SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
                r = GET_SHAPE_CONFIG(SLIDER::HANDLE_WIDTH, orientation, __handleRect.width);
@@ -353,13 +353,13 @@ _SliderPresenter::Resize(void)
        {
                titleTextBounds = GetTitleTextBounds();
                sliderY = titleTextBounds.y + titleTextBounds.height;
-               __touchRect = FloatRectangle(barLeftMargin - offset, sliderY + (__rect.height - (sliderY + __handleRect.height)) / 2.0f,
-                                                               __rect.width - (barLeftMargin + barRightMargin) + (2.0f * offset), __handleRect.height);
+               __touchRect = FloatRectangle(barLeftMargin - __handleOffset , sliderY + (__rect.height - (sliderY + __handleRect.height)) / 2.0f,
+                                                               __rect.width - (barLeftMargin + barRightMargin) + (2.0f * __handleOffset) , __handleRect.height);
        }
        else
        {
-               __touchRect = FloatRectangle(barLeftMargin - offset, (__rect.height - __handleRect.height) / 2.0f,
-                                                               (__rect.width - (barLeftMargin + barRightMargin)) + (2.0f * offset), __handleRect.height);
+               __touchRect = FloatRectangle(barLeftMargin - __handleOffset, (__rect.height - __handleRect.height) / 2.0f,
+                                                               (__rect.width - (barLeftMargin + barRightMargin)) + (2.0f * __handleOffset) , __handleRect.height);
        }
 
        if (__pSlider->GetIcon(ICON_POSITION_LEFT) != null)
@@ -373,8 +373,8 @@ _SliderPresenter::Resize(void)
                __touchRect.width = __touchRect.width - (iconWidth + iconSideMargin + iconRightMargin);
        }
 
-       __barBgRect = FloatRectangle(__touchRect.x + offset, __touchRect.y +
-                                                       ((__handleRect.height - barHeight) / 2.0f), __touchRect.width - (2.0f * offset), barHeight);
+       __barBgRect = FloatRectangle(__touchRect.x + __handleOffset, __touchRect.y +
+                                                       ((__handleRect.height - barHeight) / 2.0f), __touchRect.width - (2.0f * __handleOffset), barHeight);
 
        FloatRectangle absBounds = __pSlider->GetAbsoluteBoundsF();
        __pSliderOverlay->SetSliderRect(absBounds, __touchRect);
@@ -691,14 +691,12 @@ _SliderPresenter::CalculateSliderValue(float positionX, float offsetX)
 
        if (positionX <= __touchRect.x + offsetX)
        {
-               __sliderX = 0;
                __handleX = 0;
                return minValue;
        }
 
        if (positionX >= (__touchRect.x + __touchRect.width) - offsetX)
        {
-               __sliderX = __barBgRect.width - __handleRect.width - (2.0f * __barOffset);
                __handleX = __touchRect.width - __handleRect.width;
                return maxValue;
        }
@@ -708,7 +706,6 @@ _SliderPresenter::CalculateSliderValue(float positionX, float offsetX)
                return minValue;
        }
 
-       __sliderX = positionX - (__barBgRect.x + offsetX) - (2.0f * __barOffset);
        __handleX = positionX - (__touchRect.x + offsetX);
 
        __handleRect.x = __touchRect.x + __handleX;
@@ -995,7 +992,6 @@ _SliderPresenter::OnChangeLayout(_ControlOrientation orientation)
 
        if ( __isSliderPressed == true)
        {
-               __sliderX = ((__barBgRect.width - ( __handleRect.width  + (2.0f * __barOffset))) * (__pSliderModel->GetValue() - minValue)) / (maxValue - minValue);
                __handleX = ((__touchRect.width - __handleRect.width) * (__pSliderModel->GetValue() - minValue)) / (maxValue - minValue);
                __pSlider->Invalidate();
        }
@@ -1020,18 +1016,12 @@ _SliderPresenter::DrawSliderBar(Canvas& canvas)
        float bitmapPositionX = 0.0f;
        float bitmapPositionY = 0.0f;
        int opacity = 0;
-       float offset = 0.0f;
        Bitmap* pReplacementBitmap = null;
        Bitmap* pHandleBitmap = null;
        Bitmap* pHandleEffectBitmap = null;
        bool isCustomHandleBitmap = false;
        bool isCustomBarBitmap = false;
 
-       _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
-
-       r = GET_SHAPE_CONFIG(SLIDER::HANDLE_OFFSET, orientation, offset);
-       SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
-
        if (__pSlider->IsEnabled() == false)  // disabled
        {
                pHandleBitmap = __pHandleDisabledBitmap;
@@ -1063,14 +1053,28 @@ _SliderPresenter::DrawSliderBar(Canvas& canvas)
        int minValue = __pSliderModel->GetMinValue();
        int maxValue = __pSliderModel->GetMaxValue();
 
-       __barRect = FloatRectangle(__barBgRect.x + __barOffset, __barBgRect.y, __sliderX, __barBgRect.height);
+       __barRect = FloatRectangle(__barBgRect.x + __barOffset, __barBgRect.y, __handleRect.x , __barBgRect.height);
 
-       if (__isSliderPressed == false && (maxValue - minValue) != 0)
+       if (__isSetValue == true && __isSliderPressed == false && (maxValue - minValue) != 0)
        {
-               __barRect.width = ((__barBgRect.width - ( __handleRect.width  + (2.0f * __barOffset))) * (__pSliderModel->GetValue() - minValue)) / (maxValue - minValue);
                __handleX = ((__touchRect.width - __handleRect.width) * (__pSliderModel->GetValue() - minValue)) / (maxValue - minValue);
        }
 
+       __handleRect.x = __touchRect.x + __handleX;
+       __handleRect.y = __touchRect.y;
+
+       if (__handleRect.x < __touchRect.x )
+       {
+               __handleRect.x = __touchRect.x;
+       }
+
+       if (__handleRect.x + __handleRect.width > __touchRect.x + __touchRect.width )
+       {
+               __handleRect.x = __touchRect.x + __touchRect.width - __handleRect.width;
+       }
+
+       __barRect.width = __handleRect.x - __barRect.x + (__handleRect.width / 2);
+
        if (__pSlider->GetBarBackgroundColor() != __currentBarBgColor)
        {
                pReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pResourceBarBgBitmap, Color::GetColor(COLOR_ID_MAGENTA), __pSlider->GetBarBackgroundColor());
@@ -1121,23 +1125,10 @@ _SliderPresenter::DrawSliderBar(Canvas& canvas)
        }
 
        isCustomBarBitmap = IS_CUSTOM_BITMAP(SLIDER::BAR_NORMAL);
-       DrawBitmap(canvas, FloatRectangle(__barRect.x, __barRect.y, (__barRect.width + __handleRect.width / 2), __barRect.height), __pBarColorReplacementBitmap);
+       DrawBitmap(canvas, __barRect, __pBarColorReplacementBitmap);
        if (isCustomBarBitmap == false)
        {
-               DrawBitmap(canvas, FloatRectangle(__barRect.x, __barRect.y, (__barRect.width + __handleRect.width / 2), __barRect.height), __pBarResourceEffectBitmap);
-       }
-
-       __handleRect.x = __touchRect.x + __handleX;
-       __handleRect.y = __touchRect.y;
-
-       if (__handleRect.x < __touchRect.x )
-       {
-               __handleRect.x = __touchRect.x;
-       }
-
-       if (__handleRect.x + __handleRect.width > __touchRect.x + __touchRect.width )
-       {
-               __handleRect.x = __touchRect.x + __touchRect.width - __handleRect.width;
+               DrawBitmap(canvas, __barRect, __pBarResourceEffectBitmap);
        }
 
        Canvas* pHandleCanvas = __pSlider->GetHandleCanvasN();
@@ -1493,6 +1484,7 @@ _SliderPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touch
        if (__handleRect.Contains(point) == true)
        {
                __isSliderPressed = true;
+               __isSetValue = false;
 
                int candidateValue = CalculateSliderValue(point.x, point.x - __handleRect.x);
                __prevSliderValue = candidateValue;
@@ -1540,6 +1532,7 @@ _SliderPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touc
        {
                PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP, __pSlider);
                __isSliderPressed = false;
+               __isSetValue = false;
 
                int candidateValue = 0;
 
@@ -1761,6 +1754,8 @@ _SliderPresenter::SetValue(int value)
                value = minValue;
        }
 
+       __isSetValue = true;
+
        __pSliderModel->SetValue(value);
 
        return;
@@ -1854,6 +1849,7 @@ _SliderPresenter::SetThumbBitmap(SliderThumbStatus status, const Bitmap& bitmap)
                _VisualElement* pHandle = __pSlider->GetHandle();
                pHandle->SetBounds(FloatRectangle(__handleRect.x, __handleRect.y, __handleRect.width, __handleRect.height));
 
+               __handleOffset = __handleRect.width / 2;
                __isCustomHandle = true;
                break;
 
index bc9c55d..01ad006 100644 (file)
@@ -157,10 +157,11 @@ private:
        Tizen::Graphics::Font* __pFont;
        Tizen::Graphics::_Text::TextObject* __pTitleTextObject;
 
-       int __sliderX;
        int __handleX;
        int __prevSliderValue;
+       int __handleOffset;
        bool __isSliderPressed;
+       bool __isSetValue;
        bool __isFocusModeStateChanged;
 
        bool __isNeedToBeUpdated;