Glen Morse
Glen Morse

Reputation: 2593

Converting VLC to FMX MoveTo

Currently the VCL has

 WITH Canvas DO
          BEGIN
            CASE PathStyle OF

          psLine:
            BEGIN
                strokeThickness := Max(1, MulDiv( Min(xCellSize,yCellSize), 2, 10));
                MoveTo(xOffset + PosX * xCellSize + xCellSize DIV 2,yOffset + PosY * yCellSize + yCellSize DIV 2);
             END

But i get error on moveto (undefined).

So how can i convert the moveto to work with FMX?

Upvotes: -1

Views: 1743

Answers (1)

David Heffernan
David Heffernan

Reputation: 612824

The separate MoveTo and LineTo methods do not translate literally. Instead you make a single call to the DrawLine method of TCanvas. This receives two TPointF parameters that specify the beginning and end of the line segment. As well you pass an opacity parameter, 100 for opaque.

Borrowing from the official samples:

var
  p1, p2: TPointF;
begin
  // sets the ends of the line to be drawn
  p1.Create(20, 2);
  p2.Create(350, 400);
  Image1.Bitmap.Canvas.BeginScene;
  // draw the line on the canvas
  Image1.Bitmap.Canvas.DrawLine(p1, p2, 100);
  Image1.Bitmap.Canvas.EndScene;
  // updates the bitmap
  Image1.Bitmap.BitmapChanged;
end;

For what it is worth, the TPointF type is one of the worst designed types I've seen in a long while. Its faults are multitudinous:

  • No static class method returning a new value. This forces you to declare variables just to make a simple call to DrawLine as in the code above.
  • Dreadfully named initializing functions named Create that make you think this is a class rather than a record.
  • Pointless arithmetic methods in addition to the overloaded operators.
  • Pointless mutating methods like Offset for functionality that is best expressed with operators.

Upvotes: 3

Related Questions