if (!image.is()) return;
image.lock();
unsigned char* texd = image.data();
UInt tw = image.x();
UInt th = image.y();
UInt sz = tw*th*4;
// scrolling
{
Int wid = scrollRect.width();
Int hig = scrollRect.height();
Int top = scrollRect.top();
Int left = scrollRect.left();
if(dy < 0) // scroll down
{
for (int y = -dy; y < hig; y++)
{
UInt tb = ((top + y) * tw + left) * 4;
UInt tb2 = tb + dy * tw * 4;
if (tb >= 0 && tb < sz && tb2 >= 0 && tb2 < sz) memcpy(&texd[tb2], &texd[tb], wid * 4);
}
}
else if(dy > 0) // scroll up
{
for (int y = hig - dy; y > -1; y--)
{
UInt tb = ((top + y) * tw + left) * 4;
UInt tb2 = tb + dy * tw * 4;
if (tb >= 0 && tb < sz && tb2 >= 0 && tb2 < sz) memcpy(&texd[tb2], &texd[tb], wid * 4);
}
}
if(dx != 0) // scroll
{
int subx = dx > 0 ? 0 : -dx;
for (int y = 0; y < hig; y++)
{
UInt tb = ((top + y) * tw + left) * 4;
UInt tb2 = tb - dx * 4;
if (tb >= 0 && tb < sz && tb2 >= 0 && tb2 < sz) memcpy(&texd[tb], &texd[tb2], wid * 4 - subx);
}
}
}
// copy new rects
for(UInt i = 0; i < numCopyRects; i++)
{
Berkelium::Rect cr = copyRects[i];
Int wid = cr.width();
Int hig = cr.height();
Int top = cr.top() - sourceBufferRect.top();
Int left = cr.left() - sourceBufferRect.left();
for(int y = 0; y < hig; y++)
{
UInt tb = ((cr.top() + y) * tw + cr.left()) * 4;
UInt tb2 = (left + (y + top) * sourceBufferRect.width()) * 4;
if (tb >= 0 && tb < sz && tb2 >= 0 && tb2 < sz) memcpy(&texd[tb], &sourceBuffer[tb2], wid * 4);
}
}
image.unlock();