Added translate layer
This commit is contained in:
parent
f29ac29b05
commit
5360cca5df
@ -5,8 +5,8 @@ DOTGRID.Cursor = function () {
|
||||
this.translation = null
|
||||
this.operation = null
|
||||
|
||||
this.translate = function (from = null, to = null, multi = false, copy = false) {
|
||||
if ((from || to) && this.translation == null) { this.translation = { multi: multi, copy: copy }; console.log('Begin translation', multi, copy) }
|
||||
this.translate = function (from = null, to = null, multi = false, copy = false, layer = false) {
|
||||
if ((from || to) && this.translation == null) { this.translation = { multi: multi, copy: copy, layer: layer }; console.log('Begin translation', multi, copy, layer) }
|
||||
|
||||
if (from) { this.translation.from = from }
|
||||
if (to) { this.translation.to = to }
|
||||
@ -21,7 +21,7 @@ DOTGRID.Cursor = function () {
|
||||
|
||||
// Translation
|
||||
if (DOTGRID.tool.vertex_at(this.pos)) {
|
||||
this.translate(this.pos, this.pos, e.shiftKey, e.ctrlKey || e.metaKey)
|
||||
this.translate(this.pos, this.pos, e.shiftKey, e.ctrlKey || e.metaKey, e.altKey)
|
||||
}
|
||||
|
||||
DOTGRID.guide.update()
|
||||
@ -52,10 +52,8 @@ DOTGRID.Cursor = function () {
|
||||
this.up = function (e) {
|
||||
this.pos = this.pos_from_event(e)
|
||||
|
||||
if (e.altKey) { DOTGRID.tool.remove_segments_at(this.pos); this.translate(); return }
|
||||
|
||||
if (this.translation && !is_equal(this.translation.from, this.translation.to)) {
|
||||
if (this.translation.copy) { DOTGRID.tool.translate_copy(this.translation.from, this.translation.to) } else if (this.translation.multi) { DOTGRID.tool.translate_multi(this.translation.from, this.translation.to) } else { DOTGRID.tool.translate(this.translation.from, this.translation.to) }
|
||||
if (this.translation.layer === true) { DOTGRID.tool.translate_layer(this.translation.from, this.translation.to) } else if (this.translation.copy) { DOTGRID.tool.translate_copy(this.translation.from, this.translation.to) } else if (this.translation.multi) { DOTGRID.tool.translate_multi(this.translation.from, this.translation.to) } else { DOTGRID.tool.translate(this.translation.from, this.translation.to) }
|
||||
} else if (e.target.id == 'guide') {
|
||||
DOTGRID.tool.add_vertex({ x: this.pos.x, y: this.pos.y })
|
||||
DOTGRID.picker.stop()
|
||||
|
@ -13,8 +13,6 @@ function Generator (layer, style) {
|
||||
if (mirror == 1 || mirror == 3) { seg.vertices[k2].x = (DOTGRID.tool.settings.size.width) - seg.vertices[k2].x + 15 }
|
||||
if (mirror == 2 || mirror == 3) { seg.vertices[k2].y = (DOTGRID.tool.settings.size.height) - seg.vertices[k2].y + 30 }
|
||||
|
||||
console.log(seg)
|
||||
|
||||
// Offset
|
||||
seg.vertices[k2].x += offset.x
|
||||
seg.vertices[k2].y += offset.y
|
||||
|
@ -283,6 +283,21 @@ DOTGRID.Tool = function () {
|
||||
DOTGRID.guide.update()
|
||||
}
|
||||
|
||||
this.translate_layer = function (a, b) {
|
||||
console.log(a, b)
|
||||
const offset = { x: a.x - b.x, y: a.y - b.y }
|
||||
for (const segment_id in this.layer()) {
|
||||
let segment = this.layer()[segment_id]
|
||||
for (const vertex_id in segment.vertices) {
|
||||
let vertex = segment.vertices[vertex_id]
|
||||
segment.vertices[vertex_id] = { x: vertex.x - offset.x, y: vertex.y - offset.y }
|
||||
}
|
||||
}
|
||||
DOTGRID.history.push(this.layers)
|
||||
this.clear()
|
||||
DOTGRID.guide.update()
|
||||
}
|
||||
|
||||
this.translate_copy = function (a, b) {
|
||||
const offset = { x: a.x - b.x, y: a.y - b.y }
|
||||
const segment = this.select_segment_at(a, copy(this.layer()))
|
||||
|
Loading…
x
Reference in New Issue
Block a user