Delphi编写的GDI+界面类

简介:
使用Delphi2010开发的一个GDI+界面类,可以做出非常漂亮的界面。



unit  xDUISkinPanel ;
interface
uses
  Windows, Messages, SysUtils, Graphics, Classes, stdctrls, Buttons, GDIPlusUse, GdiPlus,
  GdiPlusHelpers, Controls, ExtCtrls, Math;
type
  TxDUISkinPanel = class(TGraphicControl)
  private
    FMouseOverButton: Boolean;
    FState: TButtonState;
    FOnReSize: TNotifyEvent;
    FAutoSize: Boolean;
    FParentCanvas: TCanvas;
    FSetParentCanvas: Boolean;
    FOffSetX, FOffSetY: Integer;
    FCaptionOffX: Integer;
    FCaptionOffY: Integer;
    FAlignment: TAlignment;
    FLayout: TTextLayout;
    FDrawFrame: Boolean;
    FDrawFrameColor: TColor;
    FIsCreateDisabledImg: Boolean;
    FBmp: TBitmap;
    FDivisionImg: Boolean;
    FDivisionCol: Integer;
    FDivisionRow: Integer;
    FDivisionFocused: Integer;
    FDivisionHot: Integer;
    FDivisionDown: Integer;
    FDivisionCount: Integer;
    FDivisionDisabled: Integer;
    FDivisionUp: Integer;
    FDivisionHighlight: Integer;
    FDivisionSelected: Integer;
    FImgSelectedHot: TGPBitmap;
    FCaptionShow: Boolean;
    FAlphaDrawImg: Integer;
    FData: Pointer;
    FTabStyle: Boolean;
    FIconSize: Integer;
    FReSizeLeft: Integer;
    FReSizeRight: Integer;
    FDivisionType: Integer;
    FTileRect: TRect;
    FMainImg: String;
    FBottomShading: String;
    FTopShading: String;
    FTileRectBottom: Integer;
    FTileRectTop: Integer;
    FTileRectLeft: Integer;
    FTileRectRight: Integer;
    FTopShowPic: String;
    procedure ReSizeImage(var ImgSrc: IGPBitmap);
    procedure ReSizeAllImg;
    procedure ReDraw;
    procedure ImgCopyRect(var Img: IGPBitmap; Value: Boolean);
    procedure CMEnabledChanged(var Msg: TMessage); message cm_EnabledChanged;
    procedure CMFontChanged(var Msg: TMessage); message cm_FontChanged;
    procedure CMColorChanged(var Message: TMessage); message CM_COLORCHANGED;
    procedure SetAutoSize(const Value: Boolean);
    procedure SetAlignment(const Value: TAlignment);
    procedure SetLayout(const Value: TTextLayout);
    procedure SetDrawFrame(const Value: Boolean);
    procedure SetDrawFrameColor(const Value: TColor);
    procedure SetImgUp(const Value: IGPBitmap);
    procedure SetImgMain(const Value: IGPBitmap);
    procedure SetAlphaDrawImg(const Value: Integer);
    procedure SetTabStyle(const Value: Boolean);
    procedure SetReSizeLeft(const Value: Integer);
    procedure SetReSizeRight(const Value: Integer);
    procedure SetDivisionImg(const Value: Boolean);
    procedure SetTileRect(const Value: TRect);
    procedure SetBottomShading(const Value: String);
    procedure SetMainImg(const Value: String);
    procedure SetTopShading(const Value: String);
    procedure SetTopShowPic(const Value: String);
    { Private declarations }
  protected
    { Protected declarations }
    procedure AdjustBounds; dynamic;
    procedure Paint; override;
  public
    { Public declarations }
    ImgMain, ImgUp: IGPBitmap;
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    property Canvas;
    procedure Clone(Btn: TxDUISkinPanel; IsFont: Boolean = True);
    procedure CreateDisabledImg;
    property Data: Pointer read FData write FData;
  published
    { Published declarations }
    property Alignment: TAlignment read FAlignment write SetAlignment default taLeftJustify;
    property Layout: TTextLayout read FLayout write SetLayout default tlTop;
    property AutoSize: Boolean read FAutoSize write SetAutoSize;
    property DivisionImg: Boolean read FDivisionImg write SetDivisionImg;
    property OnReSize: TNotifyEvent read FOnReSize write FOnReSize;
    property AlphaDrawImg: Integer read FAlphaDrawImg write SetAlphaDrawImg;
    property DrawFrame: Boolean read FDrawFrame write SetDrawFrame;
    property DrawFrameColor: TColor read FDrawFrameColor write SetDrawFrameColor;
    //平铺区域
    property TileRect: TRect read FTileRect write SetTileRect;
    //图片
    property MainImg: String read FMainImg write SetMainImg;
    property TopShading: String read FTopShading write SetTopShading;
    property BottomShading: String read FBottomShading write SetBottomShading;
    property TopShowPic: String read FTopShowPic write SetTopShowPic;
    property Color;
    property Enabled;
    property Visible;
    property Align;
    property Action;
    property Anchors;
    property Constraints;
    property DragCursor;
    property DragKind;
    property DragMode;
    property Height default 25;
    property ParentFont;
    property ParentShowHint;
    property PopupMenu;
    property ShowHint;
    property Width default 75;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
  end;
procedure GrayScale(var Image: IGPBitmap);
procedure Register;
implementation
procedure Register;
begin
  RegisterComponents('Standard', [ TxDUISkinPanel ]);
end;
procedure CloneGDIImg(var Img: IGPBitmap; Source: IGPBitmap);
var
  g: IGPGraphics;
begin
  Img := TGPBitmap.Create(Source.GetWidth, Source.GetHeight, PixelFormat32bppARGB);
  g := TGPGraphics.Create(Img);
  try
    g.DrawImage(Source, 0, 0, Source.GetWidth, Source.GetHeight);
  finally
  end;
end;
procedure GrayScale(var Image: IGPBitmap);
var
  Data: TGPBitmapData;
  W, H, y0: Integer;
  Gray, X, Y, { a, } r, g, b: Integer;
  ScanLines: array of Byte;
begin
  W := Image.GetWidth;
  H := Image.GetHeight;
  Data := Image.LockBits(MakeRect(0, 0, W, H), [ImageLockModeRead, ImageLockModeWrite],
    PixelFormat32bppARGB);
  SetLength(ScanLines, Data.Height * Data.Stride);
  Move(Data.Scan0^, ScanLines[0], Data.Height * Data.Stride);
  for Y := 0 to H - 1 do
  begin
    y0 := Y * Data.Stride;
    for X := 0 to W - 1 do
    begin
      r := ScanLines[y0 + X * 4];
      g := ScanLines[y0 + X * 4 + 1];
      b := ScanLines[y0 + X * 4 + 2];
      Gray := Round(r * 0.3 + g * 0.59 + b * 0.11);
      ScanLines[y0 + X * 4] := Gray;
      ScanLines[y0 + X * 4 + 1] := Gray;
      ScanLines[y0 + X * 4 + 2] := Gray;
    end;
  end;
  Move(ScanLines[0], Data.Scan0^, Data.Height * Data.Stride);
  SetLength(ScanLines, 0);
  Image.UnlockBits(Data);
end;
function IntToByte(i: Integer): Byte;
begin
  if i > 255 then
    Result := 255
  else if i < 0 then
    Result := 0
  else
    Result := i;
end;
procedure ChangeAlpha(var Image: IGPBitmap; alpha: Integer); // alpha=0--255
type
  PRGBAType = ^TRGBAType;
  TRGBAType = record
    Red: Byte;
    Green: Byte;
    Blue: Byte;
    alpha: Byte;
  end;
var
  Data: TGPBitmapData;
  W, H: Integer;
  X, Y, y0: Integer;
  p: PRGBAType;
begin
  W := Image.GetWidth;
  H := Image.GetHeight;
  Data := Image.LockBits(MakeRect(0, 0, W, H), [ImageLockModeRead, ImageLockModeWrite],
    PixelFormat32bppARGB);
  for Y := 0 to H - 1 do
  begin
    y0 := Y * Data.Stride;
    for X := 0 to W - 1 do
    begin
      p := PRGBAType(PChar(Data.Scan0) + y0 + X * 4);
      if p^.alpha <> 0 then
        p^.alpha := IntToByte((p^.alpha * alpha) div 255);
    end;
  end;
  Image.UnlockBits(Data);
end;
procedure DrawAlphaImage(g: IGPGraphics; Img: IGPBitmap; X, Y, alpha: Integer); overload;
var
  ImageAttributes: IGPImageAttributes;
  ColorMatrix: TGPColorMatrix;
begin
  ImageAttributes := TGPImageAttributes.Create;
  try
    { TColorMatrix 数组的 [3,3] 决定透明度 }
    ColorMatrix.M[3, 3] := alpha / 100;
    ImageAttributes.SetColorMatrix(ColorMatrix);
    g.DrawImage(Img, MakeRect(X, Y, Img.GetWidth, Img.GetHeight), 0, 0, Img.GetWidth,
      Img.GetHeight, UnitPixel, ImageAttributes);
  finally
    // ImageAttributes.Free;
  end;
end;
procedure DrawAlphaImage(g: IGPGraphics; Img: IGPBitmap; r: TRect; alpha: Integer); overload;
var
  ImageAttributes: IGPImageAttributes;
  ColorMatrix: TGPColorMatrix;
begin
  ImageAttributes := TGPImageAttributes.Create;
  try
    { TColorMatrix 数组的 [3,3] 决定透明度 }
    ColorMatrix.M[3, 3] := alpha / 100;
    ImageAttributes.SetColorMatrix(ColorMatrix);
    g.DrawImage(Img, MakeRect(r), // MakeRect(x, y, img.GetWidth, img.GetHeight),
      0, 0, Img.GetWidth, Img.GetHeight, UnitPixel, ImageAttributes);
  finally
    // ImageAttributes.Free;
  end;
end;
function ColorToGDIColor(Color: TColor; a: Byte): TGPColor;
var
  r, g, b: Byte;
begin
  r := GetRValue(Color);
  g := GetGValue(Color);
  b := GetBValue(Color);
  Result := MakeColor(a, r, g, b);
end;
function GetStretchRect(SourceWidth, SourceHeigth, StretchWidth, StretchHeigth: Integer): TRect;
var
  W, H, cw, ch: Integer;
  xyaspect: Double;
begin
  try
    W := SourceWidth;
    H := SourceHeigth;
    cw := StretchWidth;
    ch := StretchHeigth;
    begin
      xyaspect := W / H;
      if W > H then
      begin
        W := cw;
        H := Trunc(cw / xyaspect);
        if H > ch then // woops, too big
        begin
          H := ch;
          W := Trunc(ch * xyaspect);
        end;
      end
      else
      begin
        H := ch;
        W := Trunc(ch * xyaspect);
        if W > cw then // woops, too big
        begin
          W := cw;
          H := Trunc(cw / xyaspect);
        end;
      end;
    end;
    with Result do
    begin
      Left := 0;
      Top := 0;
      Right := W;
      Bottom := H;
    end;
    OffsetRect(Result, (cw - W) div 2, (ch - H) div 2);
  except
  end;
end;
constructor TxDUISkinPanel.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  ControlStyle := ControlStyle - [csOpaque];
  ControlStyle := [csAcceptsControls, csCaptureMouse, csClickEvents, csSetCaption, csDoubleClicks,
    csReplicatable];
  FAutoSize := True;
  FIconSize := 32;
  FCaptionShow := True;
  FCaptionOffX := 0;
  FCaptionOffY := 0;
  Width := 75;
  Height := 25;
  ImgUp := nil;
  FMouseOverButton := False;
  ImgMain := nil;
  FDivisionType:=0;
  FDivisionImg := False;
  FDivisionCount := 1;
  FDivisionUp := -1;
  FDivisionDown := -1;
  FDivisionHot := -1;
  FDivisionSelected := -1;
  FDivisionDisabled := -1;
  FDivisionFocused := -1;
  FDivisionHighlight := -1;
  FAlphaDrawImg := 100;
  FReSizeLeft := 0;
  FReSizeRight := 0;
  FTabStyle := True;
  FBmp := nil;
  if not(csDesigning in ComponentState) then
  begin
    FBmp := TBitmap.Create;
  end;
