[Fix for TDIS-6108]Rolling Animation bounds crossing actual bounds fo month
authorBhavya Kumili <bhavya.k@samsung.com>
Tue, 18 Jun 2013 10:25:37 +0000 (15:55 +0530)
committerBhavya Kumili <bhavya.k@samsung.com>
Fri, 21 Jun 2013 13:55:39 +0000 (19:25 +0530)
Change-Id: I1dbb540454a49c789e0a466d49bc7ba1829ffa5e

src/ui/controls/FUiCtrl_EditDatePresenter.cpp

index fad470f..bd40ac4 100644 (file)
@@ -745,7 +745,10 @@ _EditDatePresenter::DrawText(Canvas& canvas, const FloatRectangle& bounds, const
        DrawContentBitmap(canvas, bounds, boxId);
 
        FloatRectangle drawAreaBounds(0.0f, 0.0f, 0.0f, 0.0f);
-       drawAreaBounds = bounds;
+       drawAreaBounds.x = bounds.x + 2.0f;
+       drawAreaBounds.y = bounds.y + 2.0f;
+       drawAreaBounds.width = bounds.width - 4.0f;
+       drawAreaBounds.height = bounds.height - 4.0f;
 
        TextSimple* pSimpleText = null;
        pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(text.GetPointer())), text.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
@@ -1312,14 +1315,14 @@ _EditDatePresenter::Animate(void)
        SysTryReturnVoidResult(NID_UI_CTRL, !__isAnimating, E_SUCCESS, "Rolling animation is in progress.");
        SysAssertf((__pFont != null), "Font instance must not be null.");
 
-       (_FontImpl::GetInstance(*__pFont))->SetSize(__dateFontSize);
-
        result r = E_SUCCESS;
        FloatRectangle rect;
        String monthString;
        String yearString;
        String dayString;
        String newValue;
+       TextSimple* pOldSimpleText = null;
+       TextSimple* pNewSimpleText = null;
 
        _DateTimeUtils dateTimeUtils;
        monthString = dateTimeUtils.GetMonthString(GetMonth());
@@ -1365,9 +1368,6 @@ _EditDatePresenter::Animate(void)
 
        __pFont->GetTextExtent(newValue, newValue.GetLength(), newTextDim);
        __pFont->GetTextExtent(__lastSelectedValue, __lastSelectedValue.GetLength(), oldTextDim);
-       newTextDim.width += 2.0f;
-       oldTextDim.width += 2.0f;
-
 
        if (newTextDim.width > oldTextDim.width)
        {
@@ -1378,7 +1378,7 @@ _EditDatePresenter::Animate(void)
                textPoint.x = (rect.width - oldTextDim.width) / 2.0f;
        }
 
-       SysTryReturnVoidResult(NID_UI_CTRL, (rect.x + textPoint.x < __pEditDate->GetBoundsF().width), E_SUCCESS, "Rolling animation cann't be played.");
+       SysTryReturnVoidResult(NID_UI_CTRL, (rect.x + textPoint.x < __pEditDate->GetBoundsF().width), E_SUCCESS, "Rolling animation can't be played.");
 
        __isAnimating = true;
 
@@ -1428,46 +1428,39 @@ _EditDatePresenter::Animate(void)
        pNewVisualElement->SetShowState(true);
        pOldVisualElement->SetShowState(true);
 
