(************************************************************************
*    This File is Part of the AHM Triton Tools                          *
*    for Borland Delphi and C++ Builder.                                *
*************************************************************************
* Copyright © 1995-1999 Alexander H. Mehlhorn (AHM) and Tritontools.com *
* All Rights reserved.                                                  *
*                                                                       *
*    For more Information contact us at                                 *
*    E-Mail : support@tritontools.com                                   *
*    URL : http://www.tritontools.com                                   *
*                                                                       *
*    AHM is copyright by Alexander H. Mehlhorn                          *
*    All Parts of this Collection were developed,                       *
*    designed and implemented by AHM                                    *
*                                                                       *
*    Under no Circumstances may you distribute this file                *
*    in this or any other format. This File is supplied                 *
*    as Evaluation of Source only. No Delphi Components may be developed*
*    using extracts or subsets of this code without expressed permission*
*    by AHM.                                                            *
*                                                                       *
*************************************************************************)
unit AHMTBackground;
{$I AHM.INC}
interface

uses
  Windows, Messages, SysUtils,Classes,Graphics,Controls,
  AHMEnhancedClass,Forms;

type
  TAHMFillStyle = (Circle, Horizontal, Vertical, LeftBottom, RoundMiddle, SquareMiddle, Spectral,
                   DoppelFlash, Singleflash, MiddleHBar, MiddleVBar, VerticalDoppelBar, HorizontalDoppelBar);
  TAHMImageStyle = (isTile,isCenter,isStretched);
  TAHMGradient = class(TGraphicsObject)
  private
     FFillstyle : TAHMFillStyle;
     FBeginColor,FEndcolor : TColor;
     FColorCount : Integer;
     FColorStrings : TStrings;
     Procedure SetColorStrings(value : TStrings);
     Procedure SetStyle(value : TAHMFillStyle);
     Procedure SetBeginColor(value : TColor);
     Procedure SetEndColor(value : TColor);
     Procedure SetColorCount(Value : Integer);
  protected
  public
    constructor Create; virtual;
    Destructor Destroy; override;
    Procedure MultiDraw(const Cdc:HDC;iWidth,iHeight : Integer;CStrings : TStrings;NoGrad:TColor;Norm : Boolean);
  published
    Property BeginColor : TColor read FBeginColor write SetBeginColor default clbtnShadow;
    Property EndColor : TColor read FEndColor write SetEndColor default clbtnHighlight;
    Property FillStyle : TAHMFillstyle read FFillstyle write SetStyle default Horizontal;
    Property ColorCount : Integer read FColorCount write SetColorCount default 32;
    Property ColorsInBetween : TStrings read fColorStrings write SetColorStrings;
  end;
  TAHMTexture = class(TGraphicsObject)
  private
     FImage : TBitmap;
     FImageStyle : TAHMImageStyle;
     FTransparentColor : TColor;
     FTransparentBackground : TColor;
     Procedure SetTransparentColor(Value : TColor);
     Procedure SetTransparentBackground(Value : TColor);
     Procedure SetImage(Value : TBitmap);
     Procedure SetImageStyle(value : TAHMImageStyle);
  protected
  public
    Constructor Create; virtual;
    Destructor Destroy; override;
    Procedure Draw(const Cdc : HDC;Width,Height : Integer;Noimg : TColor);
  published
    Property Image : TBitmap read FImage write SetImage;
    Property ImageStyle : TAHMImageStyle read FImageStyle write SetImageStyle default isTile;
    Property TransparentColor : TColor read FTransparentColor write SetTransparentColor default clNone;
    Property TransparentBackground : TColor read FTransparentBackground write SetTransparentBackground default clbtnface;
  end;
  TAHMBrushFill = class(TGraphicsObject)
  private
     FBrushStyle:TBrushStyle;
     FBrushColor:TColor;
     Procedure SetBrushStyle(value : TBrushStyle);
     Procedure SetBrushColor(value : TColor);
  protected
  public
    Constructor Create; virtual;
  published
    Property BrushStyle : TBrushStyle read FBrushStyle write SetBrushStyle default bsSolid;
    Property BrushColor : TColor read FBrushColor write SetBrushColor default clbtnFace;
  end;
  TAHMBackStyle  = (bGradient,bTexture,bSolidcolor,bBrushFillUseCurrent,bBrushFillSolidColor);
  TAHMBackground = class(TComponent)
  private
     FAboutStr : TAHMAboutEnhancedStr;
     FTexture    : TAHMTexture;
     FBrushFill  : TAHMBrushFill;
     FBackStyle  : TAHMBackStyle;
     FOnchanged  : TNotifyevent;
     FSolidColor : TColor;
     FGradient   : TAHMGradient;
     FList       : TList;
     procedure SetSolidColor(value : TColor);
     procedure SetTexture(value : TAHMTexture);
     procedure SetGradient(value : TAHMGradient);
     procedure SetBrushFill(value : TAHMBrushFill);
     procedure SetBackStyle(value : TAHMBackStyle);
     procedure BackChange(Sender : TObject);
  protected
  public
    property OList : TList read Flist write FList stored false;
    constructor Create(AOwner : TComponent); override;
    destructor Destroy; override;
    procedure AddItem(value : TObject);
    procedure Draw(DC : HDC;fWidth,fHeight : Integer;Norm:Boolean);
    procedure DrawTrans(Canvas : TCanvas;Width,Height : Integer;Norm:Boolean;TRC:TColor);
    procedure Write(f3d : TAHMFont3D;const oFont : TFont;Canvas : TCanvas;TXTRect : TRect;Caption : String;flags : Longint);
  published
    Property About : TAHMAboutEnhancedStr read FAboutStr write FAboutStr;
    Property Texture         : TAHMTexture read FTexture write SetTexture;
    Property Gradient        : TAHMGradient read FGradient write SetGradient;
    Property BrushFill       : TAHMBrushFill read FBrushfill write SetBrushFill;
    Property OnChanged       : TNotifyevent read FOnChanged write FOnChanged;
    Property SolidColor      : TColor read FSolidColor write SetSolidColor default clbtnFace;
    Property BackgroundStyle : TAHMBackStyle read FBackstyle write SetBackStyle default bGradient;
  end;

implementation

Procedure AHMDrawTransparentBitmap(xCanvas: TCanvas; bmp: TBitmap; xStart,
                           yStart: Integer; cTransparentColor: LongInt);
begin
  with TImageList.CreateSize(bmp.Width,bmp.Height) do
  try
    Draw(xCanvas, xStart, yStart,AddMasked(bmp,cTransparentcolor));
  finally
    Free;
  end;
end;

Constructor TAHMGradient.Create;
begin
  FBeginColor:=clbtnShadow;
  FEndColor:=clbtnHighlight;
  inherited create;
  FFillStyle:=Horizontal;
  FColorCount:=32;
  FColorStrings := TStringlist.create;
end;

Destructor TAHMGradient.Destroy;
begin
  FColorStrings.free;
  inherited Destroy;
end;

Procedure TAHMGradient.SetColorStrings(value : TStrings);
begin
  FColorStrings.assign(value);
  Changed;
end;

Procedure TAHMGradient.SetStyle(value : TAHMFillStyle);
begin
  FFillstyle:=value;
  Changed;
end;

Procedure TAHMGradient.MultiDraw(const Cdc:HDC;iWidth,iHeight : Integer;CStrings : TStrings;NoGrad:TColor;Norm : Boolean);
var
  BeginRGBValue  : array[0..2] of Byte;
  RGBDifference  : array[0..2] of Integer;
  ColorBand : TRect;
  I         : Integer;
  R,G,B     : Byte;
  R2,G2,B2  : Byte;
  WorkBmp   : TBitmap;
  L1,L2,i2,FnColor : Integer;
  FStrings : TStrings;
  fbegincol,fendcol:TColor;
  fws,fwe,fhs,fhe : Integer;
