2012-11-14 13:37:28 +08:00
|
|
|
Test.Modules.LAYER = {
|
2013-02-16 07:18:02 +08:00
|
|
|
'test canvas inline styles': function(containerId) {
|
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
|
|
|
|
var layer = new Kinetic.Layer();
|
|
|
|
|
|
|
|
var circle = new Kinetic.Circle({
|
|
|
|
x: 100,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
|
|
|
fill: 'green',
|
|
|
|
stroke: 'black',
|
|
|
|
strokeWidth: 4
|
|
|
|
});
|
|
|
|
|
|
|
|
layer.add(circle);
|
|
|
|
stage.add(layer);
|
|
|
|
|
|
|
|
var style = layer.getCanvas().getElement().style;
|
|
|
|
|
|
|
|
test(style.position === 'absolute', 'canvas position style should be absolute');
|
|
|
|
test(style.border === '0px', 'canvas border style should be 0px');
|
|
|
|
test(style.margin === '0px', 'canvas margin style should be 0px');
|
|
|
|
test(style.padding === '0px', 'canvas padding style should be 0px');
|
|
|
|
test(style.backgroundColor === 'transparent', 'canvas backgroundColor style should be transparent');
|
2013-04-12 15:48:41 +08:00
|
|
|
},
|
|
|
|
|
2013-04-12 14:51:21 +08:00
|
|
|
'layer getIntersections()': function(containerId) {
|
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200,
|
|
|
|
throttle: 999
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
|
|
|
|
|
|
|
var redCircle = new Kinetic.Circle({
|
|
|
|
x: 380,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
|
|
|
strokeWidth: 4,
|
|
|
|
fill: 'red',
|
|
|
|
stroke: 'black',
|
|
|
|
id: 'redCircle'
|
|
|
|
});
|
|
|
|
|
|
|
|
var greenCircle = new Kinetic.Circle({
|
|
|
|
x: 300,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
|
|
|
strokeWidth: 4,
|
|
|
|
fill: 'green',
|
|
|
|
stroke: 'black',
|
|
|
|
id: 'greenCircle'
|
|
|
|
});
|
|
|
|
|
|
|
|
layer.add(redCircle);
|
|
|
|
layer.add(greenCircle);
|
|
|
|
stage.add(layer);
|
|
|
|
|
|
|
|
test(layer.getIntersection(300, 100).shape.getId() === 'greenCircle', 'shape should be greenCircle');
|
|
|
|
test(layer.getIntersection(380, 100).shape.getId() === 'redCircle', 'shape should be redCircle');
|
|
|
|
test(layer.getIntersection(100, 100) === null, 'shape should be null');
|
|
|
|
|
|
|
|
|
2013-02-16 07:18:02 +08:00
|
|
|
},
|
2013-04-05 14:17:20 +08:00
|
|
|
'redraw hit graph': function(containerId) {
|
2012-11-14 13:37:28 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
2013-04-05 14:17:20 +08:00
|
|
|
var rect = new Kinetic.Rect({
|
|
|
|
x: 200,
|
|
|
|
width: 100,
|
|
|
|
height: 50,
|
2012-11-14 13:37:28 +08:00
|
|
|
fill: 'green',
|
|
|
|
stroke: 'black',
|
2013-04-05 14:17:20 +08:00
|
|
|
strokeWidth: 4,
|
|
|
|
scale: [3, 1],
|
|
|
|
draggable: true,
|
|
|
|
strokeScaleEnabled: false
|
2012-11-14 13:37:28 +08:00
|
|
|
});
|
|
|
|
|
2013-04-05 14:17:20 +08:00
|
|
|
rect.colorKey = '000000';
|
|
|
|
|
|
|
|
layer.add(rect);
|
2012-11-14 13:37:28 +08:00
|
|
|
stage.add(layer);
|
|
|
|
|
2013-04-05 14:17:20 +08:00
|
|
|
rect.setY(100);
|
|
|
|
layer.drawHit();
|
2012-11-14 13:37:28 +08:00
|
|
|
|
2013-04-05 14:17:20 +08:00
|
|
|
showHit(layer);
|
2012-11-14 13:37:28 +08:00
|
|
|
|
2013-04-05 14:17:20 +08:00
|
|
|
testDataUrl(layer.hitCanvas.toDataURL(), 'black rect hit graph', 'redrawn hitgraph data url is incorrect');
|
2012-11-14 13:37:28 +08:00
|
|
|
|
|
|
|
},
|
2013-04-05 14:17:20 +08:00
|
|
|
|
2012-11-14 13:37:28 +08:00
|
|
|
'set clearBeforeDraw to false, and test toDataURL for stage, layer, group, and shape': function(containerId) {
|
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
|
|
|
|
var layer = new Kinetic.Layer({
|
|
|
|
clearBeforeDraw: false,
|
|
|
|
throttle: 999
|
|
|
|
});
|
|
|
|
|
|
|
|
var group = new Kinetic.Group();
|
|
|
|
|
|
|
|
var circle = new Kinetic.Circle({
|
|
|
|
x: 100,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
|
|
|
fill: 'green',
|
|
|
|
stroke: 'black',
|
|
|
|
strokeWidth: 4
|
|
|
|
});
|
|
|
|
|
|
|
|
group.add(circle);
|
|
|
|
layer.add(group);
|
|
|
|
stage.add(layer);
|
|
|
|
|
|
|
|
for(var n = 0; n < 20; n++) {
|
|
|
|
circle.move(10, 0);
|
|
|
|
layer.draw();
|
|
|
|
}
|
|
|
|
|
|
|
|
//console.log(layer.toDataURL());
|
|
|
|
|
|
|
|
stage.toDataURL({
|
|
|
|
callback: function(dataUrl) {
|
|
|
|
warn(dataUrls['stacked green circles'] === dataUrl, 'stacked green circles stage data url is incorrect');
|
|
|
|
}
|
|
|
|
});
|
2013-03-25 04:32:52 +08:00
|
|
|
|
2012-11-14 13:37:28 +08:00
|
|
|
warn(dataUrls['stacked green circles'] === layer.toDataURL(), 'stacked green circles layer data url is incorrect');
|
|
|
|
|
2013-01-28 08:27:17 +08:00
|
|
|
},
|
|
|
|
'save layer as png (click on Circle to open new window)': function(containerId) {
|
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
|
|
|
|
|
|
|
var Circle = new Kinetic.Circle({
|
|
|
|
x: stage.getWidth() / 2,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
|
|
|
fill: 'violet',
|
|
|
|
stroke: 'black',
|
|
|
|
strokeWidth: 4
|
|
|
|
});
|
|
|
|
|
|
|
|
Circle.on('click', function() {
|
|
|
|
window.open(layer.toDataURL());
|
|
|
|
});
|
|
|
|
|
|
|
|
layer.add(Circle);
|
|
|
|
stage.add(layer);
|
|
|
|
},
|
|
|
|
'save layer as low quality jpg (click on Circle to open new window)': function(containerId) {
|
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
|
|
|
|
|
|
|
var circle = new Kinetic.Circle({
|
|
|
|
x: stage.getWidth() / 2,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
|
|
|
fill: 'violet',
|
|
|
|
stroke: 'black',
|
|
|
|
strokeWidth: 4
|
|
|
|
});
|
|
|
|
|
|
|
|
circle.on('click', function() {
|
|
|
|
window.open(layer.toDataURL({
|
|
|
|
mimeType: 'image/jpeg',
|
|
|
|
quality: 0.2
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
layer.add(circle);
|
|
|
|
stage.add(layer);
|
|
|
|
},
|
|
|
|
'save layer as high quality jpg (click on Circle to open new window)': function(containerId) {
|
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
|
|
|
|
|
|
|
var circle = new Kinetic.Circle({
|
|
|
|
x: stage.getWidth() / 2,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
|
|
|
fill: 'violet',
|
|
|
|
stroke: 'black',
|
|
|
|
strokeWidth: 4
|
|
|
|
});
|
|
|
|
|
|
|
|
circle.on('click', function() {
|
|
|
|
window.open(layer.toDataURL({
|
|
|
|
mimeType: 'image/jpeg',
|
|
|
|
quality: 1
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
layer.add(circle);
|
|
|
|
stage.add(layer);
|
2012-11-14 13:37:28 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|