mirror of
https://github.com/scratchfoundation/scratch-paint.git
synced 2024-12-22 13:32:28 -05:00
switch to use id instead of hovered item
This commit is contained in:
parent
7e1375d855
commit
32661dde92
2 changed files with 21 additions and 17 deletions
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue