added getSize() method to Stage, Rect, and Image. Also updated unit tests

This commit is contained in:
Eric Rowell 2012-03-31 00:08:50 -07:00
parent 69c27de7df
commit 9994e8a37e
8 changed files with 91 additions and 9 deletions

35
dist/kinetic-core.js vendored
View File

@ -3,7 +3,7 @@
* http://www.kineticjs.com/
* Copyright 2012, Eric Rowell
* Licensed under the MIT or GPL Version 2 licenses.
* Date: Mar 30 2012
* Date: Mar 31 2012
*
* Copyright (C) 2011 - 2012 by Eric Rowell
*
@ -137,7 +137,7 @@ Kinetic.GlobalObject = {
return 2.5 + b * transition.time;
});
break;
// linear is default
// none is default
default:
this._transitionPow(transition, key, prop, function() {
return 1;
@ -675,8 +675,8 @@ Kinetic.Node.prototype = {
* radius, scale.x, scale.y, centerOffset.x, centerOffset.y, etc.
* @param {Object} config
* @config {Number} [duration] duration that the transition runs in seconds
* @config {String} [easing] easing function. can be linear, ease-in, ease-out, or ease-in-out.
* linear is the default
* @config {String} [easing] easing function. can be none, ease-in, ease-out, or ease-in-out.
* none is the default
* @config {Function} [callback] callback function to be executed when
* transition completes
*/
@ -1100,6 +1100,15 @@ Kinetic.Stage.prototype = {
this.backstageLayer.getCanvas().width = width;
this.backstageLayer.getCanvas().height = height;
},
/**
* return stage size
*/
getSize: function() {
return {
width: this.width,
height: this.height
};
},
/**
* clear all layers
*/
@ -2057,6 +2066,15 @@ Kinetic.Rect.prototype = {
setSize: function(width, height) {
this.width = width;
this.height = height;
},
/**
* return rect size
*/
getSize: function() {
return {
width: this.width,
height: this.height
};
}
};
@ -2189,6 +2207,15 @@ Kinetic.Image.prototype = {
setSize: function(width, height) {
this.width = width;
this.height = height;
},
/**
* return image size
*/
getSize: function() {
return {
width: this.width,
height: this.height
};
}
};
// extend Shape

File diff suppressed because one or more lines are too long

View File

@ -109,7 +109,7 @@ Kinetic.GlobalObject = {
return 2.5 + b * transition.time;
});
break;
// linear is default
// none is default
default:
this._transitionPow(transition, key, prop, function() {
return 1;

View File

@ -428,8 +428,8 @@ Kinetic.Node.prototype = {
* radius, scale.x, scale.y, centerOffset.x, centerOffset.y, etc.
* @param {Object} config
* @config {Number} [duration] duration that the transition runs in seconds
* @config {String} [easing] easing function. can be linear, ease-in, ease-out, or ease-in-out.
* linear is the default
* @config {String} [easing] easing function. can be none, ease-in, ease-out, or ease-in-out.
* none is the default
* @config {Function} [callback] callback function to be executed when
* transition completes
*/

View File

@ -120,6 +120,15 @@ Kinetic.Stage.prototype = {
this.backstageLayer.getCanvas().width = width;
this.backstageLayer.getCanvas().height = height;
},
/**
* return stage size
*/
getSize: function() {
return {
width: this.width,
height: this.height
};
},
/**
* clear all layers
*/

View File

@ -80,6 +80,15 @@ Kinetic.Image.prototype = {
setSize: function(width, height) {
this.width = width;
this.height = height;
},
/**
* return image size
*/
getSize: function() {
return {
width: this.width,
height: this.height
};
}
};
// extend Shape

View File

@ -57,6 +57,15 @@ Kinetic.Rect.prototype = {
setSize: function(width, height) {
this.width = width;
this.height = height;
},
/**
* return rect size
*/
getSize: function() {
return {
width: this.width,
height: this.height
};
}
};

View File

@ -64,6 +64,34 @@ Test.prototype.tests = {
group.add(circle);
layer.draw();
},
'STAGE - set stage size': 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.width / 2,
y: stage.height / 2,
radius: 70,
fill: 'green',
stroke: 'black',
strokeWidth: 4
});
test(stage.getSize().width === 578, 'stage height should be 578');
test(stage.getSize().height === 200, 'stage width should be 200');
stage.setSize(300, 150);
test(stage.getSize().width === 300, 'stage height should be 300');
test(stage.getSize().height === 150, 'stage width should be 150');
layer.add(circle);
stage.add(layer);
},
'STAGE - scale stage after add layer': function(containerId) {
var stage = new Kinetic.Stage({
container: containerId,