2011-03-06 19:50:44 -05:00
|
|
|
/*
|
|
|
|
* Paper.js
|
|
|
|
*
|
|
|
|
* This file is part of Paper.js, a JavaScript Vector Graphics Library,
|
|
|
|
* based on Scriptographer.org and designed to be largely API compatible.
|
2011-03-07 20:41:50 -05:00
|
|
|
* http://paperjs.org/
|
2011-03-06 19:50:44 -05:00
|
|
|
* http://scriptographer.org/
|
|
|
|
*
|
2011-03-07 20:41:50 -05:00
|
|
|
* Distributed under the MIT license. See LICENSE file for details.
|
|
|
|
*
|
2011-03-06 19:50:44 -05:00
|
|
|
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
|
|
|
|
* http://lehni.org/ & http://jonathanpuckey.com/
|
|
|
|
*
|
2011-03-07 20:41:50 -05:00
|
|
|
* All rights reserved.
|
2011-03-06 19:50:44 -05:00
|
|
|
*/
|
|
|
|
|
2011-03-04 08:34:31 -05:00
|
|
|
var DocumentView = this.DocumentView = Base.extend({
|
2011-02-28 12:28:16 -05:00
|
|
|
beans: true,
|
|
|
|
|
|
|
|
initialize: function(document) {
|
|
|
|
this.document = document;
|
|
|
|
this._bounds = this.document.bounds.clone();
|
|
|
|
this.matrix = new Matrix();
|
|
|
|
this._zoom = 1;
|
|
|
|
this._center = this._bounds.center;
|
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-02-28 12:28:16 -05:00
|
|
|
// TODO: test this.
|
|
|
|
getCenter: function() {
|
|
|
|
return this._center;
|
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-03-13 13:31:00 -04:00
|
|
|
setCenter: function(center) {
|
|
|
|
center = Point.read(arguments);
|
|
|
|
var delta = center.subtract(this._center);
|
|
|
|
this.scrollBy(delta);
|
|
|
|
this._center = center;
|
2011-02-28 12:28:16 -05:00
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-02-28 12:28:16 -05:00
|
|
|
getZoom: function() {
|
|
|
|
return this._zoom;
|
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-02-28 12:28:16 -05:00
|
|
|
setZoom: function(zoom) {
|
|
|
|
// TODO: clamp the view between 1/32 and 64?
|
|
|
|
var mx = new Matrix();
|
2011-03-04 20:26:12 -05:00
|
|
|
mx.scale(zoom / this._zoom, this._center);
|
2011-02-28 12:28:16 -05:00
|
|
|
this.transform(mx);
|
|
|
|
this._zoom = zoom;
|
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-03-13 13:31:00 -04:00
|
|
|
scrollBy: function(point) {
|
|
|
|
point = Point.read(arguments);
|
|
|
|
this.transform(new Matrix().translate(point.negate()));
|
2011-02-28 12:28:16 -05:00
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-03-04 20:42:24 -05:00
|
|
|
transform: function(matrix, flags) {
|
|
|
|
this.matrix.preConcatenate(matrix);
|
|
|
|
this._bounds = null;
|
|
|
|
},
|
|
|
|
|
2011-02-28 12:28:16 -05:00
|
|
|
getBounds: function() {
|
2011-03-04 20:42:24 -05:00
|
|
|
if (!this._bounds) {
|
|
|
|
this._bounds = this.matrix.transformBounds(this.document.bounds);
|
|
|
|
}
|
2011-02-28 12:28:16 -05:00
|
|
|
return this._bounds;
|
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-02-28 12:28:16 -05:00
|
|
|
// TODO:
|
|
|
|
// setBounds: function(rect) {
|
|
|
|
//
|
|
|
|
// },
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-02-28 12:28:16 -05:00
|
|
|
// TODO: getInvalidBounds
|
|
|
|
// TODO: invalidate(rect)
|
|
|
|
// TODO: style: artwork / preview / raster / opaque / ink
|
|
|
|
// TODO: getShowGrid
|
|
|
|
// TODO: getMousePoint
|
|
|
|
// TODO: artworkToView(rect)
|
|
|
|
artworkToView: function(point) {
|
|
|
|
return this.matrix.transform(point);
|
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-02-28 12:28:16 -05:00
|
|
|
viewToArtwork: function(point) {
|
|
|
|
// TODO: cache the inverse matrix:
|
|
|
|
return this.matrix.createInverse().transform(point);
|
|
|
|
}
|
2011-03-03 11:32:55 -05:00
|
|
|
});
|