From 7eff0c879be8ba362ca6ac3f48b992cbd26d592d Mon Sep 17 00:00:00 2001 From: ask Date: Sun, 20 Feb 2011 20:56:40 +0000 Subject: [PATCH] TAChart: Initial implementation of TAggPasDrawer git-svn-id: trunk@29620 - --- .gitattributes | 1 + components/tachart/tadraweraggpas.pas | 205 ++++++++++++++++++++++++++ 2 files changed, 206 insertions(+) create mode 100644 components/tachart/tadraweraggpas.pas diff --git a/.gitattributes b/.gitattributes index 4c0417f1f7..c812e3d823 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2385,6 +2385,7 @@ components/tachart/tachartutils.pas svneol=native#text/plain 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/tadrawutils.pas svneol=native#text/pascal components/tachart/tafuncseries.pas svneol=native#text/pascal components/tachart/tagraph.lrs svneol=native#text/pascal diff --git a/components/tachart/tadraweraggpas.pas b/components/tachart/tadraweraggpas.pas new file mode 100644 index 0000000000..0d93d3c6ec --- /dev/null +++ b/components/tachart/tadraweraggpas.pas @@ -0,0 +1,205 @@ +unit TADrawerAggPas; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, FPCanvas, Graphics, Agg_LCL, TADrawUtils; + +type + + { TAggPasDrawer } + + TAggPasDrawer = class(TFPCanvasDrawer, IChartDrawer, ISimpleTextOut) + strict private + FCanvas: TAggLCLCanvas; + procedure SetBrush(ABrush: TFPCustomBrush); + procedure SetFont(AFont: TFPCustomFont); + 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; + public + constructor Create(ACanvas: TAggLCLCanvas); + public + procedure AddToFontOrientation(ADelta: Integer); + procedure ClippingStart; + procedure ClippingStart(const AClipRect: TRect); + procedure ClippingStop; + procedure FillRect(AX1, AY1, AX2, AY2: Integer); + function GetCanvas: TCanvas; + function HasCanvas: Boolean; + procedure Line(AX1, AY1, AX2, AY2: Integer); + procedure Line(const AP1, AP2: TPoint); + procedure Polygon(const APoints: array of TPoint); + 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 SetBrushParams(AStyle: TFPBrushStyle; AColor: TChartColor); + procedure SetPenParams(AStyle: TFPPenStyle; AColor: TChartColor); + end; + +implementation + +uses + TAChartUtils; + +{ TAggPasDrawer } + +procedure TAggPasDrawer.AddToFontOrientation(ADelta: Integer); +begin + with FCanvas.Font do + AggAngle := AggAngle + OrientToRad(ADelta); +end; + +procedure TAggPasDrawer.ClippingStart(const AClipRect: TRect); +begin + FCanvas.ClipRect := AClipRect; + FCanvas.Clipping := true; +end; + +procedure TAggPasDrawer.ClippingStart; +begin + FCanvas.Clipping := true; +end; + +procedure TAggPasDrawer.ClippingStop; +begin + FCanvas.Clipping := false; +end; + +constructor TAggPasDrawer.Create(ACanvas: TAggLCLCanvas); +begin + FCanvas := ACanvas; +end; + +procedure TAggPasDrawer.FillRect(AX1, AY1, AX2, AY2: Integer); +begin + FCanvas.FillRect(AX1, AY1, AX2, AY2); +end; + +function TAggPasDrawer.GetCanvas: TCanvas; +begin + raise Exception.Create('TAggPasDrawer.GetCanvas'); + Result := nil; +end; + +function TAggPasDrawer.GetFontAngle: Double; +begin + Result := FCanvas.Font.AggAngle; +end; + +function TAggPasDrawer.HasCanvas: Boolean; +begin + Result := false; +end; + +procedure TAggPasDrawer.Line(AX1, AY1, AX2, AY2: Integer); +begin + FCanvas.Line(AX1, AY1, AX2, AY2); +end; + +procedure TAggPasDrawer.Line(const AP1, AP2: TPoint); +begin + FCanvas.Line(AP1, AP2); +end; + +procedure TAggPasDrawer.Polygon(const APoints: array of TPoint); +begin + FCanvas.Polygon(APoints, Length(APoints)); +end; + +procedure TAggPasDrawer.PrepareSimplePen(AColor: TChartColor); +begin + with FCanvas.Pen do begin + Color := AColor; + Style := psSolid; + Mode := pmCopy; + Width := 1; + end; +end; + +procedure TAggPasDrawer.RadialPie( + AX1, AY1, AX2, AY2: Integer; + AStartAngle16Deg, AAngleLength16Deg: Integer); +begin + FCanvas.RadialPie( + AX1, AY1, AX2, AY2, AStartAngle16Deg, AAngleLength16Deg); +end; + +procedure TAggPasDrawer.Rectangle(AX1, AY1, AX2, AY2: Integer); +begin + FCanvas.Rectangle(AX1, AY1, AX2, AY2); +end; + +procedure TAggPasDrawer.Rectangle(const ARect: TRect); +begin + FCanvas.Rectangle(ARect); +end; + +procedure TAggPasDrawer.SetBrush(ABrush: TFPCustomBrush); +begin + with FCanvas.Brush do begin + Style := ABrush.Style; + Image := ABrush.Image; + Pattern := ABrush.Pattern; + if ABrush is TBrush then + Color := (ABrush as TBrush).Color; + end; +end; + +procedure TAggPasDrawer.SetBrushParams( + AStyle: TFPBrushStyle; AColor: TChartColor); +begin + FCanvas.Brush.Style := AStyle; + FCanvas.Brush.Color := AColor; +end; + +procedure TAggPasDrawer.SetFont(AFont: TFPCustomFont); +var + f: TAggLCLFont; +begin + f := FCanvas.Font; + // This should be: FCanvas.Font.DoCopyProps(AFont); + f.LoadFromFile( + AFont.Name, f.SizeToAggHeight(AFont.Size), AFont.Bold, AFont.Italic); + if AFont is TFont then + with TFont(AFont) do begin + f.Color := Color; + f.AggAngle := OrientToRad(Orientation); + end; +end; + +type + TAggLCLPenCrack = class(TAggLCLPen); + +procedure TAggPasDrawer.SetPen(APen: TFPCustomPen); +begin + TAggLCLPenCrack(FCanvas.Pen).DoCopyProps(APen); + if APen is TPen then + FCanvas.Pen.Color := (APen as TPen).Color; +end; + +procedure TAggPasDrawer.SetPenParams(AStyle: TFPPenStyle; AColor: TChartColor); +begin + FCanvas.Pen.Style := AStyle; + FCanvas.Pen.Color := AColor; +end; + +function TAggPasDrawer.SimpleTextExtent(const AText: String): TPoint; +begin + Result := FCanvas.TextExtent(AText); +end; + +procedure TAggPasDrawer.SimpleTextOut(AX, AY: Integer; const AText: String); +begin + FCanvas.TextOut(AX, AY, AText); +end; + +end. +