feature : zoom level : code review

+ added explanatory comment for CanvasUtils.disableImageSmoothing
+ detect browser for chosing wheel/mousewheel event in DrawingController
+ create ABSTRACT_FUNCTION constant to be reused forabstract methods
This commit is contained in:
jdescottes 2013-11-15 00:32:18 +01:00
parent c8a8d470a7
commit 3af64d3f45
4 changed files with 27 additions and 14 deletions

View File

@ -50,5 +50,7 @@ var Constants = {
LEFT_BUTTON : 'left_button_1',
RIGHT_BUTTON : 'right_button_2',
MOUSEMOVE_THROTTLING : 10
MOUSEMOVE_THROTTLING : 10,
ABSTRACT_FUNCTION : function () {throw 'abstract method should be implemented';}
};

View File

@ -81,8 +81,12 @@
var body = $('body');
this.container.mousedown($.proxy(this.onMousedown_, this));
this.container.mousemove($.proxy(this.onMousemove_, this));
this.container.on('mousewheel', $.proxy(this.onMousewheel_, this));
this.container.on('wheel', $.proxy(this.onMousewheel_, this));
if (pskl.utils.UserAgent.isChrome) {
this.container.on('mousewheel', $.proxy(this.onMousewheel_, this));
} else {
this.container.on('wheel', $.proxy(this.onMousewheel_, this));
}
body.mouseup($.proxy(this.onMouseup_, this));

View File

@ -3,20 +3,20 @@
ns.AbstractRenderer = function () {};
ns.AbstractRenderer.prototype.clear = function () {throw 'abstract method should be implemented';};
ns.AbstractRenderer.prototype.clear = Constants.ABSTRACT_FUNCTION;
ns.AbstractRenderer.prototype.getCoordinates = function (x, y) {throw 'abstract method should be implemented';};
ns.AbstractRenderer.prototype.getCoordinates = Constants.ABSTRACT_FUNCTION;
ns.AbstractRenderer.prototype.setGridEnabled = function (b) {throw 'abstract method should be implemented';};
ns.AbstractRenderer.prototype.isGridEnabled = function () {throw 'abstract method should be implemented';};
ns.AbstractRenderer.prototype.setGridEnabled = Constants.ABSTRACT_FUNCTION;
ns.AbstractRenderer.prototype.isGridEnabled = Constants.ABSTRACT_FUNCTION;
ns.AbstractRenderer.prototype.setZoom = function (zoom) {throw 'abstract method should be implemented';};
ns.AbstractRenderer.prototype.getZoom = function () {throw 'abstract method should be implemented';};
ns.AbstractRenderer.prototype.setZoom = Constants.ABSTRACT_FUNCTION;
ns.AbstractRenderer.prototype.getZoom = Constants.ABSTRACT_FUNCTION;
ns.AbstractRenderer.prototype.moveOffset = function (x, y) {throw 'abstract method should be implemented';};
ns.AbstractRenderer.prototype.setOffset = function (x, y) {throw 'abstract method should be implemented';};
ns.AbstractRenderer.prototype.getOffset = function () {throw 'abstract method should be implemented';};
ns.AbstractRenderer.prototype.moveOffset = Constants.ABSTRACT_FUNCTION;
ns.AbstractRenderer.prototype.setOffset = Constants.ABSTRACT_FUNCTION;
ns.AbstractRenderer.prototype.getOffset = Constants.ABSTRACT_FUNCTION;
ns.AbstractRenderer.prototype.setDisplaySize = function (w, h) {throw 'abstract method should be implemented';};
ns.AbstractRenderer.prototype.getDisplaySize = function () {throw 'abstract method should be implemented';};
ns.AbstractRenderer.prototype.setDisplaySize = Constants.ABSTRACT_FUNCTION;
ns.AbstractRenderer.prototype.getDisplaySize = Constants.ABSTRACT_FUNCTION;
})();

View File

@ -19,6 +19,13 @@
return canvas;
},
/**
* By default, all scaling operations on a Canvas 2D Context are performed using antialiasing.
* Resizing a 32x32 image to 320x320 will lead to a blurry output.
* On Chrome, FF and IE>=11, this can be disabled by setting a property on the Canvas 2D Context.
* In this case the browser will use a nearest-neighbor scaling.
* @param {Canvas} canvas
*/
disableImageSmoothing : function (canvas) {
var context = canvas.getContext('2d');
context.imageSmoothingEnabled = false;