TAChart: Add color conversion method to IChartDrawer

git-svn-id: trunk@29968 -
This commit is contained in:
ask 2011-03-21 14:25:39 +00:00
parent 2c1e9b1a49
commit 20a6203533
3 changed files with 29 additions and 9 deletions

View File

@ -48,6 +48,7 @@ begin
glLoadIdentity();
d := TOpenGLDrawer.Create;
d.DoChartColorToFPColor := @ChartColorSysToFPColor;
Chart1.DisableRedrawing;
Chart1.Title.Text.Text := 'OpenGL';
Chart1.Draw(d, Rect(0, 0, OpenGLControl1.Width, OpenGLControl1.Height));

View File

@ -42,8 +42,6 @@ type
function GetFontAngle: Double; override;
function SimpleTextExtent(const AText: String): TPoint; override;
procedure SimpleTextOut(AX, AY: Integer; const AText: String); override;
public
constructor Create;
public
procedure AddToFontOrientation(ADelta: Integer);
procedure ClippingStart;
@ -129,10 +127,6 @@ begin
glDisable(GL_CLIP_PLANE3);
end;
constructor TOpenGLDrawer.Create;
begin
end;
procedure TOpenGLDrawer.Ellipse(AX1, AY1, AX2, AY2: Integer);
begin
Unused(AX1, AY1);
@ -222,7 +216,7 @@ end;
procedure TOpenGLDrawer.PrepareSimplePen(AColor: TChartColor);
begin
FPenWidth := 1;
FPenColor := ChartColorToFPColor(AColor);
FPenColor := FChartColorToFPColorFunc(AColor);
end;
procedure TOpenGLDrawer.RadialPie(
@ -259,7 +253,7 @@ end;
procedure TOpenGLDrawer.SetBrushColor(AColor: TChartColor);
begin
FBrushColor := ChartColorToFPColor(AColor);
FBrushColor := FChartColorToFPColorFunc(AColor);
end;
procedure TOpenGLDrawer.SetBrushParams(
@ -283,7 +277,7 @@ end;
procedure TOpenGLDrawer.SetPenParams(AStyle: TFPPenStyle; AColor: TChartColor);
begin
Unused(AStyle);
FPenColor := ChartColorToFPColor(AColor);
FPenColor := FChartColorToFPColorFunc(AColor);
end;
function TOpenGLDrawer.SimpleTextExtent(const AText: String): TPoint;

View File

@ -65,6 +65,8 @@ type
property Canvas: TCanvas read GetCanvas;
end;
TChartColorToFPColorFunc = function (AColor: TChartColor): TFPColor;
{ IChartDrawer }
IChartDrawer = interface
@ -77,6 +79,7 @@ type
procedure Ellipse(AX1, AY1, AX2, AY2: Integer);
procedure FillRect(AX1, AY1, AX2, AY2: Integer);
function GetBrushColor: TChartColor;
procedure SetDoChartColorToFPColorFunc(AValue: TChartColorToFPColorFunc);
procedure Line(AX1, AY1, AX2, AY2: Integer);
procedure Line(const AP1, AP2: TPoint);
procedure LineTo(AX, AY: Integer);
@ -110,16 +113,20 @@ type
property BrushColor: TChartColor read GetBrushColor write SetBrushColor;
property Font: TFPCustomFont write SetFont;
property Pen: TFPCustomPen write SetPen;
property DoChartColorToFPColor: TChartColorToFPColorFunc
write SetDoChartColorToFPColorFunc;
end;
{ TBasicDrawer }
TBasicDrawer = class(TInterfacedObject, ISimpleTextOut)
strict protected
FChartColorToFPColorFunc: TChartColorToFPColorFunc;
function GetFontAngle: Double; virtual; abstract;
function SimpleTextExtent(const AText: String): TPoint; virtual; abstract;
procedure SimpleTextOut(AX, AY: Integer; const AText: String); virtual; abstract;
public
constructor Create;
procedure DrawLineDepth(AX1, AY1, AX2, AY2, ADepth: Integer);
procedure DrawLineDepth(const AP1, AP2: TPoint; ADepth: Integer);
procedure LineTo(AX, AY: Integer); virtual; abstract;
@ -130,6 +137,7 @@ type
const APoints: array of TPoint;
AStartIndex: Integer = 0; ANumPts: Integer = -1); virtual; abstract;
function Scale(ADistance: Integer): Integer; virtual;
procedure SetDoChartColorToFPColorFunc(AValue: TChartColorToFPColorFunc);
function TextExtent(const AText: String): TPoint;
function TextExtent(AText: TStrings): TPoint;
function TextOut: TChartTextOut;
@ -179,6 +187,7 @@ type
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);
@ -191,6 +200,11 @@ 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
@ -312,6 +326,11 @@ end;
{ TBasicDrawer }
constructor TBasicDrawer.Create;
begin
FChartColorToFPColorFunc := @ChartColorToFPColor;
end;
procedure TBasicDrawer.DrawLineDepth(AX1, AY1, AX2, AY2, ADepth: Integer);
begin
DrawLineDepth(Point(AX1, AY1), Point(AX2, AY2), ADepth);
@ -340,6 +359,12 @@ begin
Result := ADistance;
end;
procedure TBasicDrawer.SetDoChartColorToFPColorFunc(
AValue: TChartColorToFPColorFunc);
begin
FChartColorToFPColorFunc := AValue;
end;
function TBasicDrawer.TextExtent(const AText: String): TPoint;
var
sl: TStrings;