Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Este objeto Faz com que o texto de um TLbel role.
unit LabelLetreiro;
interface
uses
Windows, SysUtils, Classes, Dialogs,stdCtrls, extCtrls;
type
TLetreiroInterval = 1 ..10000;
TLabelLetreiro = class(TObject)
{Por Rafael Tonello (tonello.rafinha@gmail.com)}
Private
OriginalText : AnsiString;
Posicao_att : Integer;
TimerRotaciona : TTimer;
LabelAlvo : TLabel;
RotStart, RotEnd : Integer;
procedure TimerRotacionaOnTimer(Sender: Tobject);
Public
Interval : TLetreiroInterval;
Constructor Create(Alvo: TLabel; RotateStart: Integer = -1; RotateEnd : Integer = -1);
Destructor Destroy;
procedure SetNewText(Text: AnsiString; RotateStart: Integer = -1; RotateEnd : Integer = -1);
end;
implementation
{ TLabelLetreiro }
constructor TLabelLetreiro.Create(Alvo: TLabel; RotateStart: Integer = -1; RotateEnd : Integer = -1);
begin
Self.LabelAlvo := Alvo;
Self.OriginalText := Self.LabelAlvo.Caption;
Self.Posicao_att := 0;
Self.TimerRotaciona := TTimer.Create(nil);
Self.TimerRotaciona.OnTimer := Self.TimerRotacionaOnTimer;
Self.Interval := 150;
Self.TimerRotaciona.Interval := 150;
if (RotateStart > -1) then
Self.RotStart := RotateStart
else
RotateStart := 1;
if ((RotateEnd > -1) and (RotateEnd > RotateStart)) then
Self.RotEnd := RotateEnd
else
Self.RotEnd := Length(OriginalText);
Posicao_Att := RotateStart-1;
//offsets
end;
destructor TLabelLetreiro.Destroy; Self.TimerRotaciona.Enabled := false;
Self.TimerRotaciona.Free;
end;
procedure TLabelLetreiro.SetNewText(Text: AnsiString; RotateStart: Integer = -1; RotateEnd : Integer = -1); Self.OriginalText := Text;
if (RotateStart > -1) then
Self.RotStart := RotateStart
else
RotateStart := Self.RotStart;
if ((RotateEnd > -1) and (RotateEnd > RotateStart)) then
Self.RotEnd := RotateEnd
else
Self.RotEnd := Length(Self.OriginalText);
Posicao_Att := RotateStart-1;
end;
end;
procedure TLabelLetreiro.TimerRotacionaOnTimer(Sender: Tobject); Cont : Integer;
temp : String; Inc(Posicao_att);
if (Posicao_att > Self.RotEnd) then
Posicao_att := RotStart+1;
temp := Copy(Self.OriginalText, 1, RotStart);
for Cont := Posicao_att to Self.RotEnd do
begin
Temp := Temp + Self.OriginalText[Cont];
end;
For Cont := RotStart+1 to Posicao_att-1 do
begin
Temp := Temp + Self.OriginalText[Cont];
end;
Temp := Temp + Copy(Self.OriginalText, RotEnd+1, Length(Self.OriginalText)-RotEnd);
Self.LabelAlvo.Caption := Temp;
Self.TimerRotaciona.Interval := Self.Interval;
end;
end.
Carregando comentários...