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"
|
2013-10-14 14:01:00 +08:00
|
|
|
#include "CCLayer.h"
|
2013-11-28 16:02:03 +08:00
|
|
|
#include "CCVector.h"
|
2013-10-14 14:01:00 +08:00
|
|
|
#include "CCEventTouch.h"
|
2013-12-03 17:15:48 +08:00
|
|
|
#include "CCValue.h"
|
2013-09-03 18:22:03 +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
|
|
|
|
2013-07-25 20:04:24 +08:00
|
|
|
|
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-12-06 18:07:16 +08:00
|
|
|
class CC_DLL Menu : public Layer
|
2012-03-22 14:22:06 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-07-26 08:47:42 +08:00
|
|
|
enum class State
|
2013-07-25 20:04:24 +08:00
|
|
|
{
|
2013-07-26 08:47:42 +08:00
|
|
|
WAITING,
|
|
|
|
TRACKING_TOUCH,
|
2013-07-25 20:04:24 +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 */
|
2013-07-24 06:20:22 +08:00
|
|
|
static Menu* create(MenuItem* item, ...) CC_REQUIRES_NULL_TERMINATION;
|
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 */
|
2013-11-28 16:02:03 +08:00
|
|
|
static Menu* createWithArray(const Vector<MenuItem*>& arrayOfItems);
|
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
|
|
|
|
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 */
|
2013-07-24 06:20:22 +08:00
|
|
|
void alignItemsInColumns(int columns, ...) CC_REQUIRES_NULL_TERMINATION;
|
2013-07-20 13:01:27 +08:00
|
|
|
void alignItemsInColumns(int columns, va_list args);
|
2013-12-04 17:46:57 +08:00
|
|
|
void alignItemsInColumnsWithArray(const ValueVector& rows);
|
2012-03-22 14:22:06 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** align items in columns of rows */
|
2013-07-24 06:20:22 +08:00
|
|
|
void alignItemsInRows(int rows, ...) CC_REQUIRES_NULL_TERMINATION;
|
2013-07-20 13:01:27 +08:00
|
|
|
void alignItemsInRows(int rows, va_list args);
|
2013-12-04 17:46:57 +08:00
|
|
|
void alignItemsInRowsWithArray(const ValueVector& columns);
|
2012-03-22 14:22:06 +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
|
|
|
|
2013-10-23 16:14:03 +08:00
|
|
|
virtual bool onTouchBegan(Touch* touch, Event* event);
|
|
|
|
virtual void onTouchEnded(Touch* touch, Event* event);
|
|
|
|
virtual void onTouchCancelled(Touch* touch, Event* event);
|
|
|
|
virtual void onTouchMoved(Touch* touch, Event* event);
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
// overrides
|
2013-09-16 22:20:01 +08:00
|
|
|
virtual void removeChild(Node* child, bool cleanup) override;
|
2013-09-03 18:22:03 +08:00
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual void addChild(Node * child) override;
|
|
|
|
virtual void addChild(Node * child, int zOrder) override;
|
|
|
|
virtual void addChild(Node * child, int zOrder, int tag) override;
|
2013-09-03 18:22:03 +08:00
|
|
|
|
|
|
|
virtual void onEnter() override;
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual void onExit() override;
|
|
|
|
virtual void setOpacityModifyRGB(bool bValue) override {CC_UNUSED_PARAM(bValue);}
|
|
|
|
virtual bool isOpacityModifyRGB(void) const override { return false;}
|
|
|
|
|
2013-12-13 06:30:22 +08:00
|
|
|
virtual std::string getDescription() const override;
|
|
|
|
|
2012-03-22 14:22:06 +08:00
|
|
|
protected:
|
2013-11-16 05:14:12 +08:00
|
|
|
/**
|
|
|
|
* @js ctor
|
|
|
|
*/
|
2013-12-18 17:47:20 +08:00
|
|
|
Menu() : _selectedItem(nullptr) {}
|
2013-11-16 05:14:12 +08:00
|
|
|
virtual ~Menu();
|
|
|
|
|
|
|
|
/** initializes an empty Menu */
|
|
|
|
bool init();
|
|
|
|
|
|
|
|
/** initializes a Menu with a NSArray of MenuItem objects */
|
2013-11-28 16:02:03 +08:00
|
|
|
bool initWithArray(const Vector<MenuItem*>& arrayOfItems);
|
2013-11-16 05:14:12 +08:00
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
/** whether or not the menu will receive events */
|
|
|
|
bool _enabled;
|
|
|
|
|
2013-12-03 17:15:48 +08:00
|
|
|
MenuItem* getItemForTouch(Touch * touch);
|
2013-07-25 20:04:24 +08:00
|
|
|
State _state;
|
2013-06-20 14:13:12 +08:00
|
|
|
MenuItem *_selectedItem;
|
2013-11-16 05:14:12 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
CC_DISALLOW_COPY_AND_ASSIGN(Menu);
|
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_
|