axmol/cocos/gui/widgets/ScrollWidget/UIListView.cpp

1458 lines
45 KiB
C++
Raw Normal View History

2013-09-13 22:20:20 +08:00
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "UIListView.h"
NS_CC_EXT_BEGIN
UIListView::UIListView()
2013-09-16 20:54:13 +08:00
: _direction(LISTVIEW_DIR_VERTICAL)
, _moveDirection(LISTVIEW_MOVE_DIR_NONE)
, _touchStartLocation(0.0f)
, _touchEndLocation(0.0f)
, _touchMoveStartLocation(0.0f)
, _topBoundary(0.0f)
, _bottomBoundary(0.0f)
, _leftBoundary(0.0f)
, _rightBoundary(0.0f)
, _autoScroll(false)
, _autoScrollOriginalSpeed(0.0f)
, _autoScrollAcceleration(600.0f)
, _bePressed(false)
, _slidTime(0.0f)
, _childFocusCancelOffset(5.0f)
2013-09-17 20:13:23 +08:00
, _eventListener(NULL)
, _eventSelector(NULL)
2013-09-16 20:54:13 +08:00
, _childPool(NULL)
, _updatePool(NULL)
, _dataLength(0)
, _begin(0)
, _end(0)
, _updateChild(NULL)
, _updateDataIndex(-1)
, _updateSuccess(false)
, _overTopArray(NULL)
, _overBottomArray(NULL)
, _overLeftArray(NULL)
, _overRightArray(NULL)
, _disBoundaryToChild_0(0.0f)
, _disBetweenChild(0.0f)
, _scrollDegreeRange(45.0f)
2013-09-13 22:20:20 +08:00
{
}
UIListView::~UIListView()
{
2013-09-16 20:54:13 +08:00
CC_SAFE_RELEASE_NULL(_childPool);
CC_SAFE_RELEASE_NULL(_updatePool);
CC_SAFE_RELEASE_NULL(_overTopArray);
CC_SAFE_RELEASE_NULL(_overBottomArray);
CC_SAFE_RELEASE_NULL(_overLeftArray);
CC_SAFE_RELEASE_NULL(_overRightArray);
2013-09-13 22:20:20 +08:00
}
UIListView* UIListView::create()
{
UIListView* widget = new UIListView();
if (widget && widget->init())
{
widget->autorelease();
return widget;
}
CC_SAFE_DELETE(widget);
return NULL;
}
bool UIListView::init()
{
if (Layout::init())
{
setUpdateEnabled(true);
setTouchEnabled(true);
setClippingEnabled(true);
2013-09-16 20:54:13 +08:00
_childPool = CCArray::create();
_updatePool = CCArray::create();
CC_SAFE_RETAIN(_childPool);
CC_SAFE_RETAIN(_updatePool);
_overTopArray = cocos2d::CCArray::create();
_overBottomArray = cocos2d::CCArray::create();
_overLeftArray = cocos2d::CCArray::create();
_overRightArray = cocos2d::CCArray::create();
CC_SAFE_RETAIN(_overTopArray);
CC_SAFE_RETAIN(_overBottomArray);
CC_SAFE_RETAIN(_overLeftArray);
CC_SAFE_RETAIN(_overRightArray);
2013-09-13 22:20:20 +08:00
return true;
}
return false;
}
void UIListView::onSizeChanged()
{
Layout::onSizeChanged();
2013-09-16 20:54:13 +08:00
_topBoundary = _size.height;
_rightBoundary = _size.width;
2013-09-13 22:20:20 +08:00
}
bool UIListView::addChild(UIWidget* widget)
{
Layout::addChild(widget);
resetProperty();
return true;
}
void UIListView::removeAllChildren()
{
2013-09-16 20:54:13 +08:00
_updatePool->removeAllObjects();
_childPool->removeAllObjects();
2013-09-13 22:20:20 +08:00
Layout::removeAllChildren();
}
bool UIListView::removeChild(UIWidget* child)
{
bool value = false;
if (Layout::removeChild(child))
{
value = true;
resetProperty();
}
return value;
}
bool UIListView::onTouchBegan(const Point &touchPoint)
{
bool pass = Layout::onTouchBegan(touchPoint);
handlePressLogic(touchPoint);
return pass;
}
void UIListView::onTouchMoved(const Point &touchPoint)
{
Layout::onTouchMoved(touchPoint);
handleMoveLogic(touchPoint);
}
void UIListView::onTouchEnded(const Point &touchPoint)
{
Layout::onTouchEnded(touchPoint);
handleReleaseLogic(touchPoint);
}
void UIListView::onTouchCancelled(const Point &touchPoint)
{
Layout::onTouchCancelled(touchPoint);
}
void UIListView::onTouchLongClicked(const Point &touchPoint)
{
}
void UIListView::update(float dt)
{
2013-09-16 20:54:13 +08:00
if (_autoScroll)
2013-09-13 22:20:20 +08:00
{
autoScrollChildren(dt);
}
recordSlidTime(dt);
}
void UIListView::setDirection(ListViewDirection dir)
{
2013-09-16 20:54:13 +08:00
_direction = dir;
2013-09-13 22:20:20 +08:00
}
ListViewDirection UIListView::getDirection()
{
2013-09-16 20:54:13 +08:00
return _direction;
2013-09-13 22:20:20 +08:00
}
void UIListView::resetProperty()
{
2013-09-16 15:32:52 +08:00
ccArray* arrayChildren = _children->data;
2013-09-13 22:20:20 +08:00
if (arrayChildren->num <= 0)
{
return;
}
2013-09-16 20:54:13 +08:00
switch (_direction)
2013-09-13 22:20:20 +08:00
{
case LISTVIEW_DIR_VERTICAL: // vertical
2013-09-16 20:54:13 +08:00
if (_topBoundary == 0)
2013-09-13 22:20:20 +08:00
{
return;
}
break;
case LISTVIEW_DIR_HORIZONTAL: // horizontal
2013-09-16 20:54:13 +08:00
if (_rightBoundary == 0)
2013-09-13 22:20:20 +08:00
{
return;
}
break;
default:
break;
}
2013-09-16 20:54:13 +08:00
float scroll_top = _topBoundary;
float scroll_left = _leftBoundary;
2013-09-13 22:20:20 +08:00
2013-09-16 15:32:52 +08:00
switch (_children->count())
2013-09-13 22:20:20 +08:00
{
case 1:
{
UIWidget* child_0 = dynamic_cast<UIWidget*>(arrayChildren->arr[0]);
2013-09-16 20:54:13 +08:00
switch (_direction)
2013-09-13 22:20:20 +08:00
{
case LISTVIEW_DIR_VERTICAL: // vertical
{
float child_0_top = child_0->getTopInParent();
2013-09-16 20:54:13 +08:00
_disBoundaryToChild_0 = scroll_top - child_0_top;
2013-09-13 22:20:20 +08:00
}
break;
case LISTVIEW_DIR_HORIZONTAL: // horizontal
{
float child_0_left = child_0->getLeftInParent();
2013-09-16 20:54:13 +08:00
_disBoundaryToChild_0 = child_0_left - scroll_left;
2013-09-13 22:20:20 +08:00
}
break;
default:
break;
}
}
break;
default:
{
UIWidget* child_0 = dynamic_cast<UIWidget*>(arrayChildren->arr[0]);
UIWidget* child_1 = dynamic_cast<UIWidget*>(arrayChildren->arr[1]);
2013-09-16 20:54:13 +08:00
switch (_direction)
2013-09-13 22:20:20 +08:00
{
case LISTVIEW_DIR_VERTICAL: // vertical
{
float child_0_top = child_0->getTopInParent();
2013-09-16 20:54:13 +08:00
_disBoundaryToChild_0 = scroll_top - child_0_top;
_disBetweenChild = child_0->getPosition().y - child_1->getPosition().y;
2013-09-13 22:20:20 +08:00
}
break;
case LISTVIEW_DIR_HORIZONTAL: // horizontal
{
float child_0_left = child_0->getLeftInParent();
2013-09-16 20:54:13 +08:00
_disBoundaryToChild_0 = child_0_left - scroll_left;
_disBetweenChild = child_1->getPosition().x - child_0->getPosition().x;
2013-09-13 22:20:20 +08:00
}
break;
default:
break;
}
}
break;
}
}
void UIListView::handlePressLogic(const Point &touchPoint)
{
2013-09-16 15:32:52 +08:00
Point nsp = _renderer->convertToNodeSpace(touchPoint);
2013-09-13 22:20:20 +08:00
2013-09-16 20:54:13 +08:00
switch (_direction)
2013-09-13 22:20:20 +08:00
{
case LISTVIEW_DIR_VERTICAL: // vertical
2013-09-16 20:54:13 +08:00
_touchMoveStartLocation = nsp.y;
_touchStartLocation = nsp.y;
2013-09-13 22:20:20 +08:00
break;
case LISTVIEW_DIR_HORIZONTAL: // horizontal
2013-09-16 20:54:13 +08:00
_touchMoveStartLocation = nsp.x;
_touchStartLocation = nsp.x;
2013-09-13 22:20:20 +08:00
break;
default:
break;
}
startRecordSlidAction();
clearCollectOverArray();
}
void UIListView::handleMoveLogic(const Point &touchPoint)
{
2013-09-16 15:32:52 +08:00
Point nsp = _renderer->convertToNodeSpace(touchPoint);
2013-09-13 22:20:20 +08:00
float offset = 0.0f;
2013-09-16 20:54:13 +08:00
switch (_direction)
2013-09-13 22:20:20 +08:00
{
case LISTVIEW_DIR_VERTICAL: // vertical
{
float moveY = nsp.y;
2013-09-16 20:54:13 +08:00
offset = moveY - _touchMoveStartLocation;
_touchMoveStartLocation = moveY;
2013-09-13 22:20:20 +08:00
if (offset < 0.0f)
{
2013-09-16 20:54:13 +08:00
_moveDirection = LISTVIEW_MOVE_DIR_DOWN; // down
2013-09-13 22:20:20 +08:00
}
else if (offset > 0.0f)
{
2013-09-16 20:54:13 +08:00
_moveDirection = LISTVIEW_MOVE_DIR_UP; // up
2013-09-13 22:20:20 +08:00
}
}
break;
case LISTVIEW_DIR_HORIZONTAL: // horizontal
{
float moveX = nsp.x;
2013-09-16 20:54:13 +08:00
offset = moveX - _touchMoveStartLocation;
_touchMoveStartLocation = moveX;
2013-09-13 22:20:20 +08:00
if (offset < 0)
{
2013-09-16 20:54:13 +08:00
_moveDirection = LISTVIEW_MOVE_DIR_LEFT; // left
2013-09-13 22:20:20 +08:00
}
else if (offset > 0)
{
2013-09-16 20:54:13 +08:00
_moveDirection = LISTVIEW_MOVE_DIR_RIGHT; // right
2013-09-13 22:20:20 +08:00
}
}
break;
default:
break;
}
scrollChildren(offset);
}
void UIListView::handleReleaseLogic(const Point &touchPoint)
{
2013-09-16 15:32:52 +08:00
Point nsp = _renderer->convertToNodeSpace(touchPoint);
2013-09-13 22:20:20 +08:00
2013-09-16 20:54:13 +08:00
switch (_direction)
2013-09-13 22:20:20 +08:00
{
case LISTVIEW_DIR_VERTICAL: // vertical
2013-09-16 20:54:13 +08:00
_touchEndLocation = nsp.y;
2013-09-13 22:20:20 +08:00
break;
case LISTVIEW_DIR_HORIZONTAL: // horizontal
2013-09-16 20:54:13 +08:00
_touchEndLocation = nsp.x;
2013-09-13 22:20:20 +08:00
break;
default:
break;
}
endRecordSlidAction();
}
void UIListView::interceptTouchEvent(int handleState, UIWidget *sender, const Point &touchPoint)
{
switch (handleState)
{
case 0:
handlePressLogic(touchPoint);
break;
case 1:
{
float offset = 0;
2013-09-16 20:54:13 +08:00
switch (_direction)
2013-09-13 22:20:20 +08:00
{
case LISTVIEW_DIR_VERTICAL: // vertical
offset = fabs(sender->getTouchStartPos().y - touchPoint.y);
break;
case LISTVIEW_DIR_HORIZONTAL: // horizontal
offset = fabs(sender->getTouchStartPos().x - touchPoint.x);
break;
default:
break;
}
2013-09-16 20:54:13 +08:00
if (offset > _childFocusCancelOffset)
2013-09-13 22:20:20 +08:00
{
sender->setFocused(false);
handleMoveLogic(touchPoint);
}
}
break;
case 2:
handleReleaseLogic(touchPoint);
break;
case 3:
break;
}
}
void UIListView::checkChildInfo(int handleState,UIWidget* sender,const Point &touchPoint)
{
interceptTouchEvent(handleState, sender, touchPoint);
}
void UIListView::moveChildren(float offset)
{
2013-09-16 20:54:13 +08:00
switch (_direction)
2013-09-13 22:20:20 +08:00
{
case LISTVIEW_DIR_VERTICAL: // vertical
{
2013-09-16 15:32:52 +08:00
ccArray* arrayChildren = _children->data;
2013-09-13 22:20:20 +08:00
int childrenCount = arrayChildren->num;
for (int i = 0; i < childrenCount; i++)
{
UIWidget* child = (UIWidget*)(arrayChildren->arr[i]);
2013-09-16 20:54:13 +08:00
_moveChildPoint.x = child->getPosition().x;
_moveChildPoint.y = child->getPosition().y + offset;
child->setPosition(_moveChildPoint);
2013-09-13 22:20:20 +08:00
}
break;
}
case LISTVIEW_DIR_HORIZONTAL: // horizontal
{
2013-09-16 15:32:52 +08:00
ccArray* arrayChildren = _children->data;
2013-09-13 22:20:20 +08:00
int childrenCount = arrayChildren->num;
for (int i=0;i<childrenCount;i++)
{
UIWidget* child = (UIWidget*)(arrayChildren->arr[i]);
2013-09-16 20:54:13 +08:00
_moveChildPoint.x = child->getPosition().x + offset;
_moveChildPoint.y = child->getPosition().y;
child->setPosition(_moveChildPoint);
2013-09-13 22:20:20 +08:00
}
break;
}
default:
break;
}
}
bool UIListView::scrollChildren(float touchOffset)
{
float realOffset = touchOffset;
2013-09-16 20:54:13 +08:00
switch (_direction)
2013-09-13 22:20:20 +08:00
{
case LISTVIEW_DIR_VERTICAL: // vertical
2013-09-16 20:54:13 +08:00
switch (_moveDirection)
2013-09-13 22:20:20 +08:00
{
case LISTVIEW_MOVE_DIR_UP: // up
{
2013-09-16 20:54:13 +08:00
realOffset = MIN(realOffset, _disBetweenChild);
2013-09-13 22:20:20 +08:00
2013-09-16 20:54:13 +08:00
UIWidget* child_last = dynamic_cast<UIWidget*>(_childPool->getLastObject());
2013-09-13 22:20:20 +08:00
float child_last_bottom = child_last->getBottomInParent();
2013-09-16 20:54:13 +08:00
float scroll_bottom = _bottomBoundary;
2013-09-13 22:20:20 +08:00
2013-09-16 20:54:13 +08:00
if (_end == _dataLength - 1)
2013-09-13 22:20:20 +08:00
{
2013-09-16 20:54:13 +08:00
if (realOffset > scroll_bottom + _disBoundaryToChild_0 - child_last_bottom)
2013-09-13 22:20:20 +08:00
{
2013-09-16 20:54:13 +08:00
realOffset = scroll_bottom + _disBoundaryToChild_0 - child_last_bottom;
2013-09-13 22:20:20 +08:00
}
moveChildren(realOffset);
return false;
}
moveChildren(realOffset);
2013-09-16 20:54:13 +08:00
if (_end < _dataLength - 1)
2013-09-13 22:20:20 +08:00
{
collectOverTopChild();
2013-09-16 20:54:13 +08:00
unsigned int count = _overTopArray->count();
2013-09-13 22:20:20 +08:00
if (count > 0)
{
updateChild();
setLoopPosition();
2013-09-16 20:54:13 +08:00
_overTopArray->removeAllObjects();
2013-09-13 22:20:20 +08:00
}
}
}
break;
case LISTVIEW_MOVE_DIR_DOWN: // down
{
2013-09-16 20:54:13 +08:00
realOffset = MAX(realOffset, -_disBetweenChild);
2013-09-13 22:20:20 +08:00
2013-09-16 20:54:13 +08:00
UIWidget* child_0 = dynamic_cast<UIWidget*>(_childPool->getObjectAtIndex(0));
2013-09-13 22:20:20 +08:00
float child_0_top = child_0->getTopInParent();
2013-09-16 20:54:13 +08:00
float scroll_top = _topBoundary;
2013-09-13 22:20:20 +08:00
2013-09-16 20:54:13 +08:00
if (_begin == 0)
2013-09-13 22:20:20 +08:00
{
2013-09-16 20:54:13 +08:00
if (realOffset < scroll_top - _disBoundaryToChild_0 - child_0_top)
2013-09-13 22:20:20 +08:00
{
2013-09-16 20:54:13 +08:00
realOffset = scroll_top - _disBoundaryToChild_0 - child_0_top;
2013-09-13 22:20:20 +08:00
}
moveChildren(realOffset);
return false;
}
moveChildren(realOffset);
2013-09-16 20:54:13 +08:00
if (_begin > 0)
2013-09-13 22:20:20 +08:00
{
collectOverBottomChild();
2013-09-16 20:54:13 +08:00
int count = _overBottomArray->count();
2013-09-13 22:20:20 +08:00
if (count > 0)
{
updateChild();
setLoopPosition();
2013-09-16 20:54:13 +08:00
_overBottomArray->removeAllObjects();
2013-09-13 22:20:20 +08:00
}
}
}
break;
default:
break;
}
return true;
break;
case LISTVIEW_DIR_HORIZONTAL: // horizontal
2013-09-16 20:54:13 +08:00
switch (_moveDirection)
2013-09-13 22:20:20 +08:00
{
case LISTVIEW_MOVE_DIR_LEFT: // left
{
2013-09-16 20:54:13 +08:00
realOffset = MAX(realOffset, -_disBetweenChild);
2013-09-13 22:20:20 +08:00
2013-09-16 20:54:13 +08:00
UIWidget* child_last = dynamic_cast<UIWidget*>(_childPool->getLastObject());
2013-09-13 22:20:20 +08:00
float child_last_right = child_last->getRightInParent();
2013-09-16 20:54:13 +08:00
float scroll_right = _rightBoundary;
2013-09-13 22:20:20 +08:00
2013-09-16 20:54:13 +08:00
if (_end == _dataLength - 1)
2013-09-13 22:20:20 +08:00
{
2013-09-16 20:54:13 +08:00
if (realOffset < scroll_right - _disBoundaryToChild_0 - child_last_right)
2013-09-13 22:20:20 +08:00
{
2013-09-16 20:54:13 +08:00
realOffset = scroll_right - _disBoundaryToChild_0 - child_last_right;
2013-09-13 22:20:20 +08:00
}
moveChildren(realOffset);
return false;
}
moveChildren(realOffset);
2013-09-16 20:54:13 +08:00
if (_end < _dataLength - 1)
2013-09-13 22:20:20 +08:00
{
collectOverLeftChild();
2013-09-16 20:54:13 +08:00
int count = _overLeftArray->count();
2013-09-13 22:20:20 +08:00
if (count > 0)
{
updateChild();
setLoopPosition();
2013-09-16 20:54:13 +08:00
_overLeftArray->removeAllObjects();
2013-09-13 22:20:20 +08:00
}
}
}
break;
case LISTVIEW_MOVE_DIR_RIGHT: // right
{
2013-09-16 20:54:13 +08:00
realOffset = MIN(realOffset, _disBetweenChild);
2013-09-13 22:20:20 +08:00
2013-09-16 20:54:13 +08:00
UIWidget* child_0 = dynamic_cast<UIWidget*>(_childPool->getObjectAtIndex(0));
2013-09-13 22:20:20 +08:00
float child_0_left = child_0->getLeftInParent();
2013-09-16 20:54:13 +08:00
float scroll_left = _leftBoundary;
2013-09-13 22:20:20 +08:00
2013-09-16 20:54:13 +08:00
if (_begin == 0)
2013-09-13 22:20:20 +08:00
{
2013-09-16 20:54:13 +08:00
if (realOffset > scroll_left + _disBoundaryToChild_0 - child_0_left)
2013-09-13 22:20:20 +08:00
{
2013-09-16 20:54:13 +08:00
realOffset = scroll_left + _disBoundaryToChild_0 - child_0_left;
2013-09-13 22:20:20 +08:00
}
moveChildren(realOffset);
return false;
}
moveChildren(realOffset);
collectOverRightChild();
2013-09-16 20:54:13 +08:00
int count = _overRightArray->count();
2013-09-13 22:20:20 +08:00
if (count > 0)
{
updateChild();
setLoopPosition();
2013-09-16 20:54:13 +08:00
_overRightArray->removeAllObjects();
2013-09-13 22:20:20 +08:00
}
}
break;
default:
break;
}
return true;
break;
default:
break;
}
return false;
}
void UIListView::autoScrollChildren(float dt)
{
2013-09-16 20:54:13 +08:00
switch (_direction)
2013-09-13 22:20:20 +08:00
{
case LISTVIEW_DIR_VERTICAL: // vertical
2013-09-16 20:54:13 +08:00
switch (_moveDirection)
2013-09-13 22:20:20 +08:00
{
case LISTVIEW_MOVE_DIR_UP: // up
{
float curDis = getCurAutoScrollDistance(dt);
if (curDis <= 0)
{
curDis = 0;
stopAutoScrollChildren();
}
if (!scrollChildren(curDis))
{
stopAutoScrollChildren();
}
}
break;
case LISTVIEW_MOVE_DIR_DOWN: // down
{
float curDis = getCurAutoScrollDistance(dt);
if (curDis <= 0)
{
curDis = 0;
stopAutoScrollChildren();
}
if (!scrollChildren(-curDis))
{
stopAutoScrollChildren();
}
}
break;
default:
break;
}
break;
case LISTVIEW_DIR_HORIZONTAL: // horizontal
2013-09-16 20:54:13 +08:00
switch (_moveDirection)
2013-09-13 22:20:20 +08:00
{
case LISTVIEW_MOVE_DIR_LEFT: // left
{
float curDis = getCurAutoScrollDistance(dt);
if (curDis <= 0)
{
curDis = 0;
stopAutoScrollChildren();
}
if (!scrollChildren(-curDis))
{
stopAutoScrollChildren();
}
}
break;
case LISTVIEW_MOVE_DIR_RIGHT: // right
{
float curDis = getCurAutoScrollDistance(dt);
if (curDis <= 0)
{
curDis = 0;
stopAutoScrollChildren();
}
if (!scrollChildren(curDis))
{
stopAutoScrollChildren();
}
}
break;
default:
break;
}
break;
default:
break;
}
}
float UIListView::getCurAutoScrollDistance(float time)
{
float dt = time;
2013-09-16 20:54:13 +08:00
_autoScrollOriginalSpeed -= _autoScrollAcceleration*dt;
return _autoScrollOriginalSpeed*dt;
2013-09-13 22:20:20 +08:00
}
void UIListView::startAutoScrollChildren(float v)
{
2013-09-16 20:54:13 +08:00
_autoScrollOriginalSpeed = v;
_autoScroll = true;
2013-09-13 22:20:20 +08:00
}
void UIListView::stopAutoScrollChildren()
{
2013-09-16 20:54:13 +08:00
_autoScroll = false;
_autoScrollOriginalSpeed = 0.0f;
2013-09-13 22:20:20 +08:00
}
void UIListView::recordSlidTime(float dt)
{
2013-09-16 20:54:13 +08:00
if (_bePressed)
2013-09-13 22:20:20 +08:00
{
2013-09-16 20:54:13 +08:00
_slidTime += dt;
2013-09-13 22:20:20 +08:00
}
}
void UIListView::startRecordSlidAction()
{
2013-09-16 15:32:52 +08:00
if (_children->count() <= 0)
2013-09-13 22:20:20 +08:00
{
return;
}
2013-09-16 20:54:13 +08:00
if (_autoScroll)
2013-09-13 22:20:20 +08:00
{
stopAutoScrollChildren();
}
2013-09-16 20:54:13 +08:00
_bePressed = true;
_slidTime = 0.0;
2013-09-13 22:20:20 +08:00
}
void UIListView::endRecordSlidAction()
{
2013-09-16 15:32:52 +08:00
if (_children->count() <= 0)
2013-09-13 22:20:20 +08:00
{
return;
}
2013-09-16 20:54:13 +08:00
if (_slidTime <= 0.016f)
2013-09-13 22:20:20 +08:00
{
return;
}
float totalDis = 0;
2013-09-16 20:54:13 +08:00
totalDis = _touchEndLocation-_touchStartLocation;
float orSpeed = fabs(totalDis)/(_slidTime);
2013-09-13 22:20:20 +08:00
startAutoScrollChildren(orSpeed / 4);
2013-09-16 20:54:13 +08:00
_bePressed = false;
_slidTime = 0.0;
2013-09-13 22:20:20 +08:00
}
UIWidget* UIListView::getCheckPositionChild()
{
UIWidget* child = NULL;
2013-09-16 20:54:13 +08:00
switch (_direction)
2013-09-13 22:20:20 +08:00
{
case LISTVIEW_DIR_VERTICAL: // vertical
2013-09-16 20:54:13 +08:00
switch (_moveDirection)
2013-09-13 22:20:20 +08:00
{
case LISTVIEW_MOVE_DIR_UP: // up
2013-09-16 20:54:13 +08:00
child = dynamic_cast<UIWidget*>(_childPool->getLastObject());
2013-09-13 22:20:20 +08:00
break;
case LISTVIEW_MOVE_DIR_DOWN: // down
2013-09-16 20:54:13 +08:00
child = dynamic_cast<UIWidget*>(_childPool->getObjectAtIndex(0));
2013-09-13 22:20:20 +08:00
break;
default:
break;
}
break;
case LISTVIEW_DIR_HORIZONTAL: // horizontal
2013-09-16 20:54:13 +08:00
switch (_moveDirection)
2013-09-13 22:20:20 +08:00
{
case LISTVIEW_MOVE_DIR_LEFT: // left
2013-09-16 20:54:13 +08:00
child = dynamic_cast<UIWidget*>(_childPool->getLastObject());
2013-09-13 22:20:20 +08:00
break;
case LISTVIEW_MOVE_DIR_RIGHT: // right
2013-09-16 20:54:13 +08:00
child = dynamic_cast<UIWidget*>(_childPool->getObjectAtIndex(0));
2013-09-13 22:20:20 +08:00
break;
default:
break;
}
break;
default:
break;
}
return child;
}
void UIListView::initChildWithDataLength(int length)
{
2013-09-16 20:54:13 +08:00
_dataLength = length;
_begin = 0;
_end = 0;
2013-09-13 22:20:20 +08:00
// init child pool
2013-09-16 15:32:52 +08:00
ccArray* arrayChildren = _children->data;
2013-09-13 22:20:20 +08:00
int times = arrayChildren->num;
for (int i = 0; i < times; ++i)
{
UIWidget* child = dynamic_cast<UIWidget*>(arrayChildren->arr[i]);
setUpdateChild(child);
setUpdateDataIndex(i);
initChildEvent();
2013-09-16 20:54:13 +08:00
_childPool->addObject(child);
_end = i;
2013-09-13 22:20:20 +08:00
}
}
UIWidget* UIListView::getChildFromUpdatePool()
{
2013-09-16 20:54:13 +08:00
UIWidget* child = dynamic_cast<UIWidget*>(_updatePool->getLastObject());
_updatePool->removeLastObject();
2013-09-13 22:20:20 +08:00
return child;
}
void UIListView::pushChildToPool()
{
2013-09-16 20:54:13 +08:00
switch (_direction)
2013-09-13 22:20:20 +08:00
{
case LISTVIEW_DIR_VERTICAL: // vertical
2013-09-16 20:54:13 +08:00
switch (_moveDirection)
2013-09-13 22:20:20 +08:00
{
case LISTVIEW_MOVE_DIR_UP: // up
{
2013-09-16 20:54:13 +08:00
UIWidget* child = dynamic_cast<UIWidget*>(_childPool->getObjectAtIndex(0));
_updatePool->insertObject(child, 0);
_childPool->removeObjectAtIndex(0);
2013-09-13 22:20:20 +08:00
}
break;
case LISTVIEW_MOVE_DIR_DOWN: // down
{
2013-09-16 20:54:13 +08:00
UIWidget* child = dynamic_cast<UIWidget*>(_childPool->getLastObject());
_updatePool->insertObject(child, 0);
_childPool->removeLastObject();
2013-09-13 22:20:20 +08:00
}
break;
default:
break;
}
break;
case LISTVIEW_DIR_HORIZONTAL: // horizontal
2013-09-16 20:54:13 +08:00
switch (_moveDirection)
2013-09-13 22:20:20 +08:00
{
case LISTVIEW_MOVE_DIR_LEFT: // left
{
2013-09-16 20:54:13 +08:00
UIWidget* child = dynamic_cast<UIWidget*>(_childPool->getObjectAtIndex(0));
_updatePool->insertObject(child, 0);
_childPool->removeObjectAtIndex(0);
2013-09-13 22:20:20 +08:00
}
break;
case LISTVIEW_MOVE_DIR_RIGHT: // right
{
2013-09-16 20:54:13 +08:00
UIWidget* child = dynamic_cast<UIWidget*>(_childPool->getLastObject());
_updatePool->insertObject(child, 0);
_childPool->removeLastObject();
2013-09-13 22:20:20 +08:00
}
break;
default:
break;
}
break;
default:
break;
}
}
void UIListView::getAndCallback()
{
UIWidget* child = getChildFromUpdatePool();
if (child == NULL)
{
return;
}
2013-09-16 20:54:13 +08:00
switch (_direction)
2013-09-13 22:20:20 +08:00
{
case LISTVIEW_DIR_VERTICAL: // vertical
2013-09-16 20:54:13 +08:00
switch (_moveDirection)
2013-09-13 22:20:20 +08:00
{
case LISTVIEW_MOVE_DIR_UP: // up
2013-09-16 20:54:13 +08:00
++_end;
2013-09-13 22:20:20 +08:00
setUpdateChild(child);
2013-09-16 20:54:13 +08:00
setUpdateDataIndex(_end);
2013-09-13 22:20:20 +08:00
updateChildEvent();
2013-09-16 20:54:13 +08:00
if (_updateSuccess == false)
2013-09-13 22:20:20 +08:00
{
2013-09-16 20:54:13 +08:00
--_end;
_childPool->insertObject(child, 0);
2013-09-13 22:20:20 +08:00
return;
}
2013-09-16 20:54:13 +08:00
++_begin;
2013-09-13 22:20:20 +08:00
break;
case LISTVIEW_MOVE_DIR_DOWN: // down
2013-09-16 20:54:13 +08:00
--_begin;
2013-09-13 22:20:20 +08:00
setUpdateChild(child);
2013-09-16 20:54:13 +08:00
setUpdateDataIndex(_begin);
2013-09-13 22:20:20 +08:00
updateChildEvent();
2013-09-16 20:54:13 +08:00
if (_updateSuccess == false)
2013-09-13 22:20:20 +08:00
{
2013-09-16 20:54:13 +08:00
++_begin;
_childPool->addObject(child);
2013-09-13 22:20:20 +08:00
return;
}
2013-09-16 20:54:13 +08:00
--_end;
2013-09-13 22:20:20 +08:00
break;
default:
break;
}
break;
case LISTVIEW_DIR_HORIZONTAL: // horizontal
2013-09-16 20:54:13 +08:00
switch (_moveDirection)
2013-09-13 22:20:20 +08:00
{
case LISTVIEW_MOVE_DIR_LEFT: // left
2013-09-16 20:54:13 +08:00
++_end;
2013-09-13 22:20:20 +08:00
setUpdateChild(child);
2013-09-16 20:54:13 +08:00
setUpdateDataIndex(_end);
2013-09-13 22:20:20 +08:00
updateChildEvent();
2013-09-16 20:54:13 +08:00
if (_updateSuccess == false)
2013-09-13 22:20:20 +08:00
{
2013-09-16 20:54:13 +08:00
--_end;
_childPool->insertObject(child, 0);
2013-09-13 22:20:20 +08:00
return;
}
2013-09-16 20:54:13 +08:00
++_begin;
2013-09-13 22:20:20 +08:00
break;
case LISTVIEW_MOVE_DIR_RIGHT: // right
2013-09-16 20:54:13 +08:00
--_begin;
2013-09-13 22:20:20 +08:00
setUpdateChild(child);
2013-09-16 20:54:13 +08:00
setUpdateDataIndex(_begin);
2013-09-13 22:20:20 +08:00
updateChildEvent();
2013-09-16 20:54:13 +08:00
if (_updateSuccess == false)
2013-09-13 22:20:20 +08:00
{
2013-09-16 20:54:13 +08:00
++_begin;
_childPool->addObject(child);
2013-09-13 22:20:20 +08:00
return;
}
2013-09-16 20:54:13 +08:00
--_end;
2013-09-13 22:20:20 +08:00
break;
default:
break;
}
break;
default:
break;
}
2013-09-16 20:54:13 +08:00
switch (_direction)
2013-09-13 22:20:20 +08:00
{
case LISTVIEW_DIR_VERTICAL: // vertical
2013-09-16 20:54:13 +08:00
switch (_moveDirection)
2013-09-13 22:20:20 +08:00
{
case LISTVIEW_MOVE_DIR_UP: // up
2013-09-16 20:54:13 +08:00
_childPool->addObject(child);
2013-09-13 22:20:20 +08:00
break;
case LISTVIEW_MOVE_DIR_DOWN: // down
2013-09-16 20:54:13 +08:00
_childPool->insertObject(child, 0);
2013-09-13 22:20:20 +08:00
break;
default:
break;
}
break;
case LISTVIEW_DIR_HORIZONTAL: // horizontal
2013-09-16 20:54:13 +08:00
switch (_moveDirection)
2013-09-13 22:20:20 +08:00
{
case LISTVIEW_MOVE_DIR_LEFT: // left
2013-09-16 20:54:13 +08:00
_childPool->addObject(child);
2013-09-13 22:20:20 +08:00
break;
case LISTVIEW_MOVE_DIR_RIGHT: // right
2013-09-16 20:54:13 +08:00
_childPool->insertObject(child, 0);
2013-09-13 22:20:20 +08:00
break;
default:
break;
}
break;
default:
break;
}
}
int UIListView::getDataLength()
{
2013-09-16 20:54:13 +08:00
return _dataLength;
2013-09-13 22:20:20 +08:00
}
UIWidget* UIListView::getUpdateChild()
{
2013-09-16 20:54:13 +08:00
return _updateChild;
2013-09-13 22:20:20 +08:00
}
void UIListView::setUpdateChild(UIWidget* child)
{
2013-09-16 20:54:13 +08:00
_updateChild = child;
2013-09-13 22:20:20 +08:00
}
int UIListView::getUpdateDataIndex()
{
2013-09-16 20:54:13 +08:00
return _updateDataIndex;
2013-09-13 22:20:20 +08:00
}
void UIListView::setUpdateDataIndex(int index)
{
2013-09-16 20:54:13 +08:00
_updateDataIndex = index;
2013-09-13 22:20:20 +08:00
}
bool UIListView::getUpdateSuccess()
{
2013-09-16 20:54:13 +08:00
return _updateSuccess;
2013-09-13 22:20:20 +08:00
}
void UIListView::setUpdateSuccess(bool sucess)
{
2013-09-16 20:54:13 +08:00
_updateSuccess = sucess;
2013-09-13 22:20:20 +08:00
}
void UIListView::clearCollectOverArray()
{
2013-09-16 20:54:13 +08:00
switch (_direction)
2013-09-13 22:20:20 +08:00
{
case LISTVIEW_DIR_VERTICAL:
2013-09-16 20:54:13 +08:00
_overTopArray->removeAllObjects();
_overBottomArray->removeAllObjects();
2013-09-13 22:20:20 +08:00
break;
case LISTVIEW_DIR_HORIZONTAL:
2013-09-16 20:54:13 +08:00
_overLeftArray->removeAllObjects();
_overRightArray->removeAllObjects();
2013-09-13 22:20:20 +08:00
break;
default:
break;
}
}
void UIListView::collectOverTopChild()
{
2013-09-16 20:54:13 +08:00
float scroll_top = _topBoundary;
2013-09-13 22:20:20 +08:00
2013-09-16 15:32:52 +08:00
ccArray* arrayChildren = _children->data;
2013-09-13 22:20:20 +08:00
int times = arrayChildren->num;
for (int i = 0; i < times; ++i)
{
UIWidget* child = dynamic_cast<UIWidget*>(arrayChildren->arr[i]);
float child_bottom = child->getBottomInParent();
if (child_bottom >= scroll_top)
{
2013-09-16 20:54:13 +08:00
_overTopArray->addObject(child);
2013-09-13 22:20:20 +08:00
}
}
}
void UIListView::collectOverBottomChild()
{
2013-09-16 20:54:13 +08:00
float scroll_bottom = _bottomBoundary;
2013-09-13 22:20:20 +08:00
2013-09-16 15:32:52 +08:00
ccArray* arrayChildren = _children->data;
2013-09-13 22:20:20 +08:00
int times = arrayChildren->num;
for (int i = 0; i < times; ++i)
{
UIWidget* child = dynamic_cast<UIWidget*>(arrayChildren->arr[i]);
float child_top = child->getTopInParent();
if (child_top <= scroll_bottom)
{
2013-09-16 20:54:13 +08:00
_overBottomArray->addObject(child);
2013-09-13 22:20:20 +08:00
}
}
}
void UIListView::collectOverLeftChild()
{
2013-09-16 20:54:13 +08:00
float scroll_left = _leftBoundary;
2013-09-13 22:20:20 +08:00
2013-09-16 15:32:52 +08:00
ccArray* arrayChildren = _children->data;
2013-09-13 22:20:20 +08:00
int times = arrayChildren->num;
for (int i = 0; i < times; ++i)
{
UIWidget* child = dynamic_cast<UIWidget*>(arrayChildren->arr[i]);
float child_right = child->getRightInParent();
if (child_right <= scroll_left)
{
2013-09-16 20:54:13 +08:00
_overLeftArray->addObject(child);
2013-09-13 22:20:20 +08:00
}
}
}
void UIListView::collectOverRightChild()
{
2013-09-16 20:54:13 +08:00
float scroll_right = _rightBoundary;
2013-09-13 22:20:20 +08:00
2013-09-16 15:32:52 +08:00
ccArray* arrayChildren = _children->data;
2013-09-13 22:20:20 +08:00
int times = arrayChildren->num;
for (int i = 0; i < times; ++i)
{
UIWidget* child = dynamic_cast<UIWidget*>(arrayChildren->arr[i]);
float child_left = child->getLeftInParent();
if (child_left >= scroll_right)
{
2013-09-16 20:54:13 +08:00
_overRightArray->addObject(child);
2013-09-13 22:20:20 +08:00
}
}
}
void UIListView::setLoopPosition()
{
2013-09-16 20:54:13 +08:00
switch (_direction)
2013-09-13 22:20:20 +08:00
{
case LISTVIEW_DIR_VERTICAL: // vertical
2013-09-16 20:54:13 +08:00
switch (_moveDirection)
2013-09-13 22:20:20 +08:00
{
case LISTVIEW_MOVE_DIR_UP: // up
{
2013-09-16 15:32:52 +08:00
ccArray* arrayChildren = _children->data;
2013-09-13 22:20:20 +08:00
unsigned int childrenCount = arrayChildren->num;
2013-09-16 20:54:13 +08:00
if (_overTopArray->count() == childrenCount)
2013-09-13 22:20:20 +08:00
{
unsigned int count = childrenCount;
for (unsigned int i = 0; i < count; ++i)
{
2013-09-16 20:54:13 +08:00
UIWidget* child = dynamic_cast<UIWidget*>(_overTopArray->getObjectAtIndex(i));
2013-09-13 22:20:20 +08:00
if (i == 0)
{
float height = child->getSize().height;
float offset = (child->getWidgetType() == WidgetTypeWidget) ? height / 2 : height;
2013-09-16 20:54:13 +08:00
float y = _topBoundary - _disBoundaryToChild_0 - offset;
2013-09-13 22:20:20 +08:00
child->setPosition(Point(child->getPosition().x, y));
}
else
{
2013-09-16 20:54:13 +08:00
UIWidget* prev_child = dynamic_cast<UIWidget*>(_overTopArray->getObjectAtIndex(i - 1));
child->setPosition(Point(child->getPosition().x, prev_child->getPosition().y - _disBetweenChild));
2013-09-13 22:20:20 +08:00
}
}
}
else
{
2013-09-16 20:54:13 +08:00
float scroll_top = _topBoundary;
2013-09-13 22:20:20 +08:00
2013-09-16 15:32:52 +08:00
ccArray* arrayChildren = _children->data;
2013-09-13 22:20:20 +08:00
int count = arrayChildren->num;
for (int i = 0; i < count; ++i)
{
UIWidget* child = dynamic_cast<UIWidget*>(arrayChildren->arr[i]);
float child_bottom = child->getBottomInParent();
if (child_bottom >= scroll_top)
{
int index = (i == 0) ? (count - 1) : (i - 1);
UIWidget* prev_child = dynamic_cast<UIWidget*>(arrayChildren->arr[index]);
2013-09-16 20:54:13 +08:00
child->setPosition(Point(child->getPosition().x, prev_child->getPosition().y - _disBetweenChild));
2013-09-13 22:20:20 +08:00
}
}
}
}
break;
case LISTVIEW_MOVE_DIR_DOWN: // down
{
2013-09-16 15:32:52 +08:00
ccArray* arrayChildren = _children->data;
2013-09-13 22:20:20 +08:00
unsigned int childrenCount = arrayChildren->num;
2013-09-16 20:54:13 +08:00
if (_overBottomArray->count() == childrenCount)
2013-09-13 22:20:20 +08:00
{
unsigned int count = childrenCount;
for (unsigned int i = 0; i < count; ++i)
{
2013-09-16 20:54:13 +08:00
UIWidget* child = dynamic_cast<UIWidget*>(_overBottomArray->getObjectAtIndex(i));
2013-09-13 22:20:20 +08:00
if (i == 0)
{
2013-09-16 20:54:13 +08:00
float y = _bottomBoundary + _disBoundaryToChild_0 - _disBetweenChild;
2013-09-13 22:20:20 +08:00
child->setPosition(Point(child->getPosition().x, y));
}
else
{
2013-09-16 20:54:13 +08:00
UIWidget* prev_child = dynamic_cast<UIWidget*>(_overBottomArray->getObjectAtIndex(i - 1));
child->setPosition(Point(child->getPosition().x, prev_child->getPosition().y + _disBetweenChild));
2013-09-13 22:20:20 +08:00
}
}
}
else
{
2013-09-16 20:54:13 +08:00
float scroll_bottom = _bottomBoundary;
2013-09-13 22:20:20 +08:00
2013-09-16 15:32:52 +08:00
ccArray* arrayChildren = _children->data;
2013-09-13 22:20:20 +08:00
int count = arrayChildren->num;
for (int i = count - 1; i >= 0; --i)
{
UIWidget* child = dynamic_cast<UIWidget*>(arrayChildren->arr[i]);
float child_top = child->getTopInParent();
if (child_top <= scroll_bottom)
{
int index = (i == count - 1) ? 0 : (i + 1);
UIWidget* next_child = dynamic_cast<UIWidget*>(arrayChildren->arr[index]);
2013-09-16 20:54:13 +08:00
child->setPosition(Point(child->getPosition().x, next_child->getPosition().y + _disBetweenChild));
2013-09-13 22:20:20 +08:00
}
}
}
}
break;
default:
break;
}
break;
case LISTVIEW_DIR_HORIZONTAL: // horizontal
2013-09-16 20:54:13 +08:00
switch (_moveDirection)
2013-09-13 22:20:20 +08:00
{
case LISTVIEW_MOVE_DIR_LEFT: // left
{
2013-09-16 15:32:52 +08:00
ccArray* arrayChildren = _children->data;
2013-09-13 22:20:20 +08:00
unsigned int childrenCount = arrayChildren->num;
2013-09-16 20:54:13 +08:00
if (_overLeftArray->count() == childrenCount)
2013-09-13 22:20:20 +08:00
{
unsigned int count = childrenCount;
for (unsigned int i = 0; i < count; ++i)
{
2013-09-16 20:54:13 +08:00
UIWidget* child = dynamic_cast<UIWidget*>(_overLeftArray->getObjectAtIndex(i));
2013-09-13 22:20:20 +08:00
if (i == 0)
{
float width = child->getSize().width;
float offset = (child->getWidgetType() == WidgetTypeWidget) ? (width / 2) : 0;
2013-09-16 20:54:13 +08:00
float x = _leftBoundary + _disBoundaryToChild_0 + width + offset;
2013-09-13 22:20:20 +08:00
child->setPosition(Point(x, child->getPosition().y));
}
else
{
2013-09-16 20:54:13 +08:00
UIWidget* prev_child = dynamic_cast<UIWidget*>(_overLeftArray->getObjectAtIndex(i - 1));
child->setPosition(Point(prev_child->getPosition().x + _disBetweenChild, child->getPosition().y));
2013-09-13 22:20:20 +08:00
}
}
}
else
{
2013-09-16 20:54:13 +08:00
float scroll_left = _leftBoundary;
2013-09-13 22:20:20 +08:00
2013-09-16 15:32:52 +08:00
ccArray* arrayChildren = _children->data;
2013-09-13 22:20:20 +08:00
int count = arrayChildren->num;
for (int i = 0; i < count; ++i)
{
UIWidget* child = dynamic_cast<UIWidget*>(arrayChildren->arr[i]);
float child_right = child->getRightInParent();
if (child_right <= scroll_left)
{
int index = (i == 0) ? (count - 1) : (i - 1);
UIWidget* prev_child = dynamic_cast<UIWidget*>(arrayChildren->arr[index]);
2013-09-16 20:54:13 +08:00
child->setPosition(Point(prev_child->getPosition().x + _disBetweenChild, child->getPosition().y));
2013-09-13 22:20:20 +08:00
}
}
}
}
break;
case LISTVIEW_MOVE_DIR_RIGHT: // right
{
2013-09-16 15:32:52 +08:00
ccArray* arrayChildren = _children->data;
2013-09-13 22:20:20 +08:00
unsigned int childrenCount = arrayChildren->num;
2013-09-16 20:54:13 +08:00
if (_overRightArray->count() == childrenCount)
2013-09-13 22:20:20 +08:00
{
unsigned int count = childrenCount;
for (unsigned int i = 0; i < count; ++i)
{
2013-09-16 20:54:13 +08:00
UIWidget* child = dynamic_cast<UIWidget*>(_overRightArray->getObjectAtIndex(i));
2013-09-13 22:20:20 +08:00
if (i == 0)
{
2013-09-16 20:54:13 +08:00
float x = _rightBoundary - _disBoundaryToChild_0 + _disBetweenChild;
2013-09-13 22:20:20 +08:00
child->setPosition(Point(x, child->getPosition().y));
}
else
{
2013-09-16 20:54:13 +08:00
UIWidget* prev_child = dynamic_cast<UIWidget*>(_overRightArray->getObjectAtIndex(i - 1));
child->setPosition(Point(prev_child->getPosition().x - _disBetweenChild, child->getPosition().y));
2013-09-13 22:20:20 +08:00
}
}
}
else
{
2013-09-16 20:54:13 +08:00
float scroll_right = _rightBoundary;
2013-09-13 22:20:20 +08:00
2013-09-16 15:32:52 +08:00
ccArray* arrayChildren = _children->data;
2013-09-13 22:20:20 +08:00
int count = arrayChildren->num;
for (int i = count - 1; i >= 0; --i)
{
UIWidget* child = dynamic_cast<UIWidget*>(arrayChildren->arr[i]);
float child_left = child->getLeftInParent();
if (child_left >= scroll_right)
{
int index = (i == count - 1) ? 0 : (i + 1);
UIWidget* next_child = dynamic_cast<UIWidget*>(arrayChildren->arr[index]);
2013-09-16 20:54:13 +08:00
child->setPosition(Point(next_child->getPosition().x - _disBetweenChild, child->getPosition().y));
2013-09-13 22:20:20 +08:00
}
}
}
}
break;
default:
break;
}
break;
default:
break;
}
}
void UIListView::updateChild()
{
2013-09-16 20:54:13 +08:00
switch (_direction)
2013-09-13 22:20:20 +08:00
{
case LISTVIEW_DIR_VERTICAL: // vertical
2013-09-16 20:54:13 +08:00
switch (_moveDirection)
2013-09-13 22:20:20 +08:00
{
case LISTVIEW_MOVE_DIR_UP: // up
{
2013-09-16 20:54:13 +08:00
int count = _overTopArray->count();
2013-09-13 22:20:20 +08:00
for (int i = 0; i < count; ++i)
{
pushChildToPool();
getAndCallback();
}
}
break;
case LISTVIEW_MOVE_DIR_DOWN: // down
{
2013-09-16 20:54:13 +08:00
int count = _overBottomArray->count();
2013-09-13 22:20:20 +08:00
for (int i = 0; i < count; ++i)
{
pushChildToPool();
getAndCallback();
}
}
break;
default:
break;
}
break;
case LISTVIEW_DIR_HORIZONTAL: // horizontal
2013-09-16 20:54:13 +08:00
switch (_moveDirection)
2013-09-13 22:20:20 +08:00
{
case LISTVIEW_MOVE_DIR_LEFT: // left
{
2013-09-16 20:54:13 +08:00
int count = _overLeftArray->count();
2013-09-13 22:20:20 +08:00
for (int i = 0; i < count; ++i)
{
pushChildToPool();
getAndCallback();
}
}
break;
case LISTVIEW_MOVE_DIR_RIGHT: // right
{
2013-09-16 20:54:13 +08:00
int count = _overRightArray->count();
2013-09-13 22:20:20 +08:00
for (int i = 0; i < count; ++i)
{
pushChildToPool();
getAndCallback();
}
}
break;
default:
break;
}
break;
default:
break;
}
}
void UIListView::initChildEvent()
{
2013-09-17 20:13:23 +08:00
if (_eventListener && _eventSelector)
2013-09-13 22:20:20 +08:00
{
2013-09-17 20:13:23 +08:00
(_eventListener->*_eventSelector)(this, LISTVIEW_EVENT_INIT_CHILD);
2013-09-13 22:20:20 +08:00
}
}
void UIListView::updateChildEvent()
{
2013-09-17 20:13:23 +08:00
if (_eventListener && _eventSelector)
2013-09-13 22:20:20 +08:00
{
2013-09-17 20:13:23 +08:00
(_eventListener->*_eventSelector)(this, LISTVIEW_EVENT_UPDATE_CHILD);
2013-09-13 22:20:20 +08:00
}
}
2013-09-17 20:13:23 +08:00
void UIListView::addEventListenter(Object *target, SEL_ListViewEvent selector)
2013-09-13 22:20:20 +08:00
{
2013-09-17 20:13:23 +08:00
_eventListener = target;
_eventSelector = selector;
2013-09-13 22:20:20 +08:00
}
2013-09-17 17:59:20 +08:00
const char* UIListView::getDescription() const
{
return "ListView";
}
2013-09-13 22:20:20 +08:00
NS_CC_EXT_END