PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Part of the Blt out of destination rectangle?

In a blt, what happens if part of the destination rectangle is outside the surface?

ex :
Code:

CGapiSurface surf1;
CGapiSurface surf2;

surf1.CreateSurface(GDCREATESURFACE_CLEAR,100,100);
surf2.CreateSurface(GDCREATESURFACE_CLEAR,100,100);

/* put something in surf2 */

CRect rect(0,50,100,150);

surf1.Blt(rect,surf2,NULL,GDBLT_KEYSRC,NULL);
[/code]

It seems that nothing is copied and no error detected... Am I wrong?
Do I need to detect the overlapping by my own?

jul'
Hi,

Blt returns GDERR_INVALIDRECT if you try to blit outside the surface boundaries. GapiDraw does not support clipping due to a number of reasons so you have to perform clipping manually yourself.

/Johan
Here is some simple clipping logic

Code:

// assume that you have a clip rectangle m_ClipRect (maybe the screen edge, 0, 0, ScreenWidth, ScreenHeight)
// You want to blt an image at x, y that has some size m_ImageSize (the size of the image 0, 0, ImageWidth, ImageHeight)

// Adjust the right hand side of the image
if( x + m_ImageSize.right >= m_ClipRect.right )
{
// the image can only be as wide as the space left in the clip rect
m_ImageSize.right = m_ClipRect.right - x;
}

// now check the left side of the image
if( x < m_ClipRect.left )
{
// move the left side of the image over
m_ImageSize.left = m_ClipRect.left - x;
// and move our starting location for drawing the image
x = m_ClipRect.left;
}

// see if there is anything to draw if not we are done
if( m_ImageSize.left >= m_ImageSize.right ) return;

// do the same code as above for the top and bottom

// now draw the image
foo.BltFast( x, y, pImage, &m_ImageSize, 0, NULL );


Hope this helps

--Tully