begin
  fstrings:=TStringlist.create;
  fstrings.assign(Cstrings);
  if norm then
  begin
    fstrings.insert(0,colortostring(fbegincolor));
    fstrings.add(colortostring(fendcolor));
  end else
  begin
    fstrings.insert(0,colortostring(fendcolor));
    fstrings.add(colortostring(fbegincolor));
  end;
  WorkBmp := TBitmap.Create;
  try
    workbmp.dormant;
    workbmp.Width  := iWidth;
    workbmp.Height := iHeight;
    workbmp.Canvas.pen.width:=1;
    workbmp.canvas.brush.color:=nograd;
    workbmp.canvas.pen.color:=nograd;
    workbmp.canvas.brush.style:=bssolid;
    Patblt(workbmp.Canvas.handle,0,0,iwidth,iheight,PatCopy);
    workbmp.Canvas.Pen.width:=1;
    workbmp.canvas.brush.color:=stringtocolor(fstrings[0]);
    workbmp.canvas.pen.color:=stringtocolor(fstrings[0]);
    Patblt(workbmp.Canvas.handle,0,0,iwidth,iheight,PatCopy);
    workbmp.Canvas.Pen.Style := psSolid;
    workbmp.Canvas.Pen.Mode := pmCopy;
    fncolor:=fstrings.count-1;
    for i2:=0 to fstrings.count-2 do
    for I := 0 to FColorCount -1 do
    begin
      fbegincol:=stringtocolor(fstrings[i2]);
      fendcol  :=stringtocolor(fstrings[i2+1]);
      BeginRGBValue[0]:=GetRValue(ColorToRGB(fBeginCol));
      BeginRGBValue[1]:=GetGValue(ColorToRGB(fBeginCol));
      BeginRGBValue[2]:=GetBValue(ColorToRGB(fBeginCol));
      RGBDifference[0]:=GetRValue(ColorToRGB(fEndCol))-BeginRGBValue[0];
      RGBDifference[1]:=GetGValue(ColorToRGB(fEndCol))-BeginRGBValue[1];
      RGBDifference[2]:=GetBValue(ColorToRGB(fEndCol))-BeginRGBValue[2];
      if (FColorCount > 1) then
      begin
        R  := BeginRGBValue[0] + round(MulDiv (I, RGBDifference[0],FColorCount-1));
        G  := BeginRGBValue[1] + round(MulDiv (I, RGBDifference[1],FColorCount-1));
        B  := BeginRGBValue[2] + round(MulDiv (I, RGBDifference[2],FColorCount-1));
        R2 := BeginRGBValue[0] + round(MulDiv (FColorCount-1-I,
              RGBDifference[0],FColorCount - 1));
        G2 := BeginRGBValue[1] + round(MulDiv (FColorCount-1-I,
              RGBDifference[1],FColorCount - 1));
        B2 := BeginRGBValue[2] + round(MulDiv (FColorCount-1-I,
              RGBDifference[2],FColorCount - 1));
      end else
      begin
        R  := BeginRGBValue[0];
        G  := BeginRGBValue[1];
        B  := BeginRGBValue[2];
        R2 := BeginRGBValue[0];
        G2 := BeginRGBValue[1];
        B2 := BeginRGBValue[2];
      end;
      if r<1 then r:=1;
      if g<1 then g:=1;
      if b<1 then b:=1;
      Workbmp.Canvas.Pen.Color:=RGB (R, G, B);
      Workbmp.Canvas.Brush.color:=RGB (R, G, B);
      Workbmp.Canvas.Brush.style:=bssolid;
      case ffillstyle of
        Circle :
        begin
          fhe:=Round(iHeight/(fncolor))+1; fhs:=round(fhe*i2);
          fwe:=Round(iWidth/(fncolor))+1; fws:=round(fwe*i2);
          Colorband.left   :=MulDiv(I  ,fwe,FColorCount);
          Colorband.right  :=MulDiv(I+2,fwe,FColorCount);
          Colorband.Top    :=MulDiv(I  ,fhe,FColorCount);
          Colorband.bottom :=MulDiv(I+2,fhe,FColorCount);
          for l1:=Colorband.left to Colorband.right do
          begin
            Workbmp.Canvas.Moveto(fws+l1,0);
            Workbmp.Canvas.Lineto(iWidth-l1-fws,iHeight);
          end;
          for l1:=Colorband.top to Colorband.bottom do
          begin
            Workbmp.Canvas.Moveto(0,l1+fhs);
            Workbmp.Canvas.Lineto(iWidth,iHeight-l1-fhs);
          end;
        end;
        Spectral :
        begin
          fhe:=Round(iHeight/(fncolor))+1; fhs:=round(fhe*i2);
          fwe:=Round(iWidth/(fncolor))+1; fws:=round(fwe*i2);
          Colorband.left  :=MulDiv(I  ,fwe,FColorCount);
          Colorband.right :=MulDiv(I+2,fwe,FColorCount);
          Colorband.Top   :=MulDiv(I  ,fhe,FColorCount);
          Colorband.bottom:=MulDiv(I+2,fhe,FColorCount);
          for l1:=Colorband.left to Colorband.right do
          begin
            if odd(l1) then Workbmp.Canvas.Pen.Color:=RGB (R, G, B)
                       else Workbmp.Canvas.Pen.Color:=RGB (R2, G2, B2);
            Workbmp.Canvas.Moveto(l1+fws,0);
            Workbmp.Canvas.Lineto(iWidth-l1-fws,iHeight);
          end;
          for l1:=Colorband.top to Colorband.bottom do
          begin
            if odd(l1) then Workbmp.Canvas.Pen.Color:=RGB (R, G, B)
                       else Workbmp.Canvas.Pen.Color:=RGB (R2, G2, B2);
            Workbmp.Canvas.Moveto(0,l1+fhs);
            Workbmp.Canvas.Lineto(iWidth,iHeight-l1-fhs);
          end;
        end;
        SquareMiddle :
        begin
          fhe:=Round(iHeight/(fncolor)); fhs:=round(fhe/2*i2);
          fwe:=Round(iWidth/(fncolor)); fws:=round(fwe/2*i2);
          Colorband.left  :=MulDiv(I,round(fwe/2),FColorCount);
          Colorband.right :=iwidth-Colorband.left;
          Colorband.Top   :=MulDiv(I,round(fhe/2),FColorCount);
          Colorband.bottom:=iHeight-Colorband.top;
          Patblt(Workbmp.Canvas.handle,fws+Colorband.left,fhs+Colorband.top,
            Colorband.right-Colorband.left-fws*2,Colorband.bottom-Colorband.top-fhs*2,PatCopy);
        end;
        RoundMiddle :
        begin
          fhe:=Round(iHeight/(fncolor))+1;
          fhs:=round(fhe/2*i2)+1;
          fwe:=Round(iWidth/(fncolor))+1;
          fws:=round(fwe/2*i2)+1;
          Colorband.left:=MulDiv (I,round(fwe/2)+1,FColorCount);
          Colorband.right:=iWidth-Colorband.left;
          Colorband.Top:=MulDiv (I,round(fhe/2)+1,FColorCount);
          Colorband.bottom:=iHeight-Colorband.top;
          Ellipse(Workbmp.Canvas.Handle,fws+Colorband.left,
                  fhs+Colorband.top,Colorband.right-fws,Colorband.bottom-fhs);
        end;
        LeftBottom :
        begin
          fhe:=Round(iHeight/(fncolor))+1; fhs:=round(fhe*i2);
          fwe:=Round(iWidth/(fncolor))+1; fws:=round(fwe*i2);
          Colorband.left:=MulDiv(I,fwe,FColorCount);
          Colorband.right:=iwidth;
          Colorband.Top:=MulDiv (I,fhe,FColorCount);
          Colorband.bottom:=iheight;
          Patblt(Workbmp.Canvas.handle,fws+Colorband.left,fhs+Colorband.top,
            Colorband.right-Colorband.left,Colorband.bottom-Colorband.top,PatCopy);
        end;
        DoppelFlash :
        begin
          fhe:=Round(iHeight/(fncolor))+1; fhs:=round(fhe*i2)+1;
          fwe:=Round(iWidth/(fncolor))+1; fws:=round(fwe*i2)+1;
          ColorBand.Right   := iwidth;
          ColorBand.Bottom  := iheight;
          ColorBand.Left    := MulDiv(I,fwe,FColorCount);
          ColorBand.Top     := MulDiv(I,fhe,FColorCount);
          Ellipse(Workbmp.Canvas.Handle,fws+Colorband.left,
                  fhs+Colorband.top,Colorband.right,Colorband.bottom);
          Ellipse(Workbmp.Canvas.Handle,iwidth-Colorband.left-fws,iheight-Colorband.top-fhs,
                  iwidth-Colorband.right,iheight-Colorband.bottom);

        end;
        SingleFlash :
        begin
          fhe:=Round(iHeight/(fncolor)); fhs:=round(fhe*i2);
          fwe:=Round(iWidth/(fncolor)); fws:=round(fwe*i2);
          ColorBand.Right   := iwidth;
          ColorBand.Bottom  := iheight;
          ColorBand.Left    := MulDiv(I,fwe,FColorCount);
          ColorBand.Top     := MulDiv(I,fhe,FColorCount);
          Ellipse(Workbmp.Canvas.Handle,fws+Colorband.left,
                  fhs+Colorband.top,Colorband.right,Colorband.bottom);
        end;
        MiddleHBar :
        begin
          fhe:=Round(iHeight/(fncolor))+1;
          fhs:=round((fhe/2)*i2)+1;
          ColorBand.Left :=  iheight-MulDiv(I  ,Round(fhe/2)+1,FColorCount);
          ColorBand.Right := iheight-MulDiv(I+2,Round(fhe/2)+1,FColorCount);
          ColorBand.Top    := MulDiv (I  ,Round(fhe/2),FColorCount);
          ColorBand.Bottom := MulDiv (I+2,Round(fhe/2),FColorCount);
          Patblt(Workbmp.Canvas.handle,0,Colorband.Left-1-fhs,
                iwidth,ColorBand.right-Colorband.left,PatCopy);
          Patblt(Workbmp.Canvas.handle,0,fhs+Colorband.top,
                iwidth,Colorband.bottom-Colorband.top+1,PatCopy);
        end;
        MiddleVBar :
        begin
          fwe:=Round(iWidth/(fncolor))+1;
          fws:=round((fwe/2)*i2)+1;
          ColorBand.Left   := iwidth-MulDiv(I  ,Round(fwe/2)+1,FColorCount);
          ColorBand.Right  := iwidth-MulDiv(I+2,Round(fwe/2)+1,FColorCount);
          ColorBand.Top    := MulDiv(I  ,Round(fwe/2),FColorCount);
          ColorBand.Bottom := MulDiv(I+2,Round(fwe/2),FColorCount);
          Patblt(Workbmp.Canvas.handle,Colorband.Left-1-fws,0,
                 ColorBand.right-Colorband.left,iheight,PatCopy);
          Patblt(Workbmp.Canvas.handle,fws+Colorband.top,0,
                 Colorband.bottom-Colorband.top+1,iheight,PatCopy);
        end;
        VerticalDoppelBar :
        begin
          fwe:=Round(iWidth/(fncolor))+1;
          fws:=round((fwe/3)*i2)+1;
          ColorBand.Top    := MulDiv (I  ,Round(fwe/3)+1,FColorCount);
          ColorBand.Bottom := MulDiv (I+1,Round(fwe/3)+1,FColorCount);
          Patblt(Workbmp.Canvas.handle,fws+Colorband.top,0,
                 Colorband.bottom-Colorband.top,iheight,PatCopy);
          Patblt(Workbmp.Canvas.handle,2*Round(iwidth/3)-Colorband.Bottom-fws,0,
                 Colorband.Bottom-Colorband.Top,iheight,PatCopy);
          Patblt(Workbmp.Canvas.handle,fws+2*Round(iwidth/3)+Colorband.top,0,
                 Colorband.bottom-Colorband.top,iheight,PatCopy);
        end;
        HorizontalDoppelBar:
        begin
          fhe:=Round(iHeight/(fncolor))+1;
          fhs:=round((fhe/3)*i2)+1;
          ColorBand.Top    := MulDiv (I  ,Round(fhe/3)+1,FColorCount);
          ColorBand.Bottom := MulDiv (I+1,Round(fhe/3)+1,FColorCount);
          Patblt(Workbmp.Canvas.handle,0,fhs+Colorband.top,
                 iwidth,Colorband.bottom-Colorband.top,PatCopy);
          Patblt(Workbmp.Canvas.handle,0,2*Round(iheight/3)-Colorband.bottom-fhs,
                 iwidth,Colorband.bottom-Colorband.top,PatCopy);
          Patblt(Workbmp.Canvas.handle,0,fhs+2*Round(iheight/3)+Colorband.top,
                 iwidth,Colorband.bottom-Colorband.top,PatCopy);
        end;
        Horizontal :
        begin
          fhe:=Round(iHeight/(fncolor))+1;
          fhs:=fhe*i2;
          ColorBand.Left   := 0;
          ColorBand.Right  := iWidth;
          ColorBand.Top    := MulDiv (I    ,fhe,FColorCount);
          ColorBand.Bottom := MulDiv (I + 2,fhe,FColorCount);
          Patblt(Workbmp.Canvas.handle,Colorband.left,fhs+Colorband.top,
            Colorband.right-Colorband.left,fhs+Colorband.bottom-Colorband.top,PatCopy);
        end;
        Vertical :
        begin
          fwe:=Round(iWidth/(fncolor))+1;
          fws:=fwe*i2;
          ColorBand.Top    := 0;
          ColorBand.Bottom := iHeight;
          ColorBand.Left   := MulDiv (I    , fwe,FColorCount);
          ColorBand.Right  := MulDiv (I + 2, fwe,FColorCount);
          Patblt(Workbmp.Canvas.handle,fws+Colorband.left,Colorband.top,
            fws+Colorband.right-Colorband.left,Colorband.bottom-Colorband.top,PatCopy);
        end;
      end;
    end;
    BitBlt(Cdc,0,0,iwidth,iheight,
          Workbmp.canvas.handle,0,0,srcCopy);
  finally
    WorkBmp.Free;
  end;
  fstrings.free;
