-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathGridView.h
124 lines (107 loc) · 3.7 KB
/
GridView.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* =====================================================================================
*
* Filename: GridView.h
*
* Description:
*
* Version: 1.0
* Created: 2014/09/18
* Revision: none
* Compiler: gcc
*
* Author: Shuai Yuan (),
* Organization:
*
* =====================================================================================
*/
#ifndef __GRID_VIEW_H__
#define __GRID_VIEW_H__
#include "cocos2d.h"
#include "extensions/cocos-ext.h"
#include <set>
#include <vector>
class GridView : public cocos2d::extension::TableView
{
public:
/** Empty contructor of GridView */
static GridView* create();
/**
* An intialized table view object
*
* @param dataSource data source
* @param size view size
* @return table view
* @code
* when this function bound to js or lua,the input params are changed
* in js:var create(var jsObject,var size)
* in lua:local create(var size)
* in lua:
* @endcode
*/
static GridView* create(cocos2d::extension::TableViewDataSource* dataSource, cocos2d::Size size);
/**
* An initialized table view object
*
* @param dataSource data source;
* @param size view size
* @param container parent object for cells
* @return table view
* @code
* when this function bound to js or lua,the input params are changed
* in js:var create(var jsObject,var size,var container)
* in lua:local create(var size, var container)
* in lua:
* @endcode
*/
static GridView* create(cocos2d::extension::TableViewDataSource* dataSource, cocos2d::Size size, cocos2d::Node *container);
/**
* @js ctor
*/
GridView();
/**
* @js NA
* @lua NA
*/
virtual ~GridView();
bool initWithViewSize(cocos2d::Size size, Node* container = NULL);
// Overrides
virtual void scrollViewDidScroll(cocos2d::extension::ScrollView* view) override;
virtual void scrollViewDidZoom(cocos2d::extension::ScrollView* view) override {}
virtual bool onTouchBegan(cocos2d::Touch *pTouch, cocos2d::Event *pEvent) override;
virtual void onTouchMoved(cocos2d::Touch *pTouch, cocos2d::Event *pEvent) override;
virtual void onTouchEnded(cocos2d::Touch *pTouch, cocos2d::Event *pEvent) override;
virtual void onTouchCancelled(cocos2d::Touch *pTouch, cocos2d::Event *pEvent) override;
protected:
virtual long _indexFromOffset(cocos2d::Vec2 offset) override;
virtual long __indexFromOffset(cocos2d::Vec2 offset) override;
virtual cocos2d::Vec2 _offsetFromIndex(ssize_t index) override;
virtual cocos2d::Vec2 __offsetFromIndex(ssize_t index) override;
virtual void _setIndexForCell(ssize_t index, cocos2d::extension::TableViewCell *cell) override;
virtual void _updateCellPositions();
/*-----------------------------------------------------------------------------
*
*-----------------------------------------------------------------------------*/
protected:
std::vector<cocos2d::Vec2> _vCellsPositions;
cocos2d::Size _cellSize;
ssize_t _cellsCount;
int _rowNum;
int _colNum;
public:
int getRowNum() const { return _rowNum; }
void setRowNum(const int rowNum) { _rowNum = rowNum; }
int getColNum() const { return _colNum; }
void setColNum(const int colNum) { _colNum = colNum; }
public:
int maxRowIdx() const;
int maxColIdx() const;
protected:
int rowOfIndex(const long index) const;
int colOfIndex(const long index) const;
int rowFromOffset(const cocos2d::Vec2 offset) const;
int colFromOffset(const cocos2d::Vec2 offset) const;
public:
virtual void _updateContentSize();
};
#endif /* __GRID_VIEW_H__ */