Ver Fonte

invert dependency of layer action via events

Unknown há 6 anos atrás
pai
commit
782a0224aa

+ 2 - 2
lazpaint/ucommandline.pas

@@ -119,7 +119,7 @@ begin
           val(funcParams[10],o1.y,errPos);
           val(funcParams[11],o2.x,errPos);
           val(funcParams[12],o2.y,errPos);
-          layerAction := TLayerAction.Create(instance.Image,true);
+          layerAction := instance.Image.CreateAction(true);
           layerAction.DrawingLayer.GradientFill(0,0,
             instance.Image.Width,instance.Image.Height,
             c1,c2,gt,o1,o2,dmDrawWithTransparency,True,False);
@@ -142,7 +142,7 @@ begin
             errorEncountered := true;
             exit;
           end;
-          layerAction := TLayerAction.Create(instance.Image,true);
+          layerAction := instance.Image.CreateAction(true);
           layerAction.DrawingLayer.ApplyGlobalOpacity(opacity);
           layerAction.Validate;
           FreeAndNil(layerAction);

+ 1 - 1
lazpaint/ufilterconnector.pas

@@ -122,7 +122,7 @@ begin
   ApplyOnSelectionLayer:= not FLazPaintInstance.Image.SelectionLayerIsEmpty;
 
   if AAction = nil then
-    AAction := TLayerAction.Create(ALazPaintInstance.Image, AApplyOfsBefore and not ApplyOnSelectionLayer);
+    AAction := ALazPaintInstance.Image.CreateAction(AApplyOfsBefore and not ApplyOnSelectionLayer);
 
   if ApplyOnSelectionLayer and not IsAffineMatrixIdentity(AAction.SelectionTransform) then
   begin

+ 42 - 7
lazpaint/uimage.pas

@@ -7,7 +7,7 @@ interface
 uses
   Classes, SysUtils, BGRABitmap, BGRABitmapTypes, types,
   UImageState, UStateType, Graphics, BGRALayers, UImageObservation, FPWriteBMP,
-  UImageType, UZoom, BGRATransform, BGRALayerOriginal;
+  UImageType, UZoom, BGRATransform, BGRALayerOriginal, ULayerAction;
 
 const
   MaxLayersToAdd = 99;
@@ -37,6 +37,7 @@ type
 
   TLazPaintImage = class
   private
+    FActionInProgress: TCustomLayerAction;
     FOnSelectedLayerIndexChanging: TOnCurrentLayerIndexChanged;
     FOnSelectionMaskChanged: TOnSelectionMaskChanged;
     FOnSelectedLayerIndexChanged: TOnCurrentLayerIndexChanged;
@@ -110,9 +111,10 @@ type
     procedure UpdateTiffFileUTF8(AFilename: string; AOutputFilename: string = '');
     procedure UpdateGifFileUTF8(AFilename: string; AOutputFilename: string = '');
     procedure ReplaceCurrentSelectionWithoutUndo(const AValue: TBGRABitmap);
-
+    procedure LayerActionNotifyChange(ASender: TObject; ALayer: TBGRABitmap; ARect: TRect);
+    procedure LayerActionDestroy(Sender: TObject);
+    procedure LayerActionNotifyUndo(ASender: TObject; AUndo: TCustomImageDifference; var Owned: boolean);
   public
-    ActionInProgress: TCustomLayerAction;
     OnException: TImageExceptionHandler;
     ImageOffset: TPoint;
     Zoom: TZoom;
@@ -135,6 +137,8 @@ type
     procedure CompressUndo;
     function UsedMemory: int64;
 
+    function CreateAction(AApplyOfsBefore: boolean=false): TLayerAction;
+
     // invalidating
     procedure ImageMayChange(ARect: TRect; ADiscardSelectionLayerAfterMask: boolean = true);
     procedure ImageMayChangeCompletely;
@@ -290,6 +294,14 @@ end;
 
 { TLazPaintImage }
 
+procedure TLazPaintImage.LayerActionNotifyUndo(ASender: TObject; AUndo: TCustomImageDifference;
+  var Owned: boolean);
+begin
+  AddUndo(AUndo);
+  Owned := true;
+  OnImageChanged.NotifyObservers;
+end;
+
 function TLazPaintImage.MakeCroppedLayer: TBGRABitmap;
 var r: TRect;
 begin
@@ -1002,6 +1014,17 @@ begin
       result += (TObject(FUndoList[i]) as TStateDifference).UsedMemory;
 end;
 
+function TLazPaintImage.CreateAction(AApplyOfsBefore: boolean=false): TLayerAction;
+begin
+  if not CheckNoAction(True) then
+    raise exception.Create(rsConflictingActions);
+  result := TLayerAction.Create(FCurrentState, AApplyOfsBefore);
+  result.OnNotifyChange:= @LayerActionNotifyChange;
+  result.OnDestroy:=@LayerActionDestroy;
+  result.OnNotifyUndo:=@LayerActionNotifyUndo;
+  FActionInProgress := result;
+end;
+
 procedure TLazPaintImage.ImageMayChange(ARect: TRect;
   ADiscardSelectionLayerAfterMask: boolean);
 begin
@@ -1351,14 +1374,14 @@ end;
 function TLazPaintImage.CheckNoAction(ASilent: boolean): boolean;
 begin
   result := true;
-  if ActionInProgress <> nil then
+  if FActionInProgress <> nil then
   begin
-    ActionInProgress.TryStop;
-    if ActionInProgress <> nil then
+    FActionInProgress.TryStop;
+    if FActionInProgress <> nil then
     begin
       if Assigned(FOnQueryExitToolHandler) then
         FOnQueryExitToolHandler(self);
-      if ActionInProgress <> nil then
+      if FActionInProgress <> nil then
       begin
         if not ASilent then MessagePopup(rsActionInProgress,2000);
         result := false;
@@ -1878,6 +1901,18 @@ begin
   SelectionMaskMayChangeCompletely;
 end;
 
+procedure TLazPaintImage.LayerActionNotifyChange(ASender: TObject;
+  ALayer: TBGRABitmap; ARect: TRect);
+begin
+  LayerMayChange(ALayer, ARect);
+end;
+
+procedure TLazPaintImage.LayerActionDestroy(Sender: TObject);
+begin
+  if FActionInProgress = Sender then
+    FActionInProgress := nil;
+end;
+
 procedure TLazPaintImage.ReleaseEmptySelection;
 begin
   if SelectionMaskEmpty and SelectionLayerIsEmpty then

+ 15 - 15
lazpaint/uimageaction.pas

@@ -198,7 +198,7 @@ begin
   try
     c := ToolManager.ToolBackColor;
     c.alpha := 255;
-    LayerAction := TLayerAction.Create(Image,true);
+    LayerAction := Image.CreateAction(true);
     LayerAction.SelectedImageLayer.ReplaceColor(BGRAPixelTransparent,c);
     p := LayerAction.SelectedImageLayer.Data;
     for n := LayerAction.SelectedImageLayer.NbPixels-1 downto 0 do
@@ -227,7 +227,7 @@ begin
   try
     c := ToolManager.ToolBackColor;
     c.alpha := 255;
-    LayerAction := TLayerAction.Create(Image,True);
+    LayerAction := Image.CreateAction(True);
     tempBmp := TBGRABitmap.Create(LayerAction.SelectedImageLayer.Width,1);
     for y := 0 to LayerAction.SelectedImageLayer.Height-1 do
     begin
@@ -337,7 +337,7 @@ begin
 
     if Image.CheckNoAction then
     begin
-      LayerAction := TLayerAction.Create(Image);
+      LayerAction := Image.CreateAction;
       LayerAction.RemoveSelection;
       LayerAction.QuerySelection;
       LayerAction.CurrentSelection.PutImage(0,0,newSelection,dmSet);
@@ -480,7 +480,7 @@ begin
     begin
       if not Image.SelectionMaskEmpty then
       begin
-        layeraction := TLayerAction.Create(image);
+        layeraction := image.CreateAction;
         layeraction.ReleaseSelection;
         layeraction.Validate;
         layeraction.Free;
@@ -597,7 +597,7 @@ begin
   LayerAction := nil;
   try
     if not (CurrentTool in[ptSelectRect,ptSelectEllipse]) then ChooseTool(ptSelectRect);
-    LayerAction := TLayerAction.Create(Image, false);
+    LayerAction := Image.CreateAction(false);
     LayerAction.QuerySelection;
     LayerAction.ApplySelectionTransform;
     p := LayerAction.CurrentSelection.Data;
@@ -627,7 +627,7 @@ begin
   try
     if not image.SelectionMaskEmpty then
     begin
-      LayerAction := TLayerAction.Create(Image);
+      LayerAction := Image.CreateAction;
       LayerAction.ChangeBoundsNotified:= true;
       LayerAction.ReleaseSelection;
       LayerAction.Validate;
