mirror of https://github.com/axmolengine/axmol.git
fixed #986: Add init() member funciton of CCMenu class.
This commit is contained in:
parent
f166ee2611
commit
6c01009a18
|
@ -60,17 +60,20 @@ namespace cocos2d{
|
||||||
{}
|
{}
|
||||||
virtual ~CCMenu(){}
|
virtual ~CCMenu(){}
|
||||||
|
|
||||||
/** creates an empty CCMenu */
|
/** creates an empty CCMenu */
|
||||||
static CCMenu* node();
|
static CCMenu* node();
|
||||||
|
|
||||||
/** creates a CCMenu with it's items */
|
/** creates a CCMenu with it's items */
|
||||||
static CCMenu* menuWithItems(CCMenuItem* item, ...);
|
static CCMenu* menuWithItems(CCMenuItem* item, ...);
|
||||||
|
|
||||||
/** creates a CCMenu with it's item, then use addChild() to add
|
/** 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
|
* other items. It is used for script, it can't init with undetermined
|
||||||
* number of variables.
|
* number of variables.
|
||||||
*/
|
*/
|
||||||
static CCMenu*menuWithItem(CCMenuItem* item);
|
static CCMenu* menuWithItem(CCMenuItem* item);
|
||||||
|
|
||||||
|
/** initializes an empty CCMenu */
|
||||||
|
bool init();
|
||||||
|
|
||||||
/** initializes a CCMenu with it's items */
|
/** initializes a CCMenu with it's items */
|
||||||
bool initWithItems(CCMenuItem* item, va_list args);
|
bool initWithItems(CCMenuItem* item, va_list args);
|
||||||
|
@ -122,7 +125,7 @@ namespace cocos2d{
|
||||||
protected:
|
protected:
|
||||||
CCMenuItem* itemForTouch(CCTouch * touch);
|
CCMenuItem* itemForTouch(CCTouch * touch);
|
||||||
tCCMenuState m_eState;
|
tCCMenuState m_eState;
|
||||||
CCMenuItem *m_pSelectedItem;
|
CCMenuItem *m_pSelectedItem;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,35 +72,46 @@ namespace cocos2d{
|
||||||
return menuWithItems(item, NULL);
|
return menuWithItems(item, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CCMenu::init()
|
||||||
|
{
|
||||||
|
if (CCLayer::init())
|
||||||
|
{
|
||||||
|
this->m_bIsTouchEnabled = true;
|
||||||
|
|
||||||
|
// menu in the center of the screen
|
||||||
|
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
||||||
|
|
||||||
|
this->m_bIsRelativeAnchorPoint = false;
|
||||||
|
setAnchorPoint(ccp(0.5f, 0.5f));
|
||||||
|
this->setContentSize(s);
|
||||||
|
|
||||||
|
// XXX: in v0.7, winSize should return the visible size
|
||||||
|
// XXX: so the bar calculation should be done there
|
||||||
|
CCRect r;
|
||||||
|
CCApplication::sharedApplication().statusBarFrame(&r);
|
||||||
|
ccDeviceOrientation orientation = CCDirector::sharedDirector()->getDeviceOrientation();
|
||||||
|
if (orientation == CCDeviceOrientationLandscapeLeft || orientation == CCDeviceOrientationLandscapeRight)
|
||||||
|
{
|
||||||
|
s.height -= r.size.width;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
s.height -= r.size.height;
|
||||||
|
}
|
||||||
|
setPosition(ccp(s.width/2, s.height/2));
|
||||||
|
// [self alignItemsVertically];
|
||||||
|
m_pSelectedItem = NULL;
|
||||||
|
m_eState = kCCMenuStateWaiting;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool CCMenu::initWithItems(CCMenuItem* item, va_list args)
|
bool CCMenu::initWithItems(CCMenuItem* item, va_list args)
|
||||||
{
|
{
|
||||||
if (CCLayer::init())
|
if (init())
|
||||||
{
|
{
|
||||||
this->m_bIsTouchEnabled = true;
|
int z=0;
|
||||||
|
|
||||||
// menu in the center of the screen
|
|
||||||
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
|
||||||
|
|
||||||
this->m_bIsRelativeAnchorPoint = false;
|
|
||||||
setAnchorPoint(ccp(0.5f, 0.5f));
|
|
||||||
this->setContentSize(s);
|
|
||||||
|
|
||||||
// XXX: in v0.7, winSize should return the visible size
|
|
||||||
// XXX: so the bar calculation should be done there
|
|
||||||
CCRect r;
|
|
||||||
CCApplication::sharedApplication().statusBarFrame(&r);
|
|
||||||
ccDeviceOrientation orientation = CCDirector::sharedDirector()->getDeviceOrientation();
|
|
||||||
if (orientation == CCDeviceOrientationLandscapeLeft || orientation == CCDeviceOrientationLandscapeRight)
|
|
||||||
{
|
|
||||||
s.height -= r.size.width;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
s.height -= r.size.height;
|
|
||||||
}
|
|
||||||
setPosition(ccp(s.width/2, s.height/2));
|
|
||||||
|
|
||||||
int z=0;
|
|
||||||
|
|
||||||
if (item)
|
if (item)
|
||||||
{
|
{
|
||||||
|
@ -113,14 +124,10 @@ namespace cocos2d{
|
||||||
i = va_arg(args, CCMenuItem*);
|
i = va_arg(args, CCMenuItem*);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// [self alignItemsVertically];
|
|
||||||
|
|
||||||
m_pSelectedItem = NULL;
|
|
||||||
m_eState = kCCMenuStateWaiting;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue