Przeglądaj źródła

refactor tool manager

johann 5 lat temu
rodzic
commit
b6f6294139

+ 23 - 4
lazpaint/lazpaintmainform.pas

@@ -677,10 +677,11 @@ type
     procedure ComboBox_PenStyleDrawSelectedItem(Sender: TObject;
       const ABGRA: TBGRABitmap; AState: TBCButtonState; ARect: TRect);
     function GetImage: TLazPaintImage;
+    procedure ManagerEraserChanged(Sender: TObject);
     procedure ManagerGradientChanged(Sender: TObject);
     procedure ManagerJoinStyleChanged(Sender: TObject);
     procedure ManagerLineCapChanged(Sender: TObject);
-    procedure ManagerOnPhongShapeChanged(Sender: TObject);
+    procedure ManagerPhongShapeChanged(Sender: TObject);
     procedure ManagerPenStyleChanged(Sender: TObject);
     procedure ManagerPenWidthChanged(Sender: TObject);
     procedure ManagerSplineStyleChanged(Sender: TObject);
@@ -690,6 +691,7 @@ type
     procedure ManagerTextShadowChanged(Sender: TObject);
     procedure ManagerTextureChanged(Sender: TObject);
     procedure ManagerShapeOptionChanged(Sender: TObject);
+    procedure ManagerToleranceChanged(Sender: TObject);
   private
     { private declarations }
     FLayout: TMainFormLayout;
@@ -712,6 +714,7 @@ type
     FSaveSelectionInitialFilename: string;
     FInTextFont: boolean;
     FInPenWidthChange: boolean;
+    FInEraserOption: Boolean;
     FOnlineUpdater: TLazPaintCustomOnlineUpdater;
     initialized: boolean;
     shouldArrangeOnResize: boolean;
@@ -752,6 +755,7 @@ type
     procedure RegisterToolbarElements;
     procedure InitToolbarElements;
     procedure UpdateToolOptions;
+    procedure UpdateEraserToolbar;
     procedure UpdatePenStyleToolbar;
     procedure UpdateJoinStyleToolbar;
     procedure UpdateTextFontToolbar;
@@ -763,6 +767,7 @@ type
     procedure UpdateGradientToolbar;
     procedure UpdatePenWidthToolbar;
     procedure UpdatePhongToolbar;
+    procedure UpdateToleranceToolbar;
     function ShowOpenBrushDialog: boolean;
     function TextSpinEditFocused: boolean;
     procedure UpdateBrush;
@@ -990,6 +995,7 @@ begin
   begin
     if ToolManager.OnToolChanged = @ManagerToolChanged then ToolManager.OnToolChanged := nil;
     if ToolManager.OnTextureChanged = @ManagerTextureChanged then ToolManager.OnTextureChanged := nil;
+    if ToolManager.OnEraserChanged = @ManagerEraserChanged then ToolManager.OnEraserChanged := nil;
     if ToolManager.OnPenWidthChanged = @ManagerPenWidthChanged then ToolManager.OnPenWidthChanged := nil;
     if ToolManager.OnPenStyleChanged = @ManagerPenStyleChanged then ToolManager.OnPenStyleChanged := nil;
     if ToolManager.OnJoinStyleChanged = @ManagerJoinStyleChanged then ToolManager.OnJoinStyleChanged := nil;
@@ -1001,7 +1007,8 @@ begin
     if ToolManager.OnLineCapChanged = @ManagerLineCapChanged then ToolManager.OnLineCapChanged := nil;
     if ToolManager.OnSplineStyleChanged = @ManagerSplineStyleChanged then ToolManager.OnSplineStyleChanged := nil;
     if ToolManager.OnGradientChanged = @ManagerGradientChanged then ToolManager.OnGradientChanged := nil;
-    if ToolManager.OnPhongShapeChanged = @ManagerOnPhongShapeChanged then ToolManager.OnPhongShapeChanged := nil;
+    if ToolManager.OnPhongShapeChanged = @ManagerPhongShapeChanged then ToolManager.OnPhongShapeChanged := nil;
+    if ToolManager.OnToleranceChanged = @ManagerToleranceChanged then ToolManager.OnToleranceChanged := nil;
   end;
   FreeAndNil(Zoom);
   FreeAndNil(FOnlineUpdater);
@@ -1062,6 +1069,7 @@ begin
   ToolManager.SetCurrentToolType(ptHand);
   ToolManager.OnToolChanged  :=  @ManagerToolChanged;
   ToolManager.OnTextureChanged := @ManagerTextureChanged;
+  ToolManager.OnEraserChanged:=@ManagerEraserChanged;
   ToolManager.OnPenWidthChanged:= @ManagerPenWidthChanged;
   ToolManager.OnPenStyleChanged:= @ManagerPenStyleChanged;
   ToolManager.OnJoinStyleChanged:= @ManagerJoinStyleChanged;
@@ -1073,7 +1081,8 @@ begin
   ToolManager.OnLineCapChanged := @ManagerLineCapChanged;
   ToolManager.OnSplineStyleChanged:=@ManagerSplineStyleChanged;
   ToolManager.OnGradientChanged:=@ManagerGradientChanged;
-  ToolManager.OnPhongShapeChanged:=@ManagerOnPhongShapeChanged;
+  ToolManager.OnPhongShapeChanged:=@ManagerPhongShapeChanged;
+  ToolManager.OnToleranceChanged:=@ManagerToleranceChanged;
 
   InitToolbarElements;
 
@@ -4234,6 +4243,11 @@ begin
   result := LazPaintInstance.Image;
 end;
 
+procedure TFMain.ManagerEraserChanged(Sender: TObject);
+begin
+  UpdateEraserToolbar;
+end;
+
 procedure TFMain.ManagerGradientChanged(Sender: TObject);
 begin
   UpdateGradientToolbar;
@@ -4249,7 +4263,7 @@ begin
   UpdateLineCapToolbar;
 end;
 
-procedure TFMain.ManagerOnPhongShapeChanged(Sender: TObject);
+procedure TFMain.ManagerPhongShapeChanged(Sender: TObject);
 begin
   UpdatePhongToolbar;
 end;
@@ -4301,6 +4315,11 @@ begin
   FLayout.Arrange;
 end;
 
+procedure TFMain.ManagerToleranceChanged(Sender: TObject);
+begin
+  UpdateToleranceToolbar;
+end;
+
 procedure TFMain.UpdateStatusText;
 var s: string;
 begin

+ 52 - 30
lazpaint/maintoolbar.inc

@@ -298,6 +298,18 @@ begin
   UpdateLineCapBar;
 end;
 
+procedure TFMain.UpdateEraserToolbar;
+begin
+  if FInEraserOption then exit;
+  FInEraserOption:= true;
+  case ToolManager.EraserMode of
+  emEraseAlpha: Tool_EraseAlpha.Down:= true;
+  emSoften: Tool_EraseBlur.Down:= true;
+  end;
+  SpinEdit_Eraser.Value := ToolManager.EraserAlpha;
+  FInEraserOption:= false;
+end;
+
 procedure TFMain.UpdatePenStyleToolbar;
 begin
   ComboBox_PenStyle.ItemIndex := ord(ToolManager.PenStyle);
@@ -339,6 +351,11 @@ begin
   SpinEdit_PhongBorderSize.Value := ToolManager.PhongShapeBorderSize;
 end;
 
+procedure TFMain.UpdateToleranceToolbar;
+begin
+  SpinEdit_Tolerance.Value:= ToolManager.Tolerance;
+end;
+
 procedure TFMain.UpdateJoinStyleToolbar;
 begin
   case ToolManager.JoinStyle of
@@ -422,8 +439,8 @@ begin
   end;
   UpdateLineCapToolbar;
   UpdateToolOptions;
-  SpinEdit_Eraser.Value := ToolManager.ToolEraserAlpha;
-  SpinEdit_Tolerance.Value := ToolManager.ToolTolerance;
+  SpinEdit_Eraser.Value := ToolManager.EraserAlpha;
+  SpinEdit_Tolerance.Value := ToolManager.Tolerance;
   Tool_ProgressiveFloodfill.Down := ToolManager.ToolFloodFillOptionProgressive;
   UpdateGradientToolbar;
   Tool_GridMoveWithoutDeformation.Down := ToolManager.ToolDeformationGridMoveWithoutDeformation;
@@ -658,7 +675,7 @@ end;
 procedure TFMain.GridNb_SpinEditChange(Sender: TObject; AByUser: boolean);
 begin
   if not AByUser or not initialized then exit;
-  if ToolManager.SetDeformationGridSize(SpinEdit_GridNbX.Value+1,SpinEdit_GridNbY.Value+1) then
+  if ToolManager.SetDeformationGridSize(Size(SpinEdit_GridNbX.Value+1,SpinEdit_GridNbY.Value+1)) then
     image.OnImageChanged.NotifyObservers;
 end;
 
@@ -810,8 +827,8 @@ procedure TFMain.SpinEdit_ToleranceChange(Sender: TObject; AByUser: boolean);
 begin
   if AByUser and initialized then
   begin
-    if ToolManager.ToolTolerance = SpinEdit_Tolerance.Value then exit;
-    ToolManager.ToolTolerance := SpinEdit_Tolerance.Value;
+    if ToolManager.Tolerance = SpinEdit_Tolerance.Value then exit;
+    ToolManager.Tolerance := SpinEdit_Tolerance.Value;
   end;
 end;
 
@@ -1078,17 +1095,22 @@ end;
 
 procedure TFMain.SpinEdit_EraserChange(Sender: TObject; AByUser: boolean);
 begin
-    if AByUser and initialized then
+    if AByUser and initialized and not FInEraserOption then
     begin
-      if ToolManager.ToolEraserAlpha = SpinEdit_Eraser.value then exit;
-      ToolManager.ToolEraserAlpha := SpinEdit_Eraser.Value;
+      if ToolManager.EraserAlpha = SpinEdit_Eraser.value then exit;
+      FInEraserOption := true;
+      ToolManager.EraserAlpha := SpinEdit_Eraser.Value;
+      FInEraserOption := false;
     end;
 end;
 
 procedure TFMain.Tool_EraseOptionClick(Sender: TObject);
 begin
-  if Tool_EraseAlpha.Down then ToolManager.ToolEraserMode:= emEraseAlpha else
-  if Tool_EraseBlur.Down then ToolManager.ToolEraserMode:= emSoften;
+  if FInEraserOption then exit;
+  FInEraserOption := true;
+  if Tool_EraseAlpha.Down then ToolManager.EraserMode:= emEraseAlpha else
+  if Tool_EraseBlur.Down then ToolManager.EraserMode:= emSoften;
+  FInEraserOption := false;
 end;
 
 procedure TFMain.Tool_GridMoveWithoutDeformationClick(Sender: TObject);
@@ -1383,38 +1405,38 @@ end;
 
 procedure TFMain.Tool_LinearGradientClick(Sender: TObject);
 begin
-     if Tool_LinearGradient.Down then
-     begin
-       ToolManager.GradientType := gtLinear;
-       UpdateEditPicture;
-     end;
+  if Tool_LinearGradient.Down then
+  begin
+    ToolManager.GradientType := gtLinear;
+    UpdateEditPicture;
+  end;
 end;
 
 procedure TFMain.Tool_ReflectedGradientClick(Sender: TObject);
 begin
-     if Tool_ReflectedGradient.Down then
-     begin
-       ToolManager.GradientType := gtReflected;
-       UpdateEditPicture;
-     end;
+  if Tool_ReflectedGradient.Down then
+  begin
+    ToolManager.GradientType := gtReflected;
+    UpdateEditPicture;
+  end;
 end;
 
 procedure TFMain.Tool_DiamondGradientClick(Sender: TObject);
 begin
-     if Tool_DiamondGradient.Down then
-     begin
-       ToolManager.GradientType := gtDiamond;
-       UpdateEditPicture;
-     end;
+  if Tool_DiamondGradient.Down then
+  begin
+    ToolManager.GradientType := gtDiamond;
+    UpdateEditPicture;
+  end;
 end;
 
 procedure TFMain.Tool_RadialGradientClick(Sender: TObject);
 begin
-     if Tool_RadialGradient.Down then
-     begin
-       ToolManager.GradientType := gtRadial;
-       UpdateEditPicture;
-     end;
+  if Tool_RadialGradient.Down then
+  begin
+    ToolManager.GradientType := gtRadial;
+    UpdateEditPicture;
+  end;
 end;
 
 procedure TFMain.Tool_SinGradientClick(Sender: TObject);

+ 130 - 80
lazpaint/tools/utool.pas

@@ -5,7 +5,7 @@ unit UTool;
 interface
 
 uses
-  Classes, SysUtils, Graphics, BGRABitmap, BGRABitmapTypes, uimage, UImageType,
+  Classes, Types, SysUtils, Graphics, BGRABitmap, BGRABitmapTypes, uimage, UImageType,
   ULayerAction, LCLType, Controls, UBrushType, UConfig, LCVectorPolyShapes,
   BGRAGradientScanner, BGRALayerOriginal, LCVectorRectShapes;
 
@@ -138,37 +138,27 @@ type
 
   TToolManager = class
   private
-    FOnColorChanged: TNotifyEvent;
-    FOnGradientChanged: TNotifyEvent;
-    FOnJoinStyleChanged: TNotifyEvent;
-    FOnLineCapChanged: TNotifyEvent;
-    FOnPenStyleChanged: TNotifyEvent;
-    FOnPenWidthChanged: TNotifyEvent;
-    FOnPhongShapeChanged: TNotifyEvent;
-    FOnSplineStyleChanged: TNotifyEvent;
-    FOnTextFontChanged: TNotifyEvent;
-    FOnTextOutlineChanged: TNotifyEvent;
-    FOnTextPhongChanged: TNotifyEvent;
-    FOnTextShadowChanged: TNotifyEvent;
-    FOnTextureChanged: TNotifyEvent;
-    FOnShapeOptionChanged: TNotifyEvent;
+    FConfigProvider: IConfigProvider;
     FShouldExitTool: boolean;
-    FOnToolChangedHandler: TOnToolChangedHandler;
-    FOnPopupToolHandler: TOnPopupToolHandler;
     FImage: TLazPaintImage;
+    FBlackAndWhite: boolean;
     FCurrentTool : TGenericTool;
     FCurrentToolType : TPaintToolType;
+    FToolCurrentCursorPos: TPointF;
     FSleepingTool: TGenericTool;
     FSleepingToolType: TPaintToolType;
-    FDeformationGridNbX,FDeformationGridNbY: integer;
+    FReturnValidatesHintShown: boolean;
+    FOnToolChangedHandler: TOnToolChangedHandler;
+    FOnPopupToolHandler: TOnPopupToolHandler;
+
     FForeColor, FBackColor: TBGRAPixel;
-    FReturnValidatesHintShowed: boolean;
+    FEraserMode: TEraserMode;
+    FEraserAlpha: byte;
     FTexture: TBGRABitmap;
     FTextureAfterAlpha: TBGRABitmap;
     FTextureOpactiy: byte;
     FBrushInfoList: TList;
     FBrushInfoListChanged: boolean;
-    FConfigProvider: IConfigProvider;
     FPenStyle: TPenStyle;
     FJoinStyle: TPenJoinStyle;
     FNormalPenWidth, FEraserWidth: Single;
@@ -188,6 +178,25 @@ type
     FPhongShapeAltitude: integer;
     FPhongShapeBorderSize: integer;
     FPhongShapeKind: TPhongShapeKind;
