fixed #986: Add init() member funciton of CCMenu class.

This commit is contained in:
James Chen 2012-02-29 10:07:18 +08:00
parent f166ee2611
commit 6c01009a18
2 changed files with 49 additions and 39 deletions

View File

@ -60,17 +60,20 @@ namespace cocos2d{
{}
virtual ~CCMenu(){}
/** creates an empty CCMenu */
static CCMenu* node();
/** creates an empty CCMenu */
static CCMenu* node();
/** creates a CCMenu with it's items */
static CCMenu* menuWithItems(CCMenuItem* item, ...);
/** creates a CCMenu with it's items */
static CCMenu* menuWithItems(CCMenuItem* item, ...);
/** 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
* 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 */
bool initWithItems(CCMenuItem* item, va_list args);
@ -122,7 +125,7 @@ namespace cocos2d{
protected:
CCMenuItem* itemForTouch(CCTouch * touch);
tCCMenuState m_eState;
CCMenuItem *m_pSelectedItem;
CCMenuItem *m_pSelectedItem;
};
}

View File

@ -72,35 +72,46 @@ namespace cocos2d{
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)
{
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));
int z=0;
if (init())
{
int z=0;
if (item)
{
@ -113,14 +124,10 @@ namespace cocos2d{
i = va_arg(args, CCMenuItem*);
}
}
// [self alignItemsVertically];
m_pSelectedItem = NULL;
m_eState = kCCMenuStateWaiting;
return true;
}
return false;
}
return false;
}
/*