⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sthirdparty.pas

📁 I mComputermaster programmisDelphi+pascal
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit sThirdParty;
{$I sDefs.inc}

interface

uses
  Messages, SysUtils, Classes, Windows, Graphics, Controls, Forms, Dialogs, ActnList, imglist,
    comctrls, StdCtrls, sCommonData, sConst, sBitBtn, sSpeedButton{$IFNDEF ALITE}, sToolBar{$ENDIF}
    {$IFDEF USEPNG}, PngImageList, PngFunctions, PngImage{$ENDIF};

function GetImageCount(ImgList : TCustomImageList) : integer;
procedure DrawBtnGlyph(Button : TControl; Canvas : TCanvas = nil);
{$IFNDEF ALITE}
procedure CopyToolBtnGlyph(ToolBar : TsToolBar; Button : TToolButton; State: TCustomDrawState; Stage: TCustomDrawStage; var Flags: TTBCustomDrawFlags; BtnBmp : TBitmap);
{$ENDIF}

implementation

uses sGraphUtils, acAlphaImageList, CommCtrl, acntUtils, acPNG;

function GetImageCount(ImgList : TCustomImageList) : integer;
begin
  Result := 0;
  if ImgList = nil then Exit;
{$IFDEF USEPNG}
  if ImgList is TPngImageList then begin
    Result := TPngImageList(ImgList).PngImages.Count;
  end
  else
{$ENDIF}
  Result := ImgList.Count;
end;

procedure DrawBtnGlyph(Button : TControl; Canvas : TCanvas = nil);
var
  IRect : TRect;
  Bmp : TBitmap;
  MaskColor: TsColor;
  TmpPng : TPNGGraphic;

  Images : TCustomImageList;
  Glyph : TBitmap;
  ImageIndex : integer;
  SkinData : TsCommonData;
  ImgRect : TRect;
  NumGlyphs : integer;
  Enabled : boolean;
  DisabledGlyphKind : TsDisabledGlyphKind;
  Blend : integer;
  Down : boolean;
  CurrentState : integer;
  Grayed : boolean;
{$IFDEF USEPNG}
  PngCopy: TPNGObject;
{$ENDIF}
  procedure PrepareGlyph; begin
    Bmp.Width := Images.Width;
    Bmp.Height := Images.Height;
    Bmp.PixelFormat := pf24bit;
    if Images.BkColor <> clNone then MaskColor.C := Images.BkColor else MaskColor.C := clFuchsia;
    Bmp.Canvas.Brush.Color := MaskColor.C;
    Bmp.Canvas.FillRect(Rect(0, 0, Bmp.Width, Bmp.Height));
    Images.GetBitmap(ImageIndex, Bmp);
  end;
