factor/library/ui/buttons.factor

51 lines
1.6 KiB
Factor
Raw Normal View History

! Copyright (C) 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: gadgets
2005-03-02 21:26:11 -05:00
USING: generic kernel lists math namespaces prettyprint sdl
2005-06-27 03:47:22 -04:00
sequences io sequences styles ;
2005-07-16 22:16:18 -04:00
: button-down? ( n -- ? ) hand hand-buttons member? ;
2005-02-19 23:25:21 -05:00
2005-03-03 20:43:55 -05:00
: mouse-over? ( gadget -- ? ) hand hand-gadget child? ;
: button-pressed? ( button -- ? )
2005-02-19 22:55:45 -05:00
#! Return true if the mouse was clicked on the button, and
#! is currently over the button.
dup mouse-over? [
1 button-down?
[ hand hand-clicked child? ] [ drop f ] ifte
] [
drop f
] ifte ;
: button-update ( button -- )
dup dup mouse-over? rollover set-paint-prop
2005-03-06 19:46:29 -05:00
dup dup button-pressed? reverse-video set-paint-prop
relayout ;
: button-clicked ( button -- )
#! If the mouse is released while still inside the button,
#! fire an action gesture.
dup mouse-over?
[ [ action ] swap handle-gesture drop ] [ drop ] ifte ;
2005-05-03 19:00:52 -04:00
: button-action ( action -- quot )
[ [ swap handle-gesture drop ] cons ] [ [ drop ] ] ifte* ;
: button-gestures ( button quot -- )
2005-03-10 22:52:55 -05:00
over f reverse-video set-paint-prop
over << solid f >> interior set-paint-prop
dupd [ action ] set-action
2005-03-01 18:55:25 -05:00
dup [ dup button-update button-clicked ] [ button-up 1 ] set-action
dup [ button-update ] [ button-down 1 ] set-action
dup [ button-update ] [ mouse-leave ] set-action
2005-03-06 19:46:29 -05:00
dup [ button-update ] [ mouse-enter ] set-action
[ drop ] [ drag 1 ] set-action ;
2005-07-17 02:49:07 -04:00
: <button> ( label quot -- button )
2005-07-18 18:14:13 -04:00
>r
<label> bevel-border
dup { 216 216 216 } background set-paint-prop
2005-07-18 18:14:13 -04:00
dup
r> button-gestures ;