Start refactoring hand, add new get-global word

release
slava 2006-03-19 05:30:57 +00:00
parent 100a036342
commit 500d7b5331
12 changed files with 48 additions and 36 deletions

View File

@ -15,6 +15,7 @@ sequences strings vectors words ;
: set ( value variable -- ) namespace set-hash ; : set ( value variable -- ) namespace set-hash ;
: on ( var -- ) t swap set ; inline : on ( var -- ) t swap set ; inline
: off ( var -- ) f swap set ; inline : off ( var -- ) f swap set ; inline
: get-global ( var -- value ) global hash ; inline
: set-global ( value var -- ) global set-hash ; inline : set-global ( value var -- ) global set-hash ; inline
: nest ( variable -- hash ) : nest ( variable -- hash )

View File

@ -7,11 +7,11 @@ namespaces queues sequences vectors ;
! Co-operative multitasker. ! Co-operative multitasker.
: run-queue ( -- queue ) \ run-queue global hash ; : run-queue ( -- queue ) \ run-queue get-global ;
: schedule-thread ( continuation -- ) run-queue enque ; : schedule-thread ( continuation -- ) run-queue enque ;
: sleep-queue ( -- vec ) \ sleep-queue global hash ; : sleep-queue ( -- vec ) \ sleep-queue get-global ;
: sleep-queue* ( -- vec ) : sleep-queue* ( -- vec )
sleep-queue dup [ 2car swap - ] nsort ; sleep-queue dup [ 2car swap - ] nsort ;

View File

@ -7,11 +7,14 @@ styles threads ;
TUPLE: button rollover? pressed? ; TUPLE: button rollover? pressed? ;
: button-down? ( -- ? ) hand get hand-buttons empty? not ; : button-down? ( -- ? )
hand-buttons get-global empty? not ;
: mouse-over? ( gadget -- ? ) hand get hand-gadget child? ; : mouse-over? ( gadget -- ? )
hand-gadget get-global child? ;
: mouse-clicked? ( gadget -- ? ) hand get hand-clicked child? ; : mouse-clicked? ( gadget -- ? )
hand-clicked get-global child? ;
: button-update ( button -- ) : button-update ( button -- )
dup mouse-over? over set-button-rollover? dup mouse-over? over set-button-rollover?

View File

@ -68,7 +68,8 @@ TUPLE: editor line caret font color ;
] with-editor ; ] with-editor ;
: click-editor ( editor -- ) : click-editor ( editor -- )
dup hand get relative first over set-caret-x request-focus ; dup hand get rect-loc relative-loc
first over set-caret-x request-focus ;
: popup-location ( editor -- loc ) : popup-location ( editor -- loc )
dup screen-loc swap editor-caret rect-extent nip v+ ; dup screen-loc swap editor-caret rect-extent nip v+ ;

View File

