fix mouse enter/leave handling with overlapping gadgets
parent
dc78cac25f
commit
3a366a386f
|
@ -2,15 +2,14 @@
|
||||||
---
|
---
|
||||||
|
|
||||||
- i/o: don't keep creating new sbufs
|
- i/o: don't keep creating new sbufs
|
||||||
- rollovers broken with menus
|
|
||||||
- menu dragging
|
|
||||||
- fix up the min thumb size hack
|
|
||||||
- gaps in pack layout
|
|
||||||
- fix listener prompt display after presentation commands invoked
|
- fix listener prompt display after presentation commands invoked
|
||||||
- theme abstraction in ui
|
- theme abstraction in ui
|
||||||
|
|
||||||
+ ui:
|
+ ui:
|
||||||
|
|
||||||
|
- menu dragging
|
||||||
|
- fix up the min thumb size hack
|
||||||
|
- gaps in pack layout
|
||||||
- find out why so many small bignums get consed
|
- find out why so many small bignums get consed
|
||||||
- repaint only dirty regions of the screen
|
- repaint only dirty regions of the screen
|
||||||
- faster mouse tracking
|
- faster mouse tracking
|
||||||
|
|
|
@ -333,4 +333,4 @@ M: general-list tutorial-line
|
||||||
<book-browser> ;
|
<book-browser> ;
|
||||||
|
|
||||||
: tutorial ( -- )
|
: tutorial ( -- )
|
||||||
ensure-ui <tutorial> gadget. ;
|
<tutorial> gadget. ;
|
||||||
|
|
|
@ -35,42 +35,8 @@ SYMBOL: motion
|
||||||
SYMBOL: drag
|
SYMBOL: drag
|
||||||
SYMBOL: button-up
|
SYMBOL: button-up
|
||||||
SYMBOL: button-down
|
SYMBOL: button-down
|
||||||
|
SYMBOL: mouse-enter
|
||||||
|
SYMBOL: mouse-leave
|
||||||
|
|
||||||
: hierarchy-gesture ( gadget ? gesture -- ? )
|
SYMBOL: lose-focus
|
||||||
swap [ 2drop f ] [ swap handle-gesture* drop t ] ifte ;
|
SYMBOL: gain-focus
|
||||||
|
|
||||||
: 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.
|
|
||||||
[
|
|
||||||
[ rectangle-loc v+ ] keep
|
|
||||||
2dup inside? [ mouse-enter ] hierarchy-gesture
|
|
||||||
] each-parent 2drop ;
|
|
||||||
|
|
||||||
: 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.
|
|
||||||
[
|
|
||||||
[ rectangle-loc v+ ] keep
|
|
||||||
2dup inside? [ mouse-leave ] hierarchy-gesture
|
|
||||||
] each-parent 2drop ;
|
|
||||||
|
|
||||||
: lose-focus ( new old -- )
|
|
||||||
#! If the old focus owner is a child of the new owner, do
|
|
||||||
#! not fire a focus lost gesture, since the focus was not
|
|
||||||
#! lost. Otherwise, fire a focus lost gesture and go to the
|
|
||||||
#! parent.
|
|
||||||
[
|
|
||||||
2dup child? [ lose-focus ] hierarchy-gesture
|
|
||||||
] each-parent 2drop ;
|
|
||||||
|
|
||||||
: gain-focus ( old new -- )
|
|
||||||
#! If the old focus owner is a child of the new owner, do
|
|
||||||
#! not fire a focus gained gesture, since the focus was not
|
|
||||||
#! gained. Otherwise, fire a focus gained gesture and go on
|
|
||||||
#! to the parent.
|
|
||||||
[
|
|
||||||
2dup child? [ gain-focus ] hierarchy-gesture
|
|
||||||
] each-parent 2drop ;
|
|
||||||
|
|
|
@ -46,16 +46,7 @@ C: hand ( world -- hand )
|
||||||
: button\ ( n hand -- )
|
: button\ ( n hand -- )
|
||||||
[ hand-buttons remove ] keep set-hand-buttons ;
|
[ hand-buttons remove ] keep set-hand-buttons ;
|
||||||
|
|
||||||
: fire-leave ( hand gadget -- )
|
: drag-gesture ( hand gadget gesture -- )
|
||||||
[ swap rectangle-loc swap screen-loc v- ] keep mouse-leave ;
|
|
||||||
|
|
||||||
: fire-enter ( oldpos hand -- )
|
|
||||||
hand-gadget [ screen-loc v- ] keep mouse-enter ;
|
|
||||||
|
|
||||||
: update-hand-gadget ( hand -- )
|
|
||||||
[ rectangle-loc world get pick-up ] keep set-hand-gadget ;
|
|
||||||
|
|
||||||
: motion-gesture ( hand gadget gesture -- )
|
|
||||||
#! Send a gesture like [ drag 2 ].
|
#! Send a gesture like [ drag 2 ].
|
||||||
rot hand-buttons car add swap handle-gesture drop ;
|
rot hand-buttons car add swap handle-gesture drop ;
|
||||||
|
|
||||||
|
@ -65,24 +56,36 @@ C: hand ( world -- hand )
|
||||||
#! gadget that was clicked.
|
#! gadget that was clicked.
|
||||||
[ motion ] over hand-gadget handle-gesture drop
|
[ motion ] over hand-gadget handle-gesture drop
|
||||||
dup hand-buttons
|
dup hand-buttons
|
||||||
[ dup hand-clicked [ drag ] motion-gesture ] [ drop ] ifte ;
|
[ dup hand-clicked [ drag ] drag-gesture ] [ drop ] ifte ;
|
||||||
|
|
||||||
|
: drop-prefix ( l1 l2 -- l1 l2 )
|
||||||
|
2dup and [ 2dup 2car eq? [ 2cdr drop-prefix ] when ] when ;
|
||||||
|
|
||||||
|
: each-gesture ( gesture seq -- )
|
||||||
|
[ handle-gesture* drop ] each-with ;
|
||||||
|
|
||||||
|
: hand-gestures ( hand new old -- )
|
||||||
|
drop-prefix
|
||||||
|
reverse [ mouse-leave ] swap each-gesture
|
||||||
|
swap fire-motion
|
||||||
|
[ mouse-enter ] swap each-gesture ;
|
||||||
|
|
||||||
: move-hand ( loc hand -- )
|
: move-hand ( loc hand -- )
|
||||||
dup rectangle-loc >r
|
dup hand-gadget parents-down >r
|
||||||
[ set-rectangle-loc ] keep
|
2dup set-rectangle-loc
|
||||||
dup hand-gadget >r
|
[ >r world get pick-up r> set-hand-gadget ] keep
|
||||||
dup update-hand-gadget
|
dup hand-gadget parents-down r> hand-gestures ;
|
||||||
dup r> fire-leave
|
|
||||||
dup fire-motion
|
|
||||||
r> swap fire-enter ;
|
|
||||||
|
|
||||||
: update-hand ( hand -- )
|
: update-hand ( hand -- )
|
||||||
#! Called when a gadget is removed or added.
|
#! Called when a gadget is removed or added.
|
||||||
dup rectangle-loc swap move-hand ;
|
dup rectangle-loc swap move-hand ;
|
||||||
|
|
||||||
|
: focus-gestures ( new old -- )
|
||||||
|
drop-prefix
|
||||||
|
reverse [ lose-focus ] swap each-gesture
|
||||||
|
[ gain-focus ] swap each-gesture ;
|
||||||
|
|
||||||
: request-focus ( gadget -- )
|
: request-focus ( gadget -- )
|
||||||
focusable-child
|
focusable-child
|
||||||
hand hand-focus
|
hand dup hand-focus parents-down >r
|
||||||
2dup lose-focus
|
dupd set-hand-focus parents-down r> focus-gestures ;
|
||||||
swap dup hand set-hand-focus
|
|
||||||
gain-focus ;
|
|
||||||
|
|
|
@ -35,27 +35,31 @@ sequences vectors ;
|
||||||
#! Add a gadget to a parent gadget.
|
#! Add a gadget to a parent gadget.
|
||||||
[ (add-gadget) ] keep relayout ;
|
[ (add-gadget) ] keep relayout ;
|
||||||
|
|
||||||
: parents ( gadget -- list )
|
: (parents-down) ( list gadget -- list )
|
||||||
|
[ [ swons ] keep gadget-parent (parents-down) ] when* ;
|
||||||
|
|
||||||
|
: parents-down ( gadget -- list )
|
||||||
|
#! A list of all parents of the gadget, the last element
|
||||||
|
#! is the gadget itself.
|
||||||
|
f swap (parents-down) ;
|
||||||
|
|
||||||
|
: parents-up ( gadget -- list )
|
||||||
#! A list of all parents of the gadget, the first element
|
#! A list of all parents of the gadget, the first element
|
||||||
#! is the gadget itself.
|
#! is the gadget itself.
|
||||||
dup [ dup gadget-parent parents cons ] when ;
|
dup [ dup gadget-parent parents-up cons ] when ;
|
||||||
|
|
||||||
: each-parent ( gadget quot -- ? )
|
: each-parent ( gadget quot -- ? )
|
||||||
>r parents r> all? ; inline
|
>r parents-up r> all? ; inline
|
||||||
|
|
||||||
: find-parent ( gadget quot -- ? )
|
: find-parent ( gadget quot -- ? )
|
||||||
>r parents r> find nip ; inline
|
>r parents-up r> find nip ; inline
|
||||||
|
|
||||||
: screen-loc ( gadget -- point )
|
: screen-loc ( gadget -- point )
|
||||||
#! The position of the gadget on the screen.
|
#! The position of the gadget on the screen.
|
||||||
parents { 0 0 0 } [ rectangle-loc v+ ] reduce ;
|
parents-up { 0 0 0 } [ rectangle-loc v+ ] reduce ;
|
||||||
|
|
||||||
: relative ( g1 g2 -- g2-g1 )
|
: relative ( g1 g2 -- g2-g1 )
|
||||||
screen-loc swap screen-loc v- ;
|
screen-loc swap screen-loc v- ;
|
||||||
|
|
||||||
: child? ( parent child -- ? )
|
: child? ( parent child -- ? )
|
||||||
dup [
|
parents-down memq? ;
|
||||||
2dup eq? [ 2drop t ] [ gadget-parent child? ] ifte
|
|
||||||
] [
|
|
||||||
2drop f
|
|
||||||
] ifte ;
|
|
||||||
|
|
|
@ -43,14 +43,15 @@ global [ 100 <vector> commands set ] bind
|
||||||
[ 2nip ] [ drop <styled-label> dup init-commands ] ifte ;
|
[ 2nip ] [ drop <styled-label> dup init-commands ] ifte ;
|
||||||
|
|
||||||
: gadget. ( gadget -- )
|
: gadget. ( gadget -- )
|
||||||
gadget swons unit "" swap write-attr terpri ;
|
gadget swons unit
|
||||||
|
"This stream does not support live gadgets"
|
||||||
|
swap write-attr terpri ;
|
||||||
|
|
||||||
[ drop t ] "Prettyprint" [ prettyprint ] define-command
|
[ drop t ] "Prettyprint" [ prettyprint ] define-command
|
||||||
[ drop t ] "Inspect" [ inspect ] define-command
|
[ drop t ] "Inspect" [ inspect ] define-command
|
||||||
[ drop t ] "References" [ references inspect ] define-command
|
[ drop t ] "References" [ references inspect ] define-command
|
||||||
|
|
||||||
[ word? ] "See" [ see ] define-command
|
[ word? ] "See" [ see ] define-command
|
||||||
[ word? ] "Execute" [ execute ] define-command
|
|
||||||
[ word? ] "Usage" [ usage . ] define-command
|
[ word? ] "Usage" [ usage . ] define-command
|
||||||
[ word? ] "jEdit" [ jedit ] define-command
|
[ word? ] "jEdit" [ jedit ] define-command
|
||||||
|
|
||||||
|
|
|
@ -5,9 +5,14 @@ USING: generic kernel lists math matrices namespaces sequences
|
||||||
threads vectors styles ;
|
threads vectors styles ;
|
||||||
|
|
||||||
! A viewport can be scrolled.
|
! A viewport can be scrolled.
|
||||||
|
|
||||||
TUPLE: viewport origin bottom? ;
|
TUPLE: viewport origin bottom? ;
|
||||||
|
|
||||||
|
! A slider scrolls a viewport.
|
||||||
|
TUPLE: slider thumb vector ;
|
||||||
|
|
||||||
|
! A scroller combines a viewport with two x and y sliders.
|
||||||
|
TUPLE: scroller viewport x y ;
|
||||||
|
|
||||||
: viewport-dim gadget-child pref-dim ;
|
: viewport-dim gadget-child pref-dim ;
|
||||||
|
|
||||||
: fix-scroll ( origin viewport -- origin )
|
: fix-scroll ( origin viewport -- origin )
|
||||||
|
@ -46,12 +51,6 @@ M: viewport focusable-child* ( viewport -- gadget )
|
||||||
swap viewport-dim { 1 1 1 } vmax
|
swap viewport-dim { 1 1 1 } vmax
|
||||||
v/ { 1 1 1 } vmin ;
|
v/ { 1 1 1 } vmin ;
|
||||||
|
|
||||||
! A slider scrolls a viewport.
|
|
||||||
|
|
||||||
! The offset slot is the y co-ordinate of the mouse relative to
|
|
||||||
! the thumb when it was clicked.
|
|
||||||
TUPLE: slider thumb vector ;
|
|
||||||
|
|
||||||
: slider-scroller ( slider -- scroller )
|
: slider-scroller ( slider -- scroller )
|
||||||
[ scroller? ] find-parent ;
|
[ scroller? ] find-parent ;
|
||||||
|
|
||||||
|
@ -128,8 +127,6 @@ M: slider layout* ( slider -- )
|
||||||
dup thumb-dim over slider-vector v* slider-dim vmax
|
dup thumb-dim over slider-vector v* slider-dim vmax
|
||||||
swap slider-thumb set-gadget-dim ;
|
swap slider-thumb set-gadget-dim ;
|
||||||
|
|
||||||
TUPLE: scroller viewport x y ;
|
|
||||||
|
|
||||||
: add-viewport 2dup set-scroller-viewport add-center ;
|
: add-viewport 2dup set-scroller-viewport add-center ;
|
||||||
|
|
||||||
: add-x-slider 2dup set-scroller-x add-bottom ;
|
: add-x-slider 2dup set-scroller-x add-bottom ;
|
||||||
|
|
|
@ -12,10 +12,10 @@ vectors ;
|
||||||
TUPLE: world running? hand glass invalid ;
|
TUPLE: world running? hand glass invalid ;
|
||||||
|
|
||||||
DEFER: <hand>
|
DEFER: <hand>
|
||||||
|
DEFER: update-hand
|
||||||
|
|
||||||
C: world ( -- world )
|
C: world ( -- world )
|
||||||
f <stack> over set-delegate
|
f <stack> over set-delegate
|
||||||
t over set-world-running?
|
|
||||||
t over set-gadget-root?
|
t over set-gadget-root?
|
||||||
dup <hand> over set-world-hand ;
|
dup <hand> over set-world-hand ;
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ DEFER: handle-event
|
||||||
|
|
||||||
: world-step ( -- ? )
|
: world-step ( -- ? )
|
||||||
world get dup world-invalid >r layout-world r>
|
world get dup world-invalid >r layout-world r>
|
||||||
[ hand update-hand draw-world ] [ drop ] ifte ;
|
[ dup world-hand update-hand draw-world ] [ drop ] ifte ;
|
||||||
|
|
||||||
: next-event ( -- event ? )
|
: next-event ( -- event ? )
|
||||||
<event> dup SDL_PollEvent ;
|
<event> dup SDL_PollEvent ;
|
||||||
|
@ -69,11 +69,5 @@ DEFER: handle-event
|
||||||
world get world-running? [ yield run-world ] when
|
world get world-running? [ yield run-world ] when
|
||||||
] ifte ;
|
] ifte ;
|
||||||
|
|
||||||
: ensure-ui ( -- )
|
|
||||||
#! Raise an error if the UI is not running.
|
|
||||||
world get dup [ world-running? ] when [
|
|
||||||
"UI not running." throw
|
|
||||||
] unless ;
|
|
||||||
|
|
||||||
: start-world ( -- )
|
: start-world ( -- )
|
||||||
world get t over set-world-running? relayout ;
|
world get t over set-world-running? relayout ;
|
||||||
|
|
Loading…
Reference in New Issue