TAChart: Extract TADrawerCanvas unit, remove TADrawUtils -> Graphics dependency

git-svn-id: trunk@29970 -
This commit is contained in:
ask 2011-03-21 14:52:25 +00:00
parent 8b59cb5870
commit 910e4b3def
9 changed files with 280 additions and 240 deletions

1
.gitattributes vendored
View File

@ -2441,6 +2441,7 @@ components/tachart/tacustomseries.pas svneol=native#text/plain
components/tachart/tacustomsource.pas svneol=native#text/pascal
components/tachart/tadbsource.pas svneol=native#text/pascal
components/tachart/tadraweraggpas.pas svneol=native#text/pascal
components/tachart/tadrawercanvas.pas svneol=native#text/pascal
components/tachart/tadrawerfpcanvas.pas svneol=native#text/pascal
components/tachart/tadraweropengl.pas svneol=native#text/pascal
components/tachart/tadrawutils.pas svneol=native#text/pascal

View File

@ -28,7 +28,7 @@
for details about the copyright.
"/>
<Version Major="1"/>
<Files Count="23">
<Files Count="24">
<Item1>
<Filename Value="tagraph.pas"/>
<HasRegisterProc Value="True"/>
@ -130,6 +130,10 @@
<Filename Value="tadrawerfpcanvas.pas"/>
<UnitName Value="TADrawerFPCanvas"/>
</Item23>
<Item24>
<Filename Value="tadrawercanvas.pas"/>
<UnitName Value="TADrawerCanvas"/>
</Item24>
</Files>
<LazDoc Paths="$(LazarusDir)\components\tachart\fpdoc"/>
<Type Value="RunAndDesignTime"/>

View File

@ -11,7 +11,7 @@ uses
TASeries, TASeriesEditor, TASubcomponentsEditor, TATools, TATransformations,
TATypes, TADrawUtils, TAMultiSeries, TALegend, TAStyles, TAFuncSeries,
TALegendPanel, TARadialSeries, TACustomSource, TAGeometry, TANavigation,
TADrawerFPCanvas, LazarusPackageIntf;
TADrawerFPCanvas, TADrawerCanvas, LazarusPackageIntf;
implementation

View File

