Bläddra i källkod

copy vector original as shape

circular17 6 år sedan
förälder
incheckning
606aef822d
1 ändrade filer med 63 tillägg och 3 borttagningar
  1. 63 3
      lazpaint/tools/utoolvectorial.pas

+ 63 - 3
lazpaint/tools/utoolvectorial.pas

@@ -116,6 +116,7 @@ type
     function GetIsSelectingTool: boolean; override;
     function GetIsSelectingTool: boolean; override;
     function GetVectorOriginal: TVectorOriginal;
     function GetVectorOriginal: TVectorOriginal;
     function GetGradientOriginal: TBGRALayerGradientOriginal;
     function GetGradientOriginal: TBGRALayerGradientOriginal;
+    function GetImageOriginal: TBGRALayerImageOriginal;
     function GetOriginalTransform: TAffineMatrix;
     function GetOriginalTransform: TAffineMatrix;
     function FixLayerOffset: boolean; override;
     function FixLayerOffset: boolean; override;
     function GetCurrentSplineMode: TToolSplineMode;
     function GetCurrentSplineMode: TToolSplineMode;
@@ -142,7 +143,7 @@ implementation
 
 
 uses LazPaintType, LCVectorPolyShapes, LCVectorTextShapes, LCVectorialFill, BGRASVGOriginal,
 uses LazPaintType, LCVectorPolyShapes, LCVectorTextShapes, LCVectorialFill, BGRASVGOriginal,
   ULoading, BGRATransform, math, UImageDiff, Controls, BGRAPen, UResourceStrings, ugraph,
   ULoading, BGRATransform, math, UImageDiff, Controls, BGRAPen, UResourceStrings, ugraph,
-  LCScaleDPI, LCVectorClipboard, BGRAGradientScanner;
+  LCScaleDPI, LCVectorClipboard, BGRAGradientScanner, UClipboard;
 
 
 const PointSize = 6;
 const PointSize = 6;
 
 
@@ -776,6 +777,11 @@ begin
   result := Manager.Image.LayerOriginal[Manager.Image.CurrentLayerIndex] as TBGRALayerGradientOriginal;
   result := Manager.Image.LayerOriginal[Manager.Image.CurrentLayerIndex] as TBGRALayerGradientOriginal;
 end;
 end;
 
 
+function TEditShapeTool.GetImageOriginal: TBGRALayerImageOriginal;
+begin
+  result := Manager.Image.LayerOriginal[Manager.Image.CurrentLayerIndex] as TBGRALayerImageOriginal;
+end;
+
 function TEditShapeTool.GetOriginalTransform: TAffineMatrix;
 function TEditShapeTool.GetOriginalTransform: TAffineMatrix;
 begin
 begin
   result := Manager.Image.LayerOriginalMatrix[Manager.Image.CurrentLayerIndex];
   result := Manager.Image.LayerOriginalMatrix[Manager.Image.CurrentLayerIndex];
@@ -1254,6 +1260,9 @@ end;
 function TEditShapeTool.ToolCommand(ACommand: TToolCommand): boolean;
 function TEditShapeTool.ToolCommand(ACommand: TToolCommand): boolean;
 var
 var
   key: Word;
   key: Word;
+  b: TRect;
+  bmp: TBGRABitmap;
+  s: TRectShape;
 begin
 begin
   if not ToolProvideCommand(ACommand) then exit(false);
   if not ToolProvideCommand(ACommand) then exit(false);
   if ACommand = tcDelete then
   if ACommand = tcDelete then
@@ -1308,9 +1317,60 @@ begin
       finally
       finally
         BindOriginalEvent(false);
         BindOriginalEvent(false);
       end;
       end;
