bool UIWidgetAddNodeTest::init() { if (UIScene::init()) { CCSize widgetSize = m_pWidget->getSize(); // Add the alert UILabel *alert = UILabel::create(); alert->setText("Widget Add Node"); 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 * 1.75)); m_pUiLayer->addWidget(alert); // Create the ui node container UIWidget* widget = UIWidget::create(); widget->setPosition(ccp(widgetSize.width / 2.0f, widgetSize.height / 2.0f)); m_pUiLayer->addWidget(widget); CCSprite* sprite = CCSprite::create("cocosui/ccicon.png"); sprite->setPosition(ccp(0, sprite->boundingBox().size.height / 4)); widget->addNode(sprite); return true; } return false; }
void CCScrollBar::attachToCCScrollView(CCScrollView* scrollView, ccInsets insets, bool horizontal) { // it must have parent node CCNode* svParent = scrollView->getParent(); if(!svParent) { CCLOGWARN("CCScrollView must be added to one node before calling attachToCCScrollView"); return; } // save flag m_horizontal = horizontal; // add to scroll view float thumbLength = 0; CCPoint svOrigin = CCUtils::getOrigin(scrollView); CCSize svSize = scrollView->getViewSize(); CCSize innerSize = scrollView->getContainer()->getContentSize(); 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); UIWidget* svpWidght = dynamic_cast<UIWidget*>(svParent); if(svpWidght) svpWidght->addNode(this, MAX_INT); else svParent->addChild(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)); UIWidget* svpWidght = dynamic_cast<UIWidget*>(svParent); if(svpWidght) svpWidght->addNode(this, MAX_INT); else svParent->addChild(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 syncThumbPositionForCCScrollView(scrollView); // delegate m_oldCCDelegate = scrollView->getDelegate(); scrollView->setDelegate(this); // init fade out if(m_initFadeOut) { m_fadingOut = true; CCUtils::setOpacityRecursively(this, 0); } }