2011-03-19 10:59:01 +08:00
|
|
|
/****************************************************************************
|
2012-06-14 15:13:16 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2011-03-19 10:59:01 +08:00
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
#ifndef __CCMENU_H_
|
|
|
|
#define __CCMENU_H_
|
|
|
|
|
|
|
|
#include "CCMenuItem.h"
|
2012-06-19 13:50:11 +08:00
|
|
|
#include "layers_scenes_transitions_nodes/CCLayer.h"
|
2011-03-19 10:59:01 +08:00
|
|
|
|
2012-03-22 14:22:06 +08:00
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup GUI
|
|
|
|
* @{
|
|
|
|
* @addtogroup menu
|
|
|
|
* @{
|
|
|
|
*/
|
2012-03-22 14:22:06 +08:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
kCCMenuStateWaiting,
|
|
|
|
kCCMenuStateTrackingTouch
|
|
|
|
} tCCMenuState;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
//* priority used by the menu for the event handler
|
|
|
|
kCCMenuHandlerPriority = -128,
|
|
|
|
};
|
|
|
|
|
|
|
|
/** @brief A CCMenu
|
|
|
|
*
|
|
|
|
* Features and Limitation:
|
|
|
|
* - You can add MenuItem objects in runtime using addChild:
|
2012-09-17 15:02:24 +08:00
|
|
|
* - But the only accepted children are MenuItem objects
|
2012-03-22 14:22:06 +08:00
|
|
|
*/
|
|
|
|
class CC_DLL CCMenu : public CCLayer, public CCRGBAProtocol
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
/** Color: conforms with CCRGBAProtocol protocol */
|
|
|
|
CC_PROPERTY_PASS_BY_REF(ccColor3B, m_tColor, Color);
|
|
|
|
/** Opacity: conforms with CCRGBAProtocol protocol */
|
|
|
|
CC_PROPERTY(GLubyte, m_cOpacity, Opacity);
|
|
|
|
/** whether or not the menu will receive events */
|
2012-06-15 15:10:40 +08:00
|
|
|
bool m_bEnabled;
|
|
|
|
|
2012-03-22 14:22:06 +08:00
|
|
|
public:
|
2012-04-19 14:35:52 +08:00
|
|
|
CCMenu()
|
|
|
|
: m_cOpacity(0)
|
|
|
|
, m_pSelectedItem(NULL)
|
|
|
|
{}
|
|
|
|
virtual ~CCMenu(){}
|
2012-03-22 14:22:06 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
/** creates an empty CCMenu
|
2012-06-20 14:31:36 +08:00
|
|
|
@deprecated: This interface will be deprecated sooner or later.
|
2012-06-14 15:13:16 +08:00
|
|
|
*/
|
2012-06-20 11:48:31 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE static CCMenu* node();
|
2012-06-14 15:13:16 +08:00
|
|
|
|
|
|
|
/** creates a CCMenu with it's items
|
2012-06-20 14:31:36 +08:00
|
|
|
@deprecated: This interface will be deprecated sooner or later.
|
2012-06-14 15:13:16 +08:00
|
|
|
*/
|
2012-06-20 11:48:31 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE static CCMenu* menuWithItems(CCMenuItem* item, ...);
|
2012-06-14 15:13:16 +08:00
|
|
|
|
|
|
|
/** creates a CCMenu with a NSArray of CCMenuItem objects
|
2012-06-20 14:31:36 +08:00
|
|
|
@deprecated: This interface will be deprecated sooner or later.
|
2012-06-14 15:13:16 +08:00
|
|
|
*/
|
2012-06-20 11:48:31 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE static CCMenu* menuWithArray(CCArray* pArrayOfItems);
|
2012-06-14 15:13:16 +08:00
|
|
|
|
|
|
|
/** creates a CCMenu with it's item, then use addChild() to add
|
|
|
|
* other items. It is used for script, it can't init with undetermined
|
|
|
|
* number of variables.
|
2012-06-20 14:31:36 +08:00
|
|
|
@deprecated: This interface will be deprecated sooner or later.
|
2012-06-14 15:13:16 +08:00
|
|
|
*/
|
2012-06-20 11:48:31 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE static CCMenu* menuWithItem(CCMenuItem* item);
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2012-03-22 14:22:06 +08:00
|
|
|
/** creates an empty CCMenu */
|
2012-06-14 15:13:16 +08:00
|
|
|
static CCMenu* create();
|
2012-03-22 14:22:06 +08:00
|
|
|
|
2012-11-14 18:05:15 +08:00
|
|
|
/** creates a CCMenu with CCMenuItem objects */
|
2012-06-14 15:13:16 +08:00
|
|
|
static CCMenu* create(CCMenuItem* item, ...);
|
2012-03-22 14:22:06 +08:00
|
|
|
|
2012-06-27 14:21:29 +08:00
|
|
|
/** creates a CCMenu with a CCArray of CCMenuItem objects */
|
2012-07-23 22:49:11 +08:00
|
|
|
static CCMenu* createWithArray(CCArray* pArrayOfItems);
|
2012-03-22 14:22:06 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** creates a CCMenu with it's item, then use addChild() to add
|
|
|
|
* other items. It is used for script, it can't init with undetermined
|
|
|
|
* number of variables.
|
|
|
|
*/
|
2012-06-14 15:13:16 +08:00
|
|
|
static CCMenu* createWithItem(CCMenuItem* item);
|
2012-11-14 18:05:15 +08:00
|
|
|
|
|
|
|
/** creates a CCMenu with CCMenuItem objects */
|
|
|
|
static CCMenu* createWithItems(CCMenuItem *firstItem, va_list args);
|
2012-03-22 14:22:06 +08:00
|
|
|
|
|
|
|
/** initializes an empty CCMenu */
|
|
|
|
bool init();
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** initializes a CCMenu with a NSArray of CCMenuItem objects */
|
|
|
|
bool initWithArray(CCArray* pArrayOfItems);
|
2012-03-22 14:22:06 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** align items vertically */
|
|
|
|
void alignItemsVertically();
|
|
|
|
/** align items vertically with padding
|
|
|
|
@since v0.7.2
|
|
|
|
*/
|
|
|
|
void alignItemsVerticallyWithPadding(float padding);
|
2012-03-22 14:22:06 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** align items horizontally */
|
|
|
|
void alignItemsHorizontally();
|
|
|
|
/** align items horizontally with padding
|
|
|
|
@since v0.7.2
|
|
|
|
*/
|
|
|
|
void alignItemsHorizontallyWithPadding(float padding);
|
2012-03-22 14:22:06 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** align items in rows of columns */
|
|
|
|
void alignItemsInColumns(unsigned int columns, ...);
|
|
|
|
void alignItemsInColumns(unsigned int columns, va_list args);
|
2012-11-30 21:13:25 +08:00
|
|
|
void alignItemsInColumnsWithArray(CCArray* rows);
|
2012-03-22 14:22:06 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** align items in columns of rows */
|
|
|
|
void alignItemsInRows(unsigned int rows, ...);
|
|
|
|
void alignItemsInRows(unsigned int rows, va_list args);
|
2012-11-30 21:13:25 +08:00
|
|
|
void alignItemsInRowsWithArray(CCArray* columns);
|
2012-03-22 14:22:06 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** set event handler priority. By default it is: kCCMenuTouchPriority */
|
2012-06-06 15:16:02 +08:00
|
|
|
void setHandlerPriority(int newPriority);
|
2012-03-22 14:22:06 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
//super methods
|
|
|
|
virtual void addChild(CCNode * child);
|
|
|
|
virtual void addChild(CCNode * child, int zOrder);
|
|
|
|
virtual void addChild(CCNode * child, int zOrder, int tag);
|
|
|
|
virtual void registerWithTouchDispatcher();
|
2012-03-22 14:22:06 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief For phone event handle functions
|
|
|
|
*/
|
2012-04-19 14:35:52 +08:00
|
|
|
virtual bool ccTouchBegan(CCTouch* touch, CCEvent* event);
|
|
|
|
virtual void ccTouchEnded(CCTouch* touch, CCEvent* event);
|
|
|
|
virtual void ccTouchCancelled(CCTouch *touch, CCEvent* event);
|
|
|
|
virtual void ccTouchMoved(CCTouch* touch, CCEvent* event);
|
2012-03-22 14:22:06 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
@since v0.99.5
|
|
|
|
override onExit
|
|
|
|
*/
|
|
|
|
virtual void onExit();
|
|
|
|
|
2012-06-15 15:10:40 +08:00
|
|
|
virtual void setOpacityModifyRGB(bool bValue) {CC_UNUSED_PARAM(bValue);}
|
|
|
|
virtual bool isOpacityModifyRGB(void) { return false;}
|
|
|
|
|
|
|
|
virtual bool isEnabled() { return m_bEnabled; }
|
|
|
|
virtual void setEnabled(bool value) { m_bEnabled = value; };
|
2012-03-22 14:22:06 +08:00
|
|
|
|
|
|
|
protected:
|
2012-04-19 14:35:52 +08:00
|
|
|
CCMenuItem* itemForTouch(CCTouch * touch);
|
|
|
|
tCCMenuState m_eState;
|
|
|
|
CCMenuItem *m_pSelectedItem;
|
2012-03-22 14:22:06 +08:00
|
|
|
};
|
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
// end of GUI group
|
|
|
|
/// @}
|
|
|
|
/// @}
|
|
|
|
|
2012-03-22 14:22:06 +08:00
|
|
|
NS_CC_END
|
2011-03-19 10:59:01 +08:00
|
|
|
|
2011-07-28 10:45:32 +08:00
|
|
|
#endif//__CCMENU_H_
|