! Copyright (C) 2006 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. IN: gadgets USING: arrays gadgets gadgets-frames gadgets-labels gadgets-theme gadgets-viewports hashtables kernel math models namespaces queues sequences threads ; ! Assoc mapping aliens to gadgets SYMBOL: windows : window ( handle -- world ) windows get-global assoc ; : register-window ( world handle -- ) swap 2array windows get-global push ; : unregister-window ( handle -- ) windows get-global [ first = not ] subset-with windows set-global ; : raised-window ( world -- ) windows get-global [ second eq? ] find-with drop windows get-global [ length 1- ] keep exchange ; : update-hand ( gadget -- ) find-world [ dup hand-gadget get-global find-world eq? [ hand-loc get-global swap move-hand ] [ drop ] if ] when* ; : post-layout ( gadget -- ) find-world [ dup world-handle set ] when* ; : layout-queued ( -- ) invalid dup queue-empty? [ drop ] [ deque dup layout post-layout layout-queued ] if ; : init-ui ( -- ) \ invalid set-global V{ } clone windows set-global ; : ui-step ( -- ) do-timers [ layout-queued ] make-hash hash-values [ dup update-hand dup world-handle [ dup draw-world ] when drop ] each 10 sleep ; : ( -- gadget ) ""