From 8a8af692c2b70d8ce59ad3ed4b4bcbd6be3ee5e2 Mon Sep 17 00:00:00 2001 From: clone Date: Fri, 19 Apr 2013 00:51:53 +0900 Subject: [PATCH] Changed to use nine patch image for pressed item. Change-Id: I4ff7e88da442a81c8dfcf83b3550f11c5ba0b877 Signed-off-by: clone --- .../controls/FUiCtrl_ContextMenuGridPresenter.cpp | 89 +++++++++++++++++++--- src/ui/controls/FUiCtrl_ContextMenuItem.cpp | 12 +++ src/ui/inc/FUiCtrl_ContextMenuGridPresenter.h | 1 + src/ui/inc/FUiCtrl_ContextMenuItem.h | 4 + 4 files changed, 95 insertions(+), 11 deletions(-) diff --git a/src/ui/controls/FUiCtrl_ContextMenuGridPresenter.cpp b/src/ui/controls/FUiCtrl_ContextMenuGridPresenter.cpp index 4b8700e..c779fcb 100644 --- a/src/ui/controls/FUiCtrl_ContextMenuGridPresenter.cpp +++ b/src/ui/controls/FUiCtrl_ContextMenuGridPresenter.cpp @@ -81,6 +81,7 @@ _ContextMenuGridPresenter::_ContextMenuGridPresenter(_ContextMenu* pContextMenu) , __itemBitmapHeight(0.0f) , __itemFontSize(0.0f) , __dividerHeight(0.0f) + , __bgPressedMargin(0.0f) { } @@ -172,6 +173,7 @@ _ContextMenuGridPresenter::LoadShape(void) GET_SHAPE_CONFIG(CONTEXTMENU::GRID_ICON_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, __itemBitmapWidth); GET_SHAPE_CONFIG(CONTEXTMENU::GRID_ICON_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, __itemBitmapHeight); GET_SHAPE_CONFIG(CONTEXTMENU::GRID_DIVIDER_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, __dividerHeight); + GET_SHAPE_CONFIG(CONTEXTMENU::ITEM_BG_PRESSED_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __bgPressedMargin); } _ContextMenuItem* @@ -819,6 +821,17 @@ _ContextMenuGridPresenter::AdjustItemLayoutIconStyle(void) for (int line = 0; line < lineCount; line++) { + float pressedTopMargin = 0.0f, pressedBottomMargin = 0.0f; + if (line == 0) + { + pressedTopMargin = __bgPressedMargin; + } + + if (line == lineCount - 1) + { + pressedBottomMargin = __bgPressedMargin; + } + for (int i = 0; i < countPerLine; i++) { int index = (line * countPerLine) + i; @@ -840,13 +853,31 @@ _ContextMenuGridPresenter::AdjustItemLayoutIconStyle(void) drawRect.y = (line * itemHeight); bool drawDivider = true; - if (i == countPerLine -1) + if (i == countPerLine - 1) { drawDivider = false; } pItem->SetDrawRect(drawRect); pItem->SetLowerDivider(drawDivider); + + float pressedLeftMargin = 0.0f, pressedRightMargin = 0.0f; + if (i == 0) + { + pressedLeftMargin = __bgPressedMargin; + } + + if (i == countPerLine - 1) + { + pressedRightMargin = __bgPressedMargin; + } + + FloatRectangle pressedDrawRect = drawRect; + pressedDrawRect.x += pressedLeftMargin; + pressedDrawRect.y += pressedTopMargin; + pressedDrawRect.width -= pressedLeftMargin + pressedRightMargin; + pressedDrawRect.height -= pressedTopMargin + pressedBottomMargin; + pItem->SetPressedDrawRect(pressedDrawRect); } } @@ -959,16 +990,21 @@ _ContextMenuGridPresenter::AdjustItemLayoutTabStyle(void) int itemIndex = 0; for (int line = 0; line < lineCount; line++) { - int width = lineWidthList[line]; + FloatRectangle drawRect; + float width = lineWidthList[line]; int count = lineItemCountList[line]; + float margin = (maxWidth - width) / count; - if (maxWidth == width) + float pressedTopMargin = 0.0f, pressedBottomMargin = 0.0f; + if (line == 0) { - itemIndex += count; - continue; + pressedTopMargin = __bgPressedMargin; } - int margin = (maxWidth - width) / count; + if (line == lineCount - 1) + { + pressedBottomMargin = __bgPressedMargin; + } for (int i = 0; i < count; i++) { @@ -979,12 +1015,30 @@ _ContextMenuGridPresenter::AdjustItemLayoutTabStyle(void) break; } - FloatRectangle drawRect = pItem->GetDrawRect(); + drawRect = pItem->GetDrawRect(); drawRect.width = drawRect.width + margin; drawRect.x = drawRect.x + (i * margin); pItem->SetDrawRect(drawRect); + + float pressedLeftMargin = 0.0f, pressedRightMargin = 0.0f; + if (i == 0) + { + pressedLeftMargin = __bgPressedMargin; + } + + if (i == count - 1) + { + pressedRightMargin = __bgPressedMargin; + } + + FloatRectangle pressedDrawRect = drawRect; + pressedDrawRect.x += pressedLeftMargin; + pressedDrawRect.y += pressedTopMargin; + pressedDrawRect.width -= pressedLeftMargin + pressedRightMargin; + pressedDrawRect.height -= pressedTopMargin + pressedBottomMargin; + pItem->SetPressedDrawRect(pressedDrawRect); } itemIndex += count; @@ -1018,11 +1072,14 @@ _ContextMenuGridPresenter::AdjustItemPosition(void) } FloatRectangle drawRect = pItem->GetDrawRect(); - drawRect.x += x; drawRect.y += y; - pItem->SetDrawRect(drawRect); + + FloatRectangle pressedDrawRect = pItem->GetPressedDrawRect(); + pressedDrawRect.x += x; + pressedDrawRect.y += y; + pItem->SetPressedDrawRect(pressedDrawRect); } } @@ -1249,9 +1306,14 @@ _ContextMenuGridPresenter::DrawItem(Tizen::Graphics::Canvas* pCanvas) if (__selectedIndex == i) { + FloatRectangle pressedDrawRect = pItem->GetPressedDrawRect(); itemStatus = CONTEXT_MENU_CORE_ITEM_STATUS_PRESSED; + Bitmap* bgBitmap = _BitmapImpl::GetColorReplacedBitmapN(*(pItem->GetMagentaBgBitmap()), Color::GetColor(COLOR_ID_MAGENTA), pressedColor); + SysTryReturn(NID_UI_CTRL, bgBitmap, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); - pCanvas->FillRoundRectangle(pressedColor, rect, FloatDimension(3.0f, 3.0f)); + DrawBitmap(*pCanvas, pressedDrawRect, *bgBitmap); + delete bgBitmap; + bgBitmap = null; } String text = pItem->GetText(); @@ -1280,9 +1342,14 @@ _ContextMenuGridPresenter::DrawItem(Tizen::Graphics::Canvas* pCanvas) if (__selectedIndex == i) { + FloatRectangle pressedDrawRect = pItem->GetPressedDrawRect(); itemStatus = CONTEXT_MENU_ITEM_DRAWING_STATUS_PRESSED; + Bitmap* bgBitmap = _BitmapImpl::GetColorReplacedBitmapN(*(pItem->GetMagentaBgBitmap()), Color::GetColor(COLOR_ID_MAGENTA), pressedColor); + SysTryReturn(NID_UI_CTRL, bgBitmap, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); - pCanvas->FillRoundRectangle(pressedColor, rect, FloatDimension(3.0f, 3.0f)); + DrawBitmap(*pCanvas, pressedDrawRect, *bgBitmap); + delete bgBitmap; + bgBitmap = null; } const Bitmap* pBitmap = pItem->GetBitmap(itemStatus); diff --git a/src/ui/controls/FUiCtrl_ContextMenuItem.cpp b/src/ui/controls/FUiCtrl_ContextMenuItem.cpp index 64b022a..91ef524 100644 --- a/src/ui/controls/FUiCtrl_ContextMenuItem.cpp +++ b/src/ui/controls/FUiCtrl_ContextMenuItem.cpp @@ -287,6 +287,18 @@ _ContextMenuItem::GetDrawRect(void) const return __drawRect; } +void +_ContextMenuItem::SetPressedDrawRect(Tizen::Graphics::FloatRectangle rect) +{ + __pressedDrawRect = rect; + +} + +Tizen::Graphics::FloatRectangle +_ContextMenuItem::GetPressedDrawRect(void) const +{ + return __pressedDrawRect; +} int _ContextMenuItem::Release(void) diff --git a/src/ui/inc/FUiCtrl_ContextMenuGridPresenter.h b/src/ui/inc/FUiCtrl_ContextMenuGridPresenter.h index 0f350b7..2a7eb32 100644 --- a/src/ui/inc/FUiCtrl_ContextMenuGridPresenter.h +++ b/src/ui/inc/FUiCtrl_ContextMenuGridPresenter.h @@ -143,6 +143,7 @@ private: float __itemBitmapHeight; float __itemFontSize; float __dividerHeight; + float __bgPressedMargin; }; // _ContextMenuGridPresenter }}} // Tizen::Ui: Control diff --git a/src/ui/inc/FUiCtrl_ContextMenuItem.h b/src/ui/inc/FUiCtrl_ContextMenuItem.h index 23981a6..6ff4521 100644 --- a/src/ui/inc/FUiCtrl_ContextMenuItem.h +++ b/src/ui/inc/FUiCtrl_ContextMenuItem.h @@ -96,6 +96,9 @@ public: void SetDrawRect(Tizen::Graphics::FloatRectangle rect); Tizen::Graphics::FloatRectangle GetDrawRect(void) const; + void SetPressedDrawRect(Tizen::Graphics::FloatRectangle rect); + Tizen::Graphics::FloatRectangle GetPressedDrawRect(void) const; + void SetParentScrollEnable(bool enable); bool GetParentScrollEnable() const; @@ -154,6 +157,7 @@ private: Tizen::Graphics::Bitmap* __pMagentaBgBitmap; Tizen::Graphics::FloatDimension __size; Tizen::Graphics::FloatRectangle __drawRect; + Tizen::Graphics::FloatRectangle __pressedDrawRect; Tizen::Graphics::Color __selectedBgColor; Tizen::Graphics::Color __upperDividerLineColor; Tizen::Graphics::Color __lowerDividerLineColor; -- 2.7.4