begin
  if Button is TsBitBtn then begin
    Images     := TsBitBtn(Button).Images;
    Glyph      := TsBitBtn(Button).Glyph;
    ImageIndex := TsBitBtn(Button).ImageIndex;
    SkinData   := TsBitBtn(Button).SkinData;
    ImgRect    := TsBitBtn(Button).ImgRect;
    NumGlyphs  := TsBitBtn(Button).NumGlyphs;
    Enabled    := TsBitBtn(Button).Enabled;
    Blend      := TsBitBtn(Button).Blend;
    Down       := TsBitBtn(Button).Down;
    Grayed     := TsBitBtn(Button).Grayed;
    CurrentState := TsBitBtn(Button).CurrentState;
    DisabledGlyphKind := TsBitBtn(Button).DisabledGlyphKind;
  end
  else if Button is TsSpeedButton then begin
    Images     := TsSpeedButton(Button).Images;
    Glyph      := TsSpeedButton(Button).Glyph;
    ImageIndex := TsSpeedButton(Button).ImageIndex;
    SkinData   := TsSpeedButton(Button).SkinData;
    ImgRect    := TsSpeedButton(Button).ImgRect;
    NumGlyphs  := TsSpeedButton(Button).NumGlyphs;
    Enabled    := TsSpeedButton(Button).Enabled;
    Blend      := TsSpeedButton(Button).Blend;
    Down       := TsSpeedButton(Button).Down;
    Grayed     := TsSpeedButton(Button).Grayed;
    CurrentState := TsSpeedButton(Button).CurrentState;
    DisabledGlyphKind := TsSpeedButton(Button).DisabledGlyphKind;
  end
  else Exit;

  if not Glyph.Empty then begin
    if (NumGlyphs = 1) and (Blend = 0) and (Glyph.PixelFormat = pf32bit) then begin // Patch if Png, don't work in std. mode
      TmpPng := TPNGGraphic.Create;
      TmpPng.PixelFormat := pf32bit;
      TmpPng.Width := Glyph.Width;
      TmpPng.Height := Glyph.Height;
      BitBlt(TmpPng.Canvas.Handle, 0, 0, Glyph.Width, Glyph.Height, Glyph.Canvas.Handle, 0, 0, SRCCOPY);
      SkinData.FCacheBmp.Canvas.Draw(ImgRect.Left, ImgRect.Top, TmpPng);
      TmpPng.Free;
    end
    else sGraphUtils.DrawGlyphEx(Glyph, SkinData.FCacheBmp, ImgRect, NumGlyphs, Enabled, DisabledGlyphKind, integer(ControlIsActive(SkinData)), Blend, Down);
  end
  else if Assigned(Images) and (ImageIndex > -1) and (GetImageCount(Images) > ImageIndex) then begin
    IRect := ImgRect;
{$IFDEF USEPNG}
    if Images is TPngImageList then begin
      PngCopy := nil;
      if Enabled then begin
        if ControlIsActive(SkinData) or ((Blend = 0) and not Grayed) then begin
          PngCopy := TPngImageCollectionItem(TPngImageList(Images).PngImages.Items[ImageIndex]).PngImage;
          if SkinData.Skinned
            then PngCopy.Draw(SkinData.FCacheBmp.Canvas, IRect)
            else PngCopy.Draw(Canvas, IRect);
        end
        else begin
          if Blend > 0 then begin
            PngCopy := TPNGObject.Create;
            PngCopy.Assign(TPngImageCollectionItem(TPngImageList(Images).PngImages.Items[ImageIndex]).PngImage);
            MakeImageBlended(PngCopy);
          end;
          if Grayed then begin
            if PngCopy = nil then begin
              PngCopy := TPNGObject.Create;
              PngCopy.Assign(TPngImageCollectionItem(TPngImageList(Images).PngImages.Items[ImageIndex]).PngImage);
            end;
            MakeImageGrayscale(PngCopy);
          end;
          if SkinData.Skinned
            then PngCopy.Draw(SkinData.FCacheBmp.Canvas, IRect)
            else PngCopy.Draw(Canvas, IRect);
          FreeAndNil(PngCopy);
        end;
      end
      else begin
        if dgBlended in DisabledGlyphKind then begin
          PngCopy := TPNGObject.Create;
          PngCopy.Assign(TPngImageCollectionItem(TPngImageList(Images).PngImages.Items[ImageIndex]).PngImage);
          MakeImageBlended(PngCopy);
        end;
        if dgGrayed in DisabledGlyphKind then begin
          if PngCopy = nil then begin
            PngCopy := TPNGObject.Create;
            PngCopy.Assign(TPngImageCollectionItem(TPngImageList(Images).PngImages.Items[ImageIndex]).PngImage);
          end;
          MakeImageGrayscale(PngCopy);
        end;
        if PngCopy = nil then begin
          PngCopy := TPngImageCollectionItem(TPngImageList(Images).PngImages.Items[ImageIndex]).PngImage;
          if SkinData.Skinned
            then PngCopy.Draw(SkinData.FCacheBmp.Canvas, IRect)
            else PngCopy.Draw(Canvas, IRect);
        end
        else begin
          if SkinData.Skinned
            then PngCopy.Draw(SkinData.FCacheBmp.Canvas, IRect)
            else PngCopy.Draw(Canvas, IRect);
          FreeAndNil(PngCopy);
        end;
      end;
    end
    else
{$ENDIF}
    if (Images is TsAlphaImageList) or not SkinData.Skinned then begin
      if SkinData.Skinned
        then DrawAlphaImgList(Images, SkinData.FCacheBmp, IRect.Left, IRect.Top, ImageIndex, iffi(CurrentState = 0, Blend, 0), iffi((CurrentState = 0) and Grayed, SkinData.SkinManager.gd[SkinData.SkinIndex].Color{.FontColor[1]}, clNone), CurrentState, NumGlyphs)
        else DrawAlphaImgListDC(Images, Canvas.Handle, IRect.Left, IRect.Top, ImageIndex, iffi(CurrentState = 0, Blend, 0), iffi((CurrentState = 0) and Grayed, ColorToRGB(clBtnFace), clNone), CurrentState, NumGlyphs);
    end
    else begin
      Bmp := TBitmap.Create;
      try
        PrepareGlyph;
        if not Enabled then begin
          if dgGrayed in DisabledGlyphKind then begin
            GrayScaleTrans(Bmp, ColorToSColor(Bmp.Canvas.Pixels[0, 0]));
          end;
          if dgBlended in DisabledGlyphKind then begin
            BlendTransRectangle(SkinData.FCacheBmp, IRect.Left, IRect.Top, Bmp,
                                  Rect(0, 0, Bmp.Width, Bmp.Height), 0.5, MaskColor);
          end
          else begin
            CopyTransBitmaps(SkinData.FCacheBmp, Bmp, IRect.Left, IRect.Top, MaskColor);
          end;
        end
        else begin
          if not ControlIsActive(SkinData) and Grayed then begin
            GrayScaleTrans(Bmp, ColorToSColor(Bmp.Canvas.Pixels[0, 0]));
          end;
          if not ControlIsActive(SkinData) and (Blend > 0) then begin
            BlendTransRectangle(SkinData.FCacheBmp, IRect.Left, IRect.Top, Bmp, Rect(0, 0, Bmp.Width, Bmp.Height), Blend / 100, MaskColor);
          end
          else begin
            CopyTransBitmaps(SkinData.FCacheBmp, Bmp, IRect.Left, IRect.Top, MaskColor);
          end;
        end;
      finally
        FreeAndNil(Bmp);
      end;
    end;
  end;
end;

procedure DrawSpeedButtonGlyph(Button : TsSpeedButton);
var
  IRect : TRect;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -