mirror of
https://github.com/scratchfoundation/scratch-paint.git
synced 2024-12-24 14:32:26 -05:00
51 lines
1.2 KiB
JavaScript
51 lines
1.2 KiB
JavaScript
|
import paper from 'paper';
|
||
|
|
||
|
const CLEAR_HOVERED_ITEM = 'scratch-paint/hover/CLEAR_HOVERED_ITEM';
|
||
|
/**
|
||
|
* @param hitOptions hit options to use
|
||
|
* @param event mouse event
|
||
|
* @return the hovered item or null if there is none
|
||
|
*/
|
||
|
const getHoveredItem = function (hitOptions, event) {
|
||
|
const hitResults = paper.project.hitTestAll(event.point, hitOptions);
|
||
|
if (hitResults.length === 0) {
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
let hitResult;
|
||
|
for (const result of hitResults) {
|
||
|
if (!(result.item.data && result.item.data.noHover) && !hitResult.item.selected) {
|
||
|
hitResult = result;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if (!hitResult) {
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
if (pg.item.isBoundsItem(hitResult.item)) {
|
||
|
return pg.guides.hoverBounds(hitResult.item);
|
||
|
|
||
|
} else if(pg.group.isGroupChild(hitResult.item)) {
|
||
|
return pg.guides.hoverBounds(pg.item.getRootItem(hitResult.item));
|
||
|
|
||
|
} else {
|
||
|
return pg.guides.hoverItem(hitResult);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
|
||
|
// Action creators ==================================
|
||
|
const clearHoveredItem = function () {
|
||
|
return {
|
||
|
type: CLEAR_HOVERED_ITEM
|
||
|
};
|
||
|
// TODO: paper.view.update();
|
||
|
};
|
||
|
|
||
|
|
||
|
export {
|
||
|
getHoveredItem,
|
||
|
clearHoveredItem
|
||
|
};
|