TCanvasArcTo (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

The following example exercises TCanvas.ArcTo and illustrates graphically how the parameters are used in the construction of the arc section.

Code

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  int CenterX, CenterY;
  int X1, Y1, X2, Y2, X3, Y3, X4, Y4;
  X1 = StrToInt(Edit1->Text);
  Y1 = StrToInt(Edit2->Text);
  X2 = StrToInt(Edit3->Text);
  Y2 = StrToInt(Edit4->Text);
  X3 = StrToInt(Edit5->Text);
  Y3 = StrToInt(Edit6->Text);
  X4 = StrToInt(Edit7->Text);
  Y4 = StrToInt(Edit8->Text);

  Repaint();
  Canvas->Pen->Color = clDefault;
  Canvas->MoveTo(X1, Y1);
  Canvas->LineTo(X2, Y1);
  Canvas->LineTo(X2, Y2);
  Canvas->LineTo(X1, Y2);
  Canvas->LineTo(X1, Y1);
  CenterX = (X1 + X2)/2;
  CenterY = (Y1 + Y2)/2;
  Canvas->MoveTo(CenterX, CenterY);
  Canvas->LineTo(X3, Y3);
  Canvas->MoveTo(CenterX, CenterY);
  Canvas->LineTo(X4, Y4);

  Canvas->MoveTo(CenterX, CenterY);
  Canvas->Pen->Color = clRed;
  Canvas->ArcTo(X1, Y1, X2, Y2, X3, Y3, X4, Y4);
}

Uses