2013-01-28 08:27:17 +08:00
|
|
|
Test.Modules.TRANSITION = {
|
|
|
|
'transition position and rotation': function(containerId) {
|
2012-06-16 02:47:55 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
|
|
|
var rect = new Kinetic.Rect({
|
|
|
|
x: 100,
|
|
|
|
y: 100,
|
|
|
|
width: 100,
|
|
|
|
height: 50,
|
|
|
|
fill: 'green',
|
|
|
|
stroke: 'black',
|
2012-07-01 15:19:56 +08:00
|
|
|
strokeWidth: 4,
|
2013-01-14 11:59:35 +08:00
|
|
|
shadowColor: 'black',
|
|
|
|
shadowOffset: 10,
|
|
|
|
shadowOpacity: 0.5
|
2012-06-16 02:47:55 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
layer.add(rect);
|
|
|
|
stage.add(layer);
|
|
|
|
|
|
|
|
rect.transitionTo({
|
|
|
|
duration: 2,
|
2013-03-16 07:19:12 +08:00
|
|
|
x: 400,
|
|
|
|
y: 30,
|
2013-01-14 11:59:35 +08:00
|
|
|
shadowOffset: {
|
|
|
|
x: 80
|
2012-07-01 15:19:56 +08:00
|
|
|
},
|
2012-06-16 02:47:55 +08:00
|
|
|
rotation: Math.PI * 2,
|
|
|
|
easing: 'bounce-ease-out'
|
|
|
|
});
|
2013-01-28 08:27:17 +08:00
|
|
|
|
2012-06-16 02:47:55 +08:00
|
|
|
},
|
2013-01-28 08:27:17 +08:00
|
|
|
'all transition types': function(containerId) {
|
2012-06-16 02:47:55 +08:00
|
|
|
document.getElementById(containerId).style.height = '300px';
|
|
|
|
|
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 300
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
|
|
|
|
|
|
|
var easings = ['linear', 'ease-in', 'ease-out', 'ease-in-out', 'back-ease-in', 'back-ease-out', 'back-ease-in-out', 'elastic-ease-in', 'elastic-ease-out', 'elastic-ease-in-out', 'bounce-ease-out', 'bounce-ease-in', 'bounce-ease-in-out', 'strong-ease-in', 'strong-ease-out', 'strong-ease-in-out'];
|
|
|
|
for(var n = 0; n < easings.length; n++) {
|
|
|
|
var rect = new Kinetic.Rect({
|
|
|
|
x: 10,
|
|
|
|
y: 10 + (n * 200 / easings.length),
|
|
|
|
width: 100,
|
|
|
|
height: 10,
|
|
|
|
fill: 'green',
|
|
|
|
stroke: 'black',
|
|
|
|
strokeWidth: 2
|
|
|
|
});
|
|
|
|
|
|
|
|
layer.add(rect);
|
|
|
|
|
|
|
|
rect.transitionTo({
|
|
|
|
duration: 2,
|
|
|
|
width: 500,
|
|
|
|
easing: easings[n]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
stage.add(layer);
|
|
|
|
},
|
2013-01-28 08:27:17 +08:00
|
|
|
'ease-in, ease-out, ease-in-out hovers': function(containerId) {
|
|
|
|
function addHovers(shape, easing) {
|
|
|
|
shape.on("mouseover", function() {
|
|
|
|
this.transitionTo({
|
|
|
|
scale: {
|
|
|
|
x: 1.5,
|
|
|
|
y: 1.5
|
|
|
|
},
|
|
|
|
duration: 1,
|
2013-03-16 07:19:12 +08:00
|
|
|
easing: easing,
|
|
|
|
callback: function() {
|
|
|
|
console.log('finished');
|
|
|
|
}
|
2013-01-28 08:27:17 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
shape.on("mouseout", function() {
|
|
|
|
this.transitionTo({
|
|
|
|
scale: {
|
|
|
|
x: 1,
|
|
|
|
y: 1
|
|
|
|
},
|
|
|
|
duration: 1,
|
|
|
|
easing: easing
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
|
|
|
var greenBox = new Kinetic.Rect({
|
|
|
|
x: 50,
|
|
|
|
y: stage.getHeight() / 2 - 25,
|
|
|
|
width: 100,
|
|
|
|
height: 50,
|
|
|
|
fill: 'green',
|
|
|
|
stroke: 'black',
|
|
|
|
strokeWidth: 4,
|
|
|
|
offset: {
|
|
|
|
x: 50,
|
|
|
|
y: 25
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var blueBox = new Kinetic.Rect({
|
|
|
|
x: stage.getWidth() / 2 - 50,
|
|
|
|
y: stage.getHeight() / 2 - 25,
|
|
|
|
width: 100,
|
|
|
|
height: 50,
|
|
|
|
fill: 'blue',
|
|
|
|
stroke: 'black',
|
|
|
|
strokeWidth: 4,
|
|
|
|
offset: {
|
|
|
|
x: 50,
|
|
|
|
y: 25
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var redBox = new Kinetic.Rect({
|
|
|
|
x: 428,
|
|
|
|
y: stage.getHeight() / 2 - 25,
|
|
|
|
width: 100,
|
|
|
|
height: 50,
|
|
|
|
fill: 'red',
|
|
|
|
stroke: 'black',
|
|
|
|
strokeWidth: 4,
|
|
|
|
offset: {
|
|
|
|
x: 50,
|
|
|
|
y: 25
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
addHovers(greenBox, "ease-in");
|
|
|
|
addHovers(blueBox, "ease-out");
|
|
|
|
addHovers(redBox, "ease-in-out");
|
|
|
|
|
|
|
|
layer.add(greenBox);
|
|
|
|
layer.add(blueBox);
|
|
|
|
layer.add(redBox);
|
|
|
|
stage.add(layer);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Test.Modules.ANIMATION = {
|
|
|
|
'start and stop animation': function(containerId) {
|
2012-06-16 02:47:55 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
|
|
|
var rect = new Kinetic.Rect({
|
|
|
|
x: 200,
|
|
|
|
y: 100,
|
|
|
|
width: 100,
|
|
|
|
height: 50,
|
|
|
|
fill: 'green',
|
|
|
|
stroke: 'black',
|
|
|
|
strokeWidth: 4
|
|
|
|
});
|
|
|
|
|
|
|
|
layer.add(rect);
|
|
|
|
stage.add(layer);
|
|
|
|
|
|
|
|
var amplitude = 150;
|
|
|
|
var period = 1000;
|
|
|
|
// in ms
|
|
|
|
var centerX = stage.getWidth() / 2 - 100 / 2;
|
|
|
|
|
2012-11-16 13:30:58 +08:00
|
|
|
var anim = new Kinetic.Animation(function(frame) {
|
2013-01-28 08:27:17 +08:00
|
|
|
rect.attrs.x = amplitude * Math.sin(frame.time * 2 * Math.PI / period) + centerX;
|
|
|
|
}, layer);
|
2012-06-16 02:47:55 +08:00
|
|
|
|
2012-08-04 15:23:56 +08:00
|
|
|
anim.start();
|
2012-06-16 02:47:55 +08:00
|
|
|
|
|
|
|
setTimeout(function() {
|
2013-01-08 11:38:16 +08:00
|
|
|
anim.stop();
|
2012-06-16 02:47:55 +08:00
|
|
|
}, 3000);
|
|
|
|
},
|
2013-01-28 08:27:17 +08:00
|
|
|
'test multiple animations': function(containerId) {
|
2012-12-12 14:34:58 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
|
|
|
var greenRect = new Kinetic.Rect({
|
|
|
|
x: 200,
|
|
|
|
y: 20,
|
|
|
|
width: 100,
|
|
|
|
height: 50,
|
|
|
|
fill: 'green',
|
|
|
|
stroke: 'black',
|
|
|
|
strokeWidth: 4
|
|
|
|
});
|
|
|
|
|
|
|
|
var blueRect = new Kinetic.Rect({
|
|
|
|
x: 200,
|
|
|
|
y: 100,
|
|
|
|
width: 100,
|
|
|
|
height: 50,
|
|
|
|
fill: 'blue',
|
|
|
|
stroke: 'black',
|
|
|
|
strokeWidth: 4
|
|
|
|
});
|
|
|
|
|
|
|
|
layer.add(greenRect);
|
|
|
|
layer.add(blueRect);
|
|
|
|
stage.add(layer);
|
|
|
|
|
|
|
|
var amplitude = 150;
|
|
|
|
var period = 1000;
|
|
|
|
// in ms
|
|
|
|
var centerX = stage.getWidth() / 2 - 100 / 2;
|
|
|
|
|
|
|
|
var greenAnim = new Kinetic.Animation(function(frame) {
|
|
|
|
greenRect.setX(amplitude * Math.sin(frame.time * 2 * Math.PI / period) + centerX);
|
|
|
|
}, layer);
|
|
|
|
var blueAnim = new Kinetic.Animation(function(frame) {
|
|
|
|
blueRect.setX(amplitude * Math.sin(frame.time * 2 * Math.PI / period) + centerX);
|
|
|
|
}, layer);
|
|
|
|
|
|
|
|
greenAnim.start();
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
blueAnim.start();
|
|
|
|
}, 1000);
|
|
|
|
setTimeout(function() {
|
|
|
|
greenAnim.stop();
|
|
|
|
}, 2000);
|
|
|
|
setTimeout(function() {
|
|
|
|
blueAnim.stop();
|
|
|
|
}, 3000);
|
|
|
|
setTimeout(function() {
|
|
|
|
greenAnim.start();
|
|
|
|
}, 4000);
|
|
|
|
setTimeout(function() {
|
|
|
|
greenAnim.stop();
|
|
|
|
}, 5000);
|
2013-01-28 08:27:17 +08:00
|
|
|
}
|
|
|
|
};
|
2012-12-12 14:34:58 +08:00
|
|
|
|
2012-09-26 12:23:35 +08:00
|
|
|
|
2013-01-28 08:27:17 +08:00
|
|
|
Test.Modules.EVENTS = {
|
|
|
|
'mousedown mouseup mouseover mouseout mousemove click dblclick / touchstart touchend touchmove tap dbltap': function(containerId) {
|
2012-06-16 02:47:55 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
2013-01-28 08:27:17 +08:00
|
|
|
var circle = new Kinetic.Circle({
|
|
|
|
x: stage.getWidth() / 2,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
|
|
|
fill: 'red',
|
2012-06-16 02:47:55 +08:00
|
|
|
stroke: 'black',
|
2013-01-28 08:27:17 +08:00
|
|
|
strokeWidth: 4
|
2012-06-16 02:47:55 +08:00
|
|
|
});
|
|
|
|
|
2013-01-28 08:27:17 +08:00
|
|
|
circle.on('mousedown', function() {
|
|
|
|
log('mousedown');
|
2012-06-16 02:47:55 +08:00
|
|
|
});
|
|
|
|
|
2013-01-28 08:27:17 +08:00
|
|
|
circle.on('mouseup', function() {
|
|
|
|
log('mouseup');
|
2012-06-16 02:47:55 +08:00
|
|
|
});
|
|
|
|
|
2013-01-28 08:27:17 +08:00
|
|
|
circle.on('mouseover', function() {
|
|
|
|
log('mouseover');
|
|
|
|
});
|
2012-06-16 02:47:55 +08:00
|
|
|
|
2013-01-28 08:27:17 +08:00
|
|
|
circle.on('mouseout', function() {
|
|
|
|
log('mouseout');
|
|
|
|
});
|
|
|
|
|
|
|
|
circle.on('mousemove', function() {
|
|
|
|
log('mousemove');
|
|
|
|
});
|
|
|
|
|
|
|
|
circle.on('click', function() {
|
|
|
|
log('click');
|
|
|
|
});
|
|
|
|
|
|
|
|
circle.on('dblclick', function() {
|
|
|
|
log('dblclick');
|
|
|
|
});
|
|
|
|
/*
|
|
|
|
* mobile
|
|
|
|
*/
|
|
|
|
circle.on('touchstart', function() {
|
|
|
|
log('touchstart');
|
|
|
|
});
|
|
|
|
|
|
|
|
circle.on('touchend', function() {
|
|
|
|
log('touchend');
|
|
|
|
});
|
|
|
|
|
|
|
|
circle.on('touchmove', function() {
|
|
|
|
log('touchmove');
|
|
|
|
});
|
|
|
|
|
|
|
|
circle.on('tap', function(evt) {
|
|
|
|
log('tap');
|
|
|
|
});
|
|
|
|
|
|
|
|
circle.on('dbltap', function() {
|
|
|
|
log('dbltap');
|
|
|
|
});
|
|
|
|
|
|
|
|
layer.add(circle);
|
2012-06-16 02:47:55 +08:00
|
|
|
stage.add(layer);
|
|
|
|
},
|
2013-01-28 08:27:17 +08:00
|
|
|
'modify fill stroke and stroke width on hover with star': function(containerId) {
|
2012-06-16 02:47:55 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
|
|
|
|
2013-03-25 11:42:27 +08:00
|
|
|
var star = new Kinetic.Star({
|
2012-06-16 02:47:55 +08:00
|
|
|
x: 200,
|
|
|
|
y: 100,
|
|
|
|
numPoints: 10,
|
|
|
|
innerRadius: 40,
|
|
|
|
outerRadius: 70,
|
|
|
|
fill: 'green',
|
|
|
|
stroke: 'blue',
|
|
|
|
strokeWidth: 5,
|
|
|
|
name: 'foobar'
|
|
|
|
});
|
|
|
|
|
|
|
|
star.on('mouseover', function() {
|
|
|
|
this.setFill('yellow');
|
|
|
|
this.setStroke('purple');
|
|
|
|
this.setStrokeWidth(20);
|
|
|
|
layer.draw();
|
|
|
|
});
|
|
|
|
|
|
|
|
star.on('mouseout', function() {
|
|
|
|
this.setFill('green');
|
|
|
|
this.setStroke('blue');
|
|
|
|
this.setStrokeWidth(5);
|
|
|
|
layer.draw();
|
|
|
|
});
|
|
|
|
|
|
|
|
layer.add(star);
|
|
|
|
stage.add(layer);
|
|
|
|
},
|
2013-01-28 08:27:17 +08:00
|
|
|
'modify fill stroke and stroke width on hover with image': function(containerId) {
|
2012-06-16 02:47:55 +08:00
|
|
|
var imageObj = new Image();
|
|
|
|
imageObj.onload = function() {
|
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
|
|
|
var darth = new Kinetic.Image({
|
|
|
|
x: 60,
|
|
|
|
y: 60,
|
|
|
|
image: imageObj
|
|
|
|
});
|
|
|
|
|
|
|
|
darth.on('mouseover', function() {
|
|
|
|
this.setStroke('purple');
|
|
|
|
this.setStrokeWidth(20);
|
|
|
|
layer.draw();
|
|
|
|
});
|
|
|
|
|
|
|
|
darth.on('mouseout', function() {
|
2012-06-23 04:15:29 +08:00
|
|
|
this.setStroke(null);
|
2012-06-16 02:47:55 +08:00
|
|
|
this.setStrokeWidth(0);
|
|
|
|
layer.draw();
|
|
|
|
});
|
|
|
|
|
|
|
|
layer.add(darth);
|
|
|
|
stage.add(layer);
|
2013-01-28 08:27:17 +08:00
|
|
|
|
|
|
|
//document.body.appendChild(layer.bufferCanvas.element)
|
2012-06-16 02:47:55 +08:00
|
|
|
};
|
2012-07-22 04:29:22 +08:00
|
|
|
imageObj.src = '../assets/darth-vader.jpg';
|
2012-06-16 02:47:55 +08:00
|
|
|
},
|
2013-01-28 08:27:17 +08:00
|
|
|
'star pixel detection': function(containerId) {
|
2012-06-16 02:47:55 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
|
|
|
|
var layer = new Kinetic.Layer({
|
|
|
|
rotationDeg: 20
|
|
|
|
});
|
2013-03-25 11:42:27 +08:00
|
|
|
var star = new Kinetic.Star({
|
2012-06-16 02:47:55 +08:00
|
|
|
x: 200,
|
|
|
|
y: 100,
|
|
|
|
numPoints: 10,
|
|
|
|
innerRadius: 40,
|
|
|
|
outerRadius: 70,
|
|
|
|
fill: 'green',
|
|
|
|
stroke: 'blue',
|
|
|
|
strokeWidth: 20,
|
|
|
|
draggable: true
|
|
|
|
});
|
|
|
|
|
|
|
|
star.on('mouseover', function() {
|
|
|
|
log('mouseover');
|
|
|
|
});
|
|
|
|
|
|
|
|
star.on('mouseout', function() {
|
|
|
|
log('mouseout');
|
|
|
|
});
|
|
|
|
|
|
|
|
layer.add(star);
|
|
|
|
stage.add(layer);
|
2012-09-26 12:23:35 +08:00
|
|
|
|
2012-11-28 11:43:33 +08:00
|
|
|
showHit(layer);
|
2012-06-16 02:47:55 +08:00
|
|
|
},
|
2013-01-28 08:27:17 +08:00
|
|
|
'drag events click': function(containerId) {
|
2012-06-16 02:47:55 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
2012-08-26 14:56:39 +08:00
|
|
|
var Circle = new Kinetic.Circle({
|
2012-06-16 02:47:55 +08:00
|
|
|
x: 380,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
|
|
|
strokeWidth: 4,
|
|
|
|
fill: 'red',
|
|
|
|
stroke: 'black'
|
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
Circle.setDraggable(true);
|
2012-06-16 02:47:55 +08:00
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
Circle.on('dragstart', function() {
|
2012-06-16 02:47:55 +08:00
|
|
|
log('dragstart');
|
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
Circle.on('dragmove', function() {
|
2012-06-16 02:47:55 +08:00
|
|
|
log('dragmove');
|
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
Circle.on('dragend', function() {
|
2012-06-16 02:47:55 +08:00
|
|
|
log('dragend');
|
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
Circle.on('click', function() {
|
2012-06-16 02:47:55 +08:00
|
|
|
log('click');
|
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
layer.add(Circle);
|
2012-06-16 02:47:55 +08:00
|
|
|
stage.add(layer);
|
|
|
|
},
|
2013-01-28 08:27:17 +08:00
|
|
|
'move mouse from shape to another shape in same layer': function(containerId) {
|
2012-06-16 02:47:55 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
var redCircle = new Kinetic.Circle({
|
2012-06-16 02:47:55 +08:00
|
|
|
x: 200,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
|
|
|
strokeWidth: 4,
|
|
|
|
fill: 'red',
|
|
|
|
stroke: 'black'
|
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
redCircle.on('mouseover', function() {
|
|
|
|
log('mouseover red Circle');
|
2012-06-16 02:47:55 +08:00
|
|
|
});
|
2012-08-26 14:56:39 +08:00
|
|
|
redCircle.on('mouseout', function() {
|
|
|
|
log('mouseout red Circle');
|
2012-06-16 02:47:55 +08:00
|
|
|
});
|
2012-08-26 14:56:39 +08:00
|
|
|
var greenCircle = new Kinetic.Circle({
|
2012-06-16 02:47:55 +08:00
|
|
|
x: 280,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
|
|
|
strokeWidth: 4,
|
|
|
|
fill: 'green',
|
|
|
|
stroke: 'black'
|
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
greenCircle.on('mouseover', function() {
|
|
|
|
log('mouseover green Circle');
|
2012-06-16 02:47:55 +08:00
|
|
|
});
|
2012-08-26 14:56:39 +08:00
|
|
|
greenCircle.on('mouseout', function() {
|
|
|
|
log('mouseout green Circle');
|
2012-06-16 02:47:55 +08:00
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
layer.add(redCircle);
|
|
|
|
layer.add(greenCircle);
|
2012-06-16 02:47:55 +08:00
|
|
|
|
|
|
|
stage.add(layer);
|
2012-09-26 12:23:35 +08:00
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
//greenCircle.hide();
|
2012-08-19 13:42:37 +08:00
|
|
|
layer.draw();
|
2012-09-26 12:23:35 +08:00
|
|
|
|
2012-08-19 13:42:37 +08:00
|
|
|
//document.body.appendChild(layer.bufferCanvas.element);
|
2012-06-16 02:47:55 +08:00
|
|
|
},
|
2013-01-28 08:27:17 +08:00
|
|
|
'move mouse from shape in one group to shape in another group': function(containerId) {
|
2012-06-16 02:47:55 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
|
|
|
var redGroup = new Kinetic.Group();
|
|
|
|
var greenGroup = new Kinetic.Group();
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
var redCircle = new Kinetic.Circle({
|
2012-06-16 02:47:55 +08:00
|
|
|
x: 200,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
|
|
|
strokeWidth: 4,
|
|
|
|
fill: 'red',
|
|
|
|
stroke: 'black'
|
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
redCircle.on('mouseover', function() {
|
|
|
|
log('mouseover red Circle');
|
2012-06-16 02:47:55 +08:00
|
|
|
});
|
2012-08-26 14:56:39 +08:00
|
|
|
redCircle.on('mouseout', function() {
|
|
|
|
log('mouseout red Circle');
|
2012-06-16 02:47:55 +08:00
|
|
|
});
|
2012-08-26 14:56:39 +08:00
|
|
|
var greenCircle = new Kinetic.Circle({
|
2012-06-16 02:47:55 +08:00
|
|
|
x: 280,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
|
|
|
strokeWidth: 4,
|
|
|
|
fill: 'green',
|
|
|
|
stroke: 'black'
|
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
greenCircle.on('mouseover', function() {
|
|
|
|
log('mouseover green Circle');
|
2012-06-16 02:47:55 +08:00
|
|
|
});
|
2012-08-26 14:56:39 +08:00
|
|
|
greenCircle.on('mouseout', function() {
|
|
|
|
log('mouseout green Circle');
|
2012-06-16 02:47:55 +08:00
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
redGroup.add(redCircle);
|
|
|
|
greenGroup.add(greenCircle);
|
2012-06-16 02:47:55 +08:00
|
|
|
|
|
|
|
layer.add(redGroup);
|
|
|
|
layer.add(greenGroup);
|
|
|
|
|
|
|
|
stage.add(layer);
|
|
|
|
},
|
2013-01-28 08:27:17 +08:00
|
|
|
'move mouse from shape in one layer to shape in another layer': function(containerId) {
|
2012-06-16 02:47:55 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var redLayer = new Kinetic.Layer();
|
|
|
|
var greenLayer = new Kinetic.Layer();
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
var redCircle = new Kinetic.Circle({
|
2012-06-16 02:47:55 +08:00
|
|
|
x: 200,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
|
|
|
strokeWidth: 4,
|
|
|
|
fill: 'red',
|
|
|
|
stroke: 'black'
|
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
redCircle.on('mouseover', function() {
|
|
|
|
log('mouseover red Circle');
|
2012-06-16 02:47:55 +08:00
|
|
|
});
|
2012-08-26 14:56:39 +08:00
|
|
|
redCircle.on('mouseout', function() {
|
|
|
|
log('mouseout red Circle');
|
2012-06-16 02:47:55 +08:00
|
|
|
});
|
2012-08-26 14:56:39 +08:00
|
|
|
var greenCircle = new Kinetic.Circle({
|
2012-06-16 02:47:55 +08:00
|
|
|
x: 280,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
|
|
|
strokeWidth: 4,
|
|
|
|
fill: 'green',
|
|
|
|
stroke: 'black'
|
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
greenCircle.on('mouseover', function() {
|
|
|
|
log('mouseover green Circle');
|
2012-06-16 02:47:55 +08:00
|
|
|
});
|
2012-08-26 14:56:39 +08:00
|
|
|
greenCircle.on('mouseout', function() {
|
|
|
|
log('mouseout green Circle');
|
2012-06-16 02:47:55 +08:00
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
redLayer.add(redCircle);
|
|
|
|
greenLayer.add(greenCircle);
|
2012-06-16 02:47:55 +08:00
|
|
|
|
|
|
|
stage.add(redLayer);
|
|
|
|
stage.add(greenLayer);
|
|
|
|
},
|
2013-01-28 08:27:17 +08:00
|
|
|
'mousemove from shape in one group to shape in another group': function(containerId) {
|
2012-06-16 02:47:55 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
|
|
|
var redGroup = new Kinetic.Group();
|
|
|
|
var greenGroup = new Kinetic.Group();
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
var redCircle = new Kinetic.Circle({
|
2012-06-16 02:47:55 +08:00
|
|
|
x: 200,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
|
|
|
strokeWidth: 4,
|
|
|
|
fill: 'red',
|
|
|
|
stroke: 'black'
|
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
redCircle.on('mousemove', function() {
|
|
|
|
log('mousemove red Circle');
|
2012-06-16 02:47:55 +08:00
|
|
|
});
|
2012-08-26 14:56:39 +08:00
|
|
|
var greenCircle = new Kinetic.Circle({
|
2012-06-16 02:47:55 +08:00
|
|
|
x: 280,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
|
|
|
strokeWidth: 4,
|
|
|
|
fill: 'green',
|
|
|
|
stroke: 'black'
|
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
greenCircle.on('mousemove', function() {
|
|
|
|
log('mousemove green Circle');
|
2012-06-16 02:47:55 +08:00
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
redGroup.add(redCircle);
|
|
|
|
greenGroup.add(greenCircle);
|
2012-06-16 02:47:55 +08:00
|
|
|
|
|
|
|
layer.add(redGroup);
|
|
|
|
layer.add(greenGroup);
|
|
|
|
|
|
|
|
stage.add(layer);
|
|
|
|
},
|
2013-01-28 08:27:17 +08:00
|
|
|
'group mousemove events': function(containerId) {
|
2012-06-16 02:47:55 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
|
|
|
var group = new Kinetic.Group();
|
|
|
|
|
|
|
|
group.on('mousemove', function() {
|
|
|
|
log('mousemove group');
|
|
|
|
//console.log(this);
|
|
|
|
});
|
2012-08-26 14:56:39 +08:00
|
|
|
var redCircle = new Kinetic.Circle({
|
2012-06-16 02:47:55 +08:00
|
|
|
x: stage.getWidth() / 2,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 80,
|
|
|
|
strokeWidth: 4,
|
|
|
|
fill: 'red',
|
|
|
|
stroke: 'black'
|
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
var greenCircle = new Kinetic.Circle({
|
2012-06-16 02:47:55 +08:00
|
|
|
x: stage.getWidth() / 2,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 40,
|
|
|
|
strokeWidth: 4,
|
|
|
|
fill: 'green',
|
|
|
|
stroke: 'black'
|
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
group.add(redCircle);
|
|
|
|
group.add(greenCircle);
|
2012-06-16 02:47:55 +08:00
|
|
|
|
|
|
|
layer.add(group);
|
|
|
|
stage.add(layer);
|
|
|
|
},
|
2013-01-28 08:27:17 +08:00
|
|
|
'cancel event bubbling (only the red Circle should fire click event)': function(containerId) {
|
2012-06-16 02:47:55 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
|
|
|
var group = new Kinetic.Group();
|
|
|
|
|
|
|
|
layer.on('click', function() {
|
|
|
|
log('click layer');
|
|
|
|
//console.log(this);
|
|
|
|
});
|
|
|
|
group.on('click', function() {
|
|
|
|
log('click group');
|
|
|
|
//console.log(this);
|
|
|
|
});
|
2012-08-26 14:56:39 +08:00
|
|
|
var redCircle = new Kinetic.Circle({
|
2012-06-16 02:47:55 +08:00
|
|
|
x: stage.getWidth() / 2,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 80,
|
|
|
|
strokeWidth: 4,
|
|
|
|
fill: 'red',
|
|
|
|
stroke: 'black'
|
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
redCircle.on('click', function(evt) {
|
|
|
|
log('click red Circle');
|
2012-06-16 02:47:55 +08:00
|
|
|
evt.cancelBubble = true;
|
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
group.add(redCircle);
|
2012-06-16 02:47:55 +08:00
|
|
|
layer.add(group);
|
|
|
|
stage.add(layer);
|
|
|
|
},
|
2013-01-28 08:27:17 +08:00
|
|
|
'get currentTarget': function(containerId) {
|
2012-06-16 02:47:55 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
|
|
|
var group = new Kinetic.Group();
|
|
|
|
|
|
|
|
layer.on('click', function(evt) {
|
|
|
|
log(evt.shape.getName());
|
|
|
|
|
|
|
|
});
|
2012-08-26 14:56:39 +08:00
|
|
|
var redCircle = new Kinetic.Circle({
|
2012-06-16 02:47:55 +08:00
|
|
|
x: stage.getWidth() / 2,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 80,
|
|
|
|
strokeWidth: 4,
|
|
|
|
fill: 'red',
|
|
|
|
stroke: 'black',
|
2012-08-26 14:56:39 +08:00
|
|
|
name: 'Circle'
|
2012-06-16 02:47:55 +08:00
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
group.add(redCircle);
|
2012-06-16 02:47:55 +08:00
|
|
|
layer.add(group);
|
|
|
|
stage.add(layer);
|
|
|
|
},
|
2013-01-28 08:27:17 +08:00
|
|
|
'shape mouseout handlers when mouse leaves stage': function(containerId) {
|
2012-06-16 02:47:55 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
var redCircle = new Kinetic.Circle({
|
2012-06-16 02:47:55 +08:00
|
|
|
x: 550,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 80,
|
|
|
|
strokeWidth: 4,
|
|
|
|
fill: 'red',
|
|
|
|
stroke: 'black',
|
2012-08-26 14:56:39 +08:00
|
|
|
name: 'Circle'
|
2012-06-16 02:47:55 +08:00
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
redCircle.on('mouseout', function() {
|
2012-06-16 02:47:55 +08:00
|
|
|
log('mouseout');
|
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
layer.add(redCircle);
|
2012-06-16 02:47:55 +08:00
|
|
|
stage.add(layer);
|
2013-01-28 08:27:17 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Test.Modules.DRAG_AND_DROP = {
|
|
|
|
'drag and drop elastic star with shadow': function(containerId) {
|
2012-06-16 02:47:55 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
|
|
|
|
2013-03-25 11:42:27 +08:00
|
|
|
var star = new Kinetic.Star({
|
2012-06-16 02:47:55 +08:00
|
|
|
x: 200,
|
|
|
|
y: 100,
|
|
|
|
numPoints: 5,
|
|
|
|
innerRadius: 40,
|
|
|
|
outerRadius: 70,
|
|
|
|
fill: 'green',
|
|
|
|
stroke: 'blue',
|
|
|
|
strokeWidth: 5,
|
|
|
|
lineJoin: "round",
|
2013-01-01 04:45:32 +08:00
|
|
|
shadowColor: '#aaa',
|
|
|
|
shadowBlur: 10,
|
|
|
|
shadowOffset: {
|
2013-01-28 08:27:17 +08:00
|
|
|
x: 5,
|
2013-01-01 04:45:32 +08:00
|
|
|
y: 5
|
2012-06-16 02:47:55 +08:00
|
|
|
},
|
2013-01-14 03:10:49 +08:00
|
|
|
draggable: true,
|
|
|
|
name: 'star'
|
2012-06-16 02:47:55 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
layer.add(star);
|
|
|
|
stage.add(layer);
|
|
|
|
star.setLineJoin('bevel');
|
|
|
|
layer.draw();
|
|
|
|
|
|
|
|
var trans = null;
|
2013-01-28 08:27:17 +08:00
|
|
|
/*
|
|
|
|
star.on('dragstart', function() {
|
|
|
|
if(trans) {
|
|
|
|
trans.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
star.setAttrs({
|
|
|
|
shadow: {
|
|
|
|
offset: {
|
|
|
|
x: 15,
|
|
|
|
y: 15
|
|
|
|
}
|
|
|
|
},
|
|
|
|
offset: {
|
|
|
|
x: 10,
|
|
|
|
y: 10
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2012-06-16 02:47:55 +08:00
|
|
|
|
2013-01-28 08:27:17 +08:00
|
|
|
star.on('dragend', function() {
|
|
|
|
trans = star.transitionTo({
|
|
|
|
duration: 0.5,
|
|
|
|
easing: 'elastic-ease-out',
|
|
|
|
shadow: {
|
|
|
|
offset: {
|
|
|
|
x: 5,
|
|
|
|
y: 5
|
|
|
|
}
|
|
|
|
},
|
|
|
|
offset: {
|
|
|
|
x: 0,
|
|
|
|
y: 0
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
*/
|
2012-06-16 02:47:55 +08:00
|
|
|
|
2012-11-19 11:50:50 +08:00
|
|
|
showHit(layer);
|
2012-06-16 02:47:55 +08:00
|
|
|
},
|
2013-01-28 08:27:17 +08:00
|
|
|
'two draggable shapes': function(containerId) {
|
2012-06-16 02:47:55 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
2012-08-26 14:56:39 +08:00
|
|
|
var Circle = new Kinetic.Circle({
|
2012-06-16 02:47:55 +08:00
|
|
|
x: stage.getWidth() / 2,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
|
|
|
fill: 'red',
|
|
|
|
stroke: 'black',
|
|
|
|
strokeWidth: 4,
|
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
Circle.setDraggable(true);
|
2012-06-16 02:47:55 +08:00
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
var Circle2 = new Kinetic.Circle({
|
2012-06-16 02:47:55 +08:00
|
|
|
x: 350,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
|
|
|
fill: 'green',
|
|
|
|
stroke: 'black',
|
|
|
|
strokeWidth: 4,
|
|
|
|
draggable: true
|
|
|
|
});
|
|
|
|
|
|
|
|
/*
|
2012-08-26 14:56:39 +08:00
|
|
|
Circle.on('dragend', function() {
|
|
|
|
Circle.savePixels();
|
2012-06-16 02:47:55 +08:00
|
|
|
});
|
|
|
|
*/
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
layer.add(Circle).add(Circle2);
|
2012-06-16 02:47:55 +08:00
|
|
|
stage.add(layer);
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
//Circle.savePixels();
|
2012-06-16 02:47:55 +08:00
|
|
|
},
|
2013-03-25 07:40:09 +08:00
|
|
|
'drag and drop stage': function(containerId) {
|
2012-06-16 02:47:55 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200,
|
2012-11-18 14:29:07 +08:00
|
|
|
draggable: true
|
2012-06-16 02:47:55 +08:00
|
|
|
});
|
2012-11-18 14:29:07 +08:00
|
|
|
var layer = new Kinetic.Layer();
|
2012-08-26 14:56:39 +08:00
|
|
|
var Circle = new Kinetic.Circle({
|
2012-06-16 02:47:55 +08:00
|
|
|
x: stage.getWidth() / 2,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
|
|
|
fill: 'red',
|
|
|
|
stroke: 'black',
|
2012-11-18 14:29:07 +08:00
|
|
|
strokeWidth: 4
|
2012-06-16 02:47:55 +08:00
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
layer.add(Circle);
|
2012-06-16 02:47:55 +08:00
|
|
|
stage.add(layer);
|
2013-01-28 08:27:17 +08:00
|
|
|
|
2012-11-19 11:50:50 +08:00
|
|
|
showHit(layer)
|
2012-06-16 02:47:55 +08:00
|
|
|
},
|
2013-01-29 13:27:08 +08:00
|
|
|
'draggable true': function(containerId) {
|
2012-06-16 02:47:55 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
2013-01-29 13:27:08 +08:00
|
|
|
var layer = new Kinetic.Layer({
|
|
|
|
id: 'myLayer'
|
|
|
|
});
|
|
|
|
var circle = new Kinetic.Circle({
|
2012-06-16 02:47:55 +08:00
|
|
|
x: stage.getWidth() / 2,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
|
|
|
fill: 'red',
|
|
|
|
stroke: 'black',
|
|
|
|
strokeWidth: 4
|
|
|
|
});
|
|
|
|
|
2013-01-29 13:27:08 +08:00
|
|
|
circle.setDraggable(true);
|
2012-06-16 02:47:55 +08:00
|
|
|
|
2013-01-29 13:27:08 +08:00
|
|
|
layer.add(circle);
|
2012-06-16 02:47:55 +08:00
|
|
|
stage.add(layer);
|
2013-01-29 13:27:08 +08:00
|
|
|
|
|
|
|
circle.on('dragmove', function() {
|
|
|
|
console.log(this.getLayer().getId());
|
|
|
|
});
|
2012-06-16 02:47:55 +08:00
|
|
|
|
|
|
|
},
|
2013-01-28 08:27:17 +08:00
|
|
|
'scale and rotate stage after add layer then drag and drop shape': function(containerId) {
|
2012-06-16 02:47:55 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
|
|
|
var rect = new Kinetic.Rect({
|
|
|
|
x: 200,
|
|
|
|
y: 20,
|
|
|
|
width: 100,
|
|
|
|
height: 50,
|
|
|
|
fill: 'red',
|
|
|
|
stroke: 'black',
|
|
|
|
strokeWidth: 4,
|
|
|
|
draggable: true
|
|
|
|
//rotationDeg: 60
|
|
|
|
//rotationDeg: Math.PI / 3
|
|
|
|
});
|
|
|
|
|
|
|
|
layer.add(rect);
|
|
|
|
stage.add(layer);
|
|
|
|
|
|
|
|
//stage.rotateDeg(20);
|
|
|
|
|
|
|
|
//console.log(rect.getAbsoluteTransform().getTranslation())
|
|
|
|
|
|
|
|
stage.rotate(Math.PI / 3);
|
|
|
|
stage.setScale(0.5);
|
|
|
|
|
|
|
|
stage.draw();
|
|
|
|
},
|
2013-01-28 08:27:17 +08:00
|
|
|
'scale stage before add shape then drag and drop shape': function(containerId) {
|
2012-06-16 02:47:55 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
2012-08-26 14:56:39 +08:00
|
|
|
var Circle = new Kinetic.Circle({
|
2012-06-16 02:47:55 +08:00
|
|
|
x: stage.getWidth() / 2,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
|
|
|
fill: 'red',
|
|
|
|
stroke: 'black',
|
|
|
|
strokeWidth: 4
|
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
Circle.setDraggable(true);
|
2012-06-16 02:47:55 +08:00
|
|
|
|
|
|
|
stage.setScale(0.5);
|
2012-08-26 14:56:39 +08:00
|
|
|
layer.add(Circle);
|
2012-06-16 02:47:55 +08:00
|
|
|
stage.add(layer);
|
|
|
|
},
|
2013-01-28 08:27:17 +08:00
|
|
|
'set stage scale to 1.5 after add layer then drag and drop shape': function(containerId) {
|
2012-06-16 02:47:55 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
2012-08-26 14:56:39 +08:00
|
|
|
var Circle = new Kinetic.Circle({
|
2012-06-16 02:47:55 +08:00
|
|
|
x: stage.getWidth() / 2,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
|
|
|
fill: 'red',
|
|
|
|
stroke: 'black',
|
|
|
|
strokeWidth: 4
|
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
Circle.setDraggable(true);
|
2012-06-16 02:47:55 +08:00
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
layer.add(Circle);
|
2012-06-16 02:47:55 +08:00
|
|
|
stage.add(layer);
|
|
|
|
|
|
|
|
stage.setScale(1.5);
|
|
|
|
|
|
|
|
stage.draw();
|
|
|
|
},
|
2013-01-28 08:27:17 +08:00
|
|
|
'drag bound function': function(containerId) {
|
2012-09-26 12:23:35 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
|
|
|
var rectHeight = 50;
|
|
|
|
var rectWidth = 100;
|
|
|
|
var rectY = (stage.getHeight() - rectHeight) / 2;
|
|
|
|
|
|
|
|
var hbox = new Kinetic.Text({
|
|
|
|
x: 380,
|
|
|
|
y: 70,
|
|
|
|
fontSize: 18,
|
|
|
|
fontFamily: "Calibri",
|
|
|
|
text: "shiftKey",
|
2013-01-01 04:45:32 +08:00
|
|
|
fill: "black",
|
2012-09-26 12:23:35 +08:00
|
|
|
padding: 15,
|
|
|
|
draggable: true,
|
|
|
|
dragBoundFunc: function(pos, evt) {
|
|
|
|
var newPos = pos;
|
|
|
|
if(evt.shiftKey) {
|
|
|
|
newPos.x = Math.round(pos.x / 20) * 20;
|
|
|
|
newPos.y = Math.round(pos.y / 20) * 20;
|
|
|
|
}
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var vbox = new Kinetic.Text({
|
|
|
|
x: 70,
|
|
|
|
y: 70,
|
|
|
|
draggable: true,
|
|
|
|
fontSize: 18,
|
|
|
|
fontFamily: "Calibri",
|
|
|
|
text: "diagonal",
|
2013-01-01 04:45:32 +08:00
|
|
|
fill: "black",
|
2012-09-26 12:23:35 +08:00
|
|
|
padding: 15,
|
|
|
|
draggable: true,
|
|
|
|
dragBoundFunc: function(pos) {
|
|
|
|
p = (pos.y + pos.x) / 2;
|
|
|
|
return {
|
|
|
|
y: p,
|
|
|
|
x: p
|
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var circle = new Kinetic.Circle({
|
|
|
|
x: 280,
|
|
|
|
y: 45,
|
|
|
|
radius: 50,
|
|
|
|
fill: "red",
|
|
|
|
strokeWidth: 4,
|
|
|
|
draggable: true,
|
|
|
|
fontSize: 18,
|
|
|
|
draggable: true,
|
|
|
|
dragBoundFunc: function(pos) {
|
|
|
|
var circle = {
|
|
|
|
x: 280,
|
|
|
|
y: 95,
|
|
|
|
r: 50
|
|
|
|
};
|
|
|
|
var scale = circle.r / Math.sqrt(Math.pow(pos.x - circle.x, 2) + Math.pow(pos.y - circle.y, 2));
|
|
|
|
if(scale < 1)
|
|
|
|
return {
|
|
|
|
y: Math.round((pos.y - circle.y) * scale + circle.y),
|
|
|
|
x: Math.round((pos.x - circle.x) * scale + circle.x)
|
|
|
|
};
|
|
|
|
else
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
layer.add(hbox);
|
|
|
|
layer.add(vbox);
|
|
|
|
layer.add(circle);
|
|
|
|
stage.add(layer);
|
|
|
|
},
|
2013-01-28 08:27:17 +08:00
|
|
|
'set stage scale to 1.5 before add layer then drag and drop shape': function(containerId) {
|
2012-06-16 02:47:55 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
2012-08-26 14:56:39 +08:00
|
|
|
var Circle = new Kinetic.Circle({
|
2012-06-16 02:47:55 +08:00
|
|
|
x: stage.getWidth() / 2,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
|
|
|
fill: 'red',
|
|
|
|
stroke: 'black',
|
|
|
|
strokeWidth: 4
|
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
Circle.setDraggable(true);
|
2012-06-16 02:47:55 +08:00
|
|
|
|
|
|
|
stage.setScale(1.5);
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
layer.add(Circle);
|
2012-06-16 02:47:55 +08:00
|
|
|
stage.add(layer);
|
|
|
|
},
|
2013-01-28 08:27:17 +08:00
|
|
|
'check that green events are ignored when dragging red Circle': function(containerId) {
|
2012-06-16 02:47:55 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
2012-08-26 14:56:39 +08:00
|
|
|
var Circle1 = new Kinetic.Circle({
|
2012-06-16 02:47:55 +08:00
|
|
|
x: stage.getWidth() / 2,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
|
|
|
fill: 'red',
|
|
|
|
stroke: 'black',
|
|
|
|
strokeWidth: 4
|
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
var Circle2 = new Kinetic.Circle({
|
2012-06-16 02:47:55 +08:00
|
|
|
x: stage.getWidth() / 2 + 50,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
|
|
|
fill: 'green',
|
|
|
|
stroke: 'black',
|
|
|
|
strokeWidth: 4
|
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
Circle1.setDraggable(true);
|
2012-06-16 02:47:55 +08:00
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
Circle2.on('mouseover', function() {
|
|
|
|
log('mouseover green Circle');
|
2012-06-16 02:47:55 +08:00
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
layer.add(Circle1);
|
|
|
|
layer.add(Circle2);
|
2012-06-16 02:47:55 +08:00
|
|
|
stage.add(layer);
|
|
|
|
},
|
2013-01-28 08:27:17 +08:00
|
|
|
'drag and drop constrianed horizontally inside positioned group': function(containerId) {
|
2012-06-16 02:47:55 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
|
|
|
var group = new Kinetic.Group({
|
|
|
|
x: 0,
|
|
|
|
y: 10
|
|
|
|
});
|
2012-08-26 14:56:39 +08:00
|
|
|
var Circle = new Kinetic.Circle({
|
2012-09-26 12:23:35 +08:00
|
|
|
x: 200,
|
|
|
|
y: 100,
|
2012-06-16 02:47:55 +08:00
|
|
|
radius: 70,
|
|
|
|
fill: 'red',
|
|
|
|
stroke: 'black',
|
|
|
|
strokeWidth: 4,
|
|
|
|
draggable: true,
|
2012-09-26 12:23:35 +08:00
|
|
|
dragBoundFunc: function(pos) {
|
2013-01-28 08:27:17 +08:00
|
|
|
return {
|
|
|
|
x: pos.x,
|
|
|
|
y: this.getAbsolutePosition().y
|
|
|
|
};
|
2012-09-26 12:23:35 +08:00
|
|
|
}
|
2012-06-16 02:47:55 +08:00
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
group.add(Circle);
|
2012-06-16 02:47:55 +08:00
|
|
|
layer.add(group);
|
|
|
|
stage.add(layer);
|
|
|
|
},
|
2013-01-28 08:27:17 +08:00
|
|
|
'drag and drop with left bounds': function(containerId) {
|
2012-06-16 02:47:55 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
2012-08-26 14:56:39 +08:00
|
|
|
var Circle = new Kinetic.Circle({
|
2012-06-16 02:47:55 +08:00
|
|
|
x: stage.getWidth() / 2,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
|
|
|
fill: 'red',
|
|
|
|
stroke: 'black',
|
|
|
|
strokeWidth: 4,
|
|
|
|
draggable: true,
|
2012-09-26 12:23:35 +08:00
|
|
|
dragBoundFunc: function(pos) {
|
2013-01-28 08:27:17 +08:00
|
|
|
var newX = pos.x > 50 ? pos.x : 50;
|
|
|
|
return {
|
|
|
|
x: newX,
|
|
|
|
y: this.getY()
|
|
|
|
}
|
2012-06-16 02:47:55 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
layer.add(Circle);
|
2012-06-16 02:47:55 +08:00
|
|
|
stage.add(layer);
|
|
|
|
},
|
2013-01-28 08:27:17 +08:00
|
|
|
'drag and drop shape inside scrollable div': function(containerId) {
|
2012-06-16 02:47:55 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 400
|
|
|
|
});
|
|
|
|
|
|
|
|
// make container scrollable
|
|
|
|
var container = stage.getContainer();
|
|
|
|
container.style.overflow = 'auto';
|
|
|
|
|
|
|
|
var layer = new Kinetic.Layer();
|
2012-08-26 14:56:39 +08:00
|
|
|
var Circle = new Kinetic.Circle({
|
2012-06-16 02:47:55 +08:00
|
|
|
x: stage.getWidth() / 2,
|
|
|
|
y: 100,
|
|
|
|
radius: 50,
|
|
|
|
fill: 'blue',
|
|
|
|
stroke: 'black',
|
|
|
|
strokeWidth: 4,
|
|
|
|
draggable: true
|
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
layer.add(Circle);
|
2012-06-16 02:47:55 +08:00
|
|
|
stage.add(layer);
|
|
|
|
},
|
2013-01-28 08:27:17 +08:00
|
|
|
'drag and drop shape inside scaled group': function(containerId) {
|
2012-06-16 02:47:55 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
|
|
|
var group = new Kinetic.Group({
|
|
|
|
scale: {
|
|
|
|
x: 2,
|
|
|
|
y: 2
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
var Circle = new Kinetic.Circle({
|
2012-06-16 02:47:55 +08:00
|
|
|
x: 40,
|
|
|
|
y: 40,
|
|
|
|
radius: 70,
|
|
|
|
fill: 'red',
|
|
|
|
stroke: 'black',
|
|
|
|
strokeWidth: 4,
|
|
|
|
draggable: true
|
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
group.add(Circle);
|
2012-06-16 02:47:55 +08:00
|
|
|
layer.add(group);
|
|
|
|
stage.add(layer);
|
|
|
|
},
|
2013-01-28 08:27:17 +08:00
|
|
|
'translate, rotate, and scale shape, and then drag and drop': function(containerId) {
|
2012-06-16 02:47:55 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
|
|
|
var group = new Kinetic.Group();
|
|
|
|
|
|
|
|
var rect = new Kinetic.Rect({
|
|
|
|
x: 200,
|
|
|
|
y: 100,
|
|
|
|
width: 100,
|
|
|
|
height: 50,
|
|
|
|
fill: 'red',
|
|
|
|
stroke: 'black',
|
|
|
|
strokeWidth: 4,
|
|
|
|
draggable: true,
|
|
|
|
rotationDeg: 60,
|
|
|
|
scale: {
|
|
|
|
x: 2,
|
|
|
|
y: 1
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
group.add(rect);
|
|
|
|
layer.add(group);
|
|
|
|
stage.add(layer);
|
|
|
|
},
|
2013-03-14 13:24:55 +08:00
|
|
|
'translate, rotate, center offset, and scale shape, and then drag and drop': function(containerId) {
|
2012-06-16 02:47:55 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
2013-02-13 01:58:47 +08:00
|
|
|
|
|
|
|
var bgLayer = new Kinetic.Layer();
|
2012-06-16 02:47:55 +08:00
|
|
|
var layer = new Kinetic.Layer();
|
|
|
|
var group = new Kinetic.Group();
|
|
|
|
|
|
|
|
var rect = new Kinetic.Rect({
|
|
|
|
x: 200,
|
|
|
|
y: 100,
|
|
|
|
width: 100,
|
|
|
|
height: 50,
|
|
|
|
fill: 'red',
|
|
|
|
stroke: 'black',
|
|
|
|
strokeWidth: 4,
|
|
|
|
draggable: true,
|
|
|
|
rotationDeg: 60,
|
|
|
|
scale: {
|
|
|
|
x: 2,
|
|
|
|
y: 1
|
|
|
|
},
|
|
|
|
offset: {
|
|
|
|
x: 50,
|
|
|
|
y: 25
|
2013-01-28 13:29:22 +08:00
|
|
|
},
|
|
|
|
dragOnTop: true
|
2012-06-16 02:47:55 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
group.add(rect);
|
|
|
|
layer.add(group);
|
2013-02-13 01:58:47 +08:00
|
|
|
|
|
|
|
stage.add(bgLayer);
|
2012-06-16 02:47:55 +08:00
|
|
|
stage.add(layer);
|
|
|
|
|
2012-11-16 13:30:58 +08:00
|
|
|
var anim = new Kinetic.Animation(function() {
|
2013-01-28 08:27:17 +08:00
|
|
|
rect.rotate(0.01);
|
|
|
|
}, layer);
|
2012-08-04 15:23:56 +08:00
|
|
|
anim.start();
|
2013-02-12 16:20:24 +08:00
|
|
|
|
|
|
|
showHit(layer);
|
2013-02-13 01:58:47 +08:00
|
|
|
|
|
|
|
var context = bgLayer.getCanvas().getContext();
|
|
|
|
context.beginPath();
|
|
|
|
context.moveTo(0, 0);
|
|
|
|
context.lineTo(100, 20);
|
|
|
|
context.strokeStyle = 'red';
|
|
|
|
context.stroke();
|
2013-01-28 13:29:22 +08:00
|
|
|
},
|
|
|
|
'stage and shape draggable': function(containerId) {
|
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
2013-03-25 09:17:58 +08:00
|
|
|
draggable: true,
|
2013-01-28 13:29:22 +08:00
|
|
|
width: 578,
|
2013-03-25 09:17:58 +08:00
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer({
|
|
|
|
draggable: true
|
2013-01-28 13:29:22 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
var rect = new Kinetic.Rect({
|
|
|
|
x: 150,
|
|
|
|
y: 100,
|
|
|
|
width: 100,
|
|
|
|
height: 50,
|
|
|
|
fill: 'red',
|
|
|
|
stroke: 'black',
|
2013-03-25 09:17:58 +08:00
|
|
|
strokeWidth: 4
|
2013-01-28 13:29:22 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
var rect2 = new Kinetic.Rect({
|
|
|
|
x: 300,
|
|
|
|
y: 100,
|
|
|
|
width: 100,
|
|
|
|
height: 50,
|
|
|
|
fill: 'yellow',
|
|
|
|
stroke: 'black',
|
|
|
|
strokeWidth: 4,
|
|
|
|
draggable: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
layer.add(rect).add(rect2);
|
|
|
|
stage.add(layer);
|
|
|
|
|
|
|
|
|
2012-06-16 02:47:55 +08:00
|
|
|
}
|
|
|
|
};
|