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

 Werbung

 21 Visitors Online

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

 Tip Bewertung (18):

{ .... }

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