end;
destructor TxDUISkinPanel.Destroy;
begin
  inherited;
  if FBmp <> nil then
    FreeAndNil(FBmp);
end;
procedure TxDUISkinPanel. AdjustBounds ;
var
  DC: HDC;
  X: Integer;
  Rect: TRect;
  AAlignment: TAlignment;
begin
  if not(csReading in ComponentState) and FAutoSize then
  begin
    Rect := ClientRect;
    DC := GetDC(0);
    Canvas.Handle := DC;
    ReDraw;
    Canvas.Handle := 0;
    ReleaseDC(0, DC);
    X := Left;
  end;
end;

procedure TxDUISkinPanel.ReDraw;
var
  r, DestRect, ImgRect, SkinRect, SrcRect: TRect;
  g: IGPGraphics;
  Img: IGPBitmap;
  ImgBottom: Integer;
  DivisionIndex: Integer;
  DC: HDC;
  DTFormat: UINT;
  W, H: Integer;
  aCanvas: TCanvas;
  procedure DrawImg(ImgRect, DestRect: TRect);
  var
    ImgDes: IGPBitmap;
  begin
    g := TGPGraphics.Create(FBmp.Canvas.Handle);
    try
      ReSizeImg(ImgDes, Img, DestRect, 0, 0, Point(0, Img.Width - 0));
      g.DrawImage(ImgDes,
                  MakeRect(DestRect.Left, DestRect.Top, DestRect.Right - DestRect.Left, DestRect.Bottom - DestRect.Top),
                  ImgRect.Left,
                  ImgRect.Top,
                  ImgRect.Right - ImgRect.Left,
                  ImgRect.Bottom - ImgRect.Top,
                  UnitPixel);
    finally
    end;
  end;
  //平铺绘制
  procedure TileDrawImg(ImgRect, DestRect: TRect);
  var
    ImgDes: IGPBitmap;
    cx, cy, x, y, i, j: Integer;
    DestWidth, DestHeight: Integer;
    cRect: TRect;
  begin
    g := TGPGraphics.Create(FBmp.Canvas.Handle);
    try
      DestWidth:=DestRect.Right - DestRect.Left;
      DestHeight:=DestRect.Bottom - DestRect.Top;
      cx:=(DestWidth + (Img.Width - 1))  div Img.Width;
      cy:=(DestHeight + (Img.Height - 1)) div Img.Height;
      for I := 0 to cx - 1 do
      begin
        for j := 0 to cy - 1 do
        begin
          x:=i * Img.Width;
          y:=j * Img.Height;
          g.DrawImage(img, x, y, Img.width, Img.height);
        end;
      end;
    finally
    end;
  end;
begin
  try
    if csDesigning in ComponentState then
      with Canvas do
      begin
        Brush.Color := Color;
        Pen.Style := psDash;
        Brush.Style := bsClear;
        Rectangle(0, 0, Width, Height);
        r := ClientRect;
        OffsetRect(r, FCaptionOffX, FCaptionOffY);
        Exit;
      end;
    with FBmp do
    begin
      Width := Self.Width;
      Height := Self.Height;
      Canvas.CopyRect(ClientRect, Self.Canvas, ClientRect);
      Img:=ImgUp;
      ImgBottom := r.Top;
      if Img = nil then
        Img := ImgUp;
      if Img <> nil then
      begin
        ImgRect:=Rect(0, 0, ImgUp.Width, ImgUp.Height);
        SkinRect:=ClientRect;
        {绘制顶部}
        //加载左上图像并绘制
        DestRect:=Rect(0, 0, FTileRect.Left, FTileRect.Top);
        SrcRect:=Rect(0, 0, FTileRect.Left, FTileRect.Top);
        if (DestRect.Bottom = 0) or (DestRect.Top < 0) then
        begin
          Exit;
        end;
        DrawImg(SrcRect, DestRect);
        //加载右上图像并绘制
        DestRect:=Rect(SkinRect.Right - (ImgRect.Right - FTileRect.Right), 0, SkinRect.Right, FTileRect.Top);
        SrcRect:=Rect(FTileRect.Right, 0, ImgRect.Right, FTileRect.Top);
        if (DestRect.Bottom = 0) or (DestRect.Top < 0) then
        begin
          Exit;
        end;
        DrawImg(SrcRect, DestRect);
        //拉伸上边的图像
        DestRect:=Rect(FTileRect.Left, 0, SkinRect.Right - (ImgRect.Right - FTileRect.Right), FTileRect.Top);
        SrcRect:=Rect(FTileRect.Left, 0, FTileRect.Right, FTileRect.Top);
        if (DestRect.Bottom = 0) or (DestRect.Top < 0) then
        begin
          Exit;
        end;
        DrawImg(SrcRect, DestRect);
        {绘制底部}
        //加载下上图像并绘制
        DestRect:=Rect(0, SkinRect.Bottom - (ImgRect.Bottom - FTileRect.Bottom), FTileRect.Left, SkinRect.Bottom);
        SrcRect:=Rect(0, FTileRect.Bottom, FTileRect.Left, ImgRect.Bottom);
        if (DestRect.Bottom = 0) or (DestRect.Top < 0) then
        begin
          Exit;
        end;
        DrawImg(SrcRect, DestRect);
        //加载右下图像并绘制
        DestRect:=Rect(SkinRect.Right - (ImgRect.Right - FTileRect.Right), SkinRect.Bottom - (ImgRect.Bottom - FTileRect.Bottom), SkinRect.Right, SkinRect.Bottom);
        SrcRect:=Rect(FTileRect.Right, FTileRect.Bottom, ImgRect.Right, ImgRect.Bottom);
        if (DestRect.Bottom = 0) or (DestRect.Top < 0) then
        begin
          Exit;
        end;
        DrawImg(SrcRect, DestRect);
        //拉伸下边的图像
        DestRect:=Rect(FTileRect.Left, SkinRect.Bottom - (ImgRect.Bottom - FTileRect.Bottom), SkinRect.Right - (ImgRect.Right - FTileRect.Right), SkinRect.Bottom);
        SrcRect:=Rect(FTileRect.Left, FTileRect.Bottom, FTileRect.Right, ImgRect.Bottom);
        if (DestRect.Bottom = 0) or (DestRect.Top < 0) then
        begin
          Exit;
        end;
        DrawImg(SrcRect, DestRect);
        {绘制左边}
        DestRect:=Rect(0, FTileRect.Top, FTileRect.Left, SkinRect.Bottom - (ImgRect.Bottom - FTileRect.Bottom));
        SrcRect:=Rect(0, FTileRect.Top, FTileRect.Left, FTileRect.Bottom);
        if (DestRect.Bottom = 0) or (DestRect.Top < 0) then
        begin
          Exit;
        end;
        DrawImg(SrcRect, DestRect);
        {绘制右边}
        DestRect:=Rect(SkinRect.Right - (ImgRect.Right - FTileRect.Right), FTileRect.Top, SkinRect.Right, SkinRect.Bottom - (ImgRect.Bottom - FTileRect.Bottom));
        SrcRect:=Rect(FTileRect.Right, FTileRect.Top, ImgRect.Right, FTileRect.Bottom);
        if (DestRect.Bottom = 0) or (DestRect.Top < 0) then
        begin
          Exit;
        end;
        DrawImg(SrcRect, DestRect);
        {绘制中间}
        DestRect.Left:=FTileRect.Left;
        DestRect.Top:=FTileRect.Top;
        DestRect.Right:=SkinRect.Right - (ImgRect.Right - FTileRect.Right);
        DestRect.Bottom:=SkinRect.Bottom - (ImgRect.Bottom - FTileRect.Bottom);
        SrcRect:=Rect(FTileRect.Left, FTileRect.Top, FTileRect.Right, FTileRect.Bottom);
        if (DestRect.Bottom = 0) or (DestRect.Top < 0) then
        begin
          Exit;
        end;
        DrawImg(SrcRect, DestRect);
        {绘制上底纹}
        if FileExists(FTopShading) then
        begin
          SkinRect:=ClientRect;
          Img:=TGPBitmap.Create(FTopShading);
          SkinRect.Bottom:=Img.Height;
          SkinRect.Right:=Img.Width;
          DestRect:=SkinRect;
          SrcRect:=Rect(0, 0, Img.Width, Img.Height);
          if (DestRect.Bottom = 0) or (DestRect.Top < 0) then
          begin
            Exit;
          end;
          DrawImg(SrcRect, DestRect);
        end;
        {绘制下底纹}
        if FileExists(FBottomShading) then
        begin
          SkinRect:=ClientRect;
          Img:=TGPBitmap.Create(FBottomShading);
          SkinRect.Left:=SkinRect.Right - Img.Width;
          SkinRect.Top:=SkinRect.Bottom - Img.Height;
          DestRect:=SkinRect;
          SrcRect:=Rect(0, 0, Img.Width, Img.Height);
          if (DestRect.Bottom = 0) or (DestRect.Top < 0) then
          begin
            Exit;
          end;
          DrawImg(SrcRect, DestRect);
        end;
        {绘制顶部显示图片(游戏名称)}
        if FileExists(FTopShowPic) then
        begin
          SkinRect:=ClientRect;
          Img:=TGPBitmap.Create(FTopShowPic);
          SkinRect.Bottom:=Img.Height;
          SkinRect.Right:=Img.Width;
          DestRect:=Rect(60, 15, Img.Width + 60, Img.Height + 15);
          SrcRect:=Rect(0, 0, Img.Width, Img.Height);
          if (DestRect.Bottom = 0) or (DestRect.Top < 0) then
          begin
            Exit;
          end;
          DrawImg(SrcRect, DestRect);
        end;
      end;
    end;
    Canvas.Draw(0, 0, FBmp);
  finally
  end;
end;
procedure TxDUISkinPanel.ReSizeAllImg;
begin
  if (FReSizeLeft = 0) or (FReSizeRight = 0) then
    Exit;
  ReSizeImage(ImgUp);
end;
procedure TxDUISkinPanel.ReSizeImage(var ImgSrc: IGPBitmap);
var
  Img: IGPBitmap;
  r: TRect;
begin
  if (ImgSrc <> nil) and (FReSizeLeft <> 0) and (FReSizeRight <> 0) then
  begin
    r := ClientRect;
    ReSizeImg(Img, ImgSrc, r, FReSizeLeft, FReSizeRight,
      Point(FReSizeLeft, ImgSrc.Width - FReSizeLeft - FReSizeRight));
    ImgSrc := Img;
  end;
end;
procedure TxDUISkinPanel.Paint;
begin
  ReDraw;
end;
procedure TxDUISkinPanel.SetAutoSize(const Value: Boolean);
begin
  FAutoSize := Value;
  Invalidate;
end;
procedure TxDUISkinPanel.SetBottomShading(const Value: String);
begin
  FBottomShading := Value;
end;
procedure TxDUISkinPanel.SetAlignment(const Value: TAlignment);
begin
  FAlignment := Value;
  Invalidate;
end;
procedure TxDUISkinPanel.SetLayout(const Value: TTextLayout);
begin
  FLayout := Value;
  Invalidate;
end;
procedure TxDUISkinPanel.SetMainImg(const Value: String);
begin
  FMainImg := Value;
end;
procedure TxDUISkinPanel.SetReSizeLeft(const Value: Integer);
begin
  FReSizeLeft := Value;
  ReSizeAllImg;
  Invalidate;
end;
procedure TxDUISkinPanel.SetReSizeRight(const Value: Integer);
begin
  FReSizeRight := Value;
  ReSizeAllImg;
  Invalidate;
end;
procedure TxDUISkinPanel.CMEnabledChanged(var Msg: TMessage);
begin
  inherited;
  Invalidate;
