2007-09-20 18:09:08 -04:00
|
|
|
! Copyright (C) 2005, 2007 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2008-08-31 02:42:30 -04:00
|
|
|
USING: accessors arrays ui.commands ui.gadgets ui.gadgets.buttons
|
2007-09-20 18:09:08 -04:00
|
|
|
ui.gadgets.worlds ui.gestures generic hashtables kernel math
|
|
|
|
models namespaces opengl sequences math.vectors
|
2008-07-11 19:34:43 -04:00
|
|
|
ui.gadgets.theme ui.gadgets.packs ui.gadgets.borders colors
|
|
|
|
math.geometry.rect ;
|
2007-09-20 18:09:08 -04:00
|
|
|
IN: ui.gadgets.menus
|
|
|
|
|
|
|
|
: menu-loc ( world menu -- loc )
|
2008-11-28 01:02:02 -05:00
|
|
|
[ rect-dim ] [ pref-dim ] bi* [v-] hand-loc get-global vmin ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2008-07-10 21:32:17 -04:00
|
|
|
TUPLE: menu-glass < gadget ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
: <menu-glass> ( menu world -- glass )
|
2008-07-10 21:32:17 -04:00
|
|
|
menu-glass new-gadget
|
2008-11-28 01:02:02 -05:00
|
|
|
[ over menu-loc >>loc ] dip
|
2008-09-27 15:36:04 -04:00
|
|
|
swap add-gadget ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
M: menu-glass layout* gadget-child prefer ;
|
|
|
|
|
|
|
|
: hide-glass ( world -- )
|
2008-09-27 15:36:04 -04:00
|
|
|
[ [ unparent ] when* f ] change-glass drop ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
: show-glass ( gadget world -- )
|
2008-09-27 15:36:04 -04:00
|
|
|
dup hide-glass
|
|
|
|
swap [ hand-clicked set-global ] [ >>glass ] bi
|
|
|
|
dup glass>> add-gadget drop ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
: show-menu ( gadget owner -- )
|
|
|
|
find-world [ <menu-glass> ] keep show-glass ;
|
|
|
|
|
|
|
|
\ menu-glass H{
|
|
|
|
{ T{ button-down } [ find-world [ hide-glass ] when* ] }
|
|
|
|
{ T{ drag } [ update-clicked drop ] }
|
|
|
|
} set-gestures
|
|
|
|
|
|
|
|
: <menu-item> ( hook target command -- button )
|
|
|
|
dup command-name -rot command-button-quot
|
|
|
|
swapd
|
|
|
|
[ hand-clicked get find-world hide-glass ]
|
|
|
|
3append <roll-button> ;
|
|
|
|
|
2008-06-18 23:30:54 -04:00
|
|
|
: menu-theme ( gadget -- gadget )
|
|
|
|
light-gray solid-interior
|
2007-09-20 18:09:08 -04:00
|
|
|
faint-boundary ;
|
|
|
|
|
|
|
|
: <commands-menu> ( hook target commands -- gadget )
|
2008-11-26 00:04:34 -05:00
|
|
|
[ <filled-pile> ] 3dip
|
2008-09-27 15:36:04 -04:00
|
|
|
[ <menu-item> add-gadget ] with with each
|
|
|
|
5 <border> menu-theme ;
|