void CAImageView::setContentSize(const DSize & size) { if (CAViewAnimation::areAnimationsEnabled() && CAViewAnimation::areBeginAnimations()) { CAViewAnimation::getInstance()->setContentSize(size, this); } else if (!size.equals(m_obContentSize)) { m_obContentSize = size; m_obAnchorPointInPoints = DPoint(m_obContentSize.width * m_obAnchorPoint.x, m_obContentSize.height * m_obAnchorPoint.y ); m_obFrameRect.size = DSize(m_obContentSize.width * m_fScaleX, m_obContentSize.height * m_fScaleY); this->updateByImageViewScaleType(); if(!m_obSubviews.empty()) { CAVector<CAView*>::iterator itr; for (itr=m_obSubviews.begin(); itr!=m_obSubviews.end(); itr++) { (*itr)->reViewlayout(); } } this->updateDraw(); } }
void CAView::setContentSize(const DSize & contentSize) { if (CAViewAnimation::areAnimationsEnabled() && CAViewAnimation::areBeginAnimations()) { CAViewAnimation::getInstance()->setContentSize(contentSize, this); } else if (!contentSize.equals(m_obContentSize)) { m_obContentSize = contentSize; float anchorPointInPointsX = m_obContentSize.width * m_obAnchorPoint.x; float anchorPointInPointsY = m_obContentSize.height * m_obAnchorPoint.y; m_obAnchorPointInPoints = DPoint(anchorPointInPointsX, anchorPointInPointsY); float frameRectWidth = m_obContentSize.width * m_fScaleX; float frameRectHeight = m_obContentSize.height * m_fScaleY; m_obFrameRect.size = DSize(frameRectWidth, frameRectHeight); this->updateImageRect(); if(!m_obSubviews.empty()) { CAVector<CAView*>::iterator itr; for (itr=m_obSubviews.begin(); itr!=m_obSubviews.end(); itr++) { (*itr)->reViewlayout(); } } this->updateDraw(); } }
void CAScrollView::setContainerFrame(const DPoint& point, const DSize& size) { if (!size.equals(DSizeZero)) { DRect rect; rect.origin = point; rect.size = size; m_pContainer->setFrame(rect); } else { m_pContainer->setFrameOrigin(point); } DRect rect = m_pContainer->getFrame(); }
void CAImageView::setContentSize(const DSize & contentSize) { if (CAViewAnimation::areAnimationsEnabled() && CAViewAnimation::areBeginAnimations()) { CAViewAnimation::getInstance()->setContentSize(contentSize, this); } else if (!contentSize.equals(m_obContentSize)) { m_obContentSize = contentSize; m_obAnchorPointInPoints.x = m_obContentSize.width * m_obAnchorPoint.x; m_obAnchorPointInPoints.y = m_obContentSize.height * m_obAnchorPoint.y; CAVector<CAView*>::iterator itr; for (itr=m_obSubviews.begin(); itr!=m_obSubviews.end(); itr++) { (*itr)->reViewlayout(m_obContentSize); } this->updateByImageViewScaleType(); this->updateDraw(); } }
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; DSize size = DSizeZero; 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 = DSize(this->getBounds().size.width, (defaultLineSpace + m_iLineSpacing + fontHeight) * m_nNumberOfLine); } else if (m_nNumberOfLine == 1) { size = DSize(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 = DSize(this->getBounds().size.width, (defaultLineSpace + m_iLineSpacing + fontHeight) * MIN(m_nNumberOfLine, linenumber)); } else { size = DSize(this->getBounds().size.width, (defaultLineSpace + m_iLineSpacing + fontHeight) * linenumber); } } } CAImage* image = CAImage::createWithString(m_nText.c_str(), m_cFontColor, 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; DRect rect = DRectZero; 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) { DRect rect = this->getFrame(); rect.size = size; this->setFrame(rect); } else { DRect rect = this->getCenter(); rect.size = size; this->setCenter(rect); } } } this->setImageRect(rect); }
void CAImageView::updateByImageViewScaleType() { CC_RETURN_IF(m_pobImage == NULL); CC_RETURN_IF(m_bUpdateByImageViewScaleType); m_bUpdateByImageViewScaleType = true; DSize viewSize = DSize(m_obContentSize); DRect rect = DRect(m_obRect); DSize imageSize = m_obRect.size; float viewRatio = viewSize.width / viewSize.height; float imageRatio = imageSize.width / imageSize.height; switch (m_eImageViewScaleType) { case CAImageViewScaleTypeFitViewByHorizontal: { viewSize.width = viewSize.height * imageRatio; } break; case CAImageViewScaleTypeFitViewByVertical: { viewSize.height = viewSize.width / imageRatio; } break; default: break; } m_fLeft = 0; m_fTop = 0; m_fRight = viewSize.width; m_fBottom = viewSize.height; switch (m_eImageViewScaleType) { case CAImageViewScaleTypeFitImageCrop: { if (imageRatio > viewRatio) { rect.size.width = imageSize.height * viewRatio; rect.origin.x = (imageSize.width - rect.size.width) / 2; } else if (imageRatio < viewRatio) { rect.size.height = imageSize.width / viewRatio; rect.origin.y = (imageSize.height - rect.size.height) / 2; } } break; case CAImageViewScaleTypeFitImageInside: { if (imageRatio > viewRatio) { m_fTop = (viewSize.height - viewSize.width / imageRatio) / 2; m_fBottom = m_fTop + viewSize.width / imageRatio; } else if (imageRatio < viewRatio) { m_fLeft = (viewSize.width - viewSize.height * imageRatio) / 2; m_fRight = m_fLeft + viewSize.height * imageRatio; } } break; default: break; } this->setImageRect(rect); if (!viewSize.equals(m_obContentSize)) { if (m_bFrame) { DRect rect = this->getFrame(); rect.size = viewSize; this->setFrame(rect); } else { DRect rect = this->getCenter(); rect.size = viewSize; this->setCenter(rect); } } m_bUpdateByImageViewScaleType = false; }