Hello
I would like my shape to rotate relative to a certain point dot(0,0) for example. so when I write
MyShape.RotationCenter:=dot(0,0) I noticed that manually this was a success. I can drag the roatation point arround dot(0,0) and every thing seems to be correct.
How ever when I try to do the job by code the shape continues to rotate arround the center point.
MyShape.angle:=MyShape.angle+1;
Please what do I mess here??!!
Indeed, changing Angle
property from code doesn't take RotationCenter
into account, since it always represents the angle relative to the block center. You have to calculate the new position yourself if you want to rotate the block via a different rotation center.
Here is a helper function:
uses {...}, DiagramUtils, atDiagram;
procedure TForm1.Button1Click(Sender: TObject);
begin
atDiagram1.Blocks[0].RotationCenter := Dot(0, 0);
RotateToNewAngle(atDiagram1.Blocks[0], atDiagram1.Blocks[0].Angle + 30);
end;
type
TBlockHack = class(TDiagramBlock)
end;
procedure TForm1.RotateToNewAngle(B: TCustomDiagramBlock; NewAngle: Double);
var
Drawer: TBlockDrawer;
R: TSquare;
begin
Drawer := TBlockDrawer.Create;
try
Drawer.RotationType := rtRotationCenter;
Drawer.RotationCenter := TBlockHack(B).DiagramRotCenter;
Drawer.Angle := -B.Angle;
Drawer.CurRect := B.BoundsRect;
R := Drawer.RotByCenter(B.BoundsRect);
Drawer.Angle := NewAngle;
Drawer.CurRect := R;
B.BoundsRect := Drawer.RotByCenter(R);
B.Angle := NewAngle;
finally
Drawer.Free;
end;
end;
It works when atDiagram1.Blocks[0].RotationCenter := Dot(0, 0);
I noticed that if I choose another RotationCenter (ex: Dot(0,40)) the the helper function you suggested does not perform an exact rotation....how to correct that?
It ok. Every thing is ok.
Thank you
1 Like
This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.