Browse Source

copy/paste shape without transform

minor fixes as well
circular17 6 years ago
parent
commit
35e5c7d18d
2 changed files with 40 additions and 22 deletions
  1. 23 15
      lazpaint/tools/utoolvectorial.pas
  2. 17 7
      lazpaintcontrols/lcvectorclipboard.pas

+ 23 - 15
lazpaint/tools/utoolvectorial.pas

@@ -115,6 +115,7 @@ type
     function GetIsSelectingTool: boolean; override;
     function GetIsSelectingTool: boolean; override;
     function GetVectorOriginal: TVectorOriginal;
     function GetVectorOriginal: TVectorOriginal;
     function GetGradientOriginal: TBGRALayerGradientOriginal;
     function GetGradientOriginal: TBGRALayerGradientOriginal;
+    function GetOriginalTransform: TAffineMatrix;
     function FixLayerOffset: boolean; override;
     function FixLayerOffset: boolean; override;
     function GetCurrentSplineMode: TToolSplineMode;
     function GetCurrentSplineMode: TToolSplineMode;
     procedure SetCurrentSplineMode(AMode: TToolSplineMode);
     procedure SetCurrentSplineMode(AMode: TToolSplineMode);
@@ -763,6 +764,11 @@ begin
   result := Manager.Image.LayerOriginal[Manager.Image.CurrentLayerIndex] as TBGRALayerGradientOriginal;
   result := Manager.Image.LayerOriginal[Manager.Image.CurrentLayerIndex] as TBGRALayerGradientOriginal;
 end;
 end;
 
 
+function TEditShapeTool.GetOriginalTransform: TAffineMatrix;
+begin
+  result := Manager.Image.LayerOriginalMatrix[Manager.Image.CurrentLayerIndex];
+end;
+
 function TEditShapeTool.FixLayerOffset: boolean;
 function TEditShapeTool.FixLayerOffset: boolean;
 begin
 begin
   Result:= false;
   Result:= false;
@@ -1209,7 +1215,9 @@ begin
     MakeVectorOriginal;
     MakeVectorOriginal;
     if GetCurrentLayerKind = lkVectorial then
     if GetCurrentLayerKind = lkVectorial then
     begin
     begin
-      PasteShapesFromClipboard(GetVectorOriginal);
+      BindOriginalEvent(true);
+      PasteShapesFromClipboard(GetVectorOriginal, GetOriginalTransform);
+      BindOriginalEvent(false);
       result := true;
       result := true;
     end;
     end;
   end else
   end else
@@ -1224,9 +1232,9 @@ begin
           tcMoveToFront: GetVectorOriginal.SelectedShape.BringToFront;
           tcMoveToFront: GetVectorOriginal.SelectedShape.BringToFront;
           tcMoveDown: GetVectorOriginal.SelectedShape.MoveDown(true);
           tcMoveDown: GetVectorOriginal.SelectedShape.MoveDown(true);
           tcMoveToBack: GetVectorOriginal.SelectedShape.SendToBack;
           tcMoveToBack: GetVectorOriginal.SelectedShape.SendToBack;
-          tcCopy: Result:= CopyShapesToClipboard([GetVectorOriginal.SelectedShape]);
+          tcCopy: Result:= CopyShapesToClipboard([GetVectorOriginal.SelectedShape], GetOriginalTransform);
           tcCut: begin
           tcCut: begin
