mirror of
https://github.com/konvajs/konva.git
synced 2025-09-18 18:27:58 +08:00
layer tests are now passing
This commit is contained in:
@@ -188,16 +188,18 @@
|
||||
* clear canvas
|
||||
* @method
|
||||
* @memberof Kinetic.Context.prototype
|
||||
* @param {Object} [bounds]
|
||||
* @param {Number} [bounds.x]
|
||||
* @param {Number} [bounds.y]
|
||||
* @param {Number} [bounds.width]
|
||||
* @param {Number} [bounds.height]
|
||||
*/
|
||||
clear: function() {
|
||||
var args = [].slice.call(arguments),
|
||||
canvas = this.getCanvas(),
|
||||
clear: function(bounds) {
|
||||
var canvas = this.getCanvas(),
|
||||
pos, size;
|
||||
|
||||
if (args.length) {
|
||||
pos = Kinetic.Util._getXY(args);
|
||||
size = Kinetic.Util._getSize(args);
|
||||
this.clearRect(pos.x || 0, pos.y || 0, size.width, size.height);
|
||||
if (bounds) {
|
||||
this.clearRect(bounds.x || 0, bounds.y || 0, bounds.width || 0, bounds.height || 0);
|
||||
}
|
||||
else {
|
||||
this.clearRect(0, 0, canvas.getWidth(), canvas.getHeight());
|
||||
|
12
src/Layer.js
12
src/Layer.js
@@ -153,17 +153,21 @@
|
||||
* clear scene and hit canvas contexts tied to the layer
|
||||
* @method
|
||||
* @memberof Kinetic.Node.prototype
|
||||
* @param {Array|Object} [bounds]
|
||||
* @param {Object} [bounds]
|
||||
* @param {Number} [bounds.x]
|
||||
* @param {Number} [bounds.y]
|
||||
* @param {Number} [bounds.width]
|
||||
* @param {Number} [bounds.height]
|
||||
* @example
|
||||
* layer.clear();<br>
|
||||
* layer.clear(0, 0, 100, 100);
|
||||
*/
|
||||
clear: function() {
|
||||
clear: function(bounds) {
|
||||
var context = this.getContext(),
|
||||
hitContext = this.getHitCanvas().getContext();
|
||||
|
||||
context.clear.apply(context, arguments);
|
||||
hitContext.clear.apply(hitContext, arguments);
|
||||
context.clear(bounds);
|
||||
hitContext.clear(bounds);
|
||||
return this;
|
||||
},
|
||||
// extend Node.prototype.setVisible
|
||||
|
@@ -88,7 +88,7 @@ suite('Layer', function() {
|
||||
layer.add(circle);
|
||||
stage.add(layer);
|
||||
|
||||
layer.clear(100, 100, 100, 100);
|
||||
layer.clear({x:100, y:100, width: 100, height:100});
|
||||
|
||||
var trace = layer.getContext().getTrace();
|
||||
//console.log(trace);
|
||||
@@ -130,9 +130,9 @@ suite('Layer', function() {
|
||||
layer.add(greenCircle);
|
||||
stage.add(layer);
|
||||
|
||||
assert.equal(layer.getIntersection(300, 100).getId(), 'greenCircle', 'shape should be greenCircle');
|
||||
assert.equal(layer.getIntersection(380, 100).getId(), 'redCircle', 'shape should be redCircle');
|
||||
assert.equal(layer.getIntersection(100, 100), null, 'shape should be null');
|
||||
assert.equal(layer.getIntersection({x:300, y:100}).getId(), 'greenCircle', 'shape should be greenCircle');
|
||||
assert.equal(layer.getIntersection({x:380, y:100}).getId(), 'redCircle', 'shape should be redCircle');
|
||||
assert.equal(layer.getIntersection({x:100, y:100}), null, 'shape should be null');
|
||||
|
||||
|
||||
});
|
||||
@@ -186,7 +186,7 @@ suite('Layer', function() {
|
||||
stage.add(layer);
|
||||
|
||||
for(var n = 0; n < 20; n++) {
|
||||
circle.move(10, 0);
|
||||
circle.move({x:10, y:0});
|
||||
layer.draw();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user