+    esmGradient:
+      begin
+        case ACommand of
+          tcCut,tcCopy: begin
+            s := TRectShape.Create(nil);
+            try
+              s.PenStyle := ClearPenStyle;
+              s.QuickDefine(PointF(-0.5,-0.5),PointF(Manager.Image.Width-0.5,Manager.Image.Height-0.5));
+              s.BackFill.SetGradient(GetGradientOriginal, false);
+              s.BackFill.Transform(Manager.Image.LayerOriginalMatrix[Manager.Image.CurrentLayerIndex]);
+              CopyShapesToClipboard([s],AffineMatrixIdentity);
+            finally
+              s.free;
+            end;
+            if ACommand = tcCut then ToolCommand(tcDelete);
+          end;
+          else result := false;
+        end;
+      end;
     esmOtherOriginal:
     esmOtherOriginal:
       begin
       begin
         case ACommand of
         case ACommand of
+          tcCut,tcCopy: begin
+              b := Manager.Image.CurrentLayerReadOnly.GetImageBounds;
+              if not b.IsEmpty then
+              begin
+                if GetCurrentLayerKind = lkTransformedBitmap then
+                begin
+                  bmp := GetImageOriginal.GetImageCopy;
+                  s:= TRectShape.Create(nil);
+                  s.QuickDefine(PointF(-0.5,-0.5),PointF(bmp.Width-0.5,bmp.Height-0.5));
+                  s.PenStyle := ClearPenStyle;
+                  s.BackFill.SetTexture(bmp,AffineMatrixIdentity,255,trNone);
+                  s.Transform(Manager.Image.LayerOriginalMatrix[Manager.Image.CurrentLayerIndex]);
+                  bmp.FreeReference;
+                end else
+                begin
+                  bmp := Manager.Image.CurrentLayerReadOnly.GetPart(b) as TBGRABitmap;
+                  s:= TRectShape.Create(nil);
+                  s.QuickDefine(PointF(b.Left-0.5,b.Top-0.5),PointF(b.Right-0.5,b.Bottom-0.5));
+                  s.PenStyle := ClearPenStyle;
+                  s.BackFill.SetTexture(bmp,AffineMatrixTranslation(b.Left,b.Top),255,trNone);
+                  with Manager.Image.LayerOffset[Manager.Image.CurrentLayerIndex] do
+                    s.Transform(AffineMatrixTranslation(x,y));
+                  bmp.FreeReference;
+                end;
+                try
+                  CopyShapesToClipboard([s],AffineMatrixIdentity);
+                finally
+                  s.Free;
+                end;
+                if ACommand = tcCut then ToolCommand(tcDelete);
+              end;
+            end;
           tcAlignLeft..tcAlignBottom:
           tcAlignLeft..tcAlignBottom:
               begin
               begin
                 AlignShape(FOriginalRect, ACommand,
                 AlignShape(FOriginalRect, ACommand,
@@ -1336,7 +1396,7 @@ end;
 function TEditShapeTool.ToolProvideCommand(ACommand: TToolCommand): boolean;
 function TEditShapeTool.ToolProvideCommand(ACommand: TToolCommand): boolean;
 begin
 begin
   case ACommand of
   case ACommand of
-  tcCut,tcCopy,tcDelete: result:= GetEditMode = esmShape;
+  tcCut,tcCopy,tcDelete: result:= GetEditMode in[esmShape,esmOtherOriginal,esmGradient];
   tcShapeToSpline: result:= (GetEditMode = esmShape)
   tcShapeToSpline: result:= (GetEditMode = esmShape)
                             and TCurveShape.CanCreateFrom(GetVectorOriginal.SelectedShape);
                             and TCurveShape.CanCreateFrom(GetVectorOriginal.SelectedShape);
   tcAlignLeft..tcAlignBottom: result:= GetEditMode in [esmShape, esmOtherOriginal, esmSelection];
   tcAlignLeft..tcAlignBottom: result:= GetEditMode in [esmShape, esmOtherOriginal, esmSelection];
@@ -1698,7 +1758,7 @@ begin
       MessagePopup(rsTooManyShapesInLayer, 3000);
       MessagePopup(rsTooManyShapesInLayer, 3000);
     end
     end
     else
     else
-    if GetCurrentLayerKind = lkSVG then
+    if (GetCurrentLayerKind = lkSVG) and not IsSelectingTool then
     begin
     begin
       MessagePopup(rsCannotDrawShapeOnSVGLayer, 3000);
       MessagePopup(rsCannotDrawShapeOnSVGLayer, 3000);
     end
     end