Coordinate Systems of Canvas and Shapes lazarus / 31-LCL ---------------------------------------------------------------------- blondMammuth · 2014-09-09 09:30 I have a Form, inside of it a Panel. I put some Shapes on the panel, and they have the usual border coordinates left, top, right, bottom. I also draw lines on the canvas of the Panel. I want to draw Lines such that they relate to the Shapes (i.e. connect them, or connect them with some points, and so on). Now I realise that the coordinate system of the Shape positions obviously differs from the coordinate system of the lines. The same coordinates used for lines seem to be up and to the left of where the shapes really are. So the units used for canvas drawing are smaller than the units used for shapes? I have been searching for more information on this issue, but unluckily have not found much to my help. Could someone give me a hint of where to search, or else what to do to make the coordinate systems match? Thanks in advance! ---------------------------------------------------------------------- marcov · 2014-09-09 09:43 How big is the difference? If small, it is probably the bevel. See the TPanel properties and turn of the bevel. ---------------------------------------------------------------------- blondMammuth · 2014-09-09 09:57 The difference is definitely a factor, not so much an offset. I have tested it with different shapes and the deviation grows with the coordinates. So it must be a factor. I estimate the factor to be about a half. I.e. I draw "from the middle of the shape" and the line starts at a position about halfways between the left top corner of the canvas and the intended position. May be little bit more than half. ---------------------------------------------------------------------- howardpc · 2014-09-09 10:02 Maybe you need to show the code that gives odd results? Make sure you refer all positions to the panel's canvas (not the form's canvas). The following simple example draws correctly to the exact pixel desired. Code: [Select]unit Unit1; {$mode objfpc}{$H+} interface uses   Classes, Forms, Controls, Graphics, ExtCtrls, StdCtrls; type   { TForm1 }   TForm1 = class(TForm)     procedure FormCreate(Sender: TObject);   private     PRight: TPanel;     BDrawLine: TButton;     shTriangle: TShape;     shSquare: TShape;     procedure BDrawLineClick(Sender: TObject);     function CreateShape(aPt: TPoint; aColor: TColor; aShape: TShapeType): TShape;   end; var   Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.BDrawLineClick(Sender: TObject); begin   PRight.Canvas.Line(shSquare.Left, shSquare.Top, shTriangle.Left,                      shTriangle.Top+shTriangle.Height); end; function TForm1.CreateShape(aPt: TPoint; aColor: TColor; aShape: TShapeType   ): TShape; begin   Result:=TShape.Create(Self);   Result.Left:=aPt.x;   Result.Top:=aPt.y;   Result.Brush.Color:=aColor;   Result.Shape:=aShape;   Result.Parent:=PRight; end; procedure TForm1.FormCreate(Sender: TObject); begin   PRight:=TPanel.Create(Self);   PRight.Align:=alRight;   PRight.Parent:=Self;   shTriangle:=CreateShape(Point(30,30), clBlue, stTriangle);   shSquare:=CreateShape(Point(70,150), clRed, stSquare);   BDrawLine:=TButton.Create(Self);   BDrawLine.Caption:='Draw line';   BDrawLine.AutoSize:=True;   BDrawLine.Left:=30;   BDrawLine.Top:=100;   BDrawLine.OnClick:=@BDrawLineClick;   BDrawLine.Parent:=Self; end; end. ---------------------------------------------------------------------- blondMammuth · 2014-09-09 10:05 My mistake, I got the formula wrong (subtracted instead of added the offset), and of course not good style to ask first and then analyse! Sorry and thanks for the reactions! Nevertheless, it is good for a newbie to learn that the coordinate systems seem to be equal. ---------------------------------------------------------------------- blondMammuth · 2014-09-09 10:05 And thanks for the example! ---------------------------------------------------------------------- blondMammuth · 2014-09-09 21:19 BTW for every beginner interested in such questions, I add this link to a very nice comprehensive explanation here (it helps me a lot): http://delphi.about.com/library/bluc/text/uc052102a.htm