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: 59:
| const x0 = 100; y0 = 100; R1 = 80; R2 = 100;
Var PosX, PosY, PX, PY : Integer; x1,y1 : Extended; Pressed : Boolean;
function ShiftNorm(InX, InY : Integer; Var OutX, OutY : Extended) : Boolean; Var L : Extended; begin dec(InX, x0); dec(InY, y0); L := sqrt(sqr(InX)+sqr(InY)); OutX := InX/L; OutY := InY/L; Result := L < R2; end;
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if ShiftNorm(X,Y,x1,y1) then begin PosX := PX-x0; PosY := PY-y0; Pressed := True; end; end;
procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); Var x2, y2, nX, nY, L : Extended; begin if Pressed and ShiftNorm(X,Y,x2,y2) then begin nX := (x1*x2+y1*y2)*PosX+(y1*x2-x1*y2)*PosY; nY := (x1*y2-y1*x2)*PosX+(x1*x2+y1*y2)*PosY; L := sqrt(sqr(nX)+sqr(nY)); nX := nX/L*R1+x0; nY := nY/L*R1+y0; PX := Round(nX); PY := Round(nY); With Image1.Canvas do begin Ellipse(x0-R2,y0-R2,x0+R2,y0+R2); Ellipse(PX-5,PY-5,PX+5,PY+5); Rectangle(x0-2,y0-2,x0+2,y0+2); end; end; end;
procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin Pressed := False; end; |