Draw curved arrow in delphi


I want to draw a curved right arrow at TCanvas as shape in Microsoft Word. Does anybody know an working method?

enter image description here


Answers:


Simple method to draw complex figures. If you need antialiasing, use GDIPlus or other advanced graphic means.

  procedure DrawCurveArrow(ACanvas: TCanvas; AColor: TColor;
    X0, Y0, Size: Integer);
  const
    Magic = 0.552; // constant to approximate circular arc with Bezier curve
  var
    Pt: array of TPoint;
    Flags: array of Byte;
    R, RMag: Integer;
  begin
    SetLength(Pt, 18);
    SetLength(Flags, 18);
    R := 5 * Size div 16;
    RMag := Round(R * Magic);

    Pt[0] := Point(X0 + 1, Y0); // to thicken tail a bit
    Flags[0] := PT_MOVETO;
    Pt[1] := Point(X0 + 1, Y0 - RMag);
    Flags[1] := PT_BEZIERTO;
    Pt[2] := Point(X0 + R - RMag, Y0 - R);
    Flags[2] := PT_BEZIERTO;
    Pt[3] := Point(X0 + R, Y0 - R);
    Flags[3] := PT_BEZIERTO;
    Pt[4] := Point(X0 + R + RMag, Y0 - R);
    Flags[4] := PT_BEZIERTO;
    Pt[5] := Point(X0 + 2 * R, Y0 - RMag);
    Flags[5] := PT_BEZIERTO;
    Pt[6] := Point(X0 + 2 * R, Y0);
    Flags[6] := PT_BEZIERTO;

    Pt[7] := Point(X0 + Size div 2, Y0);
    Flags[7] := PT_LINETO;
    Pt[8] := Point(X0 + Size * 3 div 4, Y0 + Size div 4);
    Flags[8] := PT_LINETO;
    Pt[9] := Point(X0 + Size, Y0);
    Flags[9] := PT_LINETO;
    Pt[10] := Point(X0 + 7 * Size div 8, Y0);
    Flags[10] := PT_LINETO;

    R := 7 * Size div 16;
    RMag := Round(R * Magic);
    Pt[11] := Point(X0 + 2 * R, Y0 - RMag);
    Flags[11] := PT_BEZIERTO;
    Pt[12] := Point(X0 + R + RMag, Y0 - R);
    Flags[12] := PT_BEZIERTO;
    Pt[13] := Point(X0 + R, Y0 - R);
    Flags[13] := PT_BEZIERTO;
    Pt[14] := Point(X0 + R - RMag, Y0 - R);
    Flags[14] := PT_BEZIERTO;
    Pt[15] := Point(X0, Y0 - RMag);
    Flags[15] := PT_BEZIERTO;
    Pt[16] := Point(X0, Y0);
    Flags[16] := PT_BEZIERTO;
    Pt[17] := Point(X0 + 1, Y0);
    Flags[17] := PT_LINETO or PT_CLOSEFIGURE;

    BeginPath(ACanvas.Handle);
    PolyDraw(ACanvas.Handle, Pt[0], Flags[0], Length(Pt));
    EndPath(ACanvas.Handle);
    ACanvas.Brush.Color := AColor;
    FillPath(ACanvas.Handle);
  end;

begin
  DrawCurveArrow(Canvas, clBlue, 100, 200, 300);