Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Invers text

19 views
Skip to first unread message

alacarte engineering

unread,
Jan 19, 2000, 3:00:00 AM1/19/00
to
>Or are you referring to inverse
>colors?

I want inverse color black <-> white


Björn Jonsson

unread,
Jan 19, 2000, 3:00:00 AM1/19/00
to
You can try Brush->Color=clBlack;
and Font->Color=clWhite;
That would be one way of doing it
Björn Jonsson


alacarte engineering <in...@alacarte-engineering.com> skrev i
diskussionsgruppsmeddelandet:38858C53...@alacarte-engineering.com...

Damon Chandler

unread,
Jan 20, 2000, 3:00:00 AM1/20/00
to
Hi Johan,

> I want inverse color black <-> white

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

0 new messages