1
|
|
2
|
Copyright (c) 2008-2010 Ricardo Quesada
|
3
|
Copyright (c) 2010-2012 cocos2d-x.org
|
4
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
5
|
|
6
|
http://www.cocos2d-x.org
|
7
|
|
8
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
of this software and associated documentation files (the "Software"), to deal
|
10
|
in the Software without restriction, including without limitation the rights
|
11
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12
|
copies of the Software, and to permit persons to whom the Software is
|
13
|
furnished to do so, subject to the following conditions:
|
14
|
|
15
|
The above copyright notice and this permission notice shall be included in
|
16
|
all copies or substantial portions of the Software.
|
17
|
|
18
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
THE SOFTWARE.
|
25
|
****************************************************************************/
|
26
|
#ifndef __CCMENU_H_
|
27
|
#define __CCMENU_H_
|
28
|
|
29
|
#include "CCMenuItem.h"
|
30
|
#include "CCLayer.h"
|
31
|
#include "CCVector.h"
|
32
|
#include "CCEventTouch.h"
|
33
|
#include "CCValue.h"
|
34
|
|
35
|
NS_CC_BEGIN
|
36
|
|
37
|
|
38
|
* @addtogroup GUI
|
39
|
* @{
|
40
|
* @addtogroup menu
|
41
|
* @{
|
42
|
*/
|
43
|
|
44
|
|
45
|
|
46
|
|
47
|
*
|
48
|
* Features and Limitation:
|
49
|
* - You can add MenuItem objects in runtime using addChild:
|
50
|
* - But the only accepted children are MenuItem objects
|
51
|
*/
|
52
|
class CC_DLL Menu : public Layer
|
53
|
{
|
54
|
public:
|
55
|
enum class State
|
56
|
{
|
57
|
WAITING,
|
58
|
TRACKING_TOUCH,
|
59
|
};
|
60
|
|
61
|
|
62
|
static Menu* create();
|
63
|
|
64
|
|
65
|
static Menu* create(MenuItem* item, ...) CC_REQUIRES_NULL_TERMINATION;
|
66
|
|
67
|
|
68
|
static Menu* createWithArray(const Vector<MenuItem*>& arrayOfItems);
|
69
|
|
70
|
|
71
|
* other items. It is used for script, it can't init with undetermined
|
72
|
* number of variables.
|
73
|
*/
|
74
|
static Menu* createWithItem(MenuItem* item);
|
75
|
|
76
|
|
77
|
static Menu* createWithItems(MenuItem *firstItem, va_list args);
|
78
|
|
79
|
|
80
|
void alignItemsVertically();
|
81
|
|
82
|
@since v0.7.2
|
83
|
*/
|
84
|
void alignItemsVerticallyWithPadding(float padding);
|
85
|
|
86
|
|
87
|
void alignItemsHorizontally();
|
88
|
|
89
|
@since v0.7.2
|
90
|
*/
|
91
|
void alignItemsHorizontallyWithPadding(float padding);
|
92
|
|
93
|
|
94
|
void alignItemsInColumns(int columns, ...) CC_REQUIRES_NULL_TERMINATION;
|
95
|
void alignItemsInColumns(int columns, va_list args);
|
96
|
void alignItemsInColumnsWithArray(const ValueVector& rows);
|
97
|
|
98
|
|
99
|
void alignItemsInRows(int rows, ...) CC_REQUIRES_NULL_TERMINATION;
|
100
|
void alignItemsInRows(int rows, va_list args);
|
101
|
void alignItemsInRowsWithArray(const ValueVector& columns);
|
102
|
|
103
|
virtual bool isEnabled() const { return _enabled; }
|
104
|
virtual void setEnabled(bool value) { _enabled = value; };
|
105
|
|
106
|
virtual bool onTouchBegan(Touch* touch, Event* event);
|
107
|
virtual void onTouchEnded(Touch* touch, Event* event);
|
108
|
virtual void onTouchCancelled(Touch* touch, Event* event);
|
109
|
virtual void onTouchMoved(Touch* touch, Event* event);
|
110
|
|
111
|
|
112
|
virtual void removeChild(Node* child, bool cleanup) override;
|
113
|
|
114
|
virtual void addChild(Node * child) override;
|
115
|
virtual void addChild(Node * child, int zOrder) override;
|
116
|
virtual void addChild(Node * child, int zOrder, int tag) override;
|
117
|
|
118
|
virtual void onEnter() override;
|
119
|
virtual void onExit() override;
|
120
|
virtual void setOpacityModifyRGB(bool bValue) override {CC_UNUSED_PARAM(bValue);}
|
121
|
virtual bool isOpacityModifyRGB(void) const override { return false;}
|
122
|
|
123
|
virtual std::string getDescription() const override;
|
124
|
|
125
|
protected:
|
126
|
|
127
|
* @js ctor
|
128
|
*/
|
129
|
Menu() : _selectedItem(nullptr) {}
|
130
|
virtual ~Menu();
|
131
|
|
132
|
|
133
|
bool init();
|
134
|
|
135
|
|
136
|
bool initWithArray(const Vector<MenuItem*>& arrayOfItems);
|
137
|
|
138
|
|
139
|
virtual void addTouchEvent();
|
140
|
|
141
|
|
142
|
bool _enabled;
|
143
|
|
144
|
MenuItem* getItemForTouch(Touch * touch);
|
145
|
State _state;
|
146
|
MenuItem *_selectedItem;
|
147
|
|
148
|
private:
|
149
|
CC_DISALLOW_COPY_AND_ASSIGN(Menu);
|
150
|
};
|
151
|
|
152
|
|
153
|
|
154
|
|
155
|
|
156
|
NS_CC_END
|
157
|
|
158
|
#endif
|