diff --git a/.gitattributes b/.gitattributes index 39c9e5a731..1a7793d576 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/components/tachart/tachartlazaruspkg.lpk b/components/tachart/tachartlazaruspkg.lpk index 256085de6f..dbc9b0a31e 100644 --- a/components/tachart/tachartlazaruspkg.lpk +++ b/components/tachart/tachartlazaruspkg.lpk @@ -28,7 +28,7 @@ for details about the copyright. "/> - + @@ -130,6 +130,10 @@ + + + + diff --git a/components/tachart/tachartlazaruspkg.pas b/components/tachart/tachartlazaruspkg.pas index 98ebd89ee2..b5678c63f3 100644 --- a/components/tachart/tachartlazaruspkg.pas +++ b/components/tachart/tachartlazaruspkg.pas @@ -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 diff --git a/components/tachart/tadrawercanvas.pas b/components/tachart/tadrawercanvas.pas new file mode 100644 index 0000000000..b755505ff3 --- /dev/null +++ b/components/tachart/tadrawercanvas.pas @@ -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. + diff --git a/components/tachart/tadrawutils.pas b/components/tachart/tadrawutils.pas index 96296ba90a..50d2c2da67 100644 --- a/components/tachart/tadrawutils.pas +++ b/components/tachart/tadrawutils.pas @@ -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. diff --git a/components/tachart/tagraph.pas b/components/tachart/tagraph.pas index 19d6fdfc50..64f554e865 100644 --- a/components/tachart/tagraph.pas +++ b/components/tachart/tagraph.pas @@ -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 diff --git a/components/tachart/talegend.pas b/components/tachart/talegend.pas index 12f10a7bb2..bef1095471 100644 --- a/components/tachart/talegend.pas +++ b/components/tachart/talegend.pas @@ -189,7 +189,7 @@ type implementation uses - Math, PropEdits, Types; + Math, PropEdits, Types, TADrawerCanvas; const SYMBOL_TEXT_SPACING = 4; diff --git a/components/tachart/taseries.pas b/components/tachart/taseries.pas index f41fecfc78..a0d5d063d5 100644 --- a/components/tachart/taseries.pas +++ b/components/tachart/taseries.pas @@ -312,7 +312,7 @@ implementation uses GraphMath, LResources, Math, PropEdits, SysUtils, - TAGeometry, TAGraph; + TADrawerCanvas, TAGeometry, TAGraph; { TLineSeries } diff --git a/components/tachart/tatools.pas b/components/tachart/tatools.pas index 7c340d58d9..6b0e0f7831 100644 --- a/components/tachart/tatools.pas +++ b/components/tachart/tatools.pas @@ -327,7 +327,7 @@ implementation uses ComponentEditors, Forms, GraphMath, Math, PropEdits, SysUtils, - TACustomSeries, TADrawUtils, TAGeometry, TASubcomponentsEditor; + TACustomSeries, TADrawerCanvas, TAGeometry, TASubcomponentsEditor; type { TToolsComponentEditor }