From 3af64d3f451d1023934f2040b7f3a1e30cf99a2b Mon Sep 17 00:00:00 2001 From: jdescottes Date: Fri, 15 Nov 2013 00:32:18 +0100 Subject: [PATCH] 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 --- js/Constants.js | 4 +++- js/controller/DrawingController.js | 8 ++++++-- js/rendering/AbstractRenderer.js | 22 +++++++++++----------- js/utils/CanvasUtils.js | 7 +++++++ 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/js/Constants.js b/js/Constants.js index 294d347f..1b7f8569 100644 --- a/js/Constants.js +++ b/js/Constants.js @@ -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';} }; \ No newline at end of file diff --git a/js/controller/DrawingController.js b/js/controller/DrawingController.js index 417e0b44..f4eb5ba4 100644 --- a/js/controller/DrawingController.js +++ b/js/controller/DrawingController.js @@ -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)); diff --git a/js/rendering/AbstractRenderer.js b/js/rendering/AbstractRenderer.js index a3539402..6254ee39 100644 --- a/js/rendering/AbstractRenderer.js +++ b/js/rendering/AbstractRenderer.js @@ -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; })(); \ No newline at end of file diff --git a/js/utils/CanvasUtils.js b/js/utils/CanvasUtils.js index 19cca6b3..be3e041d 100644 --- a/js/utils/CanvasUtils.js +++ b/js/utils/CanvasUtils.js @@ -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;