mirror of
https://github.com/konvajs/konva.git
synced 2026-01-18 19:51:21 +08:00
added getter and setter methods for pixel ratio. Also added unit tests
This commit is contained in:
@@ -7,7 +7,8 @@
|
||||
|| context.mozBackingStorePixelRatio
|
||||
|| context.msBackingStorePixelRatio
|
||||
|| context.oBackingStorePixelRatio
|
||||
|| context.backingStorePixelRatio || 1,
|
||||
|| context.backingStorePixelRatio
|
||||
|| 1,
|
||||
_pixelRatio = devicePixelRatio / backingStoreRatio;
|
||||
|
||||
/**
|
||||
@@ -46,11 +47,31 @@
|
||||
this.context = this.element.getContext(contextType);
|
||||
this.setSize(width, height);
|
||||
},
|
||||
/**
|
||||
* get pixel ratio
|
||||
* @method
|
||||
* @memberof Kinetic.Canvas.prototype
|
||||
* @returns {Number} pixel ratio
|
||||
*/
|
||||
getPixelRatio: function() {
|
||||
return this.pixelRatio;
|
||||
},
|
||||
/**
|
||||
* get pixel ratio
|
||||
* @method
|
||||
* @memberof Kinetic.Canvas.prototype
|
||||
*/
|
||||
setPixelRatio: function(pixelRatio) {
|
||||
this.pixelRatio = pixelRatio;
|
||||
this.setSize(this.getWidth(), this.getHeight());
|
||||
},
|
||||
/**
|
||||
* reset canvas context transform
|
||||
* @method
|
||||
* @memberof Kinetic.Canvas.prototype
|
||||
*/
|
||||
reset: function() {
|
||||
this.getContext().setTransform(1 * _pixelRatio, 0, 0, 1 * _pixelRatio, 0, 0);
|
||||
this.getContext().setTransform(1 * this.pixelRatio, 0, 0, 1 * this.pixelRatio, 0, 0);
|
||||
},
|
||||
/**
|
||||
* get canvas element
|
||||
|
||||
@@ -26,6 +26,21 @@ Test.Modules.CANVAS = {
|
||||
|
||||
stage.draw();
|
||||
|
||||
layer.getCanvas().setPixelRatio(1);
|
||||
test(layer.getCanvas().getPixelRatio() === 1, 'pixel ratio should be 1');
|
||||
test(layer.getCanvas().width === 289, 'canvas width should be 289');
|
||||
test(layer.getCanvas().height === 100, 'canvas height should be 100');
|
||||
|
||||
layer.getCanvas().setPixelRatio(2);
|
||||
test(layer.getCanvas().getPixelRatio() === 2, 'pixel ratio should be 2');
|
||||
test(layer.getCanvas().width === 578, 'canvas width should be 578');
|
||||
test(layer.getCanvas().height === 200, 'canvas height should be 200');
|
||||
|
||||
|
||||
|
||||
layer.draw();
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user