px;top:<%= get("y")-30 %>px;width:<%= get("w")+20 %>px;height:<%= get("h")+40 %>px;" >'+
+ '
px;top:<%= get("y") %>px;width:<%= get("w") %>px;height:<%= get("h") %>px;" >'+
'
'+
'
'+
'
'+
@@ -68,6 +68,8 @@ $(function(){
// Disable selection for better drag+drop
this.$("h1").disableSelection();
+ this.listenTo(this.model.parentGraph, "change:pan", this.bumpPosition);
+
// Bring newest to top
this.mousedown();
@@ -103,6 +105,9 @@ $(function(){
_alsoDrag: [],
_dragDelta: {},
dragStart: function(event, ui){
+ // Don't drag graph
+ event.stopPropagation();
+
if (event.target !== this.$(".module")[0]) { return; }
// Add a mask so that iframes don't steal mouse
@@ -139,6 +144,9 @@ $(function(){
});
},
drag: function(event, ui){
+ // Don't drag graph
+ event.stopPropagation();
+
if (event.target !== this.$(".module")[0]) { return; }
// Drag other helpers
@@ -161,10 +169,15 @@ $(function(){
}
},
dragStop: function(event, ui){
+ // Don't drag graph
+ event.stopPropagation();
+
if (event.target !== this.$(".module")[0]) { return; }
- var x = parseInt(ui.position.left, 10);
- var y = parseInt(ui.position.top, 10);
+ console.log(ui);
+ var delta = [ui.position.left - ui.originalPosition.left, ui.position.top - ui.originalPosition.top];
+ var x = delta[0] + this.model.get("x");
+ var y = delta[1] + this.model.get("y");
this.moveToPosition(x,y);
// Also drag
if (this._alsoDrag.length) {
@@ -173,7 +186,9 @@ $(function(){
var helper = el.data("ui-draggable-alsodrag-helper");
var node = el.data("iframework-node-view");
// Move other node
- node.moveToPosition(parseInt(helper.css("left"), 10), parseInt(helper.css("top"), 10));
+ var x = delta[0] + node.model.get("x");
+ var y = delta[1] + node.model.get("y");
+ node.moveToPosition(x, y);
// Remove helper
helper.remove();
el.data("ui-draggable-alsodrag-initial", null);
@@ -186,14 +201,20 @@ $(function(){
this.model.parentGraph.view.unmaskFrames();
},
moveToPosition: function(x, y){
+ this.model.set({
+ x: x,
+ y: y
+ });
+ this.bumpPosition();
+ },
+ bumpPosition: function(){
+ var pan = this.model.parentGraph.get("pan");
+ var x = pan[0] + this.model.get("x");
+ var y = pan[1] + this.model.get("y");
this.$(".module").css({
left: x,
top: y
});
- this.model.set({
- x: x + 10,
- y: y + 30
- });
},
resizestart: function (event, ui) {
// Add a mask so that iframes don't steal mouse
@@ -209,8 +230,8 @@ $(function(){
var newW = ui.size.width;
var newH = ui.size.height;
this.model.set({
- w: newW - 20,
- h: newH - 40
+ w: newW,
+ h: newH
});
if (this.Native) {
this.Native.resize(newW,newH);
diff --git a/src/nodes/image-triangle.js b/src/nodes/image-triangle.js
index 0efa5a8..5011d6c 100644
--- a/src/nodes/image-triangle.js
+++ b/src/nodes/image-triangle.js
@@ -2,14 +2,28 @@
$(function(){
+
+ var template =
+ '
';
+
Iframework.NativeNodes["image-triangle"] = Iframework.NativeNodes["image"].extend({
info: {
title: "triangle",
description: "draw a triangle"
},
+ events: {
+ "dragstart .control-point": "startMove",
+ "drag .control-point": "move",
+ "dragstop .control-point": "stopMove"
+ },
initializeModule: function(){
-
+ this.canvas.style.maxWidth = "auto";
+ this.$(".control-point").draggable();
},
inputmatte: function (image) {
this._matte = image;
diff --git a/src/port-view.js b/src/port-view.js
index 96b9c88..ea694cb 100644
--- a/src/port-view.js
+++ b/src/port-view.js
@@ -354,6 +354,23 @@ $(function(){
// Don't bubble
event.stopPropagation();
},
+ portOffset: function(){
+ var pan = this.model.parentNode.parentGraph.get("pan");
+ var index = this.$el.index();
+ // Node position
+ var x = pan[0] + this.model.parentNode.get("x");
+ var y = pan[1] + this.model.parentNode.get("y");
+ // Port position
+ if (this.model.isIn) {
+ x -= 70;
+ y += 9 + index*18;
+ } else {
+ var length = this.$el.siblings().length;
+ x += this.model.parentNode.get("w") + 70;
+ y += this.model.parentNode.get("h") - 9 - (length-index)*18;
+ }
+ return [x,y];
+ },
portOffsetLeft: function () {
var holeoffset = this.$('.hole').offset();
if (holeoffset) {