Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Raficcha

[Resolvido] Label rolante

Recommended Posts

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;
begin
	Self.TimerRotaciona.Enabled := false;
	Self.TimerRotaciona.Free;
end;

procedure TLabelLetreiro.SetNewText(Text: AnsiString; RotateStart: Integer = -1; RotateEnd : Integer = -1);
begin
	if (Text <> Self.OriginalText) then
	begin
		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);
var
	Cont : Integer;
	temp : String;
begin
	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.

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.