move hit options declaration into function

This commit is contained in:
DD 2017-09-22 12:31:39 -04:00
parent adbd023551
commit 3bb606e16a

View file

@ -32,43 +32,6 @@ class ReshapeTool extends paper.Tool {
this.clearHoveredItem = clearHoveredItem; this.clearHoveredItem = clearHoveredItem;
this.onUpdateSvg = onUpdateSvg; this.onUpdateSvg = onUpdateSvg;
this.prevHoveredItem = null; this.prevHoveredItem = null;
this._hitOptionsSelected = {
match: function (item) {
if (!item.item || !item.item.selected) return;
if (item.type === 'handle-out' || item.type === 'handle-in') {
// Only hit test against handles that are visible, that is,
// their segment is selected
if (!item.segment.selected) {
return false;
}
}
return true;
},
segments: true,
stroke: true,
curves: true,
handles: true,
fill: true,
guide: false
};
this._hitOptions = {
match: function (item) {
if (item.type === 'handle-out' || item.type === 'handle-in') {
// Only hit test against handles that are visible, that is,
// their segment is selected
if (!item.segment.selected) {
return false;
}
}
return true;
},
segments: true,
stroke: true,
curves: true,
handles: true,
fill: true,
guide: false
};
this.lastEvent = null; this.lastEvent = null;
this.mode = ReshapeModes.SELECTION_BOX; this.mode = ReshapeModes.SELECTION_BOX;
this.selectionRect = null; this.selectionRect = null;
@ -89,9 +52,39 @@ class ReshapeTool extends paper.Tool {
paper.settings.handleSize = 8; paper.settings.handleSize = 8;
} }
getHitOptions (preselectedOnly) { getHitOptions (preselectedOnly) {
this._hitOptions.tolerance = ReshapeTool.TOLERANCE / paper.view.zoom; const hitOptions = {
this._hitOptionsSelected.tolerance = ReshapeTool.TOLERANCE / paper.view.zoom; segments: true,
return preselectedOnly ? this._hitOptionsSelected : this._hitOptions; stroke: true,
curves: true,
handles: true,
fill: true,
guide: false
};
if (preselectedOnly) {
hitOptions.match = item => {
if (!item.item || !item.item.selected) return;
if (item.type === 'handle-out' || item.type === 'handle-in') {
// Only hit test against handles that are visible, that is,
// their segment is selected
if (!item.segment.selected) {
return false;
}
}
return true;
};
} else {
hitOptions.match = item => {
if (item.type === 'handle-out' || item.type === 'handle-in') {
// Only hit test against handles that are visible, that is,
// their segment is selected
if (!item.segment.selected) {
return false;
}
}
return true;
};
}
return hitOptions;
} }
setPrevHoveredItem (prevHoveredItem) { setPrevHoveredItem (prevHoveredItem) {
this.prevHoveredItem = prevHoveredItem; this.prevHoveredItem = prevHoveredItem;