mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-07 13:22:07 -05:00
Implement new Bootstrap feature that allows hiding of getter parameters to make sure beans are produced, and use it across the library.
This commit is contained in:
parent
6ccdca552e
commit
b535d9f843
7 changed files with 31 additions and 34 deletions
5
lib/bootstrap.js
vendored
5
lib/bootstrap.js
vendored
|
@ -147,8 +147,9 @@ var Base = new function() { // Bootstrap scope
|
||||||
// with optional arguments and as beans should not declare
|
// with optional arguments and as beans should not declare
|
||||||
// the parameters and use the arguments array internally
|
// the parameters and use the arguments array internally
|
||||||
// instead.
|
// instead.
|
||||||
if (beans && val.length === 0
|
if (beans && (bean = name.match(/^(get|is)(([A-Z])(.*))$/))
|
||||||
&& (bean = name.match(/^(get|is)(([A-Z])(.*))$/)))
|
// Reg-exp to detect non-hidden parameters
|
||||||
|
&& !/^function\s*\(.*\b[^_,].*\)/.test(val))
|
||||||
beans.push([ bean[3].toLowerCase() + bean[4], bean[2] ]);
|
beans.push([ bean[3].toLowerCase() + bean[4], bean[2] ]);
|
||||||
}
|
}
|
||||||
// No need to look up getter if this is a function already.
|
// No need to look up getter if this is a function already.
|
||||||
|
|
|
@ -504,9 +504,9 @@ var Point = this.Point = Base.extend(/** @lends Point# */{
|
||||||
* @bean
|
* @bean
|
||||||
* @type Number
|
* @type Number
|
||||||
*/
|
*/
|
||||||
getAngle: function(/* point */) {
|
getAngle: function(_point) {
|
||||||
// Hide parameters from Bootstrap so it injects bean too
|
// Hide parameters from Bootstrap so it injects bean too
|
||||||
return this.getAngleInRadians(arguments[0]) * 180 / Math.PI;
|
return this.getAngleInRadians(_point) * 180 / Math.PI;
|
||||||
},
|
},
|
||||||
|
|
||||||
setAngle: function(angle) {
|
setAngle: function(angle) {
|
||||||
|
@ -542,9 +542,9 @@ var Point = this.Point = Base.extend(/** @lends Point# */{
|
||||||
* @bean
|
* @bean
|
||||||
* @type Number
|
* @type Number
|
||||||
*/
|
*/
|
||||||
getAngleInRadians: function(/* point */) {
|
getAngleInRadians: function(_point) {
|
||||||
// Hide parameters from Bootstrap so it injects bean too
|
// Hide parameters from Bootstrap so it injects bean too
|
||||||
if (arguments[0] === undefined) {
|
if (_point === undefined) {
|
||||||
if (this._angle == null)
|
if (this._angle == null)
|
||||||
this._angle = Math.atan2(this.y, this.x);
|
this._angle = Math.atan2(this.y, this.x);
|
||||||
return this._angle;
|
return this._angle;
|
||||||
|
@ -559,8 +559,8 @@ var Point = this.Point = Base.extend(/** @lends Point# */{
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getAngleInDegrees: function(/* point */) {
|
getAngleInDegrees: function(_point) {
|
||||||
return this.getAngle(arguments[0]);
|
return this.getAngle(_point);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -167,11 +167,10 @@ var Rectangle = this.Rectangle = Base.extend(/** @lends Rectangle# */{
|
||||||
* @type Point
|
* @type Point
|
||||||
* @bean
|
* @bean
|
||||||
*/
|
*/
|
||||||
getPoint: function(/* dontLink */) {
|
getPoint: function(_dontLink) {
|
||||||
// Pass on the optional argument dontLink which tells LinkedPoint to
|
// Pass on the optional argument _dontLink which tells LinkedPoint to
|
||||||
// produce a normal point instead. Used internally for speed reasons.
|
// produce a normal point instead. Used internally for speed reasons.
|
||||||
return LinkedPoint.create(this, 'setPoint', this.x, this.y,
|
return LinkedPoint.create(this, 'setPoint', this.x, this.y, _dontLink);
|
||||||
arguments[0]);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
setPoint: function(point) {
|
setPoint: function(point) {
|
||||||
|
@ -181,16 +180,16 @@ var Rectangle = this.Rectangle = Base.extend(/** @lends Rectangle# */{
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The size of the rectangle
|
* The size of the rectangle
|
||||||
*
|
*
|
||||||
* @type Size
|
* @type Size
|
||||||
* @bean
|
* @bean
|
||||||
*/
|
*/
|
||||||
getSize: function(/* dontLink */) {
|
getSize: function(_dontLink) {
|
||||||
// See Rectangle#getPoint() about arguments[0]
|
|
||||||
return LinkedSize.create(this, 'setSize', this.width, this.height,
|
return LinkedSize.create(this, 'setSize', this.width, this.height,
|
||||||
arguments[0]);
|
_dontLink);
|
||||||
},
|
},
|
||||||
|
|
||||||
setSize: function(size) {
|
setSize: function(size) {
|
||||||
|
@ -308,9 +307,9 @@ var Rectangle = this.Rectangle = Base.extend(/** @lends Rectangle# */{
|
||||||
* @type Point
|
* @type Point
|
||||||
* @bean
|
* @bean
|
||||||
*/
|
*/
|
||||||
getCenter: function(/* dontLink */) {
|
getCenter: function(_dontLink) {
|
||||||
return LinkedPoint.create(this, 'setCenter',
|
return LinkedPoint.create(this, 'setCenter',
|
||||||
this.getCenterX(), this.getCenterY(), arguments[0]);
|
this.getCenterX(), this.getCenterY(), _dontLink);
|
||||||
},
|
},
|
||||||
|
|
||||||
setCenter: function(point) {
|
setCenter: function(point) {
|
||||||
|
@ -726,9 +725,9 @@ var Rectangle = this.Rectangle = Base.extend(/** @lends Rectangle# */{
|
||||||
setY = 'set' + y,
|
setY = 'set' + y,
|
||||||
get = 'get' + part,
|
get = 'get' + part,
|
||||||
set = 'set' + part;
|
set = 'set' + part;
|
||||||
this[get] = function(/* dontLink */) {
|
this[get] = function(_dontLink) {
|
||||||
return LinkedPoint.create(this, set,
|
return LinkedPoint.create(this, set,
|
||||||
this[getX](), this[getY](), arguments[0]);
|
this[getX](), this[getY](), _dontLink);
|
||||||
};
|
};
|
||||||
this[set] = function(point) {
|
this[set] = function(point) {
|
||||||
point = Point.read(arguments);
|
point = Point.read(arguments);
|
||||||
|
|
|
@ -512,7 +512,7 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
|
||||||
* // Move the circle 100 points to the right
|
* // Move the circle 100 points to the right
|
||||||
* circle.position.x += 100;
|
* circle.position.x += 100;
|
||||||
*/
|
*/
|
||||||
getPosition: function(/* dontLink */) {
|
getPosition: function(_dontLink) {
|
||||||
// Cache position value.
|
// Cache position value.
|
||||||
// Pass true for dontLink in getCenter(), so receive back a normal point
|
// Pass true for dontLink in getCenter(), so receive back a normal point
|
||||||
var pos = this._position
|
var pos = this._position
|
||||||
|
@ -521,7 +521,7 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
|
||||||
// use them to calculate the difference in #setPosition, as when it is
|
// use them to calculate the difference in #setPosition, as when it is
|
||||||
// modified, it would hold new values already and only then cause the
|
// modified, it would hold new values already and only then cause the
|
||||||
// calling of #setPosition.
|
// calling of #setPosition.
|
||||||
return arguments[0] ? pos
|
return _dontLink ? pos
|
||||||
: LinkedPoint.create(this, 'setPosition', pos.x, pos.y);
|
: LinkedPoint.create(this, 'setPosition', pos.x, pos.y);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -553,15 +553,14 @@ function(name) {
|
||||||
// Produce getters for bounds properties. These handle caching, matrices
|
// Produce getters for bounds properties. These handle caching, matrices
|
||||||
// and redirect the call to the private _getBounds, which can be
|
// and redirect the call to the private _getBounds, which can be
|
||||||
// overridden by subclasses, see below.
|
// overridden by subclasses, see below.
|
||||||
this[name] = function(/* matrix */) {
|
this[name] = function(_matrix) {
|
||||||
var getter = this._boundsGetter,
|
var getter = this._boundsGetter,
|
||||||
bounds = this._getCachedBounds(
|
bounds = this._getCachedBounds(
|
||||||
// Allow subclasses to override _boundsGetter if they use the
|
// Allow subclasses to override _boundsGetter if they use the
|
||||||
// same calculations for multiple type of bounds.
|
// same calculations for multiple type of bounds.
|
||||||
// The default is name:
|
// The default is name:
|
||||||
typeof getter == 'string' ? getter : getter && getter[name] || name,
|
typeof getter == 'string' ? getter : getter && getter[name] || name,
|
||||||
// Pass on the optional matrix
|
_matrix);
|
||||||
arguments[0]);
|
|
||||||
// If we're returning 'bounds', create a LinkedRectangle that uses the
|
// If we're returning 'bounds', create a LinkedRectangle that uses the
|
||||||
// setBounds() setter to update the Item whenever the bounds are
|
// setBounds() setter to update the Item whenever the bounds are
|
||||||
// changed:
|
// changed:
|
||||||
|
|
|
@ -154,13 +154,13 @@ var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{
|
||||||
* @type Context
|
* @type Context
|
||||||
* @bean
|
* @bean
|
||||||
*/
|
*/
|
||||||
getContext: function(/* notifyChange */) {
|
getContext: function(_notifyChange) {
|
||||||
if (!this._context)
|
if (!this._context)
|
||||||
this._context = this.getCanvas().getContext('2d');
|
this._context = this.getCanvas().getContext('2d');
|
||||||
// Support a hidden parameter that indicates if the context will be used
|
// Support a hidden parameter that indicates if the context will be used
|
||||||
// to modify the Raster object. We can notify such changes ahead since
|
// to modify the Raster object. We can notify such changes ahead since
|
||||||
// they are only used afterwards for redrawing.
|
// they are only used afterwards for redrawing.
|
||||||
if (arguments[0])
|
if (_notifyChange)
|
||||||
this._changed(/*#=*/ Change.PIXELS);
|
this._changed(/*#=*/ Change.PIXELS);
|
||||||
return this._context;
|
return this._context;
|
||||||
},
|
},
|
||||||
|
|
|
@ -228,14 +228,12 @@ var Curve = this.Curve = Base.extend(/** @lends Curve# */{
|
||||||
* @type Number
|
* @type Number
|
||||||
* @bean
|
* @bean
|
||||||
*/
|
*/
|
||||||
getLength: function(/* from, to */) {
|
|
||||||
// Hide parameters from Bootstrap so it injects bean too
|
// Hide parameters from Bootstrap so it injects bean too
|
||||||
var from = arguments[0],
|
getLength: function(_from, _to) {
|
||||||
to = arguments[1],
|
var fullLength = arguments.length == 0 || _from == 0 && _to == 1;
|
||||||
fullLength = arguments.length == 0 || from == 0 && to == 1;
|
|
||||||
if (fullLength && this._length != null)
|
if (fullLength && this._length != null)
|
||||||
return this._length;
|
return this._length;
|
||||||
var length = Curve.getLength(this.getValues(), from, to);
|
var length = Curve.getLength(this.getValues(), _from, _to);
|
||||||
if (fullLength)
|
if (fullLength)
|
||||||
this._length = length;
|
this._length = length;
|
||||||
return length;
|
return length;
|
||||||
|
|
|
@ -131,7 +131,7 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
|
||||||
* @type Curve[]
|
* @type Curve[]
|
||||||
* @bean
|
* @bean
|
||||||
*/
|
*/
|
||||||
getCurves: function(/* includeFill */) {
|
getCurves: function(_includeFill) {
|
||||||
var curves = this._curves,
|
var curves = this._curves,
|
||||||
segments = this._segments;
|
segments = this._segments;
|
||||||
if (!curves) {
|
if (!curves) {
|
||||||
|
@ -148,7 +148,7 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
|
||||||
// If we're asked to include the closing curve for fill, even if the
|
// If we're asked to include the closing curve for fill, even if the
|
||||||
// path is not closed for stroke, create a new uncached array and add
|
// path is not closed for stroke, create a new uncached array and add
|
||||||
// the closing curve. Used in Path#contains()
|
// the closing curve. Used in Path#contains()
|
||||||
if (arguments[0] && !this._closed && this._style._fillColor) {
|
if (_includeFill && !this._closed && this._style._fillColor) {
|
||||||
curves = curves.concat([
|
curves = curves.concat([
|
||||||
Curve.create(this, segments[segments.length - 1], segments[0])
|
Curve.create(this, segments[segments.length - 1], segments[0])
|
||||||
]);
|
]);
|
||||||
|
|
Loading…
Reference in a new issue