TAChart: Extract MakeSquare utility function

git-svn-id: trunk@31394 -
This commit is contained in:
ask 2011-06-26 07:32:18 +00:00
parent ac09dbf6fd
commit 1584ede71a
2 changed files with 24 additions and 18 deletions

View File

@ -46,6 +46,7 @@ function LineIntersectsRect(
var AA, AB: TDoublePoint; const ARect: TDoubleRect): Boolean;
procedure NormalizeRect(var ARect: TRect); overload;
procedure NormalizeRect(var ARect: TDoubleRect); overload;
function MakeSquare(const ARect: TRect): TRect;
function MeasureRotatedRect(const ASize: TPoint; AAngle: Double): TSize;
function PointDist(const A, B: TPoint): Integer; inline;
function PointDistX(const A, B: TPoint): Integer; inline;
@ -282,6 +283,25 @@ begin
Result := true;
end;
function MakeSquare(const ARect: TRect): TRect;
var
c: TPoint;
w, h: Integer;
begin
c := CenterPoint(ARect);
Result := ARect;
w := Abs(Result.Right - Result.Left);
h := Abs(Result.Bottom - Result.Top);
if w > h then begin
Result.Left := c.X - h div 2;
Result.Right := c.X + h div 2;
end
else begin
Result.Top := c.Y - w div 2;
Result.Bottom := c.Y + w div 2;
end;
end;
function MeasureRotatedRect(const ASize: TPoint; AAngle: Double): TSize;
var
pt1, pt2: TPoint;

View File

@ -143,29 +143,15 @@ procedure TLegendItemPie.Draw(ADrawer: IChartDrawer; const ARect: TRect);
const
INDEX_TO_ANGLE = 360 * 16 / Length(FColors);
var
c: TPoint;
w, h: Integer;
r: TRect;
i: Integer;
begin
inherited Draw(ADrawer, ARect);
c := CenterPoint(ARect);
r := ARect;
w := Abs(r.Right - r.Left);
h := Abs(r.Bottom - r.Top);
if w > h then begin
r.Left := c.X - h div 2;
r.Right := c.X + h div 2;
end
else begin
r.Top := c.Y - w div 2;
r.Bottom := c.Y + w div 2;
end;
for i := 0 to High(FColors) do begin
ADrawer.SetBrushColor(FColors[i]);
ADrawer.RadialPie(
r.Left, r.Top, r.Right, r.Bottom,
Round(i * INDEX_TO_ANGLE), Round(INDEX_TO_ANGLE));
with MakeSquare(ARect) do
ADrawer.RadialPie(
Left, Top, Right, Bottom,
Round(i * INDEX_TO_ANGLE), Round(INDEX_TO_ANGLE));
end;
end;