2005-01-31 22:32:06 -05:00
|
|
|
! Copyright (C) 2005 Slava Pestov.
|
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
|
|
|
IN: gadgets
|
2005-02-05 11:52:24 -05:00
|
|
|
USING: alien generic hashtables kernel lists math sdl-event ;
|
|
|
|
|
|
|
|
: action ( gadget gesture -- quot )
|
|
|
|
swap gadget-gestures hash ;
|
|
|
|
|
|
|
|
: set-action ( gadget quot gesture -- )
|
|
|
|
rot gadget-gestures set-hash ;
|
2005-02-01 21:47:10 -05:00
|
|
|
|
|
|
|
: handle-gesture* ( gesture gadget -- ? )
|
|
|
|
tuck gadget-gestures hash* dup [
|
|
|
|
cdr call f
|
|
|
|
] [
|
|
|
|
2drop t
|
|
|
|
] ifte ;
|
2005-01-31 22:32:06 -05:00
|
|
|
|
|
|
|
: handle-gesture ( gesture gadget -- )
|
|
|
|
#! If a gadget's handle-gesture* generic returns t, the
|
|
|
|
#! event was not consumed and is passed on to the gadget's
|
|
|
|
#! parent.
|
2005-02-05 11:52:24 -05:00
|
|
|
[ dupd handle-gesture* ] each-parent drop ;
|
2005-02-01 20:14:03 -05:00
|
|
|
|
2005-02-01 21:47:10 -05:00
|
|
|
! Mouse gestures are lists where the first element is one of:
|
|
|
|
SYMBOL: motion
|
|
|
|
SYMBOL: button-up
|
|
|
|
SYMBOL: button-down
|
2005-02-05 11:52:24 -05:00
|
|
|
|
|
|
|
: mouse-enter ( point gadget -- )
|
|
|
|
#! If the old point is inside the new gadget, do not fire an
|
|
|
|
#! enter gesture, since the mouse did not enter. Otherwise,
|
|
|
|
#! fire an enter gesture and go on to the parent.
|
|
|
|
[
|
|
|
|
[ shape-pos + ] keep
|
|
|
|
2dup inside? [
|
|
|
|
drop f
|
|
|
|
] [
|
|
|
|
[ mouse-enter ] swap handle-gesture* drop t
|
|
|
|
] ifte
|
|
|
|
] each-parent drop ;
|
|
|
|
|
|
|
|
: mouse-leave ( point gadget -- )
|
|
|
|
#! If the new point is inside the old gadget, do not fire a
|
|
|
|
#! leave gesture, since the mouse did not leave. Otherwise,
|
|
|
|
#! fire a leave gesture and go on to the parent.
|
|
|
|
[
|
|
|
|
[ shape-pos + ] keep
|
|
|
|
2dup inside? [
|
|
|
|
drop f
|
|
|
|
] [
|
|
|
|
[ mouse-leave ] swap handle-gesture* drop t
|
|
|
|
] ifte
|
|
|
|
] each-parent drop ;
|