Skip to content

Commit a053dcc

Browse files
committed
Merge remote-tracking branch 'origin/development'
2 parents 3114b85 + cceb5a2 commit a053dcc

File tree

1 file changed

+11
-21
lines changed

1 file changed

+11
-21
lines changed

src/components/blocks/blocks.js

+11-21
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ var Blocks = function(errorHandler = null, openParameterEditor = null)
1717
this.editable = true;
1818

1919
// View center & scale
20-
this.center = {};
20+
this.center = {
21+
x: 0,
22+
y: 0
23+
};
2124
this.newBlockOffset = 0;
2225
this.scale = 1.3;
2326
this.redrawTimeout = null;
@@ -102,7 +105,8 @@ Blocks.prototype.run = function(selector, editable = true)
102105
this.editable = editable;
103106

104107
if (!this.div) {
105-
console.log('blocks.js: Unable to find ' + selector);
108+
console.error('blocks.js: Unable to find ' + selector);
109+
return;
106110
}
107111

108112
// Inject the initial editor
@@ -119,7 +123,6 @@ Blocks.prototype.run = function(selector, editable = true)
119123
var rect = Utils.domBoundingBox(this.div);
120124
this.center.x = rect.width/2;
121125
this.center.y = rect.height/2;
122-
this.newBlockOffset = 0;
123126

124127
// Listen for mouse position
125128
this.div.addEventListener('mousemove', event => {
@@ -222,19 +225,6 @@ Blocks.prototype.showParameters = function(block) {
222225
}
223226
};
224227

225-
/**
226-
* Gets the mouse position
227-
*/
228-
Blocks.prototype.getPosition = function()
229-
{
230-
var position = {};
231-
position.x = (this.mouseX-this.center.x)/this.scale;
232-
position.y = (this.mouseY-this.center.y)/this.scale;
233-
234-
return position;
235-
};
236-
237-
238228
Blocks.prototype.hasUndo = function()
239229
{
240230
if (this.history === null) {
@@ -316,8 +306,9 @@ Blocks.prototype.addBlock = function(name, type, x, y, values = {})
316306
throw "'" + name + "' not available.";
317307
}
318308
var block = new Block(this, name, type, this.moduleTypes[type][name], this.id);
319-
block.x = x === null ? (-block.getWidth()/2 + this.newBlockOffset) : x;
320-
block.y = y === null ? (-block.getHeight()/2 + this.newBlockOffset) : y;
309+
var rect = Utils.domBoundingBox(this.div);
310+
block.x = x === null ? (-this.center.x + rect.width/2 - block.getWidth()/2 + this.newBlockOffset) : x;
311+
block.y = y === null ? (-this.center.y + rect.height/2 - block.getHeight()/2 + this.newBlockOffset) : y;
321312
if (this.newBlockOffset < 150) {
322313
this.newBlockOffset += 10;
323314
}
@@ -601,7 +592,7 @@ Blocks.prototype.doRedraw = function()
601592
'stroke-width': 3*this.scale
602593
});
603594
} catch (error) {
604-
console.log(error);
595+
console.error(error);
605596
this.linking = null;
606597
}
607598
}
@@ -723,7 +714,7 @@ Blocks.prototype.showError = function(message, title = null) {
723714
this.errorHandler(message, title);
724715
}
725716
else {
726-
console.log(title, message);
717+
console.error(title, message);
727718
}
728719
}
729720

@@ -950,7 +941,6 @@ Blocks.prototype.perfectScale = function()
950941
}
951942

952943
var rect = this.div.getBoundingClientRect();
953-
954944
var scaleA = rect.width/(xMax-xMin);
955945
var scaleB = rect.height/(yMax-yMin);
956946
var scale = Math.min(scaleA, scaleB);

0 commit comments

Comments
 (0)