2011-03-19 10:59:01 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010-2011 cocos2d-x.org
|
|
|
|
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"
|
|
|
|
#include "CCLayer.h"
|
|
|
|
|
|
|
|
namespace cocos2d{
|
2010-08-10 12:49:16 +08:00
|
|
|
|
2010-08-10 17:21:01 +08:00
|
|
|
typedef enum
|
|
|
|
{
|
2011-03-19 10:59:01 +08:00
|
|
|
kCCMenuStateWaiting,
|
|
|
|
kCCMenuStateTrackingTouch
|
2010-12-25 11:15:19 +08:00
|
|
|
} tCCMenuState;
|
|
|
|
|
2011-03-19 10:59:01 +08:00
|
|
|
enum {
|
|
|
|
//* priority used by the menu
|
|
|
|
kCCMenuTouchPriority = -128,
|
2010-12-25 11:15:19 +08:00
|
|
|
};
|
2010-08-10 12:49:16 +08:00
|
|
|
|
2010-09-29 09:44:57 +08:00
|
|
|
/** @brief A CCMenu
|
2010-08-10 12:49:16 +08:00
|
|
|
*
|
|
|
|
* Features and Limitation:
|
|
|
|
* - You can add MenuItem objects in runtime using addChild:
|
|
|
|
* - But the only accecpted children are MenuItem objects
|
|
|
|
*/
|
2011-03-07 17:11:57 +08:00
|
|
|
class CC_DLL CCMenu : public CCLayer, public CCRGBAProtocol
|
2010-08-10 12:49:16 +08:00
|
|
|
{
|
2011-08-17 21:19:57 +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);
|
2010-08-10 12:49:16 +08:00
|
|
|
public:
|
2011-04-01 16:06:53 +08:00
|
|
|
CCMenu()
|
|
|
|
: m_cOpacity(0)
|
|
|
|
, m_pSelectedItem(NULL)
|
|
|
|
{}
|
2010-08-10 12:49:16 +08:00
|
|
|
virtual ~CCMenu(){}
|
2011-07-28 10:45:32 +08:00
|
|
|
|
2012-02-29 10:07:18 +08:00
|
|
|
/** creates an empty CCMenu */
|
|
|
|
static CCMenu* node();
|
2011-07-28 10:45:32 +08:00
|
|
|
|
2012-02-29 10:07:18 +08:00
|
|
|
/** creates a CCMenu with it's items */
|
|
|
|
static CCMenu* menuWithItems(CCMenuItem* item, ...);
|
2011-06-20 17:31:38 +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-02-29 10:07:18 +08:00
|
|
|
static CCMenu* menuWithItem(CCMenuItem* item);
|
|
|
|
|
|
|
|
/** initializes an empty CCMenu */
|
|
|
|
bool init();
|
2011-06-20 17:31:38 +08:00
|
|
|
|
2010-08-10 12:49:16 +08:00
|
|
|
/** initializes a CCMenu with it's items */
|
2010-09-04 12:02:52 +08:00
|
|
|
bool initWithItems(CCMenuItem* item, va_list args);
|
2010-08-10 12:49:16 +08:00
|
|
|
|
|
|
|
/** align items vertically */
|
|
|
|
void alignItemsVertically();
|
|
|
|
/** align items vertically with padding
|
|
|
|
@since v0.7.2
|
|
|
|
*/
|
|
|
|
void alignItemsVerticallyWithPadding(float padding);
|
|
|
|
|
|
|
|
/** align items horizontally */
|
|
|
|
void alignItemsHorizontally();
|
|
|
|
/** align items horizontally with padding
|
|
|
|
@since v0.7.2
|
|
|
|
*/
|
|
|
|
void alignItemsHorizontallyWithPadding(float padding);
|
|
|
|
|
|
|
|
/** align items in rows of columns */
|
2010-08-10 17:21:01 +08:00
|
|
|
void alignItemsInColumns(unsigned int columns, ...);
|
|
|
|
void alignItemsInColumns(unsigned int columns, va_list args);
|
2010-08-10 12:49:16 +08:00
|
|
|
|
|
|
|
/** align items in columns of rows */
|
2010-08-10 17:21:01 +08:00
|
|
|
void alignItemsInRows(unsigned int rows, ...);
|
|
|
|
void alignItemsInRows(unsigned int rows, va_list args);
|
2010-08-10 12:49:16 +08:00
|
|
|
|
|
|
|
//super methods
|
2010-12-25 11:15:19 +08:00
|
|
|
virtual void addChild(CCNode * child, int zOrder);
|
|
|
|
virtual void addChild(CCNode * child, int zOrder, int tag);
|
2010-08-10 12:49:16 +08:00
|
|
|
virtual void registerWithTouchDispatcher();
|
2010-12-25 11:15:19 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief For phone event handle functions
|
|
|
|
*/
|
2011-03-18 09:39:34 +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);
|
2010-12-25 11:15:19 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
@since v0.99.5
|
|
|
|
override onExit
|
|
|
|
*/
|
|
|
|
virtual void onExit();
|
|
|
|
|
2011-12-28 14:46:49 +08:00
|
|
|
virtual void setIsOpacityModifyRGB(bool bValue) {CC_UNUSED_PARAM(bValue);}
|
|
|
|
virtual bool getIsOpacityModifyRGB(void) { return false;}
|
2010-08-31 11:20:37 +08:00
|
|
|
|
2010-08-10 12:49:16 +08:00
|
|
|
protected:
|
2011-07-29 03:18:45 +08:00
|
|
|
CCMenuItem* itemForTouch(CCTouch * touch);
|
2010-12-25 11:15:19 +08:00
|
|
|
tCCMenuState m_eState;
|
2012-02-29 10:07:18 +08:00
|
|
|
CCMenuItem *m_pSelectedItem;
|
2010-08-10 12:49:16 +08:00
|
|
|
};
|
2011-03-19 10:59:01 +08:00
|
|
|
}
|
|
|
|
|
2011-07-28 10:45:32 +08:00
|
|
|
#endif//__CCMENU_H_
|