+    FDeformationGridNbX,FDeformationGridNbY: integer;
+    FTolerance: byte;
+
+    FOnColorChanged: TNotifyEvent;
+    FOnEraserChanged: TNotifyEvent;
+    FOnGradientChanged: TNotifyEvent;
+    FOnJoinStyleChanged: TNotifyEvent;
+    FOnLineCapChanged: TNotifyEvent;
+    FOnPenStyleChanged: TNotifyEvent;
+    FOnPenWidthChanged: TNotifyEvent;
+    FOnPhongShapeChanged: TNotifyEvent;
+    FOnSplineStyleChanged: TNotifyEvent;
+    FOnTextFontChanged: TNotifyEvent;
+    FOnTextOutlineChanged: TNotifyEvent;
+    FOnTextPhongChanged: TNotifyEvent;
+    FOnTextShadowChanged: TNotifyEvent;
+    FOnTextureChanged: TNotifyEvent;
+    FOnShapeOptionChanged: TNotifyEvent;
+    FOnToleranceChanged: TNotifyEvent;
 
     function GetCursor: TCursor;
     function GetBackColor: TBGRAPixel;
@@ -209,6 +218,8 @@ type
     procedure SetArrowSize(AValue: TPointF);
     procedure SetArrowStart(AValue: TArrowKind);
     procedure SetBackColor(AValue: TBGRAPixel);
+    procedure SetEraserAlpha(AValue: byte);
+    procedure SetEraserMode(AValue: TEraserMode);
     procedure SetForeColor(AValue: TBGRAPixel);
     procedure SetGradientColorspace(AValue: TBGRAColorInterpolation);
     procedure SetGradientSine(AValue: boolean);
@@ -225,6 +236,7 @@ type
     procedure SetTextPhong(AValue: boolean);
     procedure SetTextShadow(AValue: boolean);
     procedure SetTextureOpacity(AValue: byte);
+    procedure SetTolerance(AValue: byte);
     procedure ToolCloseAndReopenImmediatly;
   protected
     function CheckExitTool: boolean;
@@ -232,6 +244,7 @@ type
     procedure InternalSetCurrentToolType(tool: TPaintToolType);
     function InternalBitmapToVirtualScreen(PtF: TPointF): TPointF;
     function AddLayerOffset(ARect: TRect) : TRect;
+    procedure SetDeformationGridSizeProc(const ASize: TSize);
   public
     BitmapToVirtualScreen: TBitmapToVirtualScreenFunction;
     PenWidthControls, AliasingControls, EraserControls, ToleranceControls,
@@ -241,12 +254,7 @@ type
     PerspectiveControls,PenColorControls,TextureControls,
     BrushControls, RatioControls: TList;
 
-    BlackAndWhite: boolean;
-
     //tools configuration
-    ToolEraserMode: TEraserMode;
-    ToolCurrentCursorPos: TPointF;
-    ToolEraserAlpha, ToolTolerance: byte;
     ToolFloodFillOptionProgressive: boolean;
     ToolPerspectiveRepeat,ToolPerspectiveTwoPlanes: boolean;
     ToolDeformationGridMoveWithoutDeformation: boolean;
@@ -300,15 +308,6 @@ type
     procedure RenderTool(formBitmap: TBGRABitmap);
     function GetRenderBounds(VirtualScreenWidth, VirtualScreenHeight: integer): TRect;
 
-    property Image: TLazPaintImage read FImage;
-    property CurrentTool: TGenericTool read FCurrentTool;
-
-    property DeformationGridNbX: integer read FDeformationGridNbX;
-    property DeformationGridNbY: integer read FDeformationGridNbY;
-    property ForeColor: TBGRAPixel read GetForeColor write SetForeColor;
-    property BackColor: TBGRAPixel read GetBackColor write SetBackColor;
-
-    function SetDeformationGridSize(NbX,NbY: integer): boolean;
     procedure SwapToolColors;
     procedure SetTexture(ATexture: TBGRABitmap); overload;
     procedure SetTexture(ATexture: TBGRABitmap; AOpacity: byte); overload;
@@ -321,25 +320,22 @@ type
     procedure SetTextFont(AFont: TFont);
     function GetTextFont: TFont;
     procedure SetTextOutline(AEnabled: boolean; AWidth: single);
+    function GetDeformationGridSize: TSize;
+    function SetDeformationGridSize(ASize: TSize): boolean;
 
-    property OnToolChanged: TOnToolChangedHandler read FOnToolChangedHandler write FOnToolChangedHandler;
-    property OnPopup: TOnPopupToolHandler read FOnPopupToolHandler write FOnPopupToolHandler;
-    property OnTextureChanged: TNotifyEvent read FOnTextureChanged write FOnTextureChanged;
-    property OnColorChanged: TNotifyEvent read FOnColorChanged write FOnColorChanged;
-    property OnPenWidthChanged: TNotifyEvent read FOnPenWidthChanged write FOnPenWidthChanged;
-    property OnPenStyleChanged: TNotifyEvent read FOnPenStyleChanged write FOnPenStyleChanged;
-    property OnJoinStyleChanged: TNotifyEvent read FOnJoinStyleChanged write FOnJoinStyleChanged;
-    property OnShapeOptionChanged: TNotifyEvent read FOnShapeOptionChanged write FOnShapeOptionChanged;
-    property OnTextFontChanged: TNotifyEvent read FOnTextFontChanged write FOnTextFontChanged;
-    property OnTextOutlineChanged: TNotifyEvent read FOnTextOutlineChanged write FOnTextOutlineChanged;
-    property OnTextPhongChanged: TNotifyEvent read FOnTextPhongChanged write FOnTextPhongChanged;
-    property OnTextShadowChanged: TNotifyEvent read FOnTextShadowChanged write FOnTextShadowChanged;
-    property OnLineCapChanged: TNotifyEvent read FOnLineCapChanged write FOnLineCapChanged;
-    property OnSplineStyleChanged: TNotifyEvent read FOnSplineStyleChanged write FOnSplineStyleChanged;
-    property OnGradientChanged: TNotifyEvent read FOnGradientChanged write FOnGradientChanged;
-    property OnPhongShapeChanged: TNotifyEvent read FOnPhongShapeChanged write FOnPhongShapeChanged;
-    property Cursor: TCursor read GetCursor;
+    property Image: TLazPaintImage read FImage;
+    property BlackAndWhite: boolean read FBlackAndWhite write FBlackAndWhite;
+    property CurrentTool: TGenericTool read FCurrentTool;
+    property ToolCurrentCursorPos: TPointF read FToolCurrentCursorPos;
     property ToolSleeping: boolean read GetToolSleeping;
+    property Cursor: TCursor read GetCursor;
+
+    property ForeColor: TBGRAPixel read GetForeColor write SetForeColor;
+    property BackColor: TBGRAPixel read GetBackColor write SetBackColor;
+    property EraserMode: TEraserMode read FEraserMode write SetEraserMode;
+    property EraserAlpha: byte read FEraserAlpha write SetEraserAlpha;
+    property Texture: TBGRABitmap read GetTexture write SetTexture;
+    property TextureAfterAlpha: TBGRABitmap read GetTextureAfterAlpha;
     property TextureOpacity: byte read GetTextureOpacity write SetTextureOpacity;
     property PenWidth: single read GetPenWidth write SetPenWidth;
     property PenStyle: TPenStyle read FPenStyle write SetPenStyle;
@@ -369,14 +365,37 @@ type
     property PhongShapeAltitude: integer read FPhongShapeAltitude write SetPhongShapeAltitude;
     property PhongShapeBorderSize: integer read FPhongShapeBorderSize write SetPhongShapeBorderSize;
     property PhongShapeKind: TPhongShapeKind read FPhongShapeKind write SetPhongShapeKind;
-   end;
+    property DeformationGridNbX: integer read FDeformationGridNbX;
+    property DeformationGridNbY: integer read FDeformationGridNbY;
+    property DeformationGridSize: TSize read GetDeformationGridSize write SetDeformationGridSizeProc;
+    property Tolerance: byte read FTolerance write SetTolerance;
+
+    property OnToolChanged: TOnToolChangedHandler read FOnToolChangedHandler write FOnToolChangedHandler;
+    property OnPopup: TOnPopupToolHandler read FOnPopupToolHandler write FOnPopupToolHandler;
+    property OnEraserChanged: TNotifyEvent read FOnEraserChanged write FOnEraserChanged;
+    property OnTextureChanged: TNotifyEvent read FOnTextureChanged write FOnTextureChanged;
+    property OnColorChanged: TNotifyEvent read FOnColorChanged write FOnColorChanged;
+    property OnPenWidthChanged: TNotifyEvent read FOnPenWidthChanged write FOnPenWidthChanged;
+    property OnPenStyleChanged: TNotifyEvent read FOnPenStyleChanged write FOnPenStyleChanged;
+    property OnJoinStyleChanged: TNotifyEvent read FOnJoinStyleChanged write FOnJoinStyleChanged;
+    property OnShapeOptionChanged: TNotifyEvent read FOnShapeOptionChanged write FOnShapeOptionChanged;
+    property OnTextFontChanged: TNotifyEvent read FOnTextFontChanged write FOnTextFontChanged;
+    property OnTextOutlineChanged: TNotifyEvent read FOnTextOutlineChanged write FOnTextOutlineChanged;
+    property OnTextPhongChanged: TNotifyEvent read FOnTextPhongChanged write FOnTextPhongChanged;
+    property OnTextShadowChanged: TNotifyEvent read FOnTextShadowChanged write FOnTextShadowChanged;
+    property OnLineCapChanged: TNotifyEvent read FOnLineCapChanged write FOnLineCapChanged;
+    property OnSplineStyleChanged: TNotifyEvent read FOnSplineStyleChanged write FOnSplineStyleChanged;
+    property OnGradientChanged: TNotifyEvent read FOnGradientChanged write FOnGradientChanged;
+    property OnPhongShapeChanged: TNotifyEvent read FOnPhongShapeChanged write FOnPhongShapeChanged;
+    property OnToleranceChanged: TNotifyEvent read FOnToleranceChanged write FOnToleranceChanged;
+  end;
 
 procedure RegisterTool(ATool: TPaintToolType; AClass: TToolClass);
 function ToolPopupMessageToStr(AMessage :TToolPopupMessage; AKey: Word = 0): string;
 
 implementation
 
-uses Types, ugraph, LCScaleDPI, LazPaintType, UCursors, BGRATextFX, ULoading, uresourcestrings,
+uses UGraph, LCScaleDPI, LazPaintType, UCursors, BGRATextFX, ULoading, uresourcestrings,
   BGRATransform, LCVectorOriginal, BGRAGradientOriginal, BGRASVGOriginal;
 
 function StrToPaintToolType(const s: ansistring): TPaintToolType;
@@ -474,10 +493,10 @@ end;
 
 procedure TToolManager.HintReturnValidates;
 begin
-  if not FReturnValidatesHintShowed then
+  if not FReturnValidatesHintShown then
   begin
     ToolPopup(tpmReturnValides);
-    FReturnValidatesHintShowed:= true;
+    FReturnValidatesHintShown:= true;
   end;
 end;
 
@@ -718,7 +737,7 @@ var
   ptF: TPointF;
 begin
   ptF := PointF(x,y);
-  Manager.ToolCurrentCursorPos := ptF;
+  Manager.FToolCurrentCursorPos := ptF;
   result := EmptyRect;
   toolDest := GetToolDrawingLayer;
   if toolDest = nil then exit;
@@ -882,6 +901,20 @@ begin
   if Assigned(FOnColorChanged) then FOnColorChanged(self);
 end;
 
+procedure TToolManager.SetEraserAlpha(AValue: byte);
+begin
+  if FEraserAlpha=AValue then Exit;
+  FEraserAlpha:=AValue;
+  if Assigned(FOnEraserChanged) then FOnEraserChanged(self);
+end;
+
+procedure TToolManager.SetEraserMode(AValue: TEraserMode);
+begin
+  if FEraserMode=AValue then Exit;
+  FEraserMode:=AValue;
+  if Assigned(FOnEraserChanged) then FOnEraserChanged(self);
+end;
+
 procedure TToolManager.SetForeColor(AValue: TBGRAPixel);
 begin
   if (AValue.red = FForeColor.red) and
@@ -1010,6 +1043,13 @@ begin
   if Assigned(FOnTextureChanged) then FOnTextureChanged(self);
 end;
 
+procedure TToolManager.SetTolerance(AValue: byte);
+begin
+  if FTolerance=AValue then Exit;
+  FTolerance:=AValue;
+  if Assigned(FOnToleranceChanged) then FOnToleranceChanged(self);
+end;
+
 function TToolManager.CheckExitTool: boolean;
 begin
   if FShouldExitTool then
@@ -1164,14 +1204,17 @@ begin
   FShouldExitTool:= false;
   FConfigProvider := AConfigProvider;
 
-  ForeColor := BGRABlack;
-  BackColor := BGRA(0,0,255);
+  FForeColor := BGRABlack;
+  FBackColor := BGRA(0,0,255);
+  FTexture := nil;
+  FTextureOpactiy:= 255;
+  FTextureAfterAlpha := nil;
   FNormalPenWidth := 5;
   FEraserWidth := 10;
-  ToolEraserMode := emEraseAlpha;
-  ShapeOptions := [toDrawShape, toFillShape, toCloseShape];
-  ToolTolerance := 64;
-  BlackAndWhite := ABlackAndWhite;
+  FEraserMode := emEraseAlpha;
+  FShapeOptions := [toDrawShape, toFillShape, toCloseShape];
+  Tolerance := 64;
+  FBlackAndWhite := ABlackAndWhite;
 
   ToolBrushSpacing := 1;
   ReloadBrushes;
@@ -1186,28 +1229,25 @@ begin
   ArrowEnd := akNone;
   ArrowSize := PointF(2,2);
   PenStyle := psSolid;
-  ToolEraserAlpha := 255;
+  FEraserAlpha := 255;
   SplineStyle := ssEasyBezier;
   FTextOutline := False;
   FTextOutlineWidth := 2;
-  TextShadow := false;
+  FTextShadow := false;
   FTextFont := TFont.Create;
   FTextFont.Size := 10;
   FTextFont.Name := 'Arial';
   ToolTextAlign := taLeftJustify;
-  TextPhong := False;
+  FTextPhong := False;
   TextShadowBlurRadius := 4;
   TextShadowOffset := Point(5,5);
   LightPosition := PointF(0,0);
   LightAltitude := 100;
-  PhongShapeAltitude := 50;
-  PhongShapeBorderSize := 20;
-  PhongShapeKind := pskRectangle;
+  FPhongShapeAltitude := 50;
+  FPhongShapeBorderSize := 20;
+  FPhongShapeKind := pskRectangle;
   ToolPerspectiveRepeat := false;
   ToolPerspectiveTwoPlanes := false;
-  FTextureOpactiy:= 255;
-  FTexture := nil;
-  FTextureAfterAlpha := nil;
 
   FDeformationGridNbX := 5;
   FDeformationGridNbY := 5;
@@ -1296,7 +1336,7 @@ begin
   if Config.DefaultToolOptionDrawShape then include(opt, toDrawShape);
   if Config.DefaultToolOptionFillShape then include(opt, toFillShape);
   if Config.DefaultToolOptionCloseShape then include(opt, toCloseShape);
-  ToolTolerance := Config.DefaultToolTolerance;
+  Tolerance := Config.DefaultToolTolerance;
   TextShadow := Config.DefaultToolTextShadow;
   FTextOutline := Config.DefaultToolTextOutline;
   FTextOutlineWidth := Config.DefaultToolTextOutlineWidth;
@@ -1328,7 +1368,7 @@ begin
   Config.SetDefaultToolOptionDrawShape(toDrawShape in ShapeOptions);
   Config.SetDefaultToolOptionFillShape(toFillShape in ShapeOptions);
   Config.SetDefaultToolOptionCloseShape(toCloseShape in ShapeOptions);
-  Config.SetDefaultToolTolerance(ToolTolerance);
+  Config.SetDefaultToolTolerance(Tolerance);
 
   Config.SetDefaultToolTextFont(FTextFont);
   Config.SetDefaultToolTextShadow(TextShadow);
@@ -1501,6 +1541,11 @@ begin
     OffsetRect(result, FCurrentTool.LayerOffset.X,FCurrentTool.LayerOffset.Y);
 end;
 
+procedure TToolManager.SetDeformationGridSizeProc(const ASize: TSize);
+begin
+  SetDeformationGridSize(ASize);
+end;
+
 procedure TToolManager.ToolWakeUp;
 begin
   if FSleepingTool <> nil then
@@ -1526,17 +1571,17 @@ end;
 
 { tool implementation }
 
-function TToolManager.SetDeformationGridSize(NbX, NbY: integer): boolean;
+function TToolManager.SetDeformationGridSize(ASize: TSize): boolean;
 begin
   result := false;
-  if NbX < 3 then NbX := 3;
-  if NbY < 3 then NbY := 3;
-  if (NbX <> DeformationGridNbX) or (NbY <> DeformationGridNbY) then
+  if ASize.cx < 3 then ASize.cx := 3;
+  if ASize.cy < 3 then ASize.cy := 3;
+  if (ASize.cx <> DeformationGridNbX) or (ASize.cy <> DeformationGridNbY) then
   begin
     CurrentTool.BeforeGridSizeChange;
-    FDeformationGridNbX := NbX;
-    FDeformationGridNbY := NbY;
-    CurrentTool.AfterGridSizeChange(NbX,NbY);
+    FDeformationGridNbX := ASize.cx;
+    FDeformationGridNbY := ASize.cy;
+    CurrentTool.AfterGridSizeChange(ASize.cx,ASize.cy);
     result := true;
   end;
 end;
@@ -1845,6 +1890,11 @@ begin
     result := EmptyRect;
 end;
 
+function TToolManager.GetDeformationGridSize: TSize;
+begin
+  result := Size(DeformationGridNbX, DeformationGridNbY);
+end;
+
 function TToolManager.ToolDown(ACoord: TPointF; ARightBtn: boolean;
   APressure: single): boolean;
 begin

+ 10 - 10
lazpaint/tools/utoolbasic.pas

@@ -95,7 +95,7 @@ end;
 
 function TToolErase.BlurRadius: single;
 begin
