mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-09 20:28:19 +02:00
TAChart: Replace IChartDrawer.HasCanvas/GetCanvas with a separate IChartTCanvasDrawer interface
git-svn-id: trunk@29943 -
This commit is contained in:
parent
127376bc5f
commit
a4d4972a0a
@ -20,7 +20,7 @@ unit TADrawerAggPas;
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, FPCanvas, Graphics, Agg_LCL, TADrawUtils;
|
||||
Classes, SysUtils, FPCanvas, Agg_LCL, TADrawUtils;
|
||||
|
||||
type
|
||||
|
||||
@ -46,8 +46,6 @@ type
|
||||
procedure Ellipse(AX1, AY1, AX2, AY2: Integer);
|
||||
procedure FillRect(AX1, AY1, AX2, AY2: Integer);
|
||||
function GetBrushColor: TChartColor;
|
||||
function GetCanvas: TCanvas;
|
||||
function HasCanvas: Boolean;
|
||||
procedure Line(AX1, AY1, AX2, AY2: Integer);
|
||||
procedure Line(const AP1, AP2: TPoint);
|
||||
procedure LineTo(AX, AY: Integer); override;
|
||||
@ -72,7 +70,7 @@ type
|
||||
implementation
|
||||
|
||||
uses
|
||||
Math, TAChartUtils, TAGeometry;
|
||||
Math, Graphics, TAChartUtils, TAGeometry;
|
||||
|
||||
{ TAggPasDrawer }
|
||||
|
||||
@ -118,22 +116,11 @@ begin
|
||||
Result := FCanvas.Brush.Color;
|
||||
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);
|
||||
|
@ -20,7 +20,7 @@ unit TADrawerOpenGL;
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, FPCanvas, Graphics, OpenGLContext, GL, GLu, Glut,
|
||||
Classes, SysUtils, FPCanvas, OpenGLContext, GL, GLu, Glut,
|
||||
TADrawUtils;
|
||||
|
||||
type
|
||||
@ -53,8 +53,6 @@ type
|
||||
procedure Ellipse(AX1, AY1, AX2, AY2: Integer);
|
||||
procedure FillRect(AX1, AY1, AX2, AY2: Integer);
|
||||
function GetBrushColor: TChartColor;
|
||||
function GetCanvas: TCanvas;
|
||||
function HasCanvas: Boolean;
|
||||
procedure Line(AX1, AY1, AX2, AY2: Integer);
|
||||
procedure Line(const AP1, AP2: TPoint);
|
||||
procedure LineTo(AX, AY: Integer); override;
|
||||
@ -78,7 +76,7 @@ type
|
||||
implementation
|
||||
|
||||
uses
|
||||
TAChartUtils;
|
||||
Graphics, TAChartUtils;
|
||||
|
||||
procedure ChartGLColor(AColor: TChartColor);
|
||||
var
|
||||
@ -132,21 +130,11 @@ begin
|
||||
Result := FBrushColor;
|
||||
end;
|
||||
|
||||
function TOpenGLDrawer.GetCanvas: TCanvas;
|
||||
begin
|
||||
Result := nil;
|
||||
end;
|
||||
|
||||
function TOpenGLDrawer.GetFontAngle: Double;
|
||||
begin
|
||||
Result := 0.0;
|
||||
end;
|
||||
|
||||
function TOpenGLDrawer.HasCanvas: Boolean;
|
||||
begin
|
||||
Result := false;
|
||||
end;
|
||||
|
||||
procedure TOpenGLDrawer.InternalPolyline(
|
||||
const APoints: array of TPoint; AStartIndex, ANumPts, AMode: Integer);
|
||||
var
|
||||
|
@ -64,6 +64,12 @@ type
|
||||
function Width(AWidth: Integer): TChartTextOut;
|
||||
end;
|
||||
|
||||
IChartTCanvasDrawer = interface
|
||||
['{6D8E5591-6788-4D2D-9FE6-596D5157C3C2}']
|
||||
function GetCanvas: TCanvas;
|
||||
property Canvas: TCanvas read GetCanvas;
|
||||
end;
|
||||
|
||||
{ IChartDrawer }
|
||||
|
||||
IChartDrawer = interface
|
||||
@ -76,8 +82,6 @@ type
|
||||
procedure Ellipse(AX1, AY1, AX2, AY2: Integer);
|
||||
procedure FillRect(AX1, AY1, AX2, AY2: Integer);
|
||||
function GetBrushColor: TChartColor;
|
||||
function GetCanvas: TCanvas;
|
||||
function HasCanvas: Boolean;
|
||||
procedure Line(AX1, AY1, AX2, AY2: Integer);
|
||||
procedure Line(const AP1, AP2: TPoint);
|
||||
procedure LineTo(AX, AY: Integer);
|
||||
@ -109,7 +113,6 @@ type
|
||||
|
||||
property Brush: TFPCustomBrush write SetBrush;
|
||||
property BrushColor: TChartColor read GetBrushColor write SetBrushColor;
|
||||
property Canvas: TCanvas read GetCanvas;
|
||||
property Font: TFPCustomFont write SetFont;
|
||||
property Pen: TFPCustomPen write SetPen;
|
||||
end;
|
||||
@ -139,7 +142,8 @@ type
|
||||
|
||||
{ TCanvasDrawer }
|
||||
|
||||
TCanvasDrawer = class(TFPCanvasDrawer, IChartDrawer, ISimpleTextOut)
|
||||
TCanvasDrawer = class(
|
||||
TFPCanvasDrawer, IChartDrawer, IChartTCanvasDrawer, ISimpleTextOut)
|
||||
private
|
||||
FCanvas: TCanvas;
|
||||
procedure SetBrush(ABrush: TFPCustomBrush);
|
||||
@ -159,7 +163,6 @@ type
|
||||
procedure FillRect(AX1, AY1, AX2, AY2: Integer);
|
||||
function GetBrushColor: TChartColor;
|
||||
function GetCanvas: TCanvas;
|
||||
function HasCanvas: Boolean;
|
||||
procedure Line(AX1, AY1, AX2, AY2: Integer);
|
||||
procedure Line(const AP1, AP2: TPoint);
|
||||
procedure LineTo(AX, AY: Integer); override;
|
||||
@ -405,11 +408,6 @@ begin
|
||||
Result := OrientToRad(FCanvas.Font.Orientation);
|
||||
end;
|
||||
|
||||
function TCanvasDrawer.HasCanvas: Boolean;
|
||||
begin
|
||||
Result := true;
|
||||
end;
|
||||
|
||||
procedure TCanvasDrawer.Line(AX1, AY1, AX2, AY2: Integer);
|
||||
begin
|
||||
FCanvas.Line(AX1, AY1, AX2, AY2);
|
||||
@ -442,9 +440,9 @@ procedure TCanvasDrawer.Polyline(
|
||||
begin
|
||||
FCanvas.Polyline(APoints, AStartIndex, ANumPts);
|
||||
if AEndPoint then begin
|
||||
// Polyline does not draw the end point.
|
||||
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;
|
||||
|
@ -455,15 +455,16 @@ end;
|
||||
procedure TChart.Clear(ADrawer: IChartDrawer; const ARect: TRect);
|
||||
var
|
||||
defaultDrawing: Boolean = true;
|
||||
ic: IChartTCanvasDrawer;
|
||||
begin
|
||||
ADrawer.PrepareSimplePen(Color);
|
||||
ADrawer.SetBrushParams(bsSolid, Color);
|
||||
if ADrawer.HasCanvas and Assigned(OnBeforeDrawBackground) then
|
||||
OnBeforeDrawBackground(Self, ADrawer.Canvas, ARect, defaultDrawing);
|
||||
if Supports(ADrawer, IChartTCanvasDrawer, ic) and Assigned(OnBeforeDrawBackground) then
|
||||
OnBeforeDrawBackground(Self, ic.Canvas, ARect, defaultDrawing);
|
||||
if defaultDrawing then
|
||||
ADrawer.Rectangle(ARect);
|
||||
if ADrawer.HasCanvas and Assigned(OnAfterDrawBackground) then
|
||||
OnAfterDrawBackground(Self, ADrawer.Canvas, ARect);
|
||||
if Supports(ADrawer, IChartTCanvasDrawer, ic) and Assigned(OnAfterDrawBackground) then
|
||||
OnAfterDrawBackground(Self, ic.Canvas, ARect);
|
||||
end;
|
||||
|
||||
procedure TChart.ClearSeries;
|
||||
@ -701,9 +702,10 @@ end;
|
||||
procedure TChart.DrawBackWall(ADrawer: IChartDrawer);
|
||||
var
|
||||
defaultDrawing: Boolean = true;
|
||||
ic: IChartTCanvasDrawer;
|
||||
begin
|
||||
if ADrawer.HasCanvas and Assigned(OnBeforeDrawBackWall) then
|
||||
OnBeforeDrawBackWall(Self, ADrawer.Canvas, FClipRect, defaultDrawing);
|
||||
if Supports(ADrawer, IChartTCanvasDrawer, ic) and Assigned(OnBeforeDrawBackWall) then
|
||||
OnBeforeDrawBackWall(Self, ic.Canvas, FClipRect, defaultDrawing);
|
||||
if defaultDrawing then
|
||||
with ADrawer do begin
|
||||
if FFrame.Visible then
|
||||
@ -714,8 +716,8 @@ begin
|
||||
with FClipRect do
|
||||
Rectangle(Left, Top, Right + 1, Bottom + 1);
|
||||
end;
|
||||
if ADrawer.HasCanvas and Assigned(OnAfterDrawBackWall) then
|
||||
OnAfterDrawBackWall(Self, ADrawer.Canvas, FClipRect);
|
||||
if Supports(ADrawer, IChartTCanvasDrawer, ic) and Assigned(OnAfterDrawBackWall) then
|
||||
OnAfterDrawBackWall(Self, ic.Canvas, FClipRect);
|
||||
|
||||
// Z axis
|
||||
if (Depth > 0) and FFrame.Visible then begin
|
||||
@ -758,9 +760,11 @@ begin
|
||||
end;
|
||||
|
||||
procedure TChart.DrawReticule(ADrawer: IChartDrawer);
|
||||
var
|
||||
ic: IChartTCanvasDrawer;
|
||||
begin
|
||||
if not ADrawer.HasCanvas then exit;
|
||||
PrepareXorPen(ADrawer.Canvas);
|
||||
if not Supports(ADrawer, IChartTCanvasDrawer, ic) then exit;
|
||||
PrepareXorPen(ic.Canvas);
|
||||
if ReticuleMode in [rmVertical, rmCross] then
|
||||
DrawLineVert(ADrawer, FReticulePos.X);
|
||||
if ReticuleMode in [rmHorizontal, rmCross] then
|
||||
|
@ -219,9 +219,11 @@ begin
|
||||
end;
|
||||
|
||||
procedure TLegendItemUserDrawn.Draw(ADrawer: IChartDrawer; const ARect: TRect);
|
||||
var
|
||||
ic: IChartTCanvasDrawer;
|
||||
begin
|
||||
if ADrawer.HasCanvas and Assigned(FOnDraw) then
|
||||
FOnDraw(ADrawer.Canvas, ARect, FIndex, FText);
|
||||
if Supports(ADrawer, IChartTCanvasDrawer, ic) and Assigned(FOnDraw) then
|
||||
FOnDraw(ic.Canvas, ARect, FIndex, FText);
|
||||
inherited Draw(ADrawer, ARect);
|
||||
end;
|
||||
|
||||
|
@ -26,7 +26,7 @@ type
|
||||
|
||||
{ TPrinterDrawer }
|
||||
|
||||
TPrinterDrawer = class(TCanvasDrawer, IChartDrawer, ISimpleTextOut)
|
||||
TPrinterDrawer = class(TCanvasDrawer)
|
||||
private
|
||||
FPrinter: TPrinter;
|
||||
FCoeff: Double;
|
||||
|
@ -467,6 +467,7 @@ var
|
||||
i: Integer;
|
||||
ai: TPoint;
|
||||
p: TDoublePoint;
|
||||
ic: IChartTCanvasDrawer;
|
||||
begin
|
||||
DrawLines;
|
||||
DrawLabels(ADrawer);
|
||||
@ -477,8 +478,8 @@ begin
|
||||
if not ParentChart.IsPointInViewPort(p) then continue;
|
||||
ai := ParentChart.GraphToImage(p);
|
||||
FPointer.Draw(ADrawer, ai, Source[i]^.Color);
|
||||
if ADrawer.HasCanvas and Assigned(FOnDrawPointer) then
|
||||
FOnDrawPointer(Self, ADrawer.Canvas, i, ai);
|
||||
if Supports(ADrawer, IChartTCanvasDrawer, ic) and Assigned(FOnDrawPointer) then
|
||||
FOnDrawPointer(Self, ic.Canvas, i, ai);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -757,6 +758,7 @@ var
|
||||
sz: TSize;
|
||||
defaultDrawing: Boolean = true;
|
||||
c: TColor;
|
||||
ic: IChartTCanvasDrawer;
|
||||
begin
|
||||
ADrawer.Brush := BarBrush;
|
||||
ADrawer.Pen := BarPen;
|
||||
@ -771,9 +773,8 @@ var
|
||||
ADrawer.SetPenParams(psSolid, ADrawer.BrushColor);
|
||||
end;
|
||||
|
||||
if ADrawer.HasCanvas and Assigned(OnBeforeDrawBar) then
|
||||
OnBeforeDrawBar(
|
||||
Self, ADrawer.Canvas, AR, pointIndex, stackIndex, defaultDrawing);
|
||||
if Supports(ADrawer, IChartTCanvasDrawer, ic) and Assigned(OnBeforeDrawBar) then
|
||||
OnBeforeDrawBar(Self, ic.Canvas, AR, pointIndex, stackIndex, defaultDrawing);
|
||||
if not defaultDrawing then exit;
|
||||
|
||||
ADrawer.Rectangle(AR);
|
||||
@ -1177,9 +1178,11 @@ begin
|
||||
end;
|
||||
|
||||
procedure TUserDrawnSeries.Draw(ADrawer: IChartDrawer);
|
||||
var
|
||||
ic: IChartTCanvasDrawer;
|
||||
begin
|
||||
if ADrawer.HasCanvas and Assigned(FOnDraw) then
|
||||
FOnDraw(ADrawer.Canvas, FChart.ClipRect);
|
||||
if Supports(ADrawer, IChartTCanvasDrawer, ic) and Assigned(FOnDraw) then
|
||||
FOnDraw(ic.Canvas, FChart.ClipRect);
|
||||
end;
|
||||
|
||||
procedure TUserDrawnSeries.GetBounds(var ABounds: TDoubleRect);
|
||||
|
Loading…
Reference in New Issue
Block a user