Einzelnen Beitrag anzeigen

Hawkeye219

Registriert seit: 18. Feb 2006
Ort: Stolberg
2.227 Beiträge
 
Delphi 2010 Professional
 
#26

Re: Suche Pfeile zur Visualisierung von Beziehungen

  Alt 20. Aug 2007, 12:20
Hallo Tom,

die Position der beiden beteiligten Panels zueinander läßt sich recht einfach mit dem Sutherland-Cohen-Algorithmus ermitteln. In Abhängigkeit des ermittelten Lagecodes wird dann der Pfeil gezeichnet.

Delphi-Quellcode:
procedure TForm1.FormPaint (Sender: TObject);

  procedure DoDrawVector (aPin1, aPin2: TPin);
  var
    P1, P2 : TPoint;
  begin
    P1 := PinPosition(Panel1, aPin1);
    P2 := PinPosition(Panel2, aPin2);
    Canvas.Pen.Color := clBlue;
    Canvas.Brush.Color := clBlue;
    DrawVector (Canvas, P1.X, P1.Y, P2.X, P2.Y, 10, True);
  end;

var
  code : Integer;
begin
  inherited;

  // Lagecode des ersten Panels bezogen auf das zweite Panel ermitteln
  code := 0;
  if (Panel1.Left + Panel1.Width < Panel2.Left) then Inc (code, 1);
  if (Panel1.Left > Panel2.Left + Panel2.Width) then Inc (code, 2);
  if (Panel1.Top + Panel1.Height < Panel2.Top) then Inc (code, 8);
  if (Panel1.Top > Panel2.Top + Panel2.Height) then Inc (code, 4);

  // Vektor in Abhängigkeit des Lagecodes zeichnen
  case code of
    1: DoDrawVector (pinRight, pinLeft);
    2: DoDrawVector (pinLeft, pinRight);
    4: DoDrawVector (pinTop, pinBottom);
    5: DoDrawVector (pinTop, pinLeft);
    6: DoDrawVector (pinTop, pinRight);
    8: DoDrawVector (pinBottom, pinTop);
    9: DoDrawVector (pinBottom, pinLeft);
   10: DoDrawVector (pinBottom, pinRight);
  end;
end;
Die Lösung von oki (mehrere Ecken pro Verbindung) ist natürlich wesentlich ansprechender, aber auch etwas aufwendiger.

Gruß Hawkeye
  Mit Zitat antworten Zitat