-       if (newTextDim.width > oldTextDim.width)
-       {
-               textPoint.x = (rect.width - newTextDim.width) / 2.0f;
-               textPoint.y = (rect.height - newTextDim.height) / 2.0f;
-               __pContentProvider->SetBounds(FloatRectangle((rect.x + textPoint.x) * 1.0f, (rect.y + textPoint.y) * 1.0f, newTextDim.width * 1.0f, newTextDim.height * 1.0f));
-               pNewVisualElement->SetBounds(FloatRectangle(0.0f, newTextDim.height * 1.0f, newTextDim.width * 1.0f, newTextDim.height * 1.0f));
-
-               rect.width = __pContentProvider->GetBounds().width;
-               rect.height = __pContentProvider->GetBounds().height;
-
-               textPoint.x = (rect.width - oldTextDim.width) / 2.0f;
-               textPoint.y = (rect.height - oldTextDim.height) / 2.0f;
-
-               rect.x = __pContentProvider->GetBounds().x - 2.0f;
-               rect.y = __pContentProvider->GetBounds().y;
-               rect.width = __pContentProvider->GetBounds().width + 4.0f;
+       __pContentProvider->SetBounds(FloatRectangle((rect.x + 2.0f), (rect.y + 2.0f), (rect.width - 4.0f), (rect.height - 4.0f)));
+       textPoint.x = (__pContentProvider->GetBounds().width - newTextDim.width) / 2.0f;
+       textPoint.y = (__pContentProvider->GetBounds().height - newTextDim.height) / 2.0f;
 
-               pOldVisualElement->SetBounds(FloatRectangle(textPoint.x * 1.0f, 0.0f, oldTextDim.width * 1.0f, oldTextDim.height * 1.0f));
-       }
-       else
+       if (textPoint.x < 0)
        {
-               textPoint.x = (rect.width - oldTextDim.width) / 2.0f;
-               textPoint.y = (rect.height - oldTextDim.height) / 2.0f;
-               __pContentProvider->SetBounds(FloatRectangle((rect.x + textPoint.x) * 1.0f, (rect.y + textPoint.y) * 1.0f, oldTextDim.width * 1.0f, oldTextDim.height * 1.0f));
-               pOldVisualElement->SetBounds(FloatRectangle(0.0f, 0.0f, oldTextDim.width * 1.0f, oldTextDim.height * 1.0f));
+               textPoint.x = 0.0f;
+               newTextDim.width = __pContentProvider->GetBounds().width;
+       }
 
-               rect.width = __pContentProvider->GetBounds().width;
-               rect.height = __pContentProvider->GetBounds().height;
+       if (textPoint.y < 0)
+       {
+               textPoint.y = 0.0f;
+       }
 
-               textPoint.x = (rect.width - newTextDim.width) / 2.0f;
-               textPoint.y = (rect.height - newTextDim.height) / 2.0f;
+       pNewVisualElement->SetBounds(FloatRectangle(textPoint.x, oldTextDim.height, newTextDim.width, newTextDim.height));
+       textPoint.x = (__pContentProvider->GetBounds().width - oldTextDim.width) / 2.0f;
+       textPoint.y = (__pContentProvider->GetBounds().height - oldTextDim.height) / 2.0f;
 
-               rect.x = __pContentProvider->GetBounds().x - 2.0f;
-               rect.y = __pContentProvider->GetBounds().y;
-               rect.width = __pContentProvider->GetBounds().width + 4.0f;
+       if (textPoint.x < 0)
+       {
+               textPoint.x = 0.0f;
+               oldTextDim.width = __pContentProvider->GetBounds().width;
+       }
 
-               pNewVisualElement->SetBounds(FloatRectangle(textPoint.x * 1.0f, newTextDim.height * 1.0f, newTextDim.width * 1.0f, newTextDim.height * 1.0f));
+       if (textPoint.y < 0)
+       {
+               textPoint.y = 0.0f;
        }
 
-       pCanvas = pEditDateElement->GetCanvasN(rect);
+       pOldVisualElement->SetBounds(FloatRectangle(textPoint.x, textPoint.y, oldTextDim.width, oldTextDim.height));
+
+       pCanvas = pEditDateElement->GetCanvasN(__pContentProvider->GetBounds());
        pCanvas->SetBackgroundColor(contentBgColor);
        pCanvas->Clear();
        delete pCanvas;
@@ -1483,7 +1476,7 @@ _EditDatePresenter::Animate(void)
 
        pNewBoundsAnimation->SetDuration(300);
        pNewBoundsAnimation->SetPropertyName("bounds.position");
-       pNewBoundsAnimation->SetStartValue(Variant(FloatPoint(pNewVisualElement->GetBounds().x * 1.0f, newTextDim.height * 1.0f)));
+       pNewBoundsAnimation->SetStartValue(Variant(FloatPoint(pNewVisualElement->GetBounds().x * 1.0f, oldTextDim.height * 1.0f)));
        pNewBoundsAnimation->SetEndValue(Variant(FloatPoint(pNewVisualElement->GetBounds().x * 1.0f, 0.0f)));
        pNewBoundsAnimation->SetVisualElementAnimationStatusEventListener(this);
 
@@ -1496,6 +1489,9 @@ _EditDatePresenter::Animate(void)
        pOldBoundsAnimation->SetEndValue(Variant(FloatPoint(pOldVisualElement->GetBounds().x * 1.0f, oldTextDim.height * -1.0f)));
        pOldBoundsAnimation->SetVisualElementAnimationStatusEventListener(this);
 
+       pOldSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(__lastSelectedValue.GetPointer())), __lastSelectedValue.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
+       SysTryCatch(NID_UI_CTRL, (pOldSimpleText != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
+
        pCanvas = pOldVisualElement->GetCanvasN();
        r = GetLastResult();
        SysTryCatch(NID_UI_CTRL, (pCanvas != null), , r, "[%s] Propagating.", GetErrorMessage(r));
@@ -1503,13 +1499,23 @@ _EditDatePresenter::Animate(void)
        pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
        pCanvas->Clear();
        pCanvas->SetForegroundColor(textPressedColor);
-       (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_BOLD);
-       pCanvas->SetFont(*__pFont);
-       pCanvas->DrawText(FloatPoint(0.0f, 0.0f), __lastSelectedValue);
+
+       (_FontImpl::GetInstance(*__pFont))->SetSize(__dateFontSize);
+       (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_PLAIN);
+       __textObject.RemoveAll();
+       __textObject.AppendElement(*pOldSimpleText);
+
+       __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
+       __textObject.SetForegroundColor(textPressedColor, 0, __textObject.GetTextLength());
+       __textObject.SetBounds(pCanvas->GetBounds());
+       __textObject.Draw(*_CanvasImpl::GetInstance(*pCanvas));
 
        delete pCanvas;
        pCanvas = null;
 
+       pNewSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(newValue.GetPointer())), newValue.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
+       SysTryCatch(NID_UI_CTRL, (pNewSimpleText != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
+
        pCanvas = pNewVisualElement->GetCanvasN();
        r = GetLastResult();
        SysTryCatch(NID_UI_CTRL, (pCanvas != null), , r, "[%s] Propagating.", GetErrorMessage(r));
@@ -1517,9 +1523,16 @@ _EditDatePresenter::Animate(void)
        pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
        pCanvas->Clear();
        pCanvas->SetForegroundColor(textPressedColor);
-       (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_BOLD);
-       pCanvas->SetFont(*__pFont);
-       pCanvas->DrawText(FloatPoint(0.0f, 0.0f), newValue);
+
+       (_FontImpl::GetInstance(*__pFont))->SetSize(__dateFontSize);
+       (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_PLAIN);
+       __textObject.RemoveAll();
+       __textObject.AppendElement(*pNewSimpleText);
+
+       __textObject.SetFont(__pFont, 0, __textObject.GetTextLength());
+       __textObject.SetForegroundColor(textPressedColor, 0, __textObject.GetTextLength());
+       __textObject.SetBounds(pCanvas->GetBounds());
+       __textObject.Draw(*_CanvasImpl::GetInstance(*pCanvas));
 
        delete pCanvas;
        pCanvas = null;
@@ -1535,7 +1548,7 @@ _EditDatePresenter::Animate(void)
 
        return;
 
-       CATCH:
+CATCH:
        __isAnimating = false;
        __pContentProvider->Destroy();
        __pContentProvider = null;
@@ -1549,6 +1562,12 @@ _EditDatePresenter::Animate(void)
        delete pCanvas;
        pCanvas = null;
 
+       delete pOldSimpleText;
+       pOldSimpleText = null;
+
+       delete pNewSimpleText;
+       pNewSimpleText = null;
+
        return;
 }