2018-11-13 05:24:09 +00:00
// Compiled by ClojureScript 1.10.439 {}
2018-11-12 21:18:45 +00:00
goog . provide ( 'quil.middlewares.navigation_2d' ) ;
goog . require ( 'cljs.core' ) ;
goog . require ( 'quil.core' ) ;
2018-11-13 05:24:09 +00:00
quil . middlewares . navigation _2d . missing _navigation _key _error = [ "state map is missing :navigation-2d key. " , "Did you accidentally removed it from the state in " , ":update or any other handler?" ] . join ( '' ) ;
2018-11-12 21:18:45 +00:00
/ * *
* Asserts that state map contains : navigation - 2 d object .
* /
quil . middlewares . navigation _2d . assert _state _has _navigation = ( function quil$middlewares$navigation _2d$assert _state _has _navigation ( state ) {
if ( cljs . core . truth _ ( new cljs . core . Keyword ( null , "navigation-2d" , "navigation-2d" , - 1924168611 ) . cljs$core$IFn$ _invoke$arity$1 ( state ) ) ) {
return null ;
} else {
throw ( new Error ( quil . middlewares . navigation _2d . missing _navigation _key _error ) ) ;
}
} ) ;
/ * *
* Default position configuration : zoom is neutral and central point is
* width / 2 , height / 2.
* /
quil . middlewares . navigation _2d . default _position = ( function quil$middlewares$navigation _2d$default _position ( ) {
return new cljs . core . PersistentArrayMap ( null , 2 , [ new cljs . core . Keyword ( null , "position" , "position" , - 2011731912 ) , new cljs . core . PersistentVector ( null , 2 , 5 , cljs . core . PersistentVector . EMPTY _NODE , [ ( quil . core . width . call ( null ) / 2.0 ) , ( quil . core . height . call ( null ) / 2.0 ) ] , null ) , new cljs . core . Keyword ( null , "zoom" , "zoom" , - 1827487038 ) , ( 1 ) ] , null ) ;
} ) ;
/ * *
* Custom 'setup' function which creates initial position
* configuration and puts it to the state map .
* /
quil . middlewares . navigation _2d . setup _2d _nav = ( function quil$middlewares$navigation _2d$setup _2d _nav ( user _setup , user _settings ) {
var initial _state = cljs . core . merge . call ( null , quil . middlewares . navigation _2d . default _position . call ( null ) , cljs . core . select _keys . call ( null , user _settings , new cljs . core . PersistentVector ( null , 2 , 5 , cljs . core . PersistentVector . EMPTY _NODE , [ new cljs . core . Keyword ( null , "position" , "position" , - 2011731912 ) , new cljs . core . Keyword ( null , "zoom" , "zoom" , - 1827487038 ) ] , null ) ) ) ;
return cljs . core . update _in . call ( null , user _setup . call ( null ) , new cljs . core . PersistentVector ( null , 1 , 5 , cljs . core . PersistentVector . EMPTY _NODE , [ new cljs . core . Keyword ( null , "navigation-2d" , "navigation-2d" , - 1924168611 ) ] , null ) , ( ( function ( initial _state ) {
2018-11-13 05:24:09 +00:00
return ( function ( p1 _ _2126 _SHARP _ ) {
return cljs . core . merge . call ( null , initial _state , p1 _ _2126 _SHARP _ ) ;
2018-11-12 21:18:45 +00:00
} ) ; } ) ( initial _state ) )
) ;
} ) ;
/ * *
* Changes center of the sketch depending on the last mouse move . Takes
* zoom into account as well .
* /
quil . middlewares . navigation _2d . mouse _dragged = ( function quil$middlewares$navigation _2d$mouse _dragged ( state , event ) {
quil . middlewares . navigation _2d . assert _state _has _navigation . call ( null , state ) ;
var dx = ( new cljs . core . Keyword ( null , "p-x" , "p-x" , - 1721211211 ) . cljs$core$IFn$ _invoke$arity$1 ( event ) - new cljs . core . Keyword ( null , "x" , "x" , 2099068185 ) . cljs$core$IFn$ _invoke$arity$1 ( event ) ) ;
var dy = ( new cljs . core . Keyword ( null , "p-y" , "p-y" , - 530704830 ) . cljs$core$IFn$ _invoke$arity$1 ( event ) - new cljs . core . Keyword ( null , "y" , "y" , - 1757859776 ) . cljs$core$IFn$ _invoke$arity$1 ( event ) ) ;
var zoom = new cljs . core . Keyword ( null , "zoom" , "zoom" , - 1827487038 ) . cljs$core$IFn$ _invoke$arity$1 ( new cljs . core . Keyword ( null , "navigation-2d" , "navigation-2d" , - 1924168611 ) . cljs$core$IFn$ _invoke$arity$1 ( state ) ) ;
return cljs . core . update _in . call ( null , cljs . core . update _in . call ( null , state , new cljs . core . PersistentVector ( null , 3 , 5 , cljs . core . PersistentVector . EMPTY _NODE , [ new cljs . core . Keyword ( null , "navigation-2d" , "navigation-2d" , - 1924168611 ) , new cljs . core . Keyword ( null , "position" , "position" , - 2011731912 ) , ( 0 ) ] , null ) , cljs . core . _PLUS _ , ( dx / zoom ) ) , new cljs . core . PersistentVector ( null , 3 , 5 , cljs . core . PersistentVector . EMPTY _NODE , [ new cljs . core . Keyword ( null , "navigation-2d" , "navigation-2d" , - 1924168611 ) , new cljs . core . Keyword ( null , "position" , "position" , - 2011731912 ) , ( 1 ) ] , null ) , cljs . core . _PLUS _ , ( dy / zoom ) ) ;
} ) ;
/ * *
* Changes zoom settings based on scroll .
* /
quil . middlewares . navigation _2d . mouse _wheel = ( function quil$middlewares$navigation _2d$mouse _wheel ( state , event ) {
quil . middlewares . navigation _2d . assert _state _has _navigation . call ( null , state ) ;
return cljs . core . update _in . call ( null , state , new cljs . core . PersistentVector ( null , 2 , 5 , cljs . core . PersistentVector . EMPTY _NODE , [ new cljs . core . Keyword ( null , "navigation-2d" , "navigation-2d" , - 1924168611 ) , new cljs . core . Keyword ( null , "zoom" , "zoom" , - 1827487038 ) ] , null ) , cljs . core . _STAR _ , ( ( 1 ) + ( - 0.1 * event ) ) ) ;
} ) ;
/ * *
* Calls user draw function with necessary all transformations ( position
* and zoom ) applied .
* /
quil . middlewares . navigation _2d . draw = ( function quil$middlewares$navigation _2d$draw ( user _draw , state ) {
quil . middlewares . navigation _2d . assert _state _has _navigation . call ( null , state ) ;
quil . core . push _matrix . call ( null ) ;
2018-11-13 05:24:09 +00:00
var nav _2d _2127 = new cljs . core . Keyword ( null , "navigation-2d" , "navigation-2d" , - 1924168611 ) . cljs$core$IFn$ _invoke$arity$1 ( state ) ;
var zoom _2128 = new cljs . core . Keyword ( null , "zoom" , "zoom" , - 1827487038 ) . cljs$core$IFn$ _invoke$arity$1 ( nav _2d _2127 ) ;
var pos _2129 = new cljs . core . Keyword ( null , "position" , "position" , - 2011731912 ) . cljs$core$IFn$ _invoke$arity$1 ( nav _2d _2127 ) ;
quil . core . scale . call ( null , zoom _2128 ) ;
2018-11-12 21:18:45 +00:00
2018-11-13 05:24:09 +00:00
var tr _ _2049 _ _auto _ _ _2130 = new cljs . core . PersistentVector ( null , 2 , 5 , cljs . core . PersistentVector . EMPTY _NODE , [ ( ( ( quil . core . width . call ( null ) / ( 2 ) ) / zoom _2128 ) - cljs . core . first . call ( null , pos _2129 ) ) , ( ( ( quil . core . height . call ( null ) / ( 2 ) ) / zoom _2128 ) - cljs . core . second . call ( null , pos _2129 ) ) ] , null ) ;
2018-11-12 21:18:45 +00:00
quil . core . push _matrix . call ( null ) ;
2018-11-13 05:24:09 +00:00
try { quil . core . translate . call ( null , tr _ _2049 _ _auto _ _ _2130 ) ;
2018-11-12 21:18:45 +00:00
user _draw . call ( null , state ) ;
} finally { quil . core . pop _matrix . call ( null ) ;
}
return quil . core . pop _matrix . call ( null ) ;
} ) ;
/ * *
* Enables navigation over 2 D sketch . Dragging mouse will move center of the
* skecth and mouse wheel controls zoom .
* /
quil . middlewares . navigation _2d . navigation _2d = ( function quil$middlewares$navigation _2d$navigation _2d ( options ) {
var user _settings = new cljs . core . Keyword ( null , "navigation-2d" , "navigation-2d" , - 1924168611 ) . cljs$core$IFn$ _invoke$arity$1 ( options ) ;
var user _draw = new cljs . core . Keyword ( null , "draw" , "draw" , 1358331674 ) . cljs$core$IFn$ _invoke$arity$2 ( options , ( ( function ( user _settings ) {
return ( function ( state ) {
return null ;
} ) ; } ) ( user _settings ) )
) ;
var user _mouse _dragged = new cljs . core . Keyword ( null , "mouse-dragged" , "mouse-dragged" , - 1220073441 ) . cljs$core$IFn$ _invoke$arity$2 ( options , ( ( function ( user _settings , user _draw ) {
return ( function ( state , _ ) {
return state ;
} ) ; } ) ( user _settings , user _draw ) )
) ;
var user _mouse _wheel = new cljs . core . Keyword ( null , "mouse-wheel" , "mouse-wheel" , 1811662439 ) . cljs$core$IFn$ _invoke$arity$2 ( options , ( ( function ( user _settings , user _draw , user _mouse _dragged ) {
return ( function ( state , _ ) {
return state ;
} ) ; } ) ( user _settings , user _draw , user _mouse _dragged ) )
) ;
var setup = new cljs . core . Keyword ( null , "setup" , "setup" , 1987730512 ) . cljs$core$IFn$ _invoke$arity$2 ( options , ( ( function ( user _settings , user _draw , user _mouse _dragged , user _mouse _wheel ) {
return ( function ( ) {
return cljs . core . PersistentArrayMap . EMPTY ;
} ) ; } ) ( user _settings , user _draw , user _mouse _dragged , user _mouse _wheel ) )
) ;
return cljs . core . assoc . call ( null , options , new cljs . core . Keyword ( null , "setup" , "setup" , 1987730512 ) , cljs . core . partial . call ( null , quil . middlewares . navigation _2d . setup _2d _nav , setup , user _settings ) , new cljs . core . Keyword ( null , "draw" , "draw" , 1358331674 ) , cljs . core . partial . call ( null , quil . middlewares . navigation _2d . draw , user _draw ) , new cljs . core . Keyword ( null , "mouse-dragged" , "mouse-dragged" , - 1220073441 ) , ( ( function ( user _settings , user _draw , user _mouse _dragged , user _mouse _wheel , setup ) {
return ( function ( state , event ) {
return user _mouse _dragged . call ( null , quil . middlewares . navigation _2d . mouse _dragged . call ( null , state , event ) , event ) ;
} ) ; } ) ( user _settings , user _draw , user _mouse _dragged , user _mouse _wheel , setup ) )
, new cljs . core . Keyword ( null , "mouse-wheel" , "mouse-wheel" , 1811662439 ) , ( ( function ( user _settings , user _draw , user _mouse _dragged , user _mouse _wheel , setup ) {
return ( function ( state , event ) {
return user _mouse _wheel . call ( null , quil . middlewares . navigation _2d . mouse _wheel . call ( null , state , event ) , event ) ;
} ) ; } ) ( user _settings , user _draw , user _mouse _dragged , user _mouse _wheel , setup ) )
) ;
} ) ;
2018-11-13 05:24:09 +00:00
//# sourceMappingURL=navigation_2d.js.map