📄 tewipe.pas
字号:
unit teWipe;
interface
{$INCLUDE teDefs.inc}
uses
SysUtils, Classes, TransEff, teTimed,
{$ifdef CLX}
QForms, QGraphics;
{$else}
Windows, Messages, Forms, Graphics;
{$endif CLX}
type
TWipeTransition = class(TTimedTransitionEffect)
private
FBandWidth: Integer;
LastDirectionUsed: TTEEffectDirection;
function GetBandWidth: Integer;
procedure SetBandWidth(const Value: Integer);
protected
BandBmp,
AuxBmp1,
AuxBmp2: TBitmap;
RVisible,
R2,
RBand: TRect;
BandLeft,
BandTop: Integer;
procedure Initialize(Data: TTETransitionData; var Frames: Longint); override;
procedure ExecuteFrame(Data: TTETransitionData;
CurrentFrame, Step, TotalFrames, LastExecutedFrame: Longint); override;
procedure Finalize(Data: TTETransitionData); override;
function RenderWhenClipped: Boolean; override;
function NeedSrcImage: Boolean; override;
function UseOffScreenBmp: Boolean; override;
public
constructor Create(AOwner: TComponent{$ifdef DP} = nil{$endif}); override;
destructor Destroy; override;
class function Description: String; override;
procedure Assign(Source: TPersistent); override;
class function GetEditor: String; override;
published
property BandWidth: Integer read GetBandWidth write SetBandWidth default 50;
property Direction default tedRight;
property Reversed;
end;
implementation
uses teRender;
const
Margin = 75;
constructor TWipeTransition.Create(AOwner: TComponent);
begin
inherited;
AllowedDirections := [tedRight, tedLeft, tedDown, tedUp, tedDownRight,
tedDownLeft, tedUpRight, tedUpLeft, tedIn, tedOut];
Direction := tedRight;
LastDirectionUsed := tedRight;
BandWidth := 50;
AuxBmp1 := nil;
AuxBmp2 := nil;
BandBmp := nil;
end;
destructor TWipeTransition.Destroy;
begin
BandBmp.Free;
BandBmp := nil;
inherited;
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);
BandWidth := Transition.BandWidth;
end
else inherited;
end;
class function TWipeTransition.GetEditor: String;
begin
Result := 'TWipeTransitionEditor';
end;
function TWipeTransition.GetBandWidth: Integer;
begin
case DirectionToUse of
tedRight,
tedLeft,
tedDown,
tedUp : Result := FBandWidth;
tedDownRight,
tedDownLeft,
tedUpRight,
tedUpLeft,
tedIn,
tedOut : Result := 0;
else Result := 0;
end;
end;
procedure TWipeTransition.SetBandWidth(const Value: Integer);
begin
FBandWidth := Value;
end;
function TWipeTransition.RenderWhenClipped: Boolean;
begin
Result := False;
end;
function TWipeTransition.NeedSrcImage: Boolean;
begin
Result := BandWidth > 0;
end;
function TWipeTransition.UseOffScreenBmp: Boolean;
begin
Result := BandWidth > 0;
end;
procedure TWipeTransition.Initialize(Data: TTETransitionData; var Frames: Longint);
function CreateBandBmp(Width, Height: Integer): TBitmap;
var
i, j,
Prob: Integer;
begin
RandSeed := 1642000;
Result := TBitmap.Create;
Result.Monochrome := True;
Result.Width := Width;
Result.Height := Height;
case DirectionToUse of
tedRight:
begin
for i:=0 to BandWidth-1 do
begin
Prob := 100 - ((i * 100) DIV BandWidth);
if Prob = 0 then
Prob := 1;
for j:=0 to Height do
if Random(100) <= Prob then
Result.Canvas.Pixels[i, j] := clBlack;
end;
end;
tedLeft:
begin
for i:=0 to BandWidth-1 do
begin
Prob := ((i * 100) DIV BandWidth);
if Prob = 0 then
Prob := 1;
for j:=0 to Height do
if Random(100) <= Prob then
Result.Canvas.Pixels[i, j] := clBlack;
end;
end;
tedDown:
begin
for j:=0 to BandWidth-1 do
begin
Prob := 100 - ((j * 100) DIV BandWidth);
if Prob = 0 then
Prob := 1;
for i:=0 to Width do
if Random(100) <= Prob then
Result.Canvas.Pixels[i, j] := clBlack;
end;
end;
tedUp:
begin
for j:=0 to BandWidth-1 do
begin
Prob := ((j * 100) DIV BandWidth);
if Prob = 0 then
Prob := 1;
for i:=0 to Width do
if Random(100) <= Prob then
Result.Canvas.Pixels[i, j] := clBlack;
end;
end;
end;
LastDirectionUsed := DirectionToUse;
end;
var
BandBmpWidth,
BandBmpHeight,
auxWidth,
auxHeight: Integer;
begin
AuxBmp1 := nil;
AuxBmp2 := nil;
BandLeft := 0;
BandTop := 0;
BandBmpWidth := 0;
BandBmpHeight := 0;
if BandWidth = 0
then
begin
BandBmp.Free;
BandBmp := nil;
end
else
begin
case DirectionToUse of
tedRight, tedLeft:
begin
BandBmpWidth := BandWidth;
BandBmpHeight := Data.Height + Margin;
end;
tedDown, tedUp:
begin
BandBmpWidth := Data.Width + Margin;
BandBmpHeight := BandWidth;
end;
end;
if(BandBmp = nil) or
(BandBmpWidth <> BandBmp.Width) or
(BandBmpHeight <> BandBmp.Height) or
(DirectionToUse <> LastDirectionUsed) then
begin
BandBmp.Free;
BandBmp := CreateBandBmp(BandBmpWidth, BandBmpHeight);
end;
AuxBmp1 := TBitmap.Create;
AuxBmp2 := TBitmap.Create;
auxWidth := 0;
auxHeight := 0;
case DirectionToUse of
tedRight, tedLeft:
begin
auxWidth := BandBmp.Width;
auxHeight := BandBmp.Height - Margin;
end;
tedDown, tedUp :
begin
auxWidth := BandBmp.Width - Margin;
auxHeight := BandBmp.Height;
end;
end;
AdjustBmpForTransition(AuxBmp1, Data.DstBmp.Palette, auxWidth, auxHeight,
GetPixelFormat);
AdjustBmpForTransition(AuxBmp2, Data.DstBmp.Palette, auxWidth, auxHeight,
GetPixelFormat);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -