FloatingPoint changes for GroupContainer
authorPrakalathan Ponnusamy <prakalath.p@samsung.com>
Fri, 22 Mar 2013 13:34:27 +0000 (19:04 +0530)
committerPrakalathan Ponnusamy <prakalath.p@samsung.com>
Wed, 27 Mar 2013 10:30:02 +0000 (16:00 +0530)
Change-Id: Ie40265b2da048b0bc463dd36f55b9bef695ff1e4

src/ui/controls/FUiCtrl_GroupContainer.cpp
src/ui/controls/FUiCtrl_GroupContainerPresenter.cpp
src/ui/inc/FUiCtrl_GroupContainer.h
src/ui/resource/FUi_ResourceGroupContainerConfig.cpp

index 9c5f499..5b1dc1e 100644 (file)
 #include "FUi_ControlManager.h"
 #include "FUi_ResourceManager.h"
 #include "FUiCtrl_Label.h"
-#include "FUi_CoordinateSystemUtils.h"
 
 using namespace Tizen::Graphics;
 using namespace Tizen::Ui;
 using namespace Tizen::Base;
 using namespace Tizen::Ui::Animations;
+using namespace Tizen::Base::Utility;
 
 class GroupedContentContentProvider : public IVisualElementContentProvider
 {
@@ -132,12 +132,9 @@ _GroupContainer::Initialize(const FloatRectangle& rect, int rowCount, int column
 
        float balanceWidthPixels = fmod((rect.width - totalColLineWidth), columnCount);
        float balanceHeightPixels = fmod((rect.height - totalRowLineHeight), rowCount);
-       int additionalWidth = -1;
-       int additionalHeight = -1;
        int margin = 0;
-
-       int width = _CoordinateSystemUtils::ConvertToInteger(balanceWidthPixels);
-       int height = _CoordinateSystemUtils::ConvertToInteger(balanceHeightPixels);
+       int width = Math::Round((balanceWidthPixels + ROUNDOFF_VALUE) * 10.0f);
+       int height = Math::Round((balanceHeightPixels + ROUNDOFF_VALUE) * 10.0f);
 
        _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
        r = GET_FIXED_VALUE_CONFIG(GROUPCONTAINER::DEFAULT_MARGIN, orientation, margin);
@@ -173,13 +170,49 @@ _GroupContainer::Initialize(const FloatRectangle& rect, int rowCount, int column
                SysTryCatch(NID_UI_CTRL, __pCellsArray[i] != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
        }
 
+       for (int rowIndex = 0; rowIndex < rowCount; rowIndex++)
+       {
+               for (int columnIndex = 0; columnIndex < columnCount; columnIndex++)
+               {
+                       __pCellsArray[rowIndex][columnIndex].cellBounds.width = 0;
+                       __pCellsArray[rowIndex][columnIndex].cellBounds.height = 0;
+               }
+       }
+
+       while (width > 0)
+       {
+               for (int columnIndex = 0; columnIndex < columnCount; columnIndex++)
+               {
+                       if (width > 0)
+                       {
+                               for (int rowIndex = 0; rowIndex < rowCount; rowIndex++)
+                               {
+                                       __pCellsArray[rowIndex][columnIndex].cellBounds.width += 0.1f;
+                               }
+                               width = width - 1;
+                       }
+               }
+       }
+
+       while (height > 0)
+       {
+               for (int rowIndex = 0; rowIndex < rowCount; rowIndex++)
+               {
+                       if (height > 0)
+                       {
+                               for (int columnIndex = 0; columnIndex < columnCount; columnIndex++)
+                               {
+                                       __pCellsArray[rowIndex][columnIndex].cellBounds.height += 0.1f;
+                               }
+                               height = height - 1;
+                       }
+               }
+       }
+
        for (int row = 0; row < rowCount; row++)
        {
                for (int col = 0; col < columnCount; col++)
                {
-                       additionalWidth = (col < width) ? 1 : 0;
-                       additionalHeight = (row < height) ? 1 : 0;
-
                        if (col == 0)
                        {
                                __pCellsArray[row][col].cellBounds.x = __lineWidth;
@@ -198,8 +231,8 @@ _GroupContainer::Initialize(const FloatRectangle& rect, int rowCount, int column
                                __pCellsArray[row][col].cellBounds.y = (__pCellsArray[row - 1][col].cellBounds.y + __pCellsArray[row - 1][col].cellBounds.height) + __lineWidth;
                        }
 
-                       __pCellsArray[row][col].cellBounds.width = cellWidth + additionalWidth;
-                       __pCellsArray[row][col].cellBounds.height = cellHeight + additionalHeight;
+                       __pCellsArray[row][col].cellBounds.width += cellWidth;
+                       __pCellsArray[row][col].cellBounds.height += cellHeight;
 
                        __pCellsArray[row][col].actualSize.width = __pCellsArray[row][col].cellBounds.width;
                        __pCellsArray[row][col].actualSize.height = __pCellsArray[row][col].cellBounds.height;
@@ -273,6 +306,8 @@ void
 _GroupContainer::SetImpl(_GroupContainerImpl *pImpl)
 {
        __pGroupContainerImpl = pImpl;
+
+       return;
 }
 
 result
@@ -759,6 +794,8 @@ void
 _GroupContainer::SetLineColor(const Color& color)
 {
        __lineColor = color;
+
+       return;
 }
 
 Color
@@ -767,7 +804,7 @@ _GroupContainer::GetLineColor(void)
        return __lineColor;
 }
 
-int
+float
 _GroupContainer::GetLineWidth(void)
 {
        return __lineWidth;
@@ -888,6 +925,8 @@ _GroupContainer::CollapseCell(int rowIndex, int columnIndex, int rowStartIndex,
        __pCellsArray[rowIndex][columnIndex].isMerged = true;
        __pCellsArray[rowIndex][columnIndex].parentCell.row = rowStartIndex;
        __pCellsArray[rowIndex][columnIndex].parentCell.column = columnStartIndex;
+
+       return;
 }
 
 bool
@@ -972,6 +1011,8 @@ _GroupContainer::OnDraw(void)
        {
                __pGroupContainerPresenter->Draw();
        }
+
+       return;
 }
 
 result
@@ -992,6 +1033,8 @@ _GroupContainer::OnChildAttached(const _Control& child)
        }
        __childAttachedRowIndex = -1;
        __childAttachedColumnIndex = -1;
+
+       return;
 }
 
 void
@@ -1032,6 +1075,8 @@ _GroupContainer::OnChildBoundsChanged(const _Control& child)
                __pCellsArray[parentIndex.row][parentIndex.column].childControlPos = childNewPosition;
                (const_cast<_Control&>(child)).SetPosition(childNewPosition);
        }
+
+       return;
 }
 
 result
@@ -1053,6 +1098,8 @@ void
 _GroupContainer::OnBoundsChanged(void)
 {
        __pSystemControl->SetBounds(FloatRectangle(0.0f, 0.0f, GetBoundsF().width, GetBoundsF().height), false);
+
+       return;
 }
 
 void
@@ -1060,15 +1107,19 @@ _GroupContainer::UpdateStretchableCellBounds(FloatRectangle gridRect, FloatRecta
 {
        int stretchableRowCount = 0;
        int stretchableColumnCount = 0;
-       float stretchableWidth = 0.0f;
-       float stretchableHeight = 0.0f;
+       int stretchableWidth = 0;
+       int stretchableHeight = 0;
        float balanceWidthPixels  = 0.0f;
        float balanceHeightPixels = 0.0f;
        int width = 0;
        int height = 0;
+       float columnWidth[__columnCount];
+       float rowHeight[__rowCount];
 
        for (int columnIndex = 0; columnIndex < __columnCount; columnIndex++)
        {
+               columnWidth[columnIndex] = 0.0f;
+
                if (__pStretchableColumnIndex[columnIndex])
                {
                        stretchableColumnCount++;
@@ -1080,38 +1131,57 @@ _GroupContainer::UpdateStretchableCellBounds(FloatRectangle gridRect, FloatRecta
                stretchableWidth = (controlRect.width - gridRect.width) / stretchableColumnCount;
                balanceWidthPixels = fmod((controlRect.width - gridRect.width), stretchableColumnCount);
 
-               width = _CoordinateSystemUtils::ConvertToInteger(balanceWidthPixels);
+               if (balanceWidthPixels > 0)
+               {
+                       width = Math::Round((balanceWidthPixels + ROUNDOFF_VALUE) * 10.0);
+               }
+               else if (balanceWidthPixels < 0)
+               {
+                       width = Math::Round((balanceWidthPixels - ROUNDOFF_VALUE) * 10.0);
+               }
 
-               for (int columnIndex = 0; columnIndex < __columnCount; columnIndex++)
+               while (width != 0)
                {
-                       if (__pStretchableColumnIndex[columnIndex] == true)
+                       for (int columnIndex = 0; columnIndex < __columnCount; columnIndex++)
                        {
-                               FloatDimension rect = __pCellsArray[0][columnIndex].actualSize;
-                               rect.width = rect.width + stretchableWidth;
-
-                               if (width > 0)
-                               {
-                                       rect.width = rect.width + 1;
-                                       width--;
-                               }
-                               else if (width < 0)
+                               if (__pStretchableColumnIndex[columnIndex] == true)
                                {
-                                       rect.width = rect.width - 1;
-                                       width++;
+                                       if (width > 0)
+                                       {
+                                               columnWidth[columnIndex] = columnWidth[columnIndex] + 0.1f;
+
+                                               width = width - 1;
+                                       }
+                                       else if (width < 0)
+                                       {
+                                               columnWidth[columnIndex] = columnWidth[columnIndex] - 0.1f;
+
+                                               width = width + 1;
+                                       }
                                }
+                       }
+               }
 
-                               if (rect.width < 0)
+               for (int columnIndex = 0; columnIndex < __columnCount; columnIndex++)
+               {
+                       if (__pStretchableColumnIndex[columnIndex] == true)
+                       {
+                               columnWidth[columnIndex] = columnWidth[columnIndex] + __pCellsArray[0][columnIndex].actualSize.width + stretchableWidth;
+
+                               if (columnWidth[columnIndex] < 0)
                                {
-                                       rect.width = 0;
+                                       columnWidth[columnIndex] = 0;
                                }
 
-                               SetColumnWidth(columnIndex, rect.width);
+                               SetColumnWidth(columnIndex, columnWidth[columnIndex]);
                        }
                }
        }
 
        for (int rowIndex = 0; rowIndex < __rowCount; rowIndex++)
        {
+               rowHeight[rowIndex] = 0.0f;
+
                if (__pStretchableRowIndex[rowIndex])
                {
                        stretchableRowCount++;
@@ -1122,35 +1192,55 @@ _GroupContainer::UpdateStretchableCellBounds(FloatRectangle gridRect, FloatRecta
        {
                stretchableHeight = (controlRect.height - gridRect.height) / stretchableRowCount;
                balanceHeightPixels = fmod((controlRect.height - gridRect.height), stretchableRowCount);
-               height = _CoordinateSystemUtils::ConvertToInteger(balanceHeightPixels);
 
-               for (int rowIndex = 0; rowIndex < __rowCount; rowIndex++)
+               if ( balanceHeightPixels > 0)
                {
-                       if (__pStretchableRowIndex[rowIndex] == true)
-                       {
-                               FloatDimension rect = __pCellsArray[rowIndex][0].actualSize;
-                               rect.height = rect.height + stretchableHeight;
+                       height = Math::Round((balanceHeightPixels + ROUNDOFF_VALUE) * 10.0);
+               }
+               else if (balanceHeightPixels < 0)
+               {
+                       height = Math::Round((balanceHeightPixels - ROUNDOFF_VALUE) * 10.0);
+               }
 
-                               if (height > 0)
-                               {
-                                       rect.height = rect.height + 1;
-                                       height--;
-                               }
-                               else if (height < 0)
+               while (height != 0)
+               {
+                       for (int rowIndex = 0; rowIndex < __rowCount; rowIndex++)
+                       {
+                               if (__pStretchableRowIndex[rowIndex] == true)
                                {
-                                       rect.height = rect.height - 1;
-                                       height++;
+                                       if (height > 0)
+                                       {
+                                               rowHeight[rowIndex] = rowHeight[rowIndex] + 0.1f;
+
+                                               height = height - 1;
+                                       }
+                                       else if (height < 0)
+                                       {
+                                               rowHeight[rowIndex] = rowHeight[rowIndex] - 0.1f;
+
+                                               height = height + 1;
+                                       }
                                }
+                       }
+               }
+
+               for (int rowIndex = 0; rowIndex < __rowCount; rowIndex++)
+               {
+                       if (__pStretchableRowIndex[rowIndex] == true)
+                       {
+                               rowHeight[rowIndex] = rowHeight[rowIndex] + __pCellsArray[rowIndex][0].actualSize.height + stretchableHeight;
 
-                               if (rect.height < 0)
+                               if (rowHeight[rowIndex] < 0)
                                {
-                                       rect.height = 0;
+                                       rowHeight[rowIndex] = 0;
                                }
 
-                               SetRowHeight(rowIndex, rect.height);
+                               SetRowHeight(rowIndex, rowHeight[rowIndex]);
                        }
                }
        }
+
+       return;
 }
 
 FloatRectangle
index 713a3a0..49b0e88 100755 (executable)
 #include <FBaseSysLog.h>
 #include <FBaseErrorDefine.h>
 #include <FGrpCanvas.h>
+#include <FGrp_BitmapImpl.h>
 #include "FUiCtrl_GroupContainerPresenter.h"
 #include "FUi_ResourceManager.h"
-#include <FGrp_BitmapImpl.h>
 #include "FUiAnim_VisualElement.h"
+#include "FUi_CoordinateSystemUtils.h"
 
 using namespace Tizen::Graphics;
 using namespace Tizen::Ui::Animations;
@@ -96,12 +97,13 @@ _GroupContainerPresenter::Draw(void)
        result r = E_SUCCESS;
        FloatRectangle gridBounds(0.0f, 0.0f, 0.0f, 0.0f);
        FloatRectangle rect(0.0f, 0.0f, 0.0f, 0.0f);
+       int width = 0;
        int lineAdjustPosition = 0;
        int rowIndex = 0;
        int columnIndex = 0;
        int rows = __pGroupContainer->GetRowCount();
        int columns = __pGroupContainer->GetColumnCount();
-       int lineWidth = __pGroupContainer->GetLineWidth();
+       float lineWidth = __pGroupContainer->GetLineWidth();
 
        Canvas* pCanvas = __pGroupContainer->GetVisualElement()->GetCanvasN();
        _Control* pControl = __pGroupContainer->GetSystemChild();
@@ -110,6 +112,10 @@ _GroupContainerPresenter::Draw(void)
 
        pCanvas->SetBackgroundColor(__pGroupContainer->GetBackgroundColor());
        pCanvas->Clear();
+
+       pControlCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
+       pControlCanvas->Clear();
+
        pCanvas->SetLineStyle(LINE_STYLE_SOLID);
        pCanvas->SetLineWidth(lineWidth);
        r = GetLastResult();
@@ -133,7 +139,9 @@ _GroupContainerPresenter::Draw(void)
                pCanvas->DrawLine(FloatPoint(gridBounds.x, gridBounds.y + gridBounds.height), FloatPoint(gridBounds.x + gridBounds.width, gridBounds.y + gridBounds.height));
        }
 
-       lineAdjustPosition = ((lineWidth % 2) == 0) ? (lineWidth / 2) : ((lineWidth - 1) / 2);
+       width = _CoordinateSystemUtils::ConvertToInteger(lineWidth);
+       lineAdjustPosition = ((width % 2) == 0) ? (width / 2) : ((width - 1) / 2);
+
        for (rowIndex = 0; rowIndex < rows; rowIndex++)
        {
                for (columnIndex = 0; columnIndex < columns; columnIndex++)
@@ -194,6 +202,7 @@ _GroupContainerPresenter::DrawBackgroundBitmapForSystemChild(Canvas* pCanvas)
                }
        }
 
+       return;
 }
 
 void
@@ -218,8 +227,9 @@ _GroupContainerPresenter::DrawBackgroundEffectBitmapForSystemChild(Canvas* pCanv
                        SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
                }
        }
-}
 
+       return;
+}
 
 }}} // Tizen::Ui::Controls
 