-                   result := CopyShapesToClipboard([GetVectorOriginal.SelectedShape]) and
+                   result := CopyShapesToClipboard([GetVectorOriginal.SelectedShape], GetOriginalTransform) and
                              GetVectorOriginal.RemoveShape(GetVectorOriginal.SelectedShape);
                              GetVectorOriginal.RemoveShape(GetVectorOriginal.SelectedShape);
                  end;
                  end;
           tcAlignLeft..tcAlignBottom: AlignShape(GetVectorOriginal.SelectedShape, ACommand,
           tcAlignLeft..tcAlignBottom: AlignShape(GetVectorOriginal.SelectedShape, ACommand,
@@ -1869,33 +1877,33 @@ var
   r: TRect;
   r: TRect;
   toolDest: TBGRABitmap;
   toolDest: TBGRABitmap;
 begin
 begin
+  result := false;
   case ACommand of
   case ACommand of
-  tcCopy: begin
+  tcCopy:
       if ToolProvideCommand(tcCopy) then
       if ToolProvideCommand(tcCopy) then
-        result := CopyShapesToClipboard([FShape])
-      else
-        Result:= false;
-    end;
-  tcCut: begin
+        result := CopyShapesToClipboard([FShape], VectorTransform(false));
+  tcCut:
       if ToolCommand(tcCopy) then
       if ToolCommand(tcCopy) then
       begin
       begin
         toolDest := GetToolDrawingLayer;
         toolDest := GetToolDrawingLayer;
         r := CancelShape;
         r := CancelShape;
         Action.NotifyChange(toolDest, r);
         Action.NotifyChange(toolDest, r);
         result := true;
         result := true;
-      end else
-        result := false;
-    end;
+      end;
   tcFinish: begin
   tcFinish: begin
-            r := ValidateShape;
-            Action.NotifyChange(toolDest, r);
-            result := true;
+              toolDest := GetToolDrawingLayer;
+              r := ValidateShape;
+              Action.NotifyChange(toolDest, r);
+              result := true;
           end;
           end;
   tcAlignLeft..tcAlignBottom:
   tcAlignLeft..tcAlignBottom:
       if ToolProvideCommand(ACommand) then
       if ToolProvideCommand(ACommand) then
+      begin
         AlignShape(FShape, ACommand,
         AlignShape(FShape, ACommand,
                  Manager.Image.LayerOriginalMatrix[Manager.Image.CurrentLayerIndex],
                  Manager.Image.LayerOriginalMatrix[Manager.Image.CurrentLayerIndex],
                  rect(0,0,Manager.Image.Width,Manager.Image.Height));
                  rect(0,0,Manager.Image.Width,Manager.Image.Height));
+        result := true;
+      end;
   else
   else
     result := false;
     result := false;
   end;
   end;

+ 17 - 7
lazpaintcontrols/lcvectorclipboard.pas

@@ -5,10 +5,10 @@ unit LCVectorClipboard;
 interface
 interface
 
 
 uses
 uses
-  Classes, SysUtils, Clipbrd, LCLType, LCVectorOriginal;
+  Classes, SysUtils, Clipbrd, LCLType, LCVectorOriginal, BGRATransform;
 
 
-function CopyShapesToClipboard(AShapes: array of TVectorShape): boolean;
-procedure PasteShapesFromClipboard(ATargetContainer: TVectorOriginal);
+function CopyShapesToClipboard(AShapes: array of TVectorShape; const AMatrix: TAffineMatrix): boolean;
+procedure PasteShapesFromClipboard(ATargetContainer: TVectorOriginal; const ATargetMatrix: TAffineMatrix);
 function ClipboardHasShapes: boolean;
 function ClipboardHasShapes: boolean;
 
 
 implementation
 implementation
@@ -16,11 +16,12 @@ implementation
 var
 var
   vectorClipboardFormat : TClipboardFormat;
   vectorClipboardFormat : TClipboardFormat;
 
 
-function CopyShapesToClipboard(AShapes: array of TVectorShape): boolean;
+function CopyShapesToClipboard(AShapes: array of TVectorShape; const AMatrix: TAffineMatrix): boolean;
 var
 var
   tempContainer: TVectorOriginal;
   tempContainer: TVectorOriginal;
   mem: TMemoryStream;
   mem: TMemoryStream;
   i: Integer;
   i: Integer;
+  s: TVectorShape;
 begin
 begin
   result:= false;
   result:= false;
   if length(AShapes)=0 then exit;
   if length(AShapes)=0 then exit;
@@ -28,7 +29,11 @@ begin
   mem := TMemoryStream.Create;
   mem := TMemoryStream.Create;
   try
   try
     for i := 0 to high(AShapes) do
     for i := 0 to high(AShapes) do
-      tempContainer.AddShape(AShapes[i].Duplicate);
+    begin
+      s := AShapes[i].Duplicate;
+      s.Transform(AMatrix);
+      tempContainer.AddShape(s);
+    end;
     tempContainer.SaveToStream(mem);
     tempContainer.SaveToStream(mem);
     Clipboard.Clear;
     Clipboard.Clear;
     mem.Position:= 0;
     mem.Position:= 0;
@@ -39,13 +44,16 @@ begin
   end;
   end;
 end;
 end;
 
 
-procedure PasteShapesFromClipboard(ATargetContainer: TVectorOriginal);
+procedure PasteShapesFromClipboard(ATargetContainer: TVectorOriginal; const ATargetMatrix: TAffineMatrix);
 var
 var
   tempContainer: TVectorOriginal;
   tempContainer: TVectorOriginal;
   mem: TMemoryStream;
   mem: TMemoryStream;
   i: Integer;
   i: Integer;
   pastedShape: TVectorShape;
   pastedShape: TVectorShape;
+  invMatrix: TAffineMatrix;
 begin
 begin
+  if not IsAffineMatrixInversible(ATargetMatrix) then exit;
+  invMatrix := AffineMatrixInverse(ATargetMatrix);
   if Clipboard.HasFormat(vectorClipboardFormat) then
   if Clipboard.HasFormat(vectorClipboardFormat) then
   begin
   begin
     mem := TMemoryStream.Create;
     mem := TMemoryStream.Create;
@@ -58,8 +66,10 @@ begin
         for i := 0 to tempContainer.ShapeCount-1 do
         for i := 0 to tempContainer.ShapeCount-1 do
         begin
         begin
           pastedShape := tempContainer.Shape[i].Duplicate;
           pastedShape := tempContainer.Shape[i].Duplicate;
+          pastedShape.Transform(invMatrix);
           ATargetContainer.AddShape(pastedShape);
           ATargetContainer.AddShape(pastedShape);
-          ATargetContainer.SelectShape(pastedShape);
+          if i = tempContainer.ShapeCount-1 then
+            ATargetContainer.SelectShape(pastedShape);
         end;
         end;
       end;
       end;
     finally
     finally