示例#1
0
//-----------------------------------------------------------------------------
void D2DDrawContext::drawRect (const CRect &_rect, const CDrawStyle drawStyle)
{
    if (renderTarget)
    {
        CRect rect (_rect);
        rect.offset (currentState.offset.x, currentState.offset.y);
        rect.normalize ();
        if (currentState.drawMode.integralMode ())
        {
            rect.makeIntegral ();
        }
        D2DApplyClip clip (this);
        if (drawStyle == kDrawFilled || drawStyle == kDrawFilledAndStroked)
        {
            renderTarget->FillRectangle (makeD2DRect (rect), fillBrush);
        }
        if (drawStyle == kDrawStroked || drawStyle == kDrawFilledAndStroked)
        {
            rect.left++;
            rect.bottom--;
            if ((((int32_t)currentState.frameWidth) % 2))
                renderTarget->SetTransform (D2D1::Matrix3x2F::Translation (0.f, 0.5f));
            renderTarget->DrawRectangle (makeD2DRect (rect), strokeBrush, (FLOAT)currentState.frameWidth, strokeStyle);
            renderTarget->SetTransform (D2D1::Matrix3x2F::Identity ());
        }
    }
}
示例#2
0
//-----------------------------------------------------------------------------
void D2DDrawContext::drawRect (const CRect &_rect, const CDrawStyle drawStyle)
{
	if (renderTarget == 0)
		return;
	CRect rect (_rect);
	if (currentState.drawMode.integralMode ())
		pixelAllign (rect);
	bool halfPointOffset = (((int32_t)currentState.frameWidth) % 2) != 0;
	if (drawStyle == kDrawFilled || drawStyle == kDrawFilledAndStroked)
	{
		D2DApplyClip ac (this);
		if (ac.isEmpty ())
			return;
		renderTarget->FillRectangle (makeD2DRect (rect), fillBrush);
	}
	if (drawStyle == kDrawStroked || drawStyle == kDrawFilledAndStroked)
	{
		D2DApplyClip ac (this, halfPointOffset);
		if (ac.isEmpty ())
			return;
		rect.right -= 1.;
		rect.bottom -= 1.;
		renderTarget->DrawRectangle (makeD2DRect (rect), strokeBrush, (FLOAT)currentState.frameWidth, strokeStyle);
	}
}
示例#3
0
//-----------------------------------------------------------------------------
D2DDrawContext::D2DApplyClip::D2DApplyClip (D2DDrawContext* drawContext, bool halfPointOffset)
: drawContext (drawContext)
{
	if (drawContext->currentClip != drawContext->currentState.clipRect)
	{
		CRect clip = drawContext->currentState.clipRect;
		if (drawContext->getDrawMode ().integralMode ())
			clip.makeIntegral ();
		if (drawContext->currentClip.isEmpty () == false)
			drawContext->getRenderTarget ()->PopAxisAlignedClip ();
		if (clip.isEmpty () == false)
			drawContext->getRenderTarget ()->PushAxisAlignedClip (makeD2DRect (clip), D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
		drawContext->currentClip = applyClip = clip;
	}
	else
	{
		applyClip = drawContext->currentClip;
	}

	if (drawContext->getCurrentTransform ().isInvariant () == false)
	{
		CGraphicsTransform transform = drawContext->getCurrentTransform ();
		if (halfPointOffset)
			transform.translate (0.5, 0.5);
		drawContext->getRenderTarget ()->SetTransform (convert (transform));
	}
	else if (halfPointOffset)
		drawContext->getRenderTarget ()->SetTransform (D2D1::Matrix3x2F::Translation (0.5f, 0.5f));
}
示例#4
0
//-----------------------------------------------------------------------------
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);
			}
		}
	}
}
示例#5
0
//-----------------------------------------------------------------------------
void D2DDrawContext::drawBitmap (CBitmap* bitmap, const CRect& dest, const CPoint& offset, float alpha)
{
    D2DBitmap* d2dBitmap = bitmap->getPlatformBitmap () ? dynamic_cast<D2DBitmap*> (bitmap->getPlatformBitmap ()) : 0;
    if (renderTarget && d2dBitmap)
    {
        if (d2dBitmap->getSource ())
        {
            ID2D1Bitmap* d2d1Bitmap = D2DBitmapCache::instance ()->getBitmap (d2dBitmap, renderTarget);
            if (d2d1Bitmap)
            {
                D2DApplyClip clip (this);
                CRect d (dest);
                d.offset (currentState.offset.x, currentState.offset.y);
                d.makeIntegral ();
                CRect source (dest);
                source.offset (-source.left, -source.top);
                source.offset (offset.x, offset.y);
                D2D1_RECT_F sourceRect = makeD2DRect (source);
                renderTarget->DrawBitmap (d2d1Bitmap, makeD2DRect (d), alpha * currentState.globalAlpha, D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, &sourceRect);
            }
        }
    }
}
示例#6
0
//-----------------------------------------------------------------------------
D2DDrawContext::D2DApplyClip::D2DApplyClip (D2DDrawContext* drawContext)
    : drawContext (drawContext)
{
    drawContext->getRenderTarget ()->PushAxisAlignedClip (makeD2DRect (drawContext->currentState.clipRect), D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
}