Cleanup
This commit is contained in:
parent
60a8c62927
commit
24a7b76254
@ -17,7 +17,7 @@ function Cursor () {
|
||||
}
|
||||
|
||||
this.down = function (e) {
|
||||
this.pos = this.pos_from_event(e)
|
||||
this.pos = this.atEvent(e)
|
||||
|
||||
// Translation
|
||||
if (DOTGRID.tool.vertexAt(this.pos)) {
|
||||
@ -32,7 +32,7 @@ function Cursor () {
|
||||
this.last_pos = { x: 0, y: 0 }
|
||||
|
||||
this.move = function (e) {
|
||||
this.pos = this.pos_from_event(e)
|
||||
this.pos = this.atEvent(e)
|
||||
|
||||
// Translation
|
||||
if (this.translation) {
|
||||
@ -50,7 +50,7 @@ function Cursor () {
|
||||
}
|
||||
|
||||
this.up = function (e) {
|
||||
this.pos = this.pos_from_event(e)
|
||||
this.pos = this.atEvent(e)
|
||||
|
||||
if (this.translation && !is_equal(this.translation.from, this.translation.to)) {
|
||||
if (this.translation.layer === true) { DOTGRID.tool.translateLayer(this.translation.from, this.translation.to) } else if (this.translation.copy) { DOTGRID.tool.translateCopy(this.translation.from, this.translation.to) } else if (this.translation.multi) { DOTGRID.tool.translateMulti(this.translation.from, this.translation.to) } else { DOTGRID.tool.translate(this.translation.from, this.translation.to) }
|
||||
@ -67,7 +67,7 @@ function Cursor () {
|
||||
}
|
||||
|
||||
this.alt = function (e) {
|
||||
this.pos = this.pos_from_event(e)
|
||||
this.pos = this.atEvent(e)
|
||||
|
||||
DOTGRID.tool.removeSegmentsAt(this.pos)
|
||||
e.preventDefault()
|
||||
@ -77,18 +77,18 @@ function Cursor () {
|
||||
|
||||
// Position Mods
|
||||
|
||||
this.pos_from_event = function (e) {
|
||||
return this.pos_snap(this.pos_relative({ x: e.clientX, y: e.clientY }))
|
||||
this.atEvent = function (e) {
|
||||
return this.snapPos(this.relativePos({ x: e.clientX, y: e.clientY }))
|
||||
}
|
||||
|
||||
this.pos_relative = function (pos) {
|
||||
this.relativePos = function (pos) {
|
||||
return {
|
||||
x: pos.x - DOTGRID.renderer.el.offsetLeft,
|
||||
y: pos.y - DOTGRID.renderer.el.offsetTop
|
||||
}
|
||||
}
|
||||
|
||||
this.pos_snap = function (pos) {
|
||||
this.snapPos = function (pos) {
|
||||
return {
|
||||
x: clamp(step(pos.x, 15), 15, DOTGRID.tool.settings.size.width),
|
||||
y: clamp(step(pos.y, 15), 15, DOTGRID.tool.settings.size.height + 15)
|
||||
|
@ -52,7 +52,7 @@ function Dotgrid (width, height) {
|
||||
// File
|
||||
|
||||
this.new = function () {
|
||||
this.set_zoom(1.0)
|
||||
this.setZoom(1.0)
|
||||
this.setSize({ width: 300, height: 300 })
|
||||
this.history.push(this.tool.layers)
|
||||
this.clear()
|
||||
@ -72,32 +72,6 @@ function Dotgrid (width, height) {
|
||||
})
|
||||
}
|
||||
|
||||
function grab (base64, name) {
|
||||
const link = document.createElement('a')
|
||||
link.setAttribute('href', base64)
|
||||
link.setAttribute('download', name)
|
||||
link.dispatchEvent(new MouseEvent(`click`, { bubbles: true, cancelable: true, view: window }))
|
||||
}
|
||||
|
||||
this.save = function () {
|
||||
if (DOTGRID.tool.length() < 1) { console.warn('Nothing to save'); return }
|
||||
|
||||
this.manager.toGRID(grab)
|
||||
}
|
||||
|
||||
this.export = function () {
|
||||
if (DOTGRID.tool.length() < 1) { console.warn('Nothing to export'); return }
|
||||
|
||||
this.manager.toSVG(grab)
|
||||
}
|
||||
|
||||
this.render = function () {
|
||||
if (DOTGRID.tool.length() < 1) { console.warn('Nothing to render'); return }
|
||||
|
||||
const size = { width: DOTGRID.tool.settings.size.width * 2, height: DOTGRID.tool.settings.size.height * 2 }
|
||||
this.manager.toPNG(size, grab)
|
||||
}
|
||||
|
||||
// Basics
|
||||
|
||||
this.getSize = function () {
|
||||
@ -125,7 +99,7 @@ function Dotgrid (width, height) {
|
||||
this.renderer.update()
|
||||
}
|
||||
|
||||
this.set_zoom = function (scale) {
|
||||
this.setZoom = function (scale) {
|
||||
this.setSize({ width: this.tool.settings.size.width, height: this.tool.settings.size.height }, true, scale)
|
||||
|
||||
try {
|
||||
|
@ -79,4 +79,28 @@ function Manager (dotgrid) {
|
||||
const file = new Blob([text], { type: 'text/plain' })
|
||||
callback(URL.createObjectURL(file), 'export.grid')
|
||||
}
|
||||
|
||||
// Helpers
|
||||
|
||||
this.save = function () {
|
||||
if (DOTGRID.tool.length() < 1) { console.warn('Nothing to save'); return }
|
||||
this.toGRID(grab)
|
||||
}
|
||||
|
||||
this.export = function () {
|
||||
if (DOTGRID.tool.length() < 1) { console.warn('Nothing to export'); return }
|
||||
this.toSVG(grab)
|
||||
}
|
||||
|
||||
this.render = function () {
|
||||
if (DOTGRID.tool.length() < 1) { console.warn('Nothing to render'); return }
|
||||
this.toPNG({ width: DOTGRID.tool.settings.size.width * 2, height: DOTGRID.tool.settings.size.height * 2 }, grab)
|
||||
}
|
||||
|
||||
function grab (base64, name) {
|
||||
const link = document.createElement('a')
|
||||
link.setAttribute('href', base64)
|
||||
link.setAttribute('download', name)
|
||||
link.dispatchEvent(new MouseEvent(`click`, { bubbles: true, cancelable: true, view: window }))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user