
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.




#INCLUDE <Include\Windows.inc>
 
FBSLSETTEXT(ME, "Hello world! ")
RESIZE(ME, 0, 0, 220, 0)
CENTER(ME)
SHOW(ME)
SetTimer(ME, 1000, 100, NULL)
 
BEGIN EVENTS
	STATIC bForward AS BOOLEAN = TRUE
	IF CBMSG = WM_TIMER THEN
		Marquee(bForward)
		RETURN 0
	ELSEIF CBMSG = WM_NCLBUTTONDOWN THEN
		IF CBWPARAM = HTCAPTION THEN bForward = NOT bForward
	ELSEIF CBMSG = WM_CLOSE THEN
		KillTimer(ME, 1000)
	END IF
END EVENTS
 
SUB Marquee(BYVAL forward AS BOOLEAN)
	STATIC caption AS STRING = FBSLGETTEXT(ME)
	STATIC length AS INTEGER = STRLEN(caption)
	IF forward THEN
		caption = RIGHT(caption, 1) & LEFT(caption, length - 1)
	ELSE
		caption = MID(caption, 2) & LEFT(caption, 1)
	END IF
	FBSLSETTEXT(ME, caption)
END SUB