ui.gadgets.plot: Keyboard controls

db4
Eduardo Cavazos 2008-07-31 21:53:37 -05:00
parent 52085a4e49
commit 28abbfc6c2
1 changed files with 74 additions and 1 deletions

View File

@ -61,4 +61,77 @@ M: plot draw-slate ( plot -- plot )
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: add-function ( plot function -- plot )
over functions>> swap suffix >>functions ;
over functions>> swap suffix >>functions ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: x-span ( plot -- span ) [ x-max>> ] [ x-min>> ] bi - ;
: y-span ( plot -- span ) [ y-max>> ] [ y-min>> ] bi - ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
USING: ui.gestures ui.gadgets ;
: left ( plot -- plot )
dup [ x-min>> ] [ x-span 1/10 * ] bi - >>x-min
dup [ x-max>> ] [ x-span 1/10 * ] bi - >>x-max
dup relayout-1 ;
: right ( plot -- plot )
dup [ x-min>> ] [ x-span 1/10 * ] bi + >>x-min
dup [ x-max>> ] [ x-span 1/10 * ] bi + >>x-max
dup relayout-1 ;
: down ( plot -- plot )
dup [ y-min>> ] [ y-span 1/10 * ] bi - >>y-min
dup [ y-max>> ] [ y-span 1/10 * ] bi - >>y-max
dup relayout-1 ;
: up ( plot -- plot )
dup [ y-min>> ] [ y-span 1/10 * ] bi + >>y-min
dup [ y-max>> ] [ y-span 1/10 * ] bi + >>y-max
dup relayout-1 ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: zoom-in-horizontal ( plot -- plot )
dup [ x-min>> ] [ x-span 1/10 * ] bi + >>x-min
dup [ x-max>> ] [ x-span 1/10 * ] bi - >>x-max ;
: zoom-in-vertical ( plot -- plot )
dup [ y-min>> ] [ y-span 1/10 * ] bi + >>y-min
dup [ y-max>> ] [ y-span 1/10 * ] bi - >>y-max ;
: zoom-in ( plot -- plot )
zoom-in-horizontal
zoom-in-vertical
dup relayout-1 ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: zoom-out-horizontal ( plot -- plot )
dup [ x-min>> ] [ x-span 1/10 * ] bi - >>x-min
dup [ x-max>> ] [ x-span 1/10 * ] bi + >>x-max ;
: zoom-out-vertical ( plot -- plot )
dup [ y-min>> ] [ y-span 1/10 * ] bi - >>y-min
dup [ y-max>> ] [ y-span 1/10 * ] bi + >>y-max ;
: zoom-out ( plot -- plot )
zoom-out-horizontal
zoom-out-vertical
dup relayout-1 ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
plot
H{
{ T{ mouse-enter } [ request-focus ] }
{ T{ key-down f f "LEFT" } [ left drop ] }
{ T{ key-down f f "RIGHT" } [ right drop ] }
{ T{ key-down f f "DOWN" } [ down drop ] }
{ T{ key-down f f "UP" } [ up drop ] }
{ T{ key-down f f "a" } [ zoom-in drop ] }
{ T{ key-down f f "z" } [ zoom-out drop ] }
}
set-gestures