#include <common/iconfrm.hpp>

void IconFrame::drawFrame(PureDevice &displayDevice,IconBitmap &someIconBitmap,const Point &xyPoint)
{
	PureDevice bkCurrDevice;
	PureDevice srcDevice;
	PureDevice maskDevice;

	srcDevice.compatibleDevice(displayDevice);
	maskDevice.compatibleDevice(displayDevice);
	bkCurrDevice.compatibleDevice(displayDevice);
	if(!mBitmapBkGnd.isOkay()||!(mCurrentPoint==xyPoint))
	{
		if(mBitmapBkGnd.isOkay())displayDevice.bitBlt(Rect(mCurrentPoint.x(),mCurrentPoint.y(),someIconBitmap.colorBitmap().width(),someIconBitmap.colorBitmap().height()),bkCurrDevice,Point(0,0),PureDevice::SourceCopy);
		mCurrentPoint=xyPoint;
		mBitmapBkGnd.compatibleBitmap(displayDevice,someIconBitmap.colorBitmap().width(),someIconBitmap.colorBitmap().height());
		bkCurrDevice.select(mBitmapBkGnd);
		bkCurrDevice.bitBlt(Rect(0,0,someIconBitmap.colorBitmap().width(),someIconBitmap.colorBitmap().height()),displayDevice,Point(mCurrentPoint.x(),mCurrentPoint.y()),PureDevice::SourceCopy);
	}
	else bkCurrDevice.select(mBitmapBkGnd);
	displayDevice.bitBlt(Rect(mCurrentPoint.x(),mCurrentPoint.y(),someIconBitmap.colorBitmap().width(),someIconBitmap.colorBitmap().height()),bkCurrDevice,Point(0,0),PureDevice::SourceCopy);
	srcDevice.select(someIconBitmap.colorBitmap());
	maskDevice.select(someIconBitmap.maskBitmap());
	displayDevice.bitBlt(Rect(mCurrentPoint.x(),mCurrentPoint.y(),someIconBitmap.colorBitmap().width(),someIconBitmap.colorBitmap().height()),maskDevice,Point(0,0),PureDevice::SourceAnd);
	displayDevice.bitBlt(Rect(mCurrentPoint.x(),mCurrentPoint.y(),someIconBitmap.colorBitmap().width(),someIconBitmap.colorBitmap().height()),srcDevice,Point(0,0),PureDevice::SourcePaint);
}
