Przeglądaj źródła

allowed fill types for tool

johann 5 lat temu
rodzic
commit
31a9539f89

+ 1 - 4
lazpaint/lazpaintmainform.pas

@@ -746,6 +746,7 @@ type
     procedure RegisterToolbarElements;
     procedure InitToolbarElements;
     procedure UpdateChooseColors;
+    procedure UpdateAllowedFillTypes;
     procedure UpdateToolOptions;
     procedure UpdateEraserToolbar;
     procedure UpdatePenStyleToolbar;
@@ -2921,10 +2922,6 @@ begin
       if self.Visible then
       begin
         case Tool of
-          ptGradient:
-            begin
-              VectorialFill_Back.FillType:= vftGradient;
-            end;
           ptTextureMapping:
           begin
             useSelection:= false;

+ 57 - 1
lazpaint/maintoolbar.inc

@@ -531,6 +531,7 @@ begin
 
   UpdateCurveModeToolbar;
 
+  UpdateAllowedFillTypes;
   VectorialFill_Pen.CanAdjustToShape := ToolManager.ToolProvideCommand(tcForeAdjustToShape);
   VectorialFill_Back.CanAdjustToShape := ToolManager.ToolProvideCommand(tcBackAdjustToShape);
   VectorialFill_Pen.CanEditGradTexPoints := ToolManager.ToolProvideCommand(tcForeEditGradTexPoints);
@@ -690,8 +691,12 @@ end;
 
 procedure TFMain.TimerArrangeTimer(Sender: TObject);
 begin
+  if Assigned(FLayout) then
+  begin
+    UpdateAllowedFillTypes;
+    FLayout.Arrange;
+  end;
   TimerArrange.Enabled:= false;
-  if Assigned(FLayout) then FLayout.Arrange;
 end;
 
 procedure TFMain.TimerHideFillTimer(Sender: TObject);
@@ -780,6 +785,57 @@ begin
       LazPaintInstance.ColorToFChooseColor;
 end;
 
+procedure TFMain.UpdateAllowedFillTypes;
+begin
+  if VectorialFill_Pen.AllowedFillTypes <> ToolManager.AllowedForeFillTypes then
+  begin
+    if not (VectorialFill_Pen.FillType in ToolManager.AllowedForeFillTypes) then
+    begin
+      if vftGradient in ToolManager.AllowedForeFillTypes then
+      begin
+        VectorialFill_Pen.AllowedFillTypes:= [VectorialFill_Pen.FillType] + ToolManager.AllowedForeFillTypes;
+        ToolManager.NeedForeGradient;
+      end else
+      if vftTexture in ToolManager.AllowedForeFillTypes then
+      begin
+        VectorialFill_Pen.AllowedFillTypes:= [VectorialFill_Pen.FillType] + ToolManager.AllowedForeFillTypes;
+        Vectorialfill_Pen.FillType := vftTexture;
+      end else
+      if vftSolid in ToolManager.AllowedForeFillTypes then
+      begin
+        VectorialFill_Pen.AllowedFillTypes:= [VectorialFill_Pen.FillType] + ToolManager.AllowedForeFillTypes;
+        Vectorialfill_Pen.FillType := vftSolid;
+      end;
+    end;
+    VectorialFill_Pen.AllowedFillTypes:= ToolManager.AllowedForeFillTypes;
+    VectorialFill_Pen.Width := VectorialFill_Pen.PreferredSize.cx;
+  end;
+
+  if VectorialFill_Back.AllowedFillTypes <> ToolManager.AllowedBackFillTypes then
+  begin
+    if not (VectorialFill_Back.FillType in ToolManager.AllowedBackFillTypes) then
+    begin
+      if vftGradient in ToolManager.AllowedBackFillTypes then
+      begin
+        VectorialFill_Back.AllowedFillTypes:= [VectorialFill_Back.FillType] + ToolManager.AllowedBackFillTypes;
+        ToolManager.NeedBackGradient;
+      end else
+      if vftTexture in ToolManager.AllowedBackFillTypes then
+      begin
+        VectorialFill_Back.AllowedFillTypes:= [VectorialFill_Back.FillType] + ToolManager.AllowedBackFillTypes;
+        Vectorialfill_Back.FillType := vftTexture;
+      end else
+      if vftSolid in ToolManager.AllowedBackFillTypes then
+      begin
+        VectorialFill_Back.AllowedFillTypes:= [VectorialFill_Back.FillType] + ToolManager.AllowedBackFillTypes;
+        Vectorialfill_Back.FillType := vftSolid;
+      end;
+    end;
+    VectorialFill_Back.AllowedFillTypes:= ToolManager.AllowedBackFillTypes;
+    VectorialFill_Back.Width := VectorialFill_Back.PreferredSize.cx;
+  end;
+end;
+
 procedure TFMain.SwitchColors;
 begin
   if ToolManager.SwapToolColors then

