?? aactrls.pas
字號:
end;
end;
//設(shè)置文本內(nèi)容
procedure TAAScrollText.SetText(const Value: TScrollTextParam);
begin
FText.Assign(Value);
end;
//重頭開始滾動(dòng)
procedure TAAScrollText.ReStart;
begin
FRepeatedCount := -1;
CurrPos := 0;
end;
//設(shè)置當(dāng)前位置
procedure TAAScrollText.SetCurrPos(const Value: Integer);
begin
if FCurrPos <> Value then
begin
FCurrPos := Value mod TextBmp.Height;
if FCurrPos < 0 then
Inc(FCurrPos, TextBmp.Height);
Paint;
end;
end;
//大小變化消息
function TAAScrollText.CanResize(var NewWidth,
NewHeight: Integer): Boolean;
begin
if NewWidth < 20 then NewWidth := 20;
if NewHeight < 20 then NewHeight := 20;
Result := inherited CanResize(NewWidth, NewHeight);
end;
//循環(huán)延時(shí)
procedure TAAScrollText.OnDelayTimer(Sender: TObject);
begin
DelayTimer.Enabled := False;
CurrPos := CurrPos + FScrollStep;
if Active then
ScrollTimer.Enabled := True;
end;
//創(chuàng)建默認(rèn)字體集
procedure TAAScrollText.CreateDefFonts;
var
FLabel: TFontLabel;
begin
inherited;
FLabel := Fonts.AddItem('Title4', '隸書', 22, clBlack, [fsBold], True, 2, 2);
if Assigned(FLabel) then
begin
FLabel.Effect.Gradual.Enabled := True;
FLabel.Effect.Gradual.Style := gsLeftToRight;
FLabel.Effect.Gradual.StartColor := $00FF2200;
FLabel.Effect.Gradual.EndColor := $002210FF;
FLabel.Effect.Outline := True;
FLabel.Effect.Blur := 50;
end;
FLabel := Fonts.AddItem('Text3', '隸書', 11, clBlue, [], True, 1, 1);
if Assigned(FLabel) then
begin
FLabel.Effect.Gradual.Enabled := True;
FLabel.Effect.Gradual.Style := gsTopToBottom;
FLabel.Effect.Gradual.StartColor := $00CC3311;
FLabel.Effect.Gradual.EndColor := $00FF22AA;
end;
end;
//默認(rèn)文本創(chuàng)建默認(rèn)標(biāo)簽
function TAAScrollText.UseDefaultLabels: Boolean;
begin
Result := not FText.IsLinesStored;
end;
//控件屬性已裝載
procedure TAAScrollText.LoadedEx;
begin
inherited;
Reset;
end;
{ TScrollTextParam }
//--------------------------------------------------------//
//平滑滾動(dòng)文本參數(shù) //
//--------------------------------------------------------//
//初始化
constructor TScrollTextParam.Create(AOwner: TAAGraphicControl;
ChangedProc: TNotifyEvent);
begin
inherited;
Randomize;
if Random(csCopyRandom) = 1 then //缺省文本
TStringList(Lines).Text := csDancewithmoon
else
TStringList(Lines).Text := csAAScrollTextCopyRight;
FFade := True;
FFadeHeight := 10;
FHeadSpace := 0;
FTailSpace := 60;
Alignment := taCenter;
BackGroundMode := bmTiled;
end;
//釋放
destructor TScrollTextParam.Destroy;
begin
inherited;
end;
//設(shè)置淡入淡出
procedure TScrollTextParam.SetFade(const Value: Boolean);
begin
if FFade <> Value then
begin
FFade := Value;
Changed;
end;
end;
//設(shè)置淡入淡出高度
procedure TScrollTextParam.SetFadeHeight(const Value: Integer);
begin
if FFadeHeight <> Value then
begin
FFadeHeight := Value;
Changed;
end;
end;
//設(shè)置頭部空白
procedure TScrollTextParam.SetHeadSpace(const Value: Integer);
begin
if FHeadSpace <> Value then
begin
FHeadSpace := Value;
if FHeadSpace < 0 then
FHeadSpace := 0;
if FHeadSpace > 150 then
FHeadSpace := 150;
Changed;
end;
end;
//設(shè)置尾部空白
procedure TScrollTextParam.SetTailSpace(const Value: Integer);
begin
if FTailSpace <> Value then
begin
FTailSpace := Value;
if FTailSpace < 0 then
FTailSpace := 0;
if FTailSpace > 150 then
FTailSpace := 150;
Changed;
end;
end;
//文本內(nèi)容是否存儲(chǔ)
function TScrollTextParam.IsLinesStored: Boolean;
begin
Result := (Lines.Text <> csAAScrollTextCopyRight) and (Lines.Text <>
csDanceWithMoon);
end;
{ TAAFadeText }
//--------------------------------------------------------//
//平滑特效漸隱文本控件 //
//--------------------------------------------------------//
//創(chuàng)建
constructor TAAFadeText.Create(AOwner: TComponent);
begin
inherited;
ControlStyle := ControlStyle + [csReplicatable];
TextBmp := TBitmap.Create;
TextBmp.PixelFormat := pf24bit;
InBmp := TBitmap.Create;
InBmp.PixelFormat := pf24bit;
OutBmp := TBitmap.Create;
OutBmp.PixelFormat := pf24bit;
FadeTimer := TTimer.Create(Self);
FadeTimer.Interval := 25;
FadeTimer.Enabled := False;
FadeTimer.OnTimer := OnFadeTimer;
DelayTimer := TTimer.Create(Self);
DelayTimer.Enabled := False;
DelayTimer.OnTimer := OnDelayTimer;
FText := TFadeTextParam.Create(Self, OnLabelChanged);
FLineIndex := -1;
FFadeProgress := 0;
FRepeatCount := 0;
FRepeatedCount := 0;
FActive := True;
Color := clWhite;
LastText := '';
CurrText := '';
NewProg := 0;
SetBounds(0, 0, 240, 34);
end;
//創(chuàng)建默認(rèn)字體標(biāo)簽
procedure TAAFadeText.CreateDefFonts;
var
FLabel: TFontLabel;
begin
inherited;
FLabel := Fonts.AddItem('Title4', '隸書', 22, clBlack, [], True, 2, 2);
if Assigned(FLabel) then
begin
FLabel.Effect.Gradual.Enabled := True;
FLabel.Effect.Gradual.Style := gsLeftToRight;
FLabel.Effect.Gradual.StartColor := $00FF2200;
FLabel.Effect.Gradual.EndColor := $002210FF;
FLabel.Effect.Outline := True;
FLabel.Effect.Blur := 50;
end;
FLabel := Fonts.AddItem('Text3', '隸書', 11, clBlue, [], True, 1, 1);
if Assigned(FLabel) then
begin
FLabel.Effect.Gradual.Enabled := True;
FLabel.Effect.Gradual.Style := gsTopToBottom;
FLabel.Effect.Gradual.StartColor := $00CC8811;
FLabel.Effect.Gradual.EndColor := $00FF22AA;
end;
end;
//釋放
destructor TAAFadeText.Destroy;
begin
FText.Free;
DelayTimer.Free;
FadeTimer.Free;
OutBmp.Free;
InBmp.Free;
TextBmp.Free;
inherited;
end;
//繪制漸隱圖
procedure TAAFadeText.DrawFadeBmp(AText: string; Bmp: TBitmap);
var
OffPoint: TPoint;
th, tw: Integer;
begin
AAFont.Canvas := Bmp.Canvas;
if Text.LabelEffect = leOnlyALine then
begin
Bmp.Canvas.Font.Assign(Font);
AAFont.Effect.Assign(Text.FontEffect);
CurrAlign := Text.Alignment;
end;
Fonts.Check(AText, Bmp.Canvas.Font, AAFont.Effect); //檢查字體標(biāo)簽
Labels.Check(AText, CurrAlign); //檢查用戶標(biāo)簽
th := AAFont.TextHeight(AText); //文本高度
tw := AAFont.TextWidth(AText); //文本寬度
case CurrAlign of //水平對齊方式
taLeftJustify: OffPoint.x := 0;
taRightJustify: OffPoint.x := ClientWidth - tw;
taCenter: OffPoint.x := (ClientWidth - tw) div 2;
end;
case Text.Layout of //垂直對齊方式
tlTop: OffPoint.y := 0;
tlCenter: OffPoint.y := (ClientHeight - th) div 2;
tlBottom: OffPoint.y := ClientHeight - th;
end;
Bmp.Height := ClientHeight;
Bmp.Width := ClientWidth;
Bmp.Canvas.Brush.Color := Color;
Bmp.Canvas.Brush.Style := bsSolid;
if Text.Transparent then //透明
begin
CopyParentImage(Bmp.Canvas); //復(fù)制父控件畫布
end else if not Text.IsBackEmpty then
begin //繪制背景圖
DrawBackGround(Bmp.Canvas, Rect(0, 0, Bmp.Width, Bmp.Height),
Text.BackGround.Graphic, Text.BackGroundMode);
end else
begin //填充背景色
Bmp.Canvas.FillRect(ClientRect);
end;
Bmp.Canvas.Brush.Style := bsClear;
AAFont.TextOut(OffPoint.x, OffPoint.y, AText); //平滑字體輸出
end;
//漸隱到指定行
procedure TAAFadeText.FadeTo(Line: Integer);
begin
if Text.Lines.Count <= 0 then
Exit;
if Line < 0 then
Line := 0;
if Line > Text.Lines.Count - 1 then
begin
Line := 0;
Inc(FRepeatedCount);
if (FRepeatCount > 0) and (FRepeatedCount >= FRepeatCount) then
begin
Active := False;
FRepeatedCount := 0;
FLineIndex := -1;
FadeToStr('');
if Assigned(OnComplete) then
OnComplete(Self);
Exit;
end;
end;
FadeToStr(Text.Lines[Line]);
FLineIndex := Line;
end;
//漸隱到下一行
procedure TAAFadeText.FadeToNext;
begin
FadeTo(LineIndex + 1);
end;
//漸隱到指定文本
procedure TAAFadeText.FadeToStr(AText: string);
begin
OutBmp.Assign(TextBmp);
DrawFadeBmp(AText, InBmp);
LastText := CurrText;
CurrText := AText;
FFadeProgress := 0;
FadeTimer.Enabled := False;
FadeTimer.Enabled := True;
if DelayTimer.Enabled then
begin
DelayTimer.Enabled := False;
DelayTimer.Enabled := True;
end;
end;
//屬性已裝載
procedure TAAFadeText.LoadedEx;
begin
inherited;
CurrAlign := Text.Alignment;
Reset;
FRepeatedCount := 0;
DelayTimer.Enabled := FActive;
if FActive then
OnDelayTimer(Self);
end;
//漸隱切換文本定時(shí)事件
procedure TAAFadeText.OnDelayTimer(Sender: TObject);
begin
FadeToNext;
end;
//漸隱過程定時(shí)事件
procedure TAAFadeText.OnFadeTimer(Sender: TObject);
begin
if Abs(NewProg - FadeProgress) > 1 then
NewProg := FadeProgress;
NewProg := NewProg + csMaxProgress * FadeTimer.Interval div Text.FadeDelay;
if NewProg > csMaxProgress then
begin
NewProg := csMaxProgress;
FadeTimer.Enabled := False;
end;
FadeProgress := Round(NewProg);
end;
//繪制控件畫布
procedure TAAFadeText.PaintCanvas;
begin
inherited;
if Text.Transparent then
begin //透明且完整重繪
if FadeProgress = 0 then
DrawFadeBmp(CurrText, TextBmp)
else begin
DrawFadeBmp(LastText, OutBmp);
DrawFadeBmp(CurrText, InBmp);
end;
end;
if FadeProgress <> 0 then //漸隱中
Blend(TextBmp, OutBmp, InBmp, FFadeProgress);
Bitblt(Canvas.Handle, 0, 0, Width, Height, TextBmp.Canvas.Handle, 0, 0,
SRCCOPY);
if Assigned(OnPainted) then
OnPainted(Self);
end;
//更新顯示
procedure TAAFadeText.Reset;
begin
if FadeProgress = 0 then
DrawFadeBmp(CurrText, TextBmp)
else begin
DrawFadeBmp(LastText, OutBmp);
DrawFadeBmp(CurrText, InBmp);
Blend(TextBmp, OutBmp, InBmp, FFadeProgress);
end;
inherited;
end;
//設(shè)置活躍
procedure TAAFadeText.SetActive(const Value: Boolean);
begin
if FActive <> Value then
begin
FActive := Value;
DelayTimer.Enabled := FActive;
if FActive then
begin
FRepeatedCount := 0;
OnDelayTimer(Self);
end;
end;
end;
//設(shè)置漸隱進(jìn)程
procedure TAAFadeText.SetFadeProgress(const Value: TProgress);
be
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -