#46 snapping while moving

--HG--
extra : convert_revision : svn%3Ab267cdba-c1da-11dd-874b-8bacd04a0a74/trunk%4062
This commit is contained in:
ondrej.zara
2009-11-12 18:36:52 +00:00
parent ec6c49dc5b
commit 0996adb0b9
+19 -14
View File
@@ -632,6 +632,7 @@ SQL.Table.prototype.init = function(owner, name, x, y, z) {
this.x = x || 0; this.x = x || 0;
this.y = y || 0; this.y = y || 0;
this.setZ(z); this.setZ(z);
this.snap();
} }
SQL.Table.prototype._build = function() { SQL.Table.prototype._build = function() {
@@ -769,31 +770,37 @@ SQL.Table.prototype.redraw = function() {
for (var i=0;i<rs.length;i++) { rs[i].redraw(); } for (var i=0;i<rs.length;i++) { rs[i].redraw(); }
} }
SQL.Table.prototype.moveBy = function(dx, dy, snap) { SQL.Table.prototype.moveBy = function(dx, dy) {
this.x += dx; this.x += dx;
this.y += dy; this.y += dy;
if (snap) { this.snap();
this.x = Math.round(this.x / snap) * snap;
this.y = Math.round(this.y / snap) * snap;
}
this.redraw(); this.redraw();
} }
SQL.Table.prototype.moveTo = function(x, y) { SQL.Table.prototype.moveTo = function(x, y) {
this.x = x; this.x = x;
this.y = y; this.y = y;
this.snap();
this.redraw(); this.redraw();
} }
SQL.Table.prototype.snap = function() {
var snap = parseInt(SQL.Designer.getOption("snap"));
if (snap) {
this.x = Math.round(this.x / snap) * snap;
this.y = Math.round(this.y / snap) * snap;
}
}
SQL.Table.prototype.down = function(e) { /* mousedown - start drag */ SQL.Table.prototype.down = function(e) { /* mousedown - start drag */
OZ.Event.prevent(e); OZ.Event.prevent(e);
this.owner.tableManager.select(this); this.owner.tableManager.select(this);
SQL.Table.active = this; SQL.Table.active = this;
SQL.Table.x = e.clientX; SQL.Table.x = this.x - e.clientX; /* position relative to mouse cursor */
SQL.Table.y = e.clientY; SQL.Table.y = this.y - e.clientY;
if (this.owner.getOption("hide")) { this.hideRelations(); } if (this.owner.getOption("hide")) { this.hideRelations(); }
} }
@@ -882,13 +889,12 @@ SQL.Table.prototype.getComment = function() {
SQL.Table.move = function(e) { /* mousemove */ SQL.Table.move = function(e) { /* mousemove */
var t = SQL.Table; var t = SQL.Table;
var d = SQL.Designer;
if (!t.active) { return; } if (!t.active) { return; }
SQL.Designer.removeSelection(); SQL.Designer.removeSelection();
var dx = e.clientX - t.x; var x = t.x + e.clientX;
var dy = e.clientY - t.y; var y = t.y + e.clientY;
t.active.moveBy(dx, dy); t.active.moveTo(x, y);
t.x = e.clientX;
t.y = e.clientY;
} }
SQL.Table.up = function(e) { SQL.Table.up = function(e) {
@@ -896,7 +902,6 @@ SQL.Table.up = function(e) {
var d = SQL.Designer; var d = SQL.Designer;
if (!t.active) { return; } if (!t.active) { return; }
if (d.getOption("hide")) { t.active.showRelations(); } if (d.getOption("hide")) { t.active.showRelations(); }
t.active.moveBy(0,0, parseInt(d.getOption("snap")));
t.active = false; t.active = false;
} }