
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.




 
try destroydialog animGUI catch ()
 
global userDirection = "right"
 
fn reverseStr str: direction: =
(
	local lastChar = str[str.count]
	local firstChar = str[1]
	local newStr = ""
	local dir 
 
	if direction == unsupplied then dir = "left" else dir = direction
 
	case dir of
	(
		"right": (newstr = lastChar + (substring str 1 (str.count-1)))
		"left": (newstr = (substring str 2 (str.count))+firstChar)
	)
 
	return newstr
)
 
rollout animGUI "Hello World" width:200
(
	button switchToLeft "<--" pos:[40,0] height:15
	label HelloWorldLabel "Hello World! " pos:[80,0]
	button switchToRight "-->" pos:[150,0] height:15
 
	timer activeTimer interval:70 active:true
 
	on activeTimer tick do
	(
		HelloWorldLabel.text = reverseStr str:(HelloWorldLabel.text) direction:userDirection
	)
 
	on switchToLeft pressed do
	(
		userDirection = "left"
	)
 
	on switchToRight pressed do
	(
		userDirection = "right"
	)
)
 
createdialog animGUI
 