2008-11-30 16:03:05 -05:00
|
|
|
! Copyright (C) 2005, 2008 Slava Pestov.
|
2007-09-20 18:09:08 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2008-12-19 00:56:41 -05:00
|
|
|
USING: locals accessors arrays ui.commands ui.operations ui.gadgets
|
2008-11-30 16:03:05 -05:00
|
|
|
ui.gadgets.buttons ui.gadgets.worlds ui.gestures generic
|
|
|
|
hashtables kernel math models namespaces opengl sequences
|
|
|
|
math.vectors 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
|
|
|
|
2008-11-30 16:03:05 -05:00
|
|
|
: <menu-glass> ( world menu -- glass )
|
|
|
|
tuck menu-loc >>loc
|
2008-07-10 21:32:17 -04:00
|
|
|
menu-glass new-gadget
|
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
|
|
|
|
2008-11-30 16:03:05 -05:00
|
|
|
: show-glass ( world gadget -- )
|
|
|
|
[ [ hide-glass ] [ hand-clicked set-global ] bi* ]
|
|
|
|
[ add-gadget drop ]
|
|
|
|
[ >>glass drop ]
|
|
|
|
2tri ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2008-11-30 16:03:05 -05:00
|
|
|
: show-menu ( owner menu -- )
|
|
|
|
[ find-world dup ] dip <menu-glass> show-glass ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
\ menu-glass H{
|
|
|
|
{ T{ button-down } [ find-world [ hide-glass ] when* ] }
|
|
|
|
{ T{ drag } [ update-clicked drop ] }
|
|
|
|
} set-gestures
|
|
|
|
|
2008-11-30 16:03:05 -05:00
|
|
|
:: <menu-item> ( target hook command -- button )
|
|
|
|
command command-name [
|
|
|
|
hook call
|
|
|
|
target command command-button-quot call
|
|
|
|
hand-clicked get find-world hide-glass
|
|
|
|
] <roll-button> ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
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 ;
|
|
|
|
|
2008-11-30 16:03:05 -05:00
|
|
|
: <commands-menu> ( target hook commands -- menu )
|
2008-11-26 00:04:34 -05:00
|
|
|
[ <filled-pile> ] 3dip
|
2008-11-30 16:03:05 -05:00
|
|
|
[ <menu-item> add-gadget ] with with each
|
2008-09-27 15:36:04 -04:00
|
|
|
5 <border> menu-theme ;
|
2008-11-30 16:03:05 -05:00
|
|
|
|
|
|
|
: show-commands-menu ( target commands -- )
|
|
|
|
[ dup [ ] ] dip <commands-menu> show-menu ;
|
2008-12-19 00:56:41 -05:00
|
|
|
|
|
|
|
: <operations-menu> ( target hook -- menu )
|
|
|
|
over object-operations <commands-menu> ;
|
|
|
|
|
|
|
|
: show-operations-menu ( gadget target -- )
|
|
|
|
[ ] <operations-menu> show-menu ;
|