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

📄 tewipe.pas

📁 delphi2007界面效果控件源码
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit teWipe;

interface

{$INCLUDE teDefs.inc}

uses
  SysUtils, Classes, TransEff, teTimed, Windows, Messages, Graphics;

type
  TWipeTransition = class(TTimedTransitionEffect)
  private
    FBandWidth: Word;
    FSmoothBand: Boolean;

    function GetBandData(Data: TTETransitionData;
      var ABandWidth: Word): Boolean;
  protected
    procedure Initialize(Data: TTETransitionData; var TotalFrames: Longint);
      override;
    procedure ExecuteFrame(Data: TTETransitionData; CurrentFrame, Step,
      LastExecutedFrame: Longint); override;
    function GetBitmapsWidth(Data: TTETransitionData): Integer; override;
    function GetInfo(Device: TTETransitionDevice): TTETransitionInfo; override;
    function GetPixelFormat(Device: TTETransitionDevice): TPixelFormat; override;
    function Smooth(Device: TTETransitionDevice): Boolean;
  public
    constructor Create(AOwner: TComponent = nil); override;
    class function Description: String; override;

    procedure Assign(Source: TPersistent); override;
    class function GetEditor: String; override;
  published
    property BandWidth: Word read FBandWidth write FBandWidth default 50;
    property Direction default tedRight;
    property Pass2Options;
    property PassSetting;
    property Reversed;
    property SmoothBand: Boolean read FSmoothBand write FSmoothBand default False;
  end;

implementation

uses teRender, teMskWk;

const
  Margin = 75;

type
  TWipeData = class(TTECustomData)
  public
    BandBmp,
    AuxBmp1,
    AuxBmp2: TBitmap;
    RVisible,
    R2,
    RBand: TRect;
    BandLeft,
    BandTop,
    BandWidth: Word;
    SmoothBand: Boolean;
    Apply256MaskSProc: PByteArray;

    destructor Destroy; override;
  end;

constructor TWipeTransition.Create(AOwner: TComponent);
begin
  inherited;

  AllowedDirections := [tedRight, tedLeft, tedDown, tedUp, tedDownRight,
    tedDownLeft, tedUpRight, tedUpLeft, tedIn, tedOut, tedRandom];
  Direction         := tedRight;
  FBandWidth        := 50;
  FSmoothBand       := False;
end;

class function TWipeTransition.Description: String;
begin
  Result := 'Wipe';
end;

procedure TWipeTransition.Assign(Source: TPersistent);
var
  Transition: TWipeTransition;
begin
  if Source is TWipeTransition
  then
  begin
    inherited;

    Transition  := TWipeTransition(Source);
    FBandWidth  := Transition.BandWidth;
    FSmoothBand := Transition.SmoothBand;
  end
  else inherited;
end;

class function TWipeTransition.GetEditor: String;
begin
  Result := 'TWipeTransitionEditor';
end;