+ 30 - 0
lazpaint/tools/utool.pas

@@ -97,6 +97,8 @@ type
     function GetCurrentLayerKind: TLayerKind;
     function GetIsForeEditGradTexPoints: boolean; virtual;
     function GetIsBackEditGradTexPoints: boolean; virtual;
+    function GetAllowedBackFillTypes: TVectorialFillTypes; virtual;
+    function GetAllowedForeFillTypes: TVectorialFillTypes; virtual;
   public
     ToolUpdateNeeded: boolean;
     Cursor: TCursor;
@@ -135,6 +137,8 @@ type
     property ForeUniversalBrush: TUniversalBrush read GetForeUniversalBrush;
     property IsForeEditGradTexPoints: boolean read GetIsForeEditGradTexPoints;
     property IsBackEditGradTexPoints: boolean read GetIsBackEditGradTexPoints;
+    property AllowedForeFillTypes: TVectorialFillTypes read GetAllowedForeFillTypes;
+    property AllowedBackFillTypes: TVectorialFillTypes read GetAllowedBackFillTypes;
   end;
 
   { TReadonlyTool }
@@ -245,6 +249,8 @@ type
 
     procedure BackFillChange(ASender: TObject;
       var ADiff: TCustomVectorialFillDiff);
+    function GetAllowedBackFillTypes: TVectorialFillTypes;
+    function GetAllowedForeFillTypes: TVectorialFillTypes;
     function GetCursor: TCursor;
     function GetBackColor: TBGRAPixel;
     function GetBrushAt(AIndex: integer): TLazPaintBrush;
@@ -461,7 +467,9 @@ type
     property Cursor: TCursor read GetCursor;
 
     property ForeFill: TVectorialFill read FForeFill;
+    property AllowedForeFillTypes: TVectorialFillTypes read GetAllowedForeFillTypes;
     property BackFill: TVectorialFill read FBackFill;
+    property AllowedBackFillTypes: TVectorialFillTypes read GetAllowedBackFillTypes;
     property ForeColor: TBGRAPixel read GetForeColor write SetForeColor;
     property BackColor: TBGRAPixel read GetBackColor write SetBackColor;
     property EraserMode: TEraserMode read FEraserMode write SetEraserMode;
@@ -680,6 +688,16 @@ begin
   end;
 end;
 
+function TGenericTool.GetAllowedBackFillTypes: TVectorialFillTypes;
+begin
+  result := [vftSolid,vftGradient,vftTexture];
+end;
+
+function TGenericTool.GetAllowedForeFillTypes: TVectorialFillTypes;
+begin
+  result := [vftSolid,vftGradient,vftTexture];
+end;
+
 function TGenericTool.GetIsBackEditGradTexPoints: boolean;
 begin
   result := false;
@@ -1428,6 +1446,18 @@ begin
   end;
 end;
 
+function TToolManager.GetAllowedBackFillTypes: TVectorialFillTypes;
+begin
+  if Assigned(CurrentTool) then result := currentTool.AllowedBackFillTypes
+  else result := [vftSolid,vftGradient,vftTexture];
+end;
+
+function TToolManager.GetAllowedForeFillTypes: TVectorialFillTypes;
+begin
+  if Assigned(CurrentTool) then result := currentTool.AllowedForeFillTypes
+  else result := [vftSolid,vftGradient,vftTexture];
+end;
+
 function TToolManager.GetForeColor: TBGRAPixel;
 begin
   if BlackAndWhite then

+ 13 - 1
lazpaint/tools/utoolbrush.pas

@@ -6,7 +6,7 @@ interface
 
 uses
   Classes, SysUtils, UToolBasic, BGRABitmapTypes, BGRABitmap, UTool,
-  UBrushType;
+  UBrushType, LCVectorialFill;
 
 type
 
@@ -41,6 +41,8 @@ type
     function DrawBrushAt(toolDest: TBGRABitmap; x, y: single): TRect; override;
     procedure PrepareBrush({%H-}rightBtn: boolean); override;
     procedure ReleaseBrush; override;
+    function GetAllowedForeFillTypes: TVectorialFillTypes; override;
+    function GetAllowedBackFillTypes: TVectorialFillTypes; override;
   public
     destructor Destroy; override;
     function GetContextualToolbars: TContextualToolbars; override;
@@ -211,6 +213,16 @@ begin
   FreeAndNil(coloredBrushImage);
 end;
 
+function TToolBrush.GetAllowedForeFillTypes: TVectorialFillTypes;
+begin
+  Result:= [vftSolid];
+end;
+
+function TToolBrush.GetAllowedBackFillTypes: TVectorialFillTypes;
+begin
+  Result:= [vftSolid];
+end;
+
 destructor TToolBrush.Destroy;
 begin
   ReleaseBrush;

+ 18 - 0
lazpaint/tools/utooldeformationgrid.pas

