TAChart: Simplify Polygon/Polyline interface of IChartDrawer

git-svn-id: trunk@30216 -
This commit is contained in:
ask 2011-04-06 00:21:22 +00:00
parent bdf0c74b20
commit 20bbf9174c
10 changed files with 37 additions and 53 deletions

View File

@ -51,11 +51,10 @@ type
procedure LineTo(AX, AY: Integer); override;
procedure MoveTo(AX, AY: Integer); override;
procedure Polygon(
const APoints: array of TPoint;
AStartIndex: Integer = 0; ANumPts: Integer = -1); override;
const APoints: array of TPoint; AStartIndex, ANumPts: Integer); override;
procedure Polyline(
const APoints: array of TPoint; AStartIndex: Integer = 0;
ANumPts: Integer = -1; AEndPoint: Boolean = false);
const APoints: array of TPoint; AStartIndex, ANumPts: Integer;
AEndPoint: Boolean = false);
procedure PrepareSimplePen(AColor: TChartColor);
procedure RadialPie(
AX1, AY1, AX2, AY2: Integer;
@ -147,8 +146,6 @@ procedure TAggPasDrawer.Polygon(
begin
FCanvas.Polygon(APoints, false, AStartIndex, ANumPts);
FCanvas.Polyline(APoints, AStartIndex, ANumPts);
if ANumPts < 0 then
ANumPts := Length(APoints);
FCanvas.Line(APoints[ANumPts - 1], APoints[0])
end;

View File

@ -58,11 +58,10 @@ type
procedure LineTo(AX, AY: Integer); override;
procedure MoveTo(AX, AY: Integer); override;
procedure Polygon(
const APoints: array of TPoint;
AStartIndex: Integer = 0; ANumPts: Integer = -1); override;
const APoints: array of TPoint; AStartIndex, ANumPts: Integer); override;
procedure Polyline(
const APoints: array of TPoint; AStartIndex: Integer = 0;
ANumPts: Integer = -1; AEndPoint: Boolean = false);
const APoints: array of TPoint; AStartIndex, ANumPts: Integer;
AEndPoint: Boolean = false);
procedure PrepareSimplePen(AColor: TChartColor);
procedure RadialPie(
AX1, AY1, AX2, AY2: Integer;
@ -84,8 +83,7 @@ function PointsToPointsF(
var
i: Integer;
begin
if ANumPts = -1 then
ANumPts := Length(APoints) - AStartIndex;
Assert(ANumPts >= 0);
SetLength(Result, ANumPts);
for i := 0 to ANumPts - 1 do
with APoints[i + AStartIndex] do
@ -180,7 +178,7 @@ begin
end;
procedure TBGRABitmapDrawer.Polygon(
const APoints: array of TPoint; AStartIndex: Integer; ANumPts: Integer);
const APoints: array of TPoint; AStartIndex, ANumPts: Integer);
var
bt: TBGRACustomBitmap;
begin
@ -201,7 +199,7 @@ end;
procedure TBGRABitmapDrawer.Polyline(
const APoints: array of TPoint;
AStartIndex: Integer; ANumPts: Integer; AEndPoint: Boolean);
AStartIndex, ANumPts: Integer; AEndPoint: Boolean);
begin
Unused(AEndPoint);
FCanvas.DrawPolyLineAntialias(

View File

@ -58,11 +58,10 @@ type
procedure LineTo(AX, AY: Integer); override;
procedure MoveTo(AX, AY: Integer); override;
procedure Polygon(
const APoints: array of TPoint;
AStartIndex: Integer = 0; ANumPts: Integer = -1); override;
const APoints: array of TPoint; AStartIndex, ANumPts: Integer); override;
procedure Polyline(
const APoints: array of TPoint; AStartIndex: Integer = 0;
ANumPts: Integer = -1; AEndPoint: Boolean = false);
const APoints: array of TPoint;
AStartIndex, ANumPts: Integer; AEndPoint: Boolean = false);
procedure PrepareSimplePen(AColor: TChartColor);
procedure RadialPie(
AX1, AY1, AX2, AY2: Integer;

View File

@ -61,11 +61,10 @@ type
procedure LineTo(AX, AY: Integer); override;
procedure MoveTo(AX, AY: Integer); override;
procedure Polygon(
const APoints: array of TPoint;
AStartIndex: Integer = 0; ANumPts: Integer = -1); override;
const APoints: array of TPoint; AStartIndex, ANumPts: Integer); override;
procedure Polyline(
const APoints: array of TPoint; AStartIndex: Integer = 0;
ANumPts: Integer = -1; AEndPoint: Boolean = false);
const APoints: array of TPoint; AStartIndex, ANumPts: Integer;
AEndPoint: Boolean = false);
procedure PrepareSimplePen(AColor: TChartColor);
procedure RadialPie(
AX1, AY1, AX2, AY2: Integer;
@ -187,9 +186,9 @@ begin
end;
procedure TFPCanvasDrawer.Polygon(
const APoints: array of TPoint; AStartIndex: Integer; ANumPts: Integer);
const APoints: array of TPoint; AStartIndex, ANumPts: Integer);
begin
if (ANumPts < 0) and (AStartIndex = 0) then
if (ANumPts = Length(APoints)) and (AStartIndex = 0) then
FCanvas.Polygon(APoints)
else
FCanvas.Polygon(CopyPoints(APoints, AStartIndex, ANumPts));
@ -197,10 +196,10 @@ end;
procedure TFPCanvasDrawer.Polyline(
const APoints: array of TPoint;
AStartIndex: Integer; ANumPts: Integer; AEndPoint: Boolean);
AStartIndex, ANumPts: Integer; AEndPoint: Boolean);
begin
Unused(AEndPoint);
if (ANumPts < 0) and (AStartIndex = 0) then
if (ANumPts = Length(APoints)) and (AStartIndex = 0) then
FCanvas.Polyline(APoints)
else
FCanvas.Polyline(CopyPoints(APoints, AStartIndex, ANumPts));