procedure TWipeTransition.Initialize(Data: TTETransitionData;
  var TotalFrames: Longint);

  function CreateBandBmp: TBitmap;
  var
    i,
    j,
    Prob: Integer;
  begin
    RandSeed := 1642000;
    Result   := TBitmap.Create;
    Result.Canvas.Lock;
    Result.Monochrome := True;

    case DirectionToUse of
      tedRight,
      tedLeft:
      begin
        Result.Width  := FBandWidth;
        Result.Height := Data.Height + Margin;
      end;
      tedDown,
      tedUp:
      begin
        Result.Width  := Data.Width + Margin;
        Result.Height := FBandWidth;
      end;
    end;

    case DirectionToUse of
      tedRight:
      begin
        for i:=0 to FBandWidth-1 do
        begin
          Prob := 100 - ((i * 100) DIV FBandWidth);
          if Prob = 0 then
            Prob := 1;
          for j:=0 to Result.Height do
            if Random(100) <= Prob then
              Result.Canvas.Pixels[i, j] := clBlack;
        end;
      end;
      tedLeft:
      begin
        for i:=0 to FBandWidth-1 do
        begin
          Prob := ((i * 100) DIV FBandWidth);
          if Prob = 0 then
            Prob := 1;
          for j:=0 to Result.Height do
            if Random(100) <= Prob then
              Result.Canvas.Pixels[i, j] := clBlack;
        end;
      end;
      tedDown:
      begin
        for j:=0 to FBandWidth-1 do
        begin
          Prob := 100 - ((j * 100) DIV FBandWidth);
          if Prob = 0 then
            Prob := 1;
          for i:=0 to Result.Width do
            if Random(100) <= Prob then
              Result.Canvas.Pixels[i, j] := clBlack;
        end;
      end;
      tedUp:
      begin
        for j:=0 to FBandWidth-1 do
        begin
          Prob := ((j * 100) DIV FBandWidth);
          if Prob = 0 then
            Prob := 1;
          for i:=0 to Result.Width do
            if Random(100) <= Prob then
              Result.Canvas.Pixels[i, j] := clBlack;
        end;
      end;
    end;
  end;

  function CreateSmoothBandBmp(WipeData: TWipeData): TBitmap;
  var
    Src,
    Work: PChar;
    BandBmpWidth,
    BandBmpHeight,
    i,
    j,
    aux,
    ScanLineSize,
    First,
    Last: Integer;
    Level: Byte;
    Step: Double;
  begin
    Result := nil;
    case DirectionToUse of
      tedRight,
      tedLeft:
      begin
        BandBmpWidth  := WipeData.BandWidth;
        BandBmpHeight := Data.Height;

        Result := TBitmap.Create;
        Result.Canvas.Lock;
        AdjustBmpForTransition(Result, CreateGrayScalePalette, BandBmpWidth,
          BandBmpHeight, pf8bit);
        ScanLineSize := GetBytesPerScanline(Result, pf8bit, 32);
        Work         := Result.ScanLine[Data.Height-1];
        Src          := Work;
        Step         := 253 / (WipeData.BandWidth + 1);

        if DirectionToUse = tedRight
        then
        begin
          First := 0;
          Last  := BandBmpWidth;
        end
        else
        begin
          First := BandBmpWidth-1;
          Last  := -1;
        end;
        aux := First;
        while aux <> Last do
        begin
          Level := Round(aux * Step) + 1;
          Work^ := Char(Level);
          Inc(Work);
          if DirectionToUse = tedRight
          then Inc(aux)
          else Dec(aux);
        end;
        Work := PChar(Src) + ScanLineSize;
        for i := 1 to BandBmpHeight-1 do
        begin
          Move(Src[0], Work[0], ScanLineSize);
          Inc(Work, ScanLineSize);
        end;
      end;
      tedDown,
      tedUp:
      begin
        BandBmpHeight := WipeData.BandWidth;
        BandBmpWidth  := Data.Width;

        Result := TBitmap.Create;
        Result.Canvas.Lock;
        AdjustBmpForTransition(Result, CreateGrayScalePalette, BandBmpWidth,
          BandBmpHeight, pf8bit);
        ScanLineSize := GetBytesPerScanline(Result, pf8bit, 32);
        Work         := Result.ScanLine[BandBmpHeight-1];
        Step         := 253 / (BandBmpHeight + 1);

        if DirectionToUse = tedUp
        then First := 0
        else First := BandBmpHeight-1;
        aux := First;
        for i := 0 to BandBmpHeight-1 do
        begin
          Level := Round(aux * Step) + 1;
          for j := 0 to BandBmpWidth-1 do
            Work[j] := Char(Level);
          Inc(Work, ScanLineSize);
          if DirectionToUse = tedUp
          then Inc(aux)
          else Dec(aux);
        end;
      end;
    end;
  end;

var
  auxWidth,
  auxHeight: Integer;
  WipeData: TWipeData;
