Page 1 of 1

PolygonFloat...world or screen coordinates?

Posted: Wed Sep 18, 2024 1:49 pm
by 16493447
I don't know why I cannot find any documentation or previous posts about this, but do the xxFloat calls take world or screen coordinates? I tried sending world figuring that was the purpose and the points would be transformed to screen in the call, but it does not seem to be working.

Re: PolygonFloat...world or screen coordinates?

Posted: Thu Sep 19, 2024 6:34 am
by yeray
Hello,

All the drawing methods in the canvas use screen coordinates.
Here you have an example using PolygonFloat function:
polygonfloat.png
polygonfloat.png (21.55 KiB) Viewed 7894 times

Code: Select all

uses Chart, TeEngine, TeCanvas, Series;

var Chart1: TChart;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1:=TChart.Create(Self);

  with Chart1 do
  begin
    Parent:=Self;
    Align:=alClient;
    Color:=clWhite;
    Gradient.Visible:=False;
    Walls.Back.Color:=clWhite;
    Walls.Back.Gradient.Visible:=False;
    Legend.Hide;
    View3D:=False;

    AddSeries(TPointSeries).FillSampleValues;

    OnAfterDraw:=ChartAfterDraw;
  end;
end;

procedure TForm1.ChartAfterDraw(Sender: TObject);
var
  series: TChartSeries;
  polygon: Array of TPointFloat;
  tmpBlend : TTeeBlend;
  i: Integer;
begin
  if Chart1.SeriesCount<1 then
     Exit;

  series:=Chart1[0];
  if series.Count<2 then
     Exit;

  SetLength(polygon, series.Count+2);

  for i:=0 to series.Count-1 do
  begin
    polygon[i].x:=series.CalcXPos(i);
    polygon[i].y:=series.CalcYPos(i);
  end;

  polygon[i].x:=polygon[i-1].x;
  polygon[i].y:=Chart1.Axes.Bottom.PosAxis;

  Inc(i);
  polygon[i].x:=polygon[0].x;
  polygon[i].y:=polygon[i-1].y;

  tmpBlend:=Chart1.Canvas.BeginBlending(Chart1.ChartRect, 50);
  Chart1.Canvas.Pen.Style:=psDash;
  Chart1.Canvas.Brush.Color:=clRed;
  Chart1.Canvas.PolygonFloat(polygon);
  Chart1.Canvas.EndBlending(tmpBlend);
end;