TAChart: Use IChartDrawer to draw TSeriesPointer

git-svn-id: trunk@29634 -
This commit is contained in:
ask 2011-02-21 16:08:52 +00:00
parent 75192fa3f6
commit 94f2a8371c
5 changed files with 56 additions and 32 deletions

View File

@ -28,6 +28,7 @@ type
procedure ClippingStart;
procedure ClippingStart(const AClipRect: TRect);
procedure ClippingStop;
procedure Ellipse(AX1, AY1, AX2, AY2: Integer);
procedure FillRect(AX1, AY1, AX2, AY2: Integer);
function GetBrushColor: TChartColor;
function GetCanvas: TCanvas;
@ -38,8 +39,8 @@ type
const APoints: array of TPoint;
AStartIndex: Integer = 0; ANumPts: Integer = -1); override;
procedure Polyline(
const APoints: array of TPoint;
AStartIndex: Integer = 0; ANumPts: Integer = -1);
const APoints: array of TPoint; AStartIndex: Integer = 0;
ANumPts: Integer = -1; AEndPoint: Boolean = false);
procedure PrepareSimplePen(AColor: TChartColor);
procedure RadialPie(
AX1, AY1, AX2, AY2: Integer;
@ -85,6 +86,11 @@ begin
FCanvas := ACanvas;
end;
procedure TAggPasDrawer.Ellipse(AX1, AY1, AX2, AY2: Integer);
begin
FCanvas.Ellipse(AX1, AY1, AX2, AY2);
end;
procedure TAggPasDrawer.FillRect(AX1, AY1, AX2, AY2: Integer);
begin
FCanvas.FillRect(AX1, AY1, AX2, AY2);
@ -126,11 +132,16 @@ 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;
procedure TAggPasDrawer.Polyline(
const APoints: array of TPoint; AStartIndex, ANumPts: Integer);
const APoints: array of TPoint; AStartIndex, ANumPts: Integer;
AEndPoint: Boolean);
begin
Unused(AEndPoint);
FCanvas.Polyline(APoints, AStartIndex, ANumPts);
end;

View File

@ -61,14 +61,14 @@ type
TChartTextOut = class
strict private
FAlignment: TAlignment;
FSimpleTextOut: ISimpleTextOut;
FPos: TPoint;
FSimpleTextOut: ISimpleTextOut;
FText1: String;
FText2: TStrings;
FWidth: Integer;
procedure DoTextOutString;
procedure DoTextOutList;
procedure DoTextOutString;
public
constructor Create(ASimpleTextOut: ISimpleTextOut);
public
@ -90,6 +90,7 @@ type
procedure ClippingStop;
procedure DrawLineDepth(AX1, AY1, AX2, AY2, ADepth: Integer);
procedure DrawLineDepth(const AP1, AP2: TPoint; ADepth: Integer);
procedure Ellipse(AX1, AY1, AX2, AY2: Integer);
procedure FillRect(AX1, AY1, AX2, AY2: Integer);
function GetBrushColor: TChartColor;
function GetCanvas: TCanvas;
@ -100,8 +101,8 @@ type
const APoints: array of TPoint;
AStartIndex: Integer = 0; ANumPts: Integer = -1);
procedure Polyline(
const APoints: array of TPoint;
AStartIndex: Integer = 0; ANumPts: Integer = -1);
const APoints: array of TPoint; AStartIndex: Integer = 0;
ANumPts: Integer = -1; AEndPoint: Boolean = false);
procedure PrepareSimplePen(AColor: TChartColor);
procedure RadialPie(
AX1, AY1, AX2, AY2: Integer;
@ -130,8 +131,8 @@ type
TFPCanvasDrawer = class(TInterfacedObject, ISimpleTextOut)
strict protected
function GetFontAngle: Double; virtual; abstract;
procedure SimpleTextOut(AX, AY: Integer; const AText: String); virtual; abstract;
function SimpleTextExtent(const AText: String): TPoint; virtual; abstract;
procedure SimpleTextOut(AX, AY: Integer; const AText: String); virtual; abstract;
public
procedure DrawLineDepth(AX1, AY1, AX2, AY2, ADepth: Integer);
procedure DrawLineDepth(const AP1, AP2: TPoint; ADepth: Integer);
@ -153,14 +154,15 @@ type
procedure SetPen(APen: TFPCustomPen);
strict protected
function GetFontAngle: Double; override;
procedure SimpleTextOut(AX, AY: Integer; const AText: String); override;
function SimpleTextExtent(const AText: String): TPoint; override;
procedure SimpleTextOut(AX, AY: Integer; const AText: String); override;
public
procedure AddToFontOrientation(ADelta: Integer);
procedure ClippingStart;
procedure ClippingStart(const AClipRect: TRect);
procedure ClippingStop;
constructor Create(ACanvas: TCanvas);
procedure Ellipse(AX1, AY1, AX2, AY2: Integer);
procedure FillRect(AX1, AY1, AX2, AY2: Integer);
function GetBrushColor: TChartColor;
function GetCanvas: TCanvas;
@ -171,8 +173,8 @@ type
const APoints: array of TPoint;
AStartIndex: Integer = 0; ANumPts: Integer = -1); override;
procedure Polyline(
const APoints: array of TPoint;
AStartIndex: Integer = 0; ANumPts: Integer = -1);
const APoints: array of TPoint; AStartIndex: Integer = 0;
ANumPts: Integer = -1; AEndPoint: Boolean = false);
procedure PrepareSimplePen(AColor: TChartColor);
procedure RadialPie(
AX1, AY1, AX2, AY2: Integer;
@ -385,6 +387,11 @@ begin
FCanvas := ACanvas;
end;
procedure TCanvasDrawer.Ellipse(AX1, AY1, AX2, AY2: Integer);
begin
FCanvas.Ellipse(AX1, AY1, AX2, AY2);
end;
procedure TCanvasDrawer.FillRect(AX1, AY1, AX2, AY2: Integer);
begin
FCanvas.FillRect(AX1, AY1, AX2, AY2);
@ -427,9 +434,17 @@ begin
end;
procedure TCanvasDrawer.Polyline(
const APoints: array of TPoint; AStartIndex, ANumPts: Integer);
const APoints: array of TPoint; AStartIndex, ANumPts: Integer;
AEndPoint: Boolean);
begin
FCanvas.Polyline(APoints, AStartIndex, ANumPts);
if AEndPoint then begin
// Polyline does not draw the end point.
if ANumPts < 0 then
ANumPts := Length(APoints);
with APoints[ANumPts - 1] do
FCanvas.Pixels[X, Y] := FCanvas.Pen.Color;
end;
end;
procedure TCanvasDrawer.PrepareSimplePen(AColor: TChartColor);