@@ -649,7 +649,7 @@ begin
     if not image.CheckNoAction then exit;
     bounds := Image.SelectionMaskBounds;
     if IsRectEmpty(bounds) then exit;
-    LayerAction := TLayerAction.Create(Image);
+    LayerAction := Image.CreateAction;
     LayerAction.ApplySelectionMask;
     if Image.SelectionLayerIsEmpty then
       LayerAction.RetrieveSelection;
@@ -679,7 +679,7 @@ begin
   LayerAction := nil;
   try
     CopySelection;
-    LayerAction := TLayerAction.Create(Image);
+    LayerAction := Image.CreateAction;
     LayerAction.ApplySelectionTransform;
     if (LayerAction.GetSelectionLayerIfExists = nil) or (LayerAction.GetSelectionLayerIfExists.Empty) then
       LayerAction.EraseSelectionInBitmap;
@@ -703,7 +703,7 @@ begin
   if not image.CheckNoAction then exit;
   LayerAction := nil;
   try
-    LayerAction := TLayerAction.Create(Image, false);
+    LayerAction := Image.CreateAction(false);
     if LayerAction.RetrieveSelectionIfLayerEmpty(True) then
     begin
       r := Image.SelectionMaskBounds;
@@ -724,7 +724,7 @@ begin
   if not image.CheckNoAction then exit;
   LayerAction := nil;
   try
-    LayerAction := TLayerAction.Create(Image);
+    LayerAction := Image.CreateAction;
     if Image.SelectionLayerIsEmpty then
     begin
       LayerAction.ApplySelectionTransform;
@@ -749,7 +749,7 @@ begin
   if not image.CheckNoAction then exit;
   LayerAction := nil;
   try
-    LayerAction := TLayerAction.Create(Image);
+    LayerAction := Image.CreateAction;
     LayerAction.RemoveSelection;
     LayerAction.Validate;
     if (CurrentTool = ptRotateSelection) or
@@ -772,7 +772,7 @@ begin
       if partial.NbPixels <> 0 then
       begin
         ToolManager.ToolCloseDontReopen;
-        layeraction := TLayerAction.Create(Image, true);
+        layeraction := Image.CreateAction(true);
         layeraction.ReleaseSelection;
         layeraction.QuerySelection;
         pastePos := Point((image.Width - partial.Width) div 2 - image.ImageOffset.X,
@@ -823,7 +823,7 @@ var LayerAction : TLayerAction;
 begin
   try
     if not ToolManager.IsSelectingTool then ChooseTool(ptSelectRect);
-    LayerAction := TLayerAction.Create(Image);
+    LayerAction := Image.CreateAction;
     LayerAction.QuerySelection;
     LayerAction.currentSelection.Fill(BGRAWhite);
     Image.SelectionMaskMayChangeCompletely;
@@ -841,7 +841,7 @@ var LayerAction: TLayerAction;
 begin
   if not image.CheckNoAction then exit;
   try
-    LayerAction := TLayerAction.Create(Image);
+    LayerAction := Image.CreateAction;
     LayerAction.ChangeBoundsNotified := true;
 
     if image.SelectionMaskEmpty then
@@ -946,7 +946,7 @@ var lSelection,lTemp: TBGRABitmap;
 begin
   if not image.CheckNoAction then exit;
   try
-    LayerAction := TLayerAction.Create(Image);
+    LayerAction := Image.CreateAction;
     try
       LayerAction.QuerySelection;
       lSelection:= LayerAction.currentSelection.Duplicate as TBGRABitmap;

+ 76 - 37
lazpaint/ulayeraction.pas

@@ -5,16 +5,22 @@ unit ULayerAction;
 interface
 
 uses
-  Classes, SysUtils, UImage, BGRABitmap, BGRABitmapTypes, UImageType,
+  Classes, SysUtils, BGRABitmap, BGRABitmapTypes, UImageType,
   UStateType, UImageState;
 
 type
+  TNotifyChangeEvent = procedure(ASender: TObject; ALayer: TBGRABitmap; ARect: TRect) of object;
+  TNotifyUndoEvent = procedure(ASender: TObject; AUndo: TCustomImageDifference; var Owned: boolean) of object;
+
   { TLayerAction }
 
   TLayerAction = class(TCustomLayerAction)
   private
     FChangeBoundsNotified: boolean;
-    FImage: TLazPaintImage;
+    FImageState: TImageState;
+    FOnDestroy: TNotifyEvent;
+    FOnNotifyChange: TNotifyChangeEvent;
+    FOnNotifyUndo: TNotifyUndoEvent;
     FPrediff: TComposedImageDifference;
     FBackupSelectedLayer, FBackupSelectionLayer, FBackupSelection: TBGRABitmap;
     FBackupSelectedLayerDefined, FBackupSelectionLayerDefined, FBackupSelectionMaskDefined: boolean;
@@ -33,6 +39,9 @@ type
     function GetSelectedImageLayerOffset: TPoint;
     function GetSelectionLayerBounds: TRect;
     function GetSelectionTransform: TAffineMatrix;
+    procedure SetOnDestroy(AValue: TNotifyEvent);
+    procedure SetOnNotifyChange(AValue: TNotifyChangeEvent);
+    procedure SetOnNotifyUndo(AValue: TNotifyUndoEvent);
   protected
     procedure Cancel;
     procedure NeedSelectionMaskBackup;
@@ -40,7 +49,7 @@ type
     procedure NeedSelectionLayerBackup;
     property CurrentState: TImageState read GetCurrentState;
   public
-    constructor Create(AImage: TLazPaintImage; AApplyOfsBefore: boolean = false);
+    constructor Create(AState: TImageState; AApplyOfsBefore: boolean = false);
     procedure Validate;
     procedure PartialValidate(ADiscardBackup: boolean = false);
     procedure PartialCancel;
@@ -81,6 +90,9 @@ type
     property ChangeBoundsNotified: boolean read FChangeBoundsNotified write FChangeBoundsNotified;
     property SelectionTransform: TAffineMatrix read GetSelectionTransform;
     property SelectionLayerBounds: TRect read GetSelectionLayerBounds;
+    property OnNotifyChange: TNotifyChangeEvent read FOnNotifyChange write SetOnNotifyChange;
+    property OnNotifyUndo: TNotifyUndoEvent read FOnNotifyUndo write SetOnNotifyUndo;
+    property OnDestroy: TNotifyEvent read FOnDestroy write SetOnDestroy;
   end;
 
 implementation
@@ -105,7 +117,7 @@ end;
 
 function TLayerAction.GetCurrentState: TImageState;
 begin
-  result := FImage.CurrentState;
+  result := FImageState;
 end;
 
 function TLayerAction.GetBackupSelectedLayer: TBGRABitmap;
@@ -116,7 +128,7 @@ end;
 
 function TLayerAction.GetBackupDrawingLayer: TBGRABitmap;
 begin
-  if FImage.SelectionMaskEmpty then result := BackupSelectedLayer else
+  if CurrentState.SelectionMaskEmpty then result := BackupSelectedLayer else
     result := BackupSelectionLayer;
 end;
 
@@ -134,7 +146,7 @@ end;
 
 function TLayerAction.GetDrawingLayer: TBGRABitmap;
 begin
-  if FImage.SelectionMaskEmpty then result := GetSelectedImageLayer else
+  if CurrentState.SelectionMaskEmpty then result := GetSelectedImageLayer else
     result := GetOrCreateSelectionLayer;
 end;
 
@@ -153,6 +165,24 @@ begin
   result:= CurrentState.SelectionTransform;
 end;
 
+procedure TLayerAction.SetOnDestroy(AValue: TNotifyEvent);
+begin
+  if FOnDestroy=AValue then Exit;
+  FOnDestroy:=AValue;
+end;
+
+procedure TLayerAction.SetOnNotifyChange(AValue: TNotifyChangeEvent);
+begin
+  if FOnNotifyChange=AValue then Exit;
+  FOnNotifyChange:=AValue;
+end;
+
+procedure TLayerAction.SetOnNotifyUndo(AValue: TNotifyUndoEvent);
+begin
+  if FOnNotifyUndo=AValue then Exit;
+  FOnNotifyUndo:=AValue;
+end;
+
 procedure TLayerAction.Cancel;
 begin
   if FDone then raise Exception.Create('Already done');
@@ -195,17 +225,11 @@ begin
   end;
 end;
 
-constructor TLayerAction.Create(AImage: TLazPaintImage; AApplyOfsBefore: boolean = false);
+constructor TLayerAction.Create(AState: TImageState; AApplyOfsBefore: boolean);
 var
   layerOfsDiff: TCustomImageDifference;
 begin
-  if AImage <> nil then
-  begin
-    if not AImage.CheckNoAction(True) then
-      raise exception.Create(rsConflictingActions);
-  end;
-  FImage := AImage;
-  FImage.ActionInProgress := self;
+  FImageState := AState;
   FBackupSelectedLayer := nil;
   FBackupSelection := nil;
   FBackupSelectionLayer := nil;
@@ -220,7 +244,7 @@ begin
   FPrediff := TComposedImageDifference.Create;
   if AApplyOfsBefore then
   begin
-    with AImage.LayerOffset[AImage.CurrentLayerIndex] do
+    with CurrentState.LayerOffset[CurrentState.SelectedImageLayerIndex] do
       layerOfsDiff := CurrentState.ComputeLayerOffsetDifference(X,Y);
     if layerOfsDiff.IsIdentity then FreeAndNil(layerOfsDiff)
     else
@@ -238,11 +262,7 @@ begin
   FBackupSelectedLayer.Free;
   FBackupSelection.Free;
   FBackupSelectionLayer.Free;
-  if FImage <> nil then
-  begin
-    if FImage.ActionInProgress = self then
-      FImage.ActionInProgress := nil;
-  end;
+  if Assigned(FOnDestroy) then FOnDestroy(self);
   inherited Destroy;
 end;
 
@@ -275,7 +295,8 @@ begin
     FSelectedImageLayerChangedArea := RectUnion(FSelectedImageLayerChangedArea, ARect)
   else if ADest = CurrentState.SelectionLayer then
     FSelectionLayerChangedArea := RectUnion(FSelectionLayerChangedArea, ARect);
-  FImage.LayerMayChange(ADest, ARect);
+  if Assigned(FOnNotifyChange) then
+    FOnNotifyChange(self, ADest, ARect);
 end;
 
 procedure TLayerAction.RestoreSelectionMask;
@@ -292,14 +313,15 @@ begin
     else
       CurrentState.SelectionMask.FillRect(0,0,CurrentState.Width,CurrentState.Height,BGRABlack,dmSet);
     CurrentState.SelectionMask.ClipRect := prevClip;
-    FImage.SelectionMaskMayChange(FSelectionMaskChangedArea);
+    If Assigned(FOnNotifyChange) then
+      FOnNotifyChange(self, CurrentState.SelectionMask, FSelectionMaskChangedArea);
     FSelectionMaskChangedArea := EmptyRect;
   end;
 end;
 
 procedure TLayerAction.RestoreDrawingLayer;
 begin
-  if FImage.SelectionMaskEmpty then RestoreSelectedLayer
+  if CurrentState.SelectionMaskEmpty then RestoreSelectedLayer
     else RestoreSelectionLayer;
 end;
 
@@ -317,7 +339,8 @@ begin
     else
       CurrentState.SelectedImageLayer.FillRect(0,0,CurrentState.Width,CurrentState.Height,BGRAPixelTransparent,dmSet);
     CurrentState.SelectedImageLayer.ClipRect := prevClip;
-    FImage.LayerMayChange(CurrentState.SelectedImageLayer,FSelectedImageLayerChangedArea);
+    If Assigned(FOnNotifyChange) then
+      FOnNotifyChange(self, CurrentState.SelectedImageLayer, FSelectedImageLayerChangedArea);
     FSelectedImageLayerChangedArea := EmptyRect;
   end;
 end;
@@ -336,7 +359,8 @@ begin
     else
       CurrentState.SelectionLayer.FillRect(0,0,CurrentState.Width,CurrentState.Height,BGRAPixelTransparent,dmSet);
     CurrentState.SelectionLayer.ClipRect := prevClip;
-    FImage.LayerMayChange(CurrentState.SelectionLayer,FSelectionLayerChangedArea);
+    If Assigned(FOnNotifyChange) then
+      FOnNotifyChange(self, CurrentState.SelectionLayer, FSelectionLayerChangedArea);
     FSelectionLayerChangedArea := EmptyRect;
   end;
 end;
@@ -356,7 +380,7 @@ end;
 procedure TLayerAction.RemoveSelection;
 var bounds: TRect;
 begin
-  if not FImage.SelectionMaskEmpty or (FImage.SelectionLayerReadonly <> nil) then
+  if not CurrentState.SelectionMaskEmpty or (CurrentState.SelectionLayer <> nil) then
   begin
     NeedSelectionMaskBackup;
     NeedSelectionLayerBackup;
@@ -406,9 +430,9 @@ end;
 procedure TLayerAction.ReleaseSelection;
 var bounds: TRect;
 begin
-  if not FImage.SelectionMaskEmpty then
+  if not CurrentState.SelectionMaskEmpty then
   begin
-    bounds := FImage.SelectionMaskBounds;
+    bounds := CurrentState.GetSelectionMaskBounds;
     NeedSelectionMaskBackup;
     NotifyChange(CurrentState.SelectionMask, bounds);
     if CurrentState.SelectionLayer <> nil then
@@ -432,7 +456,7 @@ var temp : TBGRABitmap;
   offs: TPoint;
   r, maskBounds: TRect;
 begin
-  if not FImage.SelectionMaskEmpty then
+  if not CurrentState.SelectionMaskEmpty then
   begin
     NeedSelectedLayerBackup;
     NeedSelectionLayerBackup;
@@ -565,7 +589,7 @@ var
   composedDiff: TComposedImageDifference;
   ofs: TPoint;
   applyOfs: TCustomImageDifference;
-  appendOfs: boolean;
+  appendOfs, owned: boolean;
 begin
   if FBackupSelectedLayerDefined or FBackupSelectionMaskDefined or FBackupSelectionLayerDefined then
   begin
@@ -581,7 +605,7 @@ begin
     if FBackupSelectionMaskDefined then
     begin
       CurrentState.DiscardSelectionMaskBounds;
-      if FImage.SelectionMaskEmpty then
+      if CurrentState.SelectionMaskEmpty then
         CurrentState.RemoveSelection;
     end;
     //original will be backed up if there are changes in the raster image of the selected layer
@@ -656,7 +680,7 @@ begin
       begin
         if (FBackupSelection = nil) and (CurrentState.SelectionMask <> nil) then
         begin
-          if not FImage.SelectionMaskEmpty then
+          if not CurrentState.SelectionMaskEmpty then
             FBackupSelection := CurrentState.SelectionMask.Duplicate as TBGRABitmap;
         end else
         if (FBackupSelection <> nil) then
@@ -696,19 +720,34 @@ begin
           end else
             applyOfs.Free;
         end;
-        FImage.AddUndo(composedDiff);
+        if Assigned(FOnNotifyUndo) then
+        begin
+          owned := false;
+          FOnNotifyUndo(self, composedDiff, owned);
+          if not owned then composedDiff.Free;
+        end;
       end else
-        FImage.AddUndo(imgDiff);
+      begin
+        if Assigned(FOnNotifyUndo) then
+        begin
+          owned := false;
+          FOnNotifyUndo(self, imgDiff, owned);
+          if not owned then imgDiff.Free;
+        end;
+      end;
     end;
 
     FBackupSelectionTransform := CurrentState.SelectionTransform;
-
-    FImage.OnImageChanged.NotifyObservers;
   end else
   begin
     if Assigned(FPrediff) then
     begin
-      FImage.AddUndo(FPrediff);
+      if Assigned(FOnNotifyUndo) then
+      begin
+        owned := false;
+        FOnNotifyUndo(self, FPrediff, owned);
+        if not owned then FPrediff.Free;
+      end;
       FPrediff := nil;
     end;
   end;

+ 1 - 1
lazpaint/upalettetoolbar.pas

@@ -491,7 +491,7 @@ begin
   quant := TBGRAColorQuantizer.Create(FColors, not FTransparentPalette);
   LayerAction := nil;
   try
-    LayerAction := TLayerAction.Create(LazPaintInstance.Image);
+    LayerAction := LazPaintInstance.Image.CreateAction;
     quant.ApplyDitheringInplace(ADither,LayerAction.SelectedImageLayer);
     LazPaintInstance.image.LayerMayChangeCompletely(LayerAction.SelectedImageLayer);
     LayerAction.Validate;

+ 1 - 1
lazpaint/utool.pas

@@ -398,7 +398,7 @@ var
 begin
   if not Assigned(FAction) then
   begin
-    FAction := TLayerAction.Create(Manager.Image, not IsSelectingTool And Manager.Image.SelectionMaskEmpty);
+    FAction := Manager.Image.CreateAction(not IsSelectingTool And Manager.Image.SelectionMaskEmpty);
     FAction.OnTryStop := @OnTryStop;
     FAction.ChangeBoundsNotified:= true;
     if IsSelectingTool or not Manager.Image.SelectionMaskEmpty then