I am working in one task in that dynamic layer want to do as a resize able by kinectic. layer function.
For ex:
When I am click the rectangle shaped button at that time the rectangle shaped would be shown in a canvas.
And it is working also, infact it is draggable also. Now, the problem is coming that shaped rectangle I want to do as a dynamic resizeable but it is not working according to the kinectic.js function.
For clearly, let we see the image
And here is my code for the rectangle shaped
function addShape(w,h,c){
var layerRect = new Kinetic.Layer();
layerRect.add(new Kinetic.Rect({
x:0,
y:0,
width:w,
height:h,
fill: c,
draggable: true
}));
stage.add(layerRect);
var kShaped;
var startRight=-1;
var startWidth=0;
var startHeight=0;
$(stage.getContent()).on('mousedown', function (event) {
var pos=stage.getPointerPosition();
var mouseX=parseInt(pos.x);
var mouseY=parseInt(pos.y);
var ipos=layerRect.position();
var isize=layerRect.getSize();
var right=ipos.x+isize.width;
if(mouseX>right-10 && mouseX<right+10){
startRight=mouseX;
startWidth=isize.width;
startHeight=isize.height;
}
});
$(stage.getContent()).on('mouseup', function (event) {
startRight=-1;
});
$(stage.getContent()).on('mousemove', function (event) {
if(startRight>=0){
var pos=stage.getPointerPosition();
var mouseX=parseInt(pos.x);
var mouseY=parseInt(pos.y);
var dx=mouseX-startRight;
var scaleFactor=(mouseX-(startRight-startWidth))/startWidth;
layerRect.width(startWidth*scaleFactor);
layerRect.height(startHeight*scaleFactor);
layer.draw();
}
});
}
//This click function is for create rectangle shape
$("#textsubmitShape").live("click",function(){
addShape(200,100,"Green");
});
