Controling FillColor for different parts inside a shape

Hello
Iam trying to draw a shape with this routine(Class derived from TDatabaseBlock)

procedure TInclinedPlane.GetBlockPath(APath: TDgrGraphicsPath;ADrawer:TDgrBlockDrawer);
begin
//Draw Triangle with red color
APath.StartFigure;
Apath.AddLine(0,0,0,100);
Apath.AddLine(0,LeftSide,BottomSide,LeftSide);
ADrawer.Canvas.Brush.Color:=clGreen;
Apath.CloseFigure;

//Draw Sphare with green color
Apath.StartFigure;
Apath.AddEllipse(20,50,20,20);
Apath.CloseFigure;
end;
image
How can choose a Red color for the sphare preserving the green color for the triangle...
Please Help!!!

In this case you can't. The GetBlockPath is just a helper method to be used in the case where you want the shape to be defined by the path but all other paint properties like shadow, pen width, pen color, brush color, etc..

In this case you will have to do a full painting of the block yourself, you will have to override the DrawBlock method - there are examples of it in the ElectricBlocks unit.

Thank you for your reply. I am going to try what you suggested. Please keep this post this open!

1 Like

Hello again.
After a deep searching, I did't find any DiagramBlock from all samples which deals with
"giving different background color to different parts of a Block shape...
I think after all, it would be better if I combine more than one DiagramBlock... with this approach I have no problems.
Thank you again

You just need to change the Brush/Pen properties and call the draw methods. It's a lower level way of drawing the block.

Yes. There is one Block (TFlowListBlock) that uses Two fill colors in the same block. It was about creating path inside the block> this is exactly what I wanted!!
Thank you

AInfo.DgrDrawer.Canvas.Brush.Color :=Clred;// CaptionColor;
AInfo.DgrDrawer.Canvas.Brush.BrushMode := bmSolid;
path := AInfo.DgrDrawer.Canvas.CreatePath;
try
  path.AddRectangle(Square(0, 0, 100, 20));
  AInfo.DgrDrawer.TransformPath(path);
  AInfo.DgrDrawer.Canvas.Path(path);
finally
  path.Free;
end;
1 Like