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
|
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
kMenuStateWaiting,
|
|
|
|
kMenuStateTrackingTouch
|
|
|
|
} tMenuState;
|
2012-03-22 14:22:06 +08:00
|
|
|
|
|
|
|
enum {
|
|
|
|
//* priority used by the menu for the event handler
|
2013-06-20 14:13:12 +08:00
|
|
|
kMenuHandlerPriority = -128,
|
2012-03-22 14:22:06 +08:00
|
|
|
};
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** @brief A Menu
|
2012-03-22 14:22:06 +08:00
|
|
|
*
|
|
|
|
* 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
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
class CC_DLL Menu : public LayerRGBA
|
2012-03-22 14:22:06 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
/** whether or not the menu will receive events */
|
2013-06-15 14:03:30 +08:00
|
|
|
bool _enabled;
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2012-03-22 14:22:06 +08:00
|
|
|
public:
|
2013-06-20 14:13:12 +08:00
|
|
|
Menu() : _selectedItem(NULL) {}
|
|
|
|
virtual ~Menu(){}
|
2012-03-22 14:22:06 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** creates an empty Menu */
|
|
|
|
static Menu* create();
|
2012-03-22 14:22:06 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** creates a Menu with MenuItem objects */
|
|
|
|
static Menu* create(MenuItem* item, ...);
|
2012-03-22 14:22:06 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** creates a Menu with a Array of MenuItem objects */
|
|
|
|
static Menu* createWithArray(Array* pArrayOfItems);
|
2012-03-22 14:22:06 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** creates a Menu with it's item, then use addChild() to add
|
2012-04-19 14:35:52 +08:00
|
|
|
* other items. It is used for script, it can't init with undetermined
|
|
|
|
* number of variables.
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
static Menu* createWithItem(MenuItem* item);
|
2012-11-14 18:05:15 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** creates a Menu with MenuItem objects */
|
|
|
|
static Menu* createWithItems(MenuItem *firstItem, va_list args);
|
2012-03-22 14:22:06 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** initializes an empty Menu */
|
2012-03-22 14:22:06 +08:00
|
|
|
bool init();
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** initializes a Menu with a NSArray of MenuItem objects */
|
|
|
|
bool initWithArray(Array* 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);
|
2013-06-20 14:13:12 +08:00
|
|
|
void alignItemsInColumnsWithArray(Array* 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);
|
2013-06-20 14:13:12 +08:00
|
|
|
void alignItemsInRowsWithArray(Array* columns);
|
2012-03-22 14:22:06 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** set event handler priority. By default it is: kMenuTouchPriority */
|
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
|
2013-06-20 14:13:12 +08:00
|
|
|
virtual void addChild(Node * child);
|
|
|
|
virtual void addChild(Node * child, int zOrder);
|
|
|
|
virtual void addChild(Node * child, int zOrder, int tag);
|
2012-04-19 14:35:52 +08:00
|
|
|
virtual void registerWithTouchDispatcher();
|
2013-06-20 14:13:12 +08:00
|
|
|
virtual void removeChild(Node* child, bool cleanup);
|
2012-03-22 14:22:06 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
@brief For phone event handle functions
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
virtual bool ccTouchBegan(Touch* touch, Event* event);
|
|
|
|
virtual void ccTouchEnded(Touch* touch, Event* event);
|
|
|
|
virtual void ccTouchCancelled(Touch *touch, Event* event);
|
|
|
|
virtual void ccTouchMoved(Touch* touch, Event* 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);}
|
2013-07-05 15:06:38 +08:00
|
|
|
virtual bool isOpacityModifyRGB(void) const { return false;}
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2013-07-07 13:01:21 +08:00
|
|
|
virtual bool isEnabled() const { return _enabled; }
|
2013-06-15 14:03:30 +08:00
|
|
|
virtual void setEnabled(bool value) { _enabled = value; };
|
2012-03-22 14:22:06 +08:00
|
|
|
|
|
|
|
protected:
|
2013-06-20 14:13:12 +08:00
|
|
|
MenuItem* itemForTouch(Touch * touch);
|
|
|
|
tMenuState _state;
|
|
|
|
MenuItem *_selectedItem;
|
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_
|