More enum class: ScrollView::Direction, TableView::VerticalFillOrder

This commit is contained in:
James Chen 2013-07-26 22:55:41 +08:00
parent 19d9c08c79
commit 58a3560bca
10 changed files with 81 additions and 75 deletions

View File

@ -37,15 +37,6 @@ NS_CC_BEGIN
* @{
*/
typedef enum
{
ccTouchSelectorBeganBit = 1 << 0,
ccTouchSelectorMovedBit = 1 << 1,
ccTouchSelectorEndedBit = 1 << 2,
ccTouchSelectorCancelledBit = 1 << 3,
ccTouchSelectorAllBits = ( ccTouchSelectorBeganBit | ccTouchSelectorMovedBit | ccTouchSelectorEndedBit | ccTouchSelectorCancelledBit),
} ccTouchSelectorFlag;
enum {
CCTOUCHBEGAN,

View File

@ -47,7 +47,7 @@ void ScrollViewLoader::onHandlePropTypeFloat(Node * pNode, Node * pParent, const
void ScrollViewLoader::onHandlePropTypeIntegerLabeled(Node * pNode, Node * pParent, const char * pPropertyName, int pIntegerLabeled, CCBReader * pCCBReader) {
if(strcmp(pPropertyName, PROPERTY_DIRECTION) == 0) {
((ScrollView *)pNode)->setDirection(ScrollViewDirection(pIntegerLabeled));
((ScrollView *)pNode)->setDirection(ScrollView::Direction(pIntegerLabeled));
} else {
NodeLoader::onHandlePropTypeFloatScale(pNode, pParent, pPropertyName, pIntegerLabeled, pCCBReader);
}

View File

@ -61,4 +61,14 @@ const EditBox::InputFlag kEditBoxInputFlagInitialCapsWord = EditBox::InputFlag::
const EditBox::InputFlag kEditBoxInputFlagInitialCapsSentence = EditBox::InputFlag::INITIAL_CAPS_SENTENCE;
const EditBox::InputFlag kEditBoxInputFlagInitialCapsAllCharacters = EditBox::InputFlag::INTIAL_CAPS_ALL_CHARACTERS;
const ScrollView::Direction kCCScrollViewDirectionNone = ScrollView::Direction::NONE;
const ScrollView::Direction kCCScrollViewDirectionHorizontal = ScrollView::Direction::HORIZONTAL;
const ScrollView::Direction kCCScrollViewDirectionVertical = ScrollView::Direction::VERTICAL;
const ScrollView::Direction kCCScrollViewDirectionBoth = ScrollView::Direction::BOTH;
const TableView::VerticalFillOrder kCCTableViewFillTopDown = TableView::VerticalFillOrder::TOP_DOWN;
const TableView::VerticalFillOrder kCCTableViewFillBottomUp = TableView::VerticalFillOrder::BOTTOM_UP;
NS_CC_EXT_END

View File

@ -117,20 +117,24 @@ CC_DEPRECATED_ATTRIBUTE typedef AttachmentTimeline CCAttachmentTimeline;
CC_DEPRECATED_ATTRIBUTE typedef AtlasAttachmentLoader CCAtlasAttachmentLoader;
CC_DEPRECATED_ATTRIBUTE typedef VertexIndex CCVertexIndex;
CC_DEPRECATED_ATTRIBUTE typedef RegionAttachment CCRegionAttachment;
CC_DEPRECATED_ATTRIBUTE typedef ScrollViewDirection CCScrollViewDirection;
CC_DEPRECATED_ATTRIBUTE typedef TableViewVerticalFillOrder CCTableViewVerticalFillOrder;
CC_DEPRECATED_ATTRIBUTE typedef ControlStepperPart CCControlStepperPart;
CC_DEPRECATED_ATTRIBUTE typedef NodeLoaderMap CCNodeLoaderMap;
CC_DEPRECATED_ATTRIBUTE typedef NodeLoaderMapEntry CCNodeLoaderMapEntry;
CC_DEPRECATED_ATTRIBUTE typedef EventRegistry CCEventRegistry;
CC_DEPRECATED_ATTRIBUTE typedef AttachmentType CCAttachmentType;
#define kCCTableViewFillTopDown kTableViewFillTopDown
#define kCCTableViewFillBottomUp kTableViewFillBottomUp
#define kCCScrollViewDirectionNone kScrollViewDirectionNone
#define kCCScrollViewDirectionHorizontal kScrollViewDirectionHorizontal
#define kCCScrollViewDirectionVertical kScrollViewDirectionVertical
#define kCCScrollViewDirectionBoth kScrollViewDirectionBoth
CC_DEPRECATED_ATTRIBUTE typedef ScrollView::Direction CCScrollViewDirection;
CC_DEPRECATED_ATTRIBUTE extern const ScrollView::Direction kCCScrollViewDirectionNone;
CC_DEPRECATED_ATTRIBUTE extern const ScrollView::Direction kCCScrollViewDirectionHorizontal;
CC_DEPRECATED_ATTRIBUTE extern const ScrollView::Direction kCCScrollViewDirectionVertical;
CC_DEPRECATED_ATTRIBUTE extern const ScrollView::Direction kCCScrollViewDirectionBoth;
CC_DEPRECATED_ATTRIBUTE typedef TableView::VerticalFillOrder CCTableViewVerticalFillOrder;
CC_DEPRECATED_ATTRIBUTE extern const TableView::VerticalFillOrder kCCTableViewFillTopDown;
CC_DEPRECATED_ATTRIBUTE extern const TableView::VerticalFillOrder kCCTableViewFillBottomUp;
CC_DEPRECATED_ATTRIBUTE extern const EditBox::KeyboardReturnType kKeyboardReturnTypeDefault;
CC_DEPRECATED_ATTRIBUTE extern const EditBox::KeyboardReturnType kKeyboardReturnTypeDone;

View File

@ -45,7 +45,7 @@ ScrollView::ScrollView()
, _minZoomScale(0.0f)
, _maxZoomScale(0.0f)
, _delegate(NULL)
, _direction(kScrollViewDirectionBoth)
, _direction(Direction::BOTH)
, _dragging(false)
, _container(NULL)
, _touchMoved(false)
@ -114,7 +114,7 @@ bool ScrollView::initWithViewSize(Size size, Node *container/* = NULL*/)
_bounceable = true;
_clippingToBounds = true;
//_container->setContentSize(Size::ZERO);
_direction = kScrollViewDirectionBoth;
_direction = Direction::BOTH;
_container->setPosition(Point(0.0f, 0.0f));
_touchLength = 0.0f;
@ -333,13 +333,13 @@ void ScrollView::relocateContainer(bool animated)
newX = oldPoint.x;
newY = oldPoint.y;
if (_direction == kScrollViewDirectionBoth || _direction == kScrollViewDirectionHorizontal)
if (_direction == Direction::BOTH || _direction == Direction::HORIZONTAL)
{
newX = MAX(newX, min.x);
newX = MIN(newX, max.x);
}
if (_direction == kScrollViewDirectionBoth || _direction == kScrollViewDirectionVertical)
if (_direction == Direction::BOTH || _direction == Direction::VERTICAL)
{
newY = MIN(newY, max.y);
newY = MAX(newY, min.y);
@ -659,11 +659,11 @@ void ScrollView::ccTouchMoved(Touch* touch, Event* event)
moveDistance = newPoint - _touchPoint;
float dis = 0.0f;
if (_direction == kScrollViewDirectionVertical)
if (_direction == Direction::VERTICAL)
{
dis = moveDistance.y;
}
else if (_direction == kScrollViewDirectionHorizontal)
else if (_direction == Direction::HORIZONTAL)
{
dis = moveDistance.x;
}
@ -690,10 +690,10 @@ void ScrollView::ccTouchMoved(Touch* touch, Event* event)
{
switch (_direction)
{
case kScrollViewDirectionVertical:
case Direction::VERTICAL:
moveDistance = Point(0.0f, moveDistance.y);
break;
case kScrollViewDirectionHorizontal:
case Direction::HORIZONTAL:
moveDistance = Point(moveDistance.x, 0.0f);
break;
default:

View File

@ -36,13 +36,6 @@ NS_CC_EXT_BEGIN
* @{
*/
typedef enum {
kScrollViewDirectionNone = -1,
kScrollViewDirectionHorizontal = 0,
kScrollViewDirectionVertical,
kScrollViewDirectionBoth
} ScrollViewDirection;
class ScrollView;
class ScrollViewDelegate
@ -61,6 +54,13 @@ public:
class ScrollView : public Layer
{
public:
enum class Direction
{
NONE = -1,
HORIZONTAL = 0,
VERTICAL,
BOTH
};
/**
* Returns an autoreleased scroll view object.
*
@ -172,8 +172,8 @@ public:
/**
* direction allowed to scroll. ScrollViewDirectionBoth by default.
*/
ScrollViewDirection getDirection() const { return _direction; }
virtual void setDirection(ScrollViewDirection eDirection) { _direction = eDirection; }
Direction getDirection() const { return _direction; }
virtual void setDirection(Direction eDirection) { _direction = eDirection; }
ScrollViewDelegate* getDelegate() { return _delegate; }
void setDelegate(ScrollViewDelegate* pDelegate) { _delegate = pDelegate; }
@ -254,7 +254,7 @@ protected:
*/
ScrollViewDelegate* _delegate;
ScrollViewDirection _direction;
Direction _direction;
/**
* If YES, the view is being dragged.
*/

View File

@ -56,8 +56,8 @@ bool TableView::initWithViewSize(Size size, Node* container/* = NULL*/)
_cellsUsed = new ArrayForObjectSorting();
_cellsFreed = new ArrayForObjectSorting();
_indices = new std::set<unsigned int>();
_vordering = kTableViewFillBottomUp;
this->setDirection(kScrollViewDirectionVertical);
_vordering = VerticalFillOrder::BOTTOM_UP;
this->setDirection(Direction::VERTICAL);
ScrollView::setDelegate(this);
return true;
@ -66,13 +66,13 @@ bool TableView::initWithViewSize(Size size, Node* container/* = NULL*/)
}
TableView::TableView()
: _touchedCell(NULL)
, _indices(NULL)
, _cellsUsed(NULL)
, _cellsFreed(NULL)
, _dataSource(NULL)
, _tableViewDelegate(NULL)
, _oldDirection(kScrollViewDirectionNone)
: _touchedCell(nullptr)
, _indices(nullptr)
, _cellsUsed(nullptr)
, _cellsFreed(nullptr)
, _dataSource(nullptr)
, _tableViewDelegate(nullptr)
, _oldDirection(Direction::NONE)
{
}
@ -84,7 +84,7 @@ TableView::~TableView()
CC_SAFE_RELEASE(_cellsFreed);
}
void TableView::setVerticalFillOrder(TableViewVerticalFillOrder fillOrder)
void TableView::setVerticalFillOrder(VerticalFillOrder fillOrder)
{
if (_vordering != fillOrder) {
_vordering = fillOrder;
@ -94,14 +94,14 @@ void TableView::setVerticalFillOrder(TableViewVerticalFillOrder fillOrder)
}
}
TableViewVerticalFillOrder TableView::getVerticalFillOrder()
TableView::VerticalFillOrder TableView::getVerticalFillOrder()
{
return _vordering;
}
void TableView::reloadData()
{
_oldDirection = kScrollViewDirectionNone;
_oldDirection = Direction::NONE;
Object* pObj = NULL;
CCARRAY_FOREACH(_cellsUsed, pObj)
{
@ -276,7 +276,7 @@ void TableView::_updateContentSize()
switch (this->getDirection())
{
case kScrollViewDirectionHorizontal:
case Direction::HORIZONTAL:
size = Size(maxPosition, _viewSize.height);
break;
default:
@ -289,7 +289,7 @@ void TableView::_updateContentSize()
if (_oldDirection != _direction)
{
if (_direction == kScrollViewDirectionHorizontal)
if (_direction == Direction::HORIZONTAL)
{
this->setContentOffset(Point(0,0));
}
@ -307,7 +307,7 @@ Point TableView::_offsetFromIndex(unsigned int index)
Point offset = this->__offsetFromIndex(index);
const Size cellSize = _dataSource->tableCellSizeForIndex(this, index);
if (_vordering == kTableViewFillTopDown)
if (_vordering == VerticalFillOrder::TOP_DOWN)
{
offset.y = this->getContainer()->getContentSize().height - offset.y - cellSize.height;
}
@ -321,7 +321,7 @@ Point TableView::__offsetFromIndex(unsigned int index)
switch (this->getDirection())
{
case kScrollViewDirectionHorizontal:
case Direction::HORIZONTAL:
offset = Point(_vCellsPositions[index], 0.0f);
break;
default:
@ -337,7 +337,7 @@ unsigned int TableView::_indexFromOffset(Point offset)
int index = 0;
const int maxIdx = _dataSource->numberOfCellsInTableView(this)-1;
if (_vordering == kTableViewFillTopDown)
if (_vordering == VerticalFillOrder::TOP_DOWN)
{
offset.y = this->getContainer()->getContentSize().height - offset.y;
}
@ -361,7 +361,7 @@ int TableView::__indexFromOffset(Point offset)
float search;
switch (this->getDirection())
{
case kScrollViewDirectionHorizontal:
case Direction::HORIZONTAL:
search = offset.x;
break;
default:
@ -433,7 +433,7 @@ void TableView::_updateCellPositions() {
cellSize = _dataSource->tableCellSizeForIndex(this, i);
switch (this->getDirection())
{
case kScrollViewDirectionHorizontal:
case Direction::HORIZONTAL:
currentPos += cellSize.width;
break;
default:
@ -462,7 +462,7 @@ void TableView::scrollViewDidScroll(ScrollView* view)
Point offset = this->getContentOffset() * -1;
maxIdx = MAX(uCountOfItems-1, 0);
if (_vordering == kTableViewFillTopDown)
if (_vordering == VerticalFillOrder::TOP_DOWN)
{
offset.y = offset.y + _viewSize.height/this->getContainer()->getScaleY();
}
@ -472,7 +472,7 @@ void TableView::scrollViewDidScroll(ScrollView* view)
startIdx = uCountOfItems - 1;
}
if (_vordering == kTableViewFillTopDown)
if (_vordering == VerticalFillOrder::TOP_DOWN)
{
offset.y -= _viewSize.height/this->getContainer()->getScaleY();
}

View File

@ -37,11 +37,6 @@ NS_CC_EXT_BEGIN
class TableView;
class ArrayForObjectSorting;
typedef enum {
kTableViewFillTopDown,
kTableViewFillBottomUp
} TableViewVerticalFillOrder;
/**
* Sole purpose of this delegate is to single touch event in this version.
*/
@ -137,6 +132,12 @@ public:
class TableView : public ScrollView, public ScrollViewDelegate
{
public:
enum class VerticalFillOrder
{
TOP_DOWN,
BOTTOM_UP
};
/**
* An intialized table view object
*
@ -174,8 +175,8 @@ public:
/**
* determines how cell is ordered and filled in the view.
*/
void setVerticalFillOrder(TableViewVerticalFillOrder order);
TableViewVerticalFillOrder getVerticalFillOrder();
void setVerticalFillOrder(VerticalFillOrder order);
VerticalFillOrder getVerticalFillOrder();
/**
* Updates the content of the cell at a given index.
@ -228,7 +229,7 @@ protected:
/**
* vertical direction of cell filling
*/
TableViewVerticalFillOrder _vordering;
VerticalFillOrder _vordering;
/**
* index set to query the indexes of the cells used.
@ -257,7 +258,7 @@ protected:
*/
TableViewDelegate* _tableViewDelegate;
ScrollViewDirection _oldDirection;
Direction _oldDirection;
int __indexFromOffset(Point offset);
unsigned int _indexFromOffset(Point offset);

View File

@ -24,17 +24,17 @@ bool TableViewTestLayer::init()
Size winSize = Director::getInstance()->getWinSize();
TableView* tableView = TableView::create(this, Size(250, 60));
tableView->setDirection(kScrollViewDirectionHorizontal);
tableView->setDirection(ScrollView::Direction::HORIZONTAL);
tableView->setPosition(Point(20,winSize.height/2-30));
tableView->setDelegate(this);
this->addChild(tableView);
tableView->reloadData();
tableView = TableView::create(this, Size(60, 250));
tableView->setDirection(kScrollViewDirectionVertical);
tableView->setDirection(ScrollView::Direction::VERTICAL);
tableView->setPosition(Point(winSize.width-150,winSize.height/2-120));
tableView->setDelegate(this);
tableView->setVerticalFillOrder(kTableViewFillTopDown);
tableView->setVerticalFillOrder(TableView::VerticalFillOrder::TOP_DOWN);
this->addChild(tableView);
tableView->reloadData();

View File

@ -591,7 +591,7 @@ static int tolua_Cocos2d_ScrollView_getDirection00(lua_State* tolua_S)
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'getDirection'", NULL);
#endif
{
ScrollViewDirection tolua_ret = (ScrollViewDirection) self->getDirection();
ScrollView::Direction tolua_ret = (ScrollView::Direction) self->getDirection();
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
}
}
@ -752,7 +752,7 @@ static int tolua_Cocos2d_ScrollView_setDirection00(lua_State* tolua_S)
#endif
{
LuaScrollView* self = (LuaScrollView*) tolua_tousertype(tolua_S,1,0);
ScrollViewDirection eDirection = ((ScrollViewDirection) (int) tolua_tonumber(tolua_S,2,0));
ScrollView::Direction eDirection = ((ScrollView::Direction) (int) tolua_tonumber(tolua_S,2,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'setDirection'", NULL);
#endif
@ -1562,10 +1562,10 @@ TOLUA_API int tolua_scroll_view_open(lua_State* tolua_S)
tolua_reg_scrollview_type(tolua_S);
tolua_module(tolua_S,NULL,0);
tolua_beginmodule(tolua_S,NULL);
tolua_constant(tolua_S,"kScrollViewDirectionNone",kScrollViewDirectionNone);
tolua_constant(tolua_S,"kScrollViewDirectionHorizontal",kScrollViewDirectionHorizontal);
tolua_constant(tolua_S,"kScrollViewDirectionVertical",kScrollViewDirectionVertical);
tolua_constant(tolua_S,"kScrollViewDirectionBoth",kScrollViewDirectionBoth);
tolua_constant(tolua_S,"kScrollViewDirectionNone",(int)ScrollView::Direction::NONE);
tolua_constant(tolua_S,"kScrollViewDirectionHorizontal",(int)ScrollView::Direction::HORIZONTAL);
tolua_constant(tolua_S,"kScrollViewDirectionVertical",(int)ScrollView::Direction::VERTICAL);
tolua_constant(tolua_S,"kScrollViewDirectionBoth",(int)ScrollView::Direction::BOTH);
tolua_constant(tolua_S,"kScrollViewScriptScroll",LuaScrollView::kScrollViewScriptScroll);
tolua_constant(tolua_S,"kScrollViewScriptZoom",LuaScrollView::kScrollViewScriptZoom);
#ifdef __cplusplus