TAChart: Add RotatePointX utility function

git-svn-id: trunk@35623 -
This commit is contained in:
ask 2012-02-29 15:25:04 +00:00
parent 43e5cef025
commit 1bb99f869b
4 changed files with 22 additions and 13 deletions

View File

@ -225,8 +225,8 @@ begin
lineExtent := FSimpleTextOut.SimpleTextExtent(FText2[i]);
p := FPos;
case FAlignment of
taCenter: p += RotatePoint(Point((FWidth - lineExtent.X) div 2, 0), a);
taRightJustify: p += RotatePoint(Point(FWidth - lineExtent.X, 0), a);
taCenter: p += RotatePointX((FWidth - lineExtent.X) div 2, a);
taRightJustify: p += RotatePointX(FWidth - lineExtent.X, a);
end;
FSimpleTextOut.SimpleTextOut(p.X, p.Y, FText2[i]);
FPos += RotatePoint(Point(0, lineExtent.Y + LINE_INTERVAL), a);

View File

@ -58,6 +58,7 @@ function RectIntersectsRect(
var ARect: TDoubleRect; const AFixed: TDoubleRect): Boolean;
function RotatePoint(const APoint: TDoublePoint; AAngle: Double): TDoublePoint; overload;
function RotatePoint(const APoint: TPoint; AAngle: Double): TPoint; overload;
function RotatePointX(AX, AAngle: Double): TPoint;
function RotateRect(const ASize: TPoint; AAngle: Double): TPointArray;
operator +(const A: TPoint; B: TSize): TPoint; overload; inline;
@ -134,17 +135,15 @@ procedure ExpandRect(
var ARect: TRect; const ACenter: TPoint; ARadius: Integer;
AAngle1, AAngle2: Double);
var
p: TPoint;
i, j: Integer;
begin
p := Point(ARadius, 0);
EnsureOrder(AAngle1, AAngle2);
ExpandRect(ARect, RotatePoint(p, AAngle1) + ACenter);
ExpandRect(ARect, RotatePoint(p, AAngle2) + ACenter);
ExpandRect(ARect, RotatePointX(ARadius, AAngle1) + ACenter);
ExpandRect(ARect, RotatePointX(ARadius, AAngle2) + ACenter);
j := Floor(AAngle1 / Pi * 2);
for i := j to j + 4 do
if InRange(Pi / 2 * i, AAngle1, AAngle2) then
ExpandRect(ARect, RotatePoint(p, Pi / 2 * i) + ACenter);
ExpandRect(ARect, RotatePointX(ARadius, Pi / 2 * i) + ACenter);
end;
function IsPointOnLine(const AP, A1, A2: TPoint): Boolean;
@ -407,6 +406,15 @@ begin
Result.Y := Round(sa * APoint.X + ca * APoint.Y);
end;
function RotatePointX(AX, AAngle: Double): TPoint;
var
sa, ca: Extended;
begin
SinCos(AAngle, sa, ca);
Result.X := Round(ca * AX);
Result.Y := Round(sa * AX);
end;
function RotateRect(const ASize: TPoint; AAngle: Double): TPointArray;
var
i: Integer;

View File

@ -346,7 +346,7 @@ function TCustomPieSeries.TryRadius(ADrawer: IChartDrawer): TRect;
function EndPoint(AAngle, ARadius: Double): TPoint;
begin
Result := RotatePoint(Point(Round(ARadius), 0), -AAngle);
Result := RotatePointX(ARadius, -AAngle);
end;
function LabelExtraDist(APoly: TPointArray; AAngle: Double): Double;

View File

@ -1201,16 +1201,17 @@ procedure TChartArrow.Draw(
APen: TFPCustomPen);
var
da: Double;
pt, pt1, pt2, ptBase: TPoint;
diag: Integer;
pt1, pt2, ptBase: TPoint;
begin
if not Visible then exit;
da := ArcTan2(Width, Length);
pt := Point(-ADrawer.Scale(Round(Sqrt(Sqr(Length) + Sqr(Width)))), 0);
pt1 := AEndPos + RotatePoint(pt, AAngle - da);
pt2 := AEndPos + RotatePoint(pt, AAngle + da);
diag := -ADrawer.Scale(Round(Sqrt(Sqr(Length) + Sqr(Width))));
pt1 := AEndPos + RotatePointX(diag, AAngle - da);
pt2 := AEndPos + RotatePointX(diag, AAngle + da);
if BaseLength > 0 then begin
ptBase := AEndPos + RotatePoint(Point(-ADrawer.Scale(BaseLength), 0), AAngle);
ptBase := AEndPos + RotatePointX(-ADrawer.Scale(BaseLength), AAngle);
ADrawer.SetBrushParams(bsSolid, FPColorToChartColor(APen.FPColor));
ADrawer.Polygon([pt1, AEndPos, pt2, ptBase], 0, 4);
end