コード例 #1
0
bool CScrollMenu::init(Size size)
{
	if (!ListView::init())
	{
		return false;
	}
	setSize(size);
	setBounceEnabled(true);
	m_pRadioMenu = RadioButtonSet::create();
	m_sRadioSize = Size(0,size.height);
	m_pRadioMenu->setContentSize(m_sRadioSize);
	m_pRadioMenu->setAnchorPoint(Point::ZERO);
	m_pRadioMenu->SetRelayout(true);
	pushBackCustomItem(m_pRadioMenu);
	addEventListenerScrollView(this,scrollvieweventselector(CScrollMenu::scrollEvent));
	return true;
}
コード例 #2
0
void CCScrollBar::attachToUIScrollView(ScrollView* scrollView, ccInsets insets, bool horizontal) {
	// save flag
	m_horizontal = horizontal;
	
	// add to scroll view
	float thumbLength = 0;
	Widget* svParent = dynamic_cast<Widget*>(scrollView->getParent());
	CCSize svSize = scrollView->getSize();
	CCPoint svOrigin = CCUtils::getOrigin(scrollView);
	CCSize innerSize = scrollView->getInnerContainerSize();
	CCSize sbSize;
	if(horizontal) {
		sbSize = CCSizeMake(m_track->getContentSize().width,
							svSize.width - insets.left - insets.right);
		setContentSize(sbSize);
		setAnchorPoint(ccp(0, 0.5f));
		setPosition(ccp(svOrigin.x + svSize.width / 2,
						svOrigin.y + insets.bottom));
		setRotation(-90);
		svParent->addNode(this, MAX_INT);
		
		// thumb length
		if(m_fixedThumb)
			thumbLength = m_fixedThumb->getContentSize().height;
		else
			thumbLength = MIN(1, svSize.width / innerSize.width) * sbSize.height;
	} else {
		sbSize = CCSizeMake(m_track->getContentSize().width,
							svSize.height - insets.top - insets.bottom);
		setContentSize(sbSize);
		setAnchorPoint(ccp(1, 0.5f));
		setPosition(ccp(svOrigin.x + svSize.width - insets.right,
						svOrigin.y + svSize.height / 2));
		svParent->addNode(this, MAX_INT);
		
		// thumb length
		if(m_fixedThumb)
			thumbLength = m_fixedThumb->getContentSize().height;
		else
			thumbLength = MIN(1, svSize.height / innerSize.height) * sbSize.height;
	}
	
	// add track
	m_track->setPreferredSize(sbSize);
	m_track->setPosition(CCUtils::getLocalCenter(this));
	addChild(m_track);
	
	// clipping node to hold thumb
	CCClippingNode* thumbClipping = CCClippingNode::create(m_track);
	thumbClipping->ignoreAnchorPointForPosition(false);
	thumbClipping->setAnchorPoint(ccp(0.5f, 0.5f));
	thumbClipping->setContentSize(sbSize);
	thumbClipping->setPosition(CCUtils::getLocalCenter(this));
	thumbClipping->setAlphaThreshold(0.5f);
	thumbClipping->setScaleX((sbSize.width - 4) / sbSize.width);
	thumbClipping->setScaleY((sbSize.height - 4) / sbSize.height);
	addChild(thumbClipping);
	
	// thumb or fixed thumb
	if(m_thumb) {
		m_thumb->setPreferredSize(CCSizeMake(sbSize.width, thumbLength));
		m_thumb->setPosition(ccp(sbSize.width / 2,
								 sbSize.height - thumbLength / 2));
		thumbClipping->addChild(m_thumb);
	} else {
		m_fixedThumb->setPosition(ccp(sbSize.width / 2,
									  sbSize.height - thumbLength / 2));
		thumbClipping->addChild(m_fixedThumb);
	}
	
	// sync thumb position
	syncThumbPositionForUIScrollView(scrollView);
	
	// listen to scrollview scrolling event
	scrollView->addEventListenerScrollView(this, scrollvieweventselector(CCScrollBar::onUIScrollViewEvent));
    
    // init fade out
    if(m_initFadeOut) {
        m_fadingOut = true;
        CCUtils::setOpacityRecursively(this, 0);
    }
}
コード例 #3
0
bool UIScrollViewTest_Vertical::init()
{
    if (UIScene::init())
    {
        CCSize widgetSize = m_pWidget->getSize();
        
        // Add a label in which the scrollview alert will be displayed
        m_pDisplayValueLabel = UILabel::create();
        m_pDisplayValueLabel->setText("Move by vertical direction");
        m_pDisplayValueLabel->setFontName("Marker Felt");
        m_pDisplayValueLabel->setFontSize(32);
        m_pDisplayValueLabel->setAnchorPoint(ccp(0.5f, -1));
        m_pDisplayValueLabel->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f + m_pDisplayValueLabel->getContentSize().height * 1.5));
        m_pUiLayer->addWidget(m_pDisplayValueLabel);
        
        // Add the alert
        UILabel *alert = UILabel::create();
        alert->setText("ScrollView vertical");
        alert->setFontName("Marker Felt");
        alert->setFontSize(30);
        alert->setColor(ccc3(159, 168, 176));
        alert->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.075));
        m_pUiLayer->addWidget(alert);
        
        UILayout *background = dynamic_cast<UILayout*>(m_pUiLayer->getWidgetByName("background_Panel"));
        
        // Create the scrollview by vertical
        UIScrollView* scrollView = UIScrollView::create();
        scrollView->setTouchEnabled(true);
        scrollView->setBounceEnabled(true);
        scrollView->setSize(CCSizeMake(280, 150));        
        CCSize backgroundSize = background->getContentSize();
        scrollView->setPosition(ccp((widgetSize.width - backgroundSize.width) / 2 +
                               (backgroundSize.width - scrollView->getSize().width) / 2,
                               (widgetSize.height - backgroundSize.height) / 2 +
                               (backgroundSize.height - scrollView->getSize().height) / 2));
        scrollView->addEventListenerScrollView(this, scrollvieweventselector(UIScrollViewTest_Vertical::scrollEvent));
        m_pUiLayer->addWidget(scrollView);
        
        UIImageView* imageView = UIImageView::create();
        imageView->loadTexture("cocosgui/ccicon.png");
        
        float innerWidth = scrollView->getSize().width;
        float innerHeight = scrollView->getSize().height + imageView->getSize().height * 2;
        
        scrollView->setInnerContainerSize(CCSizeMake(innerWidth, innerHeight));
        
        
        UIButton* button = UIButton::create();
        button->setTouchEnabled(true);
        button->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", "");
        button->setPosition(ccp(innerWidth / 2, scrollView->getInnerContainerSize().height - button->getSize().height / 2));
        scrollView->addChild(button);
        
        UIButton* titleButton = UIButton::create();
        titleButton->setTouchEnabled(true);
        titleButton->loadTextures("cocosgui/backtotopnormal.png", "cocosgui/backtotoppressed.png", "");
        titleButton->setTitleText("Title Button");
        titleButton->setPosition(ccp(innerWidth / 2, button->getBottomInParent() - button->getSize().height));
        scrollView->addChild(titleButton);
        
        UIButton* button_scale9 = UIButton::create();
        button_scale9->setTouchEnabled(true);
        button_scale9->setScale9Enabled(true);
        button_scale9->loadTextures("cocosgui/button.png", "cocosgui/buttonHighlighted.png", "");
        button_scale9->setSize(CCSizeMake(100, button_scale9->getContentSize().height));
        button_scale9->setPosition(ccp(innerWidth / 2, titleButton->getBottomInParent() - titleButton->getSize().height));
        scrollView->addChild(button_scale9);
        
        imageView->setPosition(ccp(innerWidth / 2, imageView->getSize().height / 2));
        scrollView->addChild(imageView);
        
        
        
        
//        UIButton* button_1 = UIButton::create();
//        button_1->setTouchEnabled(true);
//        button_1->loadTextures("cocosgui/animationbuttonnormal.png", "cocosgui/animationbuttonpressed.png", "");
//        button_1->addTouchEventListener(this, toucheventselector(UIScrollViewTest_Vertical::touchEvent));
//        
//        Layout* layout = Layout::create();
//        layout->setSize(button_1->getSize());
//        layout->setBackGroundImage("cocosgui/green_edit.png");
//        layout->setBackGroundImageScale9Enabled(true);
////        layout->setBackGroundColorType(LAYOUT_COLOR_SOLID);
////        layout->setBackGroundColor(ccc3(0, 255, 0));
//        layout->setPosition(ccp(imageView->getPosition().x, layout->getSize().height * 2));
//        
//        button_1->setPosition(ccp(button_1->getSize().width / 2, button_1->getSize().height / 2));
//        
//        layout->addChild(button_1);
//        scrollView->addChild(layout);
        
        return true;
    }
    
    return false;
}