end;


Procedure TAHMGradient.SetBeginColor(Value : TColor);
begin
  FBeginColor:=value;
  changed;
end;

Procedure TAHMGradient.SetEndColor(Value : TColor);
begin
  FEndColor:=value;
  changed;
end;

Procedure TAHMGradient.SetColorCount(Value : Integer);
begin
  if (value>1) and (value<256) then FColorCount:=value;
  changed;
end;


Constructor TAHMTexture.Create;
begin
  inherited create;
  FImageStyle := isTile;
  FTransparentColor := clNone;
  FTransparentBackground := clBtnFace;
  FImage := TBitmap.create;
end;

Destructor TAHMTexture.Destroy;
begin
  FImage.free;
  inherited Destroy;
end;


Procedure TAHMTexture.SetTransparentColor(Value : TColor);
begin
  FTransparentColor:=value;
  Changed;
end;

Procedure TAHMTexture.SetTransparentBackground(Value : TColor);
begin
  FTransparentBackground:=value;
  Changed;
end;

Procedure TAHMTexture.Draw(const Cdc : HDC;Width,Height : Integer;Noimg : TColor);
var i,j,nx,ny : integer;
    hbitm : TBitmap;
begin
  if not(fimage.Empty)  then
  begin
    hbitm:=TBitmap.create;
    try
    hbitm.width :=fimage.width;
    hbitm.height:=fimage.height;
    hbitm.canvas.brush.color:=FTransparentBackground;
    hbitm.canvas.brush.style:=bsSolid;
    hbitm.Canvas.BrushCopy(rect(0,0,hbitm.width,hbitm.height),fimage,
                           rect(0,0,hbitm.width,hbitm.height),FTransparentColor);
    if FImageStyle=isTile then
    begin
      nx:=width div fimage.width;
      ny:=height div fimage.height;
      for i:=0 to nx do
      for j:=0 to ny do
      if FTransparentColor=clNone then
        Bitblt(Cdc,i*fimage.width,j*fimage.height,
               fimage.width,fimage.height,fimage.canvas.handle,0,0,Srccopy)
      else
        Bitblt(Cdc,i*hbitm.width,j*hbitm.height,
               hbitm.width,hbitm.height,hbitm.canvas.handle,0,0,Srccopy);
    end else
    if FImageStyle=isStretched then
    begin
      if FTransparentColor=clNone then
        Stretchblt(Cdc,0,0,width,height,
            fimage.canvas.handle,0,0,fimage.width,fimage.height,Srccopy)
                       else
        Stretchblt(Cdc,0,0,width,height,
             hbitm.canvas.handle,0,0,hbitm.width,hbitm.height,Srccopy);
    end else
    begin
      SetBkColor(Cdc, ColorToRGB(NoImg));
      SetBkMode (Cdc, OPAQUE);
      if width >fimage.width  then nx:=((width-fimage.width) div 2)
                              else nx:=0;
      if height>fimage.height then ny:=((height-fimage.height) div 2)
                              else ny:=0;
      if FTransparentColor=clNone then
      Bitblt(Cdc,nx,ny,fimage.width,fimage.height,fimage.canvas.handle,0,0,Srccopy)
      else Bitblt(Cdc,nx,ny,hbitm.width,hbitm.height,hbitm.canvas.handle,0,0,Srccopy);

    end;
    finally
      hbitm.free;
    end;
  end;
end;

Procedure TAHMTexture.SetImageStyle(Value : TAHMImageStyle);
begin
  FImageStyle:=value;
  Changed;
end;

Procedure TAHMTexture.Setimage(Value : TBitmap);
begin
  FImage.assign(Value);
  Changed;
end;


Constructor TAHMBrushFill.Create;
begin
  inherited create;
  FBrushStyle := bssolid;
  FBrushColor := clbtnface;
end;


Procedure TAHMBrushFill.SetBrushStyle(value : TBrushStyle);
begin
  FBrushStyle:=value;
  Changed;
end;

Procedure TAHMBrushFill.SetBrushColor(value : TColor);
begin
  FBrushColor:=value;
  Changed;
end;


constructor TAHMBackground.Create(AOwner : TComponent);
begin
  inherited create(AOwner);
  FList  := TList.create;
  FList.clear;
  FSolidColor := clbtnface;
  FTexture    := TAHMTexture.create;
  FGradient   := TAHMGradient.create;
  FBrushFill  := TAHMBrushFill.create;
  FGradient.onchange  := backchange;
  FTexture.onchange   := backchange;
  FBrushFill.onchange := backchange;
end;

destructor TAHMBackground.Destroy;
begin
  FGradient.onchange :=nil;
  FTexture.onchange :=nil;
  FBrushFill.onchange:=nil;
  FList.clear;
  FTexture.free;
  FGradient.free;
  FBrushFill.free;
  FList.free;
  inherited Destroy;
end;

procedure TAHMBackground.Write(f3d : TAHMFont3D;const oFont : TFont;Canvas : TCanvas;
                               TXTRect : TRect;Caption : String;flags : Longint);
var ocol : TColor;
    i : Integer;
    fbit : TBitmap;
procedure domulti(xw,xh : Integer);
var cbit,mbit : TBitmap;
begin
  cbit:=TBitmap.create; mbit:=TBitmap.create;
  mbit.dormant; cbit.dormant;
  try
    mbit.width:=xw; mbit.height:=xh;
    cbit.width:=xw; cbit.height:=xh;
    draw(cbit.canvas.handle,xw,xh,true);
    mbit.canvas.font:=oFont;
    mbit.canvas.font.color:=oFont.Color;
    DrawTextEx(mbit.canvas.handle,PChar(caption),-1,Txtrect,flags,nil);
{$IFDEF AHMINPRISE3}
    if f3d.MaskFont then
    begin
      mbit.mask(ofont.color);
      mbit.Releasemaskhandle;
    end;
{$ENDIF}
    cbit.canvas.brush.style := bsClear;
    with TImageList.CreateSize(mbit.Width,mbit.Height) do
    try
      Draw(cbit.Canvas, 0, 0,AddMasked(mbit,ofont.color));
    finally
      Free;
    end;
    fbit.canvas.brush.style := bsClear;
    with TImageList.CreateSize(cbit.Width,cbit.Height) do
    try
      Draw(fbit.Canvas, 0, 0,AddMasked(cbit,cbit.canvas.pixels[0,0]));
    finally
      Free;
    end;
  finally
    mbit.free;
    cbit.free;
  end;
end;
begin
  fbit:=Tbitmap.create;
  fbit.dormant;
  fbit.width:=txtrect.right-txtrect.left;
  fbit.height:=txtrect.bottom-txtrect.top;
  Inflaterect(TXTRect,-round(f3d.repetitionwidth),0);
  Bitblt(fbit.canvas.handle,0,0,fbit.width,fbit.height,canvas.handle,0,0,srccopy);
  fbit.Canvas.font:=ofont;
  fbit.canvas.brush.style:=bsclear;
  if f3d.ThreeDimensional then
  begin
    ocol := fbit.canvas.Font.color;
    if f3d.repetition<>repeatNone then
    begin
      if f3d.Repetition=repeatOnShadow then
      begin
        fbit.canvas.Font.Color := f3d.repetitioncolor;
        OffsetRect(TXTRect, f3d.repetitionwidth, f3d.repetitionwidth);
        for i:=1 to f3d.repetitionwidth do
        begin
          DrawTextEx(fbit.canvas.handle,PChar(caption),-1,TxtRect,flags,nil);
          OffsetRect(TXTRect, -1, -1);
        end;
      end
      else
      begin
        fbit.canvas.Font.Color := f3d.repetitioncolor;
        for i:=f3d.repetitionwidth downto 1 do
        begin
          DrawTextEx(fbit.canvas.handle,PChar(caption),-1,TxtRect,flags,nil);
          OffsetRect(TXTRect, 1, 1);
        end;
      end;
    end;
    case f3d.style3D of
    fontRaised,fontOnlyHighlight,fontOnlyShadow,fontInset :
    begin
      if (f3d.style3D=fontRaised) or (f3d.style3D=fontOnlyHighlight) then
         fbit.canvas.Font.Color := f3d.Highlight else fbit.canvas.Font.Color := f3d.Shadow;
      OffsetRect(TXTRect, -f3d.offset, -f3d.offset);
      if (f3d.style3D<>fontOnlyShadow) then
      DrawTextEx(fbit.Canvas.handle,PChar(caption),-1,TxtRect,flags,nil);
      if (f3d.style3D=fontRaised) or (f3d.style3D=fontOnlyShadow) then
         fbit.canvas.Font.Color := f3d.shadow else fbit.canvas.Font.Color := f3d.highlight;
      OffsetRect(TXTRect, 2*f3d.offset, 2*f3d.offset);
      if (f3d.style3D<>fontonlyHighLight) then
            DrawTextEx(fbit.canvas.handle,PChar(caption),-1,TxtRect,flags,nil);
      OffsetRect(TXTRect, -f3d.offset, -f3d.offset);
    end;
    fontOutlineShadow :
    begin
      fbit.canvas.Font.Color := f3d.shadow;
      OffsetRect(TXTRect, -1, -1);
      DrawTextEx(fbit.canvas.handle,PChar(caption),-1,TxtRect,flags,nil);
      OffsetRect(TXTRect, 2, 0);
      DrawTextEx(fbit.canvas.handle,PChar(caption),-1,TxtRect,flags,nil);
      OffsetRect(TXTRect, 0, 2);
      DrawTextEx(fbit.canvas.handle,PChar(caption),-1,TxtRect,flags,nil);
      OffsetRect(TXTRect, -2, 0);
      DrawTextEx(fbit.canvas.handle,PChar(caption),-1,TxtRect,flags,nil);
      OffsetRect(TXTRect, 1, -1);
    end;
    end;
    fbit.canvas.Font.color:=ocol;
    domulti(fbit.width,fbit.height);
  end
  else domulti(fbit.width,fbit.height);
  Bitblt(canvas.handle,0,0,fbit.width,fbit.height,fbit.canvas.handle,0,0,srccopy);
  fbit.free;
