1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| Procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
Var A,B:Integer; // X <=> A | Y <=> B
Begin
If Button = mbLeft then
If Firstpoint Then //Premier point -> devient le pt de départ
Begin
Form1.Canvas.Penpos := Souris ;
Form1.Canvas.rectangle (Souris.X-2,Souris.Y-2,Souris.X+2,Souris.Y+2);
Dep.X := Souris.X;
Dep.Y := Souris.Y;
Label1.Caption := IntToStr(Dep.X) + ' ; ' + IntToStr(Dep.Y);
Firstpoint := False;
End
Else // Cas où le premier point est déjà posé
Begin
Form1.Canvas.LineTo (Souris.X,Souris.Y);
Arr.X := Souris.X;
Arr.Y := Souris.Y;
Label2.Caption := IntToStr(Arr.X) + ' ; ' + IntToStr(Arr.Y);
A:= Dep.X; B := Dep.Y;
If (Dep.X = Arr.X) Then //Déplacement Vertical
If (Dep.Y < Arr.Y) Then //Haut en Bas
While (B <> Arr.Y) Do
Begin
Form1.Canvas.Rectangle(A-2,B-2,A+2,B+2);
B:=B+1;
Pause(1);
Refresh;
End
Else //Bas en Haut
While (B <> Arr.Y) Do
Begin
Form1.Canvas.Rectangle(A-2,B-2,A+2,B+2);
B:=B-1;
Pause(1);
Refresh;
End
Else If (Dep.Y = Arr.Y) Then //Déplacement Horizontal
If (Dep.X < Arr.X) Then //Gauche à Droite
While (A <> Arr.X) Do
Begin
Form1.Canvas.Rectangle(A-2,B-2,A+2,B+2);
A:=A+1;
Pause(1);
Refresh;
End
Else //Droite à Gauche
While (A <> Arr.X) Do
Begin
Form1.Canvas.Rectangle(A-2,B-2,A+2,B+2);
A:=A-1;
Pause(1);
Refresh;
End
End;
End; |
Partager