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