2012-02-01 16:45:23 +08:00
|
|
|
/****************************************************************************
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
2012-06-14 15:13:16 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2012-02-01 16:45:23 +08:00
|
|
|
Copyright (c) 2011 Zynga Inc.
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
2012-02-01 16:45:23 +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.
|
|
|
|
****************************************************************************/
|
2012-06-19 16:20:46 +08:00
|
|
|
|
2012-02-01 16:45:23 +08:00
|
|
|
#include "CCMenuItem.h"
|
2013-10-14 14:01:00 +08:00
|
|
|
#include "CCActionInterval.h"
|
|
|
|
#include "CCSprite.h"
|
|
|
|
#include "CCLabelAtlas.h"
|
2014-03-14 17:36:05 +08:00
|
|
|
#include "CCLabel.h"
|
2013-10-14 14:01:00 +08:00
|
|
|
#include "CCScriptSupport.h"
|
2014-04-09 22:30:49 +08:00
|
|
|
#include "deprecated/CCString.h"
|
2012-02-01 16:45:23 +08:00
|
|
|
#include <stdarg.h>
|
2012-06-19 16:20:46 +08:00
|
|
|
#include <cstring>
|
2012-02-01 16:45:23 +08:00
|
|
|
|
2013-07-25 15:03:44 +08:00
|
|
|
#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
|
|
|
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
|
|
|
#elif _MSC_VER >= 1400 //vs 2005 or higher
|
|
|
|
#pragma warning (push)
|
|
|
|
#pragma warning (disable: 4996)
|
|
|
|
#endif
|
|
|
|
|
2012-03-20 15:04:53 +08:00
|
|
|
NS_CC_BEGIN
|
2012-02-02 10:39:36 +08:00
|
|
|
|
2013-12-06 16:32:06 +08:00
|
|
|
static int _globalFontSize = kItemSize;
|
2013-02-27 17:23:39 +08:00
|
|
|
static std::string _globalFontName = "Marker Felt";
|
|
|
|
static bool _globalFontNameRelease = false;
|
2012-03-20 15:04:53 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
const unsigned int kCurrentItem = 0xc0c05001;
|
|
|
|
const unsigned int kZoomActionTag = 0xc0c05002;
|
2012-03-20 15:04:53 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
const unsigned int kNormalTag = 0x1;
|
|
|
|
const unsigned int kSelectedTag = 0x2;
|
|
|
|
const unsigned int kDisableTag = 0x3;
|
2012-03-20 15:04:53 +08:00
|
|
|
//
|
2013-06-20 14:13:12 +08:00
|
|
|
// MenuItem
|
2012-03-20 15:04:53 +08:00
|
|
|
//
|
2012-07-19 05:40:09 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
MenuItem* MenuItem::create()
|
2012-07-18 08:08:45 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return MenuItem::create((const ccMenuCallback&)nullptr);
|
2012-07-18 08:08:45 +08:00
|
|
|
}
|
|
|
|
|
2013-06-05 09:29:26 +08:00
|
|
|
// XXX deprecated
|
2014-02-20 10:53:49 +08:00
|
|
|
MenuItem* MenuItem::create(Ref *target, SEL_MenuHandler selector)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-11-07 09:05:13 +08:00
|
|
|
MenuItem *ret = new MenuItem();
|
|
|
|
ret->initWithTarget(target, selector);
|
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
MenuItem* MenuItem::create( const ccMenuCallback& callback)
|
2013-06-05 09:29:26 +08:00
|
|
|
{
|
2013-11-07 09:05:13 +08:00
|
|
|
MenuItem *ret = new MenuItem();
|
|
|
|
ret->initWithCallback(callback);
|
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
2013-06-05 09:29:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// XXX deprecated
|
2014-02-20 10:53:49 +08:00
|
|
|
bool MenuItem::initWithTarget(cocos2d::Ref *target, SEL_MenuHandler selector )
|
2013-06-05 09:29:26 +08:00
|
|
|
{
|
|
|
|
_target = target;
|
|
|
|
CC_SAFE_RETAIN(_target);
|
|
|
|
return initWithCallback( std::bind(selector,target, std::placeholders::_1) );
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool MenuItem::initWithCallback(const ccMenuCallback& callback)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2014-04-15 18:13:57 +08:00
|
|
|
setAnchorPoint(Vector2(0.5f, 0.5f));
|
2013-06-05 09:29:26 +08:00
|
|
|
_callback = callback;
|
2013-06-15 14:03:30 +08:00
|
|
|
_enabled = true;
|
|
|
|
_selected = false;
|
2012-03-20 15:04:53 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
MenuItem::~MenuItem()
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-06-05 09:29:26 +08:00
|
|
|
CC_SAFE_RELEASE(_target);
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void MenuItem::selected()
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_selected = true;
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void MenuItem::unselected()
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_selected = false;
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void MenuItem::activate()
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_enabled)
|
2012-02-02 10:39:36 +08:00
|
|
|
{
|
2013-06-05 09:29:26 +08:00
|
|
|
if( _callback )
|
2012-02-01 16:45:23 +08:00
|
|
|
{
|
2013-06-05 09:29:26 +08:00
|
|
|
_callback(this);
|
2012-02-01 16:45:23 +08:00
|
|
|
}
|
2014-02-20 16:40:46 +08:00
|
|
|
#if CC_ENABLE_SCRIPT_BINDING
|
2013-07-22 17:12:53 +08:00
|
|
|
if (kScriptTypeNone != _scriptType)
|
2013-07-02 15:23:51 +08:00
|
|
|
{
|
2013-07-22 17:12:53 +08:00
|
|
|
BasicScriptData data(this);
|
2013-07-04 15:44:42 +08:00
|
|
|
ScriptEvent scriptEvent(kMenuClickedEvent,&data);
|
2013-07-22 17:24:54 +08:00
|
|
|
ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&scriptEvent);
|
2013-07-02 15:23:51 +08:00
|
|
|
}
|
2014-02-20 16:40:46 +08:00
|
|
|
#endif
|
2012-02-02 10:39:36 +08:00
|
|
|
}
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void MenuItem::setEnabled(bool enabled)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_enabled = enabled;
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
|
|
|
|
2013-07-04 12:50:17 +08:00
|
|
|
bool MenuItem::isEnabled() const
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _enabled;
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
Rect MenuItem::rect() const
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-07-12 14:30:26 +08:00
|
|
|
return Rect( _position.x - _contentSize.width * _anchorPoint.x,
|
2013-06-15 14:03:30 +08:00
|
|
|
_position.y - _contentSize.height * _anchorPoint.y,
|
|
|
|
_contentSize.width, _contentSize.height);
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
|
|
|
|
2013-07-04 12:50:17 +08:00
|
|
|
bool MenuItem::isSelected() const
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _selected;
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
|
|
|
|
2013-06-06 08:51:40 +08:00
|
|
|
// XXX deprecated
|
2014-02-20 10:53:49 +08:00
|
|
|
void MenuItem::setTarget(Ref *target, SEL_MenuHandler selector)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-06-05 09:29:26 +08:00
|
|
|
_target = target;
|
|
|
|
CC_SAFE_RETAIN(_target);
|
|
|
|
setCallback( std::bind( selector, target, std::placeholders::_1) );
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void MenuItem::setCallback(const ccMenuCallback& callback)
|
2013-06-05 09:29:26 +08:00
|
|
|
{
|
|
|
|
_callback = callback;
|
|
|
|
}
|
|
|
|
|
2013-12-13 06:30:22 +08:00
|
|
|
std::string MenuItem::getDescription() const
|
|
|
|
{
|
|
|
|
return StringUtils::format("<MenuItem | tag = %d>", _tag);
|
|
|
|
}
|
2013-06-05 09:29:26 +08:00
|
|
|
|
2012-03-20 15:04:53 +08:00
|
|
|
//
|
|
|
|
//CCMenuItemLabel
|
|
|
|
//
|
2012-07-19 05:40:09 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void MenuItemLabel::setLabel(Node* var)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
|
|
|
if (var)
|
|
|
|
{
|
2014-04-15 18:13:57 +08:00
|
|
|
var->setAnchorPoint(Vector2::ANCHOR_BOTTOM_LEFT);
|
2014-03-25 09:58:16 +08:00
|
|
|
setContentSize(var->getContentSize());
|
2012-03-20 15:04:53 +08:00
|
|
|
addChild(var);
|
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_label)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
removeChild(_label, true);
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_label = var;
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-06-05 09:29:26 +08:00
|
|
|
// XXX: deprecated
|
2014-02-20 10:53:49 +08:00
|
|
|
MenuItemLabel * MenuItemLabel::create(Node*label, Ref* target, SEL_MenuHandler selector)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-11-07 09:05:13 +08:00
|
|
|
MenuItemLabel *ret = new MenuItemLabel();
|
|
|
|
ret->initWithLabel(label, target, selector);
|
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
MenuItemLabel * MenuItemLabel::create(Node*label, const ccMenuCallback& callback)
|
2013-06-05 09:29:26 +08:00
|
|
|
{
|
2013-11-07 09:05:13 +08:00
|
|
|
MenuItemLabel *ret = new MenuItemLabel();
|
|
|
|
ret->initWithLabel(label, callback);
|
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
2013-06-05 09:29:26 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
MenuItemLabel* MenuItemLabel::create(Node *label)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-11-07 09:05:13 +08:00
|
|
|
MenuItemLabel *ret = new MenuItemLabel();
|
|
|
|
ret->initWithLabel(label, (const ccMenuCallback&) nullptr);
|
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-06-05 09:29:26 +08:00
|
|
|
// XXX: deprecated
|
2014-02-20 10:53:49 +08:00
|
|
|
bool MenuItemLabel::initWithLabel(Node* label, Ref* target, SEL_MenuHandler selector)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-06-05 09:29:26 +08:00
|
|
|
_target = target;
|
|
|
|
CC_SAFE_RETAIN(_target);
|
|
|
|
return initWithLabel(label, std::bind(selector,target, std::placeholders::_1) );
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool MenuItemLabel::initWithLabel(Node* label, const ccMenuCallback& callback)
|
2013-06-05 09:29:26 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
MenuItem::initWithCallback(callback);
|
2013-06-15 14:03:30 +08:00
|
|
|
_originalScale = 1.0f;
|
2013-07-08 18:11:32 +08:00
|
|
|
_colorBackup = Color3B::WHITE;
|
2013-07-05 16:49:22 +08:00
|
|
|
setDisabledColor(Color3B(126,126,126));
|
2012-03-20 15:04:53 +08:00
|
|
|
this->setLabel(label);
|
2013-06-05 09:29:26 +08:00
|
|
|
|
2013-02-27 17:23:39 +08:00
|
|
|
setCascadeColorEnabled(true);
|
|
|
|
setCascadeOpacityEnabled(true);
|
2013-06-05 09:29:26 +08:00
|
|
|
|
2012-03-20 15:04:53 +08:00
|
|
|
return true;
|
|
|
|
}
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-06-05 09:29:26 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
MenuItemLabel::~MenuItemLabel()
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
|
|
|
}
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-11-07 09:05:13 +08:00
|
|
|
void MenuItemLabel::setString(const std::string& label)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
dynamic_cast<LabelProtocol*>(_label)->setString(label);
|
2013-06-15 14:03:30 +08:00
|
|
|
this->setContentSize(_label->getContentSize());
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void MenuItemLabel::activate()
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if(_enabled)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
|
|
|
this->stopAllActions();
|
2013-06-15 14:03:30 +08:00
|
|
|
this->setScale( _originalScale );
|
2013-06-20 14:13:12 +08:00
|
|
|
MenuItem::activate();
|
2012-02-02 10:39:36 +08:00
|
|
|
}
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void MenuItemLabel::selected()
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
|
|
|
// subclass to change the default action
|
2013-06-15 14:03:30 +08:00
|
|
|
if(_enabled)
|
2012-02-02 10:39:36 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
MenuItem::selected();
|
2012-02-02 10:39:36 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Action *action = getActionByTag(kZoomActionTag);
|
2012-03-20 15:04:53 +08:00
|
|
|
if (action)
|
2012-02-01 16:45:23 +08:00
|
|
|
{
|
2012-03-20 15:04:53 +08:00
|
|
|
this->stopAction(action);
|
2012-02-01 16:45:23 +08:00
|
|
|
}
|
2012-03-20 15:04:53 +08:00
|
|
|
else
|
2012-02-02 10:39:36 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_originalScale = this->getScale();
|
2012-02-02 10:39:36 +08:00
|
|
|
}
|
2012-03-20 15:04:53 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Action *zoomAction = ScaleTo::create(0.1f, _originalScale * 1.2f);
|
2012-03-20 15:04:53 +08:00
|
|
|
zoomAction->setTag(kZoomActionTag);
|
|
|
|
this->runAction(zoomAction);
|
2012-02-02 10:39:36 +08:00
|
|
|
}
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void MenuItemLabel::unselected()
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
|
|
|
// subclass to change the default action
|
2013-06-15 14:03:30 +08:00
|
|
|
if(_enabled)
|
2012-02-02 10:39:36 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
MenuItem::unselected();
|
2012-03-20 15:04:53 +08:00
|
|
|
this->stopActionByTag(kZoomActionTag);
|
2013-06-20 14:13:12 +08:00
|
|
|
Action *zoomAction = ScaleTo::create(0.1f, _originalScale);
|
2012-03-20 15:04:53 +08:00
|
|
|
zoomAction->setTag(kZoomActionTag);
|
|
|
|
this->runAction(zoomAction);
|
2012-02-02 10:39:36 +08:00
|
|
|
}
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void MenuItemLabel::setEnabled(bool enabled)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if( _enabled != enabled )
|
2012-02-02 10:39:36 +08:00
|
|
|
{
|
2012-03-20 15:04:53 +08:00
|
|
|
if(enabled == false)
|
2012-02-02 10:39:36 +08:00
|
|
|
{
|
2014-03-14 17:36:05 +08:00
|
|
|
_colorBackup = this->getColor();
|
|
|
|
this->setColor(_disabledColor);
|
2012-02-02 10:39:36 +08:00
|
|
|
}
|
2012-03-20 15:04:53 +08:00
|
|
|
else
|
2012-02-02 10:39:36 +08:00
|
|
|
{
|
2014-03-14 17:36:05 +08:00
|
|
|
this->setColor(_colorBackup);
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
|
|
|
}
|
2013-06-20 14:13:12 +08:00
|
|
|
MenuItem::setEnabled(enabled);
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2012-03-20 15:04:53 +08:00
|
|
|
//
|
|
|
|
//CCMenuItemAtlasFont
|
|
|
|
//
|
2012-07-19 05:40:09 +08:00
|
|
|
|
2013-12-05 17:19:01 +08:00
|
|
|
MenuItemAtlasFont * MenuItemAtlasFont::create(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return MenuItemAtlasFont::create(value, charMapFile, itemWidth, itemHeight, startCharMap, (const ccMenuCallback&)nullptr);
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
|
|
|
|
2013-06-05 09:29:26 +08:00
|
|
|
// XXX: deprecated
|
2014-02-20 10:53:49 +08:00
|
|
|
MenuItemAtlasFont * MenuItemAtlasFont::create(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap, Ref* target, SEL_MenuHandler selector)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-11-07 09:05:13 +08:00
|
|
|
MenuItemAtlasFont *ret = new MenuItemAtlasFont();
|
|
|
|
ret->initWithString(value, charMapFile, itemWidth, itemHeight, startCharMap, target, selector);
|
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-12-05 17:19:01 +08:00
|
|
|
MenuItemAtlasFont * MenuItemAtlasFont::create(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap, const ccMenuCallback& callback)
|
2013-06-05 09:29:26 +08:00
|
|
|
{
|
2013-11-07 09:05:13 +08:00
|
|
|
MenuItemAtlasFont *ret = new MenuItemAtlasFont();
|
|
|
|
ret->initWithString(value, charMapFile, itemWidth, itemHeight, startCharMap, callback);
|
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
2013-06-05 09:29:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// XXX: deprecated
|
2014-02-20 10:53:49 +08:00
|
|
|
bool MenuItemAtlasFont::initWithString(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap, Ref* target, SEL_MenuHandler selector)
|
2013-06-05 09:29:26 +08:00
|
|
|
{
|
|
|
|
_target = target;
|
|
|
|
CC_SAFE_RETAIN(_target);
|
|
|
|
return initWithString(value, charMapFile, itemWidth, itemHeight, startCharMap, std::bind(selector,target, std::placeholders::_1) );
|
|
|
|
}
|
|
|
|
|
2013-12-05 17:19:01 +08:00
|
|
|
bool MenuItemAtlasFont::initWithString(const std::string& value, const std::string& charMapFile, int itemWidth, int itemHeight, char startCharMap, const ccMenuCallback& callback)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-11-07 09:05:13 +08:00
|
|
|
CCASSERT( value.size() != 0, "value length must be greater than 0");
|
2014-01-09 14:16:26 +08:00
|
|
|
LabelAtlas *label = LabelAtlas::create();
|
2012-03-20 15:04:53 +08:00
|
|
|
label->initWithString(value, charMapFile, itemWidth, itemHeight, startCharMap);
|
2013-06-20 14:13:12 +08:00
|
|
|
if (MenuItemLabel::initWithLabel(label, callback))
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
|
|
|
// do something ?
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2013-06-05 09:29:26 +08:00
|
|
|
|
2012-03-20 15:04:53 +08:00
|
|
|
//
|
|
|
|
//CCMenuItemFont
|
|
|
|
//
|
2012-07-19 05:40:09 +08:00
|
|
|
|
2013-12-05 17:19:01 +08:00
|
|
|
void MenuItemFont::setFontSize(int s)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-02-27 17:23:39 +08:00
|
|
|
_globalFontSize = s;
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-12-05 17:19:01 +08:00
|
|
|
int MenuItemFont::getFontSize()
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-02-27 17:23:39 +08:00
|
|
|
return _globalFontSize;
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-11-07 09:05:13 +08:00
|
|
|
void MenuItemFont::setFontName(const std::string& name)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-02-27 17:23:39 +08:00
|
|
|
if (_globalFontNameRelease)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-02-27 17:23:39 +08:00
|
|
|
_globalFontName.clear();
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
2013-02-27 17:23:39 +08:00
|
|
|
_globalFontName = name;
|
|
|
|
_globalFontNameRelease = true;
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-11-07 09:05:13 +08:00
|
|
|
const std::string& MenuItemFont::getFontName()
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-11-07 09:05:13 +08:00
|
|
|
return _globalFontName;
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-06-05 09:29:26 +08:00
|
|
|
// XXX: deprecated
|
2014-02-20 10:53:49 +08:00
|
|
|
MenuItemFont * MenuItemFont::create(const std::string& value, Ref* target, SEL_MenuHandler selector)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-11-07 09:05:13 +08:00
|
|
|
MenuItemFont *ret = new MenuItemFont();
|
|
|
|
ret->initWithString(value, target, selector);
|
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-11-07 09:05:13 +08:00
|
|
|
MenuItemFont * MenuItemFont::create(const std::string& value, const ccMenuCallback& callback)
|
2013-06-05 09:29:26 +08:00
|
|
|
{
|
2013-11-07 09:05:13 +08:00
|
|
|
MenuItemFont *ret = new MenuItemFont();
|
|
|
|
ret->initWithString(value, callback);
|
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
2013-06-05 09:29:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-07 09:05:13 +08:00
|
|
|
MenuItemFont * MenuItemFont::create(const std::string& value)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-11-07 09:05:13 +08:00
|
|
|
MenuItemFont *ret = new MenuItemFont();
|
|
|
|
ret->initWithString(value, (const ccMenuCallback&)nullptr);
|
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-10-24 17:27:57 +08:00
|
|
|
MenuItemFont::MenuItemFont()
|
|
|
|
: _fontSize(0), _fontName("")
|
|
|
|
{}
|
|
|
|
|
|
|
|
MenuItemFont::~MenuItemFont()
|
|
|
|
{
|
|
|
|
CCLOGINFO("In the destructor of MenuItemFont (%p).", this);
|
|
|
|
}
|
|
|
|
|
2013-06-06 08:51:40 +08:00
|
|
|
// XXX: deprecated
|
2014-02-20 10:53:49 +08:00
|
|
|
bool MenuItemFont::initWithString(const std::string& value, Ref* target, SEL_MenuHandler selector)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-12-24 10:51:47 +08:00
|
|
|
CCASSERT( !value.empty(), "Value length must be greater than 0");
|
2013-06-05 09:29:26 +08:00
|
|
|
|
|
|
|
_target = target;
|
|
|
|
CC_SAFE_RETAIN(target);
|
|
|
|
return initWithString(value, std::bind(selector,target, std::placeholders::_1) );
|
|
|
|
}
|
|
|
|
|
2013-11-07 09:05:13 +08:00
|
|
|
bool MenuItemFont::initWithString(const std::string& value, const ccMenuCallback& callback)
|
2013-06-05 09:29:26 +08:00
|
|
|
{
|
2013-12-24 10:51:47 +08:00
|
|
|
CCASSERT( !value.empty(), "Value length must be greater than 0");
|
2013-06-05 09:29:26 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_fontName = _globalFontName;
|
|
|
|
_fontSize = _globalFontSize;
|
2013-06-05 09:29:26 +08:00
|
|
|
|
2014-04-09 23:31:05 +08:00
|
|
|
Label *label = Label::createWithSystemFont(value, _fontName, _fontSize);
|
2013-06-20 14:13:12 +08:00
|
|
|
if (MenuItemLabel::initWithLabel(label, callback))
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
|
|
|
// do something ?
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-12-05 17:19:01 +08:00
|
|
|
void MenuItemFont::setFontSizeObj(int s)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_fontSize = s;
|
2014-04-09 23:31:05 +08:00
|
|
|
dynamic_cast<Label*>(_label)->setSystemFontSize(_fontSize);
|
2014-03-15 01:24:23 +08:00
|
|
|
this->setContentSize(dynamic_cast<Label*>(_label)->getContentSize());
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
|
|
|
|
2013-12-05 17:19:01 +08:00
|
|
|
int MenuItemFont::getFontSizeObj() const
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _fontSize;
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
|
|
|
|
2013-11-07 09:05:13 +08:00
|
|
|
void MenuItemFont::setFontNameObj(const std::string& name)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_fontName = name;
|
2014-04-10 10:23:00 +08:00
|
|
|
dynamic_cast<Label*>(_label)->setSystemFontName(_fontName);
|
2014-03-15 01:24:23 +08:00
|
|
|
this->setContentSize(dynamic_cast<Label*>(_label)->getContentSize());
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
|
|
|
|
2013-11-07 09:05:13 +08:00
|
|
|
const std::string& MenuItemFont::getFontNameObj() const
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-11-07 09:05:13 +08:00
|
|
|
return _fontName;
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
//CCMenuItemSprite
|
|
|
|
//
|
2012-07-19 05:40:09 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
void MenuItemSprite::setNormalImage(Node* image)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
if (image != _normalImage)
|
2012-02-02 10:39:36 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
if (image)
|
2012-06-08 14:50:41 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
addChild(image, 0, kNormalTag);
|
2014-04-15 18:13:57 +08:00
|
|
|
image->setAnchorPoint(Vector2(0, 0));
|
2012-06-08 14:50:41 +08:00
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_normalImage)
|
2012-06-08 14:50:41 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
removeChild(_normalImage, true);
|
2012-06-08 14:50:41 +08:00
|
|
|
}
|
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
_normalImage = image;
|
2013-06-15 14:03:30 +08:00
|
|
|
this->setContentSize(_normalImage->getContentSize());
|
2012-06-08 14:50:41 +08:00
|
|
|
this->updateImagesVisibility();
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
|
|
|
}
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
void MenuItemSprite::setSelectedImage(Node* image)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
if (image != _normalImage)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
if (image)
|
2012-06-08 14:50:41 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
addChild(image, 0, kSelectedTag);
|
2014-04-15 18:13:57 +08:00
|
|
|
image->setAnchorPoint(Vector2(0, 0));
|
2012-06-08 14:50:41 +08:00
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_selectedImage)
|
2012-06-08 14:50:41 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
removeChild(_selectedImage, true);
|
2012-06-08 14:50:41 +08:00
|
|
|
}
|
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
_selectedImage = image;
|
2012-06-08 14:50:41 +08:00
|
|
|
this->updateImagesVisibility();
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
|
|
|
}
|
2012-06-08 14:50:41 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
void MenuItemSprite::setDisabledImage(Node* image)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
if (image != _normalImage)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
if (image)
|
2012-06-08 14:50:41 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
addChild(image, 0, kDisableTag);
|
2014-04-15 18:13:57 +08:00
|
|
|
image->setAnchorPoint(Vector2(0, 0));
|
2012-06-08 14:50:41 +08:00
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_disabledImage)
|
2012-06-08 14:50:41 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
removeChild(_disabledImage, true);
|
2012-06-08 14:50:41 +08:00
|
|
|
}
|
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
_disabledImage = image;
|
2012-06-08 14:50:41 +08:00
|
|
|
this->updateImagesVisibility();
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
|
|
|
}
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2012-03-20 15:04:53 +08:00
|
|
|
//
|
2013-02-27 17:23:39 +08:00
|
|
|
//CCMenuItemSprite
|
2012-03-20 15:04:53 +08:00
|
|
|
//
|
2012-07-19 05:40:09 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
MenuItemSprite * MenuItemSprite::create(Node* normalSprite, Node* selectedSprite, Node* disabledSprite)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return MenuItemSprite::create(normalSprite, selectedSprite, disabledSprite, (const ccMenuCallback&)nullptr);
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-06-05 09:29:26 +08:00
|
|
|
// XXX deprecated
|
2014-02-20 10:53:49 +08:00
|
|
|
MenuItemSprite * MenuItemSprite::create(Node* normalSprite, Node* selectedSprite, Ref* target, SEL_MenuHandler selector)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
return MenuItemSprite::create(normalSprite, selectedSprite, nullptr, target, selector);
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
MenuItemSprite * MenuItemSprite::create(Node* normalSprite, Node* selectedSprite, const ccMenuCallback& callback)
|
2013-06-05 09:29:26 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
return MenuItemSprite::create(normalSprite, selectedSprite, nullptr, callback);
|
2013-06-05 09:29:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// XXX deprecated
|
2014-02-20 10:53:49 +08:00
|
|
|
MenuItemSprite * MenuItemSprite::create(Node *normalSprite, Node *selectedSprite, Node *disabledSprite, Ref *target, SEL_MenuHandler selector)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-11-07 09:05:13 +08:00
|
|
|
MenuItemSprite *ret = new MenuItemSprite();
|
|
|
|
ret->initWithNormalSprite(normalSprite, selectedSprite, disabledSprite, target, selector);
|
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
MenuItemSprite * MenuItemSprite::create(Node *normalSprite, Node *selectedSprite, Node *disabledSprite, const ccMenuCallback& callback)
|
2013-06-05 09:29:26 +08:00
|
|
|
{
|
2013-11-07 09:05:13 +08:00
|
|
|
MenuItemSprite *ret = new MenuItemSprite();
|
|
|
|
ret->initWithNormalSprite(normalSprite, selectedSprite, disabledSprite, callback);
|
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
2013-06-05 09:29:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// XXX deprecated
|
2014-02-20 10:53:49 +08:00
|
|
|
bool MenuItemSprite::initWithNormalSprite(Node* normalSprite, Node* selectedSprite, Node* disabledSprite, Ref* target, SEL_MenuHandler selector)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-06-05 09:29:26 +08:00
|
|
|
_target = target;
|
|
|
|
CC_SAFE_RETAIN(_target);
|
|
|
|
return initWithNormalSprite(normalSprite, selectedSprite, disabledSprite, std::bind(selector,target, std::placeholders::_1) );
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool MenuItemSprite::initWithNormalSprite(Node* normalSprite, Node* selectedSprite, Node* disabledSprite, const ccMenuCallback& callback)
|
2013-06-05 09:29:26 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
MenuItem::initWithCallback(callback);
|
2012-03-20 15:04:53 +08:00
|
|
|
setNormalImage(normalSprite);
|
|
|
|
setSelectedImage(selectedSprite);
|
|
|
|
setDisabledImage(disabledSprite);
|
2012-06-01 08:04:53 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if(_normalImage)
|
2012-06-12 02:50:32 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
this->setContentSize(_normalImage->getContentSize());
|
2012-06-12 02:50:32 +08:00
|
|
|
}
|
2013-06-05 09:29:26 +08:00
|
|
|
|
2013-02-27 17:23:39 +08:00
|
|
|
setCascadeColorEnabled(true);
|
|
|
|
setCascadeOpacityEnabled(true);
|
2013-06-05 09:29:26 +08:00
|
|
|
|
2012-03-20 15:04:53 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@since v0.99.5
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
void MenuItemSprite::selected()
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
MenuItem::selected();
|
2012-06-12 02:50:32 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_normalImage)
|
2012-02-02 10:39:36 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_disabledImage)
|
2012-06-01 08:04:53 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_disabledImage->setVisible(false);
|
2012-06-01 08:04:53 +08:00
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_selectedImage)
|
2012-06-01 08:04:53 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_normalImage->setVisible(false);
|
|
|
|
_selectedImage->setVisible(true);
|
2012-06-01 08:04:53 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_normalImage->setVisible(true);
|
2012-06-01 08:04:53 +08:00
|
|
|
}
|
2012-02-02 10:39:36 +08:00
|
|
|
}
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void MenuItemSprite::unselected()
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
MenuItem::unselected();
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_normalImage)
|
2012-02-02 10:39:36 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_normalImage->setVisible(true);
|
2012-06-01 08:04:53 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_selectedImage)
|
2012-06-01 08:04:53 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_selectedImage->setVisible(false);
|
2012-06-01 08:04:53 +08:00
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_disabledImage)
|
2012-06-01 08:04:53 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_disabledImage->setVisible(false);
|
2012-06-01 08:04:53 +08:00
|
|
|
}
|
2012-02-02 10:39:36 +08:00
|
|
|
}
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void MenuItemSprite::setEnabled(bool bEnabled)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if( _enabled != bEnabled )
|
2012-06-15 15:10:40 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
MenuItem::setEnabled(bEnabled);
|
2012-06-15 15:10:40 +08:00
|
|
|
this->updateImagesVisibility();
|
2012-02-01 16:45:23 +08:00
|
|
|
}
|
2012-06-08 14:50:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Helper
|
2013-06-20 14:13:12 +08:00
|
|
|
void MenuItemSprite::updateImagesVisibility()
|
2012-06-08 14:50:41 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_enabled)
|
2012-02-01 16:45:23 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_normalImage) _normalImage->setVisible(true);
|
|
|
|
if (_selectedImage) _selectedImage->setVisible(false);
|
|
|
|
if (_disabledImage) _disabledImage->setVisible(false);
|
2012-02-01 16:45:23 +08:00
|
|
|
}
|
2012-03-20 15:04:53 +08:00
|
|
|
else
|
2012-02-01 16:45:23 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_disabledImage)
|
2012-02-01 16:45:23 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_normalImage) _normalImage->setVisible(false);
|
|
|
|
if (_selectedImage) _selectedImage->setVisible(false);
|
|
|
|
if (_disabledImage) _disabledImage->setVisible(true);
|
2012-02-01 16:45:23 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_normalImage) _normalImage->setVisible(true);
|
|
|
|
if (_selectedImage) _selectedImage->setVisible(false);
|
|
|
|
if (_disabledImage) _disabledImage->setVisible(false);
|
2012-02-02 10:39:36 +08:00
|
|
|
}
|
|
|
|
}
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
2012-03-16 13:42:53 +08:00
|
|
|
|
2012-07-19 05:40:09 +08:00
|
|
|
///
|
2013-06-20 14:13:12 +08:00
|
|
|
/// MenuItemImage
|
2012-07-19 05:40:09 +08:00
|
|
|
///
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
MenuItemImage* MenuItemImage::create()
|
2012-06-01 08:04:53 +08:00
|
|
|
{
|
2013-11-07 09:05:13 +08:00
|
|
|
MenuItemImage *ret = new MenuItemImage();
|
|
|
|
if (ret && ret->init())
|
2012-06-01 08:04:53 +08:00
|
|
|
{
|
2013-11-07 09:05:13 +08:00
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
2012-06-01 08:04:53 +08:00
|
|
|
}
|
2013-11-07 09:05:13 +08:00
|
|
|
CC_SAFE_DELETE(ret);
|
2013-12-18 17:47:20 +08:00
|
|
|
return nullptr;
|
2012-06-01 08:04:53 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool MenuItemImage::init(void)
|
2012-06-01 08:04:53 +08:00
|
|
|
{
|
2013-11-07 09:05:13 +08:00
|
|
|
return initWithNormalImage("", "", "", (const ccMenuCallback&)nullptr);
|
2012-06-01 08:04:53 +08:00
|
|
|
}
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-11-07 09:05:13 +08:00
|
|
|
MenuItemImage * MenuItemImage::create(const std::string& normalImage, const std::string& selectedImage)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-11-07 09:05:13 +08:00
|
|
|
return MenuItemImage::create(normalImage, selectedImage, "", (const ccMenuCallback&)nullptr);
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
2012-06-08 14:50:41 +08:00
|
|
|
|
2013-06-05 09:29:26 +08:00
|
|
|
// XXX deprecated
|
2014-02-20 10:53:49 +08:00
|
|
|
MenuItemImage * MenuItemImage::create(const std::string& normalImage, const std::string& selectedImage, Ref* target, SEL_MenuHandler selector)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-11-07 09:05:13 +08:00
|
|
|
return MenuItemImage::create(normalImage, selectedImage, "", target, selector);
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
2012-06-08 14:50:41 +08:00
|
|
|
|
2013-11-07 09:05:13 +08:00
|
|
|
MenuItemImage * MenuItemImage::create(const std::string& normalImage, const std::string& selectedImage, const ccMenuCallback& callback)
|
2013-06-05 09:29:26 +08:00
|
|
|
{
|
2013-11-07 09:05:13 +08:00
|
|
|
return MenuItemImage::create(normalImage, selectedImage, "", callback);
|
2013-06-05 09:29:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// XXX deprecated
|
2014-02-20 10:53:49 +08:00
|
|
|
MenuItemImage * MenuItemImage::create(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage, Ref* target, SEL_MenuHandler selector)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-11-07 09:05:13 +08:00
|
|
|
MenuItemImage *ret = new MenuItemImage();
|
|
|
|
if (ret && ret->initWithNormalImage(normalImage, selectedImage, disabledImage, target, selector))
|
2012-02-02 10:39:36 +08:00
|
|
|
{
|
2013-11-07 09:05:13 +08:00
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
2012-02-02 10:39:36 +08:00
|
|
|
}
|
2013-11-07 09:05:13 +08:00
|
|
|
CC_SAFE_DELETE(ret);
|
2013-12-18 17:47:20 +08:00
|
|
|
return nullptr;
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
2012-06-08 14:50:41 +08:00
|
|
|
|
2013-11-07 09:05:13 +08:00
|
|
|
MenuItemImage * MenuItemImage::create(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage, const ccMenuCallback& callback)
|
2013-06-05 09:29:26 +08:00
|
|
|
{
|
2013-11-07 09:05:13 +08:00
|
|
|
MenuItemImage *ret = new MenuItemImage();
|
|
|
|
if (ret && ret->initWithNormalImage(normalImage, selectedImage, disabledImage, callback))
|
2013-06-05 09:29:26 +08:00
|
|
|
{
|
2013-11-07 09:05:13 +08:00
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
2013-06-05 09:29:26 +08:00
|
|
|
}
|
2013-11-07 09:05:13 +08:00
|
|
|
CC_SAFE_DELETE(ret);
|
2013-12-18 17:47:20 +08:00
|
|
|
return nullptr;
|
2013-06-05 09:29:26 +08:00
|
|
|
}
|
|
|
|
|
2013-11-07 09:05:13 +08:00
|
|
|
MenuItemImage * MenuItemImage::create(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-11-07 09:05:13 +08:00
|
|
|
MenuItemImage *ret = new MenuItemImage();
|
|
|
|
if (ret && ret->initWithNormalImage(normalImage, selectedImage, disabledImage, (const ccMenuCallback&)nullptr))
|
2012-02-02 10:39:36 +08:00
|
|
|
{
|
2013-11-07 09:05:13 +08:00
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
2012-02-02 10:39:36 +08:00
|
|
|
}
|
2013-11-07 09:05:13 +08:00
|
|
|
CC_SAFE_DELETE(ret);
|
2013-12-18 17:47:20 +08:00
|
|
|
return nullptr;
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
2012-06-08 14:50:41 +08:00
|
|
|
|
2013-06-05 09:29:26 +08:00
|
|
|
// XXX: deprecated
|
2014-02-20 10:53:49 +08:00
|
|
|
bool MenuItemImage::initWithNormalImage(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage, Ref* target, SEL_MenuHandler selector)
|
2013-06-05 09:29:26 +08:00
|
|
|
{
|
|
|
|
_target = target;
|
|
|
|
CC_SAFE_RETAIN(_target);
|
|
|
|
return initWithNormalImage(normalImage, selectedImage, disabledImage, std::bind(selector,target, std::placeholders::_1) );
|
|
|
|
}
|
2013-11-07 09:05:13 +08:00
|
|
|
bool MenuItemImage::initWithNormalImage(const std::string& normalImage, const std::string& selectedImage, const std::string& disabledImage, const ccMenuCallback& callback)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
Node *normalSprite = nullptr;
|
|
|
|
Node *selectedSprite = nullptr;
|
|
|
|
Node *disabledSprite = nullptr;
|
2012-06-01 08:04:53 +08:00
|
|
|
|
2013-11-07 09:05:13 +08:00
|
|
|
if (normalImage.size() >0)
|
2012-06-01 08:04:53 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
normalSprite = Sprite::create(normalImage);
|
2012-06-01 08:04:53 +08:00
|
|
|
}
|
|
|
|
|
2013-11-07 09:05:13 +08:00
|
|
|
if (selectedImage.size() >0)
|
2012-02-02 10:39:36 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
selectedSprite = Sprite::create(selectedImage);
|
2012-02-02 10:39:36 +08:00
|
|
|
}
|
2013-06-05 09:29:26 +08:00
|
|
|
|
2013-11-07 09:05:13 +08:00
|
|
|
if(disabledImage.size() >0)
|
2012-02-02 10:39:36 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
disabledSprite = Sprite::create(disabledImage);
|
2012-02-02 10:39:36 +08:00
|
|
|
}
|
2013-06-05 09:29:26 +08:00
|
|
|
return initWithNormalSprite(normalSprite, selectedSprite, disabledSprite, callback);
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
2013-06-05 09:29:26 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
//
|
|
|
|
// Setter of sprite frames
|
|
|
|
//
|
2013-06-20 14:13:12 +08:00
|
|
|
void MenuItemImage::setNormalSpriteFrame(SpriteFrame * frame)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
setNormalImage(Sprite::createWithSpriteFrame(frame));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void MenuItemImage::setSelectedSpriteFrame(SpriteFrame * frame)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
setSelectedImage(Sprite::createWithSpriteFrame(frame));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void MenuItemImage::setDisabledSpriteFrame(SpriteFrame * frame)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
setDisabledImage(Sprite::createWithSpriteFrame(frame));
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
2012-07-19 05:40:09 +08:00
|
|
|
|
2012-03-20 15:04:53 +08:00
|
|
|
//
|
|
|
|
// MenuItemToggle
|
|
|
|
//
|
2012-07-19 05:40:09 +08:00
|
|
|
|
2013-06-06 08:51:40 +08:00
|
|
|
// XXX: deprecated
|
2014-02-20 10:53:49 +08:00
|
|
|
MenuItemToggle * MenuItemToggle::createWithTarget(Ref* target, SEL_MenuHandler selector, const Vector<MenuItem*>& menuItems)
|
2013-03-12 15:11:41 +08:00
|
|
|
{
|
2013-11-07 09:05:13 +08:00
|
|
|
MenuItemToggle *ret = new MenuItemToggle();
|
|
|
|
ret->MenuItem::initWithTarget(target, selector);
|
2013-12-07 14:24:31 +08:00
|
|
|
ret->_subItems = menuItems;
|
2013-11-07 09:05:13 +08:00
|
|
|
ret->_selectedIndex = UINT_MAX;
|
|
|
|
ret->setSelectedIndex(0);
|
|
|
|
return ret;
|
2013-03-12 15:11:41 +08:00
|
|
|
}
|
|
|
|
|
2013-12-07 14:24:31 +08:00
|
|
|
MenuItemToggle * MenuItemToggle::createWithCallback(const ccMenuCallback &callback, const Vector<MenuItem*>& menuItems)
|
2013-06-06 08:51:40 +08:00
|
|
|
{
|
2013-11-07 09:05:13 +08:00
|
|
|
MenuItemToggle *ret = new MenuItemToggle();
|
|
|
|
ret->MenuItem::initWithCallback(callback);
|
2013-12-07 14:24:31 +08:00
|
|
|
ret->_subItems = menuItems;
|
2013-11-07 09:05:13 +08:00
|
|
|
ret->_selectedIndex = UINT_MAX;
|
|
|
|
ret->setSelectedIndex(0);
|
|
|
|
return ret;
|
2013-06-06 08:51:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// XXX: deprecated
|
2014-02-20 10:53:49 +08:00
|
|
|
MenuItemToggle * MenuItemToggle::createWithTarget(Ref* target, SEL_MenuHandler selector, MenuItem* item, ...)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start(args, item);
|
2013-11-07 09:05:13 +08:00
|
|
|
MenuItemToggle *ret = new MenuItemToggle();
|
|
|
|
ret->initWithTarget(target, selector, item, args);
|
|
|
|
ret->autorelease();
|
2012-03-20 15:04:53 +08:00
|
|
|
va_end(args);
|
2013-11-07 09:05:13 +08:00
|
|
|
return ret;
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
MenuItemToggle * MenuItemToggle::createWithCallback(const ccMenuCallback &callback, MenuItem* item, ...)
|
2013-06-06 08:51:40 +08:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start(args, item);
|
2013-11-07 09:05:13 +08:00
|
|
|
MenuItemToggle *ret = new MenuItemToggle();
|
|
|
|
ret->initWithCallback(callback, item, args);
|
|
|
|
ret->autorelease();
|
2013-06-06 08:51:40 +08:00
|
|
|
va_end(args);
|
2013-11-07 09:05:13 +08:00
|
|
|
return ret;
|
2013-06-06 08:51:40 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
MenuItemToggle * MenuItemToggle::create()
|
2012-08-01 08:25:38 +08:00
|
|
|
{
|
2013-11-07 09:05:13 +08:00
|
|
|
MenuItemToggle *ret = new MenuItemToggle();
|
2013-12-18 17:47:20 +08:00
|
|
|
ret->initWithItem(nullptr);
|
2013-11-07 09:05:13 +08:00
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
2012-08-01 08:25:38 +08:00
|
|
|
}
|
|
|
|
|
2013-06-06 08:51:40 +08:00
|
|
|
// XXX: deprecated
|
2014-02-20 10:53:49 +08:00
|
|
|
bool MenuItemToggle::initWithTarget(Ref* target, SEL_MenuHandler selector, MenuItem* item, va_list args)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-06-06 08:51:40 +08:00
|
|
|
_target = target;
|
|
|
|
CC_SAFE_RETAIN(_target);
|
|
|
|
return initWithCallback(std::bind( selector, target, std::placeholders::_1), item, args);
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool MenuItemToggle::initWithCallback(const ccMenuCallback &callback, MenuItem *item, va_list args)
|
2013-06-06 08:51:40 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
MenuItem::initWithCallback(callback);
|
2013-11-29 11:02:50 +08:00
|
|
|
|
2012-03-20 15:04:53 +08:00
|
|
|
int z = 0;
|
2013-06-20 14:13:12 +08:00
|
|
|
MenuItem *i = item;
|
2013-06-06 08:51:40 +08:00
|
|
|
while(i)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
|
|
|
z++;
|
2013-12-05 10:35:10 +08:00
|
|
|
_subItems.pushBack(i);
|
2013-06-20 14:13:12 +08:00
|
|
|
i = va_arg(args, MenuItem*);
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
2013-06-15 14:03:30 +08:00
|
|
|
_selectedIndex = UINT_MAX;
|
2012-03-20 15:04:53 +08:00
|
|
|
this->setSelectedIndex(0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
MenuItemToggle* MenuItemToggle::create(MenuItem *item)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-11-07 09:05:13 +08:00
|
|
|
MenuItemToggle *ret = new MenuItemToggle();
|
|
|
|
ret->initWithItem(item);
|
|
|
|
ret->autorelease();
|
|
|
|
return ret;
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool MenuItemToggle::initWithItem(MenuItem *item)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
MenuItem::initWithCallback((const ccMenuCallback&)nullptr);
|
2012-12-03 22:17:53 +08:00
|
|
|
|
2013-02-27 17:23:39 +08:00
|
|
|
if (item)
|
|
|
|
{
|
2013-12-05 10:35:10 +08:00
|
|
|
_subItems.pushBack(item);
|
2012-08-11 05:17:53 +08:00
|
|
|
}
|
2013-06-15 14:03:30 +08:00
|
|
|
_selectedIndex = UINT_MAX;
|
2012-03-20 15:04:53 +08:00
|
|
|
this->setSelectedIndex(0);
|
2013-02-27 17:23:39 +08:00
|
|
|
|
|
|
|
setCascadeColorEnabled(true);
|
|
|
|
setCascadeOpacityEnabled(true);
|
|
|
|
|
2012-03-20 15:04:53 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void MenuItemToggle::addSubItem(MenuItem *item)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-12-05 10:35:10 +08:00
|
|
|
_subItems.pushBack(item);
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
MenuItemToggle::~MenuItemToggle()
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-12-20 05:34:41 +08:00
|
|
|
for(const auto &item : _subItems) {
|
2013-11-29 11:02:50 +08:00
|
|
|
item->cleanup();
|
2013-12-20 05:34:41 +08:00
|
|
|
}
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
2013-07-23 20:36:41 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void MenuItemToggle::setSelectedIndex(unsigned int index)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-12-05 10:35:10 +08:00
|
|
|
if( index != _selectedIndex && _subItems.size() > 0 )
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_selectedIndex = index;
|
2013-06-20 14:13:12 +08:00
|
|
|
MenuItem *currentItem = (MenuItem*)getChildByTag(kCurrentItem);
|
2012-04-19 14:35:52 +08:00
|
|
|
if( currentItem )
|
|
|
|
{
|
|
|
|
currentItem->removeFromParentAndCleanup(false);
|
|
|
|
}
|
2012-03-20 15:04:53 +08:00
|
|
|
|
2013-12-05 10:35:10 +08:00
|
|
|
MenuItem* item = _subItems.at(_selectedIndex);
|
2012-03-20 15:04:53 +08:00
|
|
|
this->addChild(item, 0, kCurrentItem);
|
2013-06-20 14:13:12 +08:00
|
|
|
Size s = item->getContentSize();
|
2012-03-20 15:04:53 +08:00
|
|
|
this->setContentSize(s);
|
2014-04-15 18:13:57 +08:00
|
|
|
item->setPosition( Vector2( s.width/2, s.height/2 ) );
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
|
|
|
}
|
2013-07-23 18:26:26 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void MenuItemToggle::selected()
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
MenuItem::selected();
|
2013-12-05 10:35:10 +08:00
|
|
|
_subItems.at(_selectedIndex)->selected();
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
2013-07-23 18:26:26 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void MenuItemToggle::unselected()
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
MenuItem::unselected();
|
2013-12-05 10:35:10 +08:00
|
|
|
_subItems.at(_selectedIndex)->unselected();
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
2013-07-23 18:26:26 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void MenuItemToggle::activate()
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
|
|
|
// update index
|
2013-06-15 14:03:30 +08:00
|
|
|
if( _enabled )
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-12-05 10:35:10 +08:00
|
|
|
unsigned int newIndex = (_selectedIndex + 1) % _subItems.size();
|
2012-03-20 15:04:53 +08:00
|
|
|
this->setSelectedIndex(newIndex);
|
|
|
|
}
|
2013-06-20 14:13:12 +08:00
|
|
|
MenuItem::activate();
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
2013-06-20 14:13:12 +08:00
|
|
|
void MenuItemToggle::setEnabled(bool enabled)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_enabled != enabled)
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
MenuItem::setEnabled(enabled);
|
2012-06-08 14:50:41 +08:00
|
|
|
|
2013-12-20 05:34:41 +08:00
|
|
|
for(const auto &item : _subItems) {
|
2013-11-29 11:02:50 +08:00
|
|
|
item->setEnabled(enabled);
|
2013-12-20 05:34:41 +08:00
|
|
|
}
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
MenuItem* MenuItemToggle::getSelectedItem()
|
2012-03-20 15:04:53 +08:00
|
|
|
{
|
2013-12-05 10:35:10 +08:00
|
|
|
return _subItems.at(_selectedIndex);
|
2012-03-20 15:04:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_CC_END
|
2013-07-25 15:03:44 +08:00
|
|
|
|
|
|
|
#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
|
|
|
|
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
|
|
|
|
#elif _MSC_VER >= 1400 //vs 2005 or higher
|
|
|
|
#pragma warning (pop)
|
|
|
|
#endif
|