if (TextSize.X = 0) or (TextSize.Y = 0) or not HasGlyph then
Spacing := 0;
{ adjust Margin and Spacing }
if Margin = -1 then
begin
if Spacing = -1 then
begin
TotalSize := Point(GlyphSize.X + TextSize.X + ArrowSize.X,
GlyphSize.Y + TextSize.Y);
if LayoutLeftOrRight then
Margin := (ClientSize.X - TotalSize.X) div 3
else
Margin := (ClientSize.Y - TotalSize.Y) div 3;
Spacing := Margin;
end
else
begin
TotalSize := Point(GlyphSize.X + Spacing + TextSize.X + ArrowSize.X,
GlyphSize.Y + Spacing + TextSize.Y);
if LayoutLeftOrRight then
Margin := (ClientSize.X - TotalSize.X + 1) div 2
else
Margin := (ClientSize.Y - TotalSize.Y + 1) div 2;
end;
end
else
begin
if Spacing = -1 then
begin
TotalSize := Point(ClientSize.X - (Margin + GlyphSize.X + ArrowSize.X),
ClientSize.Y - (Margin + GlyphSize.Y));
if LayoutLeftOrRight then
Spacing := (TotalSize.X - TextSize.X) div 2
else
Spacing := (TotalSize.Y - TextSize.Y) div 2;
end;
end;
case Layout of
blGlyphLeft: begin
GlyphPos.X := Margin;
TextPos.X := GlyphPos.X + GlyphSize.X + Spacing;
ArrowPos.X := TextPos.X + TextSize.X;
end;
blGlyphRight: begin
ArrowPos.X := ClientSize.X - Margin - ArrowSize.X;
GlyphPos.X := ArrowPos.X - GlyphSize.X;
TextPos.X := GlyphPos.X - Spacing - TextSize.X;
end;
blGlyphTop: begin
GlyphPos.Y := Margin;
TextPos.Y := GlyphPos.Y + GlyphSize.Y + Spacing;
end;
blGlyphBottom: begin
GlyphPos.Y := ClientSize.Y - Margin - GlyphSize.Y;
TextPos.Y := GlyphPos.Y - Spacing - TextSize.Y;
end;
end;
Inc (ArrowPos.X);
if not HasGlyph then
ArrowPos.Y := TextPos.Y + (TextSize.Y - ArrowSize.Y) div 2
else
ArrowPos.Y := GlyphPos.Y + (GlyphSize.Y - ArrowSize.Y) div 2;
{ fixup the result variables }
with GlyphPosdo
begin
Inc (X, Client.Left + Offset.X);
Inc (Y, Client.Top + Offset.Y);
end;
with ArrowPosdo
begin
Inc (X, Client.Left + Offset.X);
Inc (Y, Client.Top + Offset.Y);
end;
OffsetRect (TextBounds, TextPos.X + Client.Left + Offset.X,
TextPos.Y + Client.Top + Offset.X);
end;
function TButtonGlyph.Draw (Canvas: TCanvas;
const Client: TRect;
const Offset: TPoint;
DrawGlyph, DrawCaption: Boolean;
const Caption: string;
WordWrap: Boolean;
Alignment: TAlignment;
Layout: TButtonLayout;
Margin, Spacing: Integer;
DropArrow: Boolean;
DropArrowWidth: Integer;
State: TButtonState97): TRect;
var
GlyphPos, ArrowPos: TPoint;
begin
CalcButtonLayout (Canvas, Client, Offset, DrawGlyph, DrawCaption, Caption,
WordWrap, Layout, Margin, Spacing, DropArrow, DropArrowWidth, GlyphPos,
ArrowPos, Result);
if DrawGlyph then
DrawButtonGlyph (Canvas, GlyphPos, State);
if DrawCaption then
DrawButtonText (Canvas, Caption, Result, WordWrap, Alignment, State);
if DropArrow then
DrawButtonDropArrow (Canvas, ArrowPos.X, ArrowPos.Y, DropArrowWidth, State);
end;