whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

74 Visitors Online


 
...draw an arrow (II)?
Autor: Ben Ruyl
Homepage: http://home.versatel.nl/benruyl
[ Print tip ]  

Tip Rating (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;


 

Rate this tip:

poor
very good


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