mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-03 20:47:09 +01:00
TAChart: Extract MakeSquare utility function
git-svn-id: trunk@31394 -
This commit is contained in:
parent
ac09dbf6fd
commit
1584ede71a
@ -46,6 +46,7 @@ function LineIntersectsRect(
|
|||||||
var AA, AB: TDoublePoint; const ARect: TDoubleRect): Boolean;
|
var AA, AB: TDoublePoint; const ARect: TDoubleRect): Boolean;
|
||||||
procedure NormalizeRect(var ARect: TRect); overload;
|
procedure NormalizeRect(var ARect: TRect); overload;
|
||||||
procedure NormalizeRect(var ARect: TDoubleRect); overload;
|
procedure NormalizeRect(var ARect: TDoubleRect); overload;
|
||||||
|
function MakeSquare(const ARect: TRect): TRect;
|
||||||
function MeasureRotatedRect(const ASize: TPoint; AAngle: Double): TSize;
|
function MeasureRotatedRect(const ASize: TPoint; AAngle: Double): TSize;
|
||||||
function PointDist(const A, B: TPoint): Integer; inline;
|
function PointDist(const A, B: TPoint): Integer; inline;
|
||||||
function PointDistX(const A, B: TPoint): Integer; inline;
|
function PointDistX(const A, B: TPoint): Integer; inline;
|
||||||
@ -282,6 +283,25 @@ begin
|
|||||||
Result := true;
|
Result := true;
|
||||||
end;
|
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;
|
function MeasureRotatedRect(const ASize: TPoint; AAngle: Double): TSize;
|
||||||
var
|
var
|
||||||
pt1, pt2: TPoint;
|
pt1, pt2: TPoint;
|
||||||
|
|||||||
@ -143,28 +143,14 @@ procedure TLegendItemPie.Draw(ADrawer: IChartDrawer; const ARect: TRect);
|
|||||||
const
|
const
|
||||||
INDEX_TO_ANGLE = 360 * 16 / Length(FColors);
|
INDEX_TO_ANGLE = 360 * 16 / Length(FColors);
|
||||||
var
|
var
|
||||||
c: TPoint;
|
|
||||||
w, h: Integer;
|
|
||||||
r: TRect;
|
|
||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
inherited Draw(ADrawer, ARect);
|
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
|
for i := 0 to High(FColors) do begin
|
||||||
ADrawer.SetBrushColor(FColors[i]);
|
ADrawer.SetBrushColor(FColors[i]);
|
||||||
|
with MakeSquare(ARect) do
|
||||||
ADrawer.RadialPie(
|
ADrawer.RadialPie(
|
||||||
r.Left, r.Top, r.Right, r.Bottom,
|
Left, Top, Right, Bottom,
|
||||||
Round(i * INDEX_TO_ANGLE), Round(INDEX_TO_ANGLE));
|
Round(i * INDEX_TO_ANGLE), Round(INDEX_TO_ANGLE));
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user