     trails-gadget new
         300 point-list >>points
         t >>clipped?
-    dup start-trails-thread ;
+        dup '[ _ dup iterate-system relayout-1 ]
+        f 10 milliseconds <timer> >>timer ;
 
 MAIN-WINDOW: trails-window
     { { title "Trails" } }

USING: accessors arrays calendar circular colors
colors.constants fry kernel locals math math.order math.vectors
namespaces opengl processing.shapes sequences threads ui
ui.gadgets ui.gestures ui.render ;

IN: trails


: dot ( pos percent -- ) percent->radius draw-circle ;

TUPLE: trails-gadget < gadget paused points timer ;

M: trails-gadget graft*
    [ timer>> start-timer yield ] [ call-next-method ] bi ;

M: trails-gadget ungraft*
    [ timer>> stop-timer ] [ t >>paused call-next-method ] bi ;

:: iterate-system ( GADGET -- )
    ! Add a valid point if the mouse is in the gadget
    ! Otherwise, add an "invisible" point
    hand-gadget get GADGET = [ mouse ] [ { -10 -10 } ] if
    GADGET points>> circular-push ;

M: trails-gadget pref-dim* drop { 500 500 } ;

