Explorar el Código

Added BCGradientButton

lainz hace 6 años
padre
commit
55b03fa6dd

+ 253 - 0
bcgradientbutton.pas

@@ -0,0 +1,253 @@
+unit BCGradientButton;
+
+{$mode delphi}
+
+interface
+
+uses
+  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs,
+  BGRABitmap, BGRABitmapTypes, BCTypes;
+
+type
+
+  { TBCGradientButton }
+
+  TBCGradientButton = class(TGraphicControl)
+  private
+    FBorderColor: TBCPixel;
+    FBorderSize: integer;
+    FColor1: TBCPixel;
+    FColor2: TBCPixel;
+    FDimColor: TBCPixel;
+    FLockHorizontal: boolean;
+    FLockVertical: boolean;
+    FOnAfterRedraw: TBGRARedrawEvent;
+    FOnBeforeRedraw: TBGRARedrawEvent;
+    Fx: integer;
+    Fy: integer;
+    Fdraw: boolean;
+    Fupdating: boolean;
+    Fdown: boolean;
+    procedure ColorInvalidate(ASender: TObject; AData: PtrInt);
+    procedure SetBorderColor(AValue: TBCPixel);
+    procedure SetBorderSize(AValue: integer);
+    procedure SetColor1(AValue: TBCPixel);
+    procedure SetColor2(AValue: TBCPixel);
+    procedure SetDimColor(AValue: TBCPixel);
+    procedure SetLockHorizontal(AValue: boolean);
+    procedure SetLockVertical(AValue: boolean);
+  protected
+    procedure Paint; override;
+    procedure Invalidate; override;
+    procedure MouseMove(Shift: TShiftState; X, Y: integer); override;
+    procedure MouseLeave; override;
+    procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: integer); override;
+    procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: integer); override;
+  public
+    constructor Create(AOwner: TComponent); override;
+    destructor Destroy; override;
+    procedure BeginUpdate;
+    procedure EndUpdate;
+  published
+    property LockHorizontal: boolean read FLockHorizontal
+      write SetLockHorizontal default False;
+    property LockVertical: boolean
+      read FLockVertical write SetLockVertical default False;
+    property DimColor: TBCPixel read FDimColor write SetDimColor;
+    property Color1: TBCPixel read FColor1 write SetColor1;
+    property Color2: TBCPixel read FColor2 write SetColor2;
+    property BorderColor: TBCPixel read FBorderColor write SetBorderColor;
+    property BorderSize: integer read FBorderSize write SetBorderSize;
+    property OnBeforeRedraw: TBGRARedrawEvent read FOnBeforeRedraw write FOnBeforeRedraw;
+    property OnAfterRedraw: TBGRARedrawEvent read FOnAfterRedraw write FOnAfterRedraw;
+  published
+    property Align;
+    property Anchors;
+    property BorderSpacing;
+    property Caption;
+    property Enabled;
+    property ShowHint;
+  end;
+
+procedure Register;
+
+implementation
+
+procedure Register;
+begin
+  RegisterComponents('BGRA Button Controls', [TBCGradientButton]);
+end;
+
+{ TBCGradientButton }
+
+procedure TBCGradientButton.SetLockHorizontal(AValue: boolean);
+begin
+  if FLockHorizontal = AValue then
+    Exit;
+  FLockHorizontal := AValue;
+  Invalidate;
+end;
+
+procedure TBCGradientButton.SetColor1(AValue: TBCPixel);
+begin
+  if FColor1 = AValue then
+    Exit;
+  FColor1 := AValue;
+  Invalidate;
+end;
+
+procedure TBCGradientButton.SetBorderColor(AValue: TBCPixel);
+begin
+  if FBorderColor = AValue then
+    Exit;
+  FBorderColor := AValue;
+  Invalidate;
+end;
+
+procedure TBCGradientButton.ColorInvalidate(ASender: TObject; AData: PtrInt);
+begin
+  Invalidate;
+end;
+
+procedure TBCGradientButton.SetBorderSize(AValue: integer);
+begin
+  if FBorderSize = AValue then
+    Exit;
+  FBorderSize := AValue;
+  Invalidate;
+end;
+
+procedure TBCGradientButton.SetColor2(AValue: TBCPixel);
+begin
+  if FColor2 = AValue then
+    Exit;
+  FColor2 := AValue;
+  Invalidate;
+end;
+
+procedure TBCGradientButton.SetDimColor(AValue: TBCPixel);
+begin
+  if FDimColor = AValue then
+    Exit;
+  FDimColor := AValue;
+  Invalidate;
+end;
+
+procedure TBCGradientButton.SetLockVertical(AValue: boolean);
+begin
+  if FLockVertical = AValue then
+    Exit;
+  FLockVertical := AValue;
+  Invalidate;
+end;
+
+procedure TBCGradientButton.Paint;
+var
+  bmp: TBGRABitmap;
+  x, y: integer;
+begin
+  bmp := TBGRABitmap.Create(Width, Height);
+  if Assigned(FOnBeforeRedraw) then
+    FOnBeforeRedraw(Self, bmp);
+  if Fdraw and Enabled then
+  begin
+    x := Fx;
+    y := Fy;
+    if FLockHorizontal then
+      x := Width div 2;
+    if FLockVertical then
+      y := Height div 2;
+    bmp.GradientFill(0, 0, Width, Height, FColor1.Pixel, FColor2.Pixel, gtRadial,
+      PointF(x, y), PointF(x - Width, y), dmDrawWithTransparency);
+    bmp.RectangleAntialias(0, 0, Width, Height, FBorderColor.Pixel,
+      FBorderSize, BGRAPixelTransparent);
+    if Fdown then
+      bmp.Rectangle(0, 0, Width, Height, FDimColor.Pixel, FDimColor.Pixel,
+        dmDrawWithTransparency);
+  end;
+  if Assigned(FOnAfterRedraw) then
+    FOnAfterRedraw(Self, bmp);
+  bmp.Draw(Canvas, 0, 0, False);
+  bmp.Free;
+end;
+
+procedure TBCGradientButton.Invalidate;
+begin
+  if Fupdating then
+    Exit;
+  inherited Invalidate;
+end;
+
+procedure TBCGradientButton.MouseMove(Shift: TShiftState; X, Y: integer);
+begin
+  inherited MouseMove(Shift, X, Y);
+  Fx := X;
+  Fy := Y;
+  Fdraw := True;
+  Invalidate;
+end;
+
+procedure TBCGradientButton.MouseLeave;
+begin
+  inherited MouseLeave;
+  Fdraw := False;
+  Fdown := False;
+  Invalidate;
+end;
+
+procedure TBCGradientButton.MouseDown(Button: TMouseButton; Shift: TShiftState;
+  X, Y: integer);
+begin
+  inherited MouseDown(Button, Shift, X, Y);
+  Fdown := True;
+  Invalidate;
+end;
+
+procedure TBCGradientButton.MouseUp(Button: TMouseButton; Shift: TShiftState;
+  X, Y: integer);
+begin
+  inherited MouseUp(Button, Shift, X, Y);
+  Fdown := False;
+  Invalidate;
+end;
+
+constructor TBCGradientButton.Create(AOwner: TComponent);
+begin
+  inherited Create(AOwner);
+  BeginUpdate;
+  FLockHorizontal := False;
+  FLockVertical := False;
+  FColor1 := TBCPixel.Create(Self, BGRA(255, 255, 255, 100));
+  FColor1.OnChange := ColorInvalidate;
+  FColor2 := TBCPixel.Create(Self, BGRA(0, 0, 0, 0));
+  FColor2.OnChange := ColorInvalidate;
+  FBorderColor := TBCPixel.Create(Self, BGRA(255, 255, 255, 100));
+  FBorderColor.OnChange := ColorInvalidate;
+  FDimColor := TBCPixel.Create(Self, BGRA(0, 0, 0, 100));
+  FDimColor.OnChange := ColorInvalidate;
+  FBorderSize := 2;
+  Fdown := False;
+  EndUpdate;
+end;
+
+destructor TBCGradientButton.Destroy;
+begin
+  FColor1.Free;
+  FColor2.Free;
+  FBorderColor.Free;
+  FDimColor.Free;
+  inherited Destroy;
+end;
+
+procedure TBCGradientButton.BeginUpdate;
+begin
+  Fupdating := True;
+end;
+
+procedure TBCGradientButton.EndUpdate;
+begin
+  Fupdating := False;
+  Invalidate;
+end;
+
+end.