@@ -82,6 +82,7 @@ type
     function DefaultTextureCenter: TPointF; virtual;
     function DoToolUpdate({%H-}toolDest: TBGRABitmap): TRect; override;
     function GetStatusText: string; override;
+    function GetAllowedBackFillTypes: TVectorialFillTypes; override;
   public
     constructor Create(AManager: TToolManager); override;
     function ToolKeyDown(var key: Word): TRect; override;
@@ -105,7 +106,9 @@ type
     procedure PrepareBackground(toolDest: TBGRABitmap; {%H-}AFirstTime: boolean); override;
     function GetTexture: TBGRABitmap; override;
     function DefaultTextureCenter: TPointF; override;
+    function GetTextureRepetition: TTextureRepetition; override;
     procedure ValidateQuad; override;
+    function GetAllowedBackFillTypes: TVectorialFillTypes; override;
   public
     constructor Create(AManager: TToolManager); override;
     function GetContextualToolbars: TContextualToolbars; override;
@@ -161,12 +164,22 @@ begin
   result := FDefaultTextureCenter;
 end;
 
+function TToolLayerMapping.GetTextureRepetition: TTextureRepetition;
+begin
+  Result:= trNone;
+end;
+
 procedure TToolLayerMapping.ValidateQuad;
 begin
   inherited ValidateQuad;
   Manager.QueryExitTool;
 end;
 
+function TToolLayerMapping.GetAllowedBackFillTypes: TVectorialFillTypes;
+begin
+  Result:= [vftSolid,vftGradient,vftTexture];
+end;
+
 constructor TToolLayerMapping.Create(AManager: TToolManager);
 begin
   inherited Create(AManager);
@@ -658,6 +671,11 @@ begin
   end;
 end;
 
+function TToolTextureMapping.GetAllowedBackFillTypes: TVectorialFillTypes;
+begin
+  Result:= [vftTexture];
+end;
+
 constructor TToolTextureMapping.Create(AManager: TToolManager);
 begin
   inherited Create(AManager);

+ 8 - 3
lazpaint/tools/utoolfloodfill.pas

@@ -6,7 +6,7 @@ interface
 
 uses
   Classes, SysUtils, UTool, UToolVectorial, BGRABitmap, BGRABitmapTypes,
-  BGRAGradientOriginal, BGRALayerOriginal, LCVectorOriginal, UStateType;
+  BGRAGradientOriginal, BGRALayerOriginal, LCVectorOriginal, UStateType, LCVectorialFill;
 
 type
 
@@ -32,6 +32,7 @@ type
     function SlowShape: boolean; override;
     function GetStatusText: string; override;
     function ReplaceLayerAndAddShape(out ARect: TRect): TCustomImageDifference; override;
+    function GetAllowedBackFillTypes: TVectorialFillTypes; override;
   public
     function GetContextualToolbars: TContextualToolbars; override;
   end;
@@ -39,7 +40,7 @@ type
 implementation
 
 uses ugraph, LazPaintType, BGRAGradientScanner, LCVectorRectShapes,
-  BGRATransform, UImageDiff, LCVectorialFill;
+  BGRATransform, UImageDiff;
 
 { TToolGradient }
 
@@ -59,7 +60,6 @@ end;
 
 procedure TToolGradient.AssignShapeStyle(AMatrix: TAffineMatrix; AAlwaysFit: boolean);
 begin
-  Manager.NeedBackGradient;
   if Manager.BackFill.FillType = vftGradient then
     FShape.BackFill.AssignExceptGeometry(Manager.BackFill);
 end;
@@ -98,6 +98,11 @@ begin
     Result:= inherited ReplaceLayerAndAddShape(ARect);
 end;
 
+function TToolGradient.GetAllowedBackFillTypes: TVectorialFillTypes;
+begin
+  result := [vftGradient];
+end;
+
 function TToolGradient.GetContextualToolbars: TContextualToolbars;
 begin
   Result:= [ctBackFill];

+ 8 - 0
lazpaint/tools/utoolvectorial.pas

@@ -144,6 +144,7 @@ type
     function BackFitMode: TFitMode;
     function GetIsForeEditGradTexPoints: boolean; override;
     function GetIsBackEditGradTexPoints: boolean; override;
+    function GetAllowedBackFillTypes: TVectorialFillTypes; override;
   public
     constructor Create(AManager: TToolManager); override;
     destructor Destroy; override;
@@ -991,6 +992,13 @@ begin
   result := (GetEditMode = esmShape) and (GetVectorOriginal.SelectedShape.Usermode = BackGradTexMode);
 end;
 
+function TEditShapeTool.GetAllowedBackFillTypes: TVectorialFillTypes;
+begin
+  if GetEditMode = esmGradient then
+    result := [vftGradient] else
+    Result:=inherited GetAllowedBackFillTypes;
+end;
+
 constructor TEditShapeTool.Create(AManager: TToolManager);
 begin
   inherited Create(AManager);