void CAImageCache::dumpCachedImageInfo() { unsigned int count = 0; unsigned int totalBytes = 0; CAMap<std::string, CAImage*>::iterator itr; for (itr=m_mImages.begin(); itr!=m_mImages.end(); itr++) { CAImage* image = itr->second; unsigned int bpp = image->bitsPerPixelForFormat(); // Each texture takes up width * height * bytesPerPixel bytes. unsigned int bytes = image->getPixelsWide() * image->getPixelsHigh() * bpp / 8; totalBytes += bytes; count++; CCLog("CrossApp: \"%s\" rc=%lu id=%lu %lu x %lu @ %ld bpp => %lu KB", itr->first.c_str(), (long)image->retainCount(), (long)image->getName(), (long)image->getPixelsWide(), (long)image->getPixelsHigh(), (long)bpp, (long)bytes / 1024); } CCLog("CrossApp: CAImageCache dumpDebugInfo: %ld images, for %lu KB (%.2f MB)", (long)count, (long)totalBytes / 1024, totalBytes / (1024.0f*1024.0f)); }
bool CATextView::init() { if (!CAView::init()) { return false; } this->setColor(CAColor_clear); CAImage* image = CAImage::create("source_material/textField_bg.png"); DRect capInsets = DRect(image->getPixelsWide()/2 ,image->getPixelsHigh()/2 , 1, 1); m_pBackgroundView = CAScale9ImageView::createWithImage(image); m_pBackgroundView->setCapInsets(capInsets); m_pBackgroundView->setImage(image); this->insertSubview(m_pBackgroundView, -1); m_pShowImageView = CAImageView::createWithFrame(DRect(0, 0, 1, 1)); m_pShowImageView->setTextTag("textView"); this->addSubview(m_pShowImageView); CATextViewWin32 *text = new CATextViewWin32(this); text->initWithFrame(DRect(0, 0, 1, 1)); text->autorelease(); this->addSubview(text); m_pTextView = (CATextViewWin32*)text; return true; }
bool CATextView::init() { CAImage* image = CAImage::create("source_material/textField_bg.png"); DRect capInsets = DRect(image->getPixelsWide()/2 ,image->getPixelsHigh()/2 , 1, 1); m_pBackgroundView = CAScale9ImageView::createWithImage(image); m_pBackgroundView->setCapInsets(capInsets); this->insertSubview(m_pBackgroundView, -1); m_pShowImageView = CAImageView::createWithFrame(DRect(0, 0, 1, 1)); m_pShowImageView->setTextTag("textView"); this->addSubview(m_pShowImageView); return true; }
bool CATextField::init() { if (!CAView::init()) { return false; } this->setColor(CAColor_clear); CAImage* image = CAImage::create("source_material/textField_bg.png"); m_pBackgroundView = CAScale9ImageView::createWithFrame(DRect(0, 0, 1, 1)); m_pBackgroundView->setLayout(DLayoutFill); m_pBackgroundView->setCapInsets(DRect(image->getPixelsWide() / 2, image->getPixelsHigh() / 2, 1, 1)); m_pBackgroundView->setImage(image); this->addSubview(m_pBackgroundView); CATextFieldWin32 *text = new CATextFieldWin32(this); text->initWithFrame(DRect(0, 0, 1, 1)); this->addSubview(text); text->release(); m_pTextField = (CATextFieldWin32*)text; return true; }
void CAView::setImageCoords(DRect rect) { CAImage* image = m_pobBatchView ? m_pobImageAtlas->getImage() : m_pobImage; CC_RETURN_IF(! image); float atlasWidth = (float)image->getPixelsWide(); float atlasHeight = (float)image->getPixelsHigh(); float left, right, top, bottom; if (m_bRectRotated) { #if CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL left = (2 * rect.origin.x + 1) / (2 * atlasWidth); right = left + (rect.size.height * 2 - 2) / (2 * atlasWidth); top = (2 * rect.origin.y + 1) / (2 * atlasHeight); bottom = top + (rect.size.width * 2 - 2) / (2 * atlasHeight); #else left = rect.origin.x / atlasWidth; right = (rect.origin.x + rect.size.height) / atlasWidth; top = rect.origin.y / atlasHeight; bottom = (rect.origin.y + rect.size.width) / atlasHeight; #endif // CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL if (m_bFlipX) { CC_SWAP(top, bottom, float); } if (m_bFlipY) { CC_SWAP(left, right, float); } m_sQuad.bl.texCoords.u = left; m_sQuad.bl.texCoords.v = top; m_sQuad.br.texCoords.u = left; m_sQuad.br.texCoords.v = bottom; m_sQuad.tl.texCoords.u = right; m_sQuad.tl.texCoords.v = top; m_sQuad.tr.texCoords.u = right; m_sQuad.tr.texCoords.v = bottom; } else { #if CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL left = (2 * rect.origin.x + 1) / (2 * atlasWidth); right = left + (rect.size.width * 2 - 2) / (2 * atlasWidth); top = (2 * rect.origin.y + 1) / (2 * atlasHeight); bottom = top + (rect.size.height * 2 - 2) / (2 * atlasHeight); #else left = rect.origin.x / atlasWidth; right = (rect.origin.x + rect.size.width) / atlasWidth; top = rect.origin.y / atlasHeight; bottom = (rect.origin.y + rect.size.height) / atlasHeight; #endif // ! CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL if(m_bFlipX) { CC_SWAP(left, right, float); } if(m_bFlipY) { CC_SWAP(top, bottom, float); } m_sQuad.bl.texCoords.u = left; m_sQuad.bl.texCoords.v = bottom; m_sQuad.br.texCoords.u = right; m_sQuad.br.texCoords.v = bottom; m_sQuad.tl.texCoords.u = left; m_sQuad.tl.texCoords.v = top; m_sQuad.tr.texCoords.u = right; m_sQuad.tr.texCoords.v = top; } }