@ -4,6 +4,16 @@ IN: gadgets
USING: gadgets-labels gadgets-layouts kernel math namespaces USING: gadgets-labels gadgets-layouts kernel math namespaces
queues sequences ; queues sequences ;
! Hand state
SYMBOL: hand-gadget
SYMBOL: hand-clicked
SYMBOL: hand-click-loc
SYMBOL: hand-buttons
V{ } clone hand-buttons set-global
! The hand is a special gadget that holds mouse position and ! The hand is a special gadget that holds mouse position and
! mouse button click state. ! mouse button click state.
@ -11,53 +21,50 @@ queues sequences ;
! - hand-gadget is the gadget under the mouse position ! - hand-gadget is the gadget under the mouse position
! - hand-clicked is the most recently clicked gadget ! - hand-clicked is the most recently clicked gadget
! - hand-focus is the gadget holding keyboard focus ! - hand-focus is the gadget holding keyboard focus
TUPLE: hand click-loc click-rel clicked buttons gadget focus ; TUPLE: hand focus ;
C: hand ( -- hand ) C: hand ( -- hand )
dup delegate>gadget V{ } clone over set-hand-buttons ; dup delegate>gadget ;
<hand> hand set-global <hand> hand set-global
: button-gesture ( buttons gesture -- ) : button-gesture ( buttons gesture -- )
#! Send a gesture like [ button-down 2 ]; if nobody #! Send a gesture like [ button-down 2 ]; if nobody
#! handles it, send [ button-down ]. #! handles it, send [ button-down ].
swap hand get hand-clicked 3dup >r add r> handle-gesture swap hand-clicked get-global 3dup >r add r> handle-gesture
[ nip handle-gesture drop ] [ 3drop ] if ; [ nip handle-gesture drop ] [ 3drop ] if ;
: update-clicked ( -- ) : update-clicked ( -- )
hand get hand-gadget get-global hand-clicked set-global
dup hand-gadget over set-hand-clicked hand get rect-loc hand-click-loc set-global ;
dup screen-loc over set-hand-click-loc
dup hand-gadget over relative swap set-hand-click-rel ;
: send-button-down ( event -- ) : send-button-down ( event -- )
update-clicked update-clicked
dup hand get hand-buttons push dup hand-buttons get-global push
[ button-down ] button-gesture ; [ button-down ] button-gesture ;
: send-button-up ( event -- ) : send-button-up ( event -- )
dup hand get hand-buttons delete dup hand-buttons get-global delete
[ button-up ] button-gesture ; [ button-up ] button-gesture ;
: send-scroll-wheel ( up/down -- ) : send-scroll-wheel ( up/down -- )
[ wheel-up ] [ wheel-down ] ? [ wheel-up ] [ wheel-down ] ?
hand get hand-gadget handle-gesture drop ; hand-gadget get-global handle-gesture drop ;
: drag-gesture ( -- ) : drag-gesture ( -- )
#! Send a gesture like [ drag 2 ]; if nobody handles it, #! Send a gesture like [ drag 2 ]; if nobody handles it,
#! send [ drag ]. #! send [ drag ].
hand get hand-buttons first [ drag ] button-gesture ; hand-buttons get-global first [ drag ] button-gesture ;
: fire-motion ( hand -- ) : fire-motion ( -- )
#! Fire a motion gesture to the gadget underneath the hand, #! Fire a motion gesture to the gadget underneath the hand,
#! and if a mouse button is down, fire a drag gesture to the #! and if a mouse button is down, fire a drag gesture to the
#! gadget that was clicked. #! gadget that was clicked.
[ motion ] over hand-gadget handle-gesture drop [ motion ] hand-gadget get-global handle-gesture drop
hand-buttons empty? [ drag-gesture ] unless ; hand-buttons get-global empty? [ drag-gesture ] unless ;
: send-user-input ( string -- ) : send-user-input ( string -- )
dup empty? dup empty? [ hand get hand-focus user-input ] unless drop ;
[ hand get hand-focus user-input ] unless drop ;
: each-gesture ( gesture seq -- ) : each-gesture ( gesture seq -- )
[ handle-gesture* drop ] each-with ; [ handle-gesture* drop ] each-with ;
@ -65,7 +72,7 @@ C: hand ( -- hand )
: hand-gestures ( new old -- ) : hand-gestures ( new old -- )
drop-prefix reverse-slice drop-prefix reverse-slice
[ mouse-leave ] swap each-gesture [ mouse-leave ] swap each-gesture
hand get fire-motion fire-motion
[ mouse-enter ] swap each-gesture ; [ mouse-enter ] swap each-gesture ;
: focus-gestures ( new old -- ) : focus-gestures ( new old -- )
@ -73,7 +80,7 @@ C: hand ( -- hand )
[ lose-focus ] swap each-gesture [ lose-focus ] swap each-gesture
[ gain-focus ] swap each-gesture ; [ gain-focus ] swap each-gesture ;
: focused-ancestors ( hand -- seq ) : focused-ancestors ( -- seq )
hand get hand-focus parents reverse-slice ; hand get hand-focus parents reverse-slice ;
: request-focus ( gadget -- ) : request-focus ( gadget -- )
@ -82,7 +89,7 @@ C: hand ( -- hand )
r> focus-gestures ; r> focus-gestures ;
: drag-loc ( gadget -- loc ) : drag-loc ( gadget -- loc )
hand get [ relative ] keep hand-click-rel v- ; hand get rect-loc relative-loc hand-click-rel v- ;
: relevant-help ( seq -- help ) : relevant-help ( seq -- help )
[ gadget-help ] map [ ] find nip ; [ gadget-help ] map [ ] find nip ;
@ -93,19 +100,19 @@ C: hand ( -- hand )
: update-help ( -- string ) : update-help ( -- string )
#! Update mouse-over help message. #! Update mouse-over help message.
hand get hand-gadget parents [ relevant-help ] keep hand-gadget get-global parents [ relevant-help ] keep
dup empty? [ 2drop ] [ peek show-message ] if ; dup empty? [ 2drop ] [ peek show-message ] if ;
: under-hand ( -- seq ) : under-hand ( -- seq )
#! A sequence whose first element is the world and last is #! A sequence whose first element is the world and last is
#! the current gadget, with all parents in between. #! the current gadget, with all parents in between.
hand get hand-gadget parents reverse-slice ; hand-gadget get-global parents reverse-slice ;
: hand-grab ( world -- gadget ) : hand-grab ( world -- gadget )
hand get rect-loc swap pick-up ; hand get rect-loc swap pick-up ;
: update-hand-gadget ( world -- ) : update-hand-gadget ( world -- )
hand-grab hand get set-hand-gadget ; hand-grab hand-gadget set-global ;
: move-hand ( loc world -- ) : move-hand ( loc world -- )
swap under-hand >r hand get set-rect-loc swap under-hand >r hand get set-rect-loc

