
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.




-- demo\rosetta\Animation.exw
with javascript_semantics
include pGUI.e

string hw = "Hello World!     "
bool direction = true
Ihandle label

function button_cb(Ihandle /*ih*/, integer /*button*/, pressed, /*x*/, /*y*/, atom /*pStatus*/)
    if pressed then
        direction = not direction
    end if
    return IUP_CONTINUE
end function

function timer_cb(Ihandle /*ih*/)
    hw = iff(direction ? hw[$] & hw[1..-2]
                       : hw[2..$] & hw[1])
    IupSetAttribute(label,"TITLE",hw)
    return IUP_IGNORE
end function

procedure main()
    IupOpen()
    label = IupLabel(hw,`FONT="Verdana, 18"`)
    IupSetCallback(label, "BUTTON_CB", Icallback("button_cb"))
    Ihandle dlg = IupDialog(label,"TITLE=Animation, DIALOGFRAME=YES, CHILDOFFSET=70x40, SIZE=200x80")
    IupShow(dlg)
    Ihandle hTimer = IupTimer(Icallback("timer_cb"), 160)
    if platform()!=JS then
        IupMainLoop()
        IupClose()
    end if
end procedure

main()
