//---------------------------------------------------------------------------
//in
source...
void
__fastcall TBltDemo::FormCreate(TObject *Sender)
{
BaseImage = new Graphics::TBitmap; //
instantiate stuff
BaseImage->Height = 160;
BaseImage->Width = 160;
OverlayImage = new Graphics::TBitmap;
OverlayImage->Height = 160;
OverlayImage->Width = 160;
Mask = new Graphics::TBitmap;
Mask->Height = 160; // all display
panels and bitmaps are 160x160
Mask->Width = 160;
BaseCanvas = new TControlCanvas;
BaseCanvas->Control = Base;
OverlayCanvas = new TControlCanvas;
OverlayCanvas->Control = Overlay;
CompositeCanvas = new TControlCanvas;
CompositeCanvas->Control = Composite;
Color[0] = clBlack;
// base background color
Color[1] = clRed;
// base object color
Color[2] = clBlack;
// overlay background color
Color[3] = clBlue;
// overlay object color
Application->OnIdle = &OnIdle;
}
//---------------------------------------------------------------------------
void
__fastcall TBltDemo::FormDestroy(TObject *Sender)
{
delete BaseImage;
delete OverlayImage;
delete Mask;
delete BaseCanvas;
delete OverlayCanvas;
delete CompositeCanvas;
}
//---------------------------------------------------------------------------
void
__fastcall TBltDemo::OnIdle(TObject*, bool& done)
{
done = true;
if (draw == true)
{
draw = false; // clear draw flag
BaseBkgndBlob->Color = Color[0];
BaseObjctBlob->Color = Color[1];
OvrlyBkgndBlob->Color = Color[2];
OvrlyObjctBlob->Color = Color[3];
DrawImages();
}
}
//---------------------------------------------------------------------------
void
__fastcall TBltDemo::FormActivate(TObject *Sender)
{
draw = true;
}
//---------------------------------------------------------------------------
void
__fastcall TBltDemo::FormPaint(TObject *Sender)
{
draw = true;
}
//---------------------------------------------------------------------------
//
Button Event Handlers
//---------------------------------------------------------------------------
void
__fastcall TBltDemo::BaseBkgndBtnClick(TObject *Sender)
{
ColorDialog->Color = Color[0];
if (ColorDialog->Execute())
{
Color[0] = ColorDialog->Color;
draw = true;
}
}
//---------------------------------------------------------------------------
void
__fastcall TBltDemo::BaseObjctClick(TObject *Sender)
{
ColorDialog->Color = Color[1];
if (ColorDialog->Execute())
{
Color[1] = ColorDialog->Color;
draw = true;
}
}
//---------------------------------------------------------------------------
void
__fastcall TBltDemo::OvrlyBkgndBtnClick(TObject *Sender)
{
ColorDialog->Color = Color[2];
if (ColorDialog->Execute())
{
Color[2] = ColorDialog->Color;
draw = true;
}
}
//---------------------------------------------------------------------------
void
__fastcall TBltDemo::OvrlyObjctBtnClick(TObject *Sender)
{
ColorDialog->Color = Color[3];
if (ColorDialog->Execute())
{
Color[3] = ColorDialog->Color;
draw = true;
}
}
//---------------------------------------------------------------------------
//
Draw and Blt routines
//---------------------------------------------------------------------------
void
TBltDemo::DrawImages()
{
BaseImage->Canvas->Brush->Color = Color[0]; //
fill in base background
BaseImage->Canvas->Pen->Color = Color[0];
BaseImage->Canvas->Rectangle(0,0,Base->Height,Base->Width);
BaseImage->Canvas->Brush->Color = Color[1]; //
draw ellipse in base image
BaseImage->Canvas->Pen->Color = Color[1];
BaseImage->Canvas->Ellipse(10,10,70,150);
OverlayImage->Canvas->Brush->Color = Color[2]; //
fill in overlay background
OverlayImage->Canvas->Pen->Color = Color[2];
OverlayImage->Canvas->Rectangle(0,0,Overlay->Height,Overlay->Width);
OverlayImage->Canvas->Brush->Color = Color[3];
OverlayImage->Canvas->Pen->Color = Color[3];
POINT points[3];
points[0] = Point(120,10);
// draw triangle in overlay
points[1] = Point(85,90);
points[2] = Point(150,150);
OverlayImage->Canvas->Polygon(points, 2);
// blt 2 component images to their displays
using copy mode
BitBlt(BaseCanvas->Handle,0,0,160,160,
BaseImage->Canvas->Handle,0,0,SRCCOPY);
BitBlt(OverlayCanvas->Handle,0,0,160,160,
OverlayImage->Canvas->Handle,0,0,SRCCOPY);
if (PaintBtn->Checked == true)
PaintBlt();
else if (AndBtn->Checked == true)
AndBlt();
else if (MaskedBtn->Checked == true)
MaskedBlt();
}
//---------------------------------------------------------------------------
void
TBltDemo::PaintBlt()
{
BitBlt(CompositeCanvas->Handle,0,0,160,160, //
copy base image to canvas
BaseImage->Canvas->Handle,0,0,SRCCOPY); //
using copy mode
BitBlt(CompositeCanvas->Handle,0,0,160,160, //
superimpose overlay image
OverlayImage->Canvas->Handle,0,0,SRCPAINT); //
using SRCPAINT
}
//---------------------------------------------------------------------------
void
TBltDemo::AndBlt()
{
BitBlt(CompositeCanvas->Handle,0,0,160,160, //
copy base image to canvas
BaseImage->Canvas->Handle,0,0,SRCCOPY); //
using copy mode
BitBlt(CompositeCanvas->Handle,0,0,160,160, //
superimpose overlay image
OverlayImage->Canvas->Handle,0,0,SRCAND);
// using SRCAND
}
//---------------------------------------------------------------------------
void
TBltDemo::MaskedBlt()
{
BitBlt(CompositeCanvas->Handle,0,0,160,160, //
copy base image to canvas
BaseImage->Canvas->Handle,0,0,SRCCOPY); //
using copy mode
OverlayImage->Canvas->Brush->Color = clWhite; //
redraw overlay object on
OverlayImage->Canvas->Pen->Color = clWhite; //
white background
OverlayImage->Canvas->Rectangle(0,0,Overlay->Height,Overlay->Width);
OverlayImage->Canvas->Brush->Color = Color[3];
OverlayImage->Canvas->Pen->Color = Color[3];
POINT points[3];
points[0] = Point(120,10);
// draw triangle in overlay
points[1] = Point(85,90);
// in correct color
points[2] = Point(150,150);
OverlayImage->Canvas->Polygon(points, 2);
Mask->Canvas->Brush->Color = clBlack; // fill
mask with
Mask->Canvas->Pen->Color = clBlack; //
black background
Mask->Canvas->Rectangle(0,0,Mask->Height,Mask->Width);
Mask->Canvas->Brush->Color = clWhite;
Mask->Canvas->Pen->Color = clWhite;
// draw triangle in white
Mask->Canvas->Polygon(points, 2);
BitBlt(CompositeCanvas->Handle,0,0,160,160,
// copy mask onto composite
Mask->Canvas->Handle,0,0,SRCPAINT); // using
SRCPAINT mode
BitBlt(CompositeCanvas->Handle,0,0,160,160, //
copy overlay onto composite
OverlayImage->Canvas->Handle,0,0,SRCAND); //
using SRCAND mode
}
|