Jelajahi Sumber

close shape when clicking first point

circular17 6 tahun lalu
induk
melakukan
a8c1538c1b

+ 27 - 0
lazpaint/tools/utoolpolygon.pas

@@ -34,10 +34,13 @@ type
 
   TToolPolygon = class(TVectorialTool)
   protected
+    initiallyClosed : boolean;
     function CreateShape: TVectorShape; override;
     procedure AssignShapeStyle(AMatrix: TAffineMatrix); override;
     procedure UpdateUserMode; virtual;
+    procedure ShapeValidated; override;
   public
+    function ToolUp: TRect; override;
     function ToolKeyPress(var key: TUTF8Char): TRect; override;
     function ToolKeyDown(var key: Word): TRect; override;
     function GetContextualToolbars: TContextualToolbars; override;
@@ -177,6 +180,7 @@ end;
 function TToolPolygon.CreateShape: TVectorShape;
 begin
   result := TPolylineShape.Create(nil);
+  initiallyClosed := toCloseShape in Manager.ShapeOptions;
 end;
 
 procedure TToolPolygon.AssignShapeStyle(AMatrix: TAffineMatrix);
@@ -196,6 +200,29 @@ begin
   if FQuickDefine then FShape.Usermode := vsuCreate;
 end;
 
+procedure TToolPolygon.ShapeValidated;
+begin
+  inherited ShapeValidated;
+  if not initiallyClosed then
+    Manager.ShapeOptions := Manager.ShapeOptions - [toCloseShape];
+end;
+
+function TToolPolygon.ToolUp: TRect;
+var
+  opt: TShapeOptions;
+begin
+  Result:=inherited ToolUp;
+  if Assigned(FShape) then
+  begin
+    opt := Manager.ShapeOptions;
+    if (FShape as TCustomPolypointShape).Closed then
+      include(opt, toCloseShape)
+    else
+      exclude(opt, toCloseShape);
+    Manager.ShapeOptions:= opt;
+  end;
+end;
+
 function TToolPolygon.ToolKeyPress(var key: TUTF8Char): TRect;
 var
   keyCode: Word;

+ 7 - 0
lazpaint/tools/utoolvectorial.pas

@@ -61,6 +61,7 @@ type
     procedure OnTryStop({%H-}sender: TCustomLayerAction); override;
     procedure UpdateUseOriginal;
     function ReplaceLayerAndAddShape(out ARect: TRect): TCustomImageDifference; virtual;
+    procedure ShapeValidated; virtual;
   public
     function ValidateShape: TRect;
     function CancelShape: TRect;
@@ -1440,6 +1441,11 @@ begin
   FShape := nil;
 end;
 
+procedure TVectorialTool.ShapeValidated;
+begin
+  //nothing
+end;
+
 function TVectorialTool.ValidateShape: TRect;
 var
   layerId: LongInt;
@@ -1482,6 +1488,7 @@ begin
     Cursor := crDefault;
     result := OnlyRenderChange;
     UpdateUseOriginal;
+    ShapeValidated;
   end else
     result := EmptyRect;
 end;

+ 12 - 1
lazpaintcontrols/lcvectorpolyshapes.pas

@@ -637,7 +637,18 @@ end;
 procedure TCustomPolypointShape.DoClickPoint(APointIndex: integer;
   AShift: TShiftState);
 begin
-  //nothing
+  if (APointIndex = 0) and (UserMode = vsuCreate) and not Closed then
+  begin
+    if PointCount > 2 then
+    begin
+      RemovePoint(PointCount-1);
+      Closed := true;
+      UserMode := vsuEdit;
+    end else
+    begin
+      Remove;
+    end;
+  end;
 end;
 
 function TCustomPolypointShape.CanMovePoints: boolean;