! Copyright (C) 2006 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. IN: gadgets USING: arrays errors gadgets gadgets-frames gadgets-grids gadgets-labels gadgets-panes gadgets-theme gadgets-viewports generic hashtables io kernel math models namespaces prettyprint queues sequences test threads ; ! Assoc mapping aliens to gadgets SYMBOL: windows : window ( handle -- world ) windows get-global assoc ; : window-focus ( handle -- gadget ) window world-focus ; : 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 ] assert-depth ; : ( -- gadget ) ""