Page 1 of 1

drawRect in COffscreenContext [Solved]

Posted: Thu Feb 09, 2017 5:28 pm
by xavier
Hi,

I'm trying to draw a view container and its subview in a COffscreenContext.
I can't achieve this, but don't see where miss something.


The code is quite simple yet, overwriting CViewContainer:

void CViewContainerPanel:drawRect (CDrawContext* pContext, const CRect& updateRect)
{
COffscreenContext * pContextCourant = COffscreenContext::create(getFrame(), Image->getWidth(), Image->getHeight());
pContextCourant->beginDraw ();
CViewContainer::drawRect (pContextCourant, updateRect);
pContextCourant->endDraw ();

Panel = pContextCourant->getBitmap();
Panel->draw(pContext, size,Point (0,0));
pContextCourant->forget();

}
But only the CViewContainer::drawRect do nothing.

If I replace pContextCourant with pContext, removing the image draw, it's working fine

Any help would be appreciated

Thanks in advance

Best regards
Xavier

Re: drawRect in COffscreenContext

Posted: Mon Feb 13, 2017 10:32 am
by xavier
Hi,

For those who need it, adding the transform translate helps

Best regards
Xavier

void CViewContainerPanel:drawRect (CDrawContext* pContext, const CRect& updateRect)
{
COffscreenContext * pContextCourant = COffscreenContext::create(getFrame(), Image->getWidth(), Image->getHeight());
pContextCourant->beginDraw ();
CDrawContext::Transform transform (*pContextCourant, CGraphicsTransform ().translate (-getViewSize ().left, -getViewSize ().top));

CViewContainer::draw (pContextCourant);
pContextCourant->endDraw ();

Panel = pContextCourant->getBitmap();
Panel->draw(pContext, size,Point (0,0));
pContextCourant->forget();

}