2011-03-19 10:59:01 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
2011-03-19 10:59:01 +08:00
|
|
|
|
|
|
|
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_
|
|
|
|
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "2d/CCMenuItem.h"
|
|
|
|
#include "2d/CCLayer.h"
|
2014-04-27 01:35:57 +08:00
|
|
|
#include "base/CCValue.h"
|
2013-09-03 18:22:03 +08:00
|
|
|
|
2012-03-22 14:22:06 +08:00
|
|
|
NS_CC_BEGIN
|
2014-08-27 13:39:50 +08:00
|
|
|
class Touch;
|
2012-03-22 14:22:06 +08:00
|
|
|
|
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();
|
2014-03-25 06:09:24 +08:00
|
|
|
|
2014-04-20 00:25:54 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
2014-03-25 06:09:24 +08:00
|
|
|
// WP8 in VS2012 does not support nullptr in variable args lists and variadic templates are also not supported
|
|
|
|
typedef MenuItem* M;
|
|
|
|
static Menu* create(M m1, std::nullptr_t listEnd) { return variadicCreate(m1, NULL); }
|
|
|
|
static Menu* create(M m1, M m2, std::nullptr_t listEnd) { return variadicCreate(m1, m2, NULL); }
|
|
|
|
static Menu* create(M m1, M m2, M m3, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, NULL); }
|
|
|
|
static Menu* create(M m1, M m2, M m3, M m4, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, NULL); }
|
|
|
|
static Menu* create(M m1, M m2, M m3, M m4, M m5, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, m5, NULL); }
|
|
|
|
static Menu* create(M m1, M m2, M m3, M m4, M m5, M m6, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, m5, m6, NULL); }
|
|
|
|
static Menu* create(M m1, M m2, M m3, M m4, M m5, M m6, M m7, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, m5, m6, m7, NULL); }
|
|
|
|
static Menu* create(M m1, M m2, M m3, M m4, M m5, M m6, M m7, M m8, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, m5, m6, m7, m8, NULL); }
|
|
|
|
static Menu* create(M m1, M m2, M m3, M m4, M m5, M m6, M m7, M m8, M m9, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, m5, m6, m7, m8, m9, NULL); }
|
|
|
|
static Menu* create(M m1, M m2, M m3, M m4, M m5, M m6, M m7, M m8, M m9, M m10, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, NULL); }
|
|
|
|
|
|
|
|
// On WP8 for lists longer than 10 items, use createWithArray or variadicCreate with NULL as the last argument
|
|
|
|
static Menu* variadicCreate(MenuItem* item, ...);
|
|
|
|
#else
|
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;
|
2014-03-25 06:09:24 +08:00
|
|
|
#endif
|
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;
|
2014-06-25 11:27:48 +08:00
|
|
|
virtual void addChild(Node * child, int zOrder, const std::string &name) 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;
|
|
|
|
|
2014-03-21 13:44:29 +08:00
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
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
|
|
|
|
2014-03-21 13:44:29 +08:00
|
|
|
protected:
|
2014-03-25 06:09:24 +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_
|