View File

@ -78,10 +78,10 @@ M: gadget remove-notify* drop ;
#! { 1 1 0 } - bottom right corner #! { 1 1 0 } - bottom right corner
>r dup screen-loc swap rect-dim r> v* v+ ; >r dup screen-loc swap rect-dim r> v* v+ ;
: relative ( g1 g2 -- g2-g1 ) screen-loc swap screen-loc v- ; : relative-loc ( g1 point -- point-g1 ) swap screen-loc v- ;
: relative-rect ( g1 g2 -- rect ) : relative-rect ( g1 g2 -- rect )
[ relative ] keep rect-dim <rect> ; [ screen-loc relative-loc ] keep rect-dim <rect> ;
: child? ( parent child -- ? ) parents memq? ; : child? ( parent child -- ? ) parents memq? ;

View File

@ -10,7 +10,7 @@ IN: gadgets-layouts
: invalidate* ( gadget -- ) dup invalidate forget-pref-dim ; : invalidate* ( gadget -- ) dup invalidate forget-pref-dim ;
: invalid ( -- queue ) \ invalid global hash ; : invalid ( -- queue ) \ invalid get-global ;
<queue> \ invalid set-global <queue> \ invalid set-global

View File

@ -26,7 +26,7 @@ namespaces sequences ;
: show-menu ( loc menu gadget -- ) : show-menu ( loc menu gadget -- )
find-world 2dup show-glass find-world 2dup show-glass
dup world-glass dup menu-actions hand get set-hand-clicked dup world-glass dup menu-actions hand-clicked set-global
over >r menu-loc r> set-rect-loc ; over >r menu-loc r> set-rect-loc ;
: show-hand-menu ( menu gadget -- ) : show-hand-menu ( menu gadget -- )

View File

@ -40,7 +40,7 @@ SYMBOL: structured-input
: pane-call ( quot pane -- ) : pane-call ( quot pane -- )
"<< command >>" over stream-print "<< command >>" over stream-print
>r structured-input set-global >r structured-input set-global
"\"structured-input\" \"gadgets-panes\" lookup global hash call" "\"structured-input\" \"gadgets-panes\" lookup get-global call"
r> pane-eval ; r> pane-eval ;
: editor-commit ( editor -- line ) : editor-commit ( editor -- line )

View File

@ -70,7 +70,7 @@ SYMBOL: slider-changed
[ slider-page * ] keep slide-by ; [ slider-page * ] keep slide-by ;
: elevator-click ( elevator -- ) : elevator-click ( elevator -- )
dup hand get relative >r find-slider r> dup hand get rect-loc relative-loc >r find-slider r>
over gadget-orientation v. over gadget-orientation v.
over screen>slider over slider-value - sgn over screen>slider over slider-value - sgn
swap slide-by-page ; swap slide-by-page ;

View File

@ -14,7 +14,7 @@ C: timer ( object delay -- timer )
GENERIC: tick ( ms object -- ) GENERIC: tick ( ms object -- )
: timers \ timers global hash ; : timers \ timers get-global ;
H{ } clone \ timers set-global H{ } clone \ timers set-global

View File

@ -8,7 +8,7 @@ SYMBOL: bootstrapping?
SYMBOL: vocabularies SYMBOL: vocabularies
: word ( -- word ) \ word global hash ; : word ( -- word ) \ word get-global ;
: set-word ( word -- ) \ word set-global ; : set-word ( word -- ) \ word set-global ;