View File

@ -264,7 +264,7 @@ begin
// Max width slightly narrower then ARect to leave place for the line.
sz.X := Min(FPointer.HorizSize, (ARect.Right - ARect.Left) div 3);
sz.Y := Min(FPointer.VertSize, (ARect.Bottom - ARect.Top) div 2);
FPointer.DrawSize(ADrawer.Canvas, c, sz, Color);
FPointer.DrawSize(ADrawer, c, sz, Color);
end;
{ TLegendItemBrushRect }

View File

@ -472,13 +472,13 @@ begin
if ADrawer.HasCanvas then
DrawLabels(ADrawer.Canvas);
if FShowPoints and ADrawer.HasCanvas then
if FShowPoints then
for i := FLoBound to FUpBound do begin
p := FGraphPoints[i - FLoBound];
if not ParentChart.IsPointInViewPort(p) then continue;
ai := ParentChart.GraphToImage(p);
FPointer.Draw(ADrawer.Canvas, ai, Source[i]^.Color);
if Assigned(FOnDrawPointer) then
FPointer.Draw(ADrawer, ai, Source[i]^.Color);
if ADrawer.HasCanvas and Assigned(FOnDrawPointer) then
FOnDrawPointer(Self, ADrawer.Canvas, i, ai);
end;
end;

View File

@ -246,9 +246,9 @@ type
public
procedure Assign(Source: TPersistent); override;
procedure Draw(ACanvas: TCanvas; ACenter: TPoint; AColor: TColor);
procedure Draw(ADrawer: IChartDrawer; ACenter: TPoint; AColor: TColor);
procedure DrawSize(
ACanvas: TCanvas; ACenter, ASize: TPoint; AColor: TColor);
ADrawer: IChartDrawer; ACenter, ASize: TPoint; AColor: TColor);
published
property Brush: TBrush read FBrush write SetBrush;
property HorizSize: Integer read FHorizSize write SetHorizSize default DEF_POINTER_SIZE;
@ -761,13 +761,14 @@ begin
inherited;
end;
procedure TSeriesPointer.Draw(ACanvas: TCanvas; ACenter: TPoint; AColor: TColor);
procedure TSeriesPointer.Draw(
ADrawer: IChartDrawer; ACenter: TPoint; AColor: TColor);
begin
DrawSize(ACanvas, ACenter, Point(HorizSize, VertSize), AColor);
DrawSize(ADrawer, ACenter, Point(HorizSize, VertSize), AColor);
end;
procedure TSeriesPointer.DrawSize(
ACanvas: TCanvas; ACenter, ASize: TPoint; AColor: TColor);
ADrawer: IChartDrawer; ACenter, ASize: TPoint; AColor: TColor);
function PointByIndex(AIndex: Char): TPoint;
// 7--8--9
@ -791,13 +792,10 @@ procedure TSeriesPointer.DrawSize(
SetLength(pts, Length(AStr));
for i := 1 to Length(AStr) do begin
if AStr[i] = ' ' then begin
if Brush.Style = bsClear then begin
ACanvas.Polyline(pts, 0, j);
// Polyline does not draw the end point.
ACanvas.Pixels[pts[j - 1].X, pts[j - 1].Y] := Pen.Color;
end
if Brush.Style = bsClear then
ADrawer.Polyline(pts, 0, j, true)
else
ACanvas.Polygon(pts, true, 0, j);
ADrawer.Polygon(pts, 0, j); // Winding?
j := 0;
end
else begin
@ -816,13 +814,13 @@ const
'41236', '47896', '87412', '89632', '84268',
'183', '842', '862');
begin
ACanvas.Brush.Assign(FBrush);
ADrawer.Brush := Brush;
if AColor <> clTAColor then
ACanvas.Brush.Color := AColor;
ACanvas.Pen.Assign(FPen);
ADrawer.BrushColor := AColor;
ADrawer.Pen := Pen;
if FStyle = psCircle then
ACanvas.Ellipse(
if Style = psCircle then
ADrawer.Ellipse(
ACenter.X - ASize.X, ACenter.Y - ASize.Y,
ACenter.X + ASize.X, ACenter.Y + ASize.Y)
else