本文整理汇总了C++中CAImage::getContentSize方法的典型用法代码示例。如果您正苦于以下问题:C++ CAImage::getContentSize方法的具体用法?C++ CAImage::getContentSize怎么用?C++ CAImage::getContentSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CAImage
的用法示例。
在下文中一共展示了CAImage::getContentSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateImage
void CALabel::updateImage()
{
CAImage *tex = new CAImage();
float fontHeight = getFontHeight(m_nfontName.c_str(), m_nfontSize);
unsigned int linenumber = (int)this->getBounds().size.height/fontHeight;
CCSize size = CCSizeZero;
if ((m_nNumberOfLine <= linenumber && m_nNumberOfLine != 0))
{
size = CCSizeMake(this->getBounds().size.width, fontHeight*m_nNumberOfLine);
}
else
{
size = this->getBounds().size;
}
tex->initWithString(m_nText.c_str(),
m_nfontName.c_str(),
m_nfontSize* CC_CONTENT_SCALE_FACTOR(),
size,
m_nTextAlignment,
m_nVerticalTextAlignmet);
m_cLabelSize = tex->getContentSize();
CCRect rect = CCRectZero;
rect.size.width = this->getBounds().size.width;
rect.size.height = tex->getContentSize().height;
float width = MIN(this->getBounds().size.width,tex->getContentSize().width);
rect.size.width = width;
this->setImage(tex);
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;
}
this->setImageRect(rect);
tex->release();
return ;
}
示例2: updateImage
bool CALabel::updateImage()
{
if (m_bRunning == false)
{
return false;
}
CAImage *tex = new CAImage();
if (!tex) {
return false;
}
caFontDefinition fontDef = setFontDefiniton(true);
CAImage *at = new CAImage();
at->initWithString("9m", fontDef.m_fontName.c_str(), fontDef.m_fontSize, CCSizeZero, fontDef.m_alignment, fontDef.m_vertAlignment);
float fontHeight = at->getContentSize().height+1;
at->release();
unsigned int linenumber = (int)this->getBounds().size.height/fontHeight;
if (m_nNumberOfLine <= linenumber && m_nNumberOfLine != 0)
{
tex->initWithString(m_nText.c_str(), fontDef.m_fontName.c_str(), fontDef.m_fontSize, CCSizeZero, fontDef.m_alignment, fontDef.m_vertAlignment);
}
else
{
if (this->getBounds().size.width == 0 && this->getBounds().size.height == 0)
{
tex->initWithString(m_nText.c_str(), fontDef.m_fontName.c_str(), fontDef.m_fontSize, CCSizeZero, fontDef.m_alignment, fontDef.m_vertAlignment);
}
else
{
tex->initWithString(m_nText.c_str(), fontDef.m_fontName.c_str(), fontDef.m_fontSize, this->getBounds().size, fontDef.m_alignment, fontDef.m_vertAlignment);
}
}
CCRect rect = CCRectZero;
rect.size = tex->getContentSize();
m_cLabelSize = tex->getContentSize();
m_pTextImage->setImage(tex);
m_pTextImage->setImageRect(rect);
m_pTextImage->setColor(ccc3(m_nTextcolor.r, m_nTextcolor.g, m_nTextcolor.b));
m_pTextImage->setOpacity(m_nTextcolor.a);
m_pTextImage->CAView::setFrameOrigin(CCPoint(0, (this->getBounds().size.height - rect.size.height)/2));
tex->release();
return true;
}
示例3: updateImage
void CATextField::updateImage()
{
float fontHeight = CAImage::getFontHeight("Arial", m_fFontSize);
CCSize size = CCSizeZero;
size = CCSizeMake(0, fontHeight);
std::string text = "";
if (spaceHolderIsOn)
{
text = m_sPlaceHolder;
this->setColor(m_cSpaceHolderColor);
} else
{
text = m_sText;
this->setColor(m_cTextColor);
}
CAImage* image = CAImage::createWithString(text.c_str(),
"Arial",
m_fFontSize * CC_CONTENT_SCALE_FACTOR(),
size,
m_aTextAlignment,
CAVerticalTextAlignmentCenter);
CCRect rect = CCRectZero;
float imageWidth = 0;
if (image != NULL)
{
rect.size.height = image->getContentSize().height;
m_rLabelRect.size = image->getContentSize();
imageWidth = image->getContentSize().width;
}
if (spaceHolderIsOn)
{
m_rLabelRect = CCRectZero;
}
float width = MIN(labelWidth, imageWidth);
rect.size.width = width;
this->setImage(image);
pTextHeight = (this->getBounds().size.height-rect.size.height)/2;
rect.origin.x = m_fString_left_offX;
this->setImageRect(rect);
return ;
}
示例4: showTitle
void CANavigationBar::showTitle()
{
CCRect rect;
rect.origin = this->getBounds().size/2;
rect.size.height = this->getBounds().size.height;
rect.size.width = this->getBounds().size.width - rect.size.height * 4;
if (m_pTitle)
{
this->removeSubview(m_pTitle);
m_pTitle = NULL;
}
CAImage* image = m_pItems.back()->getTitleViewImage();
if (image)
{
float height = MIN(image->getContentSize().height, rect.size.height * 0.75f);
float width = height * image->getContentSize().width / image->getContentSize().height;
width = MIN(rect.size.width, width);
rect.size = CCSize(width, height);
m_pTitle = CAImageView::createWithImage(image);
m_pTitle->setCenter(rect);
this->addSubview(m_pTitle);
}
else
{
int fontSize = this->getBounds().size.height * 0.35f / CROSSAPP_ADPTATION_RATIO;
CALabel* title = CALabel::createWithCenter(rect);
title->setTextAlignment(CATextAlignmentCenter);
title->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter);
title->setNumberOfLine(1);
title->setColor(CAColor_white);
title->setFontSize(fontSize);
this->addSubview(title);
m_pTitle = title;
}
if (!m_pItems.empty())
{
std::string str = m_pItems.back()->getTitle();
((CALabel*)m_pTitle)->setText(str.c_str());
}
}
示例5: updateImage
void CATextView::updateImage()
{
std::string text;
if (m_szText.empty())
{
text = m_sPlaceHolder;
}
else
{
text = m_szText;
}
m_cFontColor = m_szText.empty() ? m_cPlaceHolderColor : m_cTextColor;
float width = this->getBounds().size.width;
width -= m_iHoriMargins * 2;
CAImage* image = g_AFTFontCache.initWithString(text.c_str(),
m_szFontName.c_str(),
m_iFontSize,
width,
0,
CATextAlignmentLeft,
CAVerticalTextAlignmentTop,
m_bWordWrap,
m_iLineSpacing,
false,
false,
false,
&m_vLinesTextView);
if (m_szText.empty())
{
m_vLinesTextView.clear();
}
m_pImageView->setColor(m_cFontColor);
m_pImageView->setImage(image);
CCRect rect = CCRectZero;
if (image)
{
rect.size = image->getContentSize();
}
m_pImageView->setImageRect(rect);
m_pContainerView->setViewSize(CCSizeMake(rect.size.width, rect.size.height));
rect.origin = CCPointMake(m_iHoriMargins, 0);
m_pImageView->setFrame(rect);
calcCursorPosition();
}
示例6: getStringLength
float CATextField::getStringLength(const std::string &var)
{
float length = 0;
CAImage *image = CAImage::createWithString(var.c_str(),
"",
m_fFontSize,
CCSizeZero,
CATextAlignmentLeft,
CAVerticalTextAlignmentCenter);
length = image->getContentSize().width;
return length;
}
示例7: getFontHeight
NS_CC_BEGIN
static unsigned int getFontHeight(const char *fontName, int fontSize)
{
unsigned int result=0;
CAImage *image = new CAImage();
image->initWithString("9m", fontName, fontSize, CCSizeZero, CATextAlignmentLeft, CAVerticalTextAlignmentTop);
CAImage *image1 = new CAImage();
image1->initWithString("9\nm", fontName, fontSize, CCSizeZero, CATextAlignmentLeft, CAVerticalTextAlignmentTop);
result = image1->getContentSize().height-image->getContentSize().height;
image->release();
image1->release();
return result;
}
示例8: initMarkSprite
void CATextField::initMarkSprite()
{
int pixels[1][1];
pixels[0][0] = 0;
CAImage *image = new CAImage();
image->initWithData(pixels, kCAImagePixelFormat_RGB888, 1, 1, CCSizeMake(m_fFontSize / 10.0f, m_fFontSize));
m_pMark = CAImageView::createWithImage(image);
m_pMark->setVisible(false);
CCSize contentsize =this->getBounds().size;
m_pMark->setFrame(CCRect(0, 0, image->getContentSize().width, m_fFontSize));
this->addSubview(m_pMark);
m_pCursorAction = CCRepeatForever::create((CCActionInterval *) CCSequence::create(CCFadeOut::create(0.5f), CCFadeIn::create(0.5f), NULL));
m_pMark->runAction(m_pCursorAction);
}
示例9: getStringLength
int CATextView::getStringLength(const std::string &var)
{
#if (CC_TARGET_PLATFORM != CC_PLATFORM_LINUX)
return g_AFTFontCache.getStringWidth(m_szFontName.c_str(), m_iFontSize, var);
#else
CAImage *image = CAImage::createWithString(var.c_str(),
"",
m_iFontSize,
CCSizeZero,
CATextAlignmentLeft,
CAVerticalTextAlignmentCenter);
if (image != NULL)
{
return image->getContentSize().width;
}
return 0;
#endif
}
示例10: setGif
void CAGifView::setGif(CAGif* gif)
{
CC_SAFE_RETAIN(gif);
CC_SAFE_DELETE(m_pGif);
m_pGif = gif;
if (m_pGif)
{
CAImage* image = m_pGif->getImage();
this->setImage(image);
CCRect rect = CCRectZero;
rect.size = image->getContentSize();
this->setImageRect(rect);
if(m_pGif->getGifImageCounts()>1)
{
m_nGifcount = m_pGif->getGifImageCounts();
CAScheduler::schedule(schedule_selector(CAGifView::updateGif), this, 0);
}
this->setGifBounds(this->getBounds().size);
}
}
示例11: initWithFrame
bool CAIndicator::initWithFrame(const CCRect& rect, CAIndicatorType type)
{
if (!CAView::init())
{
return false;
}
this->setFrame(rect);
m_eType = type;
CAImage* image = CAImage::create("indicator.png");
CCRect r;
r.origin = ccpSub(ccpMult(image->getContentSize(), 0.5f), CCPoint(0.5f, 0.5f));
r.size = CCSize(1.0f, 1.0f);
m_pIndicator = CCScale9Sprite::createWithImage(r, image);
this->addSubview(m_pIndicator);
return true;
}
示例12: updateImage
void updateImage()
{
float width = this->getBounds().size.width;
CAImage* image = g_AFTFontCache.initWithString(m_szText.c_str(),
m_pCATextView->getTextColor(),
m_szFontName.c_str(),
m_pCATextView->getTextFontSize(),
width,
0,
CATextAlignmentLeft,
CAVerticalTextAlignmentTop,
true,
0,
false,
false,
false,
false,
&m_vLinesTextView);
if (m_szText.empty())
{
m_vLinesTextView.clear();
}
m_pImageView->setColor(CAColor_white);
m_pImageView->setImage(image);
DRect rect = DRectZero;
if (image)
{
rect.size = image->getContentSize();
}
m_pImageView->setImageRect(rect);
m_pContainerView->setViewSize(rect.size);
m_pImageView->setFrame(rect);
calcCursorPosition();
m_pCurPosition = m_pCursorMark->getCenterOrigin();
}
示例13: updateGif
void CAGifView::updateGif(float delta)
{
CC_RETURN_IF(!m_pGif);
float ldelta = (uint32_t)(delta * 1000) * m_fTimes;
m_fDurTime += ldelta;
if(m_fDurTime > m_pGif->getImageDuration())
{
m_pGif->nextGifImageIndex();
CAImage* image = m_pGif->getImage();
this->setImage(image);
if (image)
{
CCRect rect = CCRectZero;
rect.size = image->getContentSize();
this->setImageRect(rect);
}
m_fDurTime = 0;
}
if (!m_bIsRepeatForever && m_pGif->getGifImageIndex() >= m_pGif->getGifImageCounts() - 1)
{
CAScheduler::unschedule(schedule_selector(CAGifView::updateGif), this);
}
}
示例14: updateImage
void updateImage()
{
const std::string& sPlaceHolder = m_pTextFieldX->getPlaceHolderText();
CAColor4B cFontColor;
std::string text;
if (m_sText.empty())
{
text = sPlaceHolder;
cFontColor = m_pTextFieldX->getPlaceHolderColor();
}
else
{
text = m_sText;
cFontColor = m_pTextFieldX->getTextColor();
}
if (m_pTextFieldX->isSecureTextEntry())
{
std::string password;
for (std::string::size_type i = 0; i < m_sText.length(); i++)
{
password.append("*");
}
if (password.empty())
{
text = sPlaceHolder;
}
else
{
text = password;
}
}
int fontSize = m_pTextFieldX->getFontSize();
m_iFontHeight = CAImage::getFontHeight(m_szFontName.c_str(), fontSize);
DSize size = DSize(0, m_iFontHeight);
CAImage* image = CAImage::createWithString(text.c_str(),
cFontColor,
m_szFontName.c_str(),
fontSize,
size,
CATextAlignmentLeft,
CAVerticalTextAlignmentCenter,
true);
DRect rect = DRectZero;
if (sPlaceHolder.length() == 0)
{
this->setImage(image);
this->setImageRect(rect);
}
CC_RETURN_IF(image == NULL);
rect.size.height = image->getContentSize().height;
rect.size.width = MIN(m_iLabelWidth, image->getContentSize().width);
if (text.empty())
{
m_cImageSize = DSizeZero;
}
else
{
m_cImageSize = image->getContentSize();
}
this->setImage(image);
rect.origin.x = -m_iString_o_length;
this->setImageRect(rect);
}
示例15: updateImage
void CATextField::updateImage()
{
std::string text = "";
if (m_sText.empty())
{
text = m_sPlaceHolder;
this->setColor(m_cSpaceHolderColor);
}
else
{
text = m_sText;
this->setColor(m_cTextColor);
}
std::string password("");
if (m_nInputType == KEY_BOARD_INPUT_PASSWORD)
{
for (std::string::size_type i = 0; i<m_sText.length(); i++)
{
password.append("*");
}
if (m_sText.empty())
{
text = m_sPlaceHolder;
}
else
{
text = password;
}
}
float dt = 1.0f;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
dt = 1.2f;
#endif
CCSize size = CCSizeMake(0, m_iFontHeight*dt);
CAImage* image = CAImage::createWithString(text.c_str(),
m_nfontName.c_str(),
m_iFontSize,
size,
CATextAlignmentLeft,
CAVerticalTextAlignmentCenter,
true);
CCRect rect = CCRectZero;
if (m_sPlaceHolder.length() == 0)
{
this->setImage(image);
this->setImageRect(rect);
}
if (image == NULL )
return;
rect.size.height = image->getContentSize().height;
rect.size.width = MIN(m_iLabelWidth, image->getContentSize().width);
if (text.empty())
{
m_cImageSize = CCSizeZero;
}
else
{
m_cImageSize = image->getContentSize();
}
this->setImage(image);
rect.origin.x = -m_iString_left_offX;
this->setImageRect(rect);
}