was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

58 Visitors Online


 
... einen Pfeil zeichnen (II)?
Autor: Ben Ruyl
Homepage: http://home.versatel.nl/benruyl
[ Tip ausdrucken ]  

Tip Bewertung (23):  
     


{ .... }

var
  
BeginPoint: TPoint;
  
{ .... }

uses Math;

{ .... }

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  
BeginPoint.X := X;
  BeginPoint.Y := Y;
end;

procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  
B, deltaX, deltaY: Extended;
begin
  
Image1.Canvas.PenPos := BeginPoint;
  // Beginpoint is the point from where the use drew the line
  
Image1.Canvas.LineTo(X, Y);

  if BeginPoint.X <> X then // checks for division by zero
  
begin
    if 
(BeginPoint.X > X) then
      
B := DegToRad(135) - ArcTan((BeginPoint.Y - Y) / (BeginPoint.X - X))
    else
      
B := DegToRad(45) - ArcTan((BeginPoint.Y - Y) / (BeginPoint.X - X));
    // the arrow will have a 45 deg corner

    
deltaX := 15 * Cos(B); // 15 is the length of the arrow
    
deltaY := 15 * Sin(B);

    if (BeginPoint.X > X) then
    begin
      
Image1.Canvas.PenPos := Point(X, Y);
      Image1.Canvas.LineTo(X - Trunc(deltaX), Y + Trunc(deltaY));
      Image1.Canvas.PenPos := Point(X, Y);
      Image1.Canvas.LineTo(X + Trunc(deltaY), Y + Trunc(deltaX));
    end
    else
    begin
      
Image1.Canvas.PenPos := Point(X, Y);
      Image1.Canvas.LineTo(X - Trunc(deltaX), Y + Trunc(deltaY));
      Image1.Canvas.PenPos := Point(X, Y);
      Image1.Canvas.LineTo(X - Trunc(deltaY), Y - Trunc(deltaX));
    end;
  end
  else
  begin
    if 
BeginPoint.Y > Y then
    begin
      
Image1.Canvas.PenPos := Point(X, Y);
      Image1.Canvas.LineTo(X + 10, Y + 10);
      Image1.Canvas.PenPos := Point(X, Y);
      Image1.Canvas.LineTo(X - 10, Y + 10);
    end
    else
    begin
      
Image1.Canvas.PenPos := Point(X, Y);
      Image1.Canvas.LineTo(X + 10, Y - 10);
      Image1.Canvas.PenPos := Point(X, Y);
      Image1.Canvas.LineTo(X - 10, Y - 10);
    end;
  end;
end;


 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners