Example #1
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));
}
Example #2
0
//-----------------------------------------------------------------------------
void CBitmap::draw (CDrawContext* context, const CRect& rect, const CPoint& offset, float alpha)
{
	CRect clipRect;
	context->getClipRect (clipRect);
	clipRect.bound (rect);
	if (!clipRect.isEmpty ())
		context->drawBitmap (this, rect, offset, alpha);
}
Example #3
0
//-----------------------------------------------------------------------------
bool Win32Frame::invalidRect (const CRect& rect)
{
	if (inPaint)
		return false;
	if (!rect.isEmpty ())
	{
		RECT r = {(LONG)rect.left, (LONG)rect.top, (LONG)ceil (rect.right), (LONG)ceil (rect.bottom)};
		InvalidateRect (windowHandle, &r, true);
	}
	return true;
}
Example #4
0
//------------------------------------------------------------------------
CMouseEventResult ScaleView::onMouseEntered (CPoint &where, const CButtonState& buttons)
{
	if (origRect.isEmpty ())
		origRect = getViewSize ();
	CRect r (origRect);
	r.inset (-40, -15);
	getFrame ()->getAnimator ()->removeAnimation (this, "AlphaAnimation");
	getFrame ()->getAnimator ()->removeAnimation (this, "SizeAnimation");
	getFrame ()->getAnimator ()->addAnimation (this, "AlphaAnimation", new Animation::AlphaValueAnimation (1.f), new Animation::RepeatTimingFunction (new Animation::LinearTimingFunction (300), -1, true));
	getFrame ()->getAnimator ()->addAnimation (this, "SizeAnimation", new Animation::ViewSizeAnimation (r), new Animation::RepeatTimingFunction (new Animation::LinearTimingFunction (200), -1, true));
	return CViewContainer::onMouseEntered (where, buttons);
}
Example #5
0
//-----------------------------------------------------------------------------
void CGDrawContext::fillRectWithBitmap (CBitmap* bitmap, const CRect& srcRect, const CRect& dstRect, float alpha)
{
    if (bitmap == 0 || alpha == 0.f || srcRect.isEmpty () || dstRect.isEmpty ())
        return;

    if (!(srcRect.left == 0 && srcRect.right == 0 && srcRect.right == bitmap->getWidth () && srcRect.bottom == bitmap->getHeight ()))
    {
        // CGContextDrawTiledImage does not work with parts of a bitmap
        CDrawContext::fillRectWithBitmap(bitmap, srcRect, dstRect, alpha);
        return;
    }

    IPlatformBitmap* platformBitmap = bitmap->getBestPlatformBitmapForScaleFactor (scaleFactor);
    CPoint bitmapSize = platformBitmap->getSize ();
    if (srcRect.right > bitmapSize.x || srcRect.bottom > bitmapSize.y)
        return;

    CGBitmap* cgBitmap = platformBitmap ? dynamic_cast<CGBitmap*> (platformBitmap) : 0;
    CGImageRef image = cgBitmap ? cgBitmap->getCGImage () : 0;
    if (image)
    {
        CGContextRef context = beginCGContext (false, true);
        if (context)
        {
            // TODO: Check if this works with retina images
            CGRect clipRect = CGRectFromCRect (dstRect);
            clipRect.origin.y = -(clipRect.origin.y) - clipRect.size.height;
            clipRect = pixelAlligned (clipRect);
            CGContextClipToRect (context, clipRect);

            CGRect r = {};
            r.size.width = CGImageGetWidth (image);
            r.size.height = CGImageGetHeight (image);

            CGContextDrawTiledImage (context, r, image);

            releaseCGContext (context);
        }
    }
}
Example #6
0
//-----------------------------------------------------------------------------
void CDrawContext::fillRectWithBitmap (CBitmap* bitmap, const CRect& srcRect, const CRect& dstRect, float alpha)
{
	if (srcRect.isEmpty () || dstRect.isEmpty ())
		return;

	CRect bitmapPartRect;
	CCoord left;
	CCoord top;
	CPoint sourceOffset (srcRect.left, srcRect.top);

	CRect currentClip = getClipRect (currentClip);

	for (top = dstRect.top; top < dstRect.bottom; top += srcRect.getHeight ())
	{
		bitmapPartRect.top = top;
		bitmapPartRect.bottom = top + srcRect.getHeight ();
		if (bitmapPartRect.bottom > dstRect.bottom)
			bitmapPartRect.bottom = dstRect.bottom;
		// The following should never be true, I guess
		if (bitmapPartRect.getHeight () > srcRect.getHeight ())
			bitmapPartRect.setHeight (srcRect.getHeight ());
		
		for (left = dstRect.left; left < dstRect.right; left += srcRect.getWidth ())
		{
			bitmapPartRect.left = left;
			bitmapPartRect.right = left + srcRect.getWidth ();
			if (bitmapPartRect.right > dstRect.right)
				bitmapPartRect.right = dstRect.right;
			// The following should never be true, I guess
			if (bitmapPartRect.getWidth () > srcRect.getWidth ())
				bitmapPartRect.setWidth (srcRect.getWidth ());
			
			if (currentClip.rectOverlap (bitmapPartRect))
				drawBitmap (bitmap, bitmapPartRect, sourceOffset, alpha);
		}
	}
}