end;
procedure TxDUISkinPanel.CMFontChanged(var Msg: TMessage);
begin
  Invalidate;
end;
procedure TxDUISkinPanel.Clone(Btn: TxDUISkinPanel; IsFont: Boolean = True);
begin
  ImgUp := Btn.ImgUp;
  if IsFont then
    Font := Btn.Font;
  Alignment := Btn.Alignment;
  Layout := Btn.Layout;
end;
procedure TxDUISkinPanel.CMColorChanged(var Message: TMessage);
begin
end;
procedure TxDUISkinPanel.SetDrawFrame(const Value: Boolean);
begin
  FDrawFrame := Value;
end;
procedure TxDUISkinPanel.SetDrawFrameColor(const Value: TColor);
begin
  FDrawFrameColor := Value;
end;
procedure TxDUISkinPanel.CreateDisabledImg;
var
  Img: IGPBitmap;
begin
  if ImgUp <> nil then
  begin
    FIsCreateDisabledImg := True;
    CloneGDIImg(Img, ImgUp);
    GrayScale(Img);
  end;
end;
procedure TxDUISkinPanel.SetImgUp(const Value: IGPBitmap);
begin
  if ImgUp <> Value then
  begin
    ImgUp := Value;
  end;
end;
procedure TxDUISkinPanel.SetImgMain(const Value: IGPBitmap);
begin
  ImgMain := Value;
end;
procedure TxDUISkinPanel.ImgCopyRect(var Img: IGPBitmap; Value: Boolean);
var
  W, H, X, Y: Integer;
  r: TRect;
  g: IGPGraphics;
begin
  if Value and (ImgMain <> nil) then
  begin
    W := ImgMain.GetWidth;
    H := ImgMain.GetHeight;
    Y := H;
    r := Rect(0, 0, W, Y);
    OffsetRect(r, 0, 0);
    Img := TGPBitmap.Create(W, Y, PixelFormat32bppARGB);
    g := TGPGraphics.Create(Img);
    try
      g.DrawImage(ImgMain, MakeRect(0, 0, Img.GetWidth, Img.GetHeight), r.Left, r.Top, Img.GetWidth, Img.GetHeight, UnitPixel);
    finally
    end;
  end;
end;
procedure  TxDUISkinPanel .SetAlphaDrawImg(const Value: Integer);
begin
  FAlphaDrawImg := Value;
  Invalidate;
end;
procedure TxDUISkinPanel.SetTabStyle(const Value: Boolean);
begin
  FTabStyle := Value;
  Invalidate;
end;
procedure TxDUISkinPanel.SetTileRect(const Value: TRect);
begin
  FTileRect := Value;
end;
procedure TxDUISkinPanel.SetTopShading(const Value: String);
begin
  FTopShading := Value;
end;
procedure TxDUISkinPanel.SetTopShowPic(const Value: String);
begin
  FTopShowPic := Value;
end;
procedure TxDUISkinPanel.SetDivisionImg(const Value: Boolean);
begin
  //开始绘制Skin
  FDivisionImg:=Value;
  if not FileExists(FMainImg) then
  begin
    Exit;
  end;
  ImgMain:=TGPBitmap.Create(FMainImg);
  ImgCopyRect(ImgUp, Value);
  Invalidate;
end;

end.

本文转自狗窝博客51CTO博客,原文链接http://blog.51cto.com/fxh7622/701028如需转载请自行联系原作者


fxh7622

相关文章
|
7月前
MFC编写DLL窗口功能代码
MFC编写DLL窗口功能代码
38 0
|
C#
56【WinForm】WinForm创建类库项目,并同时在项目中调用类库文件C#
【WinForm】WinForm创建类库项目,并同时在项目中调用类库文件C#
264 0
|
安全 IDE 小程序
QT应用编程: Visual Studio里编写activex控件在网页中运行(dll插件形式)
QT应用编程: Visual Studio里编写activex控件在网页中运行(dll插件形式)
261 0
QT应用编程: Visual Studio里编写activex控件在网页中运行(dll插件形式)
|
Web App开发 安全 JavaScript