//----------------------------------------------------------------------------- IPlatformBitmap* IPlatformBitmap::createFromMemory (const void* ptr, uint32_t memSize) { CGBitmap* bitmap = 0; CFDataRef data = CFDataCreate (0, (const UInt8*)ptr, static_cast<CFIndex> (memSize)); if (data) { CGImageSourceRef source = CGImageSourceCreateWithData (data, NULL); if (source) { bitmap = new CGBitmap (); bool result = bitmap->loadFromImageSource (source); if (result == false) { bitmap->forget (); bitmap = 0; } CFRelease (source); } CFRelease (data); } return bitmap; }
//----------------------------------------------------------------------------- IPlatformBitmap* IPlatformBitmap::createFromPath (UTF8StringPtr absolutePath) { CGBitmap* bitmap = 0; CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*)absolutePath, static_cast<CFIndex> (strlen (absolutePath)), false); if (url) { CGImageSourceRef source = CGImageSourceCreateWithURL (url, NULL); if (source) { bitmap = new CGBitmap (); bool result = bitmap->loadFromImageSource (source); if (result == false) { bitmap->forget (); bitmap = 0; } CFRelease (source); } CFRelease (url); } return bitmap; }
void CCommandLine::CleanUpResources (void) // CleanUpResources // // Cleans up global resources allocated by InitResources { g_iRefCount--; if (g_iRefCount == 0) { g_BackgroundBmp.Unload(); } }
//----------------------------------------------------------------------------- void CGDrawContext::drawBitmap (CBitmap* bitmap, const CRect& inRect, const CPoint& inOffset, float alpha) { if (bitmap == 0 || alpha == 0.f) return; double transformedScaleFactor = scaleFactor; CGraphicsTransform t = getCurrentTransform (); if (t.m11 == t.m22 && t.m12 == 0 && t.m21 == 0) transformedScaleFactor *= t.m11; IPlatformBitmap* platformBitmap = bitmap->getBestPlatformBitmapForScaleFactor (transformedScaleFactor); CGBitmap* cgBitmap = platformBitmap ? dynamic_cast<CGBitmap*> (platformBitmap) : 0; CGImageRef image = cgBitmap ? cgBitmap->getCGImage () : 0; if (image) { CGContextRef context = beginCGContext (false, true); if (context) { CGLayerRef layer = cgBitmap->getCGLayer (); if (layer == 0) { BitmapDrawCountMap::iterator it = bitmapDrawCount.find (cgBitmap); if (it == bitmapDrawCount.end ()) { bitmapDrawCount.insert (std::pair<CGBitmap*, int32_t> (cgBitmap, 1)); } else { it->second++; layer = cgBitmap->createCGLayer (context); } } drawCGImageRef (context, image, layer, cgBitmap->getScaleFactor (), inRect, inOffset, alpha, bitmap); releaseCGContext (context); } } }
//----------------------------------------------------------------------------- void CGDrawContext::drawBitmap (CBitmap* bitmap, const CRect& inRect, const CPoint& inOffset, float alpha) { if (bitmap == 0 || alpha == 0.f) return; CGBitmap* cgBitmap = bitmap->getPlatformBitmap () ? dynamic_cast<CGBitmap*> (bitmap->getPlatformBitmap ()) : 0; CGImageRef image = cgBitmap ? cgBitmap->getCGImage () : 0; if (image) { CGContextRef context = beginCGContext (false, true); if (context) { CRect rect (inRect); rect.makeIntegral (); CPoint offset (inOffset); offset.makeIntegral (); CGContextSetAlpha (context, (CGFloat)alpha*currentState.globalAlpha); CGRect dest; dest.origin.x = rect.left - offset.h; dest.origin.y = -(rect.top) - (bitmap->getHeight () - offset.v); dest.size.width = cgBitmap->getSize ().x; dest.size.height = cgBitmap->getSize ().y; CGRect clipRect2; clipRect2.origin.x = rect.left; clipRect2.origin.y = -(rect.top) - rect.height (); clipRect2.size.width = rect.width (); clipRect2.size.height = rect.height (); CGContextClipToRect (context, clipRect2); CGLayerRef layer = cgBitmap->getCGLayer (); if (layer == 0) { BitmapDrawCountMap::iterator it = bitmapDrawCount.find (cgBitmap); if (it == bitmapDrawCount.end ()) { bitmapDrawCount.insert (std::pair<CGBitmap*, int32_t> (cgBitmap, 1)); CGContextDrawImage (context, dest, image); } else { it->second++; layer = cgBitmap->createCGLayer (context); } } if (layer) { CGContextDrawLayerInRect (context, dest, layer); } releaseCGContext (context); } } }
void CCommandLine::Paint (HDC hDC, RECT *pUpdateRect) // Paint // // Paint { int x, xSrc; int cxLeftToBlt; // Blt the left part of the bar x = m_rcRect.left; xSrc = 0; g_BackgroundBmp.PartialBlt(hDC, x, m_rcRect.top, CLINE_LEFTEND_WIDTH, CLINE_HEIGHT, xSrc, 0, pUpdateRect); x += CLINE_LEFTEND_WIDTH; xSrc += CLINE_LEFTEND_WIDTH; // Blt the left repeating part cxLeftToBlt = LEFT_MARGIN - CLINE_LEFTEND_WIDTH - CLINE_LEFTFIELDEND_WIDTH; while (cxLeftToBlt > 0) { int cxBlt = min(cxLeftToBlt, CLINE_LEFTREPEAT_WIDTH); g_BackgroundBmp.PartialBlt(hDC, x, m_rcRect.top, cxBlt, CLINE_HEIGHT, xSrc, 0, pUpdateRect); x += cxBlt; cxLeftToBlt -= cxBlt; } xSrc += CLINE_LEFTREPEAT_WIDTH; // Blt the left edge of the field g_BackgroundBmp.PartialBlt(hDC, x, m_rcRect.top, CLINE_LEFTFIELDEND_WIDTH, CLINE_HEIGHT, xSrc, 0, pUpdateRect); x += CLINE_LEFTFIELDEND_WIDTH; xSrc += CLINE_LEFTFIELDEND_WIDTH; // Blt the field cxLeftToBlt = m_cxFieldWidth; while (cxLeftToBlt > 0) { int cxBlt = min(cxLeftToBlt, CLINE_FIELDREPEAT_WIDTH); g_BackgroundBmp.PartialBlt(hDC, x, m_rcRect.top, cxBlt, CLINE_HEIGHT, xSrc, 0, pUpdateRect); x += cxBlt; cxLeftToBlt -= cxBlt; } xSrc += CLINE_FIELDREPEAT_WIDTH; // Blt the right edge of the field g_BackgroundBmp.PartialBlt(hDC, x, m_rcRect.top, CLINE_RIGHTFIELDEND_WIDTH, CLINE_HEIGHT, xSrc, 0, pUpdateRect); x += CLINE_RIGHTFIELDEND_WIDTH; xSrc += CLINE_RIGHTFIELDEND_WIDTH; // Blt the repeating end cxLeftToBlt = RIGHT_MARGIN - CLINE_RIGHTEND_WIDTH - CLINE_RIGHTFIELDEND_WIDTH; while (cxLeftToBlt > 0) { int cxBlt = min(cxLeftToBlt, CLINE_RIGHTREPEAT_WIDTH); g_BackgroundBmp.PartialBlt(hDC, x, m_rcRect.top, cxBlt, CLINE_HEIGHT, xSrc, 0, pUpdateRect); x += cxBlt; cxLeftToBlt -= cxBlt; } xSrc += CLINE_RIGHTREPEAT_WIDTH; // Blt the right end g_BackgroundBmp.PartialBlt(hDC, x, m_rcRect.top, CLINE_RIGHTEND_WIDTH, CLINE_HEIGHT, xSrc, 0, pUpdateRect); x += CLINE_RIGHTEND_WIDTH; xSrc += CLINE_RIGHTEND_WIDTH; }