factor/core/ui/gadgets/presentations.factor

78 lines
2.4 KiB
Factor
Raw Normal View History

2006-03-24 03:28:46 -05:00
! Copyright (C) 2005, 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
IN: gadgets-presentations
2006-08-02 15:17:13 -04:00
USING: arrays definitions gadgets gadgets-borders
gadgets-buttons gadgets-labels gadgets-theme
2006-10-07 02:17:32 -04:00
generic hashtables tools io kernel prettyprint sequences strings
styles words help math models namespaces ;
2006-11-19 21:13:37 -05:00
TUPLE: presentation object hook ;
2006-10-07 02:17:32 -04:00
2006-11-19 21:13:37 -05:00
: invoke-presentation ( presentation command -- )
over dup presentation-hook call
>r presentation-object r> invoke-command ;
: invoke-primary ( presentation -- )
dup presentation-object primary-operation
invoke-presentation ;
: invoke-secondary ( presentation -- )
dup presentation-object secondary-operation
invoke-presentation ;
2006-08-25 20:52:13 -04:00
2006-08-25 21:29:23 -04:00
: show-mouse-help ( presentation -- )
2006-12-12 15:37:51 -05:00
dup presentation-object swap find-world
[ world-status set-model ] [ drop ] if* ;
2006-08-25 21:29:23 -04:00
: hide-mouse-help ( presentation -- )
2006-11-26 21:24:07 -05:00
find-world [ world-status f swap set-model ] when* ;
2006-08-25 21:29:23 -04:00
M: presentation ungraft* ( presentation -- )
dup hide-mouse-help delegate ungraft* ;
C: presentation ( label object -- button )
2006-11-19 21:13:37 -05:00
[ drop ] over set-presentation-hook
2006-10-10 01:07:11 -04:00
[ set-presentation-object ] keep
2006-11-19 21:13:37 -05:00
swap [ invoke-primary ] <roll-button>
2006-10-10 01:07:11 -04:00
over set-gadget-delegate ;
: (command-button) ( target command -- label quot )
2006-10-10 01:07:11 -04:00
dup command-name -rot
[ invoke-command drop ] curry curry ;
: <command-button> ( target command -- button )
(command-button) <bevel-button> ;
2006-10-10 01:07:11 -04:00
2006-11-30 02:55:55 -05:00
: <toolbar> ( target classes -- toolbar )
[ commands "toolbar" swap hash ] map concat
[ <command-button> ] map-with
make-shelf ;
2006-12-05 01:23:57 -05:00
: <menu-item> ( hook target command -- button )
rot >r
(command-button) [ hand-clicked get find-world hide-glass ]
r> 3append <roll-button> ;
2006-11-18 03:51:34 -05:00
2006-12-05 01:23:57 -05:00
: <commands-menu> ( hook target commands -- gadget )
[ >r 2dup r> <menu-item> ] map 2nip make-filled-pile
<default-border>
dup menu-theme ;
2006-10-10 01:07:11 -04:00
2006-10-23 23:54:08 -04:00
: operations-menu ( presentation -- )
2006-12-05 01:23:57 -05:00
dup
dup presentation-hook curry
over presentation-object
dup object-operations <commands-menu>
2006-10-10 01:07:11 -04:00
swap show-menu ;
2006-08-25 20:52:13 -04:00
presentation H{
2006-10-10 01:07:11 -04:00
{ T{ button-down f f 3 } [ operations-menu ] }
2006-10-07 02:25:29 -04:00
{ T{ mouse-leave } [ dup hide-mouse-help button-update ] }
{ T{ motion } [ dup show-mouse-help button-update ] }
2006-08-24 22:44:42 -04:00
} set-gestures
2006-08-25 21:29:23 -04:00
! Presentation help bar
: <presentation-help> ( model -- gadget )
2006-12-12 15:37:51 -05:00
[ [ summary ] [ "" ] if* ] <filter> <label-control>
dup reverse-video-theme ;