Oh I think I know. clBlack ($000000) cannot be used here for the font color, because it cannot be distinguished from empty pixels. But I suppose you cannot control this parameter.
A work-around would be to store temporarily the alpha channel and restore it after the text is drawn :
function SaveAlphaRect(ABitmap: TBGRABitmap; ARect: TRect): Pointer;
var width,height,count,y: Integer;
pAlphaData: PByte;
pSrc: PBGRAPixel;
begin
IntersectRect(ARect,ARect,Classes.Rect(0,0,ABitmap.Width,ABitmap.Height));
width := ARect.Right-ARect.Left;
height := ARect.Bottom-ARect.Top;
if (width <= 0) or (height <= 0) then result := nil;
getmem(result, sizeof(longint)*2 + sizeof(byte)*width*height);
PLongint(result)^ := width;
(PLongint(result)+1)^ := height;
pAlphaData := pbyte(plongint(result)+2);
for y := ARect.Top to ARect.Bottom-1 do
begin
pSrc := ABitmap.ScanLine[y]+ARect.Left;
count := width;
while count > 0 do
begin
pAlphaData^ := pSrc^.alpha;
inc(pAlphaData);
inc(pSrc);
dec(count);
end;
end;
end;
procedure RestoreAlphaRectAndFree(ABitmap: TBGRABitmap; AX,AY: integer; ASavedAlphaRect: Pointer);
var width,height,count,y: Integer;
pAlphaData: PByte;
pSrc: PBGRAPixel;
begin
if ASavedAlphaRect = nil then exit;
if AX < 0 then AX := 0;
if AY < 0 then AY := 0;
width := PLongint(ASavedAlphaRect)^;
height := (PLongint(ASavedAlphaRect)+1)^;
pAlphaData := pbyte(plongint(ASavedAlphaRect)+2);
for y := AY to AY+height-1 do
begin
pSrc := ABitmap.ScanLine[y]+AX;
count := width;
while count > 0 do
begin
pSrc^.alpha := pAlphaData^;
inc(pAlphaData);
inc(pSrc);
dec(count);
end;
end;
freemem(ASavedAlphaRect);
end;
procedure TForm1.BCXButton1RenderControl(Sender: TObject; Bitmap: TBGRABitmap;
State: TBCGraphicButtonState);
var
Details: TThemedElementDetails;
PaintRect: TRect;
AlphaRect: Pointer;
begin
PaintRect := Rect(0, 0, Bitmap.Width, Bitmap.Height);
case State of
gbsNormal: Details := ThemeServices.GetElementDetails(tbPushButtonNormal);
gbsHover: Details := ThemeServices.GetElementDetails(tbPushButtonHot);
gbsActive: Details := ThemeServices.GetElementDetails(tbPushButtonPressed);
gbsDisabled: Details := ThemeServices.GetElementDetails(tbPushButtonDisabled);
end;
ThemeServices.DrawElement(Bitmap.Canvas.Handle, Details, PaintRect, nil);
Bitmap.Canvas.Changed;
PaintRect := ThemeServices.ContentRect(Bitmap.Canvas.Handle, Details, PaintRect);
AlphaRect := SaveAlphaRect(Bitmap, PaintRect);
ThemeServices.DrawText(Bitmap.Canvas, Details, 'Test caption', PaintRect,
DT_CENTER or DT_VCENTER or DT_SINGLELINE, 0);
RestoreAlphaRectAndFree(Bitmap, PaintRect.Left,PaintRect.Top, AlphaRect);
end;