+ 7 - 2
bgracontrols.lpk

@@ -33,8 +33,8 @@
     </CompilerOptions>
     <Description Value="BGRA Controls is a set of graphical UI elements that you can use with Lazarus LCL applications."/>
     <License Value="Modified LGPL"/>
-    <Version Major="6" Minor="2"/>
-    <Files Count="53">
+    <Version Major="6" Minor="2" Release="1"/>
+    <Files Count="54">
       <Item1>
         <Filename Value="bcbasectrls.pas"/>
         <AddToUsesPkgSection Value="False"/>
@@ -292,6 +292,11 @@
         <Filename Value="bgracontrolsinfo.pas"/>
         <UnitName Value="bgracontrolsinfo"/>
       </Item53>
+      <Item54>
+        <Filename Value="bcgradientbutton.pas"/>
+        <HasRegisterProc Value="True"/>
+        <UnitName Value="BCGradientButton"/>
+      </Item54>
     </Files>
     <RequiredPkgs Count="2">
       <Item1>

+ 2 - 1
bgracontrols.pas

@@ -17,7 +17,7 @@ uses
   BGRASpeedButton, BGRASpriteAnimation, BGRAVirtualScreen, ColorSpeedButton, 
   DTAnalogClock, DTAnalogCommon, DTAnalogGauge, dtthemedclock, dtthemedgauge, 
   MaterialColors, BGRAImageTheme, BGRAThemeButton, BGRATheme, BGRAColorTheme, 
