1 ! Copyright (c) 2012 Anonymous
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors timers calendar fonts kernel models sequences ui
4 ui.gadgets ui.gadgets.labels ui.gestures ;
5 FROM: models => change-model ;
6 IN: rosetta-code.animation
8 ! http://rosettacode.org/wiki/Animation
10 ! Animation is the foundation of a great many parts of graphical
11 ! user interfaces, including both the fancy effects when things
12 ! change used in window managers, and of course games. The core of
13 ! any animation system is a scheme for periodically changing the
14 ! display while still remaining responsive to the user. This task
17 ! Create a window containing the string "Hello World! " (the
18 ! trailing space is significant). Make the text appear to be
19 ! rotating right by periodically removing one letter from the end
20 ! of the string and attaching it to the front. When the user
21 ! clicks on the text, it should reverse its direction.
23 CONSTANT: sentence "Hello World! "
25 TUPLE: animated-label < label-control reversed alarm ;
27 : <animated-label> ( model -- <animated-model> )
28 sentence animated-label new-label swap >>model
29 monospace-font >>font ;
31 : update-string ( str reverse -- str )
32 [ unclip-last prefix ] [ unclip suffix ] if ;
34 : update-model ( model reversed? -- )
35 [ update-string ] curry change-model ;
39 { T{ button-down } [ [ not ] change-reversed drop ] }
42 M: animated-label graft*
43 [ [ [ model>> ] [ reversed>> ] bi update-model ] curry 400 milliseconds every ] keep
46 M: animated-label ungraft*
49 : animated-main ( -- )
50 [ sentence <model> <animated-label> "Rosetta" open-window ] with-ui ;