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

View File

@ -14,7 +14,7 @@ SYMBOL: hand-click-loc
SYMBOL: hand-buttons
V{ } clone hand-buttons set-global
TUPLE: hand focus ;
TUPLE: hand ;
C: hand ( -- hand )
dup delegate>gadget ;
@ -56,9 +56,6 @@ C: hand ( -- hand )
[ motion ] hand-gadget get-global handle-gesture drop
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 -- )
[ handle-gesture* drop ] each-with ;
@ -73,13 +70,11 @@ C: hand ( -- hand )
[ lose-focus ] swap each-gesture
[ gain-focus ] swap each-gesture ;
: focused-ancestors ( -- seq )
hand get hand-focus parents reverse-slice ;
: request-focus ( gadget -- )
focusable-child focused-ancestors >r
hand get set-hand-focus focused-ancestors
r> focus-gestures ;
dup focusable-child swap find-world
dup focused-ancestors >r
[ set-world-focus ] keep
focused-ancestors r> focus-gestures ;
: drag-loc ( gadget -- loc )
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
! handle: native resource
TUPLE: world glass status fonts handle ;
TUPLE: world glass status focus fonts handle ;
: free-fonts ( world -- )
world-fonts dup hash-values [ free-sprites ] each
@ -47,3 +47,6 @@ M: world find-world ;
: repaint ( gadget -- )
find-world [ world-handle repaint-handle ] when* ;
: focused-ancestors ( world -- seq )
world-focus parents reverse-slice ;