Skip to content
Snippets Groups Projects
Select Git revision
  • 134a342539b4d8efdbe8baa4e762d4be497e968f
  • master default protected
2 results

Step.stl

Blame
  • vtoplevel.js 24.54 KiB
    /*
    view/vtoplevel.js
    
    Jake Read at the Center for Bits and Atoms
    (c) Massachusetts Institute of Technology 2019
    
    This work may be reproduced, modified, distributed, performed, and
    displayed for any purpose, but must acknowledge the squidworks and cuttlefish projects.
    Copyright is retained and must be preserved. The work is provided as is;
    no warranty is provided, and users accept all liability.
    */
    
    // just this fn...
    
    import cfContextMenu from './vcontextmenu.js'
    import DomTools from './vdom.js'
    
    function makeTopLevel(view) {
      console.log(`MAKE TOP LEVEL ${view.name}`)
      // we need this friend as well,
      let dt = new DomTools(view)
      view.isTopLevel = true
      $(view.dom).attr('id', 'NROLVIEW')
      $(view.plane).attr('id', 'tlplane')
      // this is that (0,0) marker,
      // also needs more space ...
      $(view.plane).css('background', 'url("asset/bg.png")').css('width', '100px').css('height', '100px')
      // init transform of the plane,
      let dft = {
        s: 1,
        x: 0,
        y: 0,
        ox: 0,
        oy: 0
      }
      dt.writeTransform(view.plane, dft)
      dt.writeBackgroundTransform(view.dom, dft)
    
      view.getCurrentBounds = () => {
        let ct = dt.readTransform(view.plane)
        let w = view.dom.clientWidth / ct.s
        let h = view.dom.clientHeight / ct.s
        let x1 = -ct.x / ct.s
        let y1 = -ct.y / ct.s
        let x2 = w - x1
        let y2 = h - y1
        // move & shimmy by
        return {
          x1: x1,
          y1: y1,
          x2: x2,
          y2: y2,
          w: w,
          h: h
        }
      }
    
      // to zoom,
      view.dom.addEventListener('wheel', (evt) => {
        if (!$(evt.target).is('.view') && !$(evt.target).is('#floater')) {
          return false
        }
        evt.preventDefault()
        evt.stopPropagation()
    
        let ox = evt.clientX
        let oy = evt.clientY
    
        let ds
        if (evt.deltaY > 0) {