📄 tepage.pas
字号:
begin
Limit := DstIndex + DstUpdRowLen;
while DstIndex < Limit do
begin
if Src[DstIndex ] > Dst[DstIndex+3]
then Dst[DstIndex ] := Src[DstIndex ] - Dst[DstIndex+3]
else Dst[DstIndex ] := 0;
if Src[DstIndex+1] > Dst[DstIndex+3]
then Dst[DstIndex+1] := Src[DstIndex+1] - Dst[DstIndex+3]
else Dst[DstIndex+1] := 0;
if Src[DstIndex+2] > Dst[DstIndex+3]
then Dst[DstIndex+2] := Src[DstIndex+2] - Dst[DstIndex+3]
else Dst[DstIndex+2] := 0;
Inc(PChar(Src), PDWord(@ArcData[DstIndex])^);
Inc(DstIndex, 4);
end;
Inc(DstIndex , DstUpdGap);
Inc(PChar(Src) , SrcUpdGap);
Dec(PChar(ArcData), ArcDataGap);
end;
end
else
begin
while DstIndex < 0 do
begin
Limit := DstIndex + DstUpdRowLen;
while DstIndex < Limit do
begin
Light := -Dst[DstIndex+3];
if Src[DstIndex ] < Light
then Dst[DstIndex ] := Src[DstIndex ] + Dst[DstIndex+3]
else Dst[DstIndex ] := 255;
if Src[DstIndex+1] < Light
then Dst[DstIndex+1] := Src[DstIndex+1] + Dst[DstIndex+3]
else Dst[DstIndex+1] := 255;
if Src[DstIndex+2] < Light
then Dst[DstIndex+2] := Src[DstIndex+2] + Dst[DstIndex+3]
else Dst[DstIndex+2] := 255;
Inc(PChar(Src), PDWord(@ArcData[DstIndex])^);
Inc(DstIndex, 4);
end;
Inc(DstIndex , DstUpdGap);
Inc(PChar(Src) , SrcUpdGap);
Dec(PChar(ArcData), ArcDataGap);
end;
end;
end;
class function TPageTransition.Description: String;
begin
Result := 'Page';
end;
procedure TPageTransition.Assign(Source: TPersistent);
begin
if Source is TPageTransition
then
begin
inherited;
Use3D := TPageTransition(Source).Use3D;
Size := TPageTransition(Source).Size;
Uncover := TPageTransition(Source).Uncover;
end
else inherited;
end;
class function TPageTransition.GetEditor: String;
begin
Result := 'TPageTransitionEditor';
end;
procedure TPageTransition.Initialize(Data: TTETransitionData;
var TotalFrames: Longint);
var
PageData: TPageData;
{$ifndef TrialLimited}
procedure PlotPixel(Light: Array of Byte; x, y: Integer);
begin
if x < 0 then
exit;
if PageData.ArcLightMap[x] = 0
then // This is a visible pixel
begin
PageData.ArcLightMap[x] := Light[y];
Inc(PageData.ArcVisPixelCount);
end
else // This is an invisible pixel
begin
PageData.ArcData [x] := PageData.ArcData[x] + 1;
PageData.ArcLightMap[x] := Light[y];
end;
Inc(PageData.ArcPixelCount);
end;
procedure PlotCircle(Light: Array of Byte; x, y, x1, y1: Integer);
var
P1,
P2: TPoint;
begin
P1 := Point(x + x1, y - y1);
PlotPixel(Light, P1.x , P1.y);
P2 := Point(x + y1, y - x1);
if(P1.x <> P2.x) or (P1.y <> P2.y) then
PlotPixel(Light, P2.x , P2.y);
end;
procedure BresenhamCircle(Radius: Integer);
const
BaseLight = 200;
var
TrimLight,
CenterX,
CenterY,
x1,
y1,
p,
i,
j: Integer;
Light: array[0..255] of Byte;
ArcData: PByteArray;
begin
for i := 0 to Radius do
Light[i] := Round((i+1) * (BaseLight / (Radius+1)));
CenterX := 0;
CenterY := Radius;
x1 := 0;
y1 := Radius;
p := 3 - 2 * Radius;
while (x1 < y1) do
begin
PlotCircle(Light, CenterX, CenterY, x1, y1);
if p < 0
then p := p + 4 * x1 + 6
else
begin
p := p + 4 * (x1 - y1) + 10;
Dec(y1);
end;
Inc(x1);
end;
if x1 = y1 then
PlotCircle(Light, CenterX, CenterY, x1, y1);
// Trim the initial arc's area which is almost invisible but eats CPU
TrimLight := 0;
j := 0;
while(j < PageData.ArcVisPixelCount) and (PageData.ArcLightMap[j] <= 253) do
begin
p := 0;
while(j < PageData.ArcVisPixelCount) and
(PageData.ArcData[j] = 0) and
(PageData.ArcLightMap[j] <= TrimLight+1) do
begin
Inc(p);
Inc(j);
end;
if p > 2
then Inc(TrimLight)
else break;
end;
if TrimLight > 0 then
begin
i := 0;
while(PageData.ArcData[i] = 0) and (PageData.ArcLightMap[i] <= TrimLight) do
Inc(i);
if i > 0 then
begin
Dec(PageData.ArcPixelCount , i-(TrimLight*2));
Dec(PageData.ArcVisPixelCount, i-(TrimLight*2));
for j := 0 to TrimLight-1 do
begin
Assert(PageData.ArcData [ j*2 ] = 0);
Assert(PageData.ArcLightMap[ j*2 ] <= j+1);
PageData.ArcLightMap[ j*2 ] := j+1;
Assert(PageData.ArcData [(j*2)+1] = 0);
Assert(PageData.ArcLightMap[(j*2)+1] <= j+1);
PageData.ArcLightMap[(j*2)+1] := j+1;
end;
for j := TrimLight*2 to PageData.ArcVisPixelCount-1 do
begin
PageData.ArcData [j] := PageData.ArcData [j+i-(TrimLight*2)];
PageData.ArcLightMap[j] := PageData.ArcLightMap[j+i-(TrimLight*2)];
end;
end;
end;
// Calculate the reversed arc
for i := 0 to PageData.ArcVisPixelCount - 1 do
begin
PageData.ArcRevData [i] := PageData.ArcData [(PageData.ArcVisPixelCount-1) - i];
PageData.ArcRevLightMap[i] := PageData.ArcLightMap[(PageData.ArcVisPixelCount-1) - i];
end;
// Precalculation table
// if UncoverToUse
// then ArcData := PageData.ArcData
// else ArcData := PageData.ArcRevData;
j := 0;
PageData.ArcPreCalc[0] := 0;
for i := 1 to Radius+1 do
begin
Inc(j, PageData.ArcData[i-1] + 1); // Accumulates with previous
PageData.ArcPreCalc[i] := j;
end;
// Arc custom data
if PageData.Direction in [tedDown, tedLeft]
then ArcData := PageData.ArcData
else ArcData := PageData.ArcRevData;
if PageData.Direction in [tedDown, tedUp]
then
begin
j := GetBytesPerScanline(Data.SrcBmp, pf32bit, 32);
for i := 0 to PageData.ArcVisPixelCount - 1 do
PageData.ArcCustomData[i] := ArcData[i] * j;
end
else
begin
for i := 0 to PageData.ArcVisPixelCount - 1 do
PageData.ArcCustomData[i] := (ArcData[i]) * 4;
end;
end;
{$endif TrialLimited}
procedure EmbedLight(Direction: TTEEffectDirection; Bmp1, Bmp2: TBitmap;
LightMap, RevLightMap: PByteArray);
const
MaxLight = 50;
var
i,
Index,
Limit,
ScanLineSize: Integer;
Light,
Dst1,
Dst2: PByteArray;
aux: Byte;
begin
ScanLineSize := GetBytesPerScanline(Bmp1, pf32bit, 32);
Dst1 := PByteArray(PChar(Bmp1.ScanLine[0]) + ScanlineSize);
Dst2 := PByteArray(PChar(Bmp2.ScanLine[0]) + ScanlineSize);
Index := -(ScanlineSize * Bmp1.Height);
if Direction in [tedDown, tedLeft]
then Light := LightMap
else Light := RevLightMap;
if Direction in [tedDown, tedUp]
then
begin
i := 0;
while Index < 0 do
begin
if Light[i] > MaxLight
then aux := MaxLight
else aux := Light[i];
Limit := Index + ScanLineSize;
while Index < Limit do
begin
Dst1[Index+3] := aux;
Dst2[Index+3] := Light[i];
Inc(Index, 4);
end;
Inc(i);
end;
end
else
begin
while Index < 0 do
begin
i := 0;
Limit := Index + ScanLineSize;
while Index < Limit do
begin
if Light[i] > MaxLight
then Dst1[Index+3] := MaxLight
else Dst1[Index+3] := Light[i];
Dst2[Index+3] := Light[i];
Inc(Index, 4);
Inc(i);
end;
end;
end;
end;
var
W,
H,
SizeToUse: Integer;
begin
inherited;
if DirectionToUse in [tedDown, tedUp]
then
begin
W := Data.Width;
H := Data.Height;
end
else
begin
W := Data.Height;
H := Data.Width;
end;
SizeToUse := FSize;
if not Is3D(Data.Device)
then SizeToUse := 0
else
if SizeToUse > H div 3 then
SizeToUse := H div 3;
PageData := TPageData.Create(Data, SizeToUse, UncoverToUse, DirectionToUse);
Data.Custom := PageData;
PageData.Width := W;
PageData.Height := H;
if Data.Bitmap = nil
then PageData.DoScroll := not(Data.Device.DynamicClipping or Data.Device.Clipped)
else PageData.DoScroll := True;
PageData.RClip := PageData.Rects.CreateRect(PageData.Width, PageData.Height, 0, 0, W, H);
AdjustBmpForTransition(PageData.BmpReversed, 0, Data.Width, Data.Height, pf32bit);
{$ifndef TrialLimited}
if SizeToUse > 0 then
BresenhamCircle(SizeToUse-1);
Assert(PageData.ArcPixelCount <= H);
{$endif TrialLimited}
if UncoverToUse
then PageData.Bmp := Data.SrcBmp
else PageData.Bmp := Data.DstBmp;
TotalFrames := PageData.Height + PageData.ArcVisPixelCount - 1;
PageData.R1Arc3D := PageData.Rects.CreateRect(PageData.Width,
PageData.ArcVisPixelCount, 0, 0, PageData.Width, PageData.ArcVisPixelCount);
PageData.R2Arc3D := PageData.Rects.CreateRect(PageData.Width,
PageData.Height , 0, 0, PageData.Width, PageData.Height);
PageData.R1ArcRev3D := PageData.Rects.CreateRect(PageData.Width,
PageData.ArcVisPixelCount, 0, 0, PageData.Width, PageData.ArcVisPixelCount);
PageData.R2ArcRev3D := PageData.Rects.CreateRect(PageData.Width,
PageData.Height , 0, 0, PageData.Width, PageData.Height);
if SizeToUse > 0 then
begin
AdjustBmpForTransition(PageData.BmpArc , 0, PageData.R1Arc3D.TgtWidth,
PageData.R1Arc3D.TgtHeight, pf32bit);
AdjustBmpForTransition(PageData.BmpArcRev, 0, PageData.R1Arc3D.TgtWidth,
PageData.R1Arc3D.TgtHeight, pf32bit);
EmbedLight(PageData.Direction, PageData.BmpArc, PageData.BmpArcRev,
PageData.ArcLightMap, PageData.ArcRevLightMap);
end;
if DirectionToUse in [tedDown, tedUp]
then StretchBlt(
PageData.BmpReversed.Canvas.Handle, 0, 0, Data.Width, Data.Height,
PageData.Bmp.Canvas.Handle, 0, Data.Height-1, Data.Width, -Data.Height,
cmSrcCopy)
else StretchBlt(
PageData.BmpReversed.Canvas.Handle, 0, 0, Data.Width, Data.Height,
PageData.Bmp.Canvas.Handle, Data.Width-1, 0, -Data.Width, Data.Height,
cmSrcCopy);
PageData.RMovingPg := PageData.Rects.CreateRect(PageData.Width, PageData.Height, 0, 0, PageData.Width, 0);
PageData.RStaticPg := PageData.Rects.CreateRect(PageData.Width, PageData.Height, 0, 0, PageData.Width, 0);
PageData.RArc := PageData.Rects.CreateRect(PageData.Width, PageData.Height, 0, 0, PageData.Width, 0);
PageData.RArcRev := PageData.Rects.CreateRect(PageData.Width, PageData.Height, 0, 0, PageData.Width, 0);
PageData.RVisArc := PageData.Rects.CreateRect(PageData.Width, PageData.Height, 0, 0, 0, 0);
PageData.RVisArcRev := PageData.Rects.CreateRect(PageData.Width, PageData.Height, 0, 0, 0, 0);
PageData.RMovingPgBak := PageData.Rects.CreateRect(PageData.Width, PageData.Height, 0, 0, 0, 0);
PageData.RMovingPgNew := PageData.Rects.CreateRect(PageData.Width, PageData.Height, 0, 0, 0, 0);
end;
procedure TPageTransition.ExecuteFrame(Data: TTETransitionData;
CurrentFrame, Step, LastExecutedFrame: Longint);
procedure CalcArcPixels(IsReversed: Boolean; ArcData: PByteArray;
ArcPixelCount, ArcVisPixelCount, PixelIndex: Integer;
var CalcVisPixels, CalcTotPixels: Integer);
begin
if IsReversed then
Dec(PixelIndex, ArcPixelCount);
if PixelIndex <= 0
then
begin
CalcVisPixels := 0;
CalcTotPixels := 0;
end
else
begin
if PixelIndex >= ArcPixelCount
then
begin
CalcVisPixels := ArcVisPixelCount;
CalcTotPixels := ArcPixelCount;
end
else
begin
CalcVisPixels := 0;
CalcTotPixels := 0;
while CalcTotPixels < PixelIndex do
begin
Inc(CalcTotPixels, ArcData[CalcVisPixels] + 1);
Inc(CalcVisPixels);
end;
end;
end;
end;
var
PageData: TPageData;
Aux,
Aux2,
xAux,
yAux,
xScroll,
yScroll,
ArcVisPixels,
ArcRevVisPixels,
ArcTotPixels,
ArcRevTotPixels: Integer;
Frame: Longint;
RAux1,
RAux2: TRect;
begin
PageData := TPageData(Data.Custom);
xScroll := 0;
yScroll := 0;
if UncoverToUse
then Frame := CurrentFrame
else Frame := Data.Frames - CurrentFrame + 1;
CalcArcPixels(False, PageData.ArcData , PageData.ArcPixelCount,
PageData.ArcVisPixelCount, Frame, ArcVisPixels, ArcTotPixels);
CalcArcPixels(True , PageData.ArcRevData, PageData.ArcPixelCount,
PageData.ArcVisPixelCount, Frame, ArcRevVisPixels, ArcRevTotPixels);
PageData.RArc .Bottom := Frame;
PageData.RArc .Top := PageData.RArc .Bottom - ArcVisPixels;
PageData.RArcRev .Top := PageData.RArc .Top;
PageData.RArcRev .Bottom := PageData.RArcRev.Top + ArcRevVisPixels;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -