void UIPageView::addPage(Layout* page) { if (!page) { return; } if (page->getWidgetType() != WidgetTypeContainer) { return; } if (m_pages->containsObject(page)) { return; } CCSize pSize = page->getSize(); CCSize pvSize = getSize(); if (!pSize.equals(pvSize)) { CCLOG("page size does not match pageview size, it will be force sized!"); page->setSize(pvSize); } page->setPosition(ccp(getPositionXByIndex(m_pages->count()), 0)); m_pages->addObject(page); addChild(page); updateBoundaryPages(); }
void LuaHostWin32::onViewChangeDirection(int directionMode) { BOOL isLandscape = m_project.isLandscapeFrame(); if ((directionMode == ID_VIEW_PORTRAIT && isLandscape) || (directionMode == ID_VIEW_LANDSCAPE && !isLandscape)) { CCSize frameSize = m_project.getFrameSize(); frameSize.setSize(frameSize.height, frameSize.width); relaunch(); } }
void CC3VertexTextureCoordinates::alignWithTextureCoverage( const CCSize& texCoverage ) { CCAssert((texCoverage.width && texCoverage.height), "CC3VertexTextureCoordinates mapsize cannot have zero dimension"); // Don't waste time adjusting if nothing is changing // (eg. POT textures, or new texture has same texture map as old). if (texCoverage.equals(m_mapSize)) return; CC3_TRACE( "[vtx]CC3VertexTextureCoordinates aligning and changing map size from %s to %s but not flipping vertically", stringFromCCSize(m_mapSize).c_str(), stringFromCCSize(texCoverage).c_str() ); // The scale factor CCSize mapRatio = CCSizeMake(texCoverage.width / m_mapSize.width, texCoverage.height / m_mapSize.height); // The amount by which to translate the image vertically GLfloat currVertXln = 1.0f - m_mapSize.height; GLfloat newVertXln = 1.0f - texCoverage.height; for (GLuint i = 0; i < m_vertexCount; i++) { ccTex2F* ptc = (ccTex2F*)getAddressOfElement(i); ptc->u *= mapRatio.width; ptc->v = (ptc->v - currVertXln) * mapRatio.height + newVertXln; } m_mapSize = texCoverage; // Remember what we've set the map size to updateGLBuffer(); }
void UIPageView::insertPage(Layout* page, int idx) { if (idx < 0) { return; } if (!page) { return; } if (page->getWidgetType() != WidgetTypeContainer) { return; } if (m_pages->containsObject(page)) { return; } int pageCount = m_pages->count(); if (idx >= pageCount) { addPage(page); } else { m_pages->insertObject(page, idx); page->setPosition(ccp(getPositionXByIndex(idx), 0)); addChild(page); CCSize pSize = page->getSize(); CCSize pvSize = getSize(); if (!pSize.equals(pvSize)) { CCLOG("page size does not match pageview size, it will be force sized!"); page->setSize(pvSize); } ccArray* arrayPages = m_pages->data; int length = arrayPages->num; for (int i=(idx+1); i<length; i++) { UIWidget* behindPage = dynamic_cast<UIWidget*>(arrayPages->arr[i]); CCPoint formerPos = behindPage->getPosition(); behindPage->setPosition(ccp(formerPos.x+getSize().width, 0)); } updateBoundaryPages(); } }
void CCNode::setContentSize(const CCSize & size) { if ( ! size.equals(m_obContentSize)) { m_obContentSize = size; m_obAnchorPointInPoints = ccp(m_obContentSize.width * m_obAnchorPoint.x, m_obContentSize.height * m_obAnchorPoint.y ); } }
// Initialize the right player's background for the main game scene // // return - false if there was an error in initializing, true otherwise bool BackgroundRLayer::init() { ClipNode* clipNode; // boundary to clip the image if outside the boundary CCSize screenSize; // the size of the window CCSize layerSize; // size of this layer if(!CCLayer::init()) { return false; } // get the window size from the director screenSize = CCDirector::sharedDirector()->getWinSize(); // set layerSize to be the full height and half the width of screenSize, and position the layer to // the right side of the screen layerSize.setSize(screenSize.width * POS_HALF_SCREEN, screenSize.height); setContentSize(layerSize); setPosition(screenSize.width * POS_HALF_SCREEN, 0); // create the clip node and add it clipNode = new ClipNode(); clipNode->autorelease(); clipNode->setPosition(0, 0); clipNode->setClipsToBounds(true); clipNode->setClippingRegion( CCRect(screenSize.width, 0, layerSize.width, layerSize.height) ); addChild(clipNode); // create and add the first background sprite m_background1 = CCSprite::create(RIGHT_BACKGROUND); m_background1->setScale(screenSize.height / m_background1->boundingBox().size.height); m_background1->setPosition( ccp(getPosition().x, screenSize.height * POS_HALF_SCREEN) ); clipNode->addChild(m_background1); // create, position before first background, and add the second background m_background2 = CCSprite::create(RIGHT_BACKGROUND); m_background2->setScale(screenSize.height / m_background2->boundingBox().size.height); m_background2->setPosition( ccp(getPosition().x - m_background2->boundingBox().size.width, screenSize.height * POS_HALF_SCREEN) ); clipNode->addChild(m_background2); return true; }
void CC3Layer::setContentSize( const CCSize& contentSize ) { CCSize oldSize = getContentSize(); super::setContentSize( contentSize ); if ( !contentSize.equals( oldSize ) ) { /// invoke callback onContentSizeChanged(); } }
void CAImageView::setContentSize(const CCSize & size) { if ( ! size.equals(m_obContentSize)) { m_obContentSize = size; m_obAnchorPointInPoints = ccp(m_obContentSize.width * m_obAnchorPoint.x, m_obContentSize.height * m_obAnchorPoint.y ); m_obFrameRect.size = CCSize(m_obContentSize.width * m_fScaleX, m_obContentSize.height * m_fScaleY); this->updateByImageViewScaleType(); arrayMakeObjectsPerformSelector(m_pSubviews, reViewlayout, CAView*); this->updateDraw(); } }
void UISlider::setScale9Size(const CCSize &size) { if (size.equals(CCSizeZero)) { return; } else { m_scale9Size = size; } if (!m_bBarScale9Enable) { return; } dynamic_cast<CCScale9Sprite*>(m_pBarNode)->setContentSize(size); m_fBarLength = m_pBarNode->getContentSize().width; setSlidBallPercent(m_nBarPercent); }
void UIButton::setScale9Size(const CCSize &size) { if (size.equals(CCSizeZero)) { return; } else { m_scale9Size = size; } if (!m_bScale9Enable) { return; } dynamic_cast<CCScale9Sprite*>(m_pButtonNormal)->setContentSize(size); dynamic_cast<CCScale9Sprite*>(m_pButtonClicked)->setContentSize(size); dynamic_cast<CCScale9Sprite*>(m_pButtonDisable)->setContentSize(size); }
void CAScrollView::setContainerFrame(const CCPoint& point, const CCSize& size) { if (!size.equals(CCSizeZero)) { CCRect rect; rect.origin = point; rect.size = size; m_pContainer->setFrame(rect); } else { m_pContainer->setFrameOrigin(point); } CCRect rect = m_pContainer->getFrame(); m_bSlidingMinX = fabsf(rect.getMinX()) < FLT_EPSILON; m_bSlidingMaxX = fabsf(rect.getMaxX() - this->getBounds().size.width) < FLT_EPSILON; m_bSlidingMinY = fabsf(rect.getMinY()) < FLT_EPSILON; m_bSlidingMaxY = fabsf(rect.getMaxY() - this->getBounds().size.height) < FLT_EPSILON; }
bool CATabBar::init(const CAVector<CATabBarItem*>& items, const CCSize& size) { if (!CAView::init()) { return false; } this->setColor(CAColor_clear); this->setItems(items); CCSize winSize = CAApplication::getApplication()->getWinSize(); CCSize contentSize = size.equals(CCSizeZero) ? CCSize(winSize.width, _px(98)) : size; this->setContentSize(contentSize); CADipRect rect = this->getBounds(); rect.origin = rect.size / 2; rect.size.width = MIN(rect.size.width, 1024); m_pContentView = new CAView(); m_pContentView->setCenter(rect); this->addSubview(m_pContentView); m_pContentView->release(); unsigned int count = (unsigned int)m_pItems.size(); m_cItemSize = m_pContentView->getBounds().size; m_cItemSize.width = rect.size.width/count; if (m_pButtons.empty()) { for (unsigned int i=0; i<count; i++) { CADipRect rect = CADipRectZero; rect.size = m_cItemSize; rect.origin.x = m_cItemSize.width * i; CAButton* btn = CAButton::createWithFrame(rect, CAButtonTypeCustom); m_pContentView->addSubview(btn); btn->setTag(i); btn->addTarget(this, CAControl_selector(CATabBar::setTouchSelected), CAControlEventTouchUpInSide); m_pButtons.pushBack(btn); CABadgeView* badgeView = new CABadgeView(); badgeView->init(); badgeView->setCenter(CADipRect(rect.size.width, 25, 0, 0)); btn->insertSubview(badgeView, 10); m_pBadgeViews.pushBack(badgeView); } } if (m_pBackGroundImage == NULL) { this->setBackGroundImage(CAImage::create("source_material/tabBar_bg.png")); } if (m_pSelectedBackGroundImage == NULL) { this->setSelectedBackGroundImage(CAImage::create("source_material/tabBar_selected_bg.png")); } if (m_pSelectedIndicatorImage == NULL) { this->setSelectedIndicatorImage(CAImage::create("source_material/tabBar_selected_indicator.png")); } return true; }
void CALabel::updateImage() { int fontHeight = CAImage::getFontHeight(m_nfontName.c_str(), m_nfontSize); int defaultLineSpace = fontHeight / 4; unsigned int linenumber = (int)this->getBounds().size.height / fontHeight; CCSize size = CCSizeZero; if (m_bFitFlag) { float width = CAImage::getStringWidth(m_nfontName.c_str(), m_nfontSize, m_nText); if (width > m_obContentSize.width) { if (m_nNumberOfLine > 1) { size = CCSize(this->getBounds().size.width, (defaultLineSpace + m_iLineSpacing + fontHeight) * m_nNumberOfLine); } else if (m_nNumberOfLine == 1) { size = CCSize(width, fontHeight); } else { size.width = this->getBounds().size.width; size.height = CAImage::getStringHeight(m_nfontName.c_str(), m_nfontSize, m_nText, size.width, m_iLineSpacing, m_bWordWrap); } } else { size.height = fontHeight; size.width = width; } } else { if (linenumber == 0) { size = this->getBounds().size; } else { if (m_nNumberOfLine > 0) { size = CCSize(this->getBounds().size.width, (defaultLineSpace + m_iLineSpacing + fontHeight) * MIN(m_nNumberOfLine, linenumber)); } else { size = CCSize(this->getBounds().size.width, (defaultLineSpace + m_iLineSpacing + fontHeight) * linenumber); } } } CAImage* image = CAImage::createWithString(m_nText.c_str(), m_nfontName.c_str(), m_nfontSize, size, m_nTextAlignment, m_nVerticalTextAlignmet, m_bWordWrap, m_iLineSpacing, m_bBold, m_bItalics, m_bUnderLine); this->setImage(image); CC_RETURN_IF(image == NULL); m_cLabelSize = size; CCRect rect = CCRectZero; rect.size.width = this->getBounds().size.width; rect.size.height = size.height; float width = m_bFitFlag ? image->getContentSize().width : MIN(this->getBounds().size.width, image->getContentSize().width); rect.size.width = width; switch (m_nVerticalTextAlignmet) { case CAVerticalTextAlignmentTop: pTextHeight = 0; break; case CAVerticalTextAlignmentCenter: pTextHeight = (this->getBounds().size.height - rect.size.height) / 2; break; case CAVerticalTextAlignmentBottom: pTextHeight = this->getBounds().size.height - rect.size.height; break; default: break; } if (m_bFitFlag) { if (!size.equals(m_obContentSize)) { if (m_bFrame) { CCRect rect = this->getFrame(); rect.size = size; this->setFrame(rect); } else { CCRect rect = this->getCenter(); rect.size = size; this->setCenter(rect); } } } this->setImageRect(rect); }
CCObject* CCSize::copyWithZone(CCZone* pZone) { CCSize* pRet = new CCSize(); pRet->setSize(this->width, this->width); return pRet; }
CCSize* sizeCreate(float width, float height) { CCSize* pRet = new CCSize(width, height); pRet->autorelease(); return pRet; }
bool CPullMachHelpLayer::init() { if (!CCLayer::init()) return false; CCSize barDownSize; //µ×Ãæ±ß¿ò³ß´ç CCSize barUpSize; //ÉÏÃæ±ß¿ò³ß´ç CCSize infoBgSize; //ÐÅÏ¢±³¾°³ß´ç CCSize infoViewSize; //ÐÅÏ¢¿ÉÊӳߴç CCSprite * pSprite = NULL; if (m_pResManager->GenerateNodeByCfgID(eSpriteType_Base, PullMach_Bg_Help_Bar_Down, pSprite)) { barDownSize = pSprite->getContentSize(); pSprite->setAnchorPoint(CCPointZero); pSprite->setPosition(CCPointZero); this->addChild(pSprite); } { float fHeight = this->getContentSize().height - 200; infoBgSize.setSize(barDownSize.width, (fHeight > 600) ? 600 : fHeight); CCLayerColor * bgLayer = CCLayerColor::create(ccc4(0, 24, 85, 255), infoBgSize.width, infoBgSize.height); bgLayer->setPosition(ccp(0, barDownSize.height)); this->addChild(bgLayer); } if (m_pResManager->GenerateNodeByCfgID(eSpriteType_Base, PullMach_Bg_Help_Bar_Up, pSprite)) { barUpSize = pSprite->getContentSize(); pSprite->setAnchorPoint(CCPointZero); pSprite->setPosition(ccp(0, barDownSize.height + infoBgSize.height)); this->addChild(pSprite); } //Ìí¼Ó¹ö¶¯ÄÚÈÝ infoViewSize.setSize(infoBgSize.width - 20, infoBgSize.height); if (m_pResManager->GenerateNodeByCfgID(eSpriteType_Base, PullMach_Bg_Help_Info, pSprite)) { pSprite->setAnchorPoint(ccp(0.5f, 0.0f)); pSprite->setPosition(ccp(infoViewSize.width / 2, 0)); } CCLayerColor * layerColor = CCLayerColor::create(ccc4(0, 13, 32, 255), infoViewSize.width, pSprite->getContentSize().height); layerColor->setPosition(CCPointZero); layerColor->addChild(pSprite); m_pScroll = CCScrollView::create(); m_pScroll->setViewSize(infoViewSize); m_pScroll->setPosition(ccp(10, barDownSize.height)); m_pScroll->setDirection(kCCScrollViewDirectionVertical); m_pScroll->addChild(layerColor); m_pScroll->setContentSize(layerColor->getContentSize()); m_pScroll->setContentOffset(m_pScroll->minContainerOffset()); m_pScroll->setTouchPriority(kCCMenuHandlerPriority - 1); this->addChild(m_pScroll); this->setContentSize(CCSize(infoBgSize.width, barDownSize.height + barUpSize.height + infoBgSize.height)); //Ìí¼Ó¹Ø±Õ°´Å¥ CCControlButton* pCloseButton = m_pResManager->CreateControlButton(PullMach_Bt_Help_Close_N, PullMach_Bt_Help_Close_C); pCloseButton->setAnchorPoint(ccp(1, 1)); pCloseButton->setPosition(getContentSize().width - 10, getContentSize().height - 4); pCloseButton->addTargetWithActionForControlEvents(this, cccontrol_selector(CPullMachHelpLayer::OnTouchClose), CCControlEventTouchUpInside); pCloseButton->setScaleX(1.5f); this->addChild(pCloseButton); return true; }
bool MyWorld::init() { if (!oPlatformWorld::init()) { return false; } this->setTouchEnabled(true); // Create Back Menu CCPoint visibleOrigin = CCEGLView::sharedOpenGLView()->getVisibleOrigin(); CCSize visibleSize = CCEGLView::sharedOpenGLView()->getVisibleSize(); CCMenuItemFont *itemBack = CCMenuItemFont::create("Back", this, menu_selector(MyWorld::toExtensionsMainLayer)); itemBack->setPosition(ccp(visibleOrigin.x+visibleSize.width - 50, visibleOrigin.y+25)); CCMenu *menuBack = CCMenu::create(itemBack, NULL); menuBack->setPosition(CCPointZero); this->getUILayer()->addChild(menuBack); // Set Contact Info /* By default all groups won`t collide each other. You could set the contact info before game start or change it later. Group number can only be 0 to 15. */ GROUP_TERRAIN = 0; GROUP_ONE = 1; GROUP_TWO = 2; GROUP_TEST_SENSOR = 15; this->setShouldContact(GROUP_TERRAIN, GROUP_TERRAIN, true); this->setShouldContact(GROUP_TWO, GROUP_TERRAIN, true); this->setShouldContact(GROUP_TEST_SENSOR, GROUP_ONE, true);// Body from GROUP_ONE will be detected by test sensor. // Create Borders oBodyDef* bodyDef = oBodyDef::create(); bodyDef->type = b2_staticBody; vector<b2Vec2> vertices(5); vertices[0].Set(0, 0); vertices[1].Set(visibleSize.width, 0); vertices[2].Set(visibleSize.width, visibleSize.height); vertices[3].Set(0, visibleSize.height); vertices[4].Set(0, 0); bodyDef->attachChain(vertices, 0.4f, 0.4f); oBody* body = bodyDef->toBody(this, GROUP_TERRAIN, 0, 0, 0); CCSprite* sprite = CCSprite::create("Images/Icon.png"); sprite->setPosition(ccp(100,40)); body->addChild(sprite); this->addChild(body); // Create Body sprite = CCSprite::create("Images/Icon.png"); CCSize size = sprite->getContentSize(); bodyDef = oBodyDef::create(); bodyDef->type = b2_dynamicBody; bodyDef->attachPolygon(size.width, size.height, 1.0f, 0.4f, 0.4f);//Body define use bodyDef->attach body = bodyDef->toBody(this, GROUP_ONE, visibleSize.width*0.5f-20.0f, visibleSize.height*0.5f+20.0f, 50.0f); //body->attach(CCBodyDef::polygon(size.width, size.height, 1.0f, 0.4f, 0.4f)); //Body instance use body->attach body->addChild(sprite); this->addChild(body); body = bodyDef->toBody(this, GROUP_TERRAIN, visibleSize.width*0.5f+50.0f, visibleSize.height*0.5f+20.0f); sprite = CCSprite::create("Images/Icon.png"); sprite->runAction( CCRepeatForever::create( CCSequence::create( CCRotateTo::create(3.0f, 45), CCRotateTo::create(3.0f, 0), nullptr))); body->addChild(sprite); this->addChild(body); // Create Test Sensor int SENSOR_TAG = 1; bodyDef = oBodyDef::create(); bodyDef->type = b2_staticBody; //bodyDef->attachPolygonSensor(SENSOR_TAG, visibleSize.width, 40.0f); body = bodyDef->toBody(this, GROUP_TEST_SENSOR, visibleSize.width*0.5f, 20.0f); //CCSensor* sensor = body->getSensorByTag(SENSOR_TAG); oSensor* sensor = body->attachSensor(SENSOR_TAG, oBodyDef::polygon(visibleSize.width, 40.0f)); oSharedEffectCache.load("main.effect"); sensor->bodyEnter += [&](oSensor* sensor, oBody* body) { // When body enters sensor area, remove the body //body->getParent()->removeChild(body); this->query(CCRect(0.0f,0.0f,100.0f,100.0f), [&](oBody* body) { if (body->getGroup() != GROUP_TERRAIN) { body->getParent()->removeChild(body); return true; } return false; }); // Create a jumping grossini using its def _character = _characterDef->toBody(this, GROUP_TWO, 100.0f, 200.0f); CCSprite* sprite = CCSprite::create("Images/grossini.png"); _character->addChild(sprite); this->getCamera()->setFollowRatio(ccp(0.1f,0.1f)); this->getCamera()->follow(_character); this->addChild(_character); oEffect::create(1)->attachTo(_character)->autoRemove()->start(); }; //sensor->bodyEnter += std::make_pair(this, &MyWorld::onBodyEnter); this->addChild(body); /* Create a Platform Character`s Define (The method to make a platform character will be included in Box2D Nodes extension in the future) */ TAG_GROUND_SENSOR = 2; float BOTTOM_OFFSET = 4.0f; float GROUND_SENSOR_HEIGHT = 4.0f; size.setSize(65,116);//The physical size of our character _characterDef = oBodyDef::create(); _characterDef->type = b2_dynamicBody; //_characterDef->fixedRotation = true; float hw = size.width * 0.5f; float hh = size.height * 0.5f; b2Vec2 verts[] = { b2Vec2(-hw, hh), b2Vec2(-hw + BOTTOM_OFFSET, -hh), b2Vec2(hw - BOTTOM_OFFSET, -hh), b2Vec2(hw, hh) }; _characterDef->attachPolygon(verts, 4, 1.0f, 0.4f, 0.4f); _characterDef->attachPolygonSensor( TAG_GROUND_SENSOR, size.width - BOTTOM_OFFSET * 2, GROUND_SENSOR_HEIGHT, b2Vec2(0, -hh - GROUND_SENSOR_HEIGHT * 0.5f)); sprite = CCSprite::create("Images/Icon.png"); //sprite->setOpacity(0); sprite->runAction( oSequence::create( CCSpawn::create( oKeyPos::create(2.0f, 300.0f, 300.0f, oEase::OutBack), oKeyScale::create(2.0f, 3.0f, 3.0f, oEase::InOutElastic), nullptr), CCSpawn::create( oKeyPos::create(2.0f, 100.0f, 100.0f, oEase::OutBack), oKeyScale::create(2.0f, 1.0f, 1.0f, oEase::InOutElastic), nullptr), nullptr)); this->addChild(sprite); this->getCamera()->setBoudary(CCRectMake(-1000, -1000, 2000, 2000)); sprite = CCSprite::create("Images/Icon.png"); sprite->setScale(100.0f); this->addChild(sprite, -100); this->setLayerRatio(-100, ccp(-1.5f, -1.5f)); /* CCSpriteBatchNode* batchNode = CCSpriteBatchNode::createWithTexture(CCTextureCache::sharedTextureCache()->addImage("Images/grossini.png")); sprite = CCSprite::create("Images/grossini.png"); CCSprite* childSp = CCSprite::create("Images/grossini.png"); childSp->setRotation(45.0f); childSp->setPosition(ccp(20,30)); sprite->addChild(childSp); batchNode->addChild(sprite); this->addChild(batchNode);*/ oModelDef* modelDef = oSharedModelCache.load("nvjing.model"); _model = modelDef->toModel(); _model->setPosition(ccp(200,200)); _model->setRecovery(0.2f); _model->setFaceRight(false); _model->setLook("happy"); _model->setLoop(true); _model->play("walk"); this->addChild(_model); return true; }