Move Project#options to PaperScope#settings and define reasonable defaults.

This commit is contained in:
Jürg Lehni 2014-03-04 09:29:28 +01:00
parent 5b49fdf3ff
commit 7dbf6ceaff
5 changed files with 28 additions and 10 deletions

View file

@ -41,11 +41,17 @@ var PaperScope = Base.extend(/** @lends PaperScope# */{
* @name PaperScope#initialize
* @function
*/
// DOCS: initialize() parameters
initialize: function PaperScope(script) {
// script is only used internally, when creating scopes for PaperScript.
// Whenever a PaperScope is created, it automatically becomes the active
// one.
paper = this;
// Default configurable settings.
this.settings = {
handleSize: 4,
hitTolerance: 0
};
this.project = null;
this.projects = [];
this.tools = [];
@ -79,6 +85,18 @@ var PaperScope = Base.extend(/** @lends PaperScope# */{
*/
version: '/*#=*/ __options.version',
// DOCS: PaperScope#settings
/**
* Gives access to paper's configurable settings.
*
* <b>settings.handleSize:</b>
*
* <b>settings.hitTolerance:</b>
*
* @name PaperScope#settings
* @type Object
*/
/**
* The currently active project.
* @name PaperScope#project

View file

@ -113,7 +113,7 @@ var HitResult = Base.extend(/** @lends HitResult# */{
// 'compound-path', 'shape','raster', 'placed-symbol', ...
type: null,
// Tolerance
tolerance: paper.project.options.hitTolerance || 2,
tolerance: paper.settings.hitTolerance,
// Hit the fill of items
fill: !options,
// Hit the curves of path items, taking into account the stroke

View file

@ -2084,8 +2084,7 @@ var Path = PathItem.extend(/** @lends Path# */{
drawSegments(ctx, this, matrix);
// Now stroke it and draw its handles:
ctx.stroke();
drawHandles(ctx, this._segments, matrix,
this._project.options.handleSize || 4);
drawHandles(ctx, this._segments, matrix, paper.settings.handleSize);
}
};
}, new function() { // Path Smoothing

View file

@ -210,15 +210,16 @@ var Project = PaperScopeItem.extend(/** @lends Project# */{
return items;
},
// DOCS: Project#options
/**
* <b>options.handleSize:</b>
* Gives access to the project's configurable options.
*
* <b>options.hitTolerance:</b>
*
* @name Project#options
* @type Object
* @bean
* @deprecated use {@link PaperScope#settings} instead.
*/
getOptions: function() {
return this._scope.settings;
},
// TODO: Implement setSelectedItems?
_updateSelection: function(item) {
@ -451,7 +452,7 @@ var Project = PaperScopeItem.extend(/** @lends Project# */{
ctx.strokeWidth = 1;
for (var id in this._selectedItems) {
var item = this._selectedItems[id],
size = this.options.handleSize || 4;
size = this._scope.settings.handleSize;
half = size / 2;
if (item._updateVersion === this._updateVersion
&& (item._drawSelected || item._boundsSelected)) {

View file

@ -155,7 +155,7 @@ var CanvasView = View.extend(/** @lends CanvasView# */{
// Run the hit-test first
var project = this._project,
hit = project.hitTest(point, {
tolerance: project.options.hitTolerance || 0,
tolerance: this._scope.settings.hitTolerance,
fill: true,
stroke: true
}),