Selaa lähdekoodia

polygon align to pixel grid

johann 5 vuotta sitten
vanhempi
commit
3dbeaca9e1

+ 9 - 0
lazpaint/tools/utoolpolygon.pas

@@ -43,6 +43,7 @@ type
     procedure UpdateUserMode; virtual;
     procedure UpdateUserMode; virtual;
     procedure ShapeValidated; override;
     procedure ShapeValidated; override;
     function DoToolKeyDown(var key: Word): TRect; override;
     function DoToolKeyDown(var key: Word): TRect; override;
+    function RoundCoordinate(ptF: TPointF): TPointF; override;
   public
   public
     function ToolUp: TRect; override;
     function ToolUp: TRect; override;
     function ToolKeyPress(var key: TUTF8Char): TRect; override;
     function ToolKeyPress(var key: TUTF8Char): TRect; override;
@@ -357,6 +358,14 @@ begin
     Result:=inherited DoToolKeyDown(key);
     Result:=inherited DoToolKeyDown(key);
 end;
 end;
 
 
+function TToolPolygon.RoundCoordinate(ptF: TPointF): TPointF;
+begin
+  If Editor.GridActive then
+    result := Editor.SnapToGrid(ptF, false)
+  else
+    result := ptF;
+end;
+
 function TToolPolygon.GetContextualToolbars: TContextualToolbars;
 function TToolPolygon.GetContextualToolbars: TContextualToolbars;
 begin
 begin
   Result:= [ctFill,ctShape,ctCloseShape,ctPenWidth,ctPenStyle,ctJoinStyle,ctLineCap];
   Result:= [ctFill,ctShape,ctCloseShape,ctPenWidth,ctPenStyle,ctJoinStyle,ctLineCap];

+ 2 - 0
lazpaint/tools/utoolvectorial.pas

@@ -1927,6 +1927,7 @@ begin
     if not handled and Assigned(FShape) then
     if not handled and Assigned(FShape) then
     begin
     begin
       shapePt := AffineMatrixInverse(VectorTransform(true))*FLastPos;
       shapePt := AffineMatrixInverse(VectorTransform(true))*FLastPos;
+      If Editor.GridActive then shapePt := Editor.SnapToGrid(shapePt, false);
       FShape.MouseDown(rightBtn, ShiftState, shapePt.X,shapePt.Y, cur, handled);
       FShape.MouseDown(rightBtn, ShiftState, shapePt.X,shapePt.Y, cur, handled);
     end;
     end;
     UpdateCursor(cur);
     UpdateCursor(cur);
@@ -2015,6 +2016,7 @@ begin
     if not handled and Assigned(FShape) then
     if not handled and Assigned(FShape) then
     begin
     begin
       shapePt := AffineMatrixInverse(VectorTransform(true))*FLastPos;
       shapePt := AffineMatrixInverse(VectorTransform(true))*FLastPos;
+      If Editor.GridActive then shapePt := Editor.SnapToGrid(shapePt, false);
       FShape.MouseMove(ShiftState, shapePt.X,shapePt.Y, cur, handled);
       FShape.MouseMove(ShiftState, shapePt.X,shapePt.Y, cur, handled);
     end;
     end;
     UpdateCursor(cur);
     UpdateCursor(cur);

+ 9 - 4
lazpaintcontrols/lcvectorpolyshapes.pas

@@ -874,12 +874,18 @@ procedure TCustomPolypointShape.MouseDown(RightButton: boolean;
   Shift: TShiftState; X, Y: single; var ACursor: TOriginalEditorCursor; var
   Shift: TShiftState; X, Y: single; var ACursor: TOriginalEditorCursor; var
   AHandled: boolean);
   AHandled: boolean);
 begin
 begin
+  FMousePos := PointF(X,Y);
   if FAddingPoint then
   if FAddingPoint then
   begin
   begin
     if not RightButton then
     if not RightButton then
     begin
     begin
-      if (PointCount>1) and not PointsEqual(Points[PointCount-1],Points[PointCount-2]) then
-        AddPoint(Points[PointCount-1]);
+      if (PointCount>1) and not PointsEqual(FMousePos,Points[PointCount-2]) then
+      begin
+        BeginUpdate;
+        Points[PointCount-1] := FMousePos;
+        AddPoint(FMousePos);
+        EndUpdate;
+      end;
     end else
     end else
       Usermode := vsuEdit;
       Usermode := vsuEdit;
     AHandled:= true;
     AHandled:= true;
@@ -889,11 +895,10 @@ begin
     begin
     begin
       BeginUpdate;
       BeginUpdate;
       AddPoint(EmptyPointF);
       AddPoint(EmptyPointF);
-      FMousePos := PointF(X,Y);
       AddPoint(FMousePos);
       AddPoint(FMousePos);
       FillFit;
       FillFit;
       EndUpdate;
       EndUpdate;
-      USerMode := vsuCreate;
+      UserMode := vsuCreate;
       AHandled:= true;
       AHandled:= true;
     end;
     end;
   end;
   end;