|
|
@ -4,13 +4,13 @@ fabric.perfLimitSizeTotal = 134217728; |
|
|
|
fabric.maxCacheSideLimit = 65536; |
|
|
|
|
|
|
|
export default class Board { |
|
|
|
constructor(id) { |
|
|
|
constructor(id, {grid} = {grid: {}}) { |
|
|
|
this.id = id; |
|
|
|
this.state = {a: 32}; |
|
|
|
this.state = {}; |
|
|
|
|
|
|
|
this.containerElement = document.getElementById(id); |
|
|
|
if (this.containerElement == null) { |
|
|
|
throw new Error(`Container ${this.id} not found`) |
|
|
|
throw new Error(`Container "${this.id}" not found`) |
|
|
|
} |
|
|
|
|
|
|
|
this.canvasElement = document.createElement("canvas"); |
|
|
@ -22,6 +22,7 @@ export default class Board { |
|
|
|
this.canvas.add(this.gridGroup); |
|
|
|
|
|
|
|
this.gridOptions = { |
|
|
|
...(grid || {}), |
|
|
|
enabled: true, |
|
|
|
size: 64, |
|
|
|
hightlightInterval: 8, |
|
|
@ -59,19 +60,19 @@ export default class Board { |
|
|
|
const wCount = Math.ceil((this.canvas.getWidth() / this.canvas.getZoom()) / size) + (hightlightInterval * 2); |
|
|
|
const hCount = Math.ceil((this.canvas.getHeight() / this.canvas.getZoom()) / size) + (hightlightInterval * 2); |
|
|
|
|
|
|
|
const width2 = wCount * (size); |
|
|
|
const height2 = hCount * (size); |
|
|
|
const width = wCount * (size); |
|
|
|
const height = hCount * (size); |
|
|
|
|
|
|
|
this.gridGroup.set("left", 0); |
|
|
|
this.gridGroup.set("top", 0); |
|
|
|
this.gridGroup.set("width", width2); |
|
|
|
this.gridGroup.set("height", height2); |
|
|
|
this.gridGroup.set("width", width); |
|
|
|
this.gridGroup.set("height", height); |
|
|
|
this.gridGroup.set("selectable", false); |
|
|
|
this.gridGroup.set("hoverCursor", "default"); |
|
|
|
|
|
|
|
for (let i = 0; i <= wCount; ++i) { |
|
|
|
let x = i * size; |
|
|
|
let line = new fabric.Line([x, 0, x, height2], {stroke: lineColor, strokeWidth: 2, selectable: false}); |
|
|
|
let line = new fabric.Line([x, 0, x, height], {stroke: lineColor, strokeWidth: 2, selectable: false}); |
|
|
|
|
|
|
|
if (i % hightlightInterval == 0) { |
|
|
|
line.set("stroke", highlightColor); |
|
|
@ -82,7 +83,7 @@ export default class Board { |
|
|
|
|
|
|
|
for (let i = 0; i <= hCount; ++i) { |
|
|
|
let y = i * size; |
|
|
|
let line = new fabric.Line([0, y, width2, y], {stroke: lineColor, strokeWidth: 2, selectable: false}); |
|
|
|
let line = new fabric.Line([0, y, width, y], {stroke: lineColor, strokeWidth: 2, selectable: false}); |
|
|
|
|
|
|
|
if (i % hightlightInterval == 0) { |
|
|
|
line.set("stroke", highlightColor); |
|
|
@ -101,14 +102,14 @@ export default class Board { |
|
|
|
this.gridGroup.set("left", x - xOffset); |
|
|
|
this.gridGroup.set("top", y - yOffset); |
|
|
|
this.gridGroup.setCoords(); |
|
|
|
|
|
|
|
console.log(this.gridGroup); |
|
|
|
} |
|
|
|
|
|
|
|
setupPanning() { |
|
|
|
const parent = this; |
|
|
|
|
|
|
|
this.canvas.on('mouse:wheel', ({e}) => { |
|
|
|
return; // TODO: Fix bugs with the grid when zoomed in/out.
|
|
|
|
|
|
|
|
if (e.shiftKey === false) { |
|
|
|
return; |
|
|
|
} |
|
|
@ -129,7 +130,7 @@ export default class Board { |
|
|
|
|
|
|
|
e.preventDefault(); |
|
|
|
e.stopPropagation(); |
|
|
|
}) |
|
|
|
}); |
|
|
|
|
|
|
|
this.canvas.on('mouse:down', function(opt) { |
|
|
|
var evt = opt.e; |
|
|
|