@ -0,0 +1,267 @@
{
*****************************************************************************
* *
* See the file COPYING.modifiedLGPL.txt, included in this distribution, *
* for details about the copyright. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* *
*****************************************************************************
Authors: Alexander Klenin
}
unit TADrawerCanvas;
{$H+}
interface
uses
Classes, FPCanvas, FPImage, Graphics, SysUtils, TADrawUtils;
type
IChartTCanvasDrawer = interface
['{6D8E5591-6788-4D2D-9FE6-596D5157C3C2}']
function GetCanvas: TCanvas;
property Canvas: TCanvas read GetCanvas;
end;
{ TCanvasDrawer }
TCanvasDrawer = class(
TBasicDrawer, IChartDrawer, IChartTCanvasDrawer)
private
FCanvas: TCanvas;
procedure SetBrush(ABrush: TFPCustomBrush);
procedure SetFont(AFont: TFPCustomFont);
procedure SetPen(APen: TFPCustomPen);
strict protected
function GetFontAngle: Double; 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;
procedure Line(AX1, AY1, AX2, AY2: Integer);
procedure Line(const AP1, AP2: TPoint);
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;
procedure Polyline(
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;
AStartAngle16Deg, AAngleLength16Deg: Integer);
procedure Rectangle(const ARect: TRect);
procedure Rectangle(AX1, AY1, AX2, AY2: Integer);
procedure SetBrushColor(AColor: TChartColor);
procedure SetBrushParams(AStyle: TFPBrushStyle; AColor: TChartColor);
procedure SetPenParams(AStyle: TFPPenStyle; AColor: TChartColor);
end;
procedure PrepareXorPen(ACanvas: TCanvas);
function ChartColorSysToFPColor(AChartColor: TChartColor): TFPColor;
implementation
uses
TAChartUtils, TAGeometry;
function ChartColorSysToFPColor(AChartColor: TChartColor): TFPColor;
begin
Result := ChartColorToFPColor(ColorToRGB(AChartColor));
end;
procedure PrepareXorPen(ACanvas: TCanvas);
begin
with ACanvas do begin
Brush.Style := bsClear;
Pen.Style := psSolid;
Pen.Mode := pmXor;
Pen.Color := clWhite;
Pen.Width := 1;
end;
end;
{ TCanvasDrawer }
procedure TCanvasDrawer.AddToFontOrientation(ADelta: Integer);
begin
with FCanvas.Font do
Orientation := Orientation + ADelta;
end;
procedure TCanvasDrawer.ClippingStart(const AClipRect: TRect);
begin
FCanvas.ClipRect := AClipRect;
FCanvas.Clipping := true;
end;
procedure TCanvasDrawer.ClippingStart;
begin
FCanvas.Clipping := true;
end;
procedure TCanvasDrawer.ClippingStop;
begin
FCanvas.Clipping := false;
end;
constructor TCanvasDrawer.Create(ACanvas: TCanvas);
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);
end;
function TCanvasDrawer.GetBrushColor: TChartColor;
begin
Result := FCanvas.Brush.Color;
end;
function TCanvasDrawer.GetCanvas: TCanvas;
begin
Result := FCanvas;
end;
function TCanvasDrawer.GetFontAngle: Double;
begin
Result := OrientToRad(FCanvas.Font.Orientation);
end;
procedure TCanvasDrawer.Line(AX1, AY1, AX2, AY2: Integer);
begin
FCanvas.Line(AX1, AY1, AX2, AY2);
end;
procedure TCanvasDrawer.Line(const AP1, AP2: TPoint);
begin
FCanvas.Line(AP1, AP2);
end;
procedure TCanvasDrawer.LineTo(AX, AY: Integer);
begin
FCanvas.LineTo(AX, AY);
end;
procedure TCanvasDrawer.MoveTo(AX, AY: Integer);
begin
FCanvas.MoveTo(AX, AY);
end;
procedure TCanvasDrawer.Polygon(
const APoints: array of TPoint; AStartIndex, ANumPts: Integer);
begin
FCanvas.Polygon(APoints, false, AStartIndex, ANumPts);
end;
procedure TCanvasDrawer.Polyline(
const APoints: array of TPoint; AStartIndex, ANumPts: Integer;
AEndPoint: Boolean);
begin
FCanvas.Polyline(APoints, AStartIndex, ANumPts);
if AEndPoint then begin
if ANumPts < 0 then
ANumPts := Length(APoints);
// Polyline does not draw the end point.
with APoints[ANumPts - 1] do
FCanvas.Pixels[X, Y] := FCanvas.Pen.Color;
end;
end;
procedure TCanvasDrawer.PrepareSimplePen(AColor: TChartColor);
begin
with FCanvas.Pen do begin
Color := AColor;
Style := psSolid;
Mode := pmCopy;
Width := 1;
end;
end;
procedure TCanvasDrawer.RadialPie(
AX1, AY1, AX2, AY2: Integer;
AStartAngle16Deg, AAngleLength16Deg: Integer);
begin
FCanvas.RadialPie(
AX1, AY1, AX2, AY2, AStartAngle16Deg, AAngleLength16Deg);
end;
procedure TCanvasDrawer.Rectangle(AX1, AY1, AX2, AY2: Integer);
begin
FCanvas.Rectangle(AX1, AY1, AX2, AY2);
end;
procedure TCanvasDrawer.Rectangle(const ARect: TRect);
begin
FCanvas.Rectangle(ARect);
end;
procedure TCanvasDrawer.SetBrush(ABrush: TFPCustomBrush);
begin
FCanvas.Brush.Assign(ABrush);
end;
procedure TCanvasDrawer.SetBrushColor(AColor: TChartColor);
begin
FCanvas.Brush.Color := AColor;
end;
procedure TCanvasDrawer.SetBrushParams(
AStyle: TFPBrushStyle; AColor: TChartColor);
begin
FCanvas.Brush.Style := AStyle;
FCanvas.Brush.Color := AColor;
end;
procedure TCanvasDrawer.SetFont(AFont: TFPCustomFont);
begin
FCanvas.Font.Assign(AFont);
end;
procedure TCanvasDrawer.SetPen(APen: TFPCustomPen);
begin
FCanvas.Pen.Assign(APen);
end;
procedure TCanvasDrawer.SetPenParams(AStyle: TFPPenStyle; AColor: TChartColor);
begin
FCanvas.Pen.Style := AStyle;
FCanvas.Pen.Color := AColor;
end;
function TCanvasDrawer.SimpleTextExtent(const AText: String): TPoint;
begin
Result := FCanvas.TextExtent(AText);
end;
procedure TCanvasDrawer.SimpleTextOut(AX, AY: Integer; const AText: String);
begin
FCanvas.TextOut(AX, AY, AText);
end;
end.

