2005-02-01 20:14:03 -05:00
|
|
|
! Copyright (C) 2005 Slava Pestov.
|
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
|
|
|
IN: gadgets
|
2005-07-12 20:30:05 -04:00
|
|
|
USING: alien generic io kernel lists math matrices namespaces
|
2005-10-11 23:28:17 -04:00
|
|
|
prettyprint sequences vectors ;
|
2005-02-01 20:14:03 -05:00
|
|
|
|
|
|
|
! The hand is a special gadget that holds mouse position and
|
2005-10-07 20:26:21 -04:00
|
|
|
! mouse button click state.
|
|
|
|
|
|
|
|
! Some comments on the slots:
|
2005-02-10 23:58:28 -05:00
|
|
|
! - hand-gadget is the gadget under the mouse position
|
|
|
|
! - hand-clicked is the most recently clicked gadget
|
|
|
|
! - hand-focus is the gadget holding keyboard focus
|
2005-07-13 18:08:54 -04:00
|
|
|
TUPLE: hand click-loc click-rel clicked buttons gadget focus ;
|
2005-02-01 20:14:03 -05:00
|
|
|
|
2005-10-07 20:26:21 -04:00
|
|
|
C: hand ( -- hand )
|
2005-10-29 23:25:38 -04:00
|
|
|
dup delegate>gadget V{ } clone over set-hand-buttons ;
|
2005-07-13 22:51:43 -04:00
|
|
|
|
2005-11-14 01:54:40 -05:00
|
|
|
: button-gesture ( button gesture -- )
|
|
|
|
swap add hand get hand-clicked handle-gesture drop ;
|
2005-02-01 20:14:03 -05:00
|
|
|
|
2005-07-20 18:04:29 -04:00
|
|
|
: drag-gesture ( hand gadget gesture -- )
|
2005-03-03 20:43:55 -05:00
|
|
|
#! Send a gesture like [ drag 2 ].
|
2005-09-14 00:37:50 -04:00
|
|
|
rot hand-buttons first add swap handle-gesture drop ;
|
2005-02-05 22:51:41 -05:00
|
|
|
|
|
|
|
: fire-motion ( hand -- )
|
2005-02-26 02:11:25 -05:00
|
|
|
#! Fire a motion gesture to the gadget underneath the hand,
|
|
|
|
#! and if a mouse button is down, fire a drag gesture to the
|
|
|
|
#! gadget that was clicked.
|
|
|
|
[ motion ] over hand-gadget handle-gesture drop
|
2005-09-14 00:37:50 -04:00
|
|
|
dup hand-buttons empty?
|
|
|
|
[ dup dup hand-clicked [ drag ] drag-gesture ] unless drop ;
|
2005-07-20 18:04:29 -04:00
|
|
|
|
|
|
|
: each-gesture ( gesture seq -- )
|
|
|
|
[ handle-gesture* drop ] each-with ;
|
|
|
|
|
2005-10-09 21:27:14 -04:00
|
|
|
: hand-gestures ( new old -- )
|
|
|
|
drop-prefix reverse-slice
|
|
|
|
[ mouse-leave ] swap each-gesture
|
|
|
|
hand get fire-motion
|
2005-07-20 18:04:29 -04:00
|
|
|
[ mouse-enter ] swap each-gesture ;
|
2005-02-05 11:52:24 -05:00
|
|
|
|
2005-07-20 18:04:29 -04:00
|
|
|
: focus-gestures ( new old -- )
|
2005-10-09 21:27:14 -04:00
|
|
|
drop-prefix reverse-slice
|
|
|
|
[ lose-focus ] swap each-gesture
|
2005-07-20 18:04:29 -04:00
|
|
|
[ gain-focus ] swap each-gesture ;
|
|
|
|
|
2005-10-09 21:27:14 -04:00
|
|
|
: focused-ancestors ( hand -- seq )
|
|
|
|
hand get hand-focus parents reverse-slice ;
|
|
|
|
|
2005-07-04 18:36:07 -04:00
|
|
|
: request-focus ( gadget -- )
|
2005-10-09 21:27:14 -04:00
|
|
|
focusable-child focused-ancestors >r
|
|
|
|
hand get set-hand-focus focused-ancestors
|
|
|
|
r> focus-gestures ;
|
2005-08-27 00:22:19 -04:00
|
|
|
|
|
|
|
: drag-loc ( gadget -- loc )
|
2005-10-07 20:26:21 -04:00
|
|
|
hand get [ relative ] keep hand-click-rel v- ;
|