-  result := manager.PenWidth/4*Manager.ToolEraserAlpha/255;
+  result := manager.PenWidth/4*Manager.EraserAlpha/255;
 end;
 
 function TToolErase.StartDrawing(toolDest: TBGRABitmap; ptF: TPointF;
@@ -104,7 +104,7 @@ var ix,iy: integer;
   areaCopy, mask: TBGRABitmap;
   r: TRect;
 begin
-  if Manager.ToolEraserMode = emSoften then
+  if Manager.EraserMode = emSoften then
   begin
     result := GetShapeBounds([ptF],Manager.PenWidth+BlurRadius);
     if IntersectRect(result, result, rect(0,0,toolDest.width,toolDest.height)) then
@@ -134,7 +134,7 @@ begin
     begin
       ix := round(ptF.X);
       iy := round(ptF.Y);
-      toolDest.ErasePixel(ix,iy,round(Manager.ToolEraserAlpha*Manager.ToolPressure));
+      toolDest.ErasePixel(ix,iy,round(Manager.EraserAlpha*Manager.ToolPressure));
       result := rect(ix,iy,ix+1,iy+1);
     end
     else
@@ -145,9 +145,9 @@ begin
       begin
         r := rect(round(ptF.X-Manager.PenWidth/2+0.5),round(ptF.Y-Manager.PenWidth/2+0.5),
              round(ptF.X+Manager.PenWidth/2+0.5),round(ptF.Y+Manager.PenWidth/2+0.5));
-        toolDest.EraseEllipseInRect(r,round(Manager.ToolEraserAlpha*Manager.ToolPressure));
+        toolDest.EraseEllipseInRect(r,round(Manager.EraserAlpha*Manager.ToolPressure));
       end else
-        toolDest.EraseEllipseAntialias(ptF.X,ptF.Y,Manager.PenWidth/2,Manager.PenWidth/2,round(Manager.ToolEraserAlpha*Manager.ToolPressure));
+        toolDest.EraseEllipseAntialias(ptF.X,ptF.Y,Manager.PenWidth/2,Manager.PenWidth/2,round(Manager.EraserAlpha*Manager.ToolPressure));
       toolDest.NoClip;
     end;
   end;
@@ -158,7 +158,7 @@ function TToolErase.ContinueDrawing(toolDest: TBGRABitmap; originF,
 var areaCopy, mask: TBGRABitmap;
   pts: ArrayOfTPointF;
 begin
-  if Manager.ToolEraserMode = emSoften then
+  if Manager.EraserMode = emSoften then
   begin
     result := GetShapeBounds([destF,originF],Manager.PenWidth+BlurRadius);
     if IntersectRect(result, result, rect(0,0,toolDest.width,toolDest.height)) then
@@ -189,23 +189,23 @@ begin
   begin
     if Manager.PenWidth = 1 then
     begin
-      toolDest.EraseLine(round(destF.X),round(destF.Y),round(originF.X),round(originF.Y),round(Manager.ToolEraserAlpha*Manager.ToolPressure),false);
+      toolDest.EraseLine(round(destF.X),round(destF.Y),round(originF.X),round(originF.Y),round(Manager.EraserAlpha*Manager.ToolPressure),false);
       result := GetShapeBounds([destF,originF],1);
     end else
     begin
       pts := toolDest.Pen.ComputePolyline([PointF(destF.X,destF.Y),PointF(originF.X,originF.Y)],Manager.PenWidth,BGRAPixelTransparent,False);
-      toolDest.ErasePoly(pts, round(Manager.ToolEraserAlpha*Manager.ToolPressure));
+      toolDest.ErasePoly(pts, round(Manager.EraserAlpha*Manager.ToolPressure));
       result := GetShapeBounds([destF,originF],Manager.PenWidth);
     end;
   end else
   begin
     if snapToPixel and (Manager.PenWidth = 1) then
     begin
-      toolDest.EraseLineAntialias(round(destF.X),round(destF.Y),round(originF.X),round(originF.Y),round(Manager.ToolEraserAlpha*Manager.ToolPressure),false);
+      toolDest.EraseLineAntialias(round(destF.X),round(destF.Y),round(originF.X),round(originF.Y),round(Manager.EraserAlpha*Manager.ToolPressure),false);
       result := GetShapeBounds([destF,originF],1);
     end else
     begin
-      toolDest.EraseLineAntialias(destF.X,destF.Y,originF.X,originF.Y,round(Manager.ToolEraserAlpha*Manager.ToolPressure),Manager.PenWidth,False);
+      toolDest.EraseLineAntialias(destF.X,destF.Y,originF.X,originF.Y,round(Manager.EraserAlpha*Manager.ToolPressure),Manager.PenWidth,False);
       result := GetShapeBounds([destF,originF],Manager.PenWidth);
     end;
   end;

+ 3 - 3
lazpaint/tools/utoolfloodfill.pas

@@ -134,15 +134,15 @@ begin
   begin
     floodFillMask := TBGRABitmap.Create(toolDest.Width,toolDest.Height,BGRABlack);
     floodFillTex := Manager.GetTextureAfterAlpha.GetPart(rect(0,0,toolDest.Width,toolDest.Height)) as TBGRABitmap;
-    toolDest.ParallelFloodFill(pt.X,pt.Y,floodFillMask,BGRAWhite,fmSet,Manager.ToolTolerance);
+    toolDest.ParallelFloodFill(pt.X, pt.Y, floodFillMask, BGRAWhite, fmSet, Manager.Tolerance);
     floodFillTex.ApplyMask(floodFillMask);
     toolDest.PutImage(0,0,floodFillTex,dmDrawWithTransparency);
     floodFillMask.Free;
     floodFillTex.Free;
   end else
     if Manager.ToolFloodFillOptionProgressive then
-      toolDest.FloodFill(pt.X,pt.Y,penColor,fmProgressive,Manager.ToolTolerance) else
-        toolDest.FloodFill(pt.X,pt.Y,penColor,fmDrawWithTransparency,Manager.ToolTolerance);
+      toolDest.FloodFill(pt.X, pt.Y, penColor, fmProgressive, Manager.Tolerance) else
+        toolDest.FloodFill(pt.X, pt.Y, penColor, fmDrawWithTransparency, Manager.Tolerance);
   Action.NotifyChange(toolDest, rect(0,0,toolDest.Width,toolDest.Height));
   ValidateAction;
   result := OnlyRenderChange;

+ 2 - 2
lazpaint/tools/utoolselect.pas

@@ -625,8 +625,8 @@ begin
   end;
   if rightBtn then penColor := BGRABlack else penColor := BGRAWhite;
   ofs := Manager.Image.LayerOffset[Manager.Image.CurrentLayerIndex];
-  Manager.Image.CurrentLayerReadOnly.ParallelFloodFill(pt.X-ofs.X,pt.Y-ofs.Y,
-    toolDest,penColor,fmDrawWithTransparency,Manager.ToolTolerance,ofs.X,ofs.Y);
+  Manager.Image.CurrentLayerReadOnly.ParallelFloodFill(pt.X-ofs.X, pt.Y-ofs.Y,
+    toolDest, penColor, fmDrawWithTransparency, Manager.Tolerance, ofs.X, ofs.Y);
   result := rect(0,0,toolDest.Width,toolDest.Height);
   Action.NotifyChange(toolDest, result);
   ValidateAction;