View File

@ -55,8 +55,7 @@ type
procedure LineTo(AX, AY: Integer); override;
procedure MoveTo(AX, AY: Integer); override;
procedure Polygon(
const APoints: array of TPoint;
AStartIndex: Integer = 0; ANumPts: Integer = -1); override;
const APoints: array of TPoint; AStartIndex, ANumPts: Integer); override;
procedure Polyline(
const APoints: array of TPoint; AStartIndex: Integer = 0;
ANumPts: Integer = -1; AEndPoint: Boolean = false);
@ -155,13 +154,11 @@ procedure TOpenGLDrawer.InternalPolyline(
var
i: Integer;
begin
if ANumPts < 0 then
ANumPts := Length(APoints);
glBegin(AMode);
ChartGLColor(FPenColor);
glLineWidth(FPenWidth);
for i := AStartIndex to AStartIndex + ANumPts - 1 do
glVertex2i(APoints[i].X, APoints[i].Y);
glVertex2iv(@APoints[i]);
glEnd();
end;
@ -191,22 +188,20 @@ begin
end;
procedure TOpenGLDrawer.Polygon(
const APoints: array of TPoint; AStartIndex: Integer; ANumPts: Integer);
const APoints: array of TPoint; AStartIndex, ANumPts: Integer);
var
i: Integer;
begin
if ANumPts < 0 then
ANumPts := Length(APoints);
glBegin(GL_POLYGON);
ChartGLColor(FBrushColor);
for i := AStartIndex to AStartIndex + ANumPts - 1 do
glVertex2i(APoints[i].X, APoints[i].Y);
glVertex2iv(@APoints[i]);
glEnd();
InternalPolyline(APoints, AStartIndex, ANumPts, GL_LINE_LOOP);
end;
procedure TOpenGLDrawer.Polyline(
const APoints: array of TPoint; AStartIndex: Integer; ANumPts: Integer;
const APoints: array of TPoint; AStartIndex, ANumPts: Integer;
AEndPoint: Boolean);
begin
Unused(AEndPoint);

View File

@ -71,11 +71,10 @@ type
procedure LineTo(AX, AY: Integer); override;
procedure MoveTo(AX, AY: Integer); override;
procedure Polygon(
const APoints: array of TPoint;
AStartIndex: Integer = 0; ANumPts: Integer = -1); override;
const APoints: array of TPoint; AStartIndex, ANumPts: Integer); override;
procedure Polyline(
const APoints: array of TPoint; AStartIndex: Integer = 0;
ANumPts: Integer = -1; AEndPoint: Boolean = false);
const APoints: array of TPoint; AStartIndex, ANumPts: Integer;
AEndPoint: Boolean = false);
procedure PrepareSimplePen(AColor: TChartColor);
procedure RadialPie(
AX1, AY1, AX2, AY2: Integer;
@ -235,7 +234,7 @@ begin
end;
procedure TSVGDrawer.Polygon(
const APoints: array of TPoint; AStartIndex: Integer; ANumPts: Integer);
const APoints: array of TPoint; AStartIndex, ANumPts: Integer);
begin
WriteFmt(
'<polygon points="%s" style="%s"/>',
@ -243,7 +242,7 @@ begin
end;
procedure TSVGDrawer.Polyline(
const APoints: array of TPoint; AStartIndex: Integer; ANumPts: Integer;
const APoints: array of TPoint; AStartIndex, ANumPts: Integer;
AEndPoint: Boolean);
begin
Unused(AEndPoint);

View File

@ -84,11 +84,10 @@ type
procedure MoveTo(AX, AY: Integer);
procedure MoveTo(const AP: TPoint);
procedure Polygon(
const APoints: array of TPoint;
AStartIndex: Integer = 0; ANumPts: Integer = -1);
const APoints: array of TPoint; AStartIndex, ANumPts: Integer);
procedure Polyline(
const APoints: array of TPoint; AStartIndex: Integer = 0;
ANumPts: Integer = -1; AEndPoint: Boolean = false);
const APoints: array of TPoint;
AStartIndex, ANumPts: Integer; AEndPoint: Boolean = false);
procedure PrepareSimplePen(AColor: TChartColor);
procedure RadialPie(
AX1, AY1, AX2, AY2: Integer;
@ -137,8 +136,7 @@ type
procedure MoveTo(AX, AY: Integer); virtual; abstract;
procedure MoveTo(const AP: TPoint);
procedure Polygon(
const APoints: array of TPoint;
AStartIndex: Integer = 0; ANumPts: Integer = -1); virtual; abstract;
const APoints: array of TPoint; AStartIndex, ANumPts: Integer); virtual; abstract;
function Scale(ADistance: Integer): Integer; virtual;
procedure SetDoChartColorToFPColorFunc(AValue: TChartColorToFPColorFunc);
procedure SetGetFontOrientationFunc(AValue: TGetFontOrientationFunc);
@ -300,7 +298,7 @@ var
d: TPoint;
begin
d := Point(ADepth, -ADepth);
Polygon([AP1, AP1 + d, AP2 + d, AP2]);
Polygon([AP1, AP1 + d, AP2 + d, AP2], 0, 4);
end;
procedure TBasicDrawer.LineTo(const AP: TPoint);

View File

@ -96,8 +96,7 @@ function CopyPoints(
var
i: Integer;
begin
if ANumPts = -1 then
ANumPts := Length(APoints) - AStartIndex;
Assert(ANumPts >= 0);
SetLength(Result, ANumPts);
for i := 0 to ANumPts - 1 do
Result[i] := APoints[i + AStartIndex];

View File

@ -401,7 +401,7 @@ begin
pts[i] := FChart.GraphToImage(GraphPoint(i));
ADrawer.Pen := LinePen;
ADrawer.SetBrushParams(bsClear, clTAColor);
ADrawer.Polygon(pts);
ADrawer.Polygon(pts, 0, Length(pts));
end;
function TPolarSeries.Extent: TDoubleRect;

View File

@ -580,7 +580,7 @@ begin
ADrawer.Brush := LabelBrush;
if IsMarginRequired then begin
ADrawer.Pen := Frame;
ADrawer.Polygon(labelPoly);
ADrawer.Polygon(labelPoly, 0, Length(labelPoly));
end;
ptText := RotatePoint(-ptText div 2, LabelAngle) + ALabelCenter;