mirror of
https://github.com/konvajs/konva.git
synced 2025-12-03 12:13:55 +08:00
clipping regions now work correctly when device pixel ratio != 1
This commit is contained in:
@@ -56,6 +56,8 @@ module.exports = function(grunt) {
|
|||||||
'tests/js/unit/layerTests.js',
|
'tests/js/unit/layerTests.js',
|
||||||
'tests/js/unit/shapeTests.js',
|
'tests/js/unit/shapeTests.js',
|
||||||
'tests/js/unit/ddTests.js',
|
'tests/js/unit/ddTests.js',
|
||||||
|
'tests/js/unit/canvasTests.js',
|
||||||
|
|
||||||
'tests/js/unit/shapes/rectTests.js',
|
'tests/js/unit/shapes/rectTests.js',
|
||||||
'tests/js/unit/shapes/circleTests.js',
|
'tests/js/unit/shapes/circleTests.js',
|
||||||
'tests/js/unit/shapes/ellipseTests.js',
|
'tests/js/unit/shapes/ellipseTests.js',
|
||||||
|
|||||||
@@ -46,6 +46,12 @@
|
|||||||
this.context = this.element.getContext(contextType);
|
this.context = this.element.getContext(contextType);
|
||||||
this.setSize(width, height);
|
this.setSize(width, height);
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* reset canvas context transform
|
||||||
|
*/
|
||||||
|
reset: function() {
|
||||||
|
this.getContext().setTransform(1 * _pixelRatio, 0, 0, 1 * _pixelRatio, 0, 0);
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* get canvas element
|
* get canvas element
|
||||||
* @method
|
* @method
|
||||||
@@ -241,7 +247,9 @@
|
|||||||
context.beginPath();
|
context.beginPath();
|
||||||
context.rect(clipX, clipY, clipWidth, clipHeight);
|
context.rect(clipX, clipY, clipWidth, clipHeight);
|
||||||
context.clip();
|
context.clip();
|
||||||
context.setTransform(1, 0, 0, 1, 0, 0);
|
this.reset();
|
||||||
|
container._drawChildren(this);
|
||||||
|
context.restore();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -255,21 +255,21 @@
|
|||||||
if (clip) {
|
if (clip) {
|
||||||
canvas._clip(this);
|
canvas._clip(this);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
children = this.children;
|
this._drawChildren(canvas);
|
||||||
len = children.length;
|
|
||||||
|
|
||||||
for(n = 0; n < len; n++) {
|
|
||||||
children[n].drawScene(canvas);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (clip) {
|
|
||||||
canvas.getContext().restore();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
_drawChildren: function(canvas) {
|
||||||
|
var children = this.children;
|
||||||
|
len = children.length;
|
||||||
|
|
||||||
|
for(n = 0; n < len; n++) {
|
||||||
|
children[n].drawScene(canvas);
|
||||||
|
}
|
||||||
|
},
|
||||||
drawHit: function() {
|
drawHit: function() {
|
||||||
var clip = this.getClipWidth() && this.getClipHeight() && this.nodeType !== 'Stage',
|
var clip = this.getClipWidth() && this.getClipHeight() && this.nodeType !== 'Stage',
|
||||||
n = 0,
|
n = 0,
|
||||||
|
|||||||
32
tests/js/unit/canvasTests.js
Normal file
32
tests/js/unit/canvasTests.js
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
Test.Modules.CANVAS = {
|
||||||
|
'pixel ratio': function(containerId) {
|
||||||
|
var stage = new Kinetic.Stage({
|
||||||
|
container: containerId,
|
||||||
|
width: 578,
|
||||||
|
height: 200
|
||||||
|
});
|
||||||
|
|
||||||
|
var layer = new Kinetic.Layer();
|
||||||
|
|
||||||
|
var circle = new Kinetic.Circle({
|
||||||
|
x: 578/2,
|
||||||
|
y: 100,
|
||||||
|
radius: 70,
|
||||||
|
fill: 'green',
|
||||||
|
stroke: 'blue',
|
||||||
|
strokeWidth: 4
|
||||||
|
});
|
||||||
|
|
||||||
|
layer.add(circle);
|
||||||
|
stage.add(layer);
|
||||||
|
|
||||||
|
|
||||||
|
stage.setWidth(578/2);
|
||||||
|
stage.setHeight(100);
|
||||||
|
|
||||||
|
stage.draw();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
Test.Modules.CONTAINER = {
|
Test.Modules.CONTAINER = {
|
||||||
'use clipping function': function(containerId) {
|
'clip': function(containerId) {
|
||||||
var stage = new Kinetic.Stage({
|
var stage = new Kinetic.Stage({
|
||||||
container: containerId,
|
container: containerId,
|
||||||
width: 578,
|
width: 578,
|
||||||
@@ -7,10 +7,7 @@ Test.Modules.CONTAINER = {
|
|||||||
draggable: true
|
draggable: true
|
||||||
});
|
});
|
||||||
var layer = new Kinetic.Layer({
|
var layer = new Kinetic.Layer({
|
||||||
clipFunc: function(canvas) {
|
clip: [0, 0, stage.getWidth() / 2, 100]
|
||||||
var context = canvas.getContext();
|
|
||||||
context.rect(0, 0, 400, 100);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
var group = new Kinetic.Group();
|
var group = new Kinetic.Group();
|
||||||
var circle = new Kinetic.Circle({
|
var circle = new Kinetic.Circle({
|
||||||
|
|||||||
Reference in New Issue
Block a user