Select Git revision
divtools.js
mods.js 63.13 KiB
//
// mods.js
//
// Neil Gershenfeld
// (c) Massachusetts Institute of Technology 2018
//
// This work may be reproduced, modified, distributed, performed, and
// displayed for any purpose, but must acknowledge the mods
// project. Copyright is retained and must be preserved. The work is
// provided as is; no warranty is provided, and users accept all
// liability.
//
// closure
//
(function(){
//
// globals
//
var mods = {}
mods.mod = {}
mods.globals = {}
mods.ui = {source:null,
progname:'',
padding:7,
bezier:100,
canvas:250,
rows:5,
cols:20,
link_color:'rgb(0,0,128)',
link_highlight:'rgb(255,0,0)',
header:50,
selected:{},
mousedown:null,
menu:null,
top:null,
left:null,
xstart:null,
ystart:null,
xtrans:null,
ytrans:null
}
//
// UI
//
document.body.style.overflow = "hidden"
function mods_transform() {
var transform = document.body.style.transform
var m = new DOMMatrix(getComputedStyle(document.body).transform)
var s = m.m11
var tx = m.m41/s
var ty = m.m42/s
var origin = document.body.style.transformOrigin
var pxx = origin.indexOf('px')
var ox = parseFloat(origin.slice(0,pxx))
var pxy = origin.indexOf('px',pxx+2)
var oy = parseFloat(origin.slice(pxx+2,pxy))
return({s:s,tx:tx,ty:ty,ox:ox,oy:oy})
}
document.body.style.transform = 'scale(1) translate(0px,0px)'
document.body.style.transformOrigin = '0px 0px'
//
// scroll wheel event
//
window.addEventListener('wheel',function(evt) {
/*
(xw+tx-ox)*s+ox = xs
xw = ox-tx+(xs-ox)/s
(xw+tx0-ox0)*s+ox0 = (xw+tx1-ox1)*s+ox1
(tx0-ox0)*s+ox0 = (tx1-ox1)*s+ox1
tx0+(ox1-ox0)+(ox0-ox1)/s = tx1