
Animation is integral to many parts of GUIs, including both the fancy effects when things change used in window managers, and of course games.   The core of any animation system is a scheme for periodically changing the display while still remaining responsive to the user.   This task demonstrates this.



Task

Create a window containing the string "Hello World! " (the trailing space is significant).

Make the text appear to be rotating right by periodically removing one letter from the end of the string and attaching it to the front.

When the user clicks on the (windowed) text, it should reverse its direction.




 
unit Main;
 
interface
 
uses
  Winapi.Windows, System.SysUtils, System.Classes, Vcl.Controls, Vcl.Forms,
  Vcl.StdCtrls, Vcl.ExtCtrls;
 
type
  TForm1 = class(TForm)
    lblAniText: TLabel;
    tmrAniFrame: TTimer;
    procedure lblAniTextClick(Sender: TObject);
    procedure tmrAniFrameTimer(Sender: TObject);
  end;
 
var
  Form1: TForm1;
  Reverse: boolean = false;
 
implementation
 
{$R *.dfm}
 
procedure TForm1.lblAniTextClick(Sender: TObject);
begin
  Reverse := not Reverse;
end;
 
function Shift(text: string; direction: boolean): string;
begin
  if direction then
    result := text[text.Length] + text.Substring(0, text.Length - 1)
  else
    result := text.Substring(1, text.Length) + text[1];
end;
 
procedure TForm1.tmrAniFrameTimer(Sender: TObject);
begin
  with lblAniText do
    Caption := Shift(Caption, Reverse);
end;
end.