Implements using brush and pen in fpvtocanvas and updates the standard state of pen and brush for various objects

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1666 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
sekelsenmat
2011-06-08 06:14:37 +00:00
parent b381033113
commit be3e53b19f
2 changed files with 60 additions and 7 deletions

View File

@ -65,6 +65,7 @@ const
FPValphaOpaque = $FF; FPValphaOpaque = $FF;
clvBlack: TvColor = (Red: $00; Green: $00; Blue: $00; Alpha: FPValphaOpaque); clvBlack: TvColor = (Red: $00; Green: $00; Blue: $00; Alpha: FPValphaOpaque);
clvBlue: TvColor = (Red: $00; Green: $00; Blue: $FF; Alpha: FPValphaOpaque);
type type
T3DPoint = record T3DPoint = record
@ -169,10 +170,14 @@ type
{@@ {@@
} }
{ TvEntity }
TvEntity = class TvEntity = class
public public
Pen: TvPen; Pen: TvPen;
Brush: TvBrush; Brush: TvBrush;
constructor Create; virtual;
end; end;
{@@ {@@
@ -446,6 +451,16 @@ begin
Result.Z := 0; Result.Z := 0;
end; end;
{ TvEntity }
constructor TvEntity.Create;
begin
Pen.Style := psSolid;
Pen.Color := clvBlack;
Brush.Style := bsClear;
Brush.Color := clvBlue;
end;
{ TvEllipse } { TvEllipse }
procedure TvEllipse.CalculateBoundingRectangle; procedure TvEllipse.CalculateBoundingRectangle;
@ -855,6 +870,10 @@ begin
FTmpPath.Points := nil; FTmpPath.Points := nil;
FTmpPath.PointsEnd := nil; FTmpPath.PointsEnd := nil;
FTmpPath.Len := 0; FTmpPath.Len := 0;
FTmpPath.Brush.Color := clvBlue;
FTmpPath.Brush.Style := bsClear;
FTmpPath.Pen.Color := clvBlack;
FTmpPath.Pen.Style := psSolid;
end; end;
procedure TvVectorialDocument.AppendSegmentToTmpPath(ASegment: TPathSegment); procedure TvVectorialDocument.AppendSegmentToTmpPath(ASegment: TPathSegment);

View File

@ -42,6 +42,11 @@ begin
end; end;
{$endif} {$endif}
function VColorToFPColor(AVColor: TvColor): TFPColor; inline;
begin
Result := FPColor(AVColor.Red*$100, AVColor.Green*$100, AVColor.Blue*$100);
end;
function Rotate2DPoint(P,Fix :TPoint; alpha:double): TPoint; function Rotate2DPoint(P,Fix :TPoint; alpha:double): TPoint;
var var
sinus, cosinus : Extended; sinus, cosinus : Extended;
@ -142,6 +147,7 @@ procedure DrawFPVPathsToCanvas(ASource: TvVectorialDocument;
var var
i, j, k: Integer; i, j, k: Integer;
PosX, PosY: Integer; // Not modified by ADestX, etc PosX, PosY: Integer; // Not modified by ADestX, etc
CurPath: TPath;
CurSegment: TPathSegment; CurSegment: TPathSegment;
Cur2DSegment: T2DSegment absolute CurSegment; Cur2DSegment: T2DSegment absolute CurSegment;
Cur2DBSegment: T2DBezierSegment absolute CurSegment; Cur2DBSegment: T2DBezierSegment absolute CurSegment;
@ -160,16 +166,28 @@ begin
for i := 0 to ASource.PathCount - 1 do for i := 0 to ASource.PathCount - 1 do
begin begin
//WriteLn('i = ', i); //WriteLn('i = ', i);
ASource.Paths[i].PrepareForSequentialReading; CurPath := ASource.Paths[i];
CurPath.PrepareForSequentialReading;
// Set the path Pen and Brush options
ADest.Pen.Style := CurPath.Pen.Style;
ADest.Brush.Style := CurPath.Brush.Style;
{$ifdef USE_LCL_CANVAS}
ADest.Pen.Color := VColorToTColor(CurPath.Pen.Color);
ADest.Brush.Color := VColorToTColor(CurPath.Brush.Color);
{$else}
ADest.Pen.FPColor := VColorToFPColor(CurPath.Pen.Color);
ADest.Brush.FPColor := VColorToFPColor(CurPath.Brush.Color);
{$endif}
{$ifdef FPVECTORIAL_TOCANVAS_DEBUG} {$ifdef FPVECTORIAL_TOCANVAS_DEBUG}
Write(Format('[Path] ID=%d', [i])); Write(Format('[Path] ID=%d', [i]));
{$endif} {$endif}
for j := 0 to ASource.Paths[i].Len - 1 do for j := 0 to CurPath.Len - 1 do
begin begin
//WriteLn('j = ', j); //WriteLn('j = ', j);
CurSegment := TPathSegment(ASource.Paths[i].Next()); CurSegment := TPathSegment(CurPath.Next());
case CurSegment.SegmentType of case CurSegment.SegmentType of
stMoveTo: stMoveTo:
@ -179,11 +197,18 @@ begin
Write(Format(' M%d,%d', [CoordToCanvasX(Cur2DSegment.X), CoordToCanvasY(Cur2DSegment.Y)])); Write(Format(' M%d,%d', [CoordToCanvasX(Cur2DSegment.X), CoordToCanvasY(Cur2DSegment.Y)]));
{$endif} {$endif}
end; end;
// This element can override temporarely the Pen
st2DLineWithPen: st2DLineWithPen:
begin begin
{$ifdef USE_LCL_CANVAS}ADest.Pen.Color := VColorToTColor(T2DSegmentWithPen(Cur2DSegment).Pen.Color);{$endif} {$ifdef USE_LCL_CANVAS}
ADest.Pen.Color := VColorToTColor(T2DSegmentWithPen(Cur2DSegment).Pen.Color);
{$endif}
ADest.LineTo(CoordToCanvasX(Cur2DSegment.X), CoordToCanvasY(Cur2DSegment.Y)); ADest.LineTo(CoordToCanvasX(Cur2DSegment.X), CoordToCanvasY(Cur2DSegment.Y));
{$ifdef USE_LCL_CANVAS}ADest.Pen.Color := clBlack;{$endif}
{$ifdef USE_LCL_CANVAS}
ADest.Pen.Color := VColorToTColor(CurPath.Pen.Color);
{$endif}
{$ifdef FPVECTORIAL_TOCANVAS_DEBUG} {$ifdef FPVECTORIAL_TOCANVAS_DEBUG}
Write(Format(' L%d,%d', [CoordToCanvasX(Cur2DSegment.X), CoordToCanvasY(Cur2DSegment.Y)])); Write(Format(' L%d,%d', [CoordToCanvasX(Cur2DSegment.X), CoordToCanvasY(Cur2DSegment.Y)]));
{$endif} {$endif}
@ -252,12 +277,21 @@ var
Points: array of TPoint; Points: array of TPoint;
UpperDim, LowerDim: T3DPoint; UpperDim, LowerDim: T3DPoint;
begin begin
ADest.Brush.Style := bsClear;
// Draws all entities // Draws all entities
for i := 0 to ASource.GetEntityCount - 1 do for i := 0 to ASource.GetEntityCount - 1 do
begin begin
CurEntity := ASource.GetEntity(i); CurEntity := ASource.GetEntity(i);
ADest.Brush.Style := CurEntity.Brush.Style;
ADest.Pen.Style := CurEntity.Pen.Style;
{$ifdef USE_LCL_CANVAS}
ADest.Pen.Color := VColorToTColor(CurEntity.Pen.Color);
ADest.Brush.Color := VColorToTColor(CurEntity.Brush.Color);
{$else}
ADest.Pen.FPColor := VColorToFPColor(CurEntity.Pen.Color);
ADest.Brush.FPColor := VColorToFPColor(CurEntity.Brush.Color);
{$endif}
if CurEntity is TvCircle then if CurEntity is TvCircle then
begin begin
CurCircle := CurEntity as TvCircle; CurCircle := CurEntity as TvCircle;