View File

@ -21,7 +21,7 @@ unit TADrawUtils;
interface
uses
Classes, FPCanvas, FPImage, Graphics, Types;
Classes, FPCanvas, FPImage, Types;
type
TChartColor = -$7FFFFFFF-1..$7FFFFFFF;
@ -59,12 +59,6 @@ type
function Width(AWidth: Integer): TChartTextOut;
end;
IChartTCanvasDrawer = interface
['{6D8E5591-6788-4D2D-9FE6-596D5157C3C2}']
function GetCanvas: TCanvas;
property Canvas: TCanvas read GetCanvas;
end;
TChartColorToFPColorFunc = function (AColor: TChartColor): TFPColor;
{ IChartDrawer }
@ -143,54 +137,8 @@ type
function TextOut: TChartTextOut;
end;
{ TCanvasDrawer }
TCanvasDrawer = class(
TBasicDrawer, IChartDrawer, IChartTCanvasDrawer)
private
FCanvas: TCanvas;
procedure SetBrush(ABrush: TFPCustomBrush);
procedure SetFont(AFont: TFPCustomFont);
procedure SetPen(APen: TFPCustomPen);
strict protected
function GetFontAngle: Double; 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;
procedure Line(AX1, AY1, AX2, AY2: Integer);
procedure Line(const AP1, AP2: TPoint);
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;
procedure Polyline(
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;
AStartAngle16Deg, AAngleLength16Deg: Integer);
procedure Rectangle(const ARect: TRect);
procedure Rectangle(AX1, AY1, AX2, AY2: Integer);
procedure SetBrushColor(AColor: TChartColor);
procedure SetBrushParams(AStyle: TFPBrushStyle; AColor: TChartColor);
procedure SetPenParams(AStyle: TFPPenStyle; AColor: TChartColor);
end;
function ChartColorSysToFPColor(AChartColor: TChartColor): TFPColor;
function ChartColorToFPColor(AChartColor: TChartColor): TFPColor;
function FPColorToChartColor(AFPColor: TFPColor): TChartColor;
procedure PrepareXorPen(ACanvas: TCanvas);
implementation
@ -200,11 +148,6 @@ uses
const
LINE_INTERVAL = 2;
function ChartColorSysToFPColor(AChartColor: TChartColor): TFPColor;
begin
Result := ChartColorToFPColor(ColorToRGB(AChartColor));
end;
function ChartColorToFPColor(AChartColor: TChartColor): TFPColor;
begin
with Result do begin
@ -226,17 +169,6 @@ begin
((AFPColor.blue shl 8) and $FF0000);
end;
procedure PrepareXorPen(ACanvas: TCanvas);
begin
with ACanvas do begin
Brush.Style := bsClear;
Pen.Style := psSolid;
Pen.Mode := pmXor;
Pen.Color := clWhite;
Pen.Width := 1;
end;
end;
{ TChartTextOut }
function TChartTextOut.Alignment(AAlignment: TAlignment): TChartTextOut;
@ -397,170 +329,5 @@ begin
Result := TChartTextOut.Create(Self);
end;
{ TCanvasDrawer }
procedure TCanvasDrawer.AddToFontOrientation(ADelta: Integer);
begin
with FCanvas.Font do
Orientation := Orientation + ADelta;
end;
procedure TCanvasDrawer.ClippingStart(const AClipRect: TRect);
begin
FCanvas.ClipRect := AClipRect;
FCanvas.Clipping := true;
end;
procedure TCanvasDrawer.ClippingStart;
begin
FCanvas.Clipping := true;
end;
procedure TCanvasDrawer.ClippingStop;
begin
FCanvas.Clipping := false;
end;
constructor TCanvasDrawer.Create(ACanvas: TCanvas);
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);
end;
function TCanvasDrawer.GetBrushColor: TChartColor;
begin
Result := FCanvas.Brush.Color;
end;
function TCanvasDrawer.GetCanvas: TCanvas;
begin
Result := FCanvas;
end;
function TCanvasDrawer.GetFontAngle: Double;
begin
Result := OrientToRad(FCanvas.Font.Orientation);
end;
procedure TCanvasDrawer.Line(AX1, AY1, AX2, AY2: Integer);
begin
FCanvas.Line(AX1, AY1, AX2, AY2);
end;
procedure TCanvasDrawer.Line(const AP1, AP2: TPoint);
begin
FCanvas.Line(AP1, AP2);
end;
procedure TCanvasDrawer.LineTo(AX, AY: Integer);
begin
FCanvas.LineTo(AX, AY);
end;
procedure TCanvasDrawer.MoveTo(AX, AY: Integer);
begin
FCanvas.MoveTo(AX, AY);
end;
procedure TCanvasDrawer.Polygon(
const APoints: array of TPoint; AStartIndex, ANumPts: Integer);
begin
FCanvas.Polygon(APoints, false, AStartIndex, ANumPts);
end;
procedure TCanvasDrawer.Polyline(
const APoints: array of TPoint; AStartIndex, ANumPts: Integer;
AEndPoint: Boolean);
begin
FCanvas.Polyline(APoints, AStartIndex, ANumPts);
if AEndPoint then begin
if ANumPts < 0 then
ANumPts := Length(APoints);
// Polyline does not draw the end point.
with APoints[ANumPts - 1] do
FCanvas.Pixels[X, Y] := FCanvas.Pen.Color;
end;
end;
procedure TCanvasDrawer.PrepareSimplePen(AColor: TChartColor);
begin
with FCanvas.Pen do begin
Color := AColor;
Style := psSolid;
Mode := pmCopy;
Width := 1;
end;
end;
procedure TCanvasDrawer.RadialPie(
AX1, AY1, AX2, AY2: Integer;
AStartAngle16Deg, AAngleLength16Deg: Integer);
begin
FCanvas.RadialPie(
AX1, AY1, AX2, AY2, AStartAngle16Deg, AAngleLength16Deg);
end;
procedure TCanvasDrawer.Rectangle(AX1, AY1, AX2, AY2: Integer);
begin
FCanvas.Rectangle(AX1, AY1, AX2, AY2);
end;
procedure TCanvasDrawer.Rectangle(const ARect: TRect);
begin
FCanvas.Rectangle(ARect);
end;
procedure TCanvasDrawer.SetBrush(ABrush: TFPCustomBrush);
begin
FCanvas.Brush.Assign(ABrush);
end;
procedure TCanvasDrawer.SetBrushColor(AColor: TChartColor);
begin
FCanvas.Brush.Color := AColor;
end;
procedure TCanvasDrawer.SetBrushParams(
AStyle: TFPBrushStyle; AColor: TChartColor);
begin
FCanvas.Brush.Style := AStyle;
FCanvas.Brush.Color := AColor;
end;
procedure TCanvasDrawer.SetFont(AFont: TFPCustomFont);
begin
FCanvas.Font.Assign(AFont);
end;
procedure TCanvasDrawer.SetPen(APen: TFPCustomPen);
begin
FCanvas.Pen.Assign(APen);
end;
procedure TCanvasDrawer.SetPenParams(AStyle: TFPPenStyle; AColor: TChartColor);
begin
FCanvas.Pen.Style := AStyle;
FCanvas.Pen.Color := AColor;
end;
function TCanvasDrawer.SimpleTextExtent(const AText: String): TPoint;
begin
Result := FCanvas.TextExtent(AText);
end;
procedure TCanvasDrawer.SimpleTextOut(AX, AY: Integer; const AText: String);
begin
FCanvas.TextOut(AX, AY, AText);
end;
end.

View File

@ -375,7 +375,8 @@ var
implementation
uses
Clipbrd, Dialogs, GraphMath, LCLProc, LResources, Math, TAGeometry, Types;
Clipbrd, Dialogs, GraphMath, LCLProc, LResources, Math, TADrawerCanvas,
TAGeometry, Types;
function CompareZPosition(AItem1, AItem2: Pointer): Integer;
begin

View File

@ -189,7 +189,7 @@ type
implementation
uses
Math, PropEdits, Types;
Math, PropEdits, Types, TADrawerCanvas;
const
SYMBOL_TEXT_SPACING = 4;

View File

@ -312,7 +312,7 @@ implementation
uses
GraphMath, LResources, Math, PropEdits, SysUtils,
TAGeometry, TAGraph;
TADrawerCanvas, TAGeometry, TAGraph;
{ TLineSeries }

View File

@ -327,7 +327,7 @@ implementation
uses
ComponentEditors, Forms, GraphMath, Math, PropEdits, SysUtils,
TACustomSeries, TADrawUtils, TAGeometry, TASubcomponentsEditor;
TACustomSeries, TADrawerCanvas, TAGeometry, TASubcomponentsEditor;
type
{ TToolsComponentEditor }