Sculpture.move = function(base){ var x, y, z, position, dimension, bounds var dragging = false, moved = false var oldState this.bind = function(){ Sculpture.mouse.bind_el(base.mx.el) Sculpture.mouse.on("down", down) Sculpture.mouse.on("drag", drag) Sculpture.mouse.on("up", up) } this.unbind = function(){ base.focused = false Sculpture.mouse.unbind_el(base.mx.el) Sculpture.mouse.off("down", down) Sculpture.mouse.off("drag", drag) Sculpture.mouse.off("up", up) } function down (e, cursor){ if (e.target != base.mx.el && (e.target != base.mx.overlay)) return; if (editor.permissions.destroy) { base.remove() return } // load the modal app.controller.pick(base) if (! base.focused) { e.clickAccepted = false base.focused = true return } if (! (editor.permissions.move || editor.permissions.resize) ) { e.clickAccepted = false return } dragging = true moved = false x = base.mx.x y = base.mx.y z = base.mx.z bounds = base.bounds dimension = base.dimensions oldState = base.serialize() document.body.classList.add("dragging") } function drag (e, cursor){ if (! dragging) return moved = true var delta = cursor.delta() delta.mul( cursor_amp ) // TODO: this should be proportional to your distance from the wall delta.b *= -1 // here we need to move the element based on the XY coords, as // base.mx.y = position.b + delta.b + dimension.b / 2 base.mx.x = x + delta.a * cos(cam.rotationY) - delta.b * sin(cam.rotationY) base.mx.z = z + delta.a * sin(cam.rotationY) + delta.b * cos(cam.rotationY) // if (editor.permissions.resize) { // Sculpture.resize.move_dots() // } } function up (e, cursor){ if (! dragging || ! oldState) return if (moved) { UndoStack.push({ type: 'update-sculpture', undo: oldState, redo: base.serialize(), }) // TODO: watch individual sculpture object here Minotaur.watch( app.router.editorView.settings ) } dragging = moved = false oldState = null document.body.classList.remove("dragging") } return this }