Browse Source

set allowed fill types

johann 5 years ago
parent
commit
cc481d42dc

+ 1 - 0
lazpaintcontrols/lcvectorialfill.pas

@@ -11,6 +11,7 @@ uses
 type
   TTextureRepetition = (trNone, trRepeatX, trRepeatY, trRepeatBoth);
   TVectorialFillType = (vftNone, vftSolid, vftGradient, vftTexture);
+  TVectorialFillTypes = set of TVectorialFillType;
   TVectorialFill = class;
 
   TCustomVectorialFillDiff = class

+ 14 - 0
lazpaintcontrols/lcvectorialfillcontrol.pas

@@ -22,6 +22,7 @@ type
 
   TLCVectorialFillControl = class(TWinControl)
   private
+    function GetAllowedFillTypes: TVectorialFillTypes;
     function GetCanAdjustToShape: boolean;
     function GetFillType: TVectorialFillType;
     function GetGradEndColor: TBGRAPixel;
@@ -34,6 +35,7 @@ type
     function GetTexRepetition: TTextureRepetition;
     function GetTexture: TBGRABitmap;
     function GetToolIconSize: integer;
+    procedure SetAllowedFillTypes(AValue: TVectorialFillTypes);
     procedure SetCanAdjustToShape(AValue: boolean);
     procedure SetFillType(AValue: TVectorialFillType);
     procedure SetGradEndColor(AValue: TBGRAPixel);
@@ -86,6 +88,7 @@ type
     property Enabled;
     property Visible;
     property ToolIconSize: integer read GetToolIconSize write SetToolIconSize;
+    property AllowedFillTypes: TVectorialFillTypes read GetAllowedFillTypes write SetAllowedFillTypes;
   end;
 
 procedure Register;
@@ -101,6 +104,11 @@ end;
 
 { TLCVectorialFillControl }
 
+function TLCVectorialFillControl.GetAllowedFillTypes: TVectorialFillTypes;
+begin
+  result := FInterface.AllowedFillTypes;
+end;
+
 function TLCVectorialFillControl.GetCanAdjustToShape: boolean;
 begin
   result := FInterface.CanAdjustToShape;
@@ -161,6 +169,12 @@ begin
   result := FInterface.ImageListSize.cy;
 end;
 
+procedure TLCVectorialFillControl.SetAllowedFillTypes(
+  AValue: TVectorialFillTypes);
+begin
+  FInterface.AllowedFillTypes:= AValue;
+end;
+
 procedure TLCVectorialFillControl.SetCanAdjustToShape(AValue: boolean);
 begin
   FInterface.CanAdjustToShape := AValue;

+ 31 - 0
lazpaintcontrols/lcvectorialfillinterface.pas

@@ -24,6 +24,7 @@ type
   TVectorialFillInterface = class(TComponent)
   protected
     FFillType: TVectorialFillType;
+    FAllowedFillTypes: TVectorialFillTypes;
     FSolidColor: TBGRAPixel;
 
     FGradStartColor, FGradEndColor: TBGRAPixel;
@@ -87,6 +88,7 @@ type
     procedure SetCanAdjustToShape(AValue: boolean);
     procedure SetContainer(AValue: TWinControl);
     procedure SetFillType(AValue: TVectorialFillType);
+    procedure SetAllowedFillTypes(AValue: TVectorialFillTypes);
     procedure SetSolidColor(AValue: TBGRAPixel);
     procedure SetGradientType(AValue: TGradientType);
     procedure SetGradEndColor(AValue: TBGRAPixel);
@@ -149,6 +151,7 @@ type
     property Container: TWinControl read FContainer write SetContainer;
     property ImageListSize: TSize read FImageListSize write SetImageListSize;
     property PreferredSize: TSize read GetPreferredSize;
+    property AllowedFillTypes: TVectorialFillTypes read FAllowedFillTypes write SetAllowedFillTypes;
   end;
 
 implementation
@@ -566,6 +569,7 @@ var
 begin
   FContainer := nil;
 
+  FAllowedFillTypes := [vftNone, vftSolid, vftGradient, vftTexture];
   FFillType:= vftSolid;
   FSolidColor:= BGRAWhite;
   FGradStartColor:= CSSRed;
@@ -741,6 +745,33 @@ begin
   if FImageListLoaded then LoadImageList;
 end;
 
+procedure TVectorialFillInterface.SetAllowedFillTypes(
+  AValue: TVectorialFillTypes);
+var
+  x: Integer;
+begin
+  Include(AValue, FFillType); //cannot exclude current type
+  if FAllowedFillTypes=AValue then Exit;
+  FAllowedFillTypes:=AValue;
+  FToolbar.BeginUpdate;
+  x := FToolbar.Indent;
+  FButtonFillNone.Left := x;
+  FButtonFillNone.Wrap := [vftSolid,vftGradient,vftTexture]*FAllowedFillTypes = [];
+  FButtonFillNone.Visible:= vftNone in FAllowedFillTypes;
+  if vftNone in FAllowedFillTypes then inc(x, FButtonFillNone.Width);
+  FButtonFillSolid.Left := x;
+  FButtonFillSolid.Wrap := [vftGradient,vftTexture]*FAllowedFillTypes = [];
+  FButtonFillSolid.Visible:= vftSolid in FAllowedFillTypes;
+  if vftSolid in FAllowedFillTypes then inc(x, FButtonFillSolid.Width);
+  FButtonFillGradient.Left := x;
+  FButtonFillGradient.Wrap := [vftTexture]*FAllowedFillTypes = [];
+  FButtonFillGradient.Visible:= vftGradient in FAllowedFillTypes;
+  if vftGradient in FAllowedFillTypes then inc(x, FButtonFillGradient.Width);
+  FButtonFillTexture.Left := x;
+  FButtonFillTexture.Visible:= vftTexture in FAllowedFillTypes;
+  FToolbar.EndUpdate;
+end;
+
 procedure TVectorialFillInterface.AdjustToShapeClick(Sender: TObject);
 begin
   if Assigned(FOnAdjustToShape) then FOnAdjustToShape(self);