begin
  inherited;

  WipeData            := TWipeData.Create(Data);
  Data.Custom         := WipeData;
  WipeData.AuxBmp1    := nil;
  WipeData.AuxBmp2    := nil;
  WipeData.BandBmp    := nil;
  WipeData.BandLeft   := 0;
  WipeData.BandTop    := 0;
  WipeData.SmoothBand := Smooth(Data.Device);
  GetBandData(Data, WipeData.BandWidth);
  if WipeData.BandWidth > 0 then
  begin
    if WipeData.SmoothBand
    then
    begin
      WipeData.BandBmp := CreateSmoothBandBmp(WipeData);
      WipeData.AuxBmp1 := TBitmap.Create;
      WipeData.AuxBmp1.Canvas.Lock;
      AdjustBmpForTransition(WipeData.AuxBmp1, CreateGrayScalePalette,
        Data.Bitmap.Width, Data.Height, pf8bit);
      WipeData.Apply256MaskSProc := GetApply256MaskSProc;
    end
    else
    begin
      WipeData.BandBmp := CreateBandBmp;

      WipeData.AuxBmp1 := TBitmap.Create;
      WipeData.AuxBmp1.Canvas.Lock;
      WipeData.AuxBmp2 := TBitmap.Create;
      WipeData.AuxBmp2.Canvas.Lock;

      auxWidth  := 0;
      auxHeight := 0;
      case DirectionToUse of
        tedRight, tedLeft:
        begin
          auxWidth  := WipeData.BandBmp.Width;
          auxHeight := WipeData.BandBmp.Height - Margin;
        end;
        tedDown, tedUp   :
        begin
          auxWidth  := WipeData.BandBmp.Width - Margin;
          auxHeight := WipeData.BandBmp.Height;
        end;
      end;

      AdjustBmpForTransition(WipeData.AuxBmp1, Data.DstBmp.Palette, auxWidth,
        auxHeight, GetPixelFormat(Data.Device));
      AdjustBmpForTransition(WipeData.AuxBmp2, Data.DstBmp.Palette, auxWidth,
        auxHeight, WipeData.AuxBmp1.PixelFormat);
    end;
  end;

  case DirectionToUse of
    tedRight:
    begin
      TotalFrames       := Data.Width + WipeData.BandWidth - 1;
      WipeData.RVisible :=
        Rect(0 - WipeData.BandWidth+1, 0, -WipeData.BandWidth, Data.Height);
      if Assigned(WipeData.BandBmp) then
        WipeData.RBand := Rect(WipeData.RVisible.Right+1, WipeData.RVisible.Top,
          WipeData.RVisible.Right+WipeData.BandWidth+1, WipeData.RVisible.Bottom);
    end;
    tedLeft:
    begin
      TotalFrames   := Data.Width + WipeData.BandWidth - 1;
      WipeData.RVisible := Rect(Data.Width + WipeData.BandWidth, 0,
        Data.Width + WipeData.BandWidth, Data.Height);
      if Assigned(WipeData.BandBmp) then
        WipeData.RBand := Rect(WipeData.RVisible.Left-WipeData.BandWidth-1,
          WipeData.RVisible.Top, WipeData.RVisible.Right-1,
          WipeData.RVisible.Bottom);
    end;
    tedDown:
    begin
      TotalFrames   := Data.Height + WipeData.BandWidth - 1;
      WipeData.RVisible := Rect(0, - WipeData.BandWidth, Data.Width, -WipeData.BandWidth);
      if Assigned(WipeData.BandBmp) then
        WipeData.RBand := Rect(WipeData.RVisible.Left,
          WipeData.RVisible.Bottom+1, WipeData.RVisible.Right,
          WipeData.RVisible.Bottom+WipeData.BandWidth+1);
    end;
    tedUp:
    begin
      TotalFrames   := Data.Height + WipeData.BandWidth - 1;
      WipeData.RVisible := Rect(0, Data.Height + WipeData.BandWidth, Data.Width,
        Data.Height + WipeData.BandWidth);
      if WipeData.BandBmp <> nil then
        WipeData.RBand := Rect(WipeData.RVisible.Left,

⌨️ 快捷键说明

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