So geht es:
Delphi-Quellcode:
procedure TDWFotoBook.SnapToGrid;
var
x : Integer;
a : Integer;
b : Integer;
begin
x := FImageEnVect.Layers[ImageEnVect.LayersCurrent].PosX;
a := x div Self.GridWidth;
b := x - a * Self.GridWidth;
if b < (Self.GridWidth div 2) then
ImageEnVect.Layers[ImageEnVect.LayersCurrent].PosX := a * Self.GridWidth
else
ImageEnVect.Layers[ImageEnVect.LayersCurrent].PosX := (a + 1) * Self.GridWidth;
x := ImageEnVect.Layers[ImageEnVect.LayersCurrent].PosY;
a := x div Self.GridWidth;
b := x - a * Self.GridWidth;
if b < (Self.GridWidth div 2) then
ImageEnVect.Layers[ImageEnVect.LayersCurrent].PosY := a * Self.GridWidth
else
ImageEnVect.Layers[ImageEnVect.LayersCurrent].PosY := (a + 1) * Self.GridWidth;
end;
Danke für den Denkanstoss.