From 7285ec636ac1ef219a1c8730520f50c9a95ebe41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 14 Oct 2013 16:06:30 +0200 Subject: [PATCH] Improve CanvasView constructor. Support canvas / size arguments, but not both together, and throw exception if both fail. --- src/ui/CanvasView.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/ui/CanvasView.js b/src/ui/CanvasView.js index c314b7b8..b3f12cf0 100644 --- a/src/ui/CanvasView.js +++ b/src/ui/CanvasView.js @@ -21,16 +21,25 @@ var CanvasView = View.extend(/** @lends CanvasView# */{ /** * Creates a view object that wraps a canvas element. * - * @param {HTMLCanvasElement} canvas The canvas object that this view should + * @name CanvasView#initialize + * @param {HTMLCanvasElement} canvas the canvas object that this view should * wrap */ + /** + * Creates a view object that wraps a newly created canvas element. + * + * @name CanvasView#initialize + * @param {Size} size the size of the canvas to be created + */ initialize: function CanvasView(canvas) { // Handle canvas argument if (!(canvas instanceof HTMLCanvasElement)) { - // 2nd argument onwards could be view size, otherwise use default: - var size = Size.read(arguments, 1); + // See if the arguments describe the view size: + var size = Size.read(arguments); if (size.isZero()) - size = new Size(1024, 768); + throw new Error( + 'Cannot create CanvasView with the provided arguments: ' + + arguments); canvas = CanvasProvider.getCanvas(size); } var ctx = this._context = canvas.getContext('2d');