-  BGRAThemeRadioButton, bgracontrolsinfo, LazarusPackageIntf;
+  BGRAThemeRadioButton, bgracontrolsinfo, BCGradientButton, LazarusPackageIntf;
 
 implementation
 
@@ -58,6 +58,7 @@ begin
   RegisterUnit('BGRATheme', @BGRATheme.Register);
   RegisterUnit('BGRAColorTheme', @BGRAColorTheme.Register);
   RegisterUnit('BGRAThemeRadioButton', @BGRAThemeRadioButton.Register);
+  RegisterUnit('BCGradientButton', @BCGradientButton.Register);
 end;
 
 initialization

+ 1 - 1
bgracontrolsinfo.pas

@@ -8,7 +8,7 @@ uses
   Classes, SysUtils;
 
 const
-  BGRAControlsVersion = 6020000;
+  BGRAControlsVersion = 6020100;
 
   function BGRAControlsVersionStr: string;
 

+ 1 - 1
bgrapascalscriptcomponent.lpk

@@ -11,7 +11,7 @@
         <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
       </SearchPaths>
     </CompilerOptions>
-    <Version Major="6" Minor="2"/>
+    <Version Major="6" Minor="2" Release="1"/>
     <Files Count="3">
       <Item1>
         <Filename Value="bgrapascalscript.pas"/>

BIN
test/test_gradientbutton/gradientbutton.ico


+ 133 - 0
test/test_gradientbutton/gradientbutton.lpi

@@ -0,0 +1,133 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<CONFIG>
+  <ProjectOptions>
+    <Version Value="11"/>
+    <PathDelim Value="\"/>
+    <General>
+      <SessionStorage Value="InProjectDir"/>
+      <MainUnit Value="0"/>
+      <Title Value="gradientbutton"/>
+      <Scaled Value="True"/>
+      <ResourceType Value="res"/>
+      <UseXPManifest Value="True"/>
+      <XPManifest>
+        <DpiAware Value="True"/>
+      </XPManifest>
+      <Icon Value="0"/>
+    </General>
+    <BuildModes Count="2">
+      <Item1 Name="Debug" Default="True"/>
+      <Item2 Name="Release">
+        <CompilerOptions>
+          <Version Value="11"/>
+          <PathDelim Value="\"/>
+          <Target>
+            <Filename Value="gradientbutton"/>
+          </Target>
+          <SearchPaths>
+            <IncludeFiles Value="$(ProjOutDir)"/>
+            <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
+          </SearchPaths>
+          <CodeGeneration>
+            <SmartLinkUnit Value="True"/>
+            <Optimizations>
+              <OptimizationLevel Value="3"/>
+            </Optimizations>
+          </CodeGeneration>
+          <Linking>
+            <Debugging>
+              <GenerateDebugInfo Value="False"/>
+            </Debugging>
+            <LinkSmart Value="True"/>
+            <Options>
+              <Win32>
+                <GraphicApplication Value="True"/>
+              </Win32>
+            </Options>
+          </Linking>
+        </CompilerOptions>
+      </Item2>
+    </BuildModes>
+    <PublishOptions>
+      <Version Value="2"/>
+      <UseFileFilters Value="True"/>
+    </PublishOptions>
+    <RunParams>
+      <FormatVersion Value="2"/>
+      <Modes Count="0"/>
+    </RunParams>
+    <RequiredPackages Count="2">
+      <Item1>
+        <PackageName Value="bgracontrols"/>
+      </Item1>
+      <Item2>
+        <PackageName Value="LCL"/>
+      </Item2>
+    </RequiredPackages>
+    <Units Count="2">
+      <Unit0>
+        <Filename Value="gradientbutton.lpr"/>
+        <IsPartOfProject Value="True"/>
+      </Unit0>
+      <Unit1>
+        <Filename Value="unit1.pas"/>
+        <IsPartOfProject Value="True"/>
+        <ComponentName Value="Form1"/>
+        <HasResources Value="True"/>
+        <ResourceBaseClass Value="Form"/>
+        <UnitName Value="Unit1"/>
+      </Unit1>
+    </Units>
+  </ProjectOptions>
+  <CompilerOptions>
+    <Version Value="11"/>
+    <PathDelim Value="\"/>
+    <Target>
+      <Filename Value="gradientbutton"/>
+    </Target>
+    <SearchPaths>
+      <IncludeFiles Value="$(ProjOutDir)"/>
+      <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
+    </SearchPaths>
+    <Parsing>
+      <SyntaxOptions>
+        <IncludeAssertionCode Value="True"/>
+      </SyntaxOptions>
+    </Parsing>
+    <CodeGeneration>
+      <Checks>
+        <IOChecks Value="True"/>
+        <RangeChecks Value="True"/>
+        <OverflowChecks Value="True"/>
+        <StackChecks Value="True"/>
+      </Checks>
+      <VerifyObjMethodCallValidity Value="True"/>
+    </CodeGeneration>
+    <Linking>
+      <Debugging>
+        <DebugInfoType Value="dsDwarf2Set"/>
+        <UseHeaptrc Value="True"/>
+        <TrashVariables Value="True"/>
+        <UseExternalDbgSyms Value="True"/>
+      </Debugging>
+      <Options>
+        <Win32>
+          <GraphicApplication Value="True"/>
+        </Win32>
+      </Options>
+    </Linking>
+  </CompilerOptions>
+  <Debugging>
+    <Exceptions Count="3">
+      <Item1>
+        <Name Value="EAbort"/>
+      </Item1>
+      <Item2>
+        <Name Value="ECodetoolError"/>
+      </Item2>
+      <Item3>
+        <Name Value="EFOpenError"/>
+      </Item3>
+    </Exceptions>
+  </Debugging>
+</CONFIG>

+ 22 - 0
test/test_gradientbutton/gradientbutton.lpr

@@ -0,0 +1,22 @@
+program gradientbutton;
+
+{$mode objfpc}{$H+}
+
+uses
+  {$IFDEF UNIX}{$IFDEF UseCThreads}
+  cthreads,
+  {$ENDIF}{$ENDIF}
+  Interfaces, // this includes the LCL widgetset
+  Forms, Unit1
+  { you can add units after this };
+
+{$R *.res}
+
+begin
+  RequireDerivedFormResource:=True;
+  Application.Scaled:=True;
+  Application.Initialize;
+  Application.CreateForm(TForm1, Form1);
+  Application.Run;
+end.
+

BIN
test/test_gradientbutton/image.png


+ 38 - 0
test/test_gradientbutton/unit1.lfm

@@ -0,0 +1,38 @@
+object Form1: TForm1
+  Left = 434
+  Height = 240
+  Top = 119
+  Width = 320
+  Caption = 'Gradient Button'
+  ClientHeight = 240
+  ClientWidth = 320
+  OnCreate = FormCreate
+  OnDestroy = FormDestroy
+  LCLVersion = '2.1.0.0'
+  object BCGradientButton1: TBCGradientButton
+    Left = 30
+    Height = 180
+    Top = 30
+    Width = 260
+    DimColor.Red = 0
+    DimColor.Green = 0
+    DimColor.Blue = 0
+    DimColor.Alpha = 100
+    Color1.Red = 255
+    Color1.Green = 255
+    Color1.Blue = 255
+    Color1.Alpha = 100
+    Color2.Red = 0
+    Color2.Green = 0
+    Color2.Blue = 0
+    Color2.Alpha = 0
+    BorderColor.Red = 255
+    BorderColor.Green = 255
+    BorderColor.Blue = 255
+    BorderColor.Alpha = 100
+    BorderSize = 2
+    OnBeforeRedraw = BCGradientButton1BeforeRedraw
+    Align = alClient
+    BorderSpacing.Around = 30
+  end
+end

+ 57 - 0
test/test_gradientbutton/unit1.pas

@@ -0,0 +1,57 @@
+unit Unit1;
+
+{$mode objfpc}{$H+}
+
+interface
+
+uses
+  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, BCGradientButton,
+  BCButton, BGRABitmap, BCTypes, BGRABitmapTypes;
+
+type
+
+  { TForm1 }
+
+  TForm1 = class(TForm)
+    BCGradientButton1: TBCGradientButton;
+    procedure BCGradientButton1BeforeRedraw(Sender: TObject; Bitmap: TBGRABitmap
+      );
+    procedure FormCreate(Sender: TObject);
+    procedure FormDestroy(Sender: TObject);
+  private
+    bmp: TBGRABitmap;
+  public
+
+  end;
+
+var
+  Form1: TForm1;
+
+implementation
+
+{$R *.lfm}
+
+{ TForm1 }
+
+procedure TForm1.FormCreate(Sender: TObject);
+begin
+  BCGradientButton1.BeginUpdate;
+  BCGradientButton1.BorderSize := 4;
+  BCGradientButton1.EndUpdate;
+  bmp := TBGRABitmap.Create(Application.Location + 'image.png');
+end;
+
+procedure TForm1.FormDestroy(Sender: TObject);
+begin
+  bmp.Free;
+end;
+
+procedure TForm1.BCGradientButton1BeforeRedraw(Sender: TObject;
+  Bitmap: TBGRABitmap);
+begin
+  Bitmap.Fill(clNavy);
+  Bitmap.StretchPutImageProportionally(Rect(0, 0, Bitmap.Width, Bitmap.Height), TACenter, TLCenter, bmp, dmDrawWithTransparency);
+end;
+
+end.
+

+ 3 - 3
update_bgracontrols_force.json

@@ -6,15 +6,15 @@
   "UpdatePackageFiles" : [
     {
       "ForceNotify" : true,
-      "InternalVersion" : 24,
+      "InternalVersion" : 25,
       "Name" : "bgracontrols.lpk",
-      "Version" : "6.2.0.0"
+      "Version" : "6.2.1.0"
     },
     {
       "ForceNotify" : false,
       "InternalVersion" : 1,
       "Name" : "bgrapascalscriptcomponent.lpk",
-      "Version" : "6.2.0.0"
+      "Version" : "6.2.1.0"
     }
   ]
 }