1 ! Copyright (C) 2005, 2007 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: arrays ui.commands ui.gadgets ui.gadgets.buttons
4 ui.gadgets.worlds ui.gestures generic hashtables kernel math
5 models namespaces opengl sequences math.vectors
6 ui.gadgets.theme ui.gadgets.packs ui.gadgets.borders colors ;
9 : menu-loc ( world menu -- loc )
10 >r rect-dim r> pref-dim [v-] hand-loc get-global vmin ;
14 : <menu-glass> ( menu world -- glass )
15 menu-glass construct-gadget
16 >r over menu-loc over set-rect-loc r>
19 M: menu-glass layout* gadget-child prefer ;
21 : hide-glass ( world -- )
22 dup world-glass [ unparent ] when*
23 f swap set-world-glass ;
25 : show-glass ( gadget world -- )
26 over hand-clicked set-global
31 : show-menu ( gadget owner -- )
32 find-world [ <menu-glass> ] keep show-glass ;
35 { T{ button-down } [ find-world [ hide-glass ] when* ] }
36 { T{ drag } [ update-clicked drop ] }
39 : <menu-item> ( hook target command -- button )
40 dup command-name -rot command-button-quot
42 [ hand-clicked get find-world hide-glass ]
43 3append <roll-button> ;
45 : menu-theme ( gadget -- )
46 dup light-gray solid-interior
49 : <commands-menu> ( hook target commands -- gadget )
51 [ >r 2dup r> <menu-item> gadget, ] each 2drop
52 ] make-filled-pile 5 <border> dup menu-theme ;