#include "GalleryLayer.h"
#include "ListViewLayer.h"
using
namespace
cocos2d;
cocos2d::extension;
bool
GalleryLayer::init()
{
bRet =
false
;
do
{
CC_BREAK_IF( !CCLayer::init() );
m_nCurPage = 1;
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
CCLayer *pLayer = CCLayer::create();
char
helpstr[30] = {0};
for
(
i = 1; i <= 3; ++ i)
{
memset
(helpstr,153)!important; border:0px!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-weight:bold!important; min-height:inherit!important; background:none!important">sizeof
(helpstr));
sprintf
"bg_%02d.png"
,i);
CCSprite *pSprite = CCSprite::create(helpstr);
pSprite->setPosition(ccp(visibleSize.width * (i-0.5f),visibleSize.height / 2));
pLayer->addChild(pSprite);
}
m_pScrollView = CCScrollView::create(CCSizeMake(960,640),pLayer);
m_pScrollView->setContentOffset(CCPointZero);
m_pScrollView->setTouchEnabled(
);
m_pScrollView->setDelegate(
this
);
m_pScrollView->setDirection(kCCScrollViewDirectionHorizontal);
pLayer->setContentSize(CCSizeMake(960*3,640));
->addChild(m_pScrollView);
CCSpriteFrameCache *pCache = CCSpriteFrameCache::sharedSpriteFrameCache();
pCache->addSpriteFrame(CCSpriteFrame::create(
"button_normal.png"
);
"button_selected.png"
);
i = 1; i <= 3; ++ i)
{
CCSprite *pPoint = CCSprite::createWithSpriteFrameName(
);
pPoint->setTag(i);
pPoint->setPosition(ccp( origin.x + (visibleSize.width - 3 * pPoint->getContentSize().width)/2 + pPoint->getContentSize().width * (i-1),origin.y + 30));
->addChild(pPoint);
}
CCSprite *pPoint = (CCSprite *)
->getChildByTag(1);
pPoint->setDisplayFrame(pCache->spriteFrameByName(
));
bRet =
true
;
}
while
(0);
return
bRet;
}
GalleryLayer::menuCloseCallback(CCObject* pSender)
{
}
GalleryLayer::scrollViewDidScroll(cocos2d::extension::CCScrollView *view)
{
CCLOG(
"scroll"
);
}
GalleryLayer::scrollViewDidZoom(cocos2d::extension::CCScrollView *view)
{
"zoom"
);
}
GalleryLayer::onEnter()
{
CCLayer::onEnter();
CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(
);
}
GalleryLayer::onExit()
{
CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(
);
CCLayer::onExit();
CCSpriteFrameCache::sharedSpriteFrameCache()->removeUnusedSpriteFrames();
}
GalleryLayer::ccTouchBegan(CCTouch *pTouch,CCEvent *pEvent)
{
m_touchPoint = CCDirector::sharedDirector()->convertToGL(pTouch->getLocationInView());
return
true
;
}
GalleryLayer::ccTouchMoved(CCTouch *pTouch,CCEvent *pEvent)
{
}
GalleryLayer::ccTouchEnded(CCTouch *pTouch,CCEvent *pEvent)
{
CCPoint endPoint = CCDirector::sharedDirector()->convertToGL(pTouch->getLocationInView());
distance = endPoint.x - m_touchPoint.x;
if
(
fabs
(distance) > 50)
{
adjustScrollView(distance);
}
}
GalleryLayer::ccTouchCancelled(cocos2d::CCTouch *pTouch,cocos2d::CCEvent *pEvent)
{
CCPoint endPoint = CCDirector::sharedDirector()->convertToGL(pTouch->getLocationInView());
distance = endPoint.x - m_touchPoint.x;
(distance) > 50)
{
adjustScrollView(distance);
}
}
GalleryLayer::adjustScrollView(
offset)
{
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
CCSpriteFrameCache *pCache = CCSpriteFrameCache::sharedSpriteFrameCache();
->getChildByTag(m_nCurPage);
));
(offset<0)
{
m_nCurPage ++;
else
{
@H_502_1508@
m_nCurPage --;
@H_502_1512@
}
(m_nCurPage <1)
{
m_nCurPage = 1;
}
(m_nCurPage > 3)
{
CCLayer *pLayer = ListViewLayer::create();
CCScene *pScene = CCScene::create();
pScene->addChild(pLayer);
CCDirector::sharedDirector()->replaceScene(pScene);
}
else
{
pPoint = (CCSprite *)
->getChildByTag(m_nCurPage);
));
CCPoint adjustPos = ccp(origin.x - visibleSize.width * (m_nCurPage-1),0);
m_pScrollView->setContentOffset(adjustPos,monospace!important; font-size:1em!important; padding:0px!important; border:0px!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; margin:0px!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; min-height:inherit!important; background:none!important">);
}
}
|