end;

procedure TAHMBackground.Draw(DC : HDC;fWidth,fHeight : Integer;Norm:Boolean);
var tx,tx2 : TBitmap;
    FBrush : TBrush;
begin
  tx:=TBitmap.create;
  tx2:=TBitmap.create;
  FBrush := TBrush.Create;
  tx.width:=fwidth; tx.height:=fheight;
  tx2.width:=fwidth; tx2.height:=fheight;
  if FBackStyle=bGradient then FGradient.Multidraw(DC,fWidth,fHeight,FGradient.ColorsInbetween,FSolidColor,norm)
  else if FBackStyle=bTexture then FTexture.draw(DC,fWidth,fHeight,FSolidColor)
  else if (FBackstyle=bBrushFillUseCurrent) or (FBackstyle=bBrushFillSolidColor) then
  begin
    tx.canvas.brush.style  := FBrushFill.BrushStyle;
    tx.canvas.brush.color  := FBrushFill.BrushColor;
    tx.canvas.Fillrect(rect(0,0,fwidth,fheight));
    tx2.canvas.brush.style := FBrushFill.BrushStyle;
    tx2.canvas.brush.color := clBlack;
    tx2.canvas.Fillrect(rect(0,0,fwidth,fheight));
    tx.canvas.brushcopy(rect(0,0,fwidth,fheight),tx2,rect(0,0,fwidth,fheight),clblack);
    if FBackStyle=bBrushFillSolidColor then
    begin
      tx2.canvas.brush.style:= bsSolid;
      tx2.canvas.brush.color:= FSolidColor;
      tx2.canvas.Fillrect(rect(0,0,fwidth,fheight));
      tx2.canvas.brushcopy(rect(0,0,fwidth,fheight),tx,rect(0,0,fwidth,fheight),clwhite);
      BitBlt(tx.Canvas.handle,0,0,fwidth,fheight,tx2.canvas.handle,0,0,srcCopy);
    end;
    BitBlt(DC,0,0,fwidth,fheight,tx.canvas.handle,0,0,srcCopy);
  end else
  begin
    fbrush.style:=bsSolid;
    fbrush.color:=FSolidColor;
    Windows.FillRect(DC,rect(0,0,fwidth,fheight),fBrush.Handle);
  end;
  FBrush.free;
  tx.free;
  tx2.free;
end;

procedure TAHMBackground.DrawTrans(Canvas : TCanvas;Width,Height : Integer;Norm:Boolean;TRC:TColor);
var tbit1,tbit2 : TBitmap;
    trectx : TRect;
begin
  trectx:=rect(0,0,width,height);
  TBit1:=TBitmap.create;
  TBit2:=TBitmap.create;
  TBit1.width:=width;
  TBit1.height:=Height;
  TBit2.width:=width;
  TBit2.height:=Height;
  Draw(TBit1.Canvas.Handle,Width,Height,Norm);
  BitBlt(TBit2.Canvas.Handle,0,0,width,height,canvas.handle,0,0,SrcCopy);
  AHMDrawTransparentBitmap(TBit1.canvas,TBit2,0,0,TRC);
  BitBlt(Canvas.Handle,0,0,width,height,TBit1.canvas.handle,0,0,SrcCopy);
  Tbit2.free;
  Tbit1.free;
end;

procedure TAHMBackground.BackChange(Sender : TObject);
var i : integer;
begin
  for i:=0 to flist.count-1 do TWincontrol(flist.items[i]).invalidate;
  if assigned(fonchanged) then fonchanged(self);
end;

procedure TAHMBackground.SetGradient(value : TAHMGradient);
begin
  FGradient.assign(value);
  Backchange(self);
end;

procedure TAHMBackground.AddItem(value : TObject);
begin
  Olist.Capacity:=OList.count;
  OList.Add(value);
end;

procedure TAHMBackground.SetBrushFill(value : TAHMBrushFill);
begin
  FBrushFill.assign(value);
  Backchange(self);
end;

procedure TAHMBackground.SetSolidColor(value : TColor);
begin
  FSolidColor:=Value;
  Backchange(self);
end;

procedure TAHMBackground.SetTexture(value : TAHMTexture);
begin
  FTexture.assign(value);
  Backchange(self);
end;

procedure TAHMBackground.SetBackStyle(value : TAHMBackStyle);
begin
  FBackStyle:=value;
  Backchange(self);
end;

end.
