TAChart: Replace IChartDrawer.SetXorPen with SetXor

git-svn-id: trunk@38435 -
This commit is contained in:
ask 2012-08-30 06:17:47 +00:00
parent 3192129e6e
commit 593695c6b5
5 changed files with 59 additions and 60 deletions

View File

@ -199,31 +199,10 @@ var
a: Double;
procedure DrawPointer(APointer: TDataPointDistanceToolPointer; APos: TPoint);
var
oldMode: TFPPenMode;
oldColor: TColor;
oldStyle: TFPBrushStyle;
begin
with APointer do begin
if not Visible then exit;
if EffectiveDrawingMode = tdmXor then begin
oldMode := Pen.Mode;
oldColor := Pen.Color;
oldStyle := Brush.Style;
Pen.Mode := pmXor;
Pen.Color := clWhite;
Brush.Style := bsClear;
end;
try
with APointer do
if Visible then
DrawSize(FChart.Drawer, APos, Point(HorizSize, VertSize), clTAColor, a);
finally
if EffectiveDrawingMode = tdmXor then begin
Pen.Mode := oldMode;
Pen.Color := oldColor;
Brush.Style := oldStyle;
end;
end;
end;
end;
var
@ -237,8 +216,10 @@ begin
cdmOnlyY: p2.X := p1.X;
end;
if p1 = p2 then exit;
if LinePen.Visible then
if LinePen.Visible then begin
FChart.Drawer.Pen := LinePen;
FChart.Drawer.Line(p1, p2);
end;
a := ArcTan2(p2.Y - p1.Y, p2.X - p1.X);
DrawPointer(PointerStart, p1);
DrawPointer(PointerEnd, p2);
@ -326,8 +307,9 @@ begin
FreeAndNil(newEnd);
end;
if EffectiveDrawingMode = tdmXor then begin
FChart.Drawer.SetXorPen(FPen);
FChart.Drawer.SetXor(true);
DoDraw;
FChart.Drawer.SetXor(false);
end;
Handled;
end;

View File

@ -34,7 +34,7 @@ type
TCanvasDrawer = class(
TBasicDrawer, IChartDrawer, IChartTCanvasDrawer)
private
strict private
procedure SetBrush(ABrush: TFPCustomBrush);
procedure SetFont(AFont: TFPCustomFont);
procedure SetPen(APen: TFPCustomPen);
@ -71,7 +71,6 @@ type
procedure SetBrushColor(AColor: TChartColor);
procedure SetBrushParams(AStyle: TFPBrushStyle; AColor: TChartColor);
procedure SetPenParams(AStyle: TFPPenStyle; AColor: TChartColor);
procedure SetXorPen(APen: TFPCustomPen);
end;
function CanvasGetFontOrientationFunc(AFont: TFPCustomFont): Integer;
@ -212,9 +211,15 @@ end;
procedure TCanvasDrawer.PrepareSimplePen(AColor: TChartColor);
begin
with FCanvas.Pen do begin
Color := AColor;
if FXor then
Color := clWhite
else
Color := AColor;
Style := psSolid;
Mode := pmCopy;
if FXor then
Mode := pmXor
else
Mode := pmCopy;
Width := 1;
end;
end;
@ -245,6 +250,8 @@ end;
procedure TCanvasDrawer.SetBrush(ABrush: TFPCustomBrush);
begin
FCanvas.Brush.Assign(ABrush);
if FXor then
FCanvas.Brush.Style := bsClear;
end;
procedure TCanvasDrawer.SetBrushColor(AColor: TChartColor);
@ -266,27 +273,29 @@ end;
procedure TCanvasDrawer.SetPen(APen: TFPCustomPen);
begin
FCanvas.Pen.Assign(APen);
if FXor then
with FCanvas do begin
Brush.Style := bsClear;
if APen = nil then
Pen.Style := psSolid
else
Pen.Style := APen.Style;
Pen.Mode := pmXor;
Pen.Color := clWhite;
if APen = nil then
Pen.Width := 1
else
Pen.Width := APen.Width;
end
else
FCanvas.Pen.Assign(APen);
end;
procedure TCanvasDrawer.SetPenParams(AStyle: TFPPenStyle; AColor: TChartColor);
begin
FCanvas.Pen.Style := AStyle;
FCanvas.Pen.Color := AColor;
end;
procedure TCanvasDrawer.SetXorPen(APen: TFPCustomPen);
begin
with FCanvas do begin
Brush.Style := bsClear;
Pen.Style := psSolid;
Pen.Mode := pmXor;
Pen.Color := clWhite;
if APen = nil then
Pen.Width := 1
else
Pen.Width := APen.Width;
end;
if not FXor then
FCanvas.Pen.Color := AColor;
end;
function TCanvasDrawer.SimpleTextExtent(const AText: String): TPoint;

View File

@ -103,7 +103,7 @@ type
procedure SetGetFontOrientationFunc(AValue: TGetFontOrientationFunc);
procedure SetPen(APen: TFPCustomPen);
procedure SetPenParams(AStyle: TFPPenStyle; AColor: TChartColor);
procedure SetXorPen(APen: TFPCustomPen);
procedure SetXor(AXor: Boolean);
function TextExtent(const AText: String): TPoint;
function TextExtent(AText: TStrings): TPoint;
function TextOut: TChartTextOut;
@ -124,6 +124,7 @@ type
strict protected
FChartColorToFPColorFunc: TChartColorToFPColorFunc;
FGetFontOrientationFunc: TGetFontOrientationFunc;
FXor: Boolean;
function GetFontAngle: Double; virtual; abstract;
function SimpleTextExtent(const AText: String): TPoint; virtual; abstract;
procedure SimpleTextOut(AX, AY: Integer; const AText: String); virtual; abstract;
@ -143,7 +144,7 @@ type
procedure SetAntialiasingMode(AValue: TChartAntialiasingMode);
procedure SetDoChartColorToFPColorFunc(AValue: TChartColorToFPColorFunc);
procedure SetGetFontOrientationFunc(AValue: TGetFontOrientationFunc);
procedure SetXorPen(APen: TFPCustomPen);
procedure SetXor(AXor: Boolean);
function TextExtent(const AText: String): TPoint;
function TextExtent(AText: TStrings): TPoint;
function TextOut: TChartTextOut;
@ -343,9 +344,9 @@ begin
FGetFontOrientationFunc := AValue;
end;
procedure TBasicDrawer.SetXorPen(APen: TFPCustomPen);
procedure TBasicDrawer.SetXor(AXor: Boolean);
begin
Unused(APen);
FXor := AXor;
end;
function TBasicDrawer.TextExtent(const AText: String): TPoint;

View File

@ -837,11 +837,13 @@ end;
procedure TChart.DrawReticule(ADrawer: IChartDrawer);
begin
ADrawer.SetXorPen(nil);
ADrawer.SetXor(true);
ADrawer.PrepareSimplePen(clTAColor);
if ReticuleMode in [rmVertical, rmCross] then
DrawLineVert(ADrawer, FReticulePos.X);
if ReticuleMode in [rmHorizontal, rmCross] then
DrawLineHoriz(ADrawer, FReticulePos.Y);
ADrawer.SetXor(false);
end;
procedure TChart.EnableRedrawing;

View File

@ -748,10 +748,8 @@ end;
procedure TChartTool.PrepareDrawingModePen(
ADrawer: IChartDrawer; APen: TFPCustomPen);
begin
case EffectiveDrawingMode of
tdmXor: ADrawer.SetXorPen(APen);
tdmNormal: ADrawer.Pen := APen;
end;
ADrawer.SetXor(EffectiveDrawingMode = tdmXor);
ADrawer.Pen := APen;
end;
procedure TChartTool.ReadState(Reader: TReader);
@ -1009,7 +1007,8 @@ begin
if not IsActive or IsAnimating then exit;
inherited;
PrepareDrawingModePen(ADrawer, Frame);
FChart.Drawer.Rectangle(FSelectionRect);
ADrawer.Rectangle(FSelectionRect);
ADrawer.SetXor(false);
end;
function TZoomDragTool.GetProportional: Boolean;
@ -1031,10 +1030,12 @@ begin
if not IsActive or IsAnimating then exit;
case EffectiveDrawingMode of
tdmXor: with FChart.Drawer do begin
SetXorPen(Frame);
SetXor(true);
Pen := Frame;
Rectangle(FSelectionRect);
FSelectionRect.BottomRight := APoint;
Rectangle(FSelectionRect);
SetXor(false);
end;
tdmNormal: begin
FSelectionRect.BottomRight := APoint;
@ -1090,8 +1091,8 @@ var
begin
Unused(APoint);
FChart.Drawer.SetXorPen(Frame);
FChart.Drawer.Rectangle(FSelectionRect);
if EffectiveDrawingMode = tdmXor then
Draw(FChart, FChart.Drawer);
with FSelectionRect do begin
dragDir := DRAG_DIR[Sign(Right - Left), Sign(Bottom - Top)];
if
@ -1637,8 +1638,9 @@ procedure TDataPointDrawTool.DoHide;
begin
case EffectiveDrawingMode of
tdmXor: begin
FChart.Drawer.SetXorPen(FPen);
FChart.Drawer.SetXor(true);
DoDraw;
FChart.Drawer.SetXor(false);
end;
tdmNormal:
FChart.StyleChanged(Self);
@ -1650,6 +1652,7 @@ begin
inherited;
PrepareDrawingModePen(ADrawer, FPen);
DoDraw;
ADrawer.SetXor(false);
end;
procedure TDataPointDrawTool.Hide;
@ -1680,6 +1683,7 @@ procedure TDataPointCrosshairTool.DoDraw;
var
p: TPoint;
begin
FChart.Drawer.Pen := CrosshairPen;
p := FChart.GraphToImage(Position);
if Shape in [ccsVertical, ccsCross] then
if Size < 0 then
@ -1714,8 +1718,9 @@ begin
if FSeries = nil then exit;
FPosition := FNearestGraphPoint;
if EffectiveDrawingMode = tdmXor then begin
FChart.Drawer.SetXorPen(FPen);
FChart.Drawer.SetXor(true);
DoDraw;
FChart.Drawer.SetXor(false);
end;
end;