mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -05:00
Improve CanvasView constructor.
Support canvas / size arguments, but not both together, and throw exception if both fail.
This commit is contained in:
parent
a3d0e0d462
commit
7285ec636a
1 changed files with 13 additions and 4 deletions
|
@ -21,16 +21,25 @@ var CanvasView = View.extend(/** @lends CanvasView# */{
|
||||||
/**
|
/**
|
||||||
* Creates a view object that wraps a canvas element.
|
* 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
|
* 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) {
|
initialize: function CanvasView(canvas) {
|
||||||
// Handle canvas argument
|
// Handle canvas argument
|
||||||
if (!(canvas instanceof HTMLCanvasElement)) {
|
if (!(canvas instanceof HTMLCanvasElement)) {
|
||||||
// 2nd argument onwards could be view size, otherwise use default:
|
// See if the arguments describe the view size:
|
||||||
var size = Size.read(arguments, 1);
|
var size = Size.read(arguments);
|
||||||
if (size.isZero())
|
if (size.isZero())
|
||||||
size = new Size(1024, 768);
|
throw new Error(
|
||||||
|
'Cannot create CanvasView with the provided arguments: '
|
||||||
|
+ arguments);
|
||||||
canvas = CanvasProvider.getCanvas(size);
|
canvas = CanvasProvider.getCanvas(size);
|
||||||
}
|
}
|
||||||
var ctx = this._context = canvas.getContext('2d');
|
var ctx = this._context = canvas.getContext('2d');
|
||||||
|
|
Loading…
Reference in a new issue