Made hand-focus into world-focus

release
slava 2006-03-19 06:07:36 +00:00
parent ba471ee5bc
commit a69dde27e4
3 changed files with 25 additions and 27 deletions

View File

@ -26,14 +26,14 @@ H{ } clone views set-global
: view ( handle -- world ) views get hash ; : view ( handle -- world ) views get hash ;
: mouse-location ( event view -- loc ) : mouse-location ( view event -- loc )
[ over >r
swap [locationInWindow] f [convertPoint:fromView:] [locationInWindow] f [convertPoint:fromView:]
dup NSPoint-x swap NSPoint-y dup NSPoint-x swap NSPoint-y
] keep [frame] NSRect-h swap - 0 3array ; r> [frame] NSRect-h swap - 0 3array ;
: send-mouse-moved ( event view -- ) : send-mouse-moved ( view event -- )
[ mouse-location ] keep view move-hand ; swap [ mouse-location ] keep view move-hand ;
: button ( event -- n ) : button ( event -- n )
#! Cocoa -> Factor UI button mapping #! Cocoa -> Factor UI button mapping
@ -74,10 +74,10 @@ H{ } clone views set-global
dup [modifierFlags] modifier swap key-code dup [modifierFlags] modifier swap key-code
[ add >list ] [ drop f ] if* ; [ add >list ] [ drop f ] if* ;
: send-key-event ( event -- ) : send-key-event ( view event -- )
dup event>binding >r view world-focus r> dup event>binding
[ hand get hand-focus handle-gesture ] [ t ] if* [ pick handle-gesture ] [ t ] if*
[ [characters] CF>string send-user-input ] [ drop ] if ; [ [characters] CF>string swap user-input ] [ 2drop ] if ;
"NSOpenGLView" "FactorView" { "NSOpenGLView" "FactorView" {
{ "drawRect:" "void" { "id" "SEL" "NSRect" } { "drawRect:" "void" { "id" "SEL" "NSRect" }
@ -85,19 +85,19 @@ H{ } clone views set-global
} }
{ "mouseMoved:" "void" { "id" "SEL" "id" } { "mouseMoved:" "void" { "id" "SEL" "id" }
[ nip swap send-mouse-moved ] [ nip send-mouse-moved ]
} }
{ "mouseDragged:" "void" { "id" "SEL" "id" } { "mouseDragged:" "void" { "id" "SEL" "id" }
[ nip swap send-mouse-moved ] [ nip send-mouse-moved ]
} }
{ "rightMouseDragged:" "void" { "id" "SEL" "id" } { "rightMouseDragged:" "void" { "id" "SEL" "id" }
[ nip swap send-mouse-moved ] [ nip send-mouse-moved ]
} }
{ "otherMouseDragged:" "void" { "id" "SEL" "id" } { "otherMouseDragged:" "void" { "id" "SEL" "id" }
[ nip swap send-mouse-moved ] [ nip send-mouse-moved ]
} }
{ "mouseDown:" "void" { "id" "SEL" "id" } { "mouseDown:" "void" { "id" "SEL" "id" }
@ -129,7 +129,7 @@ H{ } clone views set-global
} }
{ "keyDown:" "void" { "id" "SEL" "id" } { "keyDown:" "void" { "id" "SEL" "id" }
[ 2nip send-key-event ] [ nip send-key-event ]
} }
{ "updateFactorGadgetSize:" "void" { "id" "SEL" "id" } { "updateFactorGadgetSize:" "void" { "id" "SEL" "id" }

View File

@ -14,7 +14,7 @@ SYMBOL: hand-click-loc
SYMBOL: hand-buttons SYMBOL: hand-buttons
V{ } clone hand-buttons set-global V{ } clone hand-buttons set-global
TUPLE: hand focus ; TUPLE: hand ;
C: hand ( -- hand ) C: hand ( -- hand )
dup delegate>gadget ; dup delegate>gadget ;
@ -56,9 +56,6 @@ C: hand ( -- hand )
[ motion ] hand-gadget get-global handle-gesture drop [ motion ] hand-gadget get-global handle-gesture drop
hand-buttons get-global empty? [ drag-gesture ] unless ; hand-buttons get-global empty? [ drag-gesture ] unless ;
: send-user-input ( string -- )
dup empty? [ 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 ;
@ -73,13 +70,11 @@ 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 ( -- seq )
hand get hand-focus parents reverse-slice ;
: request-focus ( gadget -- ) : request-focus ( gadget -- )
focusable-child focused-ancestors >r dup focusable-child swap find-world
hand get set-hand-focus focused-ancestors dup focused-ancestors >r
r> focus-gestures ; [ set-world-focus ] keep
focused-ancestors r> focus-gestures ;
: drag-loc ( gadget -- loc ) : drag-loc ( gadget -- loc )
hand get rect-loc hand-click-loc get-global v- ; hand get rect-loc hand-click-loc get-global v- ;

View File

@ -9,7 +9,7 @@ namespaces opengl sequences ;
! fonts: mapping font tuples to sprite vectors ! fonts: mapping font tuples to sprite vectors
! handle: native resource ! handle: native resource
TUPLE: world glass status fonts handle ; TUPLE: world glass status focus fonts handle ;
: free-fonts ( world -- ) : free-fonts ( world -- )
world-fonts dup hash-values [ free-sprites ] each world-fonts dup hash-values [ free-sprites ] each
@ -47,3 +47,6 @@ M: world find-world ;
: repaint ( gadget -- ) : repaint ( gadget -- )
find-world [ world-handle repaint-handle ] when* ; find-world [ world-handle repaint-handle ] when* ;
: focused-ancestors ( world -- seq )
world-focus parents reverse-slice ;