Browse Source

color with alpha = 0

johann 5 years ago
parent
commit
1b5db6f3e9

+ 2 - 0
lazpaint/tools/utool.pas

@@ -2711,9 +2711,11 @@ begin
   RegisterScriptFunctions(True);
 
   FForeFill := TVectorialFill.Create;
+  FForeFill.TransparentMode := tmAlphaZeroOnly;
   FForeFill.SolidColor := BGRABlack;
   FForeFill.OnChange:=@ForeFillChange;
   FBackFill := TVectorialFill.Create;
+  FBackFill.TransparentMode := tmAlphaZeroOnly;
   FBackFill.SolidColor := CSSSkyBlue;
   FBackFill.OnChange:=@BackFillChange;
   FForeLastGradient:= TBGRALayerGradientOriginal.Create;

+ 29 - 4
lazpaintcontrols/lcvectorialfill.pas

@@ -10,6 +10,7 @@ uses
 
 type
   TTextureRepetition = (trNone, trRepeatX, trRepeatY, trRepeatBoth);
+  TTransparentMode = (tmEnforeAllChannelsZero, tmAlphaZeroOnly, tmNoFill);
   TVectorialFillType = (vftNone, vftSolid, vftGradient, vftTexture);
   TVectorialFillTypes = set of TVectorialFillType;
   TVectorialFill = class;
@@ -44,6 +45,7 @@ type
   TVectorialFillDiff = class(TCustomVectorialFillDiff)
   protected
     FStart,FEnd: TVectorialFill;
+    FTransparentMode: TTransparentMode;
   public
     constructor Create(AFrom: TVectorialFill);
     procedure ComputeDiff(ATo: TVectorialFill);
@@ -68,6 +70,7 @@ type
     FTextureRepetition: TTextureRepetition;
     FTextureAverageColor: TBGRAPixel;
     FTextureAverageColorComputed: boolean;
+    FTransparentMode: TTransparentMode;
     FGradient: TBGRALayerGradientOriginal;
     FOnChange: TVectorialFillChangeEvent;
     FOnBeforeChange: TNotifyEvent;
@@ -81,6 +84,7 @@ type
     procedure SetTextureMatrix(AValue: TAffineMatrix);
     procedure SetTextureOpacity(AValue: byte);
     procedure SetTextureRepetition(AValue: TTextureRepetition);
+    procedure SetTransparentMode(AValue: TTransparentMode);
     procedure InternalClear;
     procedure BeginUpdate;
     procedure EndUpdate;
@@ -129,6 +133,7 @@ type
     property TextureRepetition: TTextureRepetition read FTextureRepetition write SetTextureRepetition;
     property OnChange: TVectorialFillChangeEvent read FOnChange write SetOnChange;
     property OnBeforeChange: TNotifyEvent read FOnBeforeChange write FOnBeforeChange;
+    property TransparentMode: TTransparentMode read FTransparentMode write SetTransparentMode;
   end;
 
 implementation
@@ -140,12 +145,14 @@ uses BGRAGradientScanner, BGRABlend, LCResourceString;
 constructor TVectorialFillDiff.Create(AFrom: TVectorialFill);
 begin
   FStart := TVectorialFill.Create;
+  FStart.TransparentMode:= AFrom.TransparentMode;
   FStart.Assign(AFrom);
 end;
 
 procedure TVectorialFillDiff.ComputeDiff(ATo: TVectorialFill);
 begin
   FEnd := TVectorialFill.Create;
+  FEnd.TransparentMode := ATo.TransparentMode;
   FEnd.Assign(ATo);
 end;
 
@@ -401,6 +408,7 @@ begin
   FTextureAverageColorComputed:= false;
   FGradient := nil;
   FIsSolid := false;
+  FTransparentMode := tmEnforeAllChannelsZero;
 end;
 
 function TVectorialFill.GetIsEditable: boolean;
@@ -446,6 +454,19 @@ begin
   end;
 end;
 
+procedure TVectorialFill.SetTransparentMode(AValue: TTransparentMode);
+begin
+  if FTransparentMode=AValue then Exit;
+  if (FillType = vftSolid) and (SolidColor.alpha = 0) then
+  begin
+    case FTransparentMode of
+    tmNoFill: Clear;
+    tmEnforeAllChannelsZero: SolidColor := BGRAPixelTransparent;
+    end;
+  end;
+  FTransparentMode:=AValue;
+end;
+
 procedure TVectorialFill.GradientChange(ASender: TObject; ABounds: PRectF; var ADiff: TBGRAOriginalDiff);
 var
   fillDiff: TVectorialFillGradientDiff;
@@ -501,10 +522,14 @@ end;
 
 procedure TVectorialFill.SetSolid(AColor: TBGRAPixel);
 begin
-  if (FillType = vftSolid) and (SolidColor = AColor) then exit;
+  if AColor.alpha = 0 then
+  case TransparentMode of
+  tmNoFill: begin Clear; exit; end;
+  tmEnforeAllChannelsZero: AColor := BGRAPixelTransparent;
+  end;
+  if (FillType = vftSolid) and SolidColor.EqualsExactly(AColor) then exit;
   BeginUpdate;
   InternalClear;
-  if AColor.alpha = 0 then AColor := BGRAPixelTransparent;
   FColor := AColor;
   FIsSolid:= true;
   EndUpdate;
@@ -635,7 +660,7 @@ begin
     else
     begin
       case other.FillType of
-      vftSolid: result := (FillType = vftSolid) and (other.SolidColor = SolidColor);
+      vftSolid: result := (FillType = vftSolid) and other.SolidColor.EqualsExactly(SolidColor);
       vftGradient: result := (FillType = vftGradient) and (other.Gradient.Equals(Gradient));
       vftTexture: result := (FillType = vftTexture) and (other.Texture = Texture) and
                        (other.TextureMatrix = TextureMatrix) and (other.TextureOpacity = TextureOpacity)
@@ -727,7 +752,7 @@ begin
   end;
 end;
 
-procedure TVectorialFill.ApplyOpacity(AOpacity: byte);
+procedure TVectorialFill.ApplyOpacity(AOpacity: Byte);
 var
   c: TBGRAPixel;
 begin

+ 3 - 3
lazpaintcontrols/lcvectorialfillinterface.pas

@@ -904,7 +904,7 @@ end;
 
 procedure TVectorialFillInterface.SetSolidColor(AValue: TBGRAPixel);
 begin
-  if FSolidColor=AValue then Exit;
+  if FSolidColor.EqualsExactly(AValue) then Exit;
   FSolidColor:=AValue;
   UpdateShapeSolidColor;
   If FillType = vftSolid then Changed;
@@ -957,7 +957,7 @@ end;
 
 procedure TVectorialFillInterface.SetGradEndColor(AValue: TBGRAPixel);
 begin
-  if CompareMem(@FGradEndColor,@AValue,sizeof(TBGRAPixel)) then Exit;
+  if FGradEndColor.EqualsExactly(AValue) then Exit;
   FGradEndColor:=AValue;
   UpdateGradientParams;
   if FillType = vftGradient then Changed;
@@ -965,7 +965,7 @@ end;
 
 procedure TVectorialFillInterface.SetGradStartColor(AValue: TBGRAPixel);
 begin
-  if CompareMem(@FGradStartColor,@AValue,sizeof(TBGRAPixel)) then Exit;
+  if FGradStartColor.EqualsExactly(AValue) then Exit;
   FGradStartColor:=AValue;
   UpdateGradientParams;
   if FillType = vftGradient then Changed;