I want inverse color black <-> white
alacarte engineering <in...@alacarte-engineering.com> skrev i
diskussionsgruppsmeddelandet:38858C53...@alacarte-engineering.com...
You can accomplish this by creating a mask bitmap of the text, then
transparently render this to your target device context via an inverse overlay.
If you're not familiar with masks, have a look at Dave Richards' article...
http://bcbcaq.freeservers.com/project_DR.html
Here's an example function...
#include <memory>
void __fastcall InverseTextOut(TCanvas *DestCanvas, int X, int Y,
AnsiString AText)
{
std::auto_ptr<Graphics::TBitmap> MaskBitmap
(new Graphics::TBitmap());
std::auto_ptr<Graphics::TBitmap> OverlayBitmap
(new Graphics::TBitmap());
MaskBitmap->Canvas->Font = DestCanvas->Font;
OverlayBitmap->Canvas->Font = DestCanvas->Font;
const int width = MaskBitmap->Canvas->TextWidth(AText);
const int height = MaskBitmap->Canvas->TextHeight(AText);
MaskBitmap->Width = width;
MaskBitmap->Height = height;
OverlayBitmap->Width = width;
OverlayBitmap->Height = height;
// save the original background
BitBlt(MaskBitmap->Canvas->Handle, 0, 0,
MaskBitmap->Width, MaskBitmap->Height,
DestCanvas->Handle, X, Y,
SRCCOPY);
// create the text mask
MaskBitmap->Canvas->Font->Color = clBlack;
MaskBitmap->Canvas->Brush->Style = bsClear;
MaskBitmap->Canvas->TextOut(0, 0, AText);
// create the overlay
OverlayBitmap->Canvas->Brush->Color = clWhite;
OverlayBitmap->Canvas->FillRect(OverlayBitmap->Canvas->ClipRect);
OverlayBitmap->Canvas->Font->Color = clBlack;
OverlayBitmap->Canvas->TextOut(0, 0, AText);
// blt the overlay to dest using NOTSRCERASE
BitBlt(DestCanvas->Handle, X, Y,
OverlayBitmap->Width, OverlayBitmap->Height,
OverlayBitmap->Canvas->Handle, 0, 0,
NOTSRCERASE);
// blt the result to the dest using SRCPAINT
BitBlt(DestCanvas->Handle, X, Y,
MaskBitmap->Width, MaskBitmap->Height,
MaskBitmap->Canvas->Handle, 0, 0,
SRCPAINT);
}
Good luck!
--
Damon Chandler
http://bcbcaq.freeservers.com