//----------------------------------------------------------------------------- IPlatformBitmap* CBitmap::getBestPlatformBitmapForScaleFactor (double scaleFactor) const { if (bitmaps.empty ()) return 0; IPlatformBitmap* bestBitmap = bitmaps[0]; double bestDiff = std::abs (scaleFactor - bestBitmap->getScaleFactor ()); VSTGUI_RANGE_BASED_FOR_LOOP (BitmapVector, bitmaps, BitmapPointer, bitmap) if (bitmap->getScaleFactor () == scaleFactor) return bitmap; else if (std::abs (scaleFactor - bitmap->getScaleFactor ()) <= bestDiff && bitmap->getScaleFactor () > bestBitmap->getScaleFactor ()) { bestBitmap = bitmap; bestDiff = std::abs (scaleFactor - bitmap->getScaleFactor ()); } VSTGUI_RANGE_BASED_FOR_LOOP_END return bestBitmap; }
//----------------------------------------------------------------------------- void D2DDrawContext::drawBitmap (CBitmap* bitmap, const CRect& dest, const CPoint& offset, float alpha) { if (renderTarget == 0) return; D2DApplyClip ac (this); if (ac.isEmpty ()) return; double transformedScaleFactor = getScaleFactor (); CGraphicsTransform t = getCurrentTransform (); if (t.m11 == t.m22 && t.m12 == 0 && t.m21 == 0) transformedScaleFactor *= t.m11; IPlatformBitmap* platformBitmap = bitmap->getBestPlatformBitmapForScaleFactor (transformedScaleFactor); D2DBitmap* d2dBitmap = platformBitmap ? dynamic_cast<D2DBitmap*> (platformBitmap) : 0; if (d2dBitmap) { if (d2dBitmap->getSource ()) { ID2D1Bitmap* d2d1Bitmap = D2DBitmapCache::instance ()->getBitmap (d2dBitmap, renderTarget); if (d2d1Bitmap) { double bitmapScaleFactor = platformBitmap->getScaleFactor (); CGraphicsTransform bitmapTransform; bitmapTransform.scale (bitmapScaleFactor, bitmapScaleFactor); Transform transform (*this, bitmapTransform.inverse ()); CRect d (dest); d.makeIntegral (); CRect source (dest); source.offset (-source.left, -source.top); source.offset (offset.x, offset.y); bitmapTransform.transform (source); D2D1_RECT_F sourceRect = makeD2DRect (source); renderTarget->DrawBitmap (d2d1Bitmap, makeD2DRect (d), alpha * currentState.globalAlpha, D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, &sourceRect); } } } }