index beef360..3712c0a 100644 (file)
@@ -71,7 +71,7 @@ public:
        bool IsMerged(int rowIndex, int columnIndex);
        bool IsParent(int rowIndex, int columnIndex);
        result ResizeControl(int rowIndex, int columnIndex);
-       int GetLineWidth(void);
+       float GetLineWidth(void);
        void UpdateStretchableCellBounds(Tizen::Graphics::FloatRectangle gridRect, Tizen::Graphics::FloatRectangle controlRect);
        Tizen::Graphics::FloatRectangle GetGridBounds(void);
        Tizen::Ui::_Control* GetSystemChild(void);
@@ -102,6 +102,8 @@ private:
 
 private:
 
+       static const float ROUNDOFF_VALUE = 0.00001f;
+
        struct _CellMargin
        {
                float left;
index d9686eb..e96ae8a 100644 (file)
@@ -27,7 +27,7 @@ START_UI_CONFIG(GROUPCONTAINER);
        ADD_COLOR_CONFIG(NORMAL_BG, $B0217);
        ADD_COLOR_CONFIG(LINE_COLOR_FG, $F032L1);
        ADD_IMAGE_CONFIG(BORDER_BG_EFFECT,  #00_list_group_bg_ef.#.png);
-       ADD_IMAGE_CONFIG(SYSTEM_CONTROL_BG, #00_system_control_bg.#.png);
+       ADD_IMAGE_CONFIG(SYSTEM_CONTROL_BG, #00_list_group_press_bg.#.png);
 
        START_UI_CONFIG_MODE(720x1280);
                ADD_FIXED_VALUE_CONFIG(DEFAULT_MARGIN, 2);