From 32661dde92786af288e2e2446806c736dc250065 Mon Sep 17 00:00:00 2001 From: DD Date: Fri, 22 Sep 2017 13:56:58 -0400 Subject: [PATCH] switch to use id instead of hovered item --- src/containers/reshape-mode.jsx | 14 ++++++------- src/helper/selection-tools/reshape-tool.js | 24 +++++++++++++--------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/containers/reshape-mode.jsx b/src/containers/reshape-mode.jsx index 9900f571..340c2789 100644 --- a/src/containers/reshape-mode.jsx +++ b/src/containers/reshape-mode.jsx @@ -26,8 +26,8 @@ class ReshapeMode extends React.Component { } } componentWillReceiveProps (nextProps) { - if (this.tool && nextProps.hoveredItem !== this.props.hoveredItem) { - this.tool.setPrevHoveredItem(nextProps.hoveredItem); + if (this.tool && nextProps.hoveredItemId !== this.props.hoveredItemId) { + this.tool.setPrevHoveredItemId(nextProps.hoveredItemId); } if (nextProps.isReshapeModeActive && !this.props.isReshapeModeActive) { @@ -41,7 +41,7 @@ class ReshapeMode extends React.Component { } activateTool () { this.tool = new ReshapeTool(this.props.setHoveredItem, this.props.clearHoveredItem, this.props.onUpdateSvg); - this.tool.setPrevHoveredItem(this.props.hoveredItem); + this.tool.setPrevHoveredItemId(this.props.hoveredItemId); this.tool.activate(); } deactivateTool () { @@ -60,7 +60,7 @@ class ReshapeMode extends React.Component { ReshapeMode.propTypes = { clearHoveredItem: PropTypes.func.isRequired, handleMouseDown: PropTypes.func.isRequired, - hoveredItem: PropTypes.instanceOf(paper.Item), + hoveredItemId: PropTypes.number, isReshapeModeActive: PropTypes.bool.isRequired, onUpdateSvg: PropTypes.func.isRequired, setHoveredItem: PropTypes.func.isRequired @@ -68,11 +68,11 @@ ReshapeMode.propTypes = { const mapStateToProps = state => ({ isReshapeModeActive: state.scratchPaint.mode === Modes.RESHAPE, - hoveredItem: state.scratchPaint.hoveredItem + hoveredItemId: state.scratchPaint.hoveredItemId }); const mapDispatchToProps = dispatch => ({ - setHoveredItem: hoveredItem => { - dispatch(setHoveredItem(hoveredItem)); + setHoveredItem: hoveredItemId => { + dispatch(setHoveredItem(hoveredItemId)); }, clearHoveredItem: () => { dispatch(clearHoveredItem()); diff --git a/src/helper/selection-tools/reshape-tool.js b/src/helper/selection-tools/reshape-tool.js index 424ee183..8fad8c35 100644 --- a/src/helper/selection-tools/reshape-tool.js +++ b/src/helper/selection-tools/reshape-tool.js @@ -31,10 +31,9 @@ class ReshapeTool extends paper.Tool { this.setHoveredItem = setHoveredItem; this.clearHoveredItem = clearHoveredItem; this.onUpdateSvg = onUpdateSvg; - this.prevHoveredItem = null; + this.prevHoveredItemId = null; this.lastEvent = null; this.mode = ReshapeModes.SELECTION_BOX; - this.selectionRect = null; this._modeMap = {}; this._modeMap[ReshapeModes.FILL] = new MoveTool(onUpdateSvg); this._modeMap[ReshapeModes.POINT] = new PointTool(onUpdateSvg); @@ -86,8 +85,8 @@ class ReshapeTool extends paper.Tool { } return hitOptions; } - setPrevHoveredItem (prevHoveredItem) { - this.prevHoveredItem = prevHoveredItem; + setPrevHoveredItemId (prevHoveredItemId) { + this.prevHoveredItemId = prevHoveredItemId; } handleMouseDown (event) { if (event.event.button > 0) return; // only first mouse button @@ -169,11 +168,11 @@ class ReshapeTool extends paper.Tool { } handleMouseMove (event) { const hoveredItem = getHoveredItem(event, this.getHitOptions(), true /* subselect */); - if ((!hoveredItem && this.prevHoveredItem) || // There is no longer a hovered item - (hoveredItem && !this.prevHoveredItem) || // There is now a hovered item - (hoveredItem && this.prevHoveredItem && - hoveredItem.id !== this.prevHoveredItem.id)) { // hovered item changed - this.setHoveredItem(hoveredItem); + if ((!hoveredItem && this.prevHoveredItemId) || // There is no longer a hovered item + (hoveredItem && !this.prevHoveredItemId) || // There is now a hovered item + (hoveredItem && this.prevHoveredItemId && + hoveredItem.id !== this.prevHoveredItemId)) { // hovered item changed + this.setHoveredItem(hoveredItem ? hoveredItem.id : null); } } handleMouseDrag (event) { @@ -192,9 +191,14 @@ class ReshapeTool extends paper.Tool { this.onUpdateSvg(); } } - deactivateTool() { + deactivateTool () { paper.settings.handleSize = 0; this.clearHoveredItem(); + this.setHoveredItem = null; + this.clearHoveredItem = null; + this.onUpdateSvg = null; + this.prevHoveredItemId = null; + this.lastEvent = null; } }