var Bmp,Glyph:TBitmap;
L,H,xG,yG,xC,yC,Spacing,SpacingGlyph,NbrXPButton : integer;
Name,Macro,GlyphName,GlyphPos,Caption,Css,Hint: string;
begin
NbrXPButton := GetVarInt('nbrXPButton',0);
Name := GetParam('Name','xpbutton')+'.bmp';
// générer un nom unique si on a oublié d'en indiquer un
if Name = 'xpbutton.bmp' then Name := 'XPButton'+IntToStr(NbrXPButton)+ '.bmp';

Macro := GetParam('Macro','');
Hint := GetParam('Hint','');
if Hint<>'' then Hint:='^'+Hint;
// regarder si un bouton de ce nom a déjà été dessiné dans cette session
// si oui on ne le redessine pas...
if GetVarString(Name,'')<>'true' then
begin
// positionner la variable globale au nom de l'image pour ne pas la redessiner
SetVarString(Name,'True');
// incrémenter le nombre de XPButton en activité
NbrXPButton := NbrXPButton+1;
SetVarInt('nbrXPButton',NbrXPButton);

Spacing := GetParam('Spacing','0');

// préparation du bitmap, découpé en 3 zones
// 1. zone au repos
// 2. zone au survol curseur souris
// 3. clic souris
Bmp := TBitmap.create;
L := IntToStr(GetParam('Width','24'));
H := IntToStr(GetParam('Height','24'));
Bmp.width := l*3;
Bmp.Height := H;

// préparation Texte

Css := GetParam('css','');
if css='' then
begin
bmp.Font.Name := GetParam('FontName','Arial');
bmp.Font.Size := GetParam('FontSize','8');
bmp.Font.Color := GetParam('FontColor','$000000');
end else bmp.Font.css(css);
Caption := GetParam('Caption','');


// dessin fond zone 1

bmp.Brush.Color := GetParam('Color','clBtnFace');
bmp.Pen.Color := bmp.Brush.Color;
bmp.Canvas.Rectangle(0,0,L,H);
// dessin fond zone 2&3
bmp.Brush.Color := GetParam('ColorHover','$00D6BEB5');
bmp.Pen.Color := GetShadowColor(bmp.Brush.Color);
bmp.Canvas.Rectangle(L,0,L*2,H);
bmp.Canvas.Rectangle(L*2,0,L*3,H);


// dessin du glyph (imagette)
GlyphName := GetParam('Glyph','');
if GlyphName<>'' then
begin
SpacingGlyph := GetParam('SpacingGlyph','0');
Glyph := TBitmap.Create;
Glyph.LoadFromFile(GlyphName);
Glyph.Transparent := true;
GlyphPos := GetParam('GlyphAlign','Left');
if GlyphPos='Left' then
begin
xG := SpacingGlyph+2;
yG := 1+ ((H - Glyph.Height) div 2);
xC := xG+2+Glyph.Width+Spacing;
yC := 1+((H-bmp.Canvas.TextHeight('H')) div 2);
end else if GlyphPos='Right' then
begin
xG := L-Glyph.Width-2-SpacingGlyph;
yG := 1+ ((H - Glyph.Height) div 2);
xC := xG-2-bmp.Canvas.TextWidth(Caption)-Spacing;
yC := 1+((H-bmp.Canvas.TextHeight('H')) div 2);
end else if GlyphPos='Top' then
begin
xG := 1+ ((L - Glyph.Width) div 2);
yG := SpacingGlyph+2;
xC := 1+((L-bmp.Canvas.TextWidth(Caption)) Div 2);
yC := yG+2+Glyph.Height+Spacing;
end else begin
xG := 1+ ((L - Glyph.Width) div 2);
yG := H - Glyph.Height - 2;
xC := 1+((L-bmp.Canvas.TextWidth(Caption)) Div 2);
yC := yG-2-Glyph.Height-Spacing-SpacingGlyph;
end;
bmp.Canvas.Draw(xG,yG,Glyph);
bmp.Canvas.Draw(xG+L,yG-1,Glyph);
bmp.Canvas.Draw(xG+L*2,yG+1,Glyph);
Glyph.free;
end else begin
xC := 1+((L-bmp.Canvas.TextWidth(Caption)) Div 2);
yC := 1+((H-bmp.Canvas.TextHeight('H')) div 2);
end;
// dessin du texte
bmp.Canvas.Transparent := true;
bmp.Canvas.TextOut(xC,yC,Caption);
bmp.Canvas.TextOut(xC+L,yC,Caption);
bmp.Canvas.TextOut(xC+L*2,yC,Caption);
Bmp.SaveToFile(Name);
Bmp.free;
end;

write('<<DBT(')>>+Name+Hint+<<FNT(STRING.-,-,-,-:',')>>+Macro+<<FNT(STRING.-,-,-,-:'|4